VMware Cloud Community
CalmCloud
Enthusiast
Enthusiast

Call Reconfigure action from VCO to change memory and cpu

Hi,

I have a requirement to call "Reconfigure" from VCO to change CPU and Memory. The workflow executed is "Request a resource action". I have a question about inputs to this request. One of the inpu parameter is "inputs" which is of composite type. It needs the following inputs. Where to get values for ""provider-Cafe.Shim.VirtualMachine.Reconfigure.PropertyBag",provider-Cafe.Shim.VirtualMachine.Reconfigure.Storages",:"provider-Cafe.Shim.VirtualMachine.Reconfigure.Networks".

"provider-operationId";

"provider-machineId";

"provider-MachineName";

"provider-Cafe.Shim.VirtualMachine.Reconfigure.PropertyBag";

"provider-Cafe.Shim.VirtualMachine.Reconfigure.Storages"

"provider-Cafe.Shim.VirtualMachine.Reconfigure.Networks"

"provider-Cafe.Shim.VirtualMachine.Reconfigure.Requestor";

"provider-Cafe.Shim.VirtualMachine.Reconfigure.ExecutionSelector"

"provider-Cafe.Shim.VirtualMachine.Reconfigure.PowerActionSelector"

"provider-Cafe.Shim.VirtualMachine.Reason";

"provider-Cafe.Shim.VirtualMachine.Reconfigure.CpuCount";

"provider-Cafe.Shim.VirtualMachine.Reconfigure.MemorySize"

:"provider-Cafe.Shim.VirtualMachine.Reconfigure.PropertyBag"

"provider-Cafe.Shim.VirtualMachine.Reconfigure.Storages"

:"provider-Cafe.Shim.VirtualMachine.Reconfigure.Networks"

Any help appreciated.

14 Replies
SeanKohler
Expert
Expert

I don't think you have to.  You just supply null values for them.  Here are the inputs for change owner through Reconfigure. (note I didn't supply any of the other properties in your list, but I am requesting a reconfigure action)  You should be able to do the Reconfigure binding ID (or full name which I don't recall at the moment, but isn't Reconfigure), the machine id, the machine name, and either CPU or Memory or both.

properties.jpg

properties2.jpg

