12/5/2014 - 8:45 AM

vRAAPIClient example

vRAAPIClient example

import getpass
import json
import os

from globalconfig import passwd, url, usr
from time import sleep
from sys import exit
from vraapiclient import catalog

#Get the current directory
currentDirectory = os.path.dirname(os.path.abspath(__file__))

client = catalog.ConsumerClient(url, usr, passwd)

#Create the JSON payload for the Post and submit the request
with open('requestFormatted.json') as f:
        payload = json.load(f)

requestId = client.requestResource(payload)

print "Request submitted: {id}".format(id=requestId)

acceptedStates = ['FAILED', 'SUCCESSFUL']

#Wait for the request to finish
print "Waiting for the request to complete..."

while True:
        request = client.getRequest(requestId)
        requestState = request['state']

        if requestState in acceptedStates:
                if requestState != 'SUCCESSFUL':
                        print "Request successful"


#Return networking information for the new resource
resourceId = client.getResourceIdByRequestId(requestId)
resourceNetworking = client.getResourceNetworking(resourceId)

for i in resourceNetworking:
        print "{key} : {value}".format(key=i['key'], value=i['value']['value'])