VMware Cloud Community
zhenmie365
Contributor
Contributor

helpful! customizing the vm when deploying vm by template occurred error using the vijava api!

    I want to change ip in vm when deploying it from the template(I used windows 2008R 64 bit template),so I planned to use the method customizeVM_Task() at first,but it failed for method chechCustomizationSpec() deny.

     then I used method cloneVM_Task() with the param CustomzationSpec,it done! but after vm cloned,vm startup once ,no configuration customized. And about one minutes later ,vm reboot itself !! weird! With the customization startup. Then the error about "Microsoft-Windows-Shell_setup" come out!

     helpful!! Is there anyone can tell me what's the problem ?

     my code is following  and the picture of the error is in the accessory :

          CustomizationSpec cspec = new CustomizationSpec();

            CustomizationGlobalIPSettings gIP = new CustomizationGlobalIPSettings();

            cspec.setGlobalIPSettings(gIP);

// This is windows so choose the sysprep

            CustomizationSysprep sprep = new CustomizationSysprep();

            CustomizationGuiUnattended guiUnattended = new CustomizationGuiUnattended();

            guiUnattended.setAutoLogon(false);   // do not autoLogin on reboot for customization.

            guiUnattended.setAutoLogonCount(0);  // do not autologin on reboot..

            guiUnattended.setTimeZone(4);  // set to Eastern time.

            sprep.setGuiUnattended(guiUnattended);

            // add VM to WORKGROUP

            CustomizationIdentification identification = new CustomizationIdentification();

            identification.setJoinWorkgroup("WORKGROUP");

            sprep.setIdentification(identification);

            String productId = vm.getSummary().getConfig().getGuestId();   // only needed for windows os's

// setup UserData

            CustomizationUserData userData = new CustomizationUserData();

            CustomizationFixedName n = new CustomizationFixedName();

            n.setName(name);

            userData.setComputerName(n);

            userData.setFullName("SomeName");  // This may change in the future

            userData.setOrgName("SomeOrganization");

            userData.setProductId(productId);  // Product Serial (needed for Windows 2003 and 2008)

            sprep.setUserData(userData);

            cspec.setIdentity(sprep);

           

            // NicSettingMap part

            CustomizationAdapterMapping adaptorMap = new CustomizationAdapterMapping();

            CustomizationIPSettings adapter = new CustomizationIPSettings();

            CustomizationFixedIp fixedIp = new CustomizationFixedIp();

            adapter.setDnsServerList(dnsList);

            adapter.setGateway(gatewayList);

            fixedIp.setIpAddress(ipAdd);

            adapter.setIp(fixedIp);

            adapter.setSubnetMask(subnetMask);

            adaptorMap.setAdapter(adapter);

            CustomizationAdapterMapping[] nicSettingMap = new CustomizationAdapterMapping[]{adaptorMap};

            cspec.setNicSettingMap(nicSettingMap);

            CustomizationWinOptions options = new CustomizationWinOptions();

            options.setChangeSID(true);

            options.setDeleteAccounts(false);

            cspec.setOptions(options);

            CustomizationSpecManager manager = si.getCustomizationSpecManager();

            cspec.setEncryptionKey(manager.getEncryptionKey());

  //clone vm from the template 

        VirtualMachineCloneSpec spec = new VirtualMachineCloneSpec();

        spec.setCustomization(cspec);

        VirtualMachineRelocateSpec relocSpec = new VirtualMachineRelocateSpec();

        ManagedObjectReference rpMor = ManagedObject.buildManagedObjectReference(rpNode);

        relocSpec.setPool(rpMor);

        spec.setLocation(relocSpec);

  spec.setPowerOn(false);

  spec.setTemplate(false);

Task task = vm.cloneVM_Task(folder, name,

  spec);

  String result = task.waitForMe();

Reply
0 Kudos
3 Replies
aneverov
VMware Employee
VMware Employee

Hi,

It's very important to understand why checkCustomizationSpec() fails - it's our internal validation which normally provides some useful hints. Could you please provide more info (related vpxd logs, error details)?

With regards to "Microsoft-Windows-Shell_setup", it seems like sysprep is not happy with the unattend.xml. You mentioned that the template is 64 bit, is the "guest OS type" also set to 2008R 64 bit?

Or maybe sysprep doesn't like the product key - could you try with an empty one?

Any special characters in ComputerName/FullName/OrgName?

Does using CustomizationDhcpIpGenerator instead of CustomizationFixedIp change something?

Thanks,

Andrii

/* Please remember to mark answer as 'helpful' or 'correct' such that other users know it can be used and people focusing on ‘unanswered’ questions can skip it. */
zhenmie365
Contributor
Contributor

Hi,

Thanks for your help!

I found the source of the failure from method checkCustomizationSpec(). Before it, I test finding the failure is "invalidRequest". than I tried changing every params to test the source. finally,I found it : the productId is wrong in the CustomizationUserData param.(I found the productId is "00477-OEM-8400101-10502") Then I corrected it and tested again. the code debugged successfully,but the vSphere client hinted the another error : fault.NicSettingMismatch.summary. (vpxd logs).

NicSetting code is following :

{

// NicSettingMap part

            CustomizationAdapterMapping adaptorMap = new CustomizationAdapterMapping();

            CustomizationIPSettings adapter = new CustomizationIPSettings();

            CustomizationFixedIp fixedIp = new CustomizationFixedIp();

            adapter.setDnsServerList(new String[] {"192.168.2.1"});

            adapter.setGateway(new String[] {"192.168.2.1"});

            fixedIp.setIpAddress("192.168.2.123");

            //CustomizationDhcpIpGenerator dhcpIp = new CustomizationDhcpIpGenerator();

            adapter.setIp(fixedIp);

            adapter.setSubnetMask("255.255.255.0");

            adaptorMap.setAdapter(adapter);

            CustomizationAdapterMapping[] nicSettingMap = new CustomizationAdapterMapping[]{adaptorMap};

            cspec.setNicSettingMap(nicSettingMap);

}

I also followed your advice using CustomizationDhcpIpGenerator instead of CustomizationFixedIp, but the error also come out.

I also checked other you mentioned. "guest OS type" is windows7Server64Guest. the  product key is empty. and the ComputerName/FullName/OrgName is made up of alphabet.


I found me as a pioneer in this solving problems of vsphere. But fortunately you help me  and give me advice. thanks very much!

Reply
0 Kudos
aneverov
VMware Employee
VMware Employee

Hi,

You're very welcome. Thanks for your patience.

How many NICs does your VM have? You need to create CustomizationAdapterMapping per each NIC. NicSettingMismatch fault normally means that the actual vs spec counts differ.

Thanks,

Andrii

/* Please remember to mark answer as 'helpful' or 'correct' such that other users know it can be used and people focusing on ‘unanswered’ questions can skip it. */
Reply
0 Kudos