commit 47a921d183967b0438f9b0fc3f5e52b7f55b8cde
Author: Radek Pazdera <rpazdera(a)redhat.com>
Date: Wed Jul 18 17:03:39 2012 +0200
NetConfig: Adding support for the new parser
This commit modifies NetConfig package to reflect recent changes in
parser implementation.
The original NetConfig was initialized with the machine and net
config's XML strings. Now the config is initialized with a dictionary
that contains parsed configuration the interface.
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
NetConfig/NetConfig.py | 34 +++----
NetConfig/NetConfigDevNames.py | 43 ++++-----
NetConfig/NetConfigParse.py | 199 ----------------------------------------
3 files changed, 30 insertions(+), 246 deletions(-)
---
diff --git a/NetConfig/NetConfig.py b/NetConfig/NetConfig.py
index 4dd63e1..a0a8e20 100644
--- a/NetConfig/NetConfig.py
+++ b/NetConfig/NetConfig.py
@@ -12,30 +12,15 @@ jpirko(a)redhat.com (Jiri Pirko)
import logging
import copy
-from NetConfigParse import NetConfigParse
from NetConfigDevNames import NetConfigDevNames
from NetConfigDevice import NetConfigDevice
from NetConfigDevice import NetConfigDeviceType
from NetConfigCommon import get_slaves
class NetConfig:
- def __init__(self, machine_xml_string, config_xml_string=None):
- parse = NetConfigParse(machine_xml_string)
+ def __init__(self):
devnames = NetConfigDevNames()
-
- if config_xml_string:
- config = parse.parse_config(config_xml_string)
- else:
- '''
- No config is passed so make essential netdevices as they
- are listed in machine config and stores them into config
- '''
- mnetdevs = parse.get_machine_netdevs()
- config = copy.deepcopy(mnetdevs)
- for key in config:
- config[key]["phys_id"] = key
-
- devnames.assign_names(config)
+ config = {}
self._devnames = devnames
self._config = config
@@ -73,14 +58,22 @@ class NetConfig:
types.add(netdev["type"])
return types
- def _types_init(self):
- for dev_type in self._get_used_types():
+ def _type_init(self, dev_type):
+ if not dev_type in self._get_used_types():
NetConfigDeviceType(dev_type).type_init()
def _types_cleanup(self):
for dev_type in self._get_used_types():
NetConfigDeviceType(dev_type).type_cleanup()
+ def add_interface_config(self, if_id, config):
+ self._config[if_id] = config
+ self._type_init(config["type"])
+ self._devnames.assign_name(if_id, self._config)
+
+ def get_interface_config(self, if_id):
+ return self._config[if_id]
+
def configure(self, dev_id):
netdev = self._config[dev_id]
device = NetConfigDevice(netdev, self._config)
@@ -88,7 +81,6 @@ class NetConfig:
device.up()
def configure_all(self):
- self._types_init()
dev_order = self._get_dev_order()
for dev_id in dev_order:
self.configure(dev_id)
@@ -129,7 +121,7 @@ class NetConfig:
if "slaves" in params:
netdev["slaves"] = params["slaves"]
self._config[dev_id] = netdev
- self._devnames.assign_names(self._config)
+ self._devnames.assign_name(dev_id, self._config)
return dev_id
def netdev_del(self, dev_id):
diff --git a/NetConfig/NetConfigDevNames.py b/NetConfig/NetConfigDevNames.py
index 8522e00..1619b7e 100644
--- a/NetConfig/NetConfigDevNames.py
+++ b/NetConfig/NetConfigDevNames.py
@@ -84,29 +84,20 @@ class NetConfigDevNames:
vlan_tci = get_option(netdev, "vlan_tci")
netdev["name"] = "%s.%s" % (real_netdev["name"], vlan_tci)
- def assign_names(self, config):
- for dev_id in config:
- netdev = config[dev_id]
- if "name" in netdev:
- continue
- dev_type = netdev["type"]
- if dev_type == "eth":
- self.assign_name_by_scan(dev_id, netdev)
- elif dev_type == "bond":
- self._assign_name_bond(netdev, config)
- elif dev_type == "bridge":
- self._assign_name_bridge(netdev, config)
- elif dev_type == "macvlan":
- self._assign_name_macvlan(netdev, config)
- elif dev_type == "team":
- self._assign_name_team(netdev, config)
-
- '''
- In second round assign names for vlans as they use
- previously assigned names
- '''
- for dev_id in config:
- netdev = config[dev_id]
- dev_type = netdev["type"]
- if dev_type == "vlan":
- self._assign_name_vlan(netdev, config)
+ def assign_name(self, dev_id, config):
+ netdev = config[dev_id]
+ if "name" in netdev:
+ return
+ dev_type = netdev["type"]
+ if dev_type == "eth":
+ self.assign_name_by_scan(dev_id, netdev)
+ elif dev_type == "bond":
+ self._assign_name_bond(netdev, config)
+ elif dev_type == "bridge":
+ self._assign_name_bridge(netdev, config)
+ elif dev_type == "macvlan":
+ self._assign_name_macvlan(netdev, config)
+ elif dev_type == "team":
+ self._assign_name_team(netdev, config)
+ elif dev_type == "vlan":
+ self._assign_name_vlan(netdev, config)