in UpdateBlueprint.py [0:0]
def update(launchtype, session, headers, endpoint, HOST, projectId, machinelist, configfile, dryrun):
if launchtype == "test" or launchtype == "cutover":
with open(os.path.join(sys.path[0], configfile), 'r') as ymlfile:
config = yaml.load(ymlfile)
else:
print("Invalid Launch Type !")
try:
b = requests.get(HOST + endpoint.format('projects/{}/blueprints').format(projectId), headers=headers, cookies=session)
for blueprint in json.loads(b.text)["items"]:
machineName = machinelist[blueprint["machineId"]]
for i in range(1, config["project"]["machinecount"]+1):
index = "machine" + str(i)
if config[index]["machineName"] == machineName:
url = endpoint.format('projects/{}/blueprints/').format(projectId) + blueprint['id']
blueprint["instanceType"] = config[index]["instanceType"]
blueprint["tenancy"] = config[index]["tenancy"]
if config[index]["iamRole"].lower() != "none":
blueprint["iamRole"] = config[index]["iamRole"]
for disk in blueprint["disks"]:
blueprint["disks"] = [{"type":"SSD", "name":disk["name"]}]
existing_subnetId = blueprint["subnetIDs"]
existing_SecurityGroupIds = blueprint["securityGroupIDs"]
blueprint["subnetIDs"] = config[index]["subnetIDs"]
blueprint["securityGroupIDs"] = config[index]["securitygroupIDs"]
blueprint["publicIPAction"] = 'DONT_ALLOCATE'
blueprint["privateIPAction"] = 'CREATE_NEW'
tags = []
# Update machine tags
for i in range(1, config[index]["tags"]["count"]+1):
keytag = "key" + str(i)
valuetag = "value" + str(i)
tag = {"key":config[index]["tags"][keytag], "value":config[index]["tags"][valuetag]}
tags.append(tag)
existing_tag = blueprint["tags"]
blueprint["tags"] = tags
result = requests.patch(HOST + url, data=json.dumps(blueprint), headers=headers, cookies=session)
if result.status_code != 200:
print("ERROR: Updating blueprint failed for machine: " + machineName +", invalid blueprint config....")
if dryrun == "Yes":
print("ERROR: YAML validation failed, please fix the errors in the cutover YAML file")
sys.exit(4)
machinelist[blueprint["machineId"]] = "updated"
print("Blueprint for machine: " + machineName + " updated....")
if dryrun == "Yes":
blueprint["subnetIDs"] = existing_subnetId
blueprint["securityGroupIDs"] = existing_SecurityGroupIds
blueprint["tags"] = existing_tag
result = requests.patch(HOST + url, data=json.dumps(blueprint), headers=headers, cookies=session)
if result.status_code != 200:
print("ERROR: Failed to roll back subnet,SG and tags for machine: " + machineName +"....")
sys.exit(5)
else:
print("Dryrun was successful for machine: " + machineName +"...." )
except:
print("ERROR: Updating blueprint task failed....")
print(sys.exc_info())
sys.exit(3)