def create_vpc(): REQ_CREATE_VPC = "{ \"vpc\": { \"name\": \"" + OtcConfig.VPCNAME + "\", \"cidr\": \"" + OtcConfig.CIDR + "\" } }" url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1/" + OtcConfig.PROJECT_ID + "/vpcs" ret = utils_http.post(url, REQ_CREATE_VPC) print(ret) return ret
def create_instance(): if not OtcConfig.VPCNAME is None: getplugin("ecs").convertVPCNameToId() if not OtcConfig.SUBNETNAME is None: getplugin("ecs").convertSUBNETNameToId() if not OtcConfig.SECUGROUPNAME is None: getplugin("ecs").convertSECUGROUPNameToId() if not OtcConfig.AZ is None: dcs.convertAZnameToId() if OtcConfig.INSTANCE_TYPE_NAME is None: OtcConfig.INSTANCE_TYPE_NAME = "OTC_DCS_SINGLE:1" if OtcConfig.INSTANCE_NAME is None: OtcConfig.INSTANCE_NAME = "dcs" (OtcConfig.INSTANCE_DCS_TYPE,OtcConfig.INSTANCE_DCS_SIZE) = str(OtcConfig.INSTANCE_TYPE_NAME).split(':') REQ_CREATE_DCS=utils_templates.create_request("create_instance") #print (REQ_CREATE_DCS) url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.0/" + OtcConfig.PROJECT_ID + "/instances" url = url.replace('iam', 'dcs') #print (url) ret = utils_http.post(url, REQ_CREATE_DCS ) print (ret) return ret
def create_cluster(): url = "https://" + OtcConfig.DEFAULT_HOST + "/rds/v1/"+ OtcConfig.PROJECT_ID +"/instances" url = url.replace('iam', 'rds') # url = string.replace(url, 'iam', 'rds') #vpc_id if not (OtcConfig.VPCNAME is None): getplugin("ecs").convertVPCNameToId() #network_id if not OtcConfig.SUBNETNAME is None: getplugin("ecs").convertSUBNETNameToId() if (not (OtcConfig.SECUGROUPNAME is None)): getplugin("ecs").convertSECUGROUPNameToId() if (OtcConfig.DBTYPE is None): OtcConfig.DBTYPE = "MySQL" if (OtcConfig.DBVERSION is None): OtcConfig.DBVERSION = "5.7.20" if (OtcConfig.DISK_SIZE is None): OtcConfig.DISK_SIZE = 100 if (OtcConfig.DISK_TYPE is None): OtcConfig.DISK_TYPE = "COMMON" REQ_CREATE_CLUSTER=utils_templates.create_request("create_cluster") ret = utils_http.post(url, REQ_CREATE_CLUSTER) print(REQ_CREATE_CLUSTER) rds.otcOutputHandler().print_output(ret, mainkey = "")
def add_nodes(): REQ_ADD_NODE=utils_templates.create_request("add_node") url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.1/"+ OtcConfig.PROJECT_ID +"/cluster_infos/" + OtcConfig.CLUSTER_ID ret = utils_http.post(url, REQ_ADD_NODE) print (url) print (ret) mrs.otcOutputHandler().print_output(ret, mainkey = "")
def _secgrouprulecreate(): if not (OtcConfig.VPCNAME is None): ecs.convertVPCNameToId() if not (OtcConfig.SECUGROUPNAME is None): ecs.convertSECUGROUPNameToId() sourceIp = "" if not OtcConfig.CIDR is None: sourceIp = "\", \"remote_ip_prefix\":\"" + OtcConfig.CIDR remoteGroup = "" if not OtcConfig.SOURCE_GROUP_ID is None: remoteGroup = "\", \"remote_group_id\":\"" + OtcConfig.SOURCE_GROUP_ID portrange = "" if not OtcConfig.PORTMIN is None and not OtcConfig.PORTMAX is None: portrange = "\", \"port_range_min\":\"" + OtcConfig.PORTMIN + "\", \"port_range_max\":\"" ''+ OtcConfig.PORTMAX REQ_CREATE_SECGROUPRULE = "{\"security_group_rule\":{ \"direction\":\"" + OtcConfig.DIRECTION + "\",\"ethertype\":\"" + OtcConfig.ETHERTYPE + "\", \"protocol\":\""+ OtcConfig.PROTOCOL+ portrange +remoteGroup + sourceIp+ "\" , \"security_group_id\":\""+ OtcConfig.SECUGROUP + "\" } }" #REQ_CREATE_SECGROUPRULE = "{\"security_group_rule\":{ \"direction\":\"" + OtcConfig.DIRECTION + "\", \"port_range_min\":\"" + OtcConfig.PORTMIN + "\", \"ethertype\":\"" + OtcConfig.ETHERTYPE + "\", \"port_range_max\":\"" ''+ OtcConfig.PORTMAX+ "\", \"protocol\":\""+ OtcConfig.PROTOCOL+ remoteGroup + sourceIp+ "\" , \"security_group_id\":\""+ OtcConfig.SECUGROUP + "\" } }" url = "https://" + OtcConfig.DEFAULT_HOST+ "/v2.0/security-group-rules" ret = utils_http.post(url, REQ_CREATE_SECGROUPRULE) #print REQ_CREATE_SECGROUPRULE print (ret) ecs.otcOutputHandler().print_output(ret, mainkey="security_group_rule") return ret
def create_volume(): REQ_CREATE_CLOUDVOLUMES = "{ \"volume\": { \"backup_id\": " + OtcConfig.SNAPSHOTID + ", " + "\"count\": " + OtcConfig.NUMCOUNT + ", \"availability_zone\": \"" + OtcConfig.AZ + "\",\"description\": \"" + OtcConfig.VOLUME_NAME + "\", \"size\": " + OtcConfig.VOLUME_SIZE + ", \"name\": \"" + OtcConfig.VOLUME_NAME + "\", \"imageRef\": " + "null" + ", \"volume_type\": \"" + OtcConfig.VOLUME_TYPE + "\" } }" #print REQ_CREATE_CLOUDVOLUMES url = "https://" + OtcConfig.DEFAULT_HOST+ "/v2/" + OtcConfig.PROJECT_ID + "/cloudvolumes" ret = utils_http.post(url, REQ_CREATE_CLOUDVOLUMES) print(ret) return ret
def attach_volume(): """ generated source for method AttachVolume """ REQ_ATTACH_CLOUDVOLUMES = "{ \"volumeAttachment\": { \"volumeId\": \"" + OtcConfig.VOLUME_ID + "\", \"device\": \"" + OtcConfig.EVS_DEVICE + "\" } }" url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1/" + OtcConfig.PROJECT_ID + "/cloudservers/" + OtcConfig.INSTANCE_ID + "/attachvolume" ret = utils_http.post(url, REQ_ATTACH_CLOUDVOLUMES) print(ret) return ret
def add_nodes(): REQ_ADD_NODE = utils_templates.create_request("add_node") url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.1/" + OtcConfig.PROJECT_ID + "/cluster_infos/" + OtcConfig.CLUSTER_ID ret = utils_http.post(url, REQ_ADD_NODE) print(url) print(ret) sahara.otcOutputHandler().print_output(ret, mainkey="")
def create_vpc(): REQ_CREATE_VPC = "{ \"vpc\": { \"name\": \"" + OtcConfig.VPCNAME + "\", \"cidr\": \"" + OtcConfig.CIDR + "\" } }" url = ecs.baseurl+ "/v1/" + OtcConfig.PROJECT_ID + "/vpcs" ret = utils_http.post(url, REQ_CREATE_VPC) print(ret) return ret
def add_job(): REQ_ADD_JOB = utils_templates.create_request("add_job") url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.1/" + OtcConfig.PROJECT_ID + "/jobs/submit-job" ret = utils_http.post(url, REQ_ADD_JOB) print(url) print(ret) sahara.otcOutputHandler().print_output(ret, mainkey="")
def create_jobbinary(): REQ_ADD_JOBBIN=utils_templates.create_request("create_jobbinary") url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.1/"+ OtcConfig.PROJECT_ID +"/job-binaries" ret = utils_http.post(url, REQ_ADD_JOBBIN) print (url) print (ret) sahara.otcOutputHandler().print_output(ret, mainkey = "")
def create_instance(): if not OtcConfig.VPCNAME is None: getplugin("ecs").convertVPCNameToId() if not OtcConfig.SUBNETNAME is None: getplugin("ecs").convertSUBNETNameToId() if not OtcConfig.SECUGROUPNAME is None: getplugin("ecs").convertSECUGROUPNameToId() if not OtcConfig.AZ is None: dcs.convertAZnameToId() if OtcConfig.INSTANCE_TYPE_NAME is None: OtcConfig.INSTANCE_TYPE_NAME = "OTC_DCS_SINGLE:1" if OtcConfig.INSTANCE_NAME is None: OtcConfig.INSTANCE_NAME = "dcs" (OtcConfig.INSTANCE_DCS_TYPE, OtcConfig.INSTANCE_DCS_SIZE) = str( OtcConfig.INSTANCE_TYPE_NAME).split(':') REQ_CREATE_DCS = utils_templates.create_request("create_instance") #print (REQ_CREATE_DCS) url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.0/" + OtcConfig.PROJECT_ID + "/instances" url = url.replace('iam', 'dcs') #print (url) ret = utils_http.post(url, REQ_CREATE_DCS) print(ret) return ret
def add_job(): REQ_ADD_JOB=utils_templates.create_request("add_job") url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.1/"+ OtcConfig.PROJECT_ID +"/jobs/submit-job" ret = utils_http.post(url, REQ_ADD_JOB) print (url) print (ret) mrs.otcOutputHandler().print_output(ret, mainkey = "")
def attach_volume(): """ generated source for method AttachVolume """ REQ_ATTACH_CLOUDVOLUMES = "{ \"volumeAttachment\": { \"volumeId\": \"" + OtcConfig.VOLUME_ID + "\", \"device\": \"" + OtcConfig.EVS_DEVICE + "\" } }" url = ecs.baseurl+ "/v1/" + OtcConfig.PROJECT_ID + "/cloudservers/" + OtcConfig.INSTANCE_ID + "/attachvolume" ret = utils_http.post(url, REQ_ATTACH_CLOUDVOLUMES) print(ret) return ret
def create_auto_scaling_group(): if not (OtcConfig.SCALINGGROUP_NAME is None): autoscaling.convertASNameToId() #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.SUBNETID) print(OtcConfig.SUBNETID) REQ_CREATE_SCG=utils_templates.create_request("create_as_group") url = "https://" + OtcConfig.DEFAULT_HOST+ "/autoscaling-api/v1/" + OtcConfig.PROJECT_ID + "/scaling_group" ret = utils_http.post(url, REQ_CREATE_SCG) autoscaling.otcOutputHandler().print_output(ret,mainkey="") #print(REQ_CREATE_SCG) return ret
def create_volume(): REQ_CREATE_CLOUDVOLUMES = "{ \"volume\": { \"backup_id\": " + OtcConfig.SNAPSHOTID + ", " + "\"count\": " + OtcConfig.NUMCOUNT + ", \"availability_zone\": \"" + OtcConfig.AZ + "\",\"description\": \"" + OtcConfig.VOLUME_NAME + "\", \"size\": " + OtcConfig.VOLUME_SIZE + ", \"name\": \"" + OtcConfig.VOLUME_NAME + "\", \"imageRef\": " + "null" + ", \"volume_type\": \"" + OtcConfig.VOLUME_TYPE + "\" } }" #print REQ_CREATE_CLOUDVOLUMES url = ecs.baseurl+ "/v2/" + OtcConfig.PROJECT_ID + "/cloudvolumes" ret = utils_http.post(url, REQ_CREATE_CLOUDVOLUMES) print(ret) return ret
def _secgrouprulecreate(): if not (OtcConfig.VPCNAME is None): ecs.convertVPCNameToId() if not (OtcConfig.SECUGROUPNAME is None): ecs.convertSECUGROUPNameToId() sourceIp = ""; if not OtcConfig.CIDR is None: sourceIp = "\", \"remote_ip_prefix\":\"" + OtcConfig.CIDR; remoteGroup = ""; if not OtcConfig.SOURCE_GROUP_ID is None: remoteGroup = "\", \"remote_group_id\":\"" + OtcConfig.SOURCE_GROUP_ID ; portrange = "" if not OtcConfig.PORTMIN is None and not OtcConfig.PORTMAX is None: portrange = "\", \"port_range_min\":\"" + OtcConfig.PORTMIN + "\", \"port_range_max\":\"" ''+ OtcConfig.PORTMAX REQ_CREATE_SECGROUPRULE = "{\"security_group_rule\":{ \"direction\":\"" + OtcConfig.DIRECTION + "\",\"ethertype\":\"" + OtcConfig.ETHERTYPE + "\", \"protocol\":\""+ OtcConfig.PROTOCOL+ portrange +remoteGroup + sourceIp+ "\" , \"security_group_id\":\""+ OtcConfig.SECUGROUP + "\" } }" #REQ_CREATE_SECGROUPRULE = "{\"security_group_rule\":{ \"direction\":\"" + OtcConfig.DIRECTION + "\", \"port_range_min\":\"" + OtcConfig.PORTMIN + "\", \"ethertype\":\"" + OtcConfig.ETHERTYPE + "\", \"port_range_max\":\"" ''+ OtcConfig.PORTMAX+ "\", \"protocol\":\""+ OtcConfig.PROTOCOL+ remoteGroup + sourceIp+ "\" , \"security_group_id\":\""+ OtcConfig.SECUGROUP + "\" } }" url = ecs.baseurl+ "/v2.0/security-group-rules" ret = utils_http.post(url, REQ_CREATE_SECGROUPRULE) #print REQ_CREATE_SECGROUPRULE print (ret) ecs.otcOutputHandler().print_output(ret, mainkey="security_group_rule") return ret
def create_jobbinary(): REQ_ADD_JOBBIN = utils_templates.create_request("create_jobbinary") url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.1/" + OtcConfig.PROJECT_ID + "/job-binaries" ret = utils_http.post(url, REQ_ADD_JOBBIN) print(url) print(ret) sahara.otcOutputHandler().print_output(ret, mainkey="")
def run_instances(): if not OtcConfig.VPCNAME is None: ecs.convertVPCNameToId() if not OtcConfig.SUBNETNAME is None: ecs.convertSUBNETNameToId() if not OtcConfig.IMAGENAME is None: ecs.convertIMAGENameToId() if not OtcConfig.SECUGROUPNAME is None: ecs.convertSECUGROUPNameToId() if not OtcConfig.INSTANCE_TYPE_NAME is None: ecs.convertFlavorNameToId() if OtcConfig.IMAGE_ID is None: print("Image definition not Correct ! Check images:") print("otc ecs describe-images") os._exit(1) if OtcConfig.INSTANCE_TYPE is None: print("Instance Type definition not Correct ! Check flavors:") print("otc ecs describe-flavors") os._exit(1) if OtcConfig.VPCID is None: print("VPC definition not Correct ! Check VPCs:") print("otc ecs describe-vpcs") os._exit(1) if OtcConfig.SECUGROUP is None: print("Security Group definition not Correct ! Check security groups:") print("otc ecs describe-security-groups") os._exit(1) if OtcConfig.SUBNETID is None: print("Subnet definition not Correct ! Check subnets:") print("otc ecs describe-subnets") os._exit(1) PUBLICIPJSON = "" if OtcConfig.CREATE_ECS_WITH_PUBLIC_IP == "true": PUBLICIPJSON = "\"publicip\": { \"eip\": { \"iptype\": \"5_bgp\", \"bandwidth\": { \"size\": 5, \"sharetype\": \"PER\", \"chargemode\": \"traffic\" } } }," PERSONALIZATION = ecs.getPersonalizationJSON() REQ_CREATE_VM = " { " + " \"server\": { " + " \"availability_zone\": \"" + OtcConfig.AZ + "\", " + " \"name\": \"" + OtcConfig.INSTANCE_NAME + "\", " + " \"imageRef\": \"" + OtcConfig.IMAGE_ID + "\", " + " \"root_volume\": { " + " \"volumetype\": \"SATA\" " + " }, " + " \"flavorRef\": \"" + OtcConfig.INSTANCE_TYPE + "\"," + PERSONALIZATION + " \"vpcid\": \"" + OtcConfig.VPCID + "\", " + " \"security_groups\": [ " + " { " + " \"id\": \"" + OtcConfig.SECUGROUP + "\" " + " } " + " ], " + " \"nics\": [ " + " { " + " \"subnet_id\": \"" + OtcConfig.SUBNETID + "\" " + " } " + " ], " + PUBLICIPJSON + " \"key_name\": \"" + OtcConfig.KEYNAME + "\", " + " \"adminPass\": \"" + OtcConfig.ADMINPASS + "\", " + " \"count\": \"" + OtcConfig.NUMCOUNT + "\", " + " \"},\": { " + " \"__vnc_keymap\": \"de\" " + " } " + " } " + " } " + " " #print (REQ_CREATE_VM) url = ecs.baseurl+ "/v1/" + OtcConfig.PROJECT_ID + "/cloudservers" ret = utils_http.post(url, REQ_CREATE_VM) # ecs.otcOutputHandler().print_output(json.loads(ret),mainkey = "",listkey={"job_id"} ) OtcConfig.ECSTASKID = json.loads(ret)["job_id"] if OtcConfig.WAIT_CREATE: ecs.getECSJOBList() while OtcConfig.ECSCREATEJOBSTATUS in ["RUNNING", "INIT"]: sleep(10) ecs.getECSJOBList() sys.stdout.write('.') #sys.stdout.flush() if "SUCCESS" == OtcConfig.ECSCREATEJOBSTATUS: os._exit(1) print("ECS Creation status: " + OtcConfig.ECSCREATEJOBSTATUS) return ret
def rename_namespace(): if OtcConfig.CLUSTER: cce.convertClusterNameToId() url = "https://" + OtcConfig.DEFAULT_HOST + "/api/v1/namespaces" req = utils_templates.create_request("cce_rename_namespace") ret = utils_http.post(url, req) cce.otcOutputHandler().print_output(ret,mainkey="") return ret
def rename_namespace(): if OtcConfig.CLUSTER: cce.convertClusterNameToId() url = "https://" + OtcConfig.DEFAULT_HOST + "/api/v1/namespaces" req = utils_templates.create_request("cce_rename_namespace") ret = utils_http.post(url, req) ecs.otcOutputHandler().print_output(ret, mainkey="") return ret
def create_security_group(): if not (OtcConfig.VPCNAME is None): ecs.convertVPCNameToId() REQ_CREATE_SECGROUP = "{ \"security_group\": { \"name\":\"" + OtcConfig.SECUGROUPNAME + "\", \"vpc_id\" : \"" + OtcConfig.VPCID + "\" } }" url = ecs.baseurl+ "/v1/" + OtcConfig.PROJECT_ID + "/security-groups" ret = utils_http.post(url, REQ_CREATE_SECGROUP) return ret
def create_datasource(): REQ_ADD_NODE=utils_templates.create_request("create_datasource") url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.1/"+ OtcConfig.PROJECT_ID +"/data-sources" ret = utils_http.post(url, REQ_ADD_NODE) print (url) print (ret) sahara.otcOutputHandler().print_output(ret, mainkey = "")
def create_datasource(): REQ_ADD_NODE = utils_templates.create_request("create_datasource") url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.1/" + OtcConfig.PROJECT_ID + "/data-sources" ret = utils_http.post(url, REQ_ADD_NODE) print(url) print(ret) sahara.otcOutputHandler().print_output(ret, mainkey="")
def create_auto_scaling_policy(): if not (OtcConfig.SCALINGGROUP_NAME is None): autoscaling.convertASNameToId() REQ_CREATE_SCP=utils_templates.create_request("create_as_policy") url = "https://" + OtcConfig.DEFAULT_HOST+ "/autoscaling-api/v1/" + OtcConfig.PROJECT_ID + "/scaling_policy" ret = utils_http.post(url, REQ_CREATE_SCP) autoscaling.otcOutputHandler().print_output(ret,mainkey="") return ret
def create_security_group(): if not (OtcConfig.VPCNAME is None): ecs.convertVPCNameToId() REQ_CREATE_SECGROUP = "{ \"security_group\": { \"name\":\"" + OtcConfig.SECUGROUPNAME + "\", \"vpc_id\" : \"" + OtcConfig.VPCID + "\" } }" url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1/" + OtcConfig.PROJECT_ID + "/security-groups" ret = utils_http.post(url, REQ_CREATE_SECGROUP) return ret
def disable_auto_scaling_group(): if not (OtcConfig.SCALINGGROUP_NAME is None): autoscaling.convertASNameToId() OtcConfig.ACTION_DISABLE_ENABLE_AS_GROUP="pause" REQ_ACTION_SCG=utils_templates.create_request("disable_enable_as_group") url = "https://" + OtcConfig.DEFAULT_HOST + "/autoscaling-api/v1/" + OtcConfig.PROJECT_ID + "/scaling_group/" + OtcConfig.SCALINGGROUP_ID + "/action" ret = utils_http.post(url, REQ_ACTION_SCG) autoscaling.otcOutputHandler().print_output(ret,mainkey="") return ret
def execute_auto_scaling_policy(): if not (OtcConfig.SCALING_POLICY_NAME is None): autoscaling.convertASPolicyNameToId() OtcConfig.AS_POLICY_ACTION="execute" REQ_ACTION_SCP=utils_templates.create_request("execute_enable_disable_as_policy") url = "https://" + OtcConfig.DEFAULT_HOST + "/autoscaling-api/v1/" + OtcConfig.PROJECT_ID + "/scaling_policy/" + OtcConfig.SCALING_POLICY_ID + "/action" ret = utils_http.post(url, REQ_ACTION_SCP) autoscaling.otcOutputHandler().print_output(ret,mainkey="") return ret
def create_subnet(): if not (OtcConfig.VPCNAME is None): ecs.convertVPCNameToId() REQ_CREATE_SUBNET = "{ \"subnet\": { \"name\": \"" + OtcConfig.SUBNETNAME + "\", \"cidr\": \"" + OtcConfig.CIDR + "\", \"gateway_ip\": \"" + OtcConfig.GWIP + "\", \"dhcp_enable\": \"true\", \"primary_dns\": \"" + OtcConfig.PRIMARYDNS + "\", \"secondary_dns\": \"" + OtcConfig.SECDNS + "\", \"availability_zone\":\"" + OtcConfig.AZ + "\", \"vpc_id\":\"" + OtcConfig.VPCID + "\" } }" url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1/" + OtcConfig.PROJECT_ID + "/subnets" ret = utils_http.post(url, REQ_CREATE_SUBNET) print(ret) return ret
def create_jobobject(): REQ_ADD_JOB = utils_templates.create_request("create_jobobject") url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.1/" + OtcConfig.PROJECT_ID + "/jobs" ret = utils_http.post(url, REQ_ADD_JOB) if OtcConfig.DEBUG: print REQ_ADD_JOB #print (url) #print (ret) sahara.otcOutputHandler().print_output(ret, mainkey="")
def create_jobobject(): REQ_ADD_JOB=utils_templates.create_request("create_jobobject") url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.1/"+ OtcConfig.PROJECT_ID +"/jobs" ret = utils_http.post(url, REQ_ADD_JOB) if OtcConfig.DEBUG: print(REQ_ADD_JOB) #print (url) #print (ret) sahara.otcOutputHandler().print_output(ret, mainkey = "")
def create_subnet(): if not (OtcConfig.VPCNAME is None): ecs.convertVPCNameToId() REQ_CREATE_SUBNET = "{ \"subnet\": { \"name\": \"" + OtcConfig.SUBNETNAME + "\", \"cidr\": \"" + OtcConfig.CIDR + "\", \"gateway_ip\": \"" + OtcConfig.GWIP + "\", \"dhcp_enable\": \"true\", \"primary_dns\": \"" + OtcConfig.PRIMARYDNS + "\", \"secondary_dns\": \"" + OtcConfig.SECDNS + "\", \"availability_zone\":\"" + OtcConfig.AZ + "\", \"vpc_id\":\"" + OtcConfig.VPCID + "\" } }" url = ecs.baseurl+ "/v1/" + OtcConfig.PROJECT_ID + "/subnets" ret = utils_http.post(url, REQ_CREATE_SUBNET) print(ret) return ret
def batch_delete_auto_scaling_configuration(): if (OtcConfig.SCALING_CONFIGURATION_ID is None) and not (OtcConfig.SCALING_CONFIGURATION_NAME is None): autoscaling.convertASConfigurationNameToId() REQ_DELETE_BATCH_SC=utils_templates.create_request("batch_delete_AS_config") url = "https://" + OtcConfig.DEFAULT_HOST + "/autoscaling-api/v1/" + OtcConfig.PROJECT_ID + "/scaling_configurations" ret = utils_http.post(url, REQ_DELETE_BATCH_SC) autoscaling.otcOutputHandler().print_output(ret,mainkey="") #print(REQ_DELETE_BATCH_SC) return ret
def create_health_check(): if not (OtcConfig.LISTENER_NAME is None): elb.convertLISTENERNameToId() url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1.0/" + OtcConfig.PROJECT_ID + "/elbaas/healthcheck" REQ_CREATE_HEALTH_CHECK=utils_templates.create_request("creating_health_check_task") ret = utils_http.post(url, REQ_CREATE_HEALTH_CHECK) return ret
def add_node(): #vpc_id if not (OtcConfig.CLUSTER is None): getplugin("cce").convertClusterNameToId() url = "https://cce.eu-de.otc.t-systems.com" + "/api/v1/clusters/" + OtcConfig.CLUSTER_ID + "/hosts" req = utils_templates.create_request("cce_add_node") ret = utils_http.post(url, req) cce.otcOutputHandler().print_output(ret, mainkey="") return ret
def create_endpoint(): if OtcConfig.CLUSTER: cce.convertClusterNameToId() url = "https://" + OtcConfig.DEFAULT_HOST + "/api/v1/namespaces/" + OtcConfig.NAMESPACE + "/endpoints" req = utils_templates.create_request("cce_create_endpoint") print req ret = utils_http.post(url, req) cce.otcOutputHandler().print_output(ret, mainkey="") return ret
def create_rc(): if OtcConfig.CLUSTER: cce.convertClusterNameToId() url = "https://" + OtcConfig.DEFAULT_HOST + "/api/v1/namespaces/" + OtcConfig.NAMESPACE + "/replicationcontrollers" req = utils_templates.create_request("cce_create_rc") #print(req) ret = utils_http.post(url, req) cce.otcOutputHandler().print_output(ret,mainkey="") return ret
def add_node(): #vpc_id if not (OtcConfig.CLUSTER is None): getplugin("cce").convertClusterNameToId() url = "https://cce.eu-de.otc.t-systems.com" + "/api/v1/clusters/" + OtcConfig.CLUSTER_ID + "/hosts" req = utils_templates.create_request("cce_add_node") ret = utils_http.post(url, req) cce.otcOutputHandler().print_output(ret,mainkey="") return ret
def create_backend_member(): if not (OtcConfig.LISTENER_NAME is None): elb.convertLISTENERNameToId() if not OtcConfig.INSTANCE_NAME is None: getplugin("ecs").convertINSTANCENameToId() url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1.0/" + OtcConfig.PROJECT_ID + "/elbaas/listeners/" + OtcConfig.LISTENER_ID + "/members" REQ_CREATE_BACKEND_MEMBER = utils_templates.create_request("add_backend_member") ret = utils_http.post(url, REQ_CREATE_BACKEND_MEMBER) print(ret) return ret
def create_backend_member(): if not (OtcConfig.LISTENER_NAME is None): elb.convertLISTENERNameToId() if not OtcConfig.INSTANCE_NAME is None: getplugin("ecs").convertINSTANCENameToId() url = "https://" + OtcConfig.DEFAULT_HOST + "/v1.0/" + OtcConfig.PROJECT_ID + "/elbaas/listeners/" + OtcConfig.LISTENER_ID + "/members" REQ_CREATE_BACKEND_MEMBER = utils_templates.create_request( "add_backend_member") ret = utils_http.post(url, REQ_CREATE_BACKEND_MEMBER) print(ret) return ret
def create_key_pair(): REQ_CREATE_KEYPAIR = "{ \"keypair\": { \"name\": \"" + OtcConfig.KEYNAME + "\", " + "\"public_key\": \"" + OtcConfig.PUBLICKEY + "\" } }" url = ecs.baseurl+ "/v2/" + OtcConfig.PROJECT_ID + "/os-keypairs" ret = utils_http.post(url, REQ_CREATE_KEYPAIR) parsed = json.loads(ret) if "keypair" not in parsed: print("Can not create:" +ret) os._exit( 1 ) ecs.otcOutputHandler().print_output(ret, mainkey="keypair") return ret
def delete_instances(): if not OtcConfig.INSTANCE_NAME is None: ecs.convertINSTANCENameToId() if OtcConfig.INSTANCE_ID is None : raise RuntimeError( "Error. Must be specify the Instance ID!") REQ_ECS_DELETE_VM = "{ \"servers\": [ { \"id\": \"" + OtcConfig.INSTANCE_ID + "\" } ]," + " \"delete_publicip\": \"" + OtcConfig.DELETE_PUBLICIP + "\", \"delete_volume\": \"" + OtcConfig.DELETE_VOLUME + "\" }" url = ecs.baseurl+ "/v1/" + OtcConfig.PROJECT_ID + "/cloudservers" + "/delete" ret = utils_http.post(url, REQ_ECS_DELETE_VM) print(ret) return ret
def create_auto_scaling_group(): raise RuntimeError("TODO: Not implemented!") if not (OtcConfig.SCALINGGROUP_NAME is None): autoscaling.convertASNameToId() REQ_CREATE_SCG = None url = autoscaling.baseurl + "/autoscaling-api/v1/" + OtcConfig.PROJECT_ID + "/scaling_group" ret = utils_http.post(url, REQ_CREATE_SCG) print(ret) return ret
def create_auto_scaling_group(): raise RuntimeError("TODO: Not implemented!") if not (OtcConfig.SCALINGGROUP_NAME is None): autoscaling.convertASNameToId() REQ_CREATE_SCG = None url = autoscaling.baseurl+ "/autoscaling-api/v1/" + OtcConfig.PROJECT_ID + "/scaling_group" ret = utils_http.post(url, REQ_CREATE_SCG) print(ret) return ret
def create_auto_scaling_configuration(): if not OtcConfig.INSTANCE_TYPE_NAME is None: getplugin("ecs").convertFlavorNameToId() if not OtcConfig.IMAGENAME is None: getplugin("ecs").convertIMAGENameToId() REQ_CREATE_SC=utils_templates.create_request("create_as_configuration") #print(REQ_CREATE_SC) url = "https://" + OtcConfig.DEFAULT_HOST+ "/autoscaling-api/v1/" + OtcConfig.PROJECT_ID + "/scaling_configuration" ret = utils_http.post(url, REQ_CREATE_SC) autoscaling.otcOutputHandler().print_output(ret,mainkey="") return ret
def delete_instances(): if not OtcConfig.INSTANCE_NAME is None: ecs.convertINSTANCENameToId() if OtcConfig.INSTANCE_ID is None : raise RuntimeError( "Error. Must be specify the Instance ID!") REQ_ECS_DELETE_VM = "{ \"servers\": [ { \"id\": \"" + OtcConfig.INSTANCE_ID + "\" } ]," + " \"delete_publicip\": \"" + OtcConfig.DELETE_PUBLICIP + "\", \"delete_volume\": \"" + OtcConfig.DELETE_VOLUME + "\" }" url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1/" + OtcConfig.PROJECT_ID + "/cloudservers" + "/delete" ret = utils_http.post(url, REQ_ECS_DELETE_VM) print(ret) return ret
def create_key_pair(): REQ_CREATE_KEYPAIR = "{ \"keypair\": { \"name\": \"" + OtcConfig.KEYNAME + "\", " + "\"public_key\": \"" + OtcConfig.PUBLICKEY + "\" } }" url = "https://" + OtcConfig.DEFAULT_HOST+ "/v2/" + OtcConfig.PROJECT_ID + "/os-keypairs" ret = utils_http.post(url, REQ_CREATE_KEYPAIR) parsed = json.loads(ret) if "keypair" not in parsed: print("Can not create:" +ret) os._exit( 1 ) ecs.otcOutputHandler().print_output(ret, mainkey="keypair") return ret
def allocate_address(): REQ_CREATE_PUBLICIP = "{\"publicip\":{\"type\":\"5_bgp\"},\"bandwidth\":{\"name\":\"apiTest\",\"size\":5,\"share_type\":\"PER\",\"charge_mode\":\"traffic\"}}" url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1/" + OtcConfig.PROJECT_ID + "/publicips" ret = utils_http.post(url, REQ_CREATE_PUBLICIP) print( ret ) maindata = json.loads(ret) if "code" in maindata: print("Can not create:" +maindata["message"]) os._exit( 1 ) ecs.otcOutputHandler().print_output(ret, mainkey="publicip") return ret
def allocate_address(): REQ_CREATE_PUBLICIP = "{\"publicip\":{\"type\":\"5_bgp\"},\"bandwidth\":{\"name\":\"apiTest\",\"size\":5,\"share_type\":\"PER\",\"charge_mode\":\"traffic\"}}" url = ecs.baseurl+ "/v1/" + OtcConfig.PROJECT_ID + "/publicips" ret = utils_http.post(url, REQ_CREATE_PUBLICIP) print( ret ) maindata = json.loads(ret) if "code" in maindata: print("Can not create:" +maindata["message"]) os._exit( 1 ) ecs.otcOutputHandler().print_output(ret, mainkey="publicip") return ret
def ECSAction(): if not OtcConfig.INSTANCE_NAME is None: ecs.convertINSTANCENameToId() if OtcConfig.INSTANCE_ID is None : raise RuntimeError( "Error. Must be specify the Instance ID!") REQ_ECS_ACTION_VM = "{ " + " \"" + OtcConfig.ECSACTION + "\": " + " { " + " \"type\":\"" + OtcConfig.ECSACTIONTYPE + "\", " + " \"servers\": [ { \"id\": \"" + OtcConfig.INSTANCE_ID + "\" }] " + " } " + "}" url = ecs.baseurl+ "/v1/" + OtcConfig.PROJECT_ID + "/cloudservers/action" ret = utils_http.post(url, REQ_ECS_ACTION_VM) print(ret) return ret
def ECSAction(): if not OtcConfig.INSTANCE_NAME is None: ecs.convertINSTANCENameToId() if OtcConfig.INSTANCE_ID is None : raise RuntimeError( "Error. Must be specify the Instance Name or ID!") REQ_ECS_ACTION_VM = "{ " + " \"" + OtcConfig.ECSACTION + "\": " + " { " + " \"type\":\"" + OtcConfig.ECSACTIONTYPE + "\", " + " \"servers\": [ { \"id\": \"" + OtcConfig.INSTANCE_ID + "\" }] " + " } " + "}" url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1/" + OtcConfig.PROJECT_ID + "/cloudservers/action" ret = utils_http.post(url, REQ_ECS_ACTION_VM) print(ret) return ret