Start a Conversation

Unsolved

This post is more than 5 years old

1484

December 22nd, 2011 08:00

VMware SDK/ PERL

Hello everyone,

I would be eternally grateful if someone could help me to write a PERL script (cannot be Powershell) to achieve the metrics below. I have successfully managed to create the master_vm in a different script. See attached file. This script segment below will form the basis of a VDI project.

I have the master_vm created  -see attached but I cannot seem to use the clone VM task.

My attempt at writing this code segment is also attached but as is evident I am nowhere near completion.

 

Brian

Script to link-clone the master VM

To provide a virtual desktop for each user, I need to create one link-clone for each user, using the master VM as base.

The script should accept the following parameters:

master, required, but no default

vmsnumber, defaults to 1

The vmsnumber parameter will specify how many linked-clones your script will

have to create.

The script should perform the following steps:

  1. 1.  Locate the master VM
  2. 2.  Protect master’s base disks
  3. 3.  For each clone VM to be created:
  4. a.  Create the clone VM
  5. b.  Snapshot the clone VM to protect the master’s base disk

Locating the master VM

The master parameter will indicate the name of the master VM from which your script will create the linked clones, and should match the basename part of the name of the master VM (or, in other words, the script should add _master to the master option, and locate the VM that way).If the script can’t find the master vm, it should print a message of verbosity level 0 and exit.

Protect the Master’s base disks

The master VM must have 0 or 1 snapshots to continue:

   if it has 1, you should

o Print a message with verbosity level higher than 0, informing the admin that  you’re using the current snapshot (and include the name of the snapshot used).

        if it has more than 1 snapshot, you should

o print a message with verbosity level 0, informing the admin that the master  VM has X snapshots, and therefore the script can’t continue.

o exit

   If on the other hand the VM has no snapshots, you should

o Create a snapshot on the master VM. The name of the snapshot should  indicate that it is for a linked-clone base disk, while the description should let the administrator understand who created the snapshot (for example including the name of the script using

$0), the fact that the snapshot was added for the master’s base

disk and should not be removed before any other linked clone is removed, and include the date and time of the snapshot creation.

o print,  still  using  a  verbosity  level  higher  than  0,  a  message informing the administrator that you’ve created a snapshot on the master VM, and what is the snapshot name.

Create the clone VM(s)

At this point you can create the VMs from 1 to vmsnumber, each having the same hardware details as the master (so you’ll need to check the n. of CPUs, memory size and so on, since they are configurable), except for the disk:

each VM should not have a new disk, nor point to the same snapshot the master VM  has,  but point to the parent disk of the snapshot created on the master.

The name of the VM should be master_clone_X, where X is the sequential

number in the creation (so from 1 to vmsnumber), and master is the name provided by the user to identify the pool.

It is acceptable to let the script produce an error if any “clone” VM with the

same  master  already  exists  (that  is,  it  is  acceptable  not  to  handle  this situation).

Optionally, the script can detect this situation before starting creating VMs, calculate the new sequence number and deploy the requested clone VMs by adding to the existing pool. In  this  case  you  should  also  print  a  message,  using  a verbosity level above 0, indicating the re-sequencing.

Snapshot the VM

Once the clone VM is created, you should create a snapshot on it to protect the master’s base disk from being modified.

2 Attachments

6 Posts

December 22nd, 2011 10:00

Matt,

Thanks for your answer but William's script is based on having a vcentre server.

I dont. So William's script which is based on the clonevm_task will not work for me.

I need a workaround.

Brian

61 Posts

December 22nd, 2011 10:00

Brian,

This script, written a little by my and alot by a former colleague of mine (William Lam) will do much of what you need.  It very clearly demonstrates how to use the CloneVM_Task function to create Linked Clones:

http://download.virtuallyghetto.com/vGhettoLinkedClone.html

It does violate a few of your requirements, mostly around the snapshots, because you need a snapshot to base the Linked Clone off of.  You can't do it with 0 snapshots .

61 Posts

December 22nd, 2011 17:00

You're right, that functionality requires vCenter.

You're only other option would be to manually create a linked-clone VMDK (see the link I gave for what such a file looks like - you might be able to do it via the API), then manually create a new VM and attach the VMDK to it.

6 Posts

December 23rd, 2011 02:00

Matt,

If I create an add VMDK script and a snapshot script, could you take one look at it

Brian

6 Posts

December 27th, 2011 10:00

Thanks Matt. Would truly appreciate it\!

Brian

61 Posts

December 27th, 2011 10:00

I'd be happy to.

No Events found!

Top