|
|
|
|
|
|
|
|
|
|
xen-api
[Xen-API] [PATCH 27 of 33] interface-reconfigure: Move bond and VLAN uti
Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
diff -r f45285e6fbe3 -r 7fbd1addf5d8 scripts/InterfaceReconfigure.py
--- a/scripts/InterfaceReconfigure.py Fri Dec 18 14:16:32 2009 +0000
+++ b/scripts/InterfaceReconfigure.py Fri Dec 18 14:16:32 2009 +0000
@@ -404,3 +404,97 @@
return self.__vlans[vlan]
else:
return None
+
+#
+# Bonded PIFs
+#
+def pif_is_bond(pif):
+ pifrec = db().get_pif_record(pif)
+
+ return len(pifrec['bond_master_of']) > 0
+
+def pif_get_bond_masters(pif):
+ """Returns a list of PIFs which are bond masters of this PIF"""
+
+ pifrec = db().get_pif_record(pif)
+
+ bso = pifrec['bond_slave_of']
+
+ # bond-slave-of is currently a single reference but in principle a
+ # PIF could be a member of several bonds which are not
+ # concurrently attached. Be robust to this possibility.
+ if not bso or bso == "OpaqueRef:NULL":
+ bso = []
+ elif not type(bso) == list:
+ bso = [bso]
+
+ bondrecs = [db().get_bond_record(bond) for bond in bso]
+ bondrecs = [rec for rec in bondrecs if rec]
+
+ return [bond['master'] for bond in bondrecs]
+
+def pif_get_bond_slaves(pif):
+ """Returns a list of PIFs which make up the given bonded pif."""
+
+ pifrec = db().get_pif_record(pif)
+
+ bmo = pifrec['bond_master_of']
+ if len(bmo) > 1:
+ raise Error("Bond-master-of contains too many elements")
+
+ if len(bmo) == 0:
+ return []
+
+ bondrec = db().get_bond_record(bmo[0])
+ if not bondrec:
+ raise Error("No bond record for bond master PIF")
+
+ # build a list of slave's pifs
+ slave_pifs = bondrec['slaves']
+
+ # Ensure any currently attached slaves are listed in the opposite order to
the order in
+ # which they were attached. The first slave attached must be the last
detached since
+ # the bond is using its MAC address.
+ try:
+ attached_slaves = open("/sys/class/net/%s/bonding/slaves" %
pifrec['device']).readline().split()
+ for slave in attached_slaves:
+ pifs = [p for p in db().get_pifs_by_device(slave) if not
pif_is_vlan(p)]
+ slave_pif = pifs[0]
+ slave_pifs.remove(slave_pif)
+ slave_pifs.insert(0, slave_pif)
+ except IOError:
+ pass
+
+ return slave_pifs
+
+#
+# VLAN PIFs
+#
+
+def pif_is_vlan(pif):
+ return db().get_pif_record(pif)['VLAN'] != '-1'
+
+def pif_get_vlan_slave(pif):
+ """Find the PIF which is the VLAN slave of pif.
+
+Returns the 'physical' PIF underneath the a VLAN PIF @pif."""
+
+ pifrec = db().get_pif_record(pif)
+
+ vlan = pifrec['VLAN_master_of']
+ if not vlan or vlan == "OpaqueRef:NULL":
+ raise Error("PIF is not a VLAN master")
+
+ vlanrec = db().get_vlan_record(vlan)
+ if not vlanrec:
+ raise Error("No VLAN record found for PIF")
+
+ return vlanrec['tagged_PIF']
+
+def pif_get_vlan_masters(pif):
+ """Returns a list of PIFs which are VLANs on top of the given pif."""
+
+ pifrec = db().get_pif_record(pif)
+ vlans = [db().get_vlan_record(v) for v in pifrec['VLAN_slave_of']]
+ return [v['untagged_PIF'] for v in vlans if v and
db().pif_exists(v['untagged_PIF'])]
+
diff -r f45285e6fbe3 -r 7fbd1addf5d8 scripts/interface-reconfigure
--- a/scripts/interface-reconfigure Fri Dec 18 14:16:32 2009 +0000
+++ b/scripts/interface-reconfigure Fri Dec 18 14:16:32 2009 +0000
@@ -570,68 +570,6 @@
log("Invalid value for mtu = %s" % oc['mtu'])
return None
-#
-# Bonded PIFs
-#
-def pif_is_bond(pif):
- pifrec = db().get_pif_record(pif)
-
- return len(pifrec['bond_master_of']) > 0
-
-def pif_get_bond_masters(pif):
- """Returns a list of PIFs which are bond masters of this PIF"""
-
- pifrec = db().get_pif_record(pif)
-
- bso = pifrec['bond_slave_of']
-
- # bond-slave-of is currently a single reference but in principle a
- # PIF could be a member of several bonds which are not
- # concurrently attached. Be robust to this possibility.
- if not bso or bso == "OpaqueRef:NULL":
- bso = []
- elif not type(bso) == list:
- bso = [bso]
-
- bondrecs = [db().get_bond_record(bond) for bond in bso]
- bondrecs = [rec for rec in bondrecs if rec]
-
- return [bond['master'] for bond in bondrecs]
-
-def pif_get_bond_slaves(pif):
- """Returns a list of PIFs which make up the given bonded pif."""
-
- pifrec = db().get_pif_record(pif)
-
- bmo = pifrec['bond_master_of']
- if len(bmo) > 1:
- raise Error("Bond-master-of contains too many elements")
-
- if len(bmo) == 0:
- return []
-
- bondrec = db().get_bond_record(bmo[0])
- if not bondrec:
- raise Error("No bond record for bond master PIF")
-
- # build a list of slave's pifs
- slave_pifs = bondrec['slaves']
-
- # Ensure any currently attached slaves are listed in the opposite order to
the order in
- # which they were attached. The first slave attached must be the last
detached since
- # the bond is using its MAC address.
- try:
- attached_slaves = open("/sys/class/net/%s/bonding/slaves" %
pifrec['device']).readline().split()
- for slave in attached_slaves:
- pifs = [p for p in db().get_pifs_by_device(slave) if not
pif_is_vlan(p)]
- slave_pif = pifs[0]
- slave_pifs.remove(slave_pif)
- slave_pifs.insert(0, slave_pif)
- except IOError:
- pass
-
- return slave_pifs
-
def configure_bond_interface(pif):
"""Write the configuration for a bond interface.
@@ -688,37 +626,6 @@
f.write("%s=%s " % (name,val))
f.write('"\n')
return f
-
-#
-# VLAN PIFs
-#
-
-def pif_is_vlan(pif):
- return db().get_pif_record(pif)['VLAN'] != '-1'
-
-def pif_get_vlan_slave(pif):
- """Find the PIF which is the VLAN slave of pif.
-
-Returns the 'physical' PIF underneath the a VLAN PIF @pif."""
-
- pifrec = db().get_pif_record(pif)
-
- vlan = pifrec['VLAN_master_of']
- if not vlan or vlan == "OpaqueRef:NULL":
- raise Error("PIF is not a VLAN master")
-
- vlanrec = db().get_vlan_record(vlan)
- if not vlanrec:
- raise Error("No VLAN record found for PIF")
-
- return vlanrec['tagged_PIF']
-
-def pif_get_vlan_masters(pif):
- """Returns a list of PIFs which are VLANs on top of the given pif."""
-
- pifrec = db().get_pif_record(pif)
- vlans = [db().get_vlan_record(v) for v in pifrec['VLAN_slave_of']]
- return [v['untagged_PIF'] for v in vlans if v and
db().pif_exists(v['untagged_PIF'])]
def configure_vlan_interface(pif):
"""Write the configuration for a VLAN interface.
_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api
|
<Prev in Thread] |
Current Thread |
[Next in Thread>
|
- [Xen-API] [PATCH 17 of 33] interface-reconfigure: Rename some functions to match vswitch version, (continued)
- [Xen-API] [PATCH 17 of 33] interface-reconfigure: Rename some functions to match vswitch version, Ian Campbell
- [Xen-API] [PATCH 15 of 33] interface-reconfigure: Various refactoring, Ian Campbell
- [Xen-API] [PATCH 18 of 33] interface-reconfigure: use the same other-config:ethtool-* and MTU as vswitch version, Ian Campbell
- [Xen-API] [PATCH 20 of 33] interface-reconfigure: add pif_is_bond(), Ian Campbell
- [Xen-API] [PATCH 19 of 33] interface-reconfigure: further separate the concept of ipdev and datapath, Ian Campbell
- [Xen-API] [PATCH 21 of 33] interface-reconfigure: explicitly rename devices early, Ian Campbell
- [Xen-API] [PATCH 22 of 33] interface-reconfigure: move /etc/init.d/management-interface to this repository, Ian Campbell
- [Xen-API] [PATCH 23 of 33] interface-reconfigure: Do not try to bring down interfaces before forcing them up, Ian Campbell
- [Xen-API] [PATCH 24 of 33] interface-reconfigure: do not require a PIF for rewrite action, Ian Campbell
- [Xen-API] [PATCH 25 of 33] interface-reconfigure: Refactor the action_* methods, Ian Campbell
- [Xen-API] [PATCH 27 of 33] interface-reconfigure: Move bond and VLAN utilities to utility module,
Ian Campbell <=
- [Xen-API] [PATCH 29 of 33] interface-reconfigure: Move ethtool and MTU setting utilities to module, Ian Campbell
- [Xen-API] [PATCH 28 of 33] interface-reconfigure: do not sort the result in pif_get_bond_slaves, Ian Campbell
- [Xen-API] [PATCH 26 of 33] interface-reconfigure: Move DatabaseCache object to utility module, Ian Campbell
- [Xen-API] [PATCH 31 of 33] interface-reconfigure: Improve error handling of if{up, down} if ifcfg, Ian Campbell
- [Xen-API] [PATCH 32 of 33] interface-reconfigure: Add license headers to new InterfaceReconfigure*.py, Ian Campbell
- [Xen-API] [PATCH 33 of 33] interface-reconfigure: vswitch: explicitly configure IP device MAC address, Ian Campbell
- [Xen-API] [PATCH 30 of 33] interface-reconfigure: move datapath configuration to module, Ian Campbell
- [Xen-API] [PATCH 16 of 33] interface-reconfigure: hang all configuration off of the ipdev, Ian Campbell
|
|
|
|
|