Sunday, August 16, 2015

REST while using CURL for vRA

irtualpatel.blogspot.com: REST while using CURL for vRA: DevOps needs REST :-) In DevOps world users are mostly using the command line and APIs to do almost all of their work. So for the foll...

REST while using CURL for vRA

DevOps needs REST :-)

In DevOps world users are mostly using the command line and APIs to do almost all of their work. So for the following example you’re going to need curl as the usage was done keeping in mind the universal tool and just not focusing other available large number of REST client or such, and as this is inside a Lab encryption is not needed bu you will need the version that supports SSL for end-to-end encryption !  

Use of jq, ( a new parsing tool for JSON) is used here, which does everything thro' command-line, and being portable (zero install) and open source, it runs on Windows and Linux both, so all of the developers out there can use it irrespective of the platform they’re using. I saved both utilities in C:\curl, and put my .bat file and .json files there too.  You can decide the best way to do that, Token is required.

So what is Token or a Bearer Token?  Putting it simply, its an authentication token.  First thing you’ll need is to get a bearer token and parse it.  You’ll need a .json file with your authentication details; the basic format is 

{“username”:”domain\\myusername“, “password”:”mypassword“, “tenant”:”vsphere.local”}.  

Fill in your username, password, and if you’re not using the default tenant, then save it to C:\curl\hellotoken.json and you’re good to go. 

Use the following curl command to submit your request:

curl –insecure -H “Accept: application/json” -H “Content-Type: 
application/json” –data @hellotoken.json https://vra-fqdn/identity/api/tokens > identity.json

Please note I used –insecure because my vRA environment is still using self-signed SSL certs.  If you have actual SSL certs that will validate, please drop the –insecure option.  This command will drop a .json file named identity.json in the current folder (c:\curl if you’ve been following along), the file looks a little like this:

{“expires”:”2015-07-08T18:47:58.963Z”,”id”:”long-token-goes-here“,”tenant”:”vsphere.local”}

So it has an expiry, an id, and a tenant. Bearer tokens are good for 24 hours, and what's not obvious is a user can only have one at a time; if you ask for a new bearer token, that invalidates all previous bearer token/s.  These two facts means, it’s very difficult to manually get and use a bearer token. What we want to do is extract that ID in such a way that we can automatically use it in subsequent curl calls.

For this I will be using jq:

jq .id -r < identity.json > bearer.txtset /p btoken=
)

Let’s look into what it consists of:

jq .id -r parse out the id field from the json.  Print it to stdout in raw mode (i.e. no surrounding quotes or symbols)

< identity.json use the previously generated identity.json file as input to jq

> bearer.txt output the parsed id field to a file bearer.txt

use bearer.txt as the input file for the following command

set /p btoken= set the environment variable btoken to the input.  The /p normally means to prompt for the environment variable, but in this case since we provided a stdin pipe, the contents of bearer.txt will be used instead of prompting the user

) Close the section using bearer.txt as input. Yes I know it is required to do it here. 

To use the bearer token add the following HTTP Header to all future curl calls:

-H “Authorization: Bearer %btoken%”

Machine Request

Now you can request the catalog item you want from the vRA console and note the request ID. After the request has completed, you can use curl to look at the request with the following command:

curl –insecure -H “Accept: application/json” -H “Authorization: Bearer %btoken%” https://vra-fqdn/catalog-service/api/consumer/resources/?$filter=request/requestNumber+eq+myReqNumber > myreqOutput.json

This will create a file myreqOutput.json with details of your request.  The item you care most about is the catalog ID which you will be able to find at .content.0.catalogItem.id  Note that ID, then request the entitled catalog item with the following:

curl –insecure -H “Accept: application/json” -H “Authorization: Bearer %btoken%”https://vra-fqdn/catalog-service/api/consumer/entitledCatalogItems/?$filter=id+eq+&#8217;catalogItemId‘ > catalogItem.json

This time, note the provider binding at .content.0.catalogItem.providerBinding.bindingId.  Also note the tenant ID specified here.

Now you have the information you need to format the machineRequest.json file:

