Cloning a template with a specification-customization

1,853 views
Skip to first unread message

Malte Krüger

unread,
Mar 26, 2012, 2:21:36 PM3/26/12
to pysphere
Today I was about to start with Powershell again because I had to
create a vSphere Script. I was lucky to find this nice python-lib. Now
i am thinking about a second script that should create a VM based on a
Template with a given Customization. Is this possible and how to do
it? The approach in PowerCLI would be something like this:
http://mcpguides.com/?p=101

Thanks,
Malte

Seba

unread,
Apr 10, 2012, 4:56:29 PM4/10/12
to pysp...@googlegroups.com, malte....@hcu-hamburg.de
Hi Malte,

   I'm sorry for my late response, I was on holiday and when I can back I answered pending questions but I accidentally missed yours :(
   Pysphere provides a simple way of cloning VMs (and templates) allowing some basic customization. (clone() method on a VIVirtualMachine object)

   In order to provide more advanced customization you can check the clone method code and write something similar (you'll need to know the vSphere SDK specifications: http://pubs.vmware.com/vsphere-50/topic/com.vmware.wssdk.apiref.doc_50/vim.VirtualMachine.html?path=5_0_2_5_3_21#clone). Other possible way is to clone a vm with the basic customization and then customize the new VM using the ReconfigVM_Task method from the SDK. Check out these other threads from the discussion forum which are related with cloning and VM reconfiguration. Let me know any specific setting you want to set so I can give you some guidance.



Regards,

Sebastian,

PS: Keep in mind that the resourcepool parameter is mandatory if you are cloning from a template

2012/3/26 Malte Krüger

Malte Krüger

unread,
Apr 10, 2012, 6:31:12 PM4/10/12
to Seba, pysp...@googlegroups.com

Hi Sebastian,

 

that sounds pretty interesting. I will check it out and update the thread if I know more.

 

Regards,

Malte

 

 

Von: Malte Krüger [mailto:malte....@hcu-hamburg.de]
Gesendet: Mittwoch, 11. April 2012 00:30
An: 'Seba'
Betreff: AW: Cloning a template with a specification-customization

 

Hi Sebastian,

 

that sounds pretty interesting. I will check it out and update the thread if I know more.

 

Regards

Malte

oddur.m...@gmail.com

unread,
Apr 12, 2012, 8:52:13 AM4/12/12
to pysphere
I'm looking to extend the clone method to have the CustomizationSpec
filled out so that we run the os customization on each new VM.

ATM I need this so that we run sysprep on new windows machines. The
values in the CustomizationSpec differ between windows and linux
guests(CustomizationLinuxPrep vs CustomizationLinuxPrep) and we'd need
to support both.

Would you guys be interested in pulling those changes back into the
library once I've got them in ?

- Oddur

On Apr 10, 10:31 pm, Malte Krüger <malte.krue...@hcu-hamburg.de>
wrote:
> Hi Sebastian,
>
> that sounds pretty interesting. I will check it out and update the thread if
> I know more.
>
> Regards,
>
> Malte
>
> Von: Malte Krüger [mailto:malte.krue...@hcu-hamburg.de]
> Gesendet: Mittwoch, 11. April 2012 00:30
> An: 'Seba'
> Betreff: AW: Cloning a template with a specification-customization
>
> Hi Sebastian,
>
> that sounds pretty interesting. I will check it out and update the thread if
> I know more.
>
> Regards
>
> Malte
>
> Von: Seba [mailto:argo...@gmail.com]
> Gesendet: Dienstag, 10. April 2012 22:56
> An: pysp...@googlegroups.com
> Cc: malte.krue...@hcu-hamburg.de
> Betreff: Re: Cloning a template with a specification-customization
>
> Hi Malte,
>
>    I'm sorry for my late response, I was on holiday and when I can back I
> answered pending questions but I accidentally missed yours :(
>
>    Pysphere provides a simple way of cloning VMs (and templates) allowing
> some basic customization. (clone() method on a VIVirtualMachine object)
>
>    In order to provide more advanced customization you can check the clone
> method code and write something similar (you'll need to know the vSphere SDK
> specifications:http://pubs.vmware.com/vsphere-50/topic/com.vmware.wssdk.apiref.doc_5...
> irtualMachine.html?path=5_0_2_5_3_21#clone). Other possible way is to clone
> a vm with the basic customization and then customize the new VM using the
> ReconfigVM_Task method from the SDK. Check out these other threads from the
> discussion forum which are related with cloning and VM reconfiguration. Let
> me know any specific setting you want to set so I can give you some
> guidance.
>
> http://groups.google.com/group/pysphere/browse_thread/thread/3f87b862...
> 2#
> <http://groups.google.com/group/pysphere/browse_thread/thread/3f87b862...
> 82>
>
> http://groups.google.com/group/pysphere/browse_thread/thread/10bb4268...
> c#
> <http://groups.google.com/group/pysphere/browse_thread/thread/10bb4268...
> cc>
>
> http://groups.google.com/group/pysphere/browse_thread/thread/f55a0c68...
> 3#
> <http://groups.google.com/group/pysphere/browse_thread/thread/f55a0c68...
> 93>
>
> http://groups.google.com/group/pysphere/browse_thread/thread/5efb68c2...
> 3#
> <http://groups.google.com/group/pysphere/browse_thread/thread/5efb68c2...
> 43>
>
> http://groups.google.com/group/pysphere/browse_thread/thread/1a2990de...
> f#
> <http://groups.google.com/group/pysphere/browse_thread/thread/1a2990de...
> 9f>

Seba

unread,
Apr 13, 2012, 8:10:29 PM4/13/12
to pysp...@googlegroups.com, oddur.m...@gmail.com
Hey, sorry I didn't reply before. I've been pretty busy these days.

Of course I'm interested in adding your changes, your cooperation is much appreciated.

Thanks!

Seba.

2012/4/12

Oddur Snær Magnússon

unread,
Apr 14, 2012, 10:24:44 AM4/14/12
to pysp...@googlegroups.com, oddur.m...@gmail.com
I'm wondering what is the best way to pass in all the customization details: optional arguments or some configuration object ?

Attached is at least a version of the clone method works for me now with windows 2008 r2 VM.  I have not done the linux version yet, hopefully I'll get to it next week. 

 - Oddur
cloneWithCustomization-v1.txt

Seba

unread,
Apr 24, 2012, 8:48:01 AM4/24/12
to pysp...@googlegroups.com, oddur.m...@gmail.com
As the VM configuration has a lot of possible parameters I think the best way is to pass a configuration object. Even easier, to accept the  CustomizationSpec  object directly, besides each user needs can be too different as to set default values (e.g fixed IP or DHCP).

A different approach is to create a new class (e.g. VIVirtualMachineConfiguration) which internally holds a CustomizationSpec object, and define different methods to model that CustomizationSpec, e.g. add_nic(....), set_login_settings(..)

a sample use case would be:

custom = vm.get_configuration() 
#returns a customization object
#that internally models a vSphere CustomizationSpec object

custom.add_nic(mode="bridged", dhcp=True, ...)
custom.set_computer_name("mycompany01")
custom.join_domain("domain_name", "user", "password")
....

clone = vm.clone("New VM", template=True, ..., customize=custom)

Regards,

Sebastian


2012/4/14 Oddur Snær Magnússon <oddur.m...@gmail.com>

Oddur Snær Magnússon

unread,
Apr 25, 2012, 10:33:25 AM4/25/12
to pysp...@googlegroups.com, oddur.m...@gmail.com
I ended up doing this just via a data parameter.  So in a optional parameter called customize, you  specify [SYSPREP | SYSPREPTEST | LINUX]. Depending on what type of customization you want, you specify a different dictionary in the data parameter. 

The only assumption I'm making is that the VM has 1 network card which should get DHCP. 
defclone.txt

韩凌飞

unread,
Jan 14, 2016, 4:37:01 AM1/14/16
to pysphere, oddur.m...@gmail.com
thanks, but i don't can down the defclone.txt,can you send the defclone.txt to my mail: hanli...@163.com,Thank you very much!!!

在 2012年4月25日星期三 UTC+8下午10:33:25,Oddur Snær Magnússon写道:
Reply all
Reply to author
Forward
0 new messages