Ejemplo n.º 1
0
def get_sub_resource_path_by(resource, subresource_name):
    """Helper function to find the subresource path

    :param resource: ResourceBase instance on which the name
        gets queried upon.
    :param subresource_name: name of the resource field to
        fetch the '@odata.id' from.
    """
    if not subresource_name:
        raise ValueError('"subresource_name" cannot be empty')

    if not isinstance(subresource_name, list):
        subresource_name = [subresource_name]

    body = resource.json
    for path_item in subresource_name:
        body = body.get(path_item, {})

    if not body:
        raise exceptions.MissingAttributeError(
            attribute='/'.join(subresource_name), resource=resource.path)

    if '@odata.id' not in body:
        raise exceptions.MissingAttributeError(
            attribute='/'.join(subresource_name) + '/@odata.id',
            resource=resource.path)

    return body['@odata.id']
Ejemplo n.º 2
0
 def _get_chassis_collection_path(self):
     """Helper function to find the Chassis Collection path"""
     chassis_col = self.json.get('Chassis')
     if not chassis_col:
         raise exceptions.MissingAttributeError(attribute='Chassis',
                                                resource=self._path)
     return chassis_col.get('@odata.id')
Ejemplo n.º 3
0
 def _get_sessions_collection_path(self):
     """Helper function to find the SessionCollections path"""
     sessions_col = self.json.get('Sessions')
     if not sessions_col:
         raise exceptions.MissingAttributeError(attribute='Sessions',
                                                resource=self._path)
     return sessions_col.get('@odata.id')
Ejemplo n.º 4
0
 def _get_metric_definitions_path(self):
     """Helper function to find the metric definitions path"""
     metrics = self.json.get('MetricDefinitions')
     if not metrics:
         raise exceptions.MissingAttributeError(
             attribute='MetricDefinitions', resource=self._path)
     return utils.get_resource_identity(metrics)
Ejemplo n.º 5
0
 def _get_allocated_pools_path(self):
     """Helper function to find the AllocatedPools path"""
     storage_pool_col = self.json.get('AllocatedPools')
     if not storage_pool_col:
         raise exceptions.MissingAttributeError(attribute='AllocatedPools',
                                                resource=self._path)
     return rsd_lib_utils.get_resource_identity(storage_pool_col)
Ejemplo n.º 6
0
 def _get_storage_pool_collection_path(self):
     """Helper function to find the StoragePoolCollection path"""
     storage_pool_col = self.json.get('StoragePools')
     if not storage_pool_col:
         raise exceptions.MissingAttributeError(attribute='StoragePools',
                                                resource=self._path)
     return utils.get_resource_identity(storage_pool_col)
Ejemplo n.º 7
0
 def _get_zone_collection_path(self):
     """Helper function to find the ZoneCollection path"""
     zone_col = self.json.get('Zones')
     if not zone_col:
         raise exceptions.MissingAttributeError(attribute='Zones',
                                                resource=self._path)
     return rsd_lib_utils.get_resource_identity(zone_col)
Ejemplo n.º 8
0
 def _get_drive_collection_path(self):
     """Helper function to find the DriveCollection path"""
     drive_col = self.json.get('Drives')
     if not drive_col:
         raise exceptions.MissingAttributeError(attribute='Drives',
                                                resource=self._path)
     return utils.get_resource_identity(drive_col)
Ejemplo n.º 9
0
 def _get_volume_collection_path(self):
     """Helper function to find the VolumeCollection path"""
     volume_col = self.json.get('Volumes')
     if not volume_col:
         raise exceptions.MissingAttributeError(attribute='Volumes',
                                                resource=self._path)
     return utils.get_resource_identity(volume_col)
    def _get_metrics_path(self):
        """Helper function to find the metrics path"""
        if 'Metrics' not in self.json:
            raise exceptions.MissingAttributeError(attribute='Metrics',
                                                   resource=self.path)

        return utils.get_members_identities(self.json.get('Metrics'))
Ejemplo n.º 11
0
    def _load(self, body, resource, nested_in=None):
        """Load this field from a JSON object.

        :param body: parsed JSON body.
        :param resource: ResourceBase instance for which the field is loaded.
        :param nested_in: parent resource path (for error reporting only),
            must be a list of strings or None.
        :raises: MissingAttributeError if a required field is missing.
        :raises: MalformedAttributeError on invalid field value or type.
        :returns: loaded and verified value
        """
        name = self._path[-1]
        for path_item in self._path[:-1]:
            body = body.get(path_item, {})

        if name not in body:
            if self._required:
                path = (nested_in or []) + self._path
                raise exceptions.MissingAttributeError(
                    attribute='/'.join(path), resource=resource.path)
            else:
                # Do not run the adapter on the default value
                return self._default

        try:
            value = self._adapter(body[name])
        except (UnicodeError, ValueError, TypeError) as exc:
            path = (nested_in or []) + self._path
            raise exceptions.MalformedAttributeError(attribute='/'.join(path),
                                                     resource=resource.path,
                                                     error=exc)

        return value
