VMware vCloud

 View Only
  • 1.  How to change a name of an exsisting VM

    Posted Jul 15, 2013 02:29 PM

    I have a vApp with one vm I ned to change the name od the VM and the computer name of the VM, how can I achieve this via Java API?

    I have found examples for upgrade RAM, DISK, NETWORK but i'm missing an example for changing simple VM info like name, computer name, description.



  • 2.  RE: How to change a name of an exsisting VM

    Posted Jul 15, 2013 02:42 PM

    This is using the .NET SDK (and Rest) -- bu this is what we do today to change the computer name of a vm inside a vapp.  (vApp is powered off at the time)

    Hope this helps get you going...

    (code modified a little from what we really run as the code we have does much more)

    public void ModifyComputerNames(VM vm, string newName)

    {

        if (vm.GetGuestCustomizationSection() != null)

        {

            GuestCustomizationSectionType guestSection = vm.GetGuestCustomizationSection();

            //NOTE: the computer name in vCloud must be unique and less than 15 characters

            int maxLen = 15 - modifierText.Length;

            string computerName = newName;

            if (string.IsNullOrEmpty(computerName))

            {

                computerName = "VM";

            }

            if (computerName.Length > maxLen)

            {

                computerName = computerName.Substring(0, maxLen);

            }

            guestSection.ComputerName = computerName;

            vm.UpdateSection(guestSection);

        }

    }



  • 3.  RE: How to change a name of an exsisting VM
    Best Answer

    Posted Jul 15, 2013 02:58 PM

    Tnx @cfor

       

    I've just figured it out in java is similar, I had to digg a little in the api ... the documentation could improve a lot :smileywink:

    this is the code to modify the VM name and the computer name in JAVA

         VM vm = getVm(vapp);  //this is my method which returns a single VM from given vapp

         VmType vmType = vm.getResource();

         vmType.setName(newName);

         vm.updateVM(vmType).waitForTask(0);

          

         GuestCustomizationSectionType guest = vm.getGuestCustomizationSection();

         guest.setComputerName(newName);

         vm.updateSection(guest).waitForTask(0);



  • 4.  RE: How to change a name of an exsisting VM

    Broadcom Employee
    Posted Jul 18, 2013 07:51 PM

    If you're using v5.1 of the REST API, you can take advantage of the reconfigureVm action to change the name, Description, and other config details of a Vm. See Update Multiple Sections of a Virtual Machine



  • 5.  RE: How to change a name of an exsisting VM

    Posted Jul 19, 2013 01:14 PM

    I use the following way to change the name of VM via .NET SDK:

    vmref.name = "My Changed VM Name";

    Here vmref is the reference of the VM and then use the property as above to set the desired name of the VM.



  • 6.  RE: How to change a name of an exsisting VM

    Posted Mar 27, 2014 10:17 PM



    The tips described here get the job done if your objective is to change the computer name of the vm. 


    My objective is to change the virtual machine name.  In other words, the object is to modify the value of the <vssd:VirtualSystemIdentifier> tag in the following XML:


    <ovf:System>


    <vssd:ElementName>Virtual Hardware Family</vssd:ElementName>


    <vssd:InstanceID>0</vssd:InstanceID>


    <vssd:VirtualSystemIdentifier><span class="pln">SDP</span> </vssd:VirtualSystemIdentifier>


    <vssd:VirtualSystemType>vmx-09</vssd:VirtualSystemType>


    </ovf:System>


    Changing it through the VirtualHardwareSection does not appear to work.


    Any thought?



  • 7.  RE: How to change a name of an exsisting VM

    Broadcom Employee
    Posted Mar 28, 2014 11:39 AM

    The VirtualSystemIdentifier is contained in the ovf:System element, as shown in this request fragment.

    --------------------------

    POST https://vcloud.example.com/api/vApp/vm-4/action/reconfigureVm

    Content-Type: application/vnd.vmware.vcloud.vm+xml

    ...

    <?xml version="1.0" encoding="UTF-8"?>

    <Vm ...>

       ...

       <ovf:VirtualHardwareSection ...>

          <ovf:Info>Virtual hardware requirements</ovf:Info>

          <ovf:System>

             <vssd:ElementName>Virtual Hardware Family</vssd:ElementName>

             <vssd:InstanceID>0</vssd:InstanceID>

             <vssd:VirtualSystemIdentifier>ABCDEFG</vssd:VirtualSystemIdentifier>

             <vssd:VirtualSystemType>vmx-07</vssd:VirtualSystemType>

          </ovf:System>

             ...

       </ovf:VirtualHardwareSection>

          ...

    </Vm>

    ---------------------------



  • 8.  RE: How to change a name of an exsisting VM

    Posted Mar 28, 2014 05:18 PM

    Thanks for the quick reply. I did exactly as you have described. The result was no good.

    Any way,  I have started a new discussion at How to change virtual machine name of a VM via VCloud Director API?