VMware {code} Community
SimonCigoj
Contributor
Contributor
Jump to solution

How to change a name of an exsisting VM

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.

Tags (1)
1 Solution

Accepted Solutions
SimonCigoj
Contributor
Contributor
Jump to solution

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 Smiley Wink

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

View solution in original post

Reply
0 Kudos
7 Replies
cfor
Expert
Expert
Jump to solution

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

    }

}

ChrisF (VCP4, VCP5, VCP-Cloud) - If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
SimonCigoj
Contributor
Contributor
Jump to solution

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 Smiley Wink

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

Reply
0 Kudos
srmdocs
VMware Employee
VMware Employee
Jump to solution

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

Reply
0 Kudos
sdeepak
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos
Cyren
Contributor
Contributor
Jump to solution



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?

Reply
0 Kudos
srmdocs
VMware Employee
VMware Employee
Jump to solution

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>

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

Cyren
Contributor
Contributor
Jump to solution

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?

Reply
0 Kudos