VMware Cloud Community
SeanKohler
Expert
Expert
Jump to solution

Cloning IaaS (VCAC) Reservations from VCO

Does anybody have a method to do this?

We have been looking at the solution provided here: https://communities.vmware.com/message/2396310

That does create a reservation, but it doesn't setup the storage, tag the network paths, assign network profiles, etc.  There is a clone option in the GUI that allows for setting a name and selecting a business group.  The clone then maintains everything that the source reservation had selected.

I have not been able to find where that might be exposed and haven't had much success working with VCACEntity type and VCACEntityManager scripting object.

Thanks for your consideration.

1 Solution

Accepted Solutions
SeanKohler
Expert
Expert
Jump to solution

Pretty much have the whole thing figured out end to end.

Decided to:

1. Use a Base Reservation as the "Golden Reservation".

2. Create a vRO element to hold the Base Reservation ID.

3. Bind it to a workflow that does a REST application/json GET of the data and outputs a string variable containing the response.

4. Create another workflow that calls the prior one and add a Script Task that takes a ReservationName and BusinessGroupID (subtenantRefId) Input and overwrites the output response of the prior workflow with a new variable output.

5. Run another newly created workflow that takes a string input and passes it to the reservation-service/api/reservations as a (serialized) POST.

This way the Base Reservation can be changed and when the clone workflow runs, it will be able to take the Golden Reservation's values versus supplying all of them as inputs.

I guess I would call this functional... but I would still prefer to have a direct Plugin API to the reservation service.  Give me a businessGroup.createReservationFromTemplate(reservationTypeObject) and life would be easy.  Smiley Happy

View solution in original post

Reply
0 Kudos
12 Replies
SpasKaloferov
VMware Employee
VMware Employee
Jump to solution

HI,

I can't find direct way in the API to clone all the settings you want. I guess you can try the same which was done in the post you mentioned: Check the  Reservation object with LinqPad and check all the linked objects

Some useful links:

http://www.vcoteam.info/images/phocagallery/vcacvm-relationships.png

http://www.vcoteam.info/articles/learn-vco/269-working-with-vcloud-automation-center-infrastructure-...

Best Regards / Поздрави

Spas Kaloferov | Technical Solutions Architect

SeanKohler
Expert
Expert
Jump to solution

So I am back looking into Setting up a reservation programmatically.  Supposedly 6.2 has some extended capabilities via REST to create a Reservation.  I am presently looking through the API documentation to see how to format the request/call.  If anybody is feeling friendly and has a request/tutorial worked out already... please share if you can.

Otherwise, I will post what I can here... provided I can get it figured out.

Regards,

Sean

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

Pretty much have the whole thing figured out end to end.

Decided to:

1. Use a Base Reservation as the "Golden Reservation".

2. Create a vRO element to hold the Base Reservation ID.

3. Bind it to a workflow that does a REST application/json GET of the data and outputs a string variable containing the response.

4. Create another workflow that calls the prior one and add a Script Task that takes a ReservationName and BusinessGroupID (subtenantRefId) Input and overwrites the output response of the prior workflow with a new variable output.

5. Run another newly created workflow that takes a string input and passes it to the reservation-service/api/reservations as a (serialized) POST.

This way the Base Reservation can be changed and when the clone workflow runs, it will be able to take the Golden Reservation's values versus supplying all of them as inputs.

I guess I would call this functional... but I would still prefer to have a direct Plugin API to the reservation service.  Give me a businessGroup.createReservationFromTemplate(reservationTypeObject) and life would be easy.  Smiley Happy

Reply
0 Kudos
schistad
Enthusiast
Enthusiast
Jump to solution

Hey Sean,

Would you mind posting your actions / workflows here? I am trying to get the exact same thing done, and this would save me some wall head butting Smiley Happy

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution


Well... the way that I wrote it isn't version dependent, but I suspect there is a much easier way to do it once you are on the vRA 6.2 plugin in vRO.  See I am running vRA 6.2.x with the VCAC 6.1.x plugin on VCO 5.5.x.  I won't go into the reasons why... but let's just go with a need for release stability and the things the upgrades broke outweighed the need to upgrade.

