def interface_exists(i):
return os.path.exists("/sys/class/net/" + i)
+ETHTOOL_OTHERCONFIG_ATTRS = ['ethtool-%s' % x for x in 'autoneg', 'speed', 'duplex', 'rx', 'tx', 'sg', 'tso', 'ufo', 'gso' ]
+
+PIF_ATTRS = [ 'uuid',
+ 'management',
+ 'network',
+ 'device',
+ 'bond_master_of',
+ 'bond_slave_of',
+ 'VLAN',
+ 'VLAN_master_of',
+ 'VLAN_slave_of',
+ 'ip_configuration_mode',
+ 'IP',
+ 'netmask',
+ 'gateway',
+ 'DNS',
+ 'MAC'
+ ]
+
+PIF_OTHERCONFIG_ATTRS = [ 'domain', 'peerdns', 'defaultroute', 'mtu', 'static-routes' ] + \
+ [ 'bond-%s' % x for x in 'mode', 'miimon', 'downdelay', 'updelay', 'use_carrier' ] + \
+ ETHTOOL_OTHERCONFIG_ATTRS
+
+VLAN_ATTRS = [ 'uuid',
+ 'tagged_PIF',
+ 'untagged_PIF'
+ ]
+
+BOND_ATTRS = [ 'uuid',
+ 'master',
+ 'slaves'
+ ]
+
+NETWORK_ATTRS = [ 'uuid',
+ 'PIFs',
+ 'bridge'
+ ]
+
+NETWORK_OTHERCONFIG_ATTRS = [ 'mtu', 'static-routes' ] + ETHTOOL_OTHERCONFIG_ATTRS
+
+
class DatabaseCache(object):
def __read_xensource_inventory(self):
filename = "/etc/xensource-inventory"
return dict(defs)
+
def __pif_on_host(self,pif):
return self.__pifs.has_key(pif)
-
+
+
def __get_pif_records_from_xapi(self, session, host):
- recs = session.xenapi.PIF.get_all_records()
- self.__pifs = dict(filter(lambda (ref,rec): rec['host'] == host, recs.iteritems()))
+ self.__pifs = {}
+ for (p,rec) in session.xenapi.PIF.get_all_records().items():
+ if rec['host'] != host:
+ continue
+ self.__pifs[p] = {}
+ for f in PIF_ATTRS:
+ self.__pifs[p][f] = rec[f]
+ self.__pifs[p]['other_config'] = {}
+ for f in PIF_OTHERCONFIG_ATTRS:
+ if not rec['other_config'].has_key(f): continue
+ self.__pifs[p]['other_config'][f] = rec['other_config'][f]
def __get_vlan_records_from_xapi(self, session):
- self.__vlans = dict(filter(lambda (ref,rec): self.__pif_on_host(rec['untagged_PIF']),
- session.xenapi.VLAN.get_all_records().iteritems()))
-
+ self.__vlans = {}
+ for v in session.xenapi.VLAN.get_all():
+ rec = session.xenapi.VLAN.get_record(v)
+ if not self.__pif_on_host(rec['untagged_PIF']):
+ continue
+ self.__vlans[v] = {}
+ for f in VLAN_ATTRS:
+ self.__vlans[v][f] = rec[f]
+
def __get_bond_records_from_xapi(self, session):
- self.__bonds = dict(filter(lambda (ref,rec): self.__pif_on_host(rec['master']),
- session.xenapi.Bond.get_all_records().iteritems()))
+ self.__bonds = {}
+ for b in session.xenapi.Bond.get_all():
+ rec = session.xenapi.Bond.get_record(b)
+ if not self.__pif_on_host(rec['master']):
+ continue
+ self.__bonds[b] = {}
+ for f in BOND_ATTRS:
+ self.__bonds[b][f] = rec[f]
def __get_network_records_from_xapi(self, session):
- self.__networks = session.xenapi.network.get_all_records()
-
+ self.__networks = {}
+ for n in session.xenapi.network.get_all():
+ rec = session.xenapi.network.get_record(n)
+ self.__networks[n] = {}
+ for f in NETWORK_ATTRS:
+ self.__networks[n][f] = rec[f]
+ self.__networks[n]['other_config'] = {}
+ for f in NETWORK_OTHERCONFIG_ATTRS:
+ if not rec['other_config'].has_key(f): continue
+ self.__networks[n]['other_config'][f] = rec['other_config'][f]
+
def __init__(self, session_ref=None, cache_file=None):
if session_ref and cache_file:
raise Error("can't specify session reference and cache file")
-
if cache_file == None:
session = XenAPI.xapi_local()