VMware {code} Community
nileshjais
Enthusiast
Enthusiast

Network configuration of VM after deploy from template

Hi All,

We have deployed the VM from template thanks to this discussion forum, Now we need to configure the new VM with all the network related configuration to bring the host live.

Do we have any Perl script which take care of such steps, any pointer should help us.?

Thanks,

Nilesh

48 Replies
stumpr
Virtuoso
Virtuoso

What sort of network related configuration?  Most of the network configuration can be done in your customization spec (either the vSphere Customization Spec or by setting the customization values during a CloneVM_Task).

If you need some more advanced interface configuration (such as ip aliases), then you may need to do some post-cloning automation with the GuestOperations object on the VM (assuming it has VMware Tools installed and running).

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
nileshjais
Enthusiast
Enthusiast

Thank you for the response. I think you got it perfectly right. I found similar script from VSphere forum ( Script need to deploy a VM from a template ) which does somewhat the same as per my requirement. But when i ran this script i got error message as below:

Deploying virtual machine from template surg649t  ...

FaultCannot serialize identity as CustomizationIdentitySettings at /usr/lib/perl5/5.8.8/VMware/VICommon.pm line 2432

ComplexType::serialize('CustomizationSpec=HASH(0x1bb1cfd0)', 'customization', 'undef') called at /usr/lib/perl5/5.8.8/VMware/VICommon.pm line 2439

ComplexType::serialize('VirtualMachineCloneSpec=HASH(0x1b715060)', 'spec') called at (eval 30) line 111

VimService::get_arg_string('VirtualMachineCloneSpec=HASH(0x1b715060)', 'spec', 'VirtualMachineCloneSpec') called at (eval 30) line 132

VimService::build_arg_string('ARRAY(0x180063a0)', 'HASH(0x18006320)') called at (eval 30) line 2923

VimService::CloneVM_Task('VimService=HASH(0x18dd42f0)', '_this', 'ManagedObjectReference=HASH(0x18f86d20)', 'spec', 'VirtualMachineCloneSpec=HASH(0x1b715060)', 'name', 'surg649_new', 'folder', 'ManagedObjectReference=HASH(0x190a13b0)', ...) called at /usr/lib/perl5/5.8.8/VMware/VICommon.pm line 1693

ViewBase::invoke('VirtualMachine=HASH(0x18f26940)', 'CloneVM_Task', 'spec', 'VirtualMachineCloneSpec=HASH(0x1b715060)', 'name', 'surg649_new', 'folder', 'ManagedObjectReference=HASH(0x190a13b0)') called at (eval 39) line 201

VirtualMachineOperations::CloneVM_Task('VirtualMachine=HASH(0x18f26940)', 'spec', 'VirtualMachineCloneSpec=HASH(0x1b715060)', 'name', 'surg649_new', 'folder', 'ManagedObjectReference=HASH(0x190a13b0)') called at (eval 39) line 207

VirtualMachineOperations::CloneVM('VirtualMachine=HASH(0x18f26940)', 'folder', 'ManagedObjectReference=HASH(0x190a13b0)', 'name', 'surg649_new', 'spec', 'VirtualMachineCloneSpec=HASH(0x1b715060)') called at /opt/vmware-vsphere-cli-distrib/apps/vm/template2vm.pl line 263

        eval {...} called at /opt/vmware-vsphere-cli-distrib/apps/vm/template2vm.pl line 262

main::deploy_template() called at /opt/vmware-vsphere-cli-

Don't know what is missing here.

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso

Looks like something with the format of the CustomizationIdentitySettings.  I'm not sure which script you are using, can you post it here?  I looked at the one linked from the other forum post, but line 262 where the error occurs doesn't look right for the error message.  I'm guessing it's a different script.

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
nileshjais
Enthusiast
Enthusiast

Here is the script which i am using? Please advise me if any thing is missing in this script which needs attention.

I need to valuable input and help.

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso

What are your run options?  (you can mask the password/username/server url)

Also, is this is a windows or linux clone?

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
nileshjais
Enthusiast
Enthusiast

Here are my run option.

template2vm.pl  --server dev-vcenter1.company.com --credstore ~/.vmware/credstore/vicredentials.xml --sourcevm surg649t --dnsdomain company.com --gateway <ip address> --dnsservers <ip address> --netmask 255.255.255.0 --vmhost sesxdp04.company.com  --ipaddress <ip address> --vmname surg649_new --datastore pdvnx_pool01_LUN_91 --resourcepool private-cloud

Presently i am trying this for linux but later we need to do this for windows as well, so you can assume its for both. Do you see anything missing or script requires any changes. got stuck ....please help

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso

