Tuesday, 9 August 2016

vROps REST API Deep Dive : Part 1 Create Report

vRealize Operations's Manager API is becoming rich version by version. One of the good introduction, starting version 6.1 is support for Reporting. So now you can create report ( generate report) via API. In this part, I will show how to Create report via API. The Second part would focus on how we can Schedule report.




Those who are new to vROps API topic can go through one of my old posts.
                                    Introduction to vROps REST API

vROps REST API docs can be found at https://vROPS.fqdn/suite-api/docs/rest/index.html.

Look for /api/reports section. We will be using the POST action for /api/reports. On the right-hand side you would see sample requests for Create Report like below.













You can use either XML or JSON body for vROPs. I will be using JSON. Below is the sample request in JSON format. We need to get highlighted UUIDs.

{
  "resourceId" : "24ae0ae8-2823-438a-a588-04c320f15e17",
  "reportDefinitionId" : "97d19754-0ad3-4de1-b35b-d8ad5d07be24",
  "traversalSpec" : {
    "name" : "vSphere Hosts and Clusters",
    "rootAdapterKindKey" : "VMWARE",
    "rootResourceKindKey" : "vSphere World",
    "adapterInstanceAssociation" : false,
    "others" : [ ],
    "otherAttributes" : {
    }
  },
  "others" : [ ],
  "otherAttributes" : {
  },
  "id" : null
}

First one is Resource ID. It is the ID of the resource, for example, a VirtualMachine, Host, Clusters, Datastore etc. You can get the ID by firing below request in web-browser.

https://vROPS.fqdn/suite-api/api/resources.
Look for the resource name(in our case a virtual machine) for which you want to run the report, then note down the Identifier as shown below.


















Next is to get the ReportDefinitionID. It is the ID of the report which you want to execute remotely. You can get the ID by firing below the request.

https://vROPS.fqdn/suite-api/api/reportdefinitions

Look for the name of the report.In our case VM Inventory - Disk Space Report.
 

Now let's understand what does Traversal Spec means.It means how would you traverse down for generating the report, i.e while generating report we have to select an Object.In our case, we want to execute this report for a Virtual Machine. Imagine you are doing it manually, so you will select vSphere Hosts and Clusters. Similarly via API as well, we have to look for vSphere Hosts and Clusters kind key values. So we note down rootAdapterKindkey and rootResourceKindKey values.( as highlighted above)





















That's it. Our request is now ready for generating report.

For firing REST calls you can use your preferred REST tools. Most common are plugins for Mozilla, Chrome and Postman.

Execution
Method : POST
URL: https://vROPS.fqdn/suite-api/api/reports
Enter Content-Type header value as application/json.

Ready to FIRE!!

You can verify the response from



That's it. Verify that the report has been successfully generated by going to vROps Report GUI!!

In the next blog part, I will show how we can extend this and Schedule Report as well. Combination of these operations via API will be useful in many use-cases.

Stay tuned!!


Monday, 30 May 2016

vRealize Automation 7 : Delete Stale Virtual Machine Records Using Cloud Client

vRealize Automation 7 : Delete Stale Virtual Machine Records Using Cloud Client


This blog post talks about how to remove  stale / hung virtual machine records from vRealize Automation 7.x. While in vRA 5.x /6.x, we had SQL scripts to do the same action, in vRA 7.x the same can be done with the power of Cloud client 4.1. Cloud Client is really a powerful and cool tool for further automating vRA tasks. And this blog will show why it's so Powerful!

 Scenario / Use-case


You may have come across a situation, wherein due to some failures during provisioning, virtual machine record doesn't clear out completely and this can cause issues.  The major one is , this entry blocks an IP address in Network Profiles and occupies resources in Reservation.

I also hit the same issue recently while working on vRA7- NSX integration. The ideal way out is to use GUI for deleting these stale entries, but LUCKILY, it didn't work for me and I got the chance to explore the recently added function"forceunregister" in Cloud Client 4.1. I will first talk about using the GUI for doing this action.


Using GUI:


The recommended way is to use GUI for removing these records and the process is as below.

  • Navigate to Infrastructure > Managed Machines.

  • Select the entry to be deleted. In my case it was "Edge-eGNCNSX-37b5ce54-c649-4d4f-9574-90ce44851ab4"
  • Right-click the entry and select Destroy.

  • Make sure the entry is selected and Click OK.

  • Ideally, the entry should have been deleted, but it didn't.

Using Cloud Client 4.1:

  • Download cloud client from the below link.
  • Cloud Client 4.1
  • Navigate to Bin folder of Cloud client and you would find Cloudclient.bat file.
  • Run the bat file as Administrator. 

  • Now login with the user which has admin rights into vRA appliance.
vra login userpass --user Admin ID --tenant Tenant Name --server vRA FQDN --password Password


  • Once logged in, now log in using domain service account into IaaS machine.
vra login iaas --user service account --Domain domain --server manager server --password Password

  • Now execute the command vra machines forceunregister --name Entry to be removed.

  • This does the desired MAGIC!!! The entry gets deleted from Managed Machines.

  • This action also clears and removed the reserved IP address from Network Profiles.
  • This will not delete the Virtual Machine from vCenter. So, you will have to delete the Virtual machine manually from vCenter.

I hope this post helps you in removing unwanted entries and keeping vRA clean.


Tuesday, 12 January 2016

vRealize Automation : Why my VM provisioning request got Rejected?

vRealize Automation Version: 6.x

One thing that I have thoroughly enjoyed and has given me immense satisfaction over the years as a field guy is finding interesting use-cases and providing the solutions for the same.

Use-case:

Everything was going smooth until, in UAT, we found an interesting issue. There is no way in vRealize Automation GUI can a requester see the "Bussiness Justification" after his request gets rejected. The vRA version that I am referring here is 6.2.2, but it is seen in earlier versions as well.

