VMware Cloud Community
JamesMW
Enthusiast
Enthusiast
Jump to solution

Use vCO to change Virtual Machine Owner

Hello,

Has anyone discovered a way to change the owner of a VM thru vCO?

I can update the IaaS record with the new owner:

//Find the vCAC Owner Object

var modelName = 'ManagementModelEntities.svc';

var entitySetName = 'Users';

var filter = "indexof(UserName,'" + Owner + "') gt -1";

var orderBy = '';

var top = 1;

var skip = 0;

var headers = null;

var select = null;

var entity = vCACEntityManager.readModelEntitiesBySystemQuery(vCACHost.id, modelName, entitySetName, filter, orderBy, select, top, skip, headers);

System.log("User Name - " + entity[0].properties.get("UserName"));

//Setup new links

var links = {

  Owner: entity[0]

}

//Update VM with new Owner Link

var updateProperties = new Properties();

System.getModule("com


ibrary.vcac").updateVCACEntity(vCACHost.id, modelName, "VirtualMachines", vCACEntity.keyString, updateProperties, links, null);

Is there anyway to update this information in the CAFE database as well? The owner field on the custom resource object is read-only, and there is no method for setting the owner.

Thanks,

James

1 Solution

Accepted Solutions
JamesMW
Enthusiast
Enthusiast
Jump to solution

After some testing and investigating....I've figured it out. Basically, you need to update the owner link on the virtualmachine entity as posted earlier. You then need to kick off 2 workflow operations, UpdateMachineNotes and UpdateMachineOwner.

UpdateMachineNotes will update the VRMOwner field in vsphere, UpdateMachineOwner updates the CAFE DB (I'm assuming, have not tracked it all the way thru yet).

After creating the operation, you need to add 2 workflowoperationarguments to identify which VM to run the operation on, and the identity user for the operation.

The following code runs a UpdateMachineNotes operation:

//Global Variables

var modelName = 'ManagementModelEntities.svc';

var links = null

var headers = null;

//Create the workflow operation

System.log("Create operation.")

var entitySetName = 'WorkflowOperations';

var properties = {

   OperationName:"UpdateMachineNotes"

};

var operation = vCACEntityManager.createModelEntity(vCACHost.id, modelName, entitySetName, properties, links, headers);

//Setup variables for arugments

var entitySetName = 'WorkflowOperationArguments';

var links = {

  "WorkflowOperation":operation

}

//Create workflow argument 1

System.log("Create argument 1.")

var properties = {

   Name:"VirtualMachineId",

   Value:vCACVM.virtualMachineID.toString()

};

var argEntity1 = vCACEntityManager.createModelEntity(vCACHost.id, modelName, entitySetName, properties, links, headers);

//Create workflow argument 2

System.log("Create argument 2.")

var properties = {

   Name:"IdentityUser",

   Value:Owner

};

var argEntity2 = vCACEntityManager.createModelEntity(vCACHost.id, modelName, entitySetName, properties, links, headers);

The following code runs a UpdateMachineOwner operation:

var modelName = 'ManagementModelEntities.svc';

var entitySetName = 'WorkflowOperations';

var links = null

var headers = null;

var properties = {

   OperationName:"UpdateMachineOwner"

};

System.log("Create operation.")

var operation = vCACEntityManager.createModelEntity(vCACHost.id, modelName, entitySetName, properties, links, headers);

var entitySetName = 'WorkflowOperationArguments';

var links = {

  "WorkflowOperation":operation

}

System.log("Create argument 1.")

var properties = {

   Name:"VirtualMachineId",

   Value:vCACVM.virtualMachineID.toString()

};

var argEntity1 = vCACEntityManager.createModelEntity(vCACHost.id, modelName, entitySetName, properties, links, headers);

System.log("Create argument 2.")

var properties = {

   Name:"IdentityUser",

   Value:Owner

};

var argEntity2 = vCACEntityManager.createModelEntity(vCACHost.id, modelName, entitySetName, properties, links, headers);

Running an Owner link update, followed by these 2 operations, will do the exact same operations as clicking 'Edit' in the GUI would.

-James

Edit: The Owner variable, should be in the format of <username>@<domain>. vCACVM, is a IaaS  VM object. vCACHost is an IaaS vCAC host.

View solution in original post

1 Reply
JamesMW
Enthusiast
Enthusiast
Jump to solution

After some testing and investigating....I've figured it out. Basically, you need to update the owner link on the virtualmachine entity as posted earlier. You then need to kick off 2 workflow operations, UpdateMachineNotes and UpdateMachineOwner.

UpdateMachineNotes will update the VRMOwner field in vsphere, UpdateMachineOwner updates the CAFE DB (I'm assuming, have not tracked it all the way thru yet).

After creating the operation, you need to add 2 workflowoperationarguments to identify which VM to run the operation on, and the identity user for the operation.

The following code runs a UpdateMachineNotes operation:

//Global Variables

var modelName = 'ManagementModelEntities.svc';

var links = null

var headers = null;

//Create the workflow operation

System.log("Create operation.")

var entitySetName = 'WorkflowOperations';

var properties = {

   OperationName:"UpdateMachineNotes"

};

var operation = vCACEntityManager.createModelEntity(vCACHost.id, modelName, entitySetName, properties, links, headers);

//Setup variables for arugments

var entitySetName = 'WorkflowOperationArguments';

var links = {

  "WorkflowOperation":operation

}

//Create workflow argument 1

System.log("Create argument 1.")

var properties = {

   Name:"VirtualMachineId",

   Value:vCACVM.virtualMachineID.toString()

};

var argEntity1 = vCACEntityManager.createModelEntity(vCACHost.id, modelName, entitySetName, properties, links, headers);

//Create workflow argument 2

System.log("Create argument 2.")

var properties = {

   Name:"IdentityUser",

   Value:Owner

};

var argEntity2 = vCACEntityManager.createModelEntity(vCACHost.id, modelName, entitySetName, properties, links, headers);

The following code runs a UpdateMachineOwner operation:

var modelName = 'ManagementModelEntities.svc';

var entitySetName = 'WorkflowOperations';

var links = null

var headers = null;

var properties = {

   OperationName:"UpdateMachineOwner"

};

System.log("Create operation.")

var operation = vCACEntityManager.createModelEntity(vCACHost.id, modelName, entitySetName, properties, links, headers);

var entitySetName = 'WorkflowOperationArguments';

var links = {

  "WorkflowOperation":operation

}

System.log("Create argument 1.")

var properties = {

   Name:"VirtualMachineId",

   Value:vCACVM.virtualMachineID.toString()

};

var argEntity1 = vCACEntityManager.createModelEntity(vCACHost.id, modelName, entitySetName, properties, links, headers);

System.log("Create argument 2.")

var properties = {

   Name:"IdentityUser",

   Value:Owner

};

var argEntity2 = vCACEntityManager.createModelEntity(vCACHost.id, modelName, entitySetName, properties, links, headers);

Running an Owner link update, followed by these 2 operations, will do the exact same operations as clicking 'Edit' in the GUI would.

-James

Edit: The Owner variable, should be in the format of <username>@<domain>. vCACVM, is a IaaS  VM object. vCACHost is an IaaS vCAC host.