diff options
author | Jasper Capel <capel@stone-it.com> | 2008-09-30 12:33:06 +0200 |
---|---|---|
committer | Jasper Capel <capel@stone-it.com> | 2008-09-30 12:33:06 +0200 |
commit | 94e8963a122eb2f147ab4d87527f97a0457babd5 (patch) | |
tree | d353e2afd1ab13b65d26d6dae45a1abdbc6fa58d /func | |
parent | 886d7c16a2a2b93a81ed865604fda6598592b3e8 (diff) | |
download | func-94e8963a122eb2f147ab4d87527f97a0457babd5.tar.gz func-94e8963a122eb2f147ab4d87527f97a0457babd5.tar.xz func-94e8963a122eb2f147ab4d87527f97a0457babd5.zip |
Added write() and list_permanent() methods to VLAN module. Also upped the module and API versions.
Diffstat (limited to 'func')
-rw-r--r-- | func/minion/modules/vlan.py | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/func/minion/modules/vlan.py b/func/minion/modules/vlan.py index 9a2171f..60df983 100644 --- a/func/minion/modules/vlan.py +++ b/func/minion/modules/vlan.py @@ -19,11 +19,11 @@ # 02110-1301 USA import func_module -import os +import os, re class Vlan(func_module.FuncModule): - version = "0.0.1" - api_version = "0.0.1" + version = "0.0.2" + api_version = "0.0.2" description = "Func module for VLAN management" # A list of VLAN IDs that should be ignored. @@ -62,6 +62,27 @@ class Vlan(func_module.FuncModule): return retlist + def list_permanent(self): + # Returns a dictionary of permanent VLANs, return format is the same as + # in the list() method. + retlist = {} + pattern = re.compile('ifcfg-([a-z0-9]+)\.([0-9]+)') + + for item in os.listdir("/etc/sysconfig/network-scripts"): + match = pattern.match(item) + if match: + interface = match.group(1) + vlanid = match.group(2) + + if interface not in retlist: + retlist[interface] = [ vlanid ] + else: + retlist[interface].append(vlanid) + + return retlist + + + def add(self, interface, vlanid): vlanid = int(vlanid) # Adds a vlan with vlanid on interface @@ -175,4 +196,33 @@ class Vlan(func_module.FuncModule): # Todo: Compare the current configuration to the supplied configuration return self.list() + + def write(self): + # Permantly applies configuration obtained through the list() method to + # the system. + currentconfig = self.list_permanent() + newconfig = self.list() + + # First, remove all VLANs present in current configuration, that are + # not present in new configuration. + for interface, vlans in currentconfig.iteritems(): + if interface not in newconfig: + for vlan in vlans: + self.delete_permanent(interface, vlan) + + else: + for vlan in vlans: + if vlan not in newconfig[interface]: + self.delete_permanent(interface, vlan) + + for interface, vlans in newconfig.iteritems(): + if interface not in currentconfig: + for vlan in vlans: + self.add_permanent(interface, vlan) + + else: + for vlan in vlans: + if vlan not in currentconfig[interface]: + self.add_permanent(interface, vlan) + return self.list_permanent() |