0

I’m using pyVmomi to deploy a VM from a template on vSphere, this woks ok, the new VM get the name I sent as parameter but I want that the DNS name \ hostname will be same as VM.
Is there a way to set the hostname when doing the actual clone ?
If not how can I do that after the new VM was created ?

Here is part of the code I'm using:

# RelocateSpec
relospec = vim.vm.RelocateSpec()
relospec.datastore = datastore
relospec.pool = resource_pool

# ConfigSpec
configSpec = vim.vm.ConfigSpec()
configSpec.annotation = "This is the annotation for this VM"

# CloneSpec
clonespec = vim.vm.CloneSpec()
clonespec.location = relospec
clonespec.powerOn = power_on
clonespec.config = configSpec

print ("cloning VM...")
task = template.Clone(folder=destfolder, name=vm_name, spec=clonespec)
wait_for_task(task)
Epligam
  • 741
  • 2
  • 14
  • 36

1 Answers1

1

I think you need a clonespec.customization (vim.vm.customization.Specification). You should be able to specify the hostname there somehow or other.

Oh, as far as I know VMware Tools must be installed for guest OS customization.

Hope that helps.

Mario Lenz
  • 634
  • 3
  • 8
  • Here's an example of the customization spec in use to do what you're wanting, starting at line 190: https://gist.github.com/snobear/8788977 – Kyle Ruddy Dec 26 '17 at 16:07