Skip to content
This repository has been archived by the owner on Mar 6, 2019. It is now read-only.

Commit

Permalink
Merge pull request #50 from hodigy/master
Browse files Browse the repository at this point in the history
fix of convertSECUGROUPNameToId() to handle sec groups with and without VPC
  • Loading branch information
zsoltn committed Apr 18, 2017
2 parents 56d5470 + 2fd9b8f commit 2f83357
Showing 1 changed file with 56 additions and 7 deletions.
63 changes: 56 additions & 7 deletions otcclient/plugins/ecs/ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -958,6 +971,7 @@ def convertVOLUMENameToId():

@staticmethod
def convertSUBNETNameToId():

url = "https://" + OtcConfig.DEFAULT_HOST+ "/v1/" + OtcConfig.PROJECT_ID + "/subnets"
ar = []

Expand All @@ -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():
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit 2f83357

Please sign in to comment.