in gstack/controllers/firewalls.py [0:0]
def createsecuritygroup(projectid, authorization):
command = 'createSecurityGroup'
res = json.loads(request.data)
args = {'name': res['name'],
'description': res['description']}
cloudstack_response = requester.make_request(
command,
args,
authorization.client_id,
authorization.client_secret
)
cloudstack_response = cloudstack_response
app.logger.debug(
'Processing request for creating a Firewall \n'
'Project: ' + projectid + '\n' +
'Firewall: ' + res['name'] + '\n' +
json.dumps(cloudstack_response, indent=4, separators=(',', ': '))
)
net_protocol_codes = {'1': 'icmp', '6': 'tcp', '17': 'udp'}
rules = res['allowed']
if rules is not []:
for rule in rules:
command = 'authorizeSecurityGroupIngress'
args = {'securitygroupname': res['name'],
'protocol': net_protocol_codes[str(rule['IPProtocol'])],
'startport': rule['ports'][0],
'endport': rule['ports'][0],
'cidrlist': ','.join([cidr for cidr in
res['sourceRanges']])}
cloudstack_response = requester.make_request(
command,
args,
authorization.client_id,
authorization.client_secret
)
cloudstack_response = cloudstack_response
app.logger.debug(
'Processing request for adding a rule to a Firewall \n'
'Project: ' + projectid + '\n' +
'Firewall: ' + res['name'] + '\n' +
json.dumps(cloudstack_response,
indent=4, separators=(',', ': '))
)
# return Global Operations
populated_response = {}
res = jsonify(populated_response)
res.status_code = 200
return res