VMware Cloud Community
chiputaobutuput
Contributor
Contributor

Cannot customize host name

Error:

A specified parameter is  not correct: spec.identity.hostName

My hostName is normal:"pigtails"

[Code]

protected CustomizationSpec customizeVM(ManagedObjectReference vmRef, String ipAddress, String hostName)
    throws Exception {
        CustomizationSpec customsSpec = new CustomizationSpec();
        CustomizationAdapterMapping adapterMap = new CustomizationAdapterMapping();
        CustomizationIPSettings adapter = new CustomizationIPSettings();
        CustomizationFixedIp fixedIP = new CustomizationFixedIp();
        fixedIP.setIpAddress(ipAddress);
        adapter.setIp(new CustomizationIpGenerator());

        adapterMap.setAdapter(adapter);
        adapter.setIp(fixedIP);
        adapter.setSubnetMask("255.255.255.0");
        adapter.setDnsDomain("lss.emc.com");
        customsSpec
                .setNicSettingMap(new CustomizationAdapterMapping[] { adapterMap });
        customsSpec.setOptions(new CustomizationOptions());

        customsSpec.setGlobalIPSettings(new CustomizationGlobalIPSettings());

        //set hostname
        CustomizationLinuxPrep identity = new CustomizationLinuxPrep();
        CustomizationFixedName fixedHostName = new CustomizationFixedName();
        fixedHostName.setName(hostName);
        identity.setDomain("lss.emc.com");
        identity.setHostName(fixedHostName);
        System.out.println("fixedHostName.setName(hostName):"
                + fixedHostName.getName());

        customsSpec.setIdentity(identity);

        return customsSpec;
}

2 Replies
chiputaobutuput
Contributor
Contributor

Does anyone know about it?

I've searched around the forum and found no similiar situation, so I'm quite confused.

Nor do my hostname contain any special character like underscore.

vCenter just tell me my hostname is not correct and I really have no idea why can't I change the hostname.

PS: by default, vSphere will rename a cloned guest OS's hostname to the same name of its image name

Reply
0 Kudos
chiputaobutuput
Contributor
Contributor

I figured it out myself, post here for other's reference:

hostname cannot contain doc character, e.g. you cannot set hostname like "AtvChina.lss.emc.com". You need to set host name to 'AtvChina' and set domain name to 'lss.emc.com'.

the judgement is also fault: "vSphere will rename a cloned guest OS's hostname to the same name of its image name"

this is caused by empty host name of CustomizationSpec