It is unfortunate that you are using Reconfigure, though.  It is supporting bad behavior by VMware.  Smiley Happy  There is no security granularity to it.  (For example... allow a person to change CPU and Memory, but not Storage or Network... but STILL allow another person to do Network changes.) This led us to build each action as a separate resource action in ASD.  (The only of which doesn't work is change owner) 

Reply
0 Kudos
CalmCloud
Enthusiast
Enthusiast

I tried with passing the following arguments. The request is successful in VRA and VRA shows CPU count as '5' but nothing changed on the VM in vCenter.


"provider-operationId"= "Infrastructure.Machine.Action.Reconfigure";

"provider-machineId" = "7781df7c-964d-4eca-a162-9a83bc08f3d2";

"provider-MachineName" ="ABCXYZD01";

"provider-Cafe.Shim.VirtualMachine.Reconfigure.CpuCount" =  "5";

Reply
0 Kudos
SeanKohler
Expert
Expert

Interesting.  I actually have never heard that Reconfigure actually does change the VM in VC.  Can you verify that behavior by doing a Reconfigure in the GUI?  I am going to go play around with this a bit too.

We change it against VC and then run a data collection.  (so the other way from you)

This is because our Blueprints only have a MINIMUM set for CPU and Memory.  This makes the CPU and Memory unchangeable through the Reconfigure option. 

CalmCloud
Enthusiast
Enthusiast

It works from GUI.

If you pass all the parameters( captured parameter by submitting through GUI - makeRequest call has all the params)  then min and max does not apply. I was able to set CPU count higher than max set on the blueprint.

I will try second option i.e running data collection.Do you run "Force Data Collection" workflow?

Reply
0 Kudos
SeanKohler
Expert
Expert

Yeah... but I am not hopeful that will work.  There has to be something else that needs to be set in Reconfigure I think.

Reply
0 Kudos
CalmCloud
Enthusiast
Enthusiast

Made change  CPU/Memory on vCenter VM and called "Force data collection"...It worked. The only issue is "Force data collection" takes a while to complete. Now I am trying to figure out if data collection can be restricted to  object that was updated.

Reply
0 Kudos
SeanKohler
Expert
Expert

Refreshing VM CPU/Memory values in GUI as part of ASD action

Yeah if you figure it out, can you post it here and in Katherine's thread?

Reply
0 Kudos
SeanKohler
Expert
Expert

Hmmm... this actually may solve the need to do a data collection...

=======================================

I tried with passing the following arguments. The request is successful in VRA and VRA shows CPU count as '5' but nothing changed on the VM in vCenter.


"provider-operationId"= "Infrastructure.Machine.Action.Reconfigure";

"provider-machineId" = "7781df7c-964d-4eca-a162-9a83bc08f3d2";

"provider-MachineName" ="ABCXYZD01";

"provider-Cafe.Shim.VirtualMachine.Reconfigure.CpuCount" =  "5";

========================================

Make an ASD request that changes the memory through VC:VirtualMachine and then runs a Reconfigure supplying the values to correct configuration change.  This is kind of brilliant my friend.  Nice job!

Reply
0 Kudos
SeanKohler
Expert
Expert

Are you sure you saw the value changed on the Item?  I cannot replicate... can you verify?

request.jpg

Request is good... it has the value specified.

request1.jpg

The value didn't change...

request2.jpg

Reply
0 Kudos
CalmCloud
Enthusiast
Enthusiast

hmmm. You are right it is not changed in the machine. May be I might have looked in the request and got confused.

Reply
0 Kudos
SeanKohler
Expert
Expert

No worries.  Thank you very much for verifying and letting me know.

(One of the MANY reasons I like you is that you do this...)

Reply
0 Kudos
CalmCloud
Enthusiast
Enthusiast

The minimum datacollection that can be done is on a cluster. The following code does that. It is equivalent to triggering "inventory" on the cluster. The only issue the CPU/Memory changes are not reflected in VRA till data collection is complete.

InventoryDataCollection.png

/*

* The function triggers "inventory" Datacollection on the VM Cluster

*/

var cluster = vm.runtime.host.parent;

if (cluster.vimType != "ClusterComputeResource") { 

  throw "standalone Host" + cluster.vimType;

}

/*

* Get ClusterId for the cluster

*/

var modelName = 'ManagementModelEntities.svc';

var entitySetName = 'Hosts';

var filter = "HostName  eq '"+ cluster.name+"'";

var entities = vCACEntityManager.readModelEntitiesBySystemQuery(vcachost.id, modelName, entitySetName, filter, null, null,null, null, null);

var hostId = entities[0].getProperty("HostID");

/*

* Get id for "inventory"

*/

entitySetName = 'FilterSpecGroups';

filter = "FilterSpecGroupName eq 'inventory'";

entities = vCACEntityManager.readModelEntitiesBySystemQuery(vcachost.id, modelName, entitySetName, filter, null, null,null, null, null);

var filterSpecGroupId = entities[0].getProperty("FilterSpecGroupID");

/*

* Get filterspec for "vSphere" and "inventory"

*/

entitySetName = 'FilterSpecs';

filter =  "FilterSpecName eq 'vSphere'";

entities = vCACEntityManager.readModelEntitiesBySystemQuery(vcachost.id, modelName, entitySetName, filter, null, null,null, null, null);

for( i = 0;i < entities.length; i++){

  if( entities[i].getLink(vcachost,"FilterSpecGroup")[0].getProperty("FilterSpecGroupID") == filterSpecGroupId){

  var filterSpecID = entities[i].getProperty("FilterSpecID");

  break;

  }

}

/*

* Filter DataCollectionStatuses for the cluster, "vspehere" and "inventory"

* This should filter datastatuses to number of agents installed

*/

entitySetName = 'DataCollectionStatuses';

filter = null// Well filter does ot work here "EntityID eq '"+hostId+"'";

entities = vCACEntityManager.readModelEntitiesBySystemQuery(vcachost.id, modelName, entitySetName, filter, null, null,null, null, null);

var dataCollectionArray = new Array();

for( i =0; i < entities.length; i++){

  if( entities[i].getProperty("EntityID") == hostId ){

  if( entities[i].getLink(vcachost,"FilterSpec")[0].getProperty("FilterSpecID") == filterSpecID ){

  dataCollectionArray.push(entities[i]);

  }

  }

}

/*

* Trigger data collection

*/

entitySetName = 'DataCollectionStatuses';

for each (entity in dataCollectionArray) {

  var entityKey = entity.keyString;

  System.log("Updating entity with key: " + entityKey);

  var links = null;

  var headers = null;

  var updateProperties = {

  "LastCollectedTime":null

  };

  vCACEntityManager.updateModelEntityBySerializedKey(vcachost.id, modelName, entitySetName, entityKey, updateProperties, links, headers);

}

Reply
0 Kudos
SimonSparks_UK
Contributor
Contributor

You can optimise this workflow by removing the following lines:

/*

* Get id for "inventory"

*/

entitySetName = 'FilterSpecGroups';

filter = "FilterSpecGroupName eq 'inventory'";

entities = vCACEntityManager.readModelEntitiesBySystemQuery(vcachost.id, modelName, entitySetName, filter, null, null,null, null, null);

var filterSpecGroupId = entities[0].getProperty("FilterSpecGroupID");

/*

* Get filterspec for "vSphere" and "inventory"

*/

entitySetName = 'FilterSpecs';

filter =  "FilterSpecName eq 'vSphere'";

entities = vCACEntityManager.readModelEntitiesBySystemQuery(vcachost.id, modelName, entitySetName, filter, null, null,null, null, null);

for( i = 0;i < entities.length; i++){

  if( entities[i].getLink(vcachost,"FilterSpecGroup")[0].getProperty("FilterSpecGroupID") == filterSpecGroupId){

  var filterSpecID = entities[i].getProperty("FilterSpecID");

  break;

  }

}

/*

* Filter DataCollectionStatuses for the cluster, "vspehere" and "inventory"

* This should filter datastatuses to number of agents installed

*/

entitySetName = 'DataCollectionStatuses';

filter = null// Well filter does ot work here "EntityID eq '"+hostId+"'";

entities = vCACEntityManager.readModelEntitiesBySystemQuery(vcachost.id, modelName, entitySetName, filter, null, null,null, null, null);

and replacing them with this reduces your queries down from 3 to 1...

var strFilter = "FilterSpec/FilterSpecGroup/FilterSpecGroupName eq 'inventory' and FilterSpec/FilterSpecName eq 'vSphere'";

var arrVCACEntity = vCACEntityManager.readModelEntitiesBySystemQuery(objVCACHost.id, "ManagementModelEntities.svc", "DataCollectionStatuses", strFilter, null, null,null, null, null);

Reply
0 Kudos
SimonSparks_UK
Contributor
Contributor

Presumably you also have more than 1 cluster so you can replace these lines

var cluster = vm.runtime.host.parent;

if (cluster.vimType != "ClusterComputeResource") {

  throw "standalone Host" + cluster.vimType;

}

/*

* Get ClusterId for the cluster

*/

var modelName = 'ManagementModelEntities.svc';

var entitySetName = 'Hosts';

var filter = "HostName  eq '"+ cluster.name+"'";

var entities = vCACEntityManager.readModelEntitiesBySystemQuery(vcachost.id, modelName, entitySetName, filter, null, null,null, null, null);

var hostId = entities[0].getProperty("HostID");

with these lines

var strFilter = "IsCluster eq true and IsVRMManaged eq true";

var arrVCACEntity = vCACEntityManager.readModelEntitiesBySystemQuery(objVCACHost.id, "ManagementModelEntities.svc", "Hosts", strFilter, null, null,null, null, null);

for ( var i = 0; i < arrVCACEntity.length; i++ )

{

  var objVCACEntity = arrVCACEntity[i];

  var objProperties = objVCACEntity.getProperties();

  var strHostName = objProperties.get("HostName");

  var strHostID = objProperties.get("HostID");

  System.log(strHostName);

  System.log(strHostID);

}

Reply
0 Kudos