~ubuntu-branches/ubuntu/vivid/ironic/vivid-updates

« back to all changes in this revision

Viewing changes to ironic/drivers/utils.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-01-05 12:21:37 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20150105122137-171bqrdpcxqipunk
Tags: 2015.1~b1-0ubuntu1
* New upstream beta release:
  - d/control: Align version requirements with upstream release.
* d/watch: Update uversionmangle to deal with kilo beta versioning
  changes.
* d/control: Bumped Standards-Version to 3.9.6, no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
LOG = logging.getLogger(__name__)
23
23
 
24
24
 
25
 
def _raise_unsupported_error(method=None):
26
 
    if method:
27
 
        raise exception.UnsupportedDriverExtension(_(
28
 
            "Unsupported method (%s) passed through to vendor extension.")
29
 
            % method)
30
 
    raise exception.MissingParameterValue(_(
31
 
        "Method not specified when calling vendor extension."))
32
 
 
33
 
 
34
25
class MixinVendorInterface(base.VendorInterface):
35
26
    """Wrapper around multiple VendorInterfaces."""
36
27
 
47
38
        """
48
39
        self.mapping = mapping
49
40
        self.driver_level_mapping = driver_passthru_mapping or {}
50
 
 
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,
 
43
                                                driver_passthru=True)
 
44
 
 
45
    def _build_routes(self, map_dict, driver_passthru=False):
 
46
        """Build the mapping for the vendor calls.
 
47
 
 
48
        Build the mapping between the given methods and the corresponding
 
49
        method metadata.
 
50
 
 
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
 
55
                                vendor passthru.
 
56
        """
 
57
        d = {}
 
58
        for method_name in map_dict:
 
59
            iface = map_dict[method_name]
 
60
            if driver_passthru:
 
61
                driver_methods = iface.driver_routes
 
62
            else:
 
63
                driver_methods = iface.vendor_routes
 
64
 
 
65
            try:
 
66
                d.update({method_name: driver_methods[method_name]})
 
67
            except KeyError:
 
68
                pass
 
69
        return d
 
70
 
 
71
    def _get_route(self, **kwargs):
 
72
        """Return the driver interface which contains the given method.
 
73
 
 
74
        :param method: The name of the vendor method.
 
75
        """
52
76
        method = kwargs.get('method')
53
 
        return self.mapping.get(method) or _raise_unsupported_error(method)
 
77
        if not method:
 
78
            raise exception.MissingParameterValue(
 
79
                _("Method not specified when calling vendor extension."))
 
80
 
 
81
        try:
 
82
            route = self.mapping[method]
 
83
        except KeyError:
 
84
            raise exception.InvalidParameterValue(
 
85
                _('No handler for method %s') % method)
 
86
 
 
87
        return route
54
88
 
55
89
    def get_properties(self):
56
90
        """Return the properties from all the VendorInterfaces.
69
103
 
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.
74
108
 
75
109
        """
76
 
        route = self._map(**kwargs)
 
110
        route = self._get_route(**kwargs)
77
111
        route.validate(*args, **kwargs)
78
112
 
79
 
    def vendor_passthru(self, task, **kwargs):
80
 
        """Call vendor_passthru on the appropriate interface only.
81
 
 
82
 
        Returns or raises according to the requested vendor_passthru method.
83
 
 
84
 
        :raises: UnsupportedDriverExtension if 'method' can not be mapped to
85
 
                 the supported interfaces.
86
 
        :raises: MissingParameterValue if **kwargs does not contain 'method'.
87
 
 
88
 
        """
89
 
        route = self._map(**kwargs)
90
 
        return route.vendor_passthru(task, **kwargs)
91
 
 
92
 
    def driver_vendor_passthru(self, context, method, **kwargs):
93
 
        """Call driver_vendor_passthru on a mapped interface based on the
94
 
        specified method.
95
 
 
96
 
        Returns or raises according to the requested driver_vendor_passthru
97
 
 
98
 
        :raises: UnsupportedDriverExtension if 'method' cannot be mapped to
99
 
                 a supported interface.
100
 
        """
101
 
        iface = self.driver_level_mapping.get(method)
102
 
        if iface is None:
103
 
            _raise_unsupported_error(method)
104
 
 
105
 
        return iface.driver_vendor_passthru(context, method, **kwargs)
106
 
 
107
113
 
108
114
def get_node_mac_addresses(task):
109
115
    """Get all MAC addresses for the ports belonging to this task's node.