22
22
LOG = logging.getLogger(__name__)
25
def _raise_unsupported_error(method=None):
27
raise exception.UnsupportedDriverExtension(_(
28
"Unsupported method (%s) passed through to vendor extension.")
30
raise exception.MissingParameterValue(_(
31
"Method not specified when calling vendor extension."))
34
25
class MixinVendorInterface(base.VendorInterface):
35
26
"""Wrapper around multiple VendorInterfaces."""
48
39
self.mapping = mapping
49
40
self.driver_level_mapping = driver_passthru_mapping or {}
51
def _map(self, **kwargs):
41
self.vendor_routes = self._build_routes(self.mapping)
42
self.driver_routes = self._build_routes(self.driver_level_mapping,
45
def _build_routes(self, map_dict, driver_passthru=False):
46
"""Build the mapping for the vendor calls.
48
Build the mapping between the given methods and the corresponding
51
:param map_dict: dict of {'method': interface} specifying how
52
to map multiple vendor calls to interfaces.
53
:param driver_passthru: Boolean value. Whether build the mapping
54
to the node vendor passthru or driver
58
for method_name in map_dict:
59
iface = map_dict[method_name]
61
driver_methods = iface.driver_routes
63
driver_methods = iface.vendor_routes
66
d.update({method_name: driver_methods[method_name]})
71
def _get_route(self, **kwargs):
72
"""Return the driver interface which contains the given method.
74
:param method: The name of the vendor method.
52
76
method = kwargs.get('method')
53
return self.mapping.get(method) or _raise_unsupported_error(method)
78
raise exception.MissingParameterValue(
79
_("Method not specified when calling vendor extension."))
82
route = self.mapping[method]
84
raise exception.InvalidParameterValue(
85
_('No handler for method %s') % method)
55
89
def get_properties(self):
56
90
"""Return the properties from all the VendorInterfaces.
70
104
:raises: UnsupportedDriverExtension if 'method' can not be mapped to
71
105
the supported interfaces.
72
:raises: InvalidParameterValue if **kwargs does not contain 'method'.
106
:raises: InvalidParameterValue if kwargs does not contain 'method'.
73
107
:raisee: MissingParameterValue if missing parameters in kwargs.
76
route = self._map(**kwargs)
110
route = self._get_route(**kwargs)
77
111
route.validate(*args, **kwargs)
79
def vendor_passthru(self, task, **kwargs):
80
"""Call vendor_passthru on the appropriate interface only.
82
Returns or raises according to the requested vendor_passthru method.
84
:raises: UnsupportedDriverExtension if 'method' can not be mapped to
85
the supported interfaces.
86
:raises: MissingParameterValue if **kwargs does not contain 'method'.
89
route = self._map(**kwargs)
90
return route.vendor_passthru(task, **kwargs)
92
def driver_vendor_passthru(self, context, method, **kwargs):
93
"""Call driver_vendor_passthru on a mapped interface based on the
96
Returns or raises according to the requested driver_vendor_passthru
98
:raises: UnsupportedDriverExtension if 'method' cannot be mapped to
99
a supported interface.
101
iface = self.driver_level_mapping.get(method)
103
_raise_unsupported_error(method)
105
return iface.driver_vendor_passthru(context, method, **kwargs)
108
114
def get_node_mac_addresses(task):
109
115
"""Get all MAC addresses for the ports belonging to this task's node.