summaryrefslogtreecommitdiffstats
path: root/deploy/config/network.py
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2017-03-16 15:16:12 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2017-03-21 18:25:21 +0800
commit6c077560e1cd2293fb9c6fac9065f11e555b1bbb (patch)
treed4f5a2ec3cd429c7355e922184a6276d7009d54a /deploy/config/network.py
parentfd49859523e1914bece099b326ea723068e33262 (diff)
bugfix hardcoded network configuration
Change-Id: I1fb6036a2805ccb9bdbe23622514ccd9d997c1a5 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'deploy/config/network.py')
-rw-r--r--deploy/config/network.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/deploy/config/network.py b/deploy/config/network.py
index ed14f95b..a386b5b5 100644
--- a/deploy/config/network.py
+++ b/deploy/config/network.py
@@ -4,9 +4,24 @@ from deploy.common import query
class NetworkConfig(object):
+ type2name = {
+ 'EXTERNAL': 'ext',
+ 'MANAGEMENT': 'man',
+ 'STORAGE': 'stor',
+ 'PUBLICAPI': 'pub',
+ 'TENANT': 'tenant',
+ }
+
def __init__(self, network_file):
+ self._parsers = {
+ 'network-config-metadata': self._parse_metadata,
+ 'networks': self._parse_networks,
+ 'interfaces': self._parse_interfaces
+ }
+
self._file = network_file
self._get_config()
+ self._parse()
def _get_config(self):
self.config = yaml.safe_load(file(self._file))
@@ -15,6 +30,37 @@ class NetworkConfig(object):
return query.find(lambda item: item['name'] == name,
self.config['networks'])
+ def _parse(self):
+ for conf_k, conf_v in self.config.iteritems():
+ self._parsers.get(conf_k,
+ lambda x: setattr(self, conf_k, conf_v))(conf_v)
+
+ def _parse_metadata(self, metadatas):
+ for meta_k, meta_v in metadatas.iteritems():
+ setattr(self, meta_k, meta_v)
+
+ def _parse_networks(self, networks):
+ for network in networks:
+ name = network['name']
+ self._setattr(name, '', network)
+ for network_k, network_v in network.iteritems():
+ self._setattr(name, network_k, network_v)
+
+ def _parse_interfaces(self, interfaces):
+ for interface in interfaces:
+ self._setattr(interface['name'],
+ 'iterface',
+ interface['interface'])
+
+ def _setattr(self, network_type, field, value):
+ prefix = self.type2name[network_type]
+ name = '{}_{}'.format(prefix, field) if field else prefix
+ setattr(self, name, value)
+
@property
def external_network(self):
return self._get_network('EXTERNAL')
+
+ @property
+ def external_name(self):
+ return self.external_network['network_name']