summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhijiang Hu <hu.zhijiang@zte.com.cn>2017-03-09 08:04:09 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-03-09 08:04:09 +0000
commitad7a882c71c0ed779b2111f400ac6b8bd108e4c5 (patch)
tree769365763a1b7f2a8bbf9d2a4b703a3523c462d7
parentf9385eec67ad616ed3776d8800f3bc1f93e999c5 (diff)
parent2a5cc313b0780bed2750229bf42eab39da6d49a8 (diff)
Merge "create admin external subnet"
-rw-r--r--deploy/post/execute.py24
-rw-r--r--deploy/post/neutron.py42
2 files changed, 59 insertions, 7 deletions
diff --git a/deploy/post/execute.py b/deploy/post/execute.py
index 3f05d005..d5a0727b 100644
--- a/deploy/post/execute.py
+++ b/deploy/post/execute.py
@@ -25,9 +25,29 @@ def _config_admin_external_network():
return name, body
+def _config_admin_external_subnet(nid):
+ return {
+ 'subnets': [
+ {
+ 'name': 'admin_external_subnet',
+ 'cidr': '172.10.101.0/24',
+ 'ip_version': 4,
+ 'network_id': nid,
+ 'gateway_ip': '172.10.101.1',
+ 'allocation_pools': [{
+ 'start': '172.10.101.2',
+ 'end': '172.10.101.12'
+ }],
+ 'enable_dhcp': False
+ }
+ ]
+ }
+
+
def main():
- neutron.Neutron().list_networks()
- neutron.Neutron().create_network(*(_config_admin_external_network()))
+ neutronclient = neutron.Neutron()
+ nid = neutronclient.create_network(*(_config_admin_external_network()))
+ neutronclient.create_subnet(_config_admin_external_subnet(nid))
if __name__ == '__main__':
main()
diff --git a/deploy/post/neutron.py b/deploy/post/neutron.py
index 9c81ed24..e9cea8b0 100644
--- a/deploy/post/neutron.py
+++ b/deploy/post/neutron.py
@@ -16,19 +16,41 @@ class Neutron(object):
session = keystoneauth.Keystoneauth(openrc).session
self.client = neutronclient.Client(api_v, session=session)
- def list_networks(self):
- return self.client.list_networks()['networks']
-
def create_network(self, name, body):
if not self.is_network_exist(name):
- self._create_network(name, body)
+ return self._create_network(name, body)
else:
print('admin_ext [{}] already exist'.format(name))
- pass
+ return None
+
+ def create_subnet(self, body=None):
+ if not self.is_subnet_exist(body):
+ return self._create_subnet(body)
+ else:
+ print ('subnet [{}] already exist'.format(body))
+ return None
+
+ def list_networks(self):
+ return self.client.list_networks()['networks']
+
+ def list_subnets(self):
+ return self.client.list_subnets()['subnets']
def is_network_exist(self, name):
return [] != filter(lambda n: n['name'] == name, self.list_networks())
+ def is_subnet_exist(self, body):
+ print 'body: {}'.format(body)
+
+ def same_subnet(n):
+ print 'n: {}'.format(n)
+ for item in ['name', 'network_id']:
+ if n[item] != body['subnets'][0][item]:
+ return False
+ return True
+
+ return [] != filter(lambda n: same_subnet(n), self.list_subnets())
+
def _create_network(self, name, body):
try:
nid = self.client.create_network(body=body)['network']['id']
@@ -37,3 +59,13 @@ class Neutron(object):
except Exception, e:
print('_create_admin_ext_net [{}] fail with: {}'.format(name, e))
return None
+
+ def _create_subnet(self, body):
+ print('_create_subnet with body: {}'.format(body))
+ try:
+ snid = self.client.create_subnet(body)['subnets'][0]['id']
+ print('_create_subnet success with id={}'.format(snid))
+ return snid
+ except Exception, e:
+ print('_create_subnet fail with: {}'.format(e))
+ return None