vRa Lease Update and listing Using API
vRa Lease Update Using Workflow

Introduction

In today's fast-paced and dynamic business landscape, optimizing resource allocation and streamlining operational processes is crucial. That's where vRa lease update using workflow comes into play. This powerful tool empowers organizations to efficiently manage and update lease agreements, ensuring optimal resource utilization. In this post, we will delve into the intricacies of vRa lease update using workflow/API, exploring its importance and benefits for businesses.

The Significance of vRa Lease Update Using Workflow

Enhanced Resource Utilization

By leveraging vRa lease update using workflow, organizations can ensure optimal utilization of their resources. The automated process enables timely updates to lease agreements, allowing businesses to allocate resources efficiently and avoid underutilization or overutilization scenarios. This leads to cost savings and improved operational efficiency.

Streamlined Lease Management

Managing lease agreements manually can be a cumbersome and time-consuming task. With vRa lease updates using workflow, businesses can streamline the entire process. The automated workflows eliminate the need for manual intervention, reducing human error and saving valuable time for IT teams. This enables organizations to focus on more strategic initiatives and improve overall productivity.

Compliance and Governance

Lease agreements often have specific compliance and governance requirements that organizations must adhere to. Failure to meet these obligations can result in legal consequences and financial penalties. By utilizing vRa lease update using workflow, businesses can ensure that lease agreements are updated in a compliant manner, mitigating the risk of non-compliance and ensuring regulatory adherence.

JavaScript Code for Lease Extend

Before running the workflow add the rest host in vRa and put it as input, below are the steps.

  • Launch the vRealize Orchestrator Client and log in to your vRO instance.
  • In the left-hand navigation pane, expand the Library section.
  • Under the Library, expand the HTTP-REST folder.
  • Right-click on Configuration, hover over Add, and select REST host from the sub-menu.
  • In the Add a REST host window, provide the necessary information:
    • Name: Enter a descriptive name for the REST host.
    • Base URL: Specify the base URL of the REST API you want to connect to.
    • Authentication: None
    • Timeout: Set the timeout value (in milliseconds) for the REST host connection.
  • Click OK to create the REST host.
JavaScript Code Showcase

//Expire date set 
var leasedays = customProperties.get("leasedays")
var myCurrentDate=new Date();
var myFutureDate=new Date(myCurrentDate);
    myFutureDate.setDate(myFutureDate.getDate()+ leasedays);
System.log(myFutureDate);
var leaseDateFormatted = System.formatDate(myFutureDate,"yyyy-MM-dd'T'HH:mm:ss'.000Z'")
var leasedatestr = leaseDateFormatted.toString();

// Get the deployment ID by searching the deployment(hostname) name.
try
{

var restHost  = rest_host;
var vraToken = token
var content ="";
var method = 'GET'
operationUrl1 =   '/deployment/api/deployments?%24top=10000&search=' + hostname
request1 =  restHost.createRequest("GET", operationUrl1);
request1.setHeader("Content-Type", "application/json");
request1.setHeader("Authorization", "Bearer " + vraToken);
var response = request1.execute();
var statusCode = response.statusCode;
var responseContent = response.contentAsString;
if(statusCode > 399) {
    System.error(responseContent);
    throw "executeRestAction Failed, Status Code: " + statusCode;
}
var json1 = JSON.parse(responseContent)

var resourceID = (json1.content[0]).id;

System.log("The resource ID : " + resourceID );

// Extend the lease by giving the exact date.

var LeaseChangePayload = {};
LeaseChangePayload.actionId = 'Deployment.ChangeLease';
LeaseChangePayload.reason = 'vRA Lease Update using Workflow';
LeaseChangePayload.inputs = {'Lease Expiration Date': leasedatestr };;

var loginJason = JSON.stringify(LeaseChangePayload);
var operationUrl = "/deployment/api/deployments/" + resourceID + "/requests"
var request = restHost.createRequest("POST", operationUrl, loginJason);
request.setHeader("Content-Type", "application/json");
request.setHeader("Authorization", "Bearer " + vraToken);
var response = request.execute();
System.debug(response.contentAsString);
var res = JSON.parse(response.contentAsString);

System.log("Response : " + JSON.stringify(json1.content[0],',',3));

}
catch(errordata)
{
    System.log("Error while fetching Deployment ID :" + errordata)
}
        

JavaScript Code for Listing Out All VMs Going to Expire

JavaScript Code Showcase

var restHost  = rest_host
var domain = 'System Domain';
var user = 'LocalUser';
var password = User_Password;

