VMware Cloud Community
segadson
Contributor
Contributor
Jump to solution

VMDK Properties

I have an array of disks on a VM and I want to create a property set of Hard Disk Name and Hard Disk UUID.  But when I print out the properties set it only prints out the last Hard Disk Information Below is my code:

for each (var vmdkInfo in vmdkDisks){

input = vmdkDisks (array of vm disks (lets say 3))

var vmdkProperties = new Properties ();

  vmdkProperties.put("Hard Disk Name", vmdkInfo.deviceInfo.label);

  vmdkProperties.put("VMDK UUID", vmdkInfo.backing.uuid);

  }

System.log(vmdkProperties);


current output

</input-parameters><output-parameters>

<parameter scope="local" name="vmdkProperties" type="Properties">

<properties>

<property>

<key>Hard Disk Name</key>

<string>Hard disk 3</string>

</property>

<property>

<key>VMDK UUID</key>

<string>6000C298-eb25-7aab-86f8-423565cd28e9</string>

</property>

<property>

</properties>

but not the other 2 disks (Hard Disk 1 and 2)
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

There are 2 issues in your code:

1) var vmdkProperties = new Properties ();  should be moved before the 'for each' loop. Right now, you are trying to instantiate a new properties object in each loop iteration.

2) In each loop iteration, you put 2 new values (label and uuid) using the same keys. Putting a value with the same key during the next iteration will override the value you put during the previous iterations. Keys have to be unique.

Something like the following code should work:

var vmdkProperties = new Properties();

var uniquekey = 1;

for each (var vmdkInfo in vmdkDisks) {

  vmdkProperties.put(uniquekey++, {"Hard Disk Name":vmdkInfo.label, "VMDK UUID":vmdkInfo.uuid});

}

In the above sample:

  uniquekey++ 

generates a new unique value for each loop iteration (1, 2, 3, ...)

{"Hard Disk Name":vmdkInfo.label, "VMDK UUID":vmdkInfo.uuid}

creates a new Javascript object with 2 attributes ("Hard Disk Name" and "VMDK UUID") and assigns them the corresponding values.

View solution in original post

0 Kudos
3 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

There are 2 issues in your code:

1) var vmdkProperties = new Properties ();  should be moved before the 'for each' loop. Right now, you are trying to instantiate a new properties object in each loop iteration.

2) In each loop iteration, you put 2 new values (label and uuid) using the same keys. Putting a value with the same key during the next iteration will override the value you put during the previous iterations. Keys have to be unique.

Something like the following code should work:

var vmdkProperties = new Properties();

var uniquekey = 1;

for each (var vmdkInfo in vmdkDisks) {

  vmdkProperties.put(uniquekey++, {"Hard Disk Name":vmdkInfo.label, "VMDK UUID":vmdkInfo.uuid});

}

In the above sample:

  uniquekey++ 

generates a new unique value for each loop iteration (1, 2, 3, ...)

{"Hard Disk Name":vmdkInfo.label, "VMDK UUID":vmdkInfo.uuid}

creates a new Javascript object with 2 attributes ("Hard Disk Name" and "VMDK UUID") and assigns them the corresponding values.

0 Kudos
segadson
Contributor
Contributor
Jump to solution


Thank You so Much

0 Kudos
segadson
Contributor
Contributor
Jump to solution

Hello,

I had one more question for some reason I am unable to pull out those properties in to an array of values Do you know why that is?  I am only attempting to do this because for some reason when somebody is trying to do a getResult api call from a soap services it returns a hash like map of properties instead of a clean version like it does with a rest Call Do you know why that is?

0 Kudos