summaryrefslogtreecommitdiffstats
path: root/deploy/post/execute.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/execute.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/execute.py')
-rw-r--r--deploy/post/execute.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/deploy/post/execute.py b/deploy/post/execute.py
index 94bec65e..75abaacb 100644
--- a/deploy/post/execute.py
+++ b/deploy/post/execute.py
@@ -134,6 +134,50 @@ def _create_image_TestVM():
print ('Use existing TestVM image')
+def _config_icmp_security_group_rule(security_group_id):
+ body = {
+ 'security_group_rule': {
+ 'direction': 'ingress',
+ 'ethertype': 'IPv4',
+ 'protocol': 'icmp',
+ 'remote_ip_prefix': '0.0.0.0/0',
+ 'security_group_id': security_group_id
+ }
+ }
+ return body
+
+
+def _config_ssh_security_group_rule(security_group_id):
+ body = {
+ 'security_group_rule': {
+ 'direction': 'ingress',
+ 'ethertype': 'IPv4',
+ 'protocol': 'tcp',
+ 'port_range_min': 22,
+ 'port_range_max': 22,
+ 'remote_ip_prefix': '0.0.0.0/0',
+ 'security_group_id': security_group_id
+ }
+ }
+ return body
+
+
+def _create_security_group_rules():
+ neutronclient = neutron.Neutron()
+ try:
+ security_group_name = 'default'
+ security_group = neutronclient.get_security_group_by_name(security_group_name)
+ security_group_id = security_group['id']
+ except Exception:
+ print('Cannot find security group by name %s' % security_group_name)
+ return
+
+ neutronclient.create_security_group_rule(security_group,
+ _config_icmp_security_group_rule(security_group_id))
+ neutronclient.create_security_group_rule(security_group,
+ _config_ssh_security_group_rule(security_group_id))
+
+
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-nw', '--network-file',
@@ -144,6 +188,7 @@ def main():
_create_external_network(args.network_file)
_create_flavor_m1_micro()
_create_image_TestVM()
+ _create_security_group_rules()
_config_kolla_admin_openrc('/etc/kolla/')