{
“@type”: “CatalogItemRequest”,
“catalogItemRef”: {
“id”: “catalogItemId”
},
“organization”: {
“tenantRef”: “vsphere.local”,
“subtenantRef”: “TenantId”
},
“requestedFor”: “myUserName@domain“,
“state”: “SUBMITTED”,
“requestNumber”: 0,
“requestData”: {
“entries”: [{
“key”: “provider-blueprintId”,
“value”: {
“type”: “string”,
“value”: “Provider-binding”
}
},
{
“key”: “provider-VirtualMachine.Network0.NetworkProfileName”,
“value”: {
“type”: “string”,
“value”: “Network Profile Name”
}
},
{
“key”: “provider-Variable1″,
“value”: {
“type”: “string”,
“value”: “value”
}
}]
}
}

Note the key: provider-name section above; this is how you specify any custom properties for the blueprint, I provided a couple samples above but what you put here will really depend on the blueprint configuration.  Basically just add provider- to the start of any custom property (or even VM property, see provider-VirtualMachine.Network0.NetworkProfileName above) to submit it with your request… so the next step is to…

Submit a Request

The curl command to submit a request is:

curl -X POST –insecure -H “Content-Type: application/json” -H “Authorization: Bearer %btoken%” https://vra-fqdn/catalog-service/api/consumer/requests –data @machineRequest.json

And now you can see under Infrastructure --> Recent Events or under Requests that new VM getting deployed in vRA. You can also verify under vSphere client session that the VM is getting cloned and deployed.

Hope you find this useful.

Please share and care.




Saturday, August 15, 2015

Request to extend a chance for VCDX5

virtualpatel.blogspot.com: Request to extend a chance for VCDX5: Hi, I am taking the Liberty here to request VMware Education to extend the chance for Appearing a VCDX 5 Defense after the schedule of Oc...

Request to extend a chance for VCDX5

Hi,

I am taking the Liberty here to request VMware Education to extend the chance for Appearing a VCDX 5 Defense after the schedule of Oct 2015.

Now for me, there are reasons behind it which includes personal and work related that I could not prepare on time for this and now dead line is just 10 days away.

I have put lot of time individually to attain the required certifications (VCAP5-DCA and VCAP5-DCD) with the support of my Family and this is over few years of time which covers the time of a new born and a Toddler in the house. With other factors (e.g. work changes and family - main two factors for anyone in any industry) its very difficult to manage the whole planning of preparing an Application and then Defend the same, and to prepare the application alone requires lot of dedication and time, as this is just do or die situation (being optimistic but one never knows) which I wants to attempt and experience this dangerously beautiful journey. Now I am not sure how much important it is, for you to bother about my reasons, I guess not much, but still look at this situation from the other side of the Fence and try to realize the situation from a stand point of a professional, a common man, a family member, a community contributor. and a Father.

So here is my profound Request, to all the decision makers to give the VMware Community one more chance to defend after Oct 2015, which may fall into next year, as I am sure there are others in the community who are under the same condition as me and can stand with me for the above request.

Now one thing I want to make it clear here that, this will be 1st request so far of such kind, and while thinking about it a lot, I decided to echo my thoughts through this post, and its not my intent to take this in any negative way.

With all respect, I will definitely honor the decision, taken by the program authorities and will hope other would do the same. One thing I have learned that, to achieve something you need to put the effort first, so I am considering this step as an effort rather than sitting idle.

This is no way to avoid any future plan on attaining the certifications to attain VCDX, but just a simple request to give one more chance to over all VMware community enthusiasts out there, who are dedicated, focused and being professional to attain this Elite certification which has a tremendous value.

I'm leaving this post here in your capable hands to decide about this Request and urge to give a second thought before making a decision, which infact, can change so many lives (including the person/s and their family).

Update:  (As of 13th May 2016)

VMware just announced today that the VCAP5 Exam Retirements are suspended and the Registration remains open for now. So now this will give chance to the candidates who wants to do the VCAP5/DCA-DCD based on vSphere 5.0/5.5 versions and also prepare for their VCDX.

Here are the exams still available to appear for.

VCAP5 Design Exams:
VCAP Lab Exams:
So wish you all the very best !

Crossing my fingers !

Please Share and Care !!


Saturday, August 1, 2015

vRA Blueprint and Ubuntu 14.04 with Open VM Tools ...

