Examples

0

Automate your Zerto Disaster Recovery solution with vCO

Today I show you how to automate your Zerto installation with the vCO. Or those which are not familiar with Zerto here a quote from the Zerto Website:

What is Zerto?

Zerto provides enterprise-class business continuity and disaster recovery (BCDR) solutions for virtualized infrastructure and cloud. [……]  Zerto Virtual Replication, is the industry’s first hypervisor-based replication solution for tier-one applications. Zerto Disaster Recovery solutions replace traditional array-based BCDR that was not built to deal with virtual environments.”

So for those which know the VMware Site Recovery Manager, Zerto is an alternative Product to the SRM.

For a customer Self Provisoning Portal I had to  automate the deployment of the virtual Machines within the Disaster Recovery Solution.  In my case this Automation must be archived with the VMware Orchestrator.

Zerto offers a limited documentation of the API which can be accessed with a REST API. The documentation can be found here: http://downloads.zerto.com/documentation_4acccec86a1e7cbf77f8e6bd3831c31c/3.1/Zerto%20Virtual%20Replication%20REST%20APIs%20Online%20Help/index.html

With this documentation I started my integration.

First thing what we need to do to integrate Zerto is to add the Zerto Hosts as REST Clients in the vCO Server. This integration is done over a vCO Workflow.

