summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--deploy/post/execute.py18
-rw-r--r--deploy/post/neutron.py22
2 files changed, 35 insertions, 5 deletions
diff --git a/deploy/post/execute.py b/deploy/post/execute.py
index 8758b401..3f05d005 100644
--- a/deploy/post/execute.py
+++ b/deploy/post/execute.py
@@ -9,9 +9,25 @@
import neutron
+def _config_admin_external_network():
+ name = 'admin_external'
+ body = {
+ 'network': {
+ 'name': name,
+ 'admin_state_up': True,
+ 'shared': True,
+ 'provider:network_type': 'flat',
+ 'provider:physical_network': 'physnet1',
+ 'router:external': True
+ }
+ }
+
+ return name, body
+
+
def main():
neutron.Neutron().list_networks()
-
+ neutron.Neutron().create_network(*(_config_admin_external_network()))
if __name__ == '__main__':
main()
diff --git a/deploy/post/neutron.py b/deploy/post/neutron.py
index 0dffdfc3..9c81ed24 100644
--- a/deploy/post/neutron.py
+++ b/deploy/post/neutron.py
@@ -17,9 +17,23 @@ class Neutron(object):
self.client = neutronclient.Client(api_v, session=session)
def list_networks(self):
- networks = self.client.list_networks()['networks']
- for network in networks:
- print network
+ return self.client.list_networks()['networks']
- def create_admin_ext_net(self):
+ def create_network(self, name, body):
+ if not self.is_network_exist(name):
+ self._create_network(name, body)
+ else:
+ print('admin_ext [{}] already exist'.format(name))
pass
+
+ def is_network_exist(self, name):
+ return [] != filter(lambda n: n['name'] == name, self.list_networks())
+
+ def _create_network(self, name, body):
+ try:
+ nid = self.client.create_network(body=body)['network']['id']
+ print('_create_admin_ext_net [{}] with id: {}'.format(name, nid))
+ return nid
+ except Exception, e:
+ print('_create_admin_ext_net [{}] fail with: {}'.format(name, e))
+ return None