summaryrefslogtreecommitdiffstats
path: root/deploy/post/neutron.py
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2017-03-07 10:43:56 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2017-03-07 13:59:10 +0800
commit010d2c95261820add617047a030e4d06563a6613 (patch)
tree9e0df51f9458b9794c88a444ea1ba515aa42a8ca /deploy/post/neutron.py
parent7c3c3d2a629f5bf5373d21780963a143d45e6067 (diff)
create external network
Change-Id: I6621fed21832f3e4653c2d236bb29de421b5b573 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'deploy/post/neutron.py')
-rw-r--r--deploy/post/neutron.py22
1 files changed, 18 insertions, 4 deletions
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