From: Ian Campbell Date: Thu, 6 Aug 2009 20:50:15 +0000 (-0700) Subject: xenserver: Whitelist specific XAPI fields to pickle in interface-reconfigure. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=171ed168592f59b95fa0a3ef3a5ad60262881811;p=openvswitch xenserver: Whitelist specific XAPI fields to pickle in interface-reconfigure. Only add certain fields to the database cache of database objects. This constrains the cases we need to deal with when pickling/unpickling. CP-1148. --- diff --git a/xenserver/opt_xensource_libexec_interface-reconfigure b/xenserver/opt_xensource_libexec_interface-reconfigure index 50f4f0c2..4a7dc9c8 100755 --- a/xenserver/opt_xensource_libexec_interface-reconfigure +++ b/xenserver/opt_xensource_libexec_interface-reconfigure @@ -248,6 +248,47 @@ def check_allowed(pif): 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" @@ -260,28 +301,59 @@ class DatabaseCache(object): 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()