def modify_auto_scaling_group(): if (OtcConfig.SCALINGGROUP_ID is None) and not (OtcConfig.SCALINGGROUP_NAME is None): autoscaling.convertASNameToId() #print(SCALINGGROUP_NAME) #vpc_id if not (OtcConfig.VPCNAME is None): getplugin("ecs").convertVPCNameToId() #scaling_configuration_id if not (OtcConfig.SCALING_CONFIGURATION_NAME is None): autoscaling.convertASConfigurationNameToId() #lb_listener_id if not (OtcConfig.LISTENER_NAME is None): autoscaling.convertLISTENERNameToId() #network_id if not OtcConfig.SUBNETNAME is None: getplugin("ecs").convertSUBNETNameToId() #security_group_id if not OtcConfig.SECUGROUPNAME is None: getplugin("ecs").convertSECUGROUPNameToId() #print(OtcConfig.SECUGROUPNAME) #print(OtcConfig.SECUGROUP) REQ_CREATE_SCG=utils_templates.create_request("modify_as_group") url = "https://" + OtcConfig.DEFAULT_HOST+ "/autoscaling-api/v1/" + OtcConfig.PROJECT_ID + "/scaling_group/"+ OtcConfig.SCALINGGROUP_ID ret = utils_http.put(url, REQ_CREATE_SCG) autoscaling.otcOutputHandler().print_output(ret,mainkey="") #print(REQ_CREATE_SCG) return ret
def modify_service(): if OtcConfig.CLUSTER: cce.convertClusterNameToId() url = "https://" + OtcConfig.DEFAULT_HOST + "/api/v1/namespaces/" + OtcConfig.NAMESPACE + "/services/" + OtcConfig.SERVICE_NAME req = utils_templates.create_request("cce_create_service") ret = utils_http.put(url, req) cce.otcOutputHandler().print_output(ret, mainkey="") return ret
def modify_service(): if OtcConfig.CLUSTER: cce.convertClusterNameToId() url = "https://" + OtcConfig.DEFAULT_HOST + "/api/v1/namespaces/" + OtcConfig.NAMESPACE + "/services/" + OtcConfig.SERVICE_NAME req = utils_templates.create_request("cce_create_service") ret = utils_http.put(url, req) cce.otcOutputHandler().print_output(ret,mainkey="") return ret
def associate_address(): REQ_ASSOCIATE_PUBLICIP = "{ \"publicip\": { \"port_id\": \"" + OtcConfig.NETWORKINTERFACEID + "\" } }" #print REQ_ASSOCIATE_PUBLICIP if not (OtcConfig.PUBLICIP is None): ecs.convertPublicIpNameToId() url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1/" + OtcConfig.PROJECT_ID + "/publicips" + "/" + OtcConfig.PUBLICIPID ret = utils_http.put(url, REQ_ASSOCIATE_PUBLICIP) print(ret) return ret
def modify_rc(): if OtcConfig.CLUSTER: cce.convertClusterNameToId() url = "https://" + OtcConfig.DEFAULT_HOST + "/api/v1/namespaces/" + OtcConfig.NAMESPACE + "/replicationcontrollers/" + OtcConfig.RC_NAME req = utils_templates.create_request("cce_create_rc") #print req ret = utils_http.put(url, req) cce.otcOutputHandler().print_output(ret, mainkey="") return ret
def associate_address(): REQ_ASSOCIATE_PUBLICIP = "{ \"publicip\": { \"port_id\": \"" + OtcConfig.NETWORKINTERFACEID + "\" } }" #print REQ_ASSOCIATE_PUBLICIP if not (OtcConfig.PUBLICIP is None): ecs.convertPublicIpNameToId() url = ecs.baseurl+ "/v1/" + OtcConfig.PROJECT_ID + "/publicips" + "/" + OtcConfig.PUBLICIPID ret = utils_http.put(url, REQ_ASSOCIATE_PUBLICIP) print(ret) return ret
def modify_rc(): if OtcConfig.CLUSTER: cce.convertClusterNameToId() url = "https://" + OtcConfig.DEFAULT_HOST + "/api/v1/namespaces/" + OtcConfig.NAMESPACE + "/replicationcontrollers/" + OtcConfig.RC_NAME req = utils_templates.create_request("cce_create_rc") #print(req) ret = utils_http.put(url, req) cce.otcOutputHandler().print_output(ret,mainkey="") return ret
def modify_health_check(): if not (OtcConfig.LISTENER_NAME is None): elb.convertLISTENERNameToId() url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1.0/" + OtcConfig.PROJECT_ID + "/elbaas/healthcheck/" + OtcConfig.HEALTHCHECK_ID REQ_MODIFY_HEALTH_CHECK=utils_templates.create_request("modify_information_health_check_task") ret = utils_http.put(url, REQ_MODIFY_HEALTH_CHECK) print(ret) return ret
def update_jobbinary(): if not (OtcConfig.JOBBINARY is None): getplugin("sahara").convertJOBBINARYNameToId() url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.1/"+ OtcConfig.PROJECT_ID +"/job-binaries/" + OtcConfig.JOBBINARY_ID REQ_UPDADTE_JOBBINARY=utils_templates.create_request("update_jobbinary") ret = utils_http.put(url, REQ_UPDADTE_JOBBINARY) print (url) print (ret) sahara.otcOutputHandler().print_output(ret, mainkey = "")
def update_jobbinary(): if not (OtcConfig.JOBBINARY is None): getplugin("sahara").convertJOBBINARYNameToId() url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.1/" + OtcConfig.PROJECT_ID + "/job-binaries/" + OtcConfig.JOBBINARY_ID REQ_UPDADTE_JOBBINARY = utils_templates.create_request( "update_jobbinary") ret = utils_http.put(url, REQ_UPDADTE_JOBBINARY) print(url) print(ret) sahara.otcOutputHandler().print_output(ret, mainkey="")
def restart_instance(): OtcConfig.DCS_ACTION = "restart" REQ_UPDATE_DCS = utils_templates.create_request("update_instance") #print (REQ_UPDATE_DCS) url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.0/" + OtcConfig.PROJECT_ID + "/instances/status" url = url.replace('iam', 'dcs') #print (url) ret = utils_http.put(url, REQ_UPDATE_DCS) #print (ret) return ret
def modify_health_check(): if not (OtcConfig.LOADBALANCER_NAME is None): elb.convertELBNameToId() if not (OtcConfig.HEALTHCHECK_ID is None): elb.convertLISTENERIdToHealthCheckId() url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1.0/" + OtcConfig.PROJECT_ID + "/elbaas/healthcheck/" + OtcConfig.HEALTHCHECK_ID REQ_MODIFY_HEALTH_CHECK=utils_templates.create_request("modify_information_health_check_task") ret = utils_http.put(url, REQ_MODIFY_HEALTH_CHECK) print(ret) return ret
def restart_instance(): OtcConfig.DCS_ACTION = "restart" REQ_UPDATE_DCS=utils_templates.create_request("update_instance") #print (REQ_UPDATE_DCS) url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.0/" + OtcConfig.PROJECT_ID + "/instances/status" url = url.replace('iam', 'dcs') #print (url) ret = utils_http.put(url, REQ_UPDATE_DCS ) #print (ret) return ret
def modify_auto_scaling_policy(): if not (OtcConfig.SCALINGGROUP_NAME is None): autoscaling.convertASNameToId() if not (OtcConfig.SCALING_POLICY_NAME is None): autoscaling.convertASPolicyNameToId() REQ_CREATE_SCP=utils_templates.create_request("modify_as_policy") #print(REQ_CREATE_SCP) url = "https://" + OtcConfig.DEFAULT_HOST+ "/autoscaling-api/v1/" + OtcConfig.PROJECT_ID + "/scaling_policy/" + OtcConfig.SCALING_POLICY_ID #print(url) ret = utils_http.put(url, REQ_CREATE_SCP) autoscaling.otcOutputHandler().print_output(ret,mainkey="") return ret
def update_datasource(): if not (OtcConfig.DATASOURCE_ID is None): getplugin("sahara").convertDATASOURCENameToId() url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.1/"+ OtcConfig.PROJECT_ID +"/data-sources/" + OtcConfig.DATASOURCE_ID REQ_UPDADTE_DATASORCE=utils_templates.create_request("update_datasource") ret = utils_http.put(url, REQ_UPDADTE_DATASORCE) print(REQ_UPDADTE_DATASORCE) print (url) print (ret) sahara.otcOutputHandler().print_output(ret, mainkey = "")
def register_image(): if not (OtcConfig.IMAGENAME is None): getplugin("ecs").convertIMAGENameToId() if OtcConfig.IMAGE_ID is None: # error handling raise RuntimeError("Please define image id!") # image id filled until now url = "https://" + OtcConfig.DEFAULT_HOST + "/v2/images/" + OtcConfig.IMAGE_ID + "/file" REQ_REG_IMAGE = "{\"image_url\":\"" + OtcConfig.IMAGE_URL + "\" }" ret = utils_http.put(url, REQ_REG_IMAGE) if len(ret) != 0: print("Image registration error!" + ret) return ret
def update_datasource(): if not (OtcConfig.DATASOURCE_ID is None): getplugin("sahara").convertDATASOURCENameToId() url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.1/" + OtcConfig.PROJECT_ID + "/data-sources/" + OtcConfig.DATASOURCE_ID REQ_UPDADTE_DATASORCE = utils_templates.create_request( "update_datasource") ret = utils_http.put(url, REQ_UPDADTE_DATASORCE) print REQ_UPDADTE_DATASORCE print(url) print(ret) sahara.otcOutputHandler().print_output(ret, mainkey="")
def register_image(): if not (OtcConfig.IMAGENAME is None): ecs.convertIMAGENameToId() if OtcConfig.IMAGE_ID is None: # error handling raise RuntimeError("Please define image id!") # image id filled until now url = ims.baseurl + "/v2/images/" + OtcConfig.IMAGE_ID + "/file" REQ_REG_IMAGE = "{\"image_url\":\"" + OtcConfig.IMAGE_URL + "\" }" ret = utils_http.put(url, REQ_REG_IMAGE) if len(ret) != 0: print ("Image registration error!" + ret) return ret
def modify_load_balancers(): if not (OtcConfig.LOADBALANCER_NAME is None): elb.convertELBNameToId() if not (OtcConfig.VPCNAME is None): getplugin("ecs").convertVPCNameToId() REQ_MODIFY_ELB=utils_templates.create_request("modify_load_balancer") url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1.0/" + OtcConfig.PROJECT_ID + "/elbaas/loadbalancers/" + OtcConfig.LOADBALANCER_ID print (REQ_MODIFY_ELB) ret = utils_http.put(url, REQ_MODIFY_ELB) print(ret) maindata = json.loads(ret) if "code" in maindata: print("Can not modify:" +maindata["message"]) os._exit( 1 ) print("created") return ret
def modify_load_balancers(): if not (OtcConfig.LOADBALANCER_NAME is None): elb.convertELBNameToId() if not (OtcConfig.VPCNAME is None): getplugin("ecs").convertVPCNameToId() REQ_MODIFY_ELB = utils_templates.create_request("modify_load_balancer") url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.0/" + OtcConfig.PROJECT_ID + "/elbaas/loadbalancers/" + OtcConfig.LOADBALANCER_ID print(REQ_MODIFY_ELB) ret = utils_http.put(url, REQ_MODIFY_ELB) print(ret) maindata = json.loads(ret) if "code" in maindata: print("Can not modify:" + maindata["message"]) os._exit(1) print("created") return ret
def modify_listeners(): #if not (OtcConfig.LOADBALANCER_NAME is None): # elb.convertELBNameToId() #if not (OtcConfig.VPCNAME is None): # getplugin("ecs").convertVPCNameToId() if not (OtcConfig.LISTENER_NAME is None): elb.convertLISTENERNameToId() #REQ_CREATE_LISTENER = "{ \"name\":\"listener1\", \"description\":\"\", \"loadbalancer_id\":\"0b07acf06d243925bc24a0ac7445267a\", \"protocol\":\"HTTP\", \"port\":88, \"backend_protocol\":\"HTTP\", \"backend_port\":80, \"lb_algorithm\":\"roundrobin\", \"session_sticky\":true, \"sticky_session_type\":\"insert\", \"cookie_timeout\":100 }" REQ_MODIFY_LISTENER=utils_templates.create_request("modify_information_listener") url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1.0/" + OtcConfig.PROJECT_ID + "/elbaas/listeners/"+ OtcConfig.LISTENER_ID ret = utils_http.put(url, REQ_MODIFY_LISTENER) print( ret ) maindata = json.loads(ret) if "code" in maindata: print("Can not create:" +maindata["message"]) os._exit( 1 ) print( ret ) #ecs.otcOutputHandler().print_output(ret, mainkey="loadbalancer") return ret
def modify_listeners(): #if not (OtcConfig.LOADBALANCER_NAME is None): # elb.convertELBNameToId() #if not (OtcConfig.VPCNAME is None): # getplugin("ecs").convertVPCNameToId() if not (OtcConfig.LISTENER_NAME is None): elb.convertLISTENERNameToId() #REQ_CREATE_LISTENER = "{ \"name\":\"listener1\", \"description\":\"\", \"loadbalancer_id\":\"0b07acf06d243925bc24a0ac7445267a\", \"protocol\":\"HTTP\", \"port\":88, \"backend_protocol\":\"HTTP\", \"backend_port\":80, \"lb_algorithm\":\"roundrobin\", \"session_sticky\":true, \"sticky_session_type\":\"insert\", \"cookie_timeout\":100 }" REQ_MODIFY_LISTENER = utils_templates.create_request( "modify_information_listener") url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.0/" + OtcConfig.PROJECT_ID + "/elbaas/listeners/" + OtcConfig.LISTENER_ID ret = utils_http.put(url, REQ_MODIFY_LISTENER) print(ret) maindata = json.loads(ret) if "code" in maindata: print("Can not create:" + maindata["message"]) os._exit(1) print(ret) #ecs.otcOutputHandler().print_output(ret, mainkey="loadbalancer") return ret