Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting computer name (host name) dynamically when cloning a VM #748

Open
gilmatok opened this issue May 1, 2024 · 2 comments
Open

Setting computer name (host name) dynamically when cloning a VM #748

gilmatok opened this issue May 1, 2024 · 2 comments

Comments

@gilmatok
Copy link

gilmatok commented May 1, 2024

Is your feature request related to a problem? Please describe.

I cannot set the computer name (host name) when cloning a VM from a template, so the cloned VM always get the same computer name, which can cause issues with certain programs.

Describe the solution you'd like

There should be a way to set the computer name when cloning a VM.

Describe alternatives you've considered

I've looked at the VMWare documentation for CloneSpec, but I couldn't find anything related to that. The only thing I found was CustomizationSpec, but this refers to the network hostname, not the computer (OS) name

Additional context

No response

@prziborowski
Copy link
Contributor

I believe CustomizationSpec is what you are looking for.
In the identity parameter, if you pass in type vim.vm.customization.Sysprep, then the userData of type vim.vm.customization.UserData includes the computerName (of type vim.vm.customization.NameGenerator that has a few different subclass types).

@gilmatok
Copy link
Author

gilmatok commented May 27, 2024

@prziborowski thanks. I modified my cloning code to utilize these parameters however, the hostname still remains the same.

Here's my example:

       relospec = vim.vm.RelocateSpec()
        relospec.datastore = datastore
        relospec.pool = cluster.resourcePool
        if linked:
            relospec.diskMoveType = 'createNewChildDiskBacking'

        clonespec = vim.vm.CloneSpec()
        clonespec.location = relospec
        clonespec.powerOn = True

        cust_spec = vim.vm.customization.Specification()

        # Sysprep settings
        cust_spec.identity = vim.vm.customization.Sysprep()
        cust_spec.identity.guiUnattended = vim.vm.customization.GuiUnattended(
            autoLogon=True,
            autoLogonCount=1,
            password=vim.vm.customization.Password(value='Password1', plainText=True)
        )
        cust_spec.identity.userData = vim.vm.customization.UserData(
            fullName='gilmatok',
            orgName='Your Organization',
            computerName=vim.vm.customization.FixedName(name='gilmatok'),
        )

        cust_spec.identity.identification = vim.vm.customization.Identification(joinWorkgroup='WORKGROUP')

        # Network settings
        cust_spec.globalIPSettings = vim.vm.customization.GlobalIPSettings()    

        clonespec.customization=cust_spec
        if linked:
            clonespec.template = False
            clonespec.snapshot=source.snapshot.rootSnapshotList[0].snapshot

        dest_folder = self.get_folder(content, folder_name)

        task = source.Clone(folder=dest_folder, name=dest_name, spec=clonespec)
        if not self.wait_for_task(task):
            raise Exception(f'{"Link-clone" if linked else "Clone"} task of virtual machine "{dest_name}" encountered an error.')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants