pystorcli.cachevault

StorCLI cachevault python module

  1# -*- coding: utf-8 -*-
  2
  3# Copyright (c) 2018, Martin Dojcak <martin@dojcak.sk>
  4# Copyright (c) 2022, Rafael Leira & Naudit HPCN S.L. <rafael.leira@naudit.es>
  5# See LICENSE for details.
  6
  7'''StorCLI cachevault python module
  8'''
  9
 10from . import StorCLI
 11from . import common
 12from . import exc
 13
 14
 15class CacheVaultMetrics(object):
 16    """StorCLI CacheVaultMerics
 17
 18    Instance of this class represents cache vault metrics
 19
 20    Args:
 21        cv (:obj:CacheVault): cache vault object
 22
 23    Properties:
 24        temperature (str): cache vault temperature in celsius
 25        state (str): cache vault state
 26        replacement_required (str): check if cache vault replacement is required
 27        offload_status (str): check if cache vault has got space to cache offload
 28        all (dict): all metrics
 29    """
 30
 31    def __init__(self, cv):
 32        """Constructor - create StorCLI CacheVaultMetrics object
 33
 34        Args:
 35            cv (:obj:CacheVault): cachevault object
 36        """
 37        self._cv = cv
 38
 39    @property
 40    def _show_all(self):
 41        args = [
 42            'show',
 43            'all'
 44        ]
 45        return common.response_data(self._cv._run(args))
 46
 47    def _response_property(self, data):
 48        return [(i['Property'], i['Value']) for i in data]
 49
 50    @property
 51    def _info(self):
 52        return self._show_all['Cachevault_Info']
 53
 54    @property
 55    def _firmware_satus(self):
 56        return self._show_all['Firmware_Status']
 57
 58    @property
 59    @common.stringify
 60    def temperature(self):
 61        """(str): cache vault temperature in celsius
 62        """
 63        for key, value in self._response_property(self._info):
 64            if key == 'Temperature':
 65                return value.split()[0]
 66        return 'unknown'
 67
 68    @property
 69    @common.lower
 70    def state(self):
 71        """(str): cache vault state (optimal | ??? | unknown )
 72        FIXME: need to know all possible states of the cache vault (string from binary doesnt help)
 73        """
 74        for key, value in self._response_property(self._info):
 75            if key == 'State':
 76                return value
 77        return 'unknown'
 78
 79    @property
 80    @common.lower
 81    def replacement_required(self):
 82        """(str): check if cache vault replacement is required
 83        """
 84        for key, value in self._response_property(self._firmware_satus):
 85            if key == 'Replacement required':
 86                return value
 87        return 'unknown'
 88
 89    @property
 90    def offload_status(self):
 91        """(str): cache offload space ( ok | fail | unknown)
 92        """
 93        for key, value in self._response_property(self._firmware_satus):
 94            if key == 'No space to cache offload':
 95                if value == 'No':
 96                    return 'ok'
 97                else:
 98                    return 'fail'
 99        return 'unknown'
100
101    @property
102    def all(self):
103        """(dict): all metrics
104        """
105        metrics = {}
106
107        for attribute in dir(self):
108            if not attribute.startswith('_') and not attribute == 'all':
109                metrics[attribute] = self.__getattribute__(attribute)
110        return metrics
111
112
113class CacheVault(object):
114    """StorCLI CacheVault
115
116    Instance of this class represents cachevault in StorCLI hierarchy
117
118    Args:
119        ctl_id (str): controller id
120        binary (str): storcli binary or full path to the binary
121
122    Properties:
123        facts (dict): raw cache vault facts
124        metrics (:obj:CacheVaultMetrics): cache vault metrics
125
126    Methods:
127        create_vd (:obj:VirtualDrive): create virtual drive
128
129    """
130
131    def __init__(self, ctl_id, binary='storcli64'):
132        """Constructor - create StorCLI CacheVault object
133
134        Args:
135            ctl_id (str): controller id
136            binary (str): storcli binary or full path to the binary
137        """
138        self._ctl_id = ctl_id
139        self._binary = binary
140        self._storcli = StorCLI(binary)
141        self._name = '/c{0}/cv'.format(self._ctl_id)
142
143        self._exist()
144
145    def _run(self, args, **kwargs):
146        args = args[:]
147        args.insert(0, self._name)
148        return self._storcli.run(args, **kwargs)
149
150    def _exist(self):
151        try:
152            self._run(['show'])
153        except exc.StorCliCmdError:
154            raise exc.StorCliMissingError(
155                self.__class__.__name__, self._name) from None
156
157    @property
158    def facts(self):
159        args = [
160            'show',
161            'all'
162        ]
163        return common.response_data(self._run(args))
164
165    @property
166    def metrics(self):
167        """(:obj:CacheVaultMetrics): cache vault metrics
168        """
169        return CacheVaultMetrics(self)
class CacheVaultMetrics:
 16class CacheVaultMetrics(object):
 17    """StorCLI CacheVaultMerics
 18
 19    Instance of this class represents cache vault metrics
 20
 21    Args:
 22        cv (:obj:CacheVault): cache vault object
 23
 24    Properties:
 25        temperature (str): cache vault temperature in celsius
 26        state (str): cache vault state
 27        replacement_required (str): check if cache vault replacement is required
 28        offload_status (str): check if cache vault has got space to cache offload
 29        all (dict): all metrics
 30    """
 31
 32    def __init__(self, cv):
 33        """Constructor - create StorCLI CacheVaultMetrics object
 34
 35        Args:
 36            cv (:obj:CacheVault): cachevault object
 37        """
 38        self._cv = cv
 39
 40    @property
 41    def _show_all(self):
 42        args = [
 43            'show',
 44            'all'
 45        ]
 46        return common.response_data(self._cv._run(args))
 47
 48    def _response_property(self, data):
 49        return [(i['Property'], i['Value']) for i in data]
 50
 51    @property
 52    def _info(self):
 53        return self._show_all['Cachevault_Info']
 54
 55    @property
 56    def _firmware_satus(self):
 57        return self._show_all['Firmware_Status']
 58
 59    @property
 60    @common.stringify
 61    def temperature(self):
 62        """(str): cache vault temperature in celsius
 63        """
 64        for key, value in self._response_property(self._info):
 65            if key == 'Temperature':
 66                return value.split()[0]
 67        return 'unknown'
 68
 69    @property
 70    @common.lower
 71    def state(self):
 72        """(str): cache vault state (optimal | ??? | unknown )
 73        FIXME: need to know all possible states of the cache vault (string from binary doesnt help)
 74        """
 75        for key, value in self._response_property(self._info):
 76            if key == 'State':
 77                return value
 78        return 'unknown'
 79
 80    @property
 81    @common.lower
 82    def replacement_required(self):
 83        """(str): check if cache vault replacement is required
 84        """
 85        for key, value in self._response_property(self._firmware_satus):
 86            if key == 'Replacement required':
 87                return value
 88        return 'unknown'
 89
 90    @property
 91    def offload_status(self):
 92        """(str): cache offload space ( ok | fail | unknown)
 93        """
 94        for key, value in self._response_property(self._firmware_satus):
 95            if key == 'No space to cache offload':
 96                if value == 'No':
 97                    return 'ok'
 98                else:
 99                    return 'fail'