While technically it may seem to be a small issue, but from business point of view it posed many challenges some of which Client highlighted as:
  • Since requester doesn't know why his request was rejected, he would repeat the mistake.
  • Even cloudadmin has no visibility of why a particular request was rejected or approved.
  • The bigger roadblock was Auditing, since it was a bank, they wanted to keep track of rejections and most importantly approvals of requests with high resources.
If you are new to vRA or would like to understand its components and constructs, I would recommend you to go through these useful blogs:


Solution:

The solution was quite tricky and bit complex. All Service Request(SR) related details like SR id is stored in catalog-service , while the approval related is stored in approval-service. So the way to retrieve the "Business Justification" and "Approver Detail" was to first make REST calls to catalog-service , store details and then using these details make another REST call to approval-service. I tried these stuff using the REST client and it worked perfectly. Now the next big step was to automate these REST calls and expose to Cloudadmin / Requester as a Catalog Service.

High-Level Steps:

  • Leverage vRealize Orchestrator(vRO) and develop vRO workflows to make REST calls.
  • Make a parent vRO workflow which would be called from vRA.
  • Create and Advance Service Designer(ASD) to call the parent workflow.

Low-Level Steps:


vRO:

  • Register a REST host in vRO by navigating to Library -> HTTP-REST-> Configuration -> Add a REST host.
  • Now add a REST operation by executing Add a REST operation workflow. 
                 Values to copy:
               a.  Name  :  Request-Token
               b.  Template URL : /identity/api/tokens
               c.  Content Type : application/json
               d.  HTTP Method : POST
  • Now Execute a Generate a new workflow from a REST operation for getting token ID/Authentication of vRA session.
  •  Now Add second REST operation for getting PreApproval id by executing the same workflow as in step 2
                  Values to copy:
               a.   Name: GetPreApprovalId
               b.  Template URL: /catalog-service/api/consumer/requests?   limit=1&page=1&%24filter=requestNumber+eq+{SRNumber}
    • Generate a new workflow by executing the Generate a new workflow from a REST operation for getting approval ID.
    •  Register the 3rd REST operation.
                        Values to copy:
                   a. Name : GetDetail.
                   b. Template URL : approval-service/api/info/approvals/{preApprovalId}


      • The script which will extract "Business Justification" and "Approver's Email ID" is:
                                 var jsonResponse = JSON.parse(contentAsString);
                                            var groups = jsonResponse.pastLevel;
                                                            for each (group in groups){
                                                              var requests = group.request;
                                                                  for each (req in requests) {
                                                                     var busJust = req.businessJustification
                                                                     var approver = req.completedBy
                                                                       }

                                                 System.log("Approvers is: " + approver);
                                                 System.log("BusinessJustifaction is: " + busJust);
                                                 }
                       
      •  The final parent workflow should look something like this.


      • Develop above workflow in such a way that it should have only 1 input i.e SR Number and 2 Outputs as shown below.



      vRA:


      • Login to vRealize Automation portal and navigate to Advanced Services tab and Add a new service blueprint.
      • Map it to the parent workflow created in vRO.
      • Edit "srnumber" input field to make it more descriptive, for ex "Request Number".
      • Create an Output field to capture "Business Justification" and "Approver's Email ID".
      • Give proper Entitlement as per need.
      That's it. Now let's see it in Action.

      • Login to vRA and go to Catalog, you would see something like this.

        • Request the Catalog as:

        • Go to Request and see the MAGIC!!


          I hope that you will find this useful!

          Stay tuned for more DeepDives.

          Saturday, 9 January 2016

          vRealize Operations Manager Metric Guide!

          This blog was published earlier by me in Sunny Dua's vXpresss:

          vRealize Operations Manager Metric Guide!


          I came across many requests both internally (field consultants / SE) and externally (Clients) for an extensive list of available metrics of vRealize Operations Manager in the form of sheet, so that one can easily refer to without accessing the product UI. The request was genuine, as vROps has rich library of metrics which can be leveraged for doing performance and capacity analysis and creating super-metrics, views, dashboards. I started looking through various available documents and internal sources, but couldn’t find any. Now in the same process, I found a wonderful stuff which is REST interface for vROps. Now coming from an Automation background, I really like to play with api's
          and use them to automate as much as possible.


          Now, let’s deep-dive into, how I have extracted these metrics.


          vRealize Operations API documentation can be found at https://IPADDRESS OF vROPs/ suite-api/docs/rest/index.html. In this page, you can find all relevant information like, which API’s are available, sample request and response etc. The REST call that I made to retrieve these metric details is

          That’s it. Is it the end of the Blog? Nope, because I know, you would be wondering, how did I get to this request, or how do I know which API call I need to fire, Right?

          So, let me explain this. The first thing that we do, whenever we want to see any Metric, is we always select the Adapter Type first in GUI interface. So select the “getAdapterTypes”. The request now becomes.
















            Now, fire the above request on web browser.  Here is what you will see.
























          So, now we know that the adapter-kind key is VMWARE. So the call now becomes

          Again, let’s see what we get after executing above request. 


























          So, now we see all the Object Types available under VMWARE. Note down the resourceKinds key for the Object you want to retrieve metrics. Request now becomes

          Execute the request and you see.
















          That’s it. Here you get the complete http request for getting the statkeys:

          Now, fire the above commands one by one replacing the resourceKinds with each object available under the VMWARE adapterkind. Once you have all the data, it’s quite easy to then dump them into XLS format.

          Hope this consolidated sheet helps you and becomes your reference tool. I have also uploaded this on the following link and you can get a copy. However it is always good to know how I created this as you can do the same for any other AdapterKind.