import sys,argparse,json,time
sys.path.insert(0, './classes/')

import cohesityAPI as cohesity

mdn = cohesity.API('itdmdndpc01.nd.gov')
mdnToken = mdn.GetAuthToken()
mdn.UpdateHeaders(mdnToken['accessToken'])

# Block Update all SQL jobs with new SQL policy
sqlPolicyName = mdn.GetFilteredRequest("/public/protectionPolicies", "?names=ITD-SQL")

sqlProtectionJobs = mdn.GetFilteredRequest("/public/protectionJobs", "?environments=kSQL")
uniqueJobs = {job['id'] : job for job in sqlProtectionJobs}.values()

isPaused=bool('false')

for job in uniqueJobs:
   resp = mdn.UpdateProtectionJob(job['sourceIds'],job['parentSourceId'], job['name'], sqlPolicyName[0]['id'], job['viewBoxId'], job['id'], isPaused)
   print(resp.content)
#End SQL Policy Update Block
