def activateVersion(version_number, env="STAGING"): # "notifyEmails" is unfortunately required for this API call. # TODO: Find a better email for this and release me from this torture body = { "note": "Auto-generated activation", "useFastFallback": "false", "notifyEmails": ["*****@*****.**"] } body["propertyVersion"] = version_number body["network"] = env print("API - Activating version {} on {}...".format(version_number, env)) response = json.loads( util.akamaiPost( "/papi/v1/properties/prp_516561/activations?contractId=ctr_3-1MMN3Z&groupId=grp_134508", body)) err = False # If there are any warnings in the property, it'll return a status 400 with a list of warnings. # Acknowledging these warnings in the request body will allow the activation to work. if "activationLink" in response: print("Wow, first try! Version {} activated on {}.".format( version_number, env)) elif "status" in response and response[ "status"] == 400 and "warnings" in response: warnings = [] for w in response["warnings"]: warnings.append(w["messageId"]) body["acknowledgeWarnings"] = warnings print("API - First activation request gave warnings. Acknowledging...") response = json.loads( util.akamaiPost( "/papi/v1/properties/prp_516561/activations?contractId=ctr_3-1MMN3Z&groupId=grp_134508", body)) # If it fails again, give up. if "activationLink" in response: print("Success! Version {} activated on {}.".format( version_number, env)) else: err = True print( "Something went wrong while acknowledging warnings. Here's the response we got:" ) else: err = True print( "Something went wrong on the first activation attempt. Here's the response we got:" ) if err: print(json.dumps(response)) print( "The activaction failed. Please check out the above response to see what happened." )
def createNewVersion(crc_env="stage", property_env="STAGING"): # Get the number of the latest prod version to use as a base previous_version = util.getLatestVersionNumber(crc_env, property_env) # Save this number for later: create a file that contains the latest version number with open("previousversion.txt", "w") as f: f.write(str(previous_version)) body = {"createFromVersion": previous_version} print("API - Creating new version based on v{}".format(previous_version)) response_content = json.loads( util.akamaiPost( "/papi/v1/properties/{}/versions?contractId=ctr_3-1MMN3Z&groupId=grp_134508" .format(util.getPropertyIDForEnv(crc_env)), body)) new_version = 0 m = re.search('versions\/(.+?)\?contractId', response_content["versionLink"]) if m: new_version = m.group(1) print("Version {} created.".format(new_version)) # Save this number for later: create a file that contains the new version number with open("newversion.txt", "w") as f: f.write(str(new_version)) return new_version
def createNewVersion(): # Get the number of the latest prod version to use as a base latest_prod_version = getLatestVersionNumber("PRODUCTION") body = { "createFromVersion": latest_prod_version } print("API - Creating new version based on v{}".format(latest_prod_version)) response_content = json.loads(util.akamaiPost("/papi/v1/properties/prp_516561/versions?contractId=ctr_3-1MMN3Z&groupId=grp_134508",body)) new_version = 0 m = re.search('versions\/(.+?)\?contractId', response_content["versionLink"]) if m: new_version = m.group(1) print("Version {} created.".format(new_version)) return new_version