Skip to content
Permalink
Browse files
Add poor implementation of addition of single ingress rule
  • Loading branch information
imduffy15 committed Feb 22, 2014
1 parent e28cee2 commit ce8f00ffccff925c386fbaa109fef06a8f1245f4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
@@ -58,7 +58,7 @@ def make_request_async(args, poll_period=2, timeout=3600):
response = response['queryasyncjobresultresponse']
job_status = response['jobstatus']

if job_status == 1:
if job_status in [1, 2]:
return response['jobresult']
elif job_status == 0:
return make_request_async(args, poll_period=poll_period,
@@ -1,10 +1,11 @@
#!/usr/bin/env python
# encoding: utf-8

from flask import request, abort
from flask import request, abort, current_app

from ec2stack.helpers import authentication_required, get, \
contains_parameter, missing_paramater, require_one_paramater, require_parameters
contains_parameter, missing_paramater, require_one_paramater, \
require_parameters
from ec2stack.core import Ec2stackError
from ec2stack.providers.cloudstack import requester

@@ -89,7 +90,7 @@ def authenticate_security_group_ingress():


def _authenticate_security_group_request(args=None):
if not args:
if args is None:
args = {}

args['command'] = 'authorizeSecurityGroupIngress'
@@ -99,13 +100,40 @@ def _authenticate_security_group_request(args=None):
elif contains_parameter('GroupId'):
args['securityGroupId'] = get('GroupId', request.form)

args['protocol'] = get('IpPermissions.1.IpProtocol', request.form)
args['startPort'] = get('FromPort', request.form)
args['endPort'] = get('ToPort', request.form)
args['cidrlist'] = get('CidrIp', request.form)
if contains_parameter('IpProtocol'):
_authenticate_security_group_single_request(args=args)
else:
abort(400)

response = requester.make_request_async(args)

response = response['securitygroup']
def _authenticate_security_group_single_request(args=None):
if args is None:
args = {}

return response
if _contains_key_with_keyword('IpPermissions'):
raise Ec2stackError(
'400',
'InvalidParameterCombination',
'The parameter \'ipPermissions\' may not'
'be used in combination with \'ipProtocol\''
)
else:
args['protocol'] = get('IpProtocol', request.form)

require_parameters(['FromPort', 'ToPort'])
args['startPort'] = get('FromPort', request.form)
args['endPort'] = get('ToPort', request.form)

if get('CidrIp', request.form) is None:
args['cidrlist'] = '0.0.0.0/0'
else:
args['cidrlist'] = get('CidrIp', request.form)

current_app.logger.debug(args)
response = requester.make_request_async(args)

return response


def _contains_key_with_keyword(keyword):
return len(filter(lambda x: keyword in x, request.form.keys())) >= 1

0 comments on commit ce8f00f

Please sign in to comment.