Quantcast
Channel: VMware Communities : All Content - VMware vCenter™
Viewing all articles
Browse latest Browse all 24426

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

$
0
0

    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();


Viewing all articles
Browse latest Browse all 24426

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>