def changeInstanceStatus (stmName,status): updateinstance={ "status": status, } uri=getSSCURI() url = uri+'instance/'+stmName jsontype = {'content-type': 'application/json'} client = sscConnection() try: #First see if the stm already exists response = client.get(url) except requests.exceptions.ConnectionError: print "Error: Unable to connect to " + url sys.exit(1) if (response.status_code == 404): print 'stm %s does not exist' %(stmName) else: if response.status_code == 200: print "stm %s exists" %(stmName) print "action "+status response = client.put(url, data = json.dumps(updateinstance), headers = jsontype) if response.status_code == 200: # When updating a new resource we expect to get a 200 print 'stm %s status changed' %(stmName) print response.content elif response.status_code == 400: # when its already delete inactive expect 400 data = json.loads(response.content) print "Error changing status of instance %s: URL=%s Status=%d Id=%s: %s" %(stmName, url, response.status_code, data['error_id'], data['error_text']) else: data = json.loads(response.content) print "Error changing status of instance %s: URL=%s Status=%d Id=%s: %s" %(stmName, url, response.status_code, data['error_id'], data['error_info']) else: print "Error: Status=%d URL=%s" %(response.status_code, url)
def addLic(ljson,license): uri=getSSCURI() url = uri+'license/' + license jsontype = {'content-type': 'application/json'} client = sscConnection() try: #First see if the license resource already exists response = client.get(url) except requests.exceptions.ConnectionError: print "Error: Unable to connect to " + url sys.exit(1) if (response.status_code == 404): response = client.put(url, data = json.dumps(ljson), headers = jsontype) if response.status_code == 201: # When creating a new resource we expect to get a 201 print 'license %s added' %(license) response = client.get(url) print response.content else: data = json.loads(response.content) print "Error adding instance %s: URL=%s Status=%d Id=%s: %s" %(license, url, response.status_code, data['error_id'], data['error_info']) else: if response.status_code == 200: print "license %s already exists" %(license) else: print "Error: Status=%d URL=%s" %(response.status_code, url)
def addHost(stmName): # adds instacne in host resource, its needed. hostjson={"install_root": "/data/stminstall", "work_location": "/var/cache/ssc", "username": "******"} uri=getSSCURI() url = uri+'host/'+stmName jsontype = {'content-type': 'application/json'} client = sscConnection() try: #First see if the host entry already exists response = client.get(url) except requests.exceptions.ConnectionError: print "Error: Unable to connect to " + url sys.exit(1) if (response.status_code == 401): print response.content sys.exit(1) if (response.status_code == 404): response = client.put(url, data = json.dumps(hostjson), headers = jsontype) if response.status_code == 201: # When creating a new resource we expect to get a 201 print 'host resource for stm %s added' %(stmName) print response.content else: data = json.loads(response.content) print "Error adding host resource %s: URL=%s Status=%d Id=%s: %s" %(stmName, url, response.status_code, data['error_id'], data['error_info']) else: if response.status_code == 200: print "host resource %s already exists, continue creating instance" %(stmName) else: print "Error: Status=%d URL=%s" %(response.status_code, url)
def addFeature(fjson,fpack): client=sscConnection() uri=getSSCURI() url = uri+'feature_pack/'+fpack jsontype = {'content-type': 'application/json'} try: #First see if the fpack resource already exists response = client.get(url) except requests.exceptions.ConnectionError: print "Error: Unable to connect to " + url sys.exit(1) if (response.status_code == 404): response = client.put(url, data = json.dumps(fjson), headers = jsontype) if response.status_code == 201: # When creating a new resource we expect to get a 201 print 'fpack %s added' %(fpack) response = client.get(url) print response.content else: data = json.loads(response.content) print "Error adding feature pack %s: URL=%s Status=%d Id=%s: %s" %(fpack, url, response.status_code, data['error_id'], data['error_info']) else: if response.status_code == 200: print "fpack %s already exists" %(fpack) else: print "Error: Status=%d URL=%s" %(response.status_code, url)
def addInstance(stmName,instancejson, updatejson): # need a entry for this non-maanaged hsot in host resource. addHost(stmName) uri=getSSCURI() url = uri+'instance/'+stmName+'?managed=false' jsontype = {'content-type': 'application/json'} client = sscConnection() try: #First see if the stm already exists response = client.get(url) except requests.exceptions.ConnectionError: print "Error: Unable to connect to " + url sys.exit(1) if (response.status_code == 404): response = client.put(url, data = json.dumps(instancejson), headers = jsontype) if response.status_code == 201: # When creating a new resource we expect to get a 201 print 'instance resource for %s added' %(stmName) print response.content else: data = json.loads(response.content) print "Error adding instance %s: URL=%s Status=%d Id=%s: %s" %(stmName, url, response.status_code, data['error_id'], data['error_info']) else: if response.status_code == 200: print "instance resource %s already exists, updating" %(stmName) response = client.put(url, data = json.dumps(updatejson), headers = jsontype) if response.status_code == 200: # When update a new resource we expect to get a 200 print 'instance resource %s updated' %(stmName) printjson(response.content) elif response.status_code == 400: # when its already delete / inactive expect 400, you cannot update a delete instance print 'stm %s deleted or inactive cannot udpate a deleted instance' %(stmName) printjson(response.content) data = json.loads(response.content) print "Error adding instance %s: URL=%s Status=%d Id=%s: %s" %(stmName, url, response.status_code, data['error_id'], data['error_text']) else: data = json.loads(response.content) print "Error adding instance %s: URL=%s Status=%d Id=%s: %s" %(stmName, url, response.status_code, data['error_id'], data['error_info']) else: print "Error: Status=%d URL=%s" %(response.status_code, url)