//Creating login Object
var loginObj = {};
loginObj.domain = domain;
loginObj.password = password;
loginObj.scope = ""
loginObj.username = user;
var loginJason = JSON.stringify(loginObj);

//Get the token
var operationUrl = "/csp/gateway/am/api/login";
var request = restHost.createRequest("POST", operationUrl, loginJason);
request.setHeader("Content-Type", "application/json");
var response = request.execute();
System.debug(response.contentAsString);
var res = JSON.parse(response.contentAsString);
var token = res.cspAuthToken;

System.sleep(5000)


//Create the URL string for date, This date will be 4days after the current date
var UpdateDate = new Date();
//System.log("Current date is: " + UpdateDate);  
System.log(System.formatDate(UpdateDate,"yyyy-MM-dd$HH:mm:ss:ms"))
var startDate = System.formatDate(UpdateDate,"dd")
var startMonth = System.formatDate(UpdateDate,"MM")
var startYear = System.formatDate(UpdateDate,"yyyy")
System.log(startDate + " " + startMonth + " " + startYear)

//Adding 100 hours will give the date after 4days
UpdateDate.setHours(UpdateDate.getHours() + 100)

var ENDDate = System.formatDate(UpdateDate,"dd")
var ENDMonth = System.formatDate(UpdateDate,"MM")
var ENDYear = System.formatDate(UpdateDate,"yyyy")
System.log(ENDDate + " " + ENDMonth + " " + ENDYear)

var URL_String = 'expiresAt=%5BstartYear-startMonth-startDateT08%3A00%3A00.000Z%2CENDYear-ENDMonth-ENDDateT23%3A59%3A00.000Z%5D'

URL_String = URL_String.replace('startDate',startDate)
URL_String = URL_String.replace('startMonth',startMonth)
URL_String = URL_String.replace('startYear',startYear)
URL_String = URL_String.replace('ENDDate',ENDDate)
URL_String = URL_String.replace('ENDMonth',ENDMonth)
URL_String = URL_String.replace('ENDYear',ENDYear)
//System.log(URL_String)

//Get the list of server which going to expire in next 100 hours or 4days.

try
{
var restHost  = rest_host;
var vraToken = token
var content ="";
var method = 'GET'
operationUrl1 =   'https://tenant.vraserver.local/deployment/api/deployments?%24top=100000&' + URL_String
request1 =  restHost.createRequest("GET", operationUrl1);
request1.setHeader("Content-Type", "application/json");

request1.setHeader("Authorization", "Bearer " + vraToken);

var response = request1.execute();
var statusCode = response.statusCode;
var responseContent = response.contentAsString;
if(statusCode > 399) {
    System.error(responseContent);
    throw "executeRestAction Failed, Status Code: " + statusCode;
}
var json1 = JSON.parse(responseContent)
System.log(json1.content.length)
return json1.content

}
catch(errordata)
{
    System.log("Error while fetching Deployment ID :" + errordata)
}
        

FAQ's

Q: Why is vRa lease update using workflow important for businesses?

A: vRa lease update using workflow is crucial for businesses as it enables efficient resource allocation, streamlines lease management, and ensures compliance with governance requirements.

Q: Can vRa lease update using workflow be customized to fit specific business needs?

A: Yes, vRa lease update using workflow can be customized to align with the unique requirements of different businesses. This flexibility allows organizations to tailor the solution according to their specific resource allocation and lease management processes.

Q: Are there any prerequisites for implementing vRa lease update using workflow?

A: To implement vRa lease update using workflow, businesses need to have a VMware vRealize Automation environment in place. Additionally, they should have a clear understanding of their resource allocation policies and lease management workflows.

Q: Does vRa lease update using workflow support integration with other systems and tools?

A: Yes, vRa lease update using workflow supports integration with various systems and tools commonly used in IT environments. This integration enables seamless data exchange and enhances the overall effectiveness of lease management processes.

Q: Is vRa lease update using workflow suitable for businesses of all sizes?

A: Yes, vRa lease update using workflow is designed to cater to the needs of businesses of all sizes. Whether you are a small startup or a large enterprise, this tool can bring significant benefits to your resource allocation and lease management practices.

Conclusion

Efficiently managing lease agreements and optimizing resource allocation is a key challenge for businesses. However, with vRa lease update using workflow, organizations can automate and streamline the entire process, resulting in improved operational efficiency, cost savings, and compliance with governance requirements. By leveraging this powerful tool, businesses can focus on their core objectives while ensuring optimal resource utilization. Embrace the power of vRa lease update using workflow and take your resource management practices to the next level.


Siddartha Kumar Das
About Siddartha Kumar Das

Tech Enthusiast

Topics