chelnak
7/29/2015 - 2:23 PM

createCloudClientScript.py

#!/usr/bin/python
import json

#full path to cloudclient
cloudClientPath = '/PATH_TO_CLOUD_CLIENT/bin/cloudclient.sh'
#Path to your prefix json file. If just the filename, it will look in the script directory
prefixJSONFile = 'vra-machineprefixes.json'
#Path to the resulting script file. If just the filename, it will look in the script directory
prefixScriptFile = 'machineprefix-cloudclient-commands.sh'

#Open up the file we exported earlier and parse it with json.load
with open(prefixJSONFile, 'r') as json_data:
    machinePrefixes = json.load(json_data)

#Open a new file and write out each command
with open(prefixScriptFile, 'w') as f:

    f.write('export CLOUDCLIENTPATH={path}\n'.format(path=cloudClientPath))

    for i in machinePrefixes['Items']:
        f.write(
            '$CLOUDCLIENTPATH vra machineprefix add --prefix {prefix} --numberOfDigits {numberOfDigits} --nextNumber {nextNumber}\n'.format(
                prefix=i['Prefix'],
                numberOfDigits=i['NumberOfDigits'],
                nextNumber=i['NextNumber']))

    f.close()