It was a scope issue, the linux prep was being rescoped with my in the elsif block and getting undef in your customization.

Try the attached version.  However, from the code looks like it will only work for RHEL5_64Guest, so it would need more modification to support additional linux guest os types.

Reuben Stump | http://www.virtuin.com | @ReubenStump
nileshjais
Enthusiast
Enthusiast

Thanks a lot ... you have been fantastic on this ... will try this script and get back to you. Yeah you are right this script can only perform RHEL5_64Guest, as we start using other platform we will keep on enhancing the script.

Reply
0 Kudos
nileshjais
Enthusiast
Enthusiast

Hi Stumpr,

I used the script after over few hickups i was able to deploy VM.

Following was observation:

1. After deploying VM took some time to bring the machine into network is it expected behavior? , using vminfo.pl we tried to get details of new VM, initially it didn't show any details but after some time it shows the details. does it requires reboot or start of the services. we did restart of network services after which we were able to see the details of vminfo.pl

2. /etc/resolve.conf was not having entries of primary dns and secondary dns.

Does it requires any more configuration changes.

Thanks in advance.

Regards,

Nilesh

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso

VMware Tools information such as the Guest Disks, IP Addressing, etc will not be available until VMware Tools is running (the VM is fully booted).  Some of the other information should be available, however.

In terms of the /etc/resolv.conf, looks like the script you provided doesn't really support Linux name servers properly.  It's being set on the nic level, not the global level as Linux requires.

I made a change (but didn't test it).  Basically, for Linux you need to set your dns servers in the CustomizationGlobalIPSettings (line 469 in this script).  I added the dnsServerList there.  I believe that this will work just fine on both Windows and Linux (but please test).  However, for Linux, you have to do your dns servers here, you can't do them on the NicAdapter level as the script was doing before my edit.

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
nileshjais
Enthusiast
Enthusiast

The script which you attached and the one which i sent, i don't see any difference hence i am not able to figure out the changes you made. because the dnsServerList is also present in my copy of script?  Please let me know if i am missing something here.

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso

No, you're absolutely right.  I accidentally attached the older script version.  Here's the correct version.  Sorry about that.

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
nileshjais
Enthusiast
Enthusiast

Thank you !! That's looks changed one will test it. One more request Do you have script which will add vmdisk to add to a VM or reference will also help. I got the one script http://communities.vmware.com/docs/DOC-11213, But it reports datastore not find. looks like old script, do you have better script than this, also it does not take size of disk which we needed.

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso

That should work, if it's not finding the datastore could be a permission issue.  The same process applies, you just call ReconfigVM_Task() with the new disk configuration.

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
nileshjais
Enthusiast
Enthusiast

Dear Stumpr,

We also have vdiskcreate.pl in vSphere SDK which i guess does same task of adding vm disk to vm. But using this script gave me error as below.

./vdiskcreate.pl --datacenter <data centername> --server <servername.company.com> --disksize 10000 --filename test.vmdk --pool private-cloud --vmname test --username <username>

Can't call method "key" on an undefined value at ./vdiskcreate.pl line 112.

Looks like line # 112

my $controller = VMUtils::find_scsi_controller_device(vm => $_);

      my $controllerKey = $controller->key;

Do you have any comments for the same?

Your suggestion have help me a lot you are great.

Reply
0 Kudos
nileshjais
Enthusiast
Enthusiast

I have used your updated file and now its adding entry in /etc/resolve.conf, one question if i want to add "search ss.company.com company.com" entry in resolve.conf then which data object should i used this will help us resolving machine name with ip address, else we may need to refer IP address instead of VM name.

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso

You should be able to add it to the CustomizationGlobalIPSettings->dnsSuffixList array in your CustomizationSpec.  If you're still using that script tool, I think they may have put them in the wrong place (Windows systems use the dnsSuffixList per adapter, not CustomizationGlobalIPSettings).

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
stumpr
Virtuoso
Virtuoso

For the disk controller error, it would look like the controller id requested doesn't exist (would have to be created). 

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
nileshjais
Enthusiast
Enthusiast

How to create controller id request? Also once the disk is added we observe that attached disk are not usable directly, hence require following steps manually, we need to create volume group and then mount the disk to scratch in Linux and In windows we need to format the disk d: to make it usable state. Also requires reboot of machines. if we can do these steps in automated way it help us in long run to deploy multiple VM in future. Can we do all these step using SDK perl script if yes could you please provide me how to do this. I am attaching the script i am using. Also the script which find the controller id.

Reply
0 Kudos