diff --git a/otcclient/plugins/ecs/ecs.py b/otcclient/plugins/ecs/ecs.py index 0d798be..c9c5733 100644 --- a/otcclient/plugins/ecs/ecs.py +++ b/otcclient/plugins/ecs/ecs.py @@ -150,6 +150,11 @@ def describe_security_groups(): if (not (OtcConfig.SECUGROUPNAME is None)): ecs.convertSECUGROUPNameToId() + if OtcConfig.SECUGROUP is None: + print("Security groups definition isn't correct! Check Security groups:") + print("otc ecs describe-security-groups") + os._exit(1) + url = "https://" + OtcConfig.DEFAULT_HOST+ "/v2.0/security-group-rules?security_group_id=" + OtcConfig.SECUGROUP ret = utils_http.get(url) ecs.otcOutputHandler().print_output(ret, mainkey= "security_group_rules", listkey={"id","direction", "protocol","port_range_min","port_range_max" }) @@ -582,15 +587,21 @@ def create_subnet(): args = [ arg( '--subnet-name', dest='SUBNETNAME', help='Name of the subnet reference will use during VM creation'), arg( '--subnet-id', dest='SUBNETID', help='Id of the subnet will use during VM creation'), - + arg('--vpc-name',dest='VPCNAME', help='Name of the VPC reference will use during VM creation'), + arg( '--vpc-id', dest='VPCID', help='Id of the VPC will use during VM creation') ] ) def delete_subnet(): + if not (OtcConfig.VPCNAME is None): + ecs.convertVPCNameToId() if OtcConfig.SUBNETNAME: ecs.convertSUBNETNameToId() - url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1/" + OtcConfig.PROJECT_ID + "/subnets" + OtcConfig.SUBNETID + url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1/" + OtcConfig.PROJECT_ID + "/vpcs/" + OtcConfig.VPCID + "/subnets/" + OtcConfig.SUBNETID ret = utils_http.delete(url) + if OtcConfig.DEBUG: + print(url) + print(ret) return ret @@ -665,9 +676,11 @@ def delete_security_group(): if not (OtcConfig.SECUGROUPNAME is None): ecs.convertSECUGROUPNameToId() - - url = "https://" + OtcConfig.DEFAULT_HOST+ "/v2.0/security-groups" + "/"+ OtcConfig.SECUGROUP + url = "https://" + OtcConfig.DEFAULT_HOST+ "/v2.0" + "/security-groups" + "/"+ OtcConfig.SECUGROUP ret = utils_http.delete(url) + if OtcConfig.DEBUG: + print(url) + print(ret) return ret @@ -958,6 +971,7 @@ def convertVOLUMENameToId(): @staticmethod def convertSUBNETNameToId(): + url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1/" + OtcConfig.PROJECT_ID + "/subnets" ar = [] @@ -975,7 +989,9 @@ def convertSUBNETNameToId(): if len(ret) > 0: ret = ret + "," ret = ret + subnet["id"] - OtcConfig.SUBNETID = ret + + OtcConfig.SUBNETID = ret + @staticmethod def convertIMAGENameToId(): @@ -1004,6 +1020,9 @@ def convertINSTANCENameToId(): @staticmethod def convertSECUGROUPNameToId(): + if OtcConfig.DEBUG: + print "convertSECUGROUPNameToId" + url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1/" + OtcConfig.PROJECT_ID + "/security-groups" JSON = utils_http.get(url) parsed = json.loads(JSON) @@ -1013,11 +1032,41 @@ def convertSECUGROUPNameToId(): ecs.convertVPCNameToId() for security_group in security_groups: - if security_group.get("name") == OtcConfig.SECUGROUPNAME and ( security_group.get("vpc_id") == OtcConfig.VPCID or OtcConfig.VPCID is None ) : + if security_group.get("name") == OtcConfig.SECUGROUPNAME and OtcConfig.SECUGROUP is None: + OtcConfig.SECUGROUP = security_group["id"] + if OtcConfig.DEBUG: + print "SECUGROUPNAME" + print OtcConfig.SECUGROUP + print OtcConfig.SOURCE_GROUP_ID + print OtcConfig.VPCID + if security_group.get("name") == OtcConfig.SECUGROUPNAME and ( security_group.get("vpc_id") == OtcConfig.VPCID) : OtcConfig.SECUGROUP = security_group["id"] - if security_group.get("name") == OtcConfig.SOURCE_GROUP and ( security_group.get("vpc_id") == OtcConfig.VPCID or OtcConfig.VPCID is None ) : + if OtcConfig.DEBUG: + print "SECUGROUPNAME + VPC" + print OtcConfig.SECUGROUP + print OtcConfig.SOURCE_GROUP_ID + print OtcConfig.VPCID + if security_group.get("name") == OtcConfig.SOURCE_GROUP and OtcConfig.SOURCE_GROUP is None : OtcConfig.SOURCE_GROUP_ID = security_group["id"] + if OtcConfig.DEBUG: + print "SOURCE_GROUP" + print OtcConfig.SECUGROUP + print OtcConfig.SOURCE_GROUP_ID + print OtcConfig.VPCID + if security_group.get("name") == OtcConfig.SOURCE_GROUP and ( security_group.get("vpc_id") == OtcConfig.VPC) : + OtcConfig.SOURCE_GROUP_ID = security_group["id"] + if OtcConfig.DEBUG: + print "SOURCE_GROUP + VPC" + print OtcConfig.SECUGROUP + print OtcConfig.SOURCE_GROUP_ID + print OtcConfig.VPCID + + if OtcConfig.DEBUG: + print OtcConfig.SECUGROUP + print OtcConfig.SOURCE_GROUP_ID + print OtcConfig.VPCID + OtcConfig.SECUGROUP = OtcConfig.SECUGROUP return OtcConfig.SECUGROUP