Last active
August 29, 2015 14:10
-
-
Save chelnak/595498e178ab804e274c to your computer and use it in GitHub Desktop.
vRAAPIClient example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| 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': | |
| exit(request) | |
| else: | |
| print "Request successful" | |
| break | |
| sleep(2) | |
| #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']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment