VMware Cloud Community
JonXXVIII
Contributor
Contributor
Jump to solution

vRA API - Assigning Storage Reservation Policies

Has anyone managed to use the API to allocate Storage Reservation Policies to a Storage Path via the vRA API? I can't seem to figure out where to set this.

The UI version of what I'm trying to do:

Infrastructure -> Edit Compute Resource -> Configuration -> Storage Path -> Drop-down to select Storage Reservation Policy.

The closest I've got is:


/reservation-service/api/data-service/schema/Infrastructure.Reservation.Virtual.vSphere/default/reservationStorages/values - gets me the datastores

/reservation-service/api/data-service/schema/Infrastructure.Reservation.Virtual.vSphere/default/computeResource/values - gets me the compute resources I need to edit


Any help appreciated.



0 Kudos
1 Solution

Accepted Solutions
Brian_Markussen
Enthusiast
Enthusiast
Jump to solution

Finally I got it solved. Credits to Milko for helping me.

I have created an action that uses a vSphere Cluster as input (Equal to the Compute Resource)

And a string containing the name of the Storage Reservation Policy

pastedImage_3.png

The action finds all the Storage Clusters and change the Storage Reservation Policy

var query = "HostName eq '" + vRaComputeResource.name + "'";
var computeResources = vCACEntityManager.readModelEntitiesBySystemQuery(vcacHost.id, "ManagementModelEntities.svc", "Hosts", query, null, null, null, null, null);

System.log("Found " + computeResources.length + " computeResources based on filter: " + query);

var query = "Name eq '" + newStorageReservationPolicy + "'";
var foundStorageReservationPolicies = vCACEntityManager.readModelEntitiesBySystemQuery(vcacHost.id, "ManagementModelEntities.svc", "HostStorageReservationPolicies", query, null, null, null, null, null);
if (foundStorageReservationPolicies.length == 1){
for each (computeResource in computeResources){
  var computeResourceToStorages = computeResource.getLink(vcacHost, "HostToStorages");
  for each (computeResourceToStorage in computeResourceToStorages){
   if  (computeResourceToStorage.getProperty("IsStorageCluster") == true){
    var newReservationPolicies = new Array;
    newReservationPolicies.push(foundStorageReservationPolicies[0]);

    var newStorageReservationPolicies = new Properties();
    newStorageReservationPolicies.put("HostStorageReservationPolicy", newReservationPolicies);
    var links = new Properties();
    links.put("HostToStorages", computeResourceToStorage);
    System.log("Compute Resource: " + computeResource.getProperty("HostName") + " *** Storage Cluster: " + computeResourceToStorage.getProperty("StoragePath") + " *** New Storage Policy: " + foundStorageReservationPolicies[0].getProperty("Name"));
    var emptyProps = new Properties();
    vCACEntityManager.updateModelEntityBySerializedKey(vcacHost.id, "ManagementModelEntities.svc", "HostToStorage", computeResourceToStorage.keyString, emptyProps, newStorageReservationPolicies, null);

   }
  }
}
}
else {
throw ("Storage Reservation Policy not found: " + newStorageReservationPolicy);
}

View solution in original post

9 Replies
GrantOrchardVMw
Commander
Commander
Jump to solution

Storage Policies are assigned at the Compute Resource, so you need to look at the iaas-proxy-provider API.

I can't see any function for it there. If you're doing this with vRO you can work with the Model Entity (I suspect, need to doublecheck).

Grant http://grantorchard.com
0 Kudos
JonXXVIII
Contributor
Contributor
Jump to solution

Thank you - I'm now busy hacking away at it and will report back.

0 Kudos
Brian_Markussen
Enthusiast
Enthusiast
Jump to solution

I have the same issue. Did you get a solution?

/Brian

0 Kudos
DanieleUlrich
Enthusiast
Enthusiast
Jump to solution

If you know how to do it on the vRA UI you can always use Chrome Dev Tools, Network Tab, to check which calls are performed.

In this case the HTML form gets posted to https://{vra-fqdn}/vcac/EnterpriseAdmin/EditHost.aspx?hostId={host-id}, so it's the very old IaaS stuff on .NET on the IIS web server.

I haven't found a replacement for this one, too.

btw: if somebody knows how to login to the IaaS Web Server to get all necessary cookies to use the console without using vRA, I would be very interested...

0 Kudos
daphnissov
Immortal
Immortal
Jump to solution