We are upgrading our Lab environment to the latest (with a hotfix for broken resource actions) tomorrow (6.2.1 across the board).

What I have discovered is that there are a couple of different ways to handle REST calls from the plugins in VCO (vRO).  I will call one the easy way... and the other the hard way.

-------------------------------------

THE EASY WAY

-------------------------------------

The easy way leverages the vCAC (vRA) plugin's coded REST access through the cafeHost.createRestClient(SERVICE) method.  You just supply the SERVICE you want to connect to and you can do a POST, GET, DELETE... as you see fit.  The benefit to this... why this is the EASY way... is all the authentication and authorization has been done for you based on the plugin.  You do not have to get a BEARER key for authorization.  You just run a set of methods to do you work and voila.

I put together an instructional workflow for my team that shows how this is done...

-----------------------------------------------------------------------------------------------

//only variable is a cafeHost (vCACCAFE:VCACHost)

// Parameterized Variables


var restJSON = {
//Place Your REST from Firebug Here
//You will need to parameterize some items like user and catlog item
//you can hardcode any values  (like if you want to just call one catalog item and know the ID
}

// you have to serialize the request due to how the plugin is created
restJSON = System.getModule("org.dojotoolkit.dojo.json").serialize(restJSON);


//There are only a few services that are defined that you can POST to or GET from
//If you are not using these services, you have to set up a REST host to do this work
// Catalog Requests go through the CATALOG_SERVICE.  So that is the primary one we would use.
// All Current Services (6.1)
// ADVANCED_DESIGNER_SERVICE, APPROVAL_SERVICE, AUTHENTICATION_SERVICE, AUTHORIZATION_SERVICE
// CATALOG_PROVIDER_SERVICE, CATALOG_SERVICE, EVENT_LOG_SERVICE, NOTIFICATION_SERVICE, WORK_ITEM_SERVICE

var catalogRest = cafeHost.createRestClient(vCACCAFEServicesEnum.CATALOG_SERVICE);
var response = catalogRest.post("consumer/requests",restJSON); // this is a post but gets are possible too
System.log(response);

------------------------------------------------------------------------------------

If you look at the bolded items above... those are the services.  You see one that is missing? How about the RESERVATION_SERVICE?  Yeah so in the 6.1 plugin it didn't exist because in 6.1 VCAC there were no REST capabilities for Reservations.  That became available in 6.2.  So what I suspect... if you are running the latest 6.2 plugin, you will see one more service usable by that "createRestClient(SERVICE) method off of the cafeHost.  And if that is true... then all you would need to do is do a JSON GET against a GOLDEN reservation, modify it through script/string manipulation, and then POST it back to the REST service top level and it will create a new reservation.  Depending where you are on the road of scripting these things, that may seem complicated... but once the light bulb goes off... you will see it is relatively straightforward.

---------------------------------------------

THE HARD WAY

---------------------------------------------

I am an impatient FOOL for doing it this way.  You should TOTALLY do it this way, too.  Smiley Happy  Actually... you should do it the easy way found above.

The hard way doesn't use the VCAC (vRA) plugin.  It uses the REST plugin and treats vRA 6.2 as just a normal REST endpoint.  I had to build custom helpers as the REST helpers in the plugin are overly complicated for what I needed to do.  (which was to have workflows that behave like the methods built out in the vRA 6.2 plugin).

1.  You need a ticket to ride with REST services.  For VRA, that means reaching out to the identity appliance to get a BEARER Key.  Be careful productionalizing this method... break it out into a helper that can be replaced later if VMware should decide to change their authentication provider.  Also be careful with the ticket because if it is intercepted, a malicious party can use it to impersonate.

2. You need to use your bearer token when you reach to a Service to GET the data you want as your baseline  (e.g. your golden reservation).  The GET payload.

3. You need to use your bearer token when you reach out to a Service to POST the data you want to create (e.g. your new reservation). The POST payload.

Each of those is a workflow built out as a helper in my environment.  So then I can get access, get my data, edit it through scripting, and finally post my data.... from any service.  (add a Delete and Update workflow for full CRUD-ness)

I can show you a picture of this  (which includes a custom action to get Provisioning Groups... a faster way to get Business Group Name or ID).... but I cannot share the full workflows publicly at this time.