100        return 'unknown'
101
102    @property
103    def all(self):
104        """(dict): all metrics
105        """
106        metrics = {}
107
108        for attribute in dir(self):
109            if not attribute.startswith('_') and not attribute == 'all':
110                metrics[attribute] = self.__getattribute__(attribute)
111        return metrics

StorCLI CacheVaultMerics

Instance of this class represents cache vault metrics

Args: cv (CacheVault): cache vault object

Properties: temperature (str): cache vault temperature in celsius state (str): cache vault state replacement_required (str): check if cache vault replacement is required offload_status (str): check if cache vault has got space to cache offload all (dict): all metrics

CacheVaultMetrics(cv)
32    def __init__(self, cv):
33        """Constructor - create StorCLI CacheVaultMetrics object
34
35        Args:
36            cv (:obj:CacheVault): cachevault object
37        """
38        self._cv = cv

Constructor - create StorCLI CacheVaultMetrics object

Args: cv (CacheVault): cachevault object

temperature

func effective wrapper

state

func effective wrapper

replacement_required

func effective wrapper

offload_status

(str): cache offload space ( ok | fail | unknown)

all

(dict): all metrics

class CacheVault:
114class CacheVault(object):
115    """StorCLI CacheVault
116
117    Instance of this class represents cachevault in StorCLI hierarchy
118
119    Args:
120        ctl_id (str): controller id
121        binary (str): storcli binary or full path to the binary
122
123    Properties:
124        facts (dict): raw cache vault facts
125        metrics (:obj:CacheVaultMetrics): cache vault metrics
126
127    Methods:
128        create_vd (:obj:VirtualDrive): create virtual drive
129
130    """
131
132    def __init__(self, ctl_id, binary='storcli64'):
133        """Constructor - create StorCLI CacheVault object
134
135        Args:
136            ctl_id (str): controller id
137            binary (str): storcli binary or full path to the binary
138        """
139        self._ctl_id = ctl_id
140        self._binary = binary
141        self._storcli = StorCLI(binary)
142        self._name = '/c{0}/cv'.format(self._ctl_id)
143
144        self._exist()
145
146    def _run(self, args, **kwargs):
147        args = args[:]
148        args.insert(0, self._name)
149        return self._storcli.run(args, **kwargs)
150
151    def _exist(self):
152        try:
153            self._run(['show'])
154        except exc.StorCliCmdError:
155            raise exc.StorCliMissingError(
156                self.__class__.__name__, self._name) from None
157
158    @property
159    def facts(self):
160        args = [
161            'show',
162            'all'
163        ]
164        return common.response_data(self._run(args))
165
166    @property
167    def metrics(self):
168        """(:obj:CacheVaultMetrics): cache vault metrics
169        """
170        return CacheVaultMetrics(self)

StorCLI CacheVault

Instance of this class represents cachevault in StorCLI hierarchy

Args: ctl_id (str): controller id binary (str): storcli binary or full path to the binary

Properties: facts (dict): raw cache vault facts metrics (CacheVaultMetrics): cache vault metrics

Methods: create_vd (VirtualDrive): create virtual drive

CacheVault(ctl_id, binary='storcli64')
132    def __init__(self, ctl_id, binary='storcli64'):
133        """Constructor - create StorCLI CacheVault object
134
135        Args:
136            ctl_id (str): controller id
137            binary (str): storcli binary or full path to the binary
138        """
139        self._ctl_id = ctl_id
140        self._binary = binary
141        self._storcli = StorCLI(binary)
142        self._name = '/c{0}/cv'.format(self._ctl_id)
143
144        self._exist()

Constructor - create StorCLI CacheVault object

Args: ctl_id (str): controller id binary (str): storcli binary or full path to the binary

facts
metrics

(CacheVaultMetrics): cache vault metrics