I bet jasnyder​ would like to pick that up as a challenge Smiley Happy

0 Kudos
jasnyder
Hot Shot
Hot Shot
Jump to solution

Unfortunately I don't think there is a way to do this through the API at the moment.  As the versions have increased, certain management abstractions have been put in place to put the management in the CAFE side vs. the IaaS side, but obviously some things haven't been moved yet.

That said, a potentially viable alternative may be to code what you need in a vRO workflow and call that through the vRO API from whatever your external source is.  I don't believe I've done this specific thing (setting storage res. policy on datastore of a compute resource) through vRO, but it should be possible using the highly convoluted entity model management API from the vCAC plugin.

If you go this route, you might consider putting the whole operation in a workflow and using a single API call to vRO to kick off the tasks you need to happen.  If you need outputs, just make them available as workflow outputs and consume it that way.

It is a little bit easier said than done, but I think it would work, and still gives you the flexibility to call an API to get the work done.

0 Kudos
Brian_Markussen
Enthusiast
Enthusiast
Jump to solution

I might have found a way of doing this, but I need some help.

The entity HostToStorage has a Linked Property to the HostStorageReservationPolicy. This is an array of HostStorageReservationPolicies that has zero og one entries. Either the Data Store of the  Compute Resource has a single Storage Reservation Policy assigned or  no Storage Reservation Policy is assigned.

The easy part is to extract the current StorageReservationPolicy of a HostToStorage (Compute Resource):

pastedImage_2.png

My problem is that I can't make changes to the "Linked Property": getLink(vcacHost, "HostStorageReservationPolicy"). I "just" has to change the value, but as it is a "getLink" and not a property I can't figure how to this.

Code snippet:

StorageReservationPolicy.png

P.S. I have tried to change value directly in the SQL databse and the Storage Reservation Policy i reflected in the vRA GUI.

pastedImage_11.png

Any help is most appreciated,

Brian

0 Kudos
Brian_Markussen
Enthusiast
Enthusiast
Jump to solution

Finally I got it solved. Credits to Milko for helping me.

I have created an action that uses a vSphere Cluster as input (Equal to the Compute Resource)

And a string containing the name of the Storage Reservation Policy

pastedImage_3.png

The action finds all the Storage Clusters and change the Storage Reservation Policy

var query = "HostName eq '" + vRaComputeResource.name + "'";
var computeResources = vCACEntityManager.readModelEntitiesBySystemQuery(vcacHost.id, "ManagementModelEntities.svc", "Hosts", query, null, null, null, null, null);

System.log("Found " + computeResources.length + " computeResources based on filter: " + query);

var query = "Name eq '" + newStorageReservationPolicy + "'";
var foundStorageReservationPolicies = vCACEntityManager.readModelEntitiesBySystemQuery(vcacHost.id, "ManagementModelEntities.svc", "HostStorageReservationPolicies", query, null, null, null, null, null);
if (foundStorageReservationPolicies.length == 1){
for each (computeResource in computeResources){
  var computeResourceToStorages = computeResource.getLink(vcacHost, "HostToStorages");
  for each (computeResourceToStorage in computeResourceToStorages){
   if  (computeResourceToStorage.getProperty("IsStorageCluster") == true){
    var newReservationPolicies = new Array;
    newReservationPolicies.push(foundStorageReservationPolicies[0]);

    var newStorageReservationPolicies = new Properties();
    newStorageReservationPolicies.put("HostStorageReservationPolicy", newReservationPolicies);
    var links = new Properties();
    links.put("HostToStorages", computeResourceToStorage);
    System.log("Compute Resource: " + computeResource.getProperty("HostName") + " *** Storage Cluster: " + computeResourceToStorage.getProperty("StoragePath") + " *** New Storage Policy: " + foundStorageReservationPolicies[0].getProperty("Name"));
    var emptyProps = new Properties();
    vCACEntityManager.updateModelEntityBySerializedKey(vcacHost.id, "ManagementModelEntities.svc", "HostToStorage", computeResourceToStorage.keyString, emptyProps, newStorageReservationPolicies, null);

   }
  }
}
}
else {
throw ("Storage Reservation Policy not found: " + newStorageReservationPolicy);
}

JonXXVIII
Contributor
Contributor
Jump to solution

Ah nice work! thank you for sharing Smiley Happy

0 Kudos