Ejemplo n.º 12
0
 def _get_resource_zones_collection_path(self):
     """Helper function to find the ResourceZoneCollections path"""
     res_zone_col = self.json.get('ResourceZones')
     if not res_zone_col:
         raise exceptions.MissingAttributeError(
             attribute='ResourceZones', resource=self._path)
     return res_zone_col.get('@odata.id')
Ejemplo n.º 13
0
 def _get_system_path(self):
     """Helper function to find the System path"""
     system_col = self.json.get('Links').get('ComputerSystem')
     if not system_col:
         raise exceptions.MissingAttributeError(attribute='System',
                                                resource=self._path)
     return system_col.get('@odata.id')
Ejemplo n.º 14
0
 def _get_remote_target_collection_path(self):
     """Helper function to find the RemoteTargetCollection path"""
     remote_target_col = self.json.get('RemoteTargets')
     if not remote_target_col:
         raise exceptions.MissingAttributeError(attribute='RemoteTargets',
                                                resource=self._path)
     return remote_target_col.get('@odata.id')
Ejemplo n.º 15
0
 def _get_physical_drive_collection_path(self):
     """Helper function to find the PhysicalDriveCollection path"""
     physical_drive_col = self.json.get('Drives')
     if not physical_drive_col:
         raise exceptions.MissingAttributeError(attribute='PhysicalDrives',
                                                resource=self._path)
     return physical_drive_col.get('@odata.id')
Ejemplo n.º 16
0
 def _get_endpoint_collection_path(self):
     """Helper function to find the EndpointCollection path"""
     endpoint_col = self.json.get('Endpoints')
     if not endpoint_col:
         raise exceptions.MissingAttributeError(attribute='Endpoints',
                                                resource=self._path)
     return rsd_lib_utils.get_resource_identity(endpoint_col)
Ejemplo n.º 17
0
 def _get_allocated_volumes_path(self):
     """Helper function to find the AllocatedVolumes path"""
     volume_col = self.json.get('AllocatedVolumes')
     if not volume_col:
         raise exceptions.MissingAttributeError(
             attribute='AllocatedVolumes', resource=self._path)
     return rsd_lib_utils.get_resource_identity(volume_col)
Ejemplo n.º 18
0
 def _get_processor_collection_path(self):
     """Helper function to find the ProcessorCollection path"""
     pro_col = self.json.get('ProcessorCollection')
     if not pro_col:
         raise exceptions.MissingAttributeError(
             attribute='ProcessorCollection', resource=self._path)
     return pro_col.get('@odata.id')
Ejemplo n.º 19
0
 def _get_metrics_path(self):
     """Helper function to find the System process metrics path"""
     metrics = self.json.get('Oem').get('Intel_RackScale').get('Metrics')
     if not metrics:
         raise exceptions.MissingAttributeError(
             attribute='Processor Metrics', resource=self._path)
     return utils.get_resource_identity(metrics)
Ejemplo n.º 20
0
 def _get_software_inventory_collection_path(self):
     """Helper function to find the SoftwareInventoryCollections path"""
     soft_inv_col = self.json.get('SoftwareInventory')
     if not soft_inv_col:
         raise exceptions.MissingAttributeError(
             attribute='SoftwareInventory', resource=self._path)
     return soft_inv_col.get('@odata.id')
Ejemplo n.º 21
0
    def get_sessions_path(self):
        """Returns the Sessions url"""

        try:
            links_url = self.json.get('Links')
            return links_url['Sessions']['@odata.id']
        except (TypeError, KeyError):
            raise exceptions.MissingAttributeError(
                attribute='Links/Sessions/@data.id', resource=self.path)
