0

I need to write script that run on linux and do the below:

Create VM from template. Set hostname and ip for the new VM based on user parameter.

I installed the perl sdk and run the below command

vmclone.pl --username "user" --password "passwd" --url ${VSPVERE_URL}/sdk/webService --vmhost myhost --vmname my_template --vmname_destination NEW_VM

My problem now is how I can connect via script to NEW_VM and update there the /etc/host file?

Thanks

1
  • Changing the host name and IP is OS-specific. You'll have to come up with the appropriate commands for your VM OS(es) and run the commands in each guest with e.g. the vmrun runProgramInGuest / runScriptInGuest commands.
    – nobody
    Sep 11, 2014 at 17:26

1 Answer 1

-1

As part of cloning a server using the VMware Perl API, there is an option to be able to change the server's hostname, independent of the new server's operating system. VMware tools must be installed on the template that you are cloning from. This is possible because VMware Tools knows how to customize the server.

See CloneVM_Task in the VMware docs.

For example, where $vmname is the hostname you want to give the server:

my $config_spec = VirtualMachineConfigSpec->new(
    name => $vmname,
    memoryMB => 1024,
    numCPUs => 1);

my $clone_spec = VirtualMachineCloneSpec->new(
    powerOn => 0,
    template => 0,
    config => $config_spec);

$vmtemplate->CloneVM_Task(
    folder => $vm_folder_view,
    name => $vmname,
    spec => $clone_spec);

(Please note that there may be some required arguments that I have missed in my sample)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.