diff options
author | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-03-16 16:59:48 +0800 |
---|---|---|
committer | Serena Feng <feng.xiaowei@zte.com.cn> | 2017-03-23 06:26:26 +0000 |
commit | 84b0be2e12d83a48ac15b3e4f457b7e7fb465735 (patch) | |
tree | 420116aae0aa45dd6864b29da96b7be7838b0ae9 /deploy/post/neutron.py | |
parent | 8eeced263cd35000623a69243766f0970055da69 (diff) |
simplify get_xx process using query.find()
Change-Id: I2a911fc15c1456b409db840b9ae76c04a23d449d
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'deploy/post/neutron.py')
-rw-r--r-- | deploy/post/neutron.py | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/deploy/post/neutron.py b/deploy/post/neutron.py index e9cea8b0..dc2e30b2 100644 --- a/deploy/post/neutron.py +++ b/deploy/post/neutron.py @@ -8,6 +8,7 @@ ############################################################################## from neutronclient.neutron import client as neutronclient +from deploy.common import query import keystoneauth @@ -17,14 +18,14 @@ class Neutron(object): self.client = neutronclient.Client(api_v, session=session) def create_network(self, name, body): - if not self.is_network_exist(name): + if not self.get_network_by_name(name): return self._create_network(name, body) else: print('admin_ext [{}] already exist'.format(name)) return None def create_subnet(self, body=None): - if not self.is_subnet_exist(body): + if not self.get_subnet_by_name(body): return self._create_subnet(body) else: print ('subnet [{}] already exist'.format(body)) @@ -36,20 +37,18 @@ class Neutron(object): 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 get_network_by_name(self, name): + return query.find(lambda nw: nw['name'] == name, self.list_networks()) - def is_subnet_exist(self, body): - print 'body: {}'.format(body) - - def same_subnet(n): - print 'n: {}'.format(n) + def get_subnet_by_name(self, body): + def _same_subnet(this, that): for item in ['name', 'network_id']: - if n[item] != body['subnets'][0][item]: + if this[item] != that[item]: return False return True - return [] != filter(lambda n: same_subnet(n), self.list_subnets()) + return query.find(lambda n: _same_subnet(n, body['subnets'][0]), + self.list_subnets()) def _create_network(self, name, body): try: |