Ejemplo n.º 22
0
def get_sub_resource_path_by(resource, subresource_name, is_collection=False):
    """Helper function to find the subresource path

    :param resource: ResourceBase instance on which the name
        gets queried upon.
    :param subresource_name: name of the resource field to
        fetch the '@odata.id' from.
    :param is_collection: if `True`, expect a list of resources to
        fetch the '@odata.id' from.
    :returns: Resource path (if `is_collection` is `False`) or
        a list of resource paths (if `is_collection` is `True`).
    """
    if not subresource_name:
        raise ValueError('"subresource_name" cannot be empty')

    if not isinstance(subresource_name, list):
        subresource_name = [subresource_name]

    body = resource.json
    for path_item in subresource_name:
        body = body.get(path_item, {})

    if not body:
        raise exceptions.MissingAttributeError(
            attribute='/'.join(subresource_name), resource=resource.path)

    elements = []

    try:
        if is_collection:
            for element in body:
                elements.append(element['@odata.id'])
            return elements

        return body['@odata.id']

    except (TypeError, KeyError):
        attribute = '/'.join(subresource_name)
        if is_collection:
            attribute += '[%s]' % len(elements)
        attribute += '/@odata.id'
        raise exceptions.MissingAttributeError(attribute=attribute,
                                               resource=resource.path)
Ejemplo n.º 23
0
    def get_update_service(self):
        """Get the UpdateService object

        :returns: The UpdateService object
        """
        if not self._update_service_path:
            raise exceptions.MissingAttributeError(
                attribute='UpdateService/@odata.id', resource=self._path)

        return updateservice.UpdateService(
            self._conn, self._update_service_path,
            redfish_version=self.redfish_version)
Ejemplo n.º 24
0
    def firmware_inventory(self):
        """Property to reference FirmwareInventory collection instance"""
        if not self._firmware_inventory_path:
            raise exceptions.MissingAttributeError(
                attribute='FirmwareInventory/@odata.id',
                resource=self._firmware_inventory_path)

        return softwareinventory.SoftwareInventoryCollection(
            self._conn,
            self._firmware_inventory_path,
            redfish_version=self.redfish_version,
            registries=self.registries)
Ejemplo n.º 25
0
    def get_system_collection(self):
        """Get the SystemCollection object

        :raises: MissingAttributeError, if the collection attribute is
            not found
        :returns: a SystemCollection object
        """
        if not self._systems_path:
            raise exceptions.MissingAttributeError(
                attribute='Systems/@odata.id', resource=self._path)

        return system.SystemCollection(self._conn, self._systems_path,
                                       redfish_version=self.redfish_version)
Ejemplo n.º 26
0
    def get_manager_collection(self):
        """Get the ManagerCollection object

        :raises: MissingAttributeError, if the collection attribute is
            not found
        :returns: a ManagerCollection object
        """
        if not self._managers_path:
            raise exceptions.MissingAttributeError(
                attribute='Managers/@odata.id', resource=self._path)

        return manager.ManagerCollection(self._conn, self._managers_path,
                                         redfish_version=self.redfish_version)
Ejemplo n.º 27
0
    def get_chassis_collection(self):
        """Get the ChassisCollection object

        :raises: MissingAttributeError, if the collection attribute is
            not found
        :returns: a ChassisCollection object
        """
        if not self._chassis_path:
            raise exceptions.MissingAttributeError(
                attribute='Chassis/@odata.id', resource=self._path)

        return chassis.ChassisCollection(self._conn, self._chassis_path,
                                         redfish_version=self.redfish_version)
Ejemplo n.º 28
0
Archivo: bios.py Proyecto: sapcc/sushy
    def _get_change_password_element(self):
        actions = self._actions

        if not actions:
            raise exceptions.MissingAttributeError(attribute="Actions",
                                                   resource=self._path)

        change_password_action = actions.change_password

        if not change_password_action:
            raise exceptions.MissingActionError(action='#Bios.ChangePassword',
                                                resource=self._path)
        return change_password_action
Ejemplo n.º 29
0
Archivo: bios.py Proyecto: sapcc/sushy
    def _get_reset_bios_action_element(self):
        actions = self._actions

        if not actions:
            raise exceptions.MissingAttributeError(attribute="Actions",
                                                   resource=self._path)

        reset_bios_action = actions.reset_bios

        if not reset_bios_action:
            raise exceptions.MissingActionError(action='#Bios.ResetBios',
                                                resource=self._path)
        return reset_bios_action
Ejemplo n.º 30
0
    def get_composition_service(self):
        """Get the CompositionService object

        :raises: MissingAttributeError, if the composition service
            attribute is not found
        :returns: The CompositionService object
        """
        if not self._composition_service_path:
            raise exceptions.MissingAttributeError(
                attribute='CompositionService/@odata.id',
                resource=self._path)
        return compositionservice.CompositionService(
            self._conn, self._composition_service_path,
            redfish_version=self.redfish_version)