VMware Cloud Community
CristiCalin
Contributor
Contributor
Jump to solution

vCloud API get used storage

I'm trying to figure out how to get the used storage of an organization using vCO.

There is the information regarding the storage profiles used from an Org-vDC, but that information only contains the limit.

My code looks like this:

for each (var vdc in org.getVdcs()) {

     for each (var profile in vdc.toAdminObject().getStorageProfiles()) {

          System.log(profile.toXml();

     }

}


In the XML dump I can only see the limit configured for that Org-vDC but not the consumption from that limit.

The information is present in the vCloud Web GUI, how can I get to that information from a code ?

Thanks,

Cristian

1 Solution

Accepted Solutions
Burke-
VMware Employee
VMware Employee
Jump to solution

LOL, bookmark this place, it will be a VERY valuable resource for you... now, as for your question, does this help?

This scriptable task takes a Provider VDC object as input:

System.log("============ Provider VDC: "+providerVdc.name+" ============");

System.log("NOTE: If allocatedMB = 0, then the org vdc has been configured for 'unlimited'");

var vdcs = providerVdc.getAdminVdcs();

var host = providerVdc.getHost();

for each (vdc in vdcs){

System.log("====== Processing Org VDC: "+vdc.name + " ======");

var queryService = host.getQueryService();

var profs = vdc.getStorageProfiles();

for each (var prof in profs) {

var expression = new VclExpression(VclQueryAdminOrgVdcStorageProfileField.HREF, prof.getReference().href , VclExpressionType.EQUALS);

var filter = new VclFilter(expression);

var params = new VclQueryParams();

params.setFilter(filter);

var resultSet = queryService.queryRecords(VclQueryRecordType.ADMINORGVDCSTORAGEPROFILE,params);

while (resultSet != null) {

var records = resultSet.getRecords(new VclQueryResultAdminOrgVdcStorageProfileRecord);

//System.log(records.length + " records found");

for each (var record in records) {

System.log("Storage Profile Name (usedMB/allocatedMB): " + record.name + " ("+record.storageUsedMB+"/"+record.storageLimitMB+")");

}

resultSet = resultSet.getNextPage();

}

}

System.log("");

}

// --------------------------- End code Snippet

Sample output:

[2013-03-21 12:27:03.553] [I] ============ Provider VDC: pVDC1 ============

[2013-03-21 12:27:03.554] [I] NOTE: If allocatedMB = 0, then the org vdc has been configured for 'unlimited'

[2013-03-21 12:27:03.763] [I] ====== Processing Org VDC: demo ======

[2013-03-21 12:27:03.859] [I] Storage Profile Name (usedMB/allocatedMB): Shared (0/409497)

[2013-03-21 12:27:03.861] [I]

[2013-03-21 12:27:03.863] [I] ====== Processing Org VDC: tiny ======

[2013-03-21 12:27:03.959] [I] Storage Profile Name (usedMB/allocatedMB): Local (1792/6144)

[2013-03-21 12:27:03.963] [I]

[2013-03-21 12:27:03.965] [I] ====== Processing Org VDC: CimVDC ======

[2013-03-21 12:27:04.016] [I] Storage Profile Name (usedMB/allocatedMB): Shared (231680/0)

[2013-03-21 12:27:04.020] [I]

March 21 at 12:29 pm

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter

View solution in original post

8 Replies
Burke-
VMware Employee
VMware Employee
Jump to solution

This thread should be moved/posted in the Orchestrator community for best targeted audience and accurate discussions Smiley Happy

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
CristiCalin
Contributor
Contributor
Jump to solution

done, though I think this is more related to vCloud API

0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

Hmm... you landed in the beta group, sorry for the confusion - I don't have admin rights to move this thread to the correct group, there is one that is only for Orchestrator here:

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
CristiCalin
Contributor
Contributor
Jump to solution

moved again

0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

LOL, bookmark this place, it will be a VERY valuable resource for you... now, as for your question, does this help?

This scriptable task takes a Provider VDC object as input:

System.log("============ Provider VDC: "+providerVdc.name+" ============");

System.log("NOTE: If allocatedMB = 0, then the org vdc has been configured for 'unlimited'");

var vdcs = providerVdc.getAdminVdcs();

var host = providerVdc.getHost();

for each (vdc in vdcs){

System.log("====== Processing Org VDC: "+vdc.name + " ======");

var queryService = host.getQueryService();

var profs = vdc.getStorageProfiles();

for each (var prof in profs) {

var expression = new VclExpression(VclQueryAdminOrgVdcStorageProfileField.HREF, prof.getReference().href , VclExpressionType.EQUALS);

var filter = new VclFilter(expression);

var params = new VclQueryParams();

params.setFilter(filter);

var resultSet = queryService.queryRecords(VclQueryRecordType.ADMINORGVDCSTORAGEPROFILE,params);

while (resultSet != null) {

var records = resultSet.getRecords(new VclQueryResultAdminOrgVdcStorageProfileRecord);

//System.log(records.length + " records found");

for each (var record in records) {

System.log("Storage Profile Name (usedMB/allocatedMB): " + record.name + " ("+record.storageUsedMB+"/"+record.storageLimitMB+")");

}

resultSet = resultSet.getNextPage();

}

}

System.log("");

}

// --------------------------- End code Snippet

Sample output:

[2013-03-21 12:27:03.553] [I] ============ Provider VDC: pVDC1 ============

[2013-03-21 12:27:03.554] [I] NOTE: If allocatedMB = 0, then the org vdc has been configured for 'unlimited'

[2013-03-21 12:27:03.763] [I] ====== Processing Org VDC: demo ======

[2013-03-21 12:27:03.859] [I] Storage Profile Name (usedMB/allocatedMB): Shared (0/409497)

[2013-03-21 12:27:03.861] [I]

[2013-03-21 12:27:03.863] [I] ====== Processing Org VDC: tiny ======

[2013-03-21 12:27:03.959] [I] Storage Profile Name (usedMB/allocatedMB): Local (1792/6144)

[2013-03-21 12:27:03.963] [I]

[2013-03-21 12:27:03.965] [I] ====== Processing Org VDC: CimVDC ======

[2013-03-21 12:27:04.016] [I] Storage Profile Name (usedMB/allocatedMB): Shared (231680/0)

[2013-03-21 12:27:04.020] [I]

March 21 at 12:29 pm

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
CristiCalin
Contributor
Contributor
Jump to solution

Yes, that is exactly what I need, I just need to figure out how to integrate this into my code.

Thanks,

Cristian

0 Kudos
CristiCalin
Contributor
Contributor
Jump to solution

What would be a situation where the query would return more than one record ?

I need to return a Properties object with the profile and the amount of free space and I'm trying to figure out if I need to build my object inside the while statement or outside and count the storageUsedMB inside the while loop.

0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

the query would return more than one record if you have multiple storage profiles associated with the vDC(s) being processed... My lab environment happened to only have one storage profile per Org vDC.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos