File: base.py

package info (click to toggle)
python-sushy 5.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,036 kB
  • sloc: python: 16,382; makefile: 24; sh: 2
file content (82 lines) | stat: -rw-r--r-- 2,772 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import logging

from sushy.resources import base


LOG = logging.getLogger(__name__)


class OEMResourceBase(base.ResourceBase):

    def __init__(self,
                 connector,
                 path='',
                 redfish_version=None,
                 registries=None,
                 reader=None,
                 root=None):
        """Class representing an OEM vendor extension

        :param connector: A Connector instance
        :param path: sub-URI path to the resource.
        :param redfish_version: The version of Redfish. Used to construct
            the object according to schema of the given version.
        :param registries: Dict of Redfish Message Registry objects to be
            used in any resource that needs registries to parse messages
        :param root: Sushy root object. Empty for Sushy root itself.
        """
        self._parent_resource = None
        self._vendor_id = None

        super().__init__(
            connector, path,
            redfish_version=redfish_version, registries=registries,
            reader=reader, root=root)

    def set_parent_resource(self, parent_resource, vendor_id):
        self._parent_resource = parent_resource
        self._vendor_id = vendor_id
        # NOTE(etingof): this is required to pull OEM subtree
        self.invalidate(force_refresh=True)
        return self

    def _parse_attributes(self, json_doc):
        """Parse the attributes of a resource.

        Parsed JSON fields are set to `self` as declared in the class.

        :param json_doc: parsed JSON document in form of Python types
        """
        # Too early to parse, need to call set_parent_resource first that
        # assigns vendor_id and re-parses attributes
        if self._vendor_id is None:
            return

        oem_json = json_doc.get(
            'Oem', {}).get(self._vendor_id, {})

        # NOTE(etingof): temporary copy Actions into Oem subtree for parsing
        # all fields at once

        oem_json = oem_json.copy()

        oem_actions_json = {
            'Actions': json_doc.get(
                'Actions', {}).get('Oem', {})
        }

        oem_json.update(oem_actions_json)

        super()._parse_attributes(oem_json)