If have documented this before in another post (http://www.vcoportal.de/2014/02/automating-veeam-with-vco-and-the-restful-api/) so I will only point to the parameter which are needed.

For the configuration, you give a name, have to provide the URL to the ZVM Machine with the configured Port (the default port is 9669) and a Connection and Operation timeout. Please use for the connection a HTTPS connection. HTTP is possible but I had a lot of problems that the vCO run into timeouts.

We do not need a proxy Server.

As Authentication we use the “Basic” Authentication Type.

I used a “Shared Session” for the configuration but Single Sessions are also possible.

When you “Submit” the Workflow you will get a Certificate error.

Install the Certificate and go ahead.

After we have connected your Zerto REST Connection, we have to create our API connection. The initial request we must made is to make a call to the API. This call is done with a username and password for permissions to the vCenter Server. Here it is important, that the Username and the Password are for a User with permissions vCenter Server. The Zerto REST connection response includes an “x-zerto-session” header. The String in this Header is used for any future communication with the ZVM (Zerto Virtual Manager) and the vCenter Server. All other ways doesn’t function!


First thing we have to do is to create the initial request. For the request this URL is used: “https://zvm_ip:port/v1/“. I place this initial request in an own workflow. For the workflow we need some Attributes, Input and Output Variables.

Variable Name Type Value
Attribute sessionMode String Shared Session
Attribute RestAuthType String Basic
Inputs RestHost REST:RESTHost
Inputs authUserName String
Inputs authPassword SecureString
Output xZertoSessionKey String

In the Workflow we create a Script Element.

In this scripting element we include all Attributes and Inputs as Input and the Output element as Output for the Workflow.

Then we create our Script:


// we must use "dedicated" User Credentials. With the Provided Credentials we need Access to the VC!

var authParams = [sessionMode, authUserName, authPassword];

var authenticationObject = RESTAuthenticationManager.createAuthentication(RestAuthType, authParams);

// Create the Host Authentication

RestHost.authentication = authenticationObject;

//Create the Session

var CreateSession = RestHost.createRequest("POST", "/v1/session/Add", null).execute();

// Place the Response in a separate Variable to Access the Content

var SessionResponse = new Properties();

SessionResponse.put("statusCode", CreateSession.statusCode);

SessionResponse.put("headers", CreateSession.getAllHeaders());

if ( SessionResponse.statusCode == "200") {

System.log("Session successful created")

xZertoSessionKey = SessionResponse.headers.get("x-zerto-session")

}

else {

System.log("Session could not be established")

}

With this small script we establish our connection to the ZVM and extract the x-zerto-session key.

Know we create the next workflow. In my case the next Workflow I use the command “get peersites” to access the connections between both locations.  The command to do this is: “https://zvm_ip:port/v1/peersites” .  Also for this workflow we need some Inputs and Outputs.

Variable Name Type Value
Inputs RestHost REST:RESTHost
Inputs xZertoSessionKey String
Output getPeersitesOutput String

Also here we create a scripting element within the workflow.

We use the created Input as Inputs and the Output as output with the Scriptable Task.  This Script is used with the workflow:

 


//Authenticate the request with the Zerto x-session-header
var CreateSession = RestHost.createRequest("GET", "/v1/peersites", null)

// Build up the Session Header information

CreateSession.setHeader("x-zerto-session", xZertoSessionKey);

// The Output of the Command is catch in a variable

getPeersitesOutput = CreateSession.execute();

System.log ("ContentString " + getPeersitesOutput.contentAsString);

As last point we have to build up a third Workflow witch put both before created workflow together.

The Input and Outputs are created from the need within the Workflow created before.

Variable Name Type Value
Attribute xZertoSessionKey String
Attribute getPeersitesOutput String
Inputs RestHost REST:RESTHost
Inputs authUserName String
Inputs authPassword SecureString
Output xZertoSessionKey String

After you have finished everything you can execute the Workflow and see the Output of the command.

There are many more commands witch you can use to automate your Zerto installation. All commands are documented in the API Documents to which I pointed before.

So have fun and orchestrate the World 😉

0

vCO Input Presentation

Last week I received a customer question regarding a vCO input presentation. The customer has a vCO Server were multiple vCenter Servers are connected. For his environment, he created a workflow were users are asked to give some information. Based on this information the view should be restricted.

First thing the customer had, was a Variable from type VC:SDKConnection. This is used to choose the correct vCenter Server.

When you start a vCO Client with this, you can pick the right vCenter Server for your need.

The next thing what should be archived was the possibility, to pick an ESX Host from that vCenter Server. As I looked into the customer configuration I saw that there was a  created  “Select value as” and “Specify a root object to be shown…:”

With this config the view was not as the customer was expecting it. When the user came to the point to  choose an ESX Host, the users saw all ESX Server from the hosts.

This is really uncool…..

So how can we fix this behavior?

That’s pretty easy…..

Let’s go back to the Workflow. There we choose the Presentation pane and the input. Then we change the  “Specify a root object….”

Here we change the Value over the Pen (in this case) to #vCenterServer.

When we now save the workflow and start it again wen only see the Hosts / vCenter Server to which we limited the view.

Easy or?

One important note here: The limitation of the View works only with the “Select value as” tree. It doesn’t work for the other views!

So have fun and orchestrate the World!

0

Automating Veeam with vCO and the Restful API

Do some of you remember my Blog Post about automating Veeam with vCO and Powershell (http://www.vcoportal.de/2013/04/vco-and-veeam-backupreplication-a-powerful-combination/)? The problem at this time was that Veeam only offers a PowerShell API. Now, some time is gone and Veeam released the Version 7 of Backup&Replication.  In this Version, Veeam offers an Enterprise Manager which offers a Restful API for automating.  Please be aware that the Restful API is only available in the Enterprise Plus Version of Veeam B&R.  The Veeam Restful API can be accessed over this URLs and ports:

Veeam Restful API HTTP URL  http://<Enterprise-Manager>:9399/api/

Veeam Restful API HTTPS URL https://<Enterprise-Manager>:9398/api/  

A comparison can be found here: http://www.veeam.com/backup-version-standard-enterprise-editions-comparison.html So, let’s start with the integration. First think what we have to do is to connect the vCO and the Veeam B&R server. Therefore we need the vCO Rest Plugin which must be installed over the vCO Plugin page. Details how to do install a plugin can be found in the vCO Documentation for the Plugin (http://pubs.vmware.com/orchestrator-plugins/index.jsp?topic=/com.vmware.using.http_rest.plugin.doc_10/GUID-D303E545-0BFE-4EEB-BAC3-7776EFCDB516.html)

After we have installed the Plugin, we can connect the vCO and the Veeam Server. Therefore we have a build in Workflow “Add a Rest Host”

In the Workflow we have to give our Restful Host a Name and have to define the URL. The settings for the Connection and Operation timeout doesn’t have to be changed.

The Authentication for the B&R Server has to set to Basic

The next thing is to chose a Session mode. You can chose between a “Shared Session” and a “per User Session”. Which you chose depends on your security settings. I will take a shared Session in the Screen-Shots. For the shared session you have to define a user and a password.

If you use a HTTPS connection, you have to accept the SSL Certificate for the B&R Server.

At the end you start the Workflow and if everything goes well, your Workflow finished without any problems.

 

The next thing you can do, is to import the Veeam Rest Schema. The Schema is located in the Path “C:\Program Files\Veeam\Backup and Replication\Enterprise Manager\schemas\RestAPI.xsd” on you B&R Server. To import the file, you have to transfer it to a Webserver so that the vCO Server can import the schema. To start the import we start the Workflow “Add schema to REST Host”. 

In the Workflow, we have to change the REST Host to which we want import the schema.

In the next screen we have to define the Web URL were the schema file is located.

If everything goes well, your workflow finished without any error and the Schema is available under the Rest Host.  

During my test, I had some problems with the Schema. So I decided to implement my task manual…… To implement the Veeam Restful API functions manually, the Veeam documentation is required. The documentation can be found here: http://helpcenter.veeam.com/backup/70/rest/overview.html

First thing which we have to do is to open a Restful API Connection from the vCO Server to the B&R Server. To connect the API two commands are used.

The first command is:

GET http://EnterpriseManager:9399/api/

and the second is

POST http://EnterpriseManager:9399/api/sessionMngr/

To send the commands to the Enterprise Manager you need authentication. Do the facts, that we configured our vCO Server for authentication, vCO handle this Authentication for us. Now, let’s post this request into a vCO Workflow. Therefore we create a new Workflow. For the Workflow we need one Input Parameter from Type REST:RestHost

In the Workflow itself we place a “Scriptable task” to insert our Code.

In this “Scriptable Task” we include this code:


var PostResponse = BRHost.createRequest("POST", "/api/sessionMngr/", null).execute();

System.log("Connection Successful:  " + PostResponse.contentAsString);

So, what does this code do? In the first line, we open the connection to the Enterprise Manager. The Authentication is done from the vCO Server (the provided Credentials during the Rest Host connection). The Second line just gives us the response of the Connections and the available things we can make. Now let’s expand this Workflow and let us see which Backup Jobs are implemented.


var PostResponse = BRHost.createRequest("POST", "/api/sessionMngr/", null).execute();

var BackupResponse = BRHost.createRequest("GET", "api/jobs?type=job", null).execute();

System.log("Backup Jobs " + BackupResponse.contentAsString);

The interesting Part here is the second line witch gets the Backups Jobs from the Server:

Backup Jobs <?xml version=”1.0″ encoding=”utf-8″?><EntityReferences xmlns=”http://www.veeam.com/ent/v1.0″ xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”><Ref UID=”urn:veeam:Job:a8f5b929-c5c8-4901-b749-d8c7ea9b8462″ Name=”Job1″ Href=”http://192.168.157.207:9399/api/jobs/a8f5b929-c5c8-4901-b749-d8c7ea9b8462″ Type=”JobReference”><Links><Link Href=”http://192.168.157.207:9399/api/backupServers/2b98f7dd-a2e5-4a53-9704-dfec9b30a320″ Name=”192.168.157.207″ Type=”BackupServerReference” Rel=”Up”/><Link Href=”http://192.168.157.207:9399/api/jobs/a8f5b929-c5c8-4901-b749-d8c7ea9b8462?format=Entity” Name=”Job1″ Type=”Job” Rel=”Alternate”/><Link Href=”http://192.168.157.207:9399/api/jobs/a8f5b929-c5c8-4901-b749-d8c7ea9b8462/backupSessions” Type=”BackupJobSessionReferenceList” Rel=”Down”/></Links></Ref></EntityReferences>

As we can see we have a Backup Job with the name “Job1”. Now let’s have a look with VMs are included into the Job. First of all, we need a Input parameter for the Jobname (we will use this to filter the results…)

After we are finished we will extend our code:

var PostResponse = BRHost.createRequest("POST", "/api/sessionMngr/", null).execute();
var BackupResponse = BRHost.createRequest("GET", "api/jobs?type=job", null).execute();
var XMLFile = XMLManager.fromString(BackupResponse.contentAsString);
var XMLelement = XMLFile.documentElement.getElementsByTagName("Ref");

for(i=0;i<XMLelement.getLength();i++){
 var BackupJob = XMLelement.item(i).getAttribute("Name")
if ( BackupJob == BackupJobName){

 var UIDBackup = XMLelement.item(i).getAttribute("UID")
 var UIDBackupJob = UIDBackup.substring(14,50)
 var VMResponse = BRHost.createRequest("GET", "/api/jobs/" + UIDBackupJob + "/includes", null).execute();

System.log("VMs included: " + VMResponse.contentAsString);
}
}

When we make a call to the Restful API we become a XML Response. We call the XMLManager and place the content into the variable XMLFile. On the next row we filter the XML response for the Word “Ref. Within the “Ref” response we search with a loop for the Attribute “Name” and place the response in  a variable. Then we check this name against the Backup Job name an extract the unique identifier for the Job. With this unique identifier we mal a job request and get the list of the included VMs.

The answer from the call is this:

[2014-02-09 23:15:06.281] [I] VMs included: <?xml version=”1.0″ encoding=”utf-8″?><ObjectsInJob xmlns=”http://www.veeam.com/ent/v1.0″ xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”><ObjectInJob Href=”http://192.168.157.207:9399/api/jobs/a8f5b929-c5c8-4901-b749-d8c7ea9b8462/includes/b39bdbf3-8333-4525-b393-110ef3ea9332″ Type=”ObjectInJob”><Links><Link Href=”http://192.168.157.207:9399/api/jobs/a8f5b929-c5c8-4901-b749-d8c7ea9b8462/includes/b39bdbf3-8333-4525-b393-110ef3ea9332″ Name=”WinXP2″ Type=”ObjectInJob” Rel=”Delete”/><Link Href=”http://192.168.157.207:9399/api/jobs/a8f5b929-c5c8-4901-b749-d8c7ea9b8462?format=Entity” Name=”Job1″ Type=”Job” Rel=”Up”/></Links><ObjectInJobId>b39bdbf3-8333-4525-b393-110ef3ea9332</ObjectInJobId><HierarchyObjRef>urn:VMware:Vm:ea294886-2e12-419b-934f-70b371e0f746.vm-15</HierarchyObjRef><Name>WinXP2</Name><DisplayName>WinXP2</DisplayName><Order>0</Order><GuestProcessingOptions><AppAwareProcessingMode>RequireSuccess</AppAwareProcessingMode><FileSystemIndexingMode>ExceptSpecifiedFolders</FileSystemIndexingMode><IncludedIndexingFolders/><ExcludedIndexingFolders><Path>%windir%</Path><Path>%ProgramFiles%</Path><Path>%TEMP%</Path></ExcludedIndexingFolders><CredentialsId/></GuestProcessingOptions></ObjectInJob></ObjectsInJob>

So with the techniques and methods shows in the post you are able to do a lot more interesting stuff with vCO and Veeam Enterprise Manager. A complete list about all the Enterprise Manager Restful API commands can be found here: http://helpcenter.veeam.com/backup/70/rest/em_web_api_reference.html Have fun with our automation and orchestrate the World 😉

0

Introduction to vCenter Orchestrator #vBrownbag podcast

Last night (literally) I had the honor to present an introduction to vCO as part of the #vBrownbag “Automate all the Things” community podcast series. See the recording below, more information and future agenda on http://professionalvmware.com/vbrownbag-automate-all-the-things-training-schedule/

0

New vCO video available!

Brian Watrous, one of VMware’s most senior technical trainers (you know him from the videos on www.vmwarelearning.com/orchestrator, don’t you…), has published a new video about how to customize workflow icons in vCenter Orchestrator. For your convenience, I embed the youtube video below. Make sure you subscribe to Brian’s blog on www.vvork.info and his youtube channel, there is more to come…

Great work, Brian! Keep them coming! 🙂