virtualpatel.blogspot.com: vRA Blueprint and Ubuntu 14.04 with Open VM Tools ...: If you are using Ubuntu 64 bit 14.04 version with Open VM Tools installed then you can read further on how to use the Open VM Tools and t...

vRA Blueprint and Ubuntu 14.04 with Open VM Tools customizaton

If you are using Ubuntu 64 bit 14.04 version with Open VM Tools installed then you can read further on how to use the Open VM Tools and then use it with vRA.

Ubuntu 14.04 VM w Open VMware Tools

The version of Open VM Tools its running is - 2:9.4.0-1280544-5ubuntu6.2. You can get the version details by using the following command

dpkg –l | grep open-vm-tools

You can install the open vm tools by giving the command:

apt-get install open-vm-tools

If the tools service is stopped or not running then you can run the following command:

service open-vm-tools start

If you encounter any issue then only try with the following command:

/etc/init.d/open-vm-tools start

Additionally when customizing the VM and deploy a VM from the template we required an additional package installed as per the http://kb.vmware.com/kb/2075048 .
To install this plug-in in Ubuntu: 
To obtain and import the VMware Packaging Public Keys:

Create a directory on the virtual machine to store the VMware Packaging Public Keys.  
Download all the VMware Public Packaging Public Key files from the http://packages.vmware.com/tools/keys directory.
Save the files to the directory you created.
For each key that you download, run this command to import the key:

sudo apt-key add /key_path/key_name

where:
key_path is the directory in which you saved the keys.
key_name is the file name of a key

Create the file /etc/apt/sources.list.d/vmware-tools.list with this content:
deb http://packages.vmware.com/packages/ubuntu precise main
or run this:

sudo echo "deb http://packages.vmware.com/packages/ubuntu precise main"
 >>  /etc/apt/sources.list.d/vmware-tools.list

Note
: Use either precise or trusty above.

To install the package, run this command:

sudo apt-get update
sudo apt-get install open-vm-tools-deploypkg

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.7 (GNU/Linux)
mI0ESAP+VwEEAMZylR8dOijUPNn3He3GdgM/kOXEhn3uQl+sRMNJUDm1qebi2D5b
Qa7GNBIlXm3DEMAS+ZlkiFQ4WnhUq5awEXU7MGcWCEGfums5FckV2tysSfn7HeWd
9mkEnsY2CUZF54lyKfY0f+vdFd6QdYo6b+YxGnLyiunEYHXSEo1TNj1vABEBAAG0
QlZNd2FyZSwgSW5jLiAtLSBMaW51eCBQYWNrYWdpbmcgS2V5IC0tIDxsaW51eC1w
YWNrYWdlc0B2bXdhcmUuY29tPoi8BBMBAgAmBQJIA/5XAhsDBQkRcu4ZBgsJCAcD
AgQVAggDBBYCAwECHgECF4AACgkQwLXgq2b9SUkw0AP/UlmWQIjMNcYfTKCOOyFx
Csl3bY5OZ6HZs4qCRvzESVTyKs0YN1gX5YDDRmE5EbaqSO7OLriA7p81CYhstYID
GjVTBqH/zJz/DGKQUv0A7qGvnX4MDt/cvvgEXjGpeRx42le/mkPsHdwbG/8jKveY
S/eu0g9IenS49i0hcOnjShGIRgQQEQIABgUCSAQWfAAKCRD1ZoIQEyn810LTAJ9k
IOziCqa/awfBvlLq4eRgN/NnkwCeJLOuL6eAueYjaODTcFEGKUXlgM4=
=bXtp
-----END PGP PUBLIC KEY BLOCK-----

Once installed you can reboot the VM, convert the VM back to Template by right clicking the VM and selecting an option "Convert to Template".  Now access the UI of vRA and go to Infrastructure Tab. Select the Compute Resources option and highlight the necessary Cluster which has the Ubuntu blueprint listed, and select Data Collection option at the bottom of the selection, and for the Inventory option, select "Request Now". Once you see "Succeeded" then the vRA blueprint got updated and now the customization should work for the Ubuntu Linux 14.04 version.

Please refer KB 2075048 for instructions on other Linux distros.

Please share and care !!

Thanks for reading.