X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=xenserver%2Fopt_xensource_libexec_InterfaceReconfigure.py;h=e99ae5834a62f2e1922a8d1ce71fff08407836f2;hb=f7cd0081f525dd1d45fafc68397b5393196e978d;hp=48b39389a62eb1d11748f8ad0bcda96d28297353;hpb=a361c3a86a035142590b8d8c9830e18ba1fc3091;p=openvswitch diff --git a/xenserver/opt_xensource_libexec_InterfaceReconfigure.py b/xenserver/opt_xensource_libexec_InterfaceReconfigure.py index 48b39389..e99ae583 100644 --- a/xenserver/opt_xensource_libexec_InterfaceReconfigure.py +++ b/xenserver/opt_xensource_libexec_InterfaceReconfigure.py @@ -245,9 +245,10 @@ def _map_to_xml(xml, parent, tag, val, attrs): e = xml.createElement(tag) parent.appendChild(e) for n,v in val.items(): - if not n in attrs: - raise Error("Unknown other-config attribute: %s" % n) - _str_to_xml(xml, e, n, v) + if n in attrs: + _str_to_xml(xml, e, n, v) + else: + log("Unknown other-config attribute: %s" % n) def _map_from_xml(n, attrs): ret = {} @@ -276,6 +277,7 @@ _VLAN_XML_TAG = "vlan" _TUNNEL_XML_TAG = "tunnel" _BOND_XML_TAG = "bond" _NETWORK_XML_TAG = "network" +_POOL_XML_TAG = "pool" _ETHTOOL_OTHERCONFIG_ATTRS = ['ethtool-%s' % x for x in 'autoneg', 'speed', 'duplex', 'rx', 'tx', 'sg', 'tso', 'ufo', 'gso' ] @@ -329,7 +331,7 @@ _BOND_ATTRS = { 'uuid': (_str_to_xml,_str_from_xml), lambda n: _strlist_from_xml(n, 'slaves', 'slave')), } -_NETWORK_OTHERCONFIG_ATTRS = [ 'mtu', 'static-routes' ] + _ETHTOOL_OTHERCONFIG_ATTRS +_NETWORK_OTHERCONFIG_ATTRS = [ 'mtu', 'static-routes', 'vswitch-controller-fail-mode' ] + _ETHTOOL_OTHERCONFIG_ATTRS _NETWORK_ATTRS = { 'uuid': (_str_to_xml,_str_from_xml), 'bridge': (_str_to_xml,_str_from_xml), @@ -340,6 +342,12 @@ _NETWORK_ATTRS = { 'uuid': (_str_to_xml,_str_from_xml), lambda n: _otherconfig_from_xml(n, _NETWORK_OTHERCONFIG_ATTRS)), } +_POOL_OTHERCONFIG_ATTRS = ['vswitch-controller-fail-mode'] + +_POOL_ATTRS = { 'other_config': (lambda x, p, t, v: _otherconfig_to_xml(x, p, v, _POOL_OTHERCONFIG_ATTRS), + lambda n: _otherconfig_from_xml(n, _POOL_OTHERCONFIG_ATTRS)), + } + # # Database Cache object # @@ -443,6 +451,20 @@ class DatabaseCache(object): if not rec['other_config'].has_key(f): continue self.__networks[n]['other_config'][f] = rec['other_config'][f] + def __get_pool_records_from_xapi(self, session): + self.__pools = {} + for p in session.xenapi.pool.get_all(): + rec = session.xenapi.pool.get_record(p) + + self.__pools[p] = {} + + for f in _POOL_ATTRS: + self.__pools[p][f] = rec[f] + + for f in _POOL_OTHERCONFIG_ATTRS: + if rec['other_config'].has_key(f): + self.__pools[p]['other_config'][f] = rec['other_config'][f] + def __to_xml(self, xml, parent, key, ref, rec, attrs): """Encode a database object as XML""" e = xml.createElement(key) @@ -496,6 +518,7 @@ class DatabaseCache(object): if error == "MESSAGE_METHOD_UNKNOWN" and details == "tunnel.get_all": pass + self.__get_pool_records_from_xapi(session) self.__get_vlan_records_from_xapi(session) self.__get_bond_records_from_xapi(session) self.__get_network_records_from_xapi(session) @@ -510,6 +533,7 @@ class DatabaseCache(object): self.__pifs = {} self.__bonds = {} self.__vlans = {} + self.__pools = {} self.__tunnels = {} self.__networks = {} @@ -536,6 +560,9 @@ class DatabaseCache(object): elif n.nodeName == _NETWORK_XML_TAG: (ref,rec) = self.__from_xml(n, _NETWORK_ATTRS) self.__networks[ref] = rec + elif n.nodeName == _POOL_XML_TAG: + (ref,rec) = self.__from_xml(n, _POOL_ATTRS) + self.__pools[ref] = rec else: raise Error("Unknown XML element %s" % n.nodeName) @@ -554,6 +581,8 @@ class DatabaseCache(object): for (ref,rec) in self.__networks.items(): self.__to_xml(xml, xml.documentElement, _NETWORK_XML_TAG, ref, rec, _NETWORK_ATTRS) + for (ref,rec) in self.__pools.items(): + self.__to_xml(xml, xml.documentElement, _POOL_XML_TAG, ref, rec, _POOL_ATTRS) f = open(cache_file, 'w') f.write(xml.toprettyxml()) @@ -575,10 +604,21 @@ class DatabaseCache(object): filter(lambda (ref,rec): rec['device'] == device, self.__pifs.items())) + def get_networks_with_bridge(self, bridge): + return map(lambda (ref,rec): ref, + filter(lambda (ref,rec): rec['bridge'] == bridge, + self.__networks.items())) + + def get_network_by_bridge(self, bridge): + #Assumes one network has bridge. + try: + return self.get_networks_with_bridge(bridge)[0] + except KeyError: + return None + def get_pif_by_bridge(self, bridge): - networks = map(lambda (ref,rec): ref, - filter(lambda (ref,rec): rec['bridge'] == bridge, - self.__networks.items())) + networks = self.get_networks_with_bridge(bridge) + if len(networks) == 0: raise Error("No matching network \"%s\"" % bridge) @@ -629,6 +669,10 @@ class DatabaseCache(object): else: return None + def get_pool_record(self): + if len(self.__pools) > 0: + return self.__pools.values()[0] + # # #