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

CustomizationSpec management API wanted in govc CLI #984

Open
stainboy opened this Issue Jan 4, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@stainboy
Copy link

stainboy commented Jan 4, 2018

This issue will probably be a duplication of #616, but it explains the use case in a different way.

When using govc vm.clone, there is no way to pass dynamic CustomizationSpec. govc will always retrieve an existing spec from esxi/vcenter and try to use it, via --customization args.

Details can be found in the following code,

govc/vm/clone.go

// check if customization specification requested
if len(cmd.customization) > 0 {
	// get the customization spec manager
	customizationSpecManager := object.NewCustomizationSpecManager(cmd.Client)
	// check if customization specification exists
	exists, err := customizationSpecManager.DoesCustomizationSpecExist(ctx, cmd.customization)
	if err != nil {
		return nil, err
	}
	if exists == false {
		return nil, fmt.Errorf("Customization specification %s does not exists.", cmd.customization)
	}
	// get the customization specification
	customSpecItem, err := customizationSpecManager.GetCustomizationSpec(ctx, cmd.customization)
	if err != nil {
		return nil, err
	}
	customSpec := customSpecItem.Spec
	// set the customization
	cloneSpec.Customization = &customSpec
}

But there is no CustomizationSpec management API exposed by govc CLI, which means there is no way to dynamically create customSpec and then clone vm via the new created spec.

That's why I hope govc can have this nice feature in the future.

@dougm

This comment has been minimized.

Copy link
Member

dougm commented Jan 5, 2018

Yes, I like the idea of a vm.customize command: #616 (comment)

I still have yet to use customizations myself, any pointers would be appreciated, such as:

  • Simple OS template to test with (ideally automated via packer for example)
  • Any GUI screenshots that shows the manual workflow to define / apply customizations
@mylesagray

This comment has been minimized.

Copy link

mylesagray commented Jan 25, 2019

@dougm - I am using the Ubuntu cloud images OVAs for testing (16.04 as 18.04 has a cloud-init bug):

https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64.ova

govc import.spec ~/Downloads/ubuntu-16.04-server-cloudimg-amd64.ova | python -m json.tool > ubuntu.json

I customise the OVF spec as below, editing public-keys, Network and Name:

$ cat ubuntu.json
{
    "DiskProvisioning": "thin",
    "IPAllocationPolicy": "dhcpPolicy",
    "IPProtocol": "IPv4",
    "PropertyMapping": [
        {
            "Key": "instance-id",
            "Value": "id-ovf"
        },
        {
            "Key": "hostname",
            "Value": "ubuntuguest"
        },
        {
            "Key": "seedfrom",
            "Value": ""
        },
        {
            "Key": "public-keys",
            "Value": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB[[[[[MY PUBLIC KEY]]]]3OEWMRM4/PsqPS2t/VAL993OdSshHGtT30AP86G+vuHuecw== mylesg@vmware.com"
        },
        {
            "Key": "user-data",
            "Value": ""
        },
        {
            "Key": "password",
            "Value": ""
        }
    ],
    "NetworkMapping": [
        {
            "Name": "VM Network",
            "Network": "VM Network"
        }
    ],
    "MarkAsTemplate": false,
    "PowerOn": false,
    "InjectOvfEnv": false,
    "WaitForIP": false,
    "Name": "Ubuntu1604Template"
}

From there, import the OVA and mark as a template:

govc import.ova -options=ubuntu.json ~/Downloads/ubuntu-16.04-server-cloudimg-amd64.ova
govc vm.markastemplate Ubuntu1604Template

In VC I have a customisation spec created as below:

VM Spec1

VM Spec2

VM Spec3

VM Spec4

VM Spec5

VM Spec6

VM Spec7

Then to apply the customisation spec, you deploy a new VM from Template -> enable "Guest OS Customisation" and pick the Customisation Spec, from there it will prompt for any manually required inputs:

Deploy Template1

Deploy Template2

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