restReservation.jpg

For the JSON edit... I just do a pretty standard Array load, change values, and then put the array back into a string.  (of course I am doing it completely wrong -positional awareness-... some better developer would say... but it works). The script I can show you for reference as you need to be able to edit JSON strings no matter what you do... from a REST call perspective.

----------------------------------------------------------------------

var jsonArray = new Array();
var newJson ="";

//System.log(jsonResponse); // came from the GET.. the golden reservation
//System.log(provGroupId); // came from an action that looked up the Business group ID using faster provisioning group
//System.log(provGroup); // the name of the Business Group

jsonArray = jsonResponse.split(",");
/*
for each (statement in jsonArray){
System.log(statement);
}
*/
jsonArray.shift(); // take off ID
jsonArray[0] = '{"name":"'+ provGroup + ' Base Reservation"'; // setup name correctly
jsonArray[3] = '"subTenantId":"'+provGroupId+'"'; // set correct Business Group
jsonArray[5] = '"priority":1'; // Set priority to 1

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

newJson = newJson.concat(jsonArray[i],",");

}
jsonPayload = newJson.slice(0,(newJson.length-1));

System.log("Payload =" + jsonPayload);

schistad
Enthusiast
Enthusiast
Jump to solution

Wow, awesome reply - thank you very much. I'll start digesting your answer presently. :smileylaugh:

Reply
0 Kudos
schistad
Enthusiast
Enthusiast
Jump to solution

Hmm, slightly bad news I'm afraid - vRA 6.2 does not appear to expose the reservation service in 6.2 either 😕

var rsrvRest = cafehost.createRestClient(vCACCAFEServicesEnum.RESERVATION_SERVICE);

InternalError: 404 Not Found (Workflow:Start Session / Scriptable task (item2)#260(eval)#1)

This is version 6.2, plugin build numbers

vCAC Infrastructure Administration 6.2.0.2210392

vCloud Automation Center 6.2.0.2287231

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

Bummer.... I guess I get more miles out of the Hard Way.

Can you look here?  (search for vCACCAFEServicesEnum)  I guessed on the service name... maybe it is just called something else.

restReservation2.jpg


Reply
0 Kudos
schistad
Enthusiast
Enthusiast
Jump to solution

Still only those same 9 services, I'm afraid Smiley Sad.

Reply
0 Kudos
SeanKohler
Expert
Expert
Jump to solution

Okay... thank you for looking.

Let me know if you hit any walls with the other way, and please share if you come up with something new and better.

~Sean

Reply
0 Kudos
Craig_G2
Hot Shot
Hot Shot
Jump to solution

Hmm schistad is right... It appears that the 6.2 plugin only has the following services available:

[2015-05-06 15:11:24.204] [I] com.vmware.csp.core.designer.service.api

[2015-05-06 15:11:24.204] [I] com.vmware.csp.core.cafe.approvals.api

[2015-05-06 15:11:24.204] [I] com.vmware.csp.cafe.authentication.api

[2015-05-06 15:11:24.204] [I] com.vmware.csp.cafe.authorization.api

[2015-05-06 15:11:24.205] [I] com.vmware.csp.core.cafe.catalog.api

[2015-05-06 15:11:24.205] [I] com.vmware.csp.core.cafe.catalog.api

[2015-05-06 15:11:24.205] [I] com.vmware.csp.cafe.eventlog.api

[2015-05-06 15:11:24.205] [I] com.vmware.csp.cafe.notification.api

[2015-05-06 15:11:24.205] [I] com.vmware.csp.core.cafe.workitem.api

I've been doing a similar thing to you.. Setting up a gold master template, then cloning it, but using python instead of vCO.

chelnak/vRAAPIClient · GitHub

I guess there are many ways to skin this cat... but it would be nice to have one in the vRA Plugin! 🙂

SeanKohler
Expert
Expert
Jump to solution

>>> but it would be nice to have one in the vRA Plugin!

Agreed.  This thread has some visibility.  Perhaps the powers that be can ensure 7 has REST methods for Reservations in the vRA plugin... we shall see.  There is always much to do.

Reply
0 Kudos