summaryrefslogtreecommitdiffstats
path: root/deploy/post/neutron.py
diff options
context:
space:
mode:
authorAlex Yang <yangyang1@zte.com.cn>2017-07-26 11:15:44 +0800
committerAlex Yang <yangyang1@zte.com.cn>2017-07-26 13:38:07 +0800
commit8d951bd35aca9af5f4fa26fec643d25622f4f466 (patch)
treeb9da68615a8d7149486f42cec3f3fee7b4d62104 /deploy/post/neutron.py
parent4aab5fede6d007aa7c934aabbe7294b793bc6087 (diff)
Convert the bash commands in post.sh to python code
According to the comment from Serena in the patch https://gerrit.opnfv.org/gerrit/#/c/37857/, the bash code in post.sh can be implemented by python, and the deploy script can call post/execute.py directly. Change-Id: Ibcf86fc2b6ee3942e4082384c9d4075d608b7294 Signed-off-by: Alex Yang <yangyang1@zte.com.cn>
Diffstat (limited to 'deploy/post/neutron.py')
-rw-r--r--deploy/post/neutron.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/deploy/post/neutron.py b/deploy/post/neutron.py
index 77791ea8..79703310 100644
--- a/deploy/post/neutron.py
+++ b/deploy/post/neutron.py
@@ -67,3 +67,31 @@ class Neutron(keystoneauth.ClientBase):
except Exception, e:
print('_create_subnet fail with: {}'.format(e))
return None
+
+ def _list_security_groups(self):
+ return self.client.list_security_groups()['security_groups']
+
+ def get_security_group_by_name(self, name):
+ return query.find(lambda nw: nw['name'] == name, self._list_security_groups())
+
+ def _check_security_group_rule_conflict(self, security_group, body):
+ newrule = body['security_group_rule']
+ rules = security_group['security_group_rules']
+ for rule in rules:
+ is_same = True
+ for key in newrule.keys():
+ if key in rule and newrule[key] != rule[key]:
+ is_same = False
+ break
+ if is_same:
+ print('The rule already exists in the security group %s' % security_group['id'])
+ return True
+ return False
+
+ def create_security_group_rule(self, security_group, body):
+ if not self._check_security_group_rule_conflict(security_group, body):
+ try:
+ rule = self.client.create_security_group_rule(body=body)
+ print('create_security_group_rule success with id %s' % rule['security_group_rule']['id'])
+ except Exception, e:
+ print('create_security_group_rule fail with exception %s' % e)