shaharsib
Enthusiast
Enthusiast

Get user DeployedVMCount and ID with REST API

Jump to solution

Hi,

Some background, I have some vra request in which I want to show current user quota on the request menu.

Now,

1. How can I find list of users no matter from what organization ? (the id from question 2 I found with powershell - not with REST )

2. I`m trying to get user DeployedVMCount and StoredVMCount via REST API

    but all I can find is StoredVMQuota and DeployedVMQuota with REST API

    with this command

$ curl -i -k -H "Accept:application/*+xml;version=31.0" -H "x-vcloud-authorization:1xxxxxxxxxxxxxxx4ed2" 
                      -X GET
https://My-VCD_URL/api/admin/user/03889ec7-839d-41a8-bc8b-91de96884c63
     

which returns:

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

<User xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vmw="http://www.vmware.com/schema/ovf" xmlns:ovfenv="http://schemas.dmtf.org/ovf/environment/1" xmlns:vmext="http://www.vmware.com/vcloud/extension/v1.5" xmlns:ns9="http://www.vmware.com/vcloud/versions" name="firstName" id="urn:vcloud:user:03889ec7-839d-41a8-bc8b-91de96884c63" href="My-VCD-URL/api/admin/user/03889ec7-839d-41a8-bc8b-91de96884c63" type="application/vnd.vmware.admin.user+xml">

    <Link rel="edit" href="My-VCD-URL/api/admin/user/03889ec7-839d-41a8-bc8b-91de96884c63" type="application/vnd.vmware.admin.user+xml"/>

    <Link rel="takeOwnership" href="My-VCD-URL/api/admin/user/03889ec7-839d-41a8-bc8b-91de96884c63/action/takeOwnership"/>

    <Link rel="rights" href="My-VCD-URL/api/admin/user/03889ec7-839d-41a8-bc8b-91de96884c63/grantedRights" type="application/vnd.vmware.vcloud.query.references+xml"/>

    <Link rel="rights" href="My-VCD-URL/api/admin/user/03889ec7-839d-41a8-bc8b-91de96884c63/entityRights" type="application/vnd.vmware.admin.entityReferences+xml"/>

    <FullName>Full Name</FullName>

    <EmailAddress>firstName@company.com</EmailAddress>

    <Telephone></Telephone>

    <IsEnabled>true</IsEnabled>

    <IsLocked>false</IsLocked>

    <IM></IM>

    <NameInSource>\5D\44\95\57\C7\B1\2D\43\B0\C3\5D\C2\6B\DA\A1\6B</NameInSource>

    <IsExternal>true</IsExternal>

    <ProviderType>INTEGRATED</ProviderType>

    <IsGroupRole>false</IsGroupRole>

    <StoredVmQuota>0</StoredVmQuota>

    <DeployedVmQuota>0</DeployedVmQuota>

    <Role href="My-VCD-URL/api/admin/role/db9d7415-8c80-3adc-a46d-02cae4da2a01" id="urn:vcloud:role:db9d7415-8c80-3adc-a46d-02cae4da2a01" name="Organization Administrator" type="application/vnd.vmware.admin.role+xml"/>

    <GroupReferences>

        <GroupReference href="My-VCD-URL/api/admin/group/71255492-830e-4e11-a7e6-72642968a8e7" id="urn:vcloud:group:71255492-830e-4e11-a7e6-72642968a8e7" name="all" type="application/vnd.vmware.admin.group+xml"/>

        <GroupReference href="My-VCD-URL/api/admin/group/4c09fa80-6a78-4c20-9c0a-2ba755c8ab4f" id="urn:vcloud:group:4c09fa80-6a78-4c20-9c0a-2ba755c8ab4f" name="vCD_Admins" type="application/vnd.vmware.admin.group+xml"/>

    </GroupReferences>

</User>

But the info I want doesnt show here...

help ?

1 Solution

Accepted Solutions
shaharsib
Enthusiast
Enthusiast

After long searching I have found the solution:

How to retrieve list of all users in your Cloud ?

Thanks.

View solution in original post

3 Replies
qc4vmware
Virtuoso
Virtuoso

I wrote this workflow to gather up all of the catalog resources per owner of type vm and put them in an easily manipulated object.  Maybe this will work for you?

// Get all hosts and load an array of all catalog items

var hosts = Server.findAllForType("vCACCAFE:VCACHost");

for each (var host in hosts) {

var catalogResources = vCACCAFEEntitiesFinder.getCatalogResources(host);

}

// create one entry per owner.  Some objects may have more than one owner

var xObj = [];

var allOwners = []; // index of unique owners maps to object array location

for each (var resource in catalogResources) {

if (resource.resourceTypeRef.getLabel() != "Virtual Machine") {continue;}

var vm = resource;

// get the parent deployment

var parentId = resource.parentResourceRef.getId();

for each (var host in hosts) {

var deployment = vCACCAFEEntitiesFinder.getCatalogResource(host, parentId) ;

if (deployment) break;

}

if (!deployment) {

System.error("No deployment found for request id: " + vm.requestId);

continue;

}

// if a subTenant filter is supplied check that this item lives there if not skip to the next item

if (subTenant) {

//System.debug(item.organization.getSubtenantLabel().toUpperCase() + "::" + subTenant.toUpperCase());

if (subTenant.toUpperCase() != deployment.organization.getSubtenantLabel().toUpperCase() ) { continue; }

}

var owners = deployment.owners;

var machine = {};

machine.name = vm.name

machine.catalogItem = {};

machine.catalogItem.id = deployment.catalogItem.getId();

machine.catalogItem.label = deployment.catalogItem.getLabel()

machine.costToDate = ((vm.costToDate) ? vm.costToDate.getAmount() : 0);

var costs = vm.getCosts();

machine.costs = {};

machine.costs.unit = ((costs) ? costs.getLeaseRate().getBasis().getUnit().toString() : "");

machine.costs.unitAmount = ((costs) ? costs.getLeaseRate().getBasis().amount : 0);

machine.costs.costAmount = ((costs) ? costs.getLeaseRate().getCost().amount : 0);

machine.dateCreated = deployment.dateCreated;

machine.description = vm.description;

machine.hasCosts = vm.hasCosts;

machine.hasLease = deployment.hasLease;

machine.id = vm.id;

machine.lastUpdated = vm.lastUpdated;

machine.organization = {};

machine.organization.tenant = deployment.organization.getTenantRef();

machine.organization.tenantLabel = deployment.organization.getTenantLabel();

machine.organization.subtenant = deployment.organization.getSubtenantRef();

machine.organization.subtenantLabel = deployment.organization.getSubtenantLabel();

machine.resourceTypeRef = {};

machine.resourceTypeRef.id = vm.resourceTypeRef.getId();

machine.resourceTypeRef.label = vm.resourceTypeRef.getLabel();

machine.status = vm.status.value();

machine.totalCost = vm.totalCost;

machine.vcoid = vm.vcoid;

for each (var owner in owners) {

var ownerId = owner.getRef().toLowerCase();

var ownerName = owner.getValue();

var ownerIndex = allOwners.indexOf(ownerId);

if (ownerIndex < 0) {  // new owner encountered add it to the index and create and empty object

allOwners.push(ownerId);

xObj.push({"ownerId" : ownerId,"ownerName" : ownerName,"machines" : []});

ownerIndex = allOwners.indexOf(ownerId);

}

xObj[ownerIndex].machines.push(machine);

}

}

return xObj;

0 Kudos
shaharsib
Enthusiast
Enthusiast

Hi,

thanks for your comment.

Im talking about vCD and not vRA...

even so I tried to change the code to work with vCD host with no luck.

0 Kudos
shaharsib
Enthusiast
Enthusiast

After long searching I have found the solution:

How to retrieve list of all users in your Cloud ?

Thanks.

View solution in original post