[node-patches] Change in ovirt-node[master]: [DRAFT] network: Rewrite network config backend
fabiand at fedoraproject.org
fabiand at fedoraproject.org
Thu Jun 6 13:13:31 UTC 2013
Fabian Deutsch has uploaded a new change for review.
Change subject: [DRAFT] network: Rewrite network config backend
......................................................................
[DRAFT] network: Rewrite network config backend
The network backend doing the actual OS level configuration work was
rewritten to allow different topologies, and to prepare the migration to
NetworkManager.
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=971410
Change-Id: I653023c9f856f1be51e45b86457ce24a3878015b
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M src/ovirt/node/config/defaults.py
M src/ovirt/node/config/network.py
M src/ovirt/node/utils/fs.py
M src/ovirt/node/utils/network.py
4 files changed, 132 insertions(+), 6 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/12/15412/1
diff --git a/src/ovirt/node/config/defaults.py b/src/ovirt/node/config/defaults.py
index 246fc51..11234a6 100644
--- a/src/ovirt/node/config/defaults.py
+++ b/src/ovirt/node/config/defaults.py
@@ -19,8 +19,10 @@
# MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html.
from ovirt.node import base, exceptions, valid, utils, config
-from ovirt.node.utils import storage, process
+from ovirt.node.config.network import NicConfig
+from ovirt.node.utils import storage, process, fs
from ovirt.node.utils.fs import ShellVarFile
+from ovirt.node.utils.network import NIC
import glob
import logging
import os
@@ -254,11 +256,10 @@
def transaction(self):
"""Return all transactions to re-configure networking
-
- FIXME this should be rewritten o allow more fine grained progress
- informations
"""
+ return self.__legacy_transaction()
+ def __legacy_transaction(self):
class ConfigureNIC(utils.Transaction.Element):
title = "Configuring NIC"
@@ -284,6 +285,99 @@
tx.append(ReloadNetworkConfiguration())
return tx
+ def __transaction(self):
+ services = ["network", "ntpd", "ntpdate", "rpcbind", "nfslock",
+ "rpcidmapd", "rpcgssd"]
+
+ def do_services(cmd, services):
+ for name in services:
+ process.call(["service", name, "stop"])
+
+ class StopNetworkServices(utils.Transaction.Element):
+ title = "Stop network services"
+
+ def commit(self):
+ do_services("stop", reversed(services))
+
+ class RemoveConfiguration(utils.Transaction.Element):
+ title = "Remove existing configuration"
+
+ def commit(self):
+ self._remove_devices()
+ self._remove_ifcfg_configs()
+
+ def _remove_devices(self):
+ vlans = utils.network.Vlans()
+ vifs = vlans.all_vlan_devices()
+ self.logger.debug("Attempting to delete all vlans: %s" % vifs)
+ for vifname in vifs:
+ process.call(["vconfig", "rem", vifname])
+ if NicConfig(vifname).exists:
+ NicConfig(vifname).delete()
+
+ def _remove_ifcfg_configs(self):
+ pat = NicConfig.IfcfgBackend.filename_tpl % "*"
+ remaining_ifcfgs = glob.glob(pat)
+ self.logger.debug("Attemtping to remove remaining ifcfgs: %s" %
+ remaining_ifcfgs)
+ pcfg = fs.Config()
+ for fn in remaining_ifcfgs:
+ pcfg.delete(fn)
+
+ class WriteConfiguration(utils.Transaction.Element):
+ title = "Write new configuration"
+
+ def commit(self):
+ topology = NetworkTopology().retrieve()["topology"]
+ if topology == "direct":
+ pass
+ else:
+ self.__write_bridged_config()
+
+ def __write_bridged_config(self):
+ m = Network().retrieve()
+
+ # Bridge is always the same
+ bridge_ifname = "br%s" % m["iface"]
+ bridge_cfg = NicConfig(bridge_ifname)
+ bridge_cfg.bootproto = m["bootproto"]
+ bridge_cfg.ipaddr = m["ipaddr"]
+ bridge_cfg.gateway = m["gateway"]
+ bridge_cfg.netmask = m["netmask"]
+ bridge_cfg.device = bridge_ifname
+ bridge_cfg.onboot = "yes"
+ bridge_cfg.delay = "0"
+
+ # FIXME peerntp
+ # FIXME peerdns
+ # FIXME ipv6
+
+ slave_ifname_vlan = "%s.%s" % (m["iface"],
+ m["vlanid"])
+ slave_ifname = slave_ifname_vlan if m["vlanid"] else m["iface"]
+ slave_cfg = NicConfig(slave_ifname)
+ slave_cfg.device = slave_ifname
+ slave_cfg.bridge = bridge_ifname
+ slave_cfg.hwaddr = NIC(m["iface"]).hwaddr
+ slave_cfg.vlan = "yes" if m["vlanid"] else None
+ slave_cfg.onboot = "yes"
+
+ bridge_cfg.save()
+ slave_cfg.save()
+
+ class StartNetworkServices(utils.Transaction.Element):
+ title = "Start network services"
+
+ def commit(self):
+ do_services("start", services)
+ utils.AugeasWrapper.force_reload()
+ utils.network.reset_resolver()
+
+ tx = utils.Transaction("Applying new network configuration")
+ tx.append(WriteConfiguration())
+ tx.append(ReloadNetworkConfiguration())
+ return tx
+
def configure_no_networking(self, iface=None):
"""Can be used to disable all networking
"""
diff --git a/src/ovirt/node/config/network.py b/src/ovirt/node/config/network.py
index 0f70a77..5dcf1ae 100644
--- a/src/ovirt/node/config/network.py
+++ b/src/ovirt/node/config/network.py
@@ -19,7 +19,7 @@
# MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html.
from ovirt.node import utils, base
-from ovirt.node.utils import AugeasWrapper as Augeas
+from ovirt.node.utils import AugeasWrapper as Augeas, fs
from ovirt.node.utils.fs import ShellVarFile
import glob
import logging
@@ -47,6 +47,8 @@
vlan = None
device = None
onboot = None
+ delay = None
+ hwaddr = None
ipv6init = None
ipv6forwarding = None
@@ -61,7 +63,7 @@
_keys = ["bridge", "type", "bootproto", "ipaddr", "netmask",
"gateway", "vlan", "device", "onboot", "hwaddr",
"ipv6init", "ipv6forwarding", "ipv6_autoconf",
- "dhcpv6c", "ipv6addr", "ipv6_defaultgw"]
+ "dhcpv6c", "ipv6addr", "ipv6_defaultgw", "delay"]
def __init__(self, ifname):
super(NicConfig, self).__init__()
@@ -88,6 +90,9 @@
return data
def save(self):
+ return self._backend.write(self.ifname)
+
+ def delete(self):
return self._backend.write(self.ifname)
def __str__(self):
@@ -130,6 +135,18 @@
data[k.upper()] = cfg.__dict__.get(k)
dst.update(data, True)
+ pcfg = fs.Config()
+ if pcfg.enabled():
+ pcfg.persist(filename)
+
+ def delete(self, ifname):
+ filename = self.filename_tpl % ifname
+
+ pcfg = fs.Config()
+ if pcfg.enabled():
+ pcfg.unpersist(filename)
+
+ os.remove(filename)
def _aug_get_or_set(augpath, new_servers=None):
"""Get or set some servers
diff --git a/src/ovirt/node/utils/fs.py b/src/ovirt/node/utils/fs.py
index 580d543..400c636 100644
--- a/src/ovirt/node/utils/fs.py
+++ b/src/ovirt/node/utils/fs.py
@@ -205,6 +205,13 @@
from ovirtnode import ovirtfunctions
return ovirtfunctions.remove_config(filename)
+ def delete(self, filename):
+ """Remove the persiste version and the file
+ """
+ if filename:
+ from ovirtnode import ovirtfunctions
+ return ovirtfunctions.ovirt_safe_delete_config(filename)
+
def exists(self, filename):
"""Check if the given file is persisted
"""
diff --git a/src/ovirt/node/utils/network.py b/src/ovirt/node/utils/network.py
index 6513012..2532cfa 100644
--- a/src/ovirt/node/utils/network.py
+++ b/src/ovirt/node/utils/network.py
@@ -676,3 +676,11 @@
"""Check if ifname is a vlan device
"""
return self.nic_for_vlan_device(vifname) is not None
+
+ def all_vlan_devices(self):
+ """Return all vlan devices
+ """
+ all_devices = []
+ for vifs in self.parse_cfg().values():
+ all_devices += vifs
+ return all_devices
\ No newline at end of file
--
To view, visit http://gerrit.ovirt.org/15412
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I653023c9f856f1be51e45b86457ce24a3878015b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>
More information about the node-patches
mailing list