Last active
August 29, 2015 14:26
-
-
Save chelnak/946724fb6c5ad36087b3 to your computer and use it in GitHub Desktop.
Create reservations for all business groups in vRealize Automation using vRAAPIClient
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 jinja2 import Environment, FileSystemLoader | |
| from vraapiclient import reservation | |
| #Get the current directory | |
| currentDirectory = os.path.dirname(os.path.abspath(__file__)) | |
| client = reservation.ReservationClient(url, usr, passwd) | |
| #Set up jinja2 environment | |
| env = Environment(loader=FileSystemLoader(currentDirectory)) | |
| template = env.get_template('reservationTemplate.json') | |
| #Get all business groups | |
| businessGroups = client.getAllBusinessGroups(show="json") | |
| #Loop through each group in the businessGroups object and pull out | |
| #id and name, format the reservation name and inject both values | |
| #in to the params dict. | |
| for group in businessGroups: | |
| #This is where we format the reservation name. | |
| #[ComputeResource]-Res-BusinessGroupName(nospaces) | |
| name = 'CLTEST01-Res-{groupname}'.format(groupname = group['name'].replace(" ","")) | |
| #Set all configurable parameters here | |
| params = { | |
| 'ReservationName': name, | |
| 'SubTenantId': group['id'], | |
| } | |
| #Create the JSON payload for the POST | |
| #This is where params are added to the json payload | |
| payload = json.loads(template.render(params=params)) | |
| #Attempt to create each reservation. Catch any errors and continue | |
| try: | |
| reservation = client.createReservation(payload) | |
| print "Reservation created: {id}".format(id=reservation) | |
| except Exception, e: | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment