def delete_volume(request,instanceid): credential_username = request.user.cnextpublickey credential_password = cloud_mongo.trail.encode_decode(request.user.cnextprivatekey,"decode") endpoint = request.user.cnextendpoint httpInst = httplib2.Http() httpInst.add_credentials(name = credential_username, \ password = credential_password) url=endpoint + "/api/instance/"+instanceid resp, body = httpInst.request(url, method = "DELETE") LOG.debug("Inside Delete Volume Status %s" % resp.status) if resp.status == 200: time.sleep(2) body = json.loads(body) a = body['requestId'] acount = 0 def check_call(endpoint,reqid): url =endpoint +'/api/request/' + reqid resp, body = httpInst.request(url) body = json.loads(body) return body body = check_call(endpoint,a) while (body[0]["requestStatus"] != "completed" ): if (body[0]["requestStatus"] == "failed"): return False else: time.sleep(1.5) body = check_call(endpoint,body[0]['requestId']) acount += 1 time.sleep(1) code.refresh(request,instanceid) return True else: return False
def dettach(request, instanceid, vmid, device): try: credential_username = request.user.cnextpublickey credential_password = cloud_mongo.trail.encode_decode( request.user.cnextprivatekey, "decode") endpoint = request.user.cnextendpoint httpInst = httplib2.Http() httpInst.add_credentials(name = credential_username, \ password = credential_password) h = {"content-type": "application/json"} body = {"virtualMachineId": vmid, "deviceName": device} b = json.dumps(body) url = endpoint + "/api/instance/" + instanceid + "?action=detach" time.sleep(1) resp, body = httpInst.request(url, method="PUT", body=b, headers=h) LOG.debug("Inside Volume Detach Status %s" % resp.status) dd = json.loads(body) acount = 0 a = dd["requestId"] def check_call(endpoint, reqid): url = endpoint + '/api/request/' + reqid resp, body = httpInst.request(url) body = json.loads(body) return body time.sleep(1) body = check_call(endpoint, a) while (body[0]["requestStatus"] != "completed"): if (body[0]["requestStatus"] == "failed"): return False else: time.sleep(1.5) body = check_call(endpoint, body[0]['requestId']) acount += 1 time.sleep(1) code.refresh(request, instanceid) return True except: print "inside exception of attach to vm api call" return False
def dettach(request,instanceid,vmid,device): try: credential_username = request.user.cnextpublickey credential_password = cloud_mongo.trail.encode_decode(request.user.cnextprivatekey,"decode") endpoint = request.user.cnextendpoint httpInst = httplib2.Http() httpInst.add_credentials(name = credential_username, \ password = credential_password) h = {"content-type": "application/json"} body={"virtualMachineId":vmid,"deviceName":device} b=json.dumps(body) url=endpoint + "/api/instance/"+instanceid+"?action=detach" time.sleep(1) resp, body = httpInst.request(url, method = "PUT", body = b, headers = h) LOG.debug("Inside Volume Detach Status %s" % resp.status) dd = json.loads(body) acount = 0 a = dd["requestId"] def check_call(endpoint,reqid): url =endpoint +'/api/request/' + reqid resp, body = httpInst.request(url) body = json.loads(body) return body time.sleep(1) body = check_call(endpoint,a) while (body[0]["requestStatus"] != "completed" ): if (body[0]["requestStatus"] == "failed"): return False else: time.sleep(1.5) body = check_call(endpoint,body[0]['requestId']) acount += 1 time.sleep(1) code.refresh(request,instanceid) return True except: print "inside exception of attach to vm api call" return False
def delete_volume(request, instanceid): credential_username = request.user.cnextpublickey credential_password = cloud_mongo.trail.encode_decode( request.user.cnextprivatekey, "decode") endpoint = request.user.cnextendpoint httpInst = httplib2.Http() httpInst.add_credentials(name = credential_username, \ password = credential_password) url = endpoint + "/api/instance/" + instanceid resp, body = httpInst.request(url, method="DELETE") LOG.debug("Inside Delete Volume Status %s" % resp.status) if resp.status == 200: time.sleep(2) body = json.loads(body) a = body['requestId'] acount = 0 def check_call(endpoint, reqid): url = endpoint + '/api/request/' + reqid resp, body = httpInst.request(url) body = json.loads(body) return body body = check_call(endpoint, a) while (body[0]["requestStatus"] != "completed"): if (body[0]["requestStatus"] == "failed"): return False else: time.sleep(1.5) body = check_call(endpoint, body[0]['requestId']) acount += 1 time.sleep(1) code.refresh(request, instanceid) return True else: return False