File: enterprise_pool.py

package info (click to toggle)
python-pypowervm 1.1.24%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 7,400 kB
  • sloc: python: 29,780; xml: 174; makefile: 14
file content (275 lines) | stat: -rw-r--r-- 9,697 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# Copyright 2016 IBM Corp.
#
# All Rights Reserved.
#
#    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.

from oslo_log import log as logging

from pypowervm import const
from pypowervm.i18n import _
from pypowervm.wrappers import entry_wrapper
from pypowervm.wrappers import mtms as mtms_wrapper

LOG = logging.getLogger(__name__)


_POWER_ENTERPRISE_POOL = 'PowerEnterprisePool'
_POWER_ENTERPRISE_POOL_MEMBER = 'PowerEnterprisePoolMember'

_P_POOL_ID = 'PoolID'
_P_POOL_NAME = 'PoolName'

_P_COMPLIANCE_STATE = 'ComplianceState'
_P_COMPLIANCE_REMAINING_HOURS = 'ComplianceRemainingHours'
_PM_PROC_COMPLIANCE_HOURS_LEFT = 'ProcComplianceRemainingHours'
_PM_MEM_COMPLIANCE_HOURS_LEFT = 'MemComplianceRemainingHours'

_P_TOTAL_MOBILE_PROCS = 'TotalMobileCoDProcUnits'
_P_AVAIL_MOBILE_PROCS = 'AvailableMobileCoDProcUnits'
_UNRET_MOBILE_PROCS = 'UnreturnedMobileCoDProcUnits'
_P_TOTAL_MOBILE_MEM = 'TotalMobileCoDMemory'
_P_AVAIL_MOBILE_MEM = 'AvailableMobileCoDMemory'
_UNRET_MOBILE_MEM = 'UnreturnedMobileCoDMemory'

_PM_MOBILE_PROCS = 'MobileCoDProcUnits'
_PM_MOBILE_MEM = 'MobileCoDMemory'
_PM_INACTIVE_PROCS = 'InactiveProcUnits'
_PM_INACTIVE_MEM = 'InactiveMemory'

_PM_SYS_NAME = 'ManagedSystemName'
_PM_SYS_INSTALLED_PROCS = 'ManagedSystemInstalledProcUnits'
_PM_SYS_INSTALLED_MEM = 'ManagedSystemInstalledMemory'
_PM_SYS_MTMS = 'ManagedSystemMachineTypeModelSerialNumber'
_PM_SYS_STATE = 'ManagedSystemState'

_MGMT_CONSOLES = 'PowerEnterprisePoolManagementConsoles'
_MGMT_CONSOLE = 'PowerEnterprisePoolManagementConsole'
_MGMT_CONSOLE_NAME = 'ManagementConsoleName'
_MGMT_CONSOLE_MTMS = 'ManagementConsoleMachineTypeModelSerialNumber'
_MGMT_CONSOLE_IS_MASTER_CONSOLE = 'IsMasterConsole'
_MGMT_CONSOLE_IP_ADDR = 'ManagementConsoleIPAddress'


class ComplianceState(object):
    IN_COMPLIANCE = 'InCompliance'
    APPROACHING_OUT_OF_COMPLIANCE_SERVER = 'ApproachingOutOfComplianceServer'
    APPROACHING_OUT_OF_COMPLIANCE_POOL = 'ApproachingOutOfCompliancePool'
    OUT_OF_COMPLIANCE = 'OutOfCompliance'
    UNAVAILABLE = 'Unavailable'


@entry_wrapper.EntryWrapper.pvm_type(_POWER_ENTERPRISE_POOL, has_metadata=True)
class Pool(entry_wrapper.EntryWrapper):
    """Wraps the Pool entries."""

    @property
    def id(self):
        """Integer enterprise pool ID."""
        return self._get_val_int(_P_POOL_ID)

    @property
    def name(self):
        """The name of the enterprise pool."""
        return self._get_val_str(_P_POOL_NAME)

    @property
    def compliance_state(self):
        """The compliance state of the enterprise pool."""
        return self._get_val_str(_P_COMPLIANCE_STATE)

    @entry_wrapper.Wrapper.xag_property(const.XAG.ADV)
    def compliance_hours_left(self):
        """Integer num of hours until the pool is considered out of compliance.

        Return default of 0 if it is not found.
        """
        return self._get_val_int(_P_COMPLIANCE_REMAINING_HOURS, default=0)

    @property
    def total_mobile_procs(self):
        """Integer num of the total mobile CoD proc units in the pool."""
        return self._get_val_int(_P_TOTAL_MOBILE_PROCS)

    @property
    def avail_mobile_procs(self):
        """Integer num of the available mobile CoD proc units in the pool."""
        return self._get_val_int(_P_AVAIL_MOBILE_PROCS, default=0)

    @property
    def unret_mobile_procs(self):
        """Integer num of the unreturned mobile CoD proc units in the pool."""
        return self._get_val_int(_UNRET_MOBILE_PROCS)

    @property
    def total_mobile_mem(self):
        """Integer num of the total mobile CoD memory (GB) in the pool."""
        return self._get_val_int(_P_TOTAL_MOBILE_MEM)

    @property
    def avail_mobile_mem(self):
        """Integer num of the available mobile CoD memory (GB) in the pool."""
        return self._get_val_int(_P_AVAIL_MOBILE_MEM, default=0)

    @property
    def unret_mobile_mem(self):
        """Integer num of the unreturned mobile CoD memory (GB) in the pool."""
        return self._get_val_int(_UNRET_MOBILE_MEM)

    @property
    def mgmt_consoles(self):
        """Returns a WrapperElemList of PoolMgmtConsole's."""
        elem = self._find_or_seed(_MGMT_CONSOLES)
        return entry_wrapper.WrapperElemList(
            elem, PoolMgmtConsole)

    @property
    def master_console_mtms(self):
        """The master console MTMS (machine type, model, serial number)."""
        for console in self.mgmt_consoles:
            if console.is_master_console:
                return console.mtms

        LOG.error(_('Unable to determine master management console MTMS '
                    '(machine type, model, serial number) from '
                    '%(identifier)s because no %(param)s was marked as the '
                    'master console for the pool.') %
                  {'identifier': self._type_and_uuid,
                   'param': _MGMT_CONSOLE})

        return None


@entry_wrapper.EntryWrapper.pvm_type(_POWER_ENTERPRISE_POOL_MEMBER,
                                     has_metadata=True)
class PoolMember(entry_wrapper.EntryWrapper):
    """Wraps the PoolMember entries."""

    @property
    def mobile_procs(self):
        """Integer num of the mobile CoD proc units on the system."""
        return self._get_val_int(_PM_MOBILE_PROCS)

    @mobile_procs.setter
    def mobile_procs(self, value):
        self.set_parm_value(_PM_MOBILE_PROCS, value)

    @property
    def mobile_mem(self):
        """Integer amount of mobile CoD memory (GB) on the system."""
        return self._get_val_int(_PM_MOBILE_MEM)

    @mobile_mem.setter
    def mobile_mem(self, value):
        self.set_parm_value(_PM_MOBILE_MEM, value)

    @property
    def inactive_procs(self):
        """Integer num of the inactive (dark) proc units on the system."""
        return self._get_val_int(_PM_INACTIVE_PROCS)

    @property
    def inactive_mem(self):
        """Integer amount of inactive (dark) memory (GB) on the system."""
        return self._get_val_int(_PM_INACTIVE_MEM)

    @property
    def unret_mobile_procs(self):
        """Integer num of the unreturned mobile CoD proc units on the sys."""
        return self._get_val_int(_UNRET_MOBILE_PROCS)

    @property
    def unret_mobile_mem(self):
        """Integer amount of unreturned mobile CoD memory (GB) on the sys."""
        return self._get_val_int(_UNRET_MOBILE_MEM)

    @entry_wrapper.Wrapper.xag_property(const.XAG.ADV)
    def proc_compliance_hours_left(self):
        """Integer num of proc compliance hours remaining.

        Number of hours remaining until the system is considered out of
        compliance in terms of mobile procs.

        Return default of 0 if it is not found.
        """
        return self._get_val_int(_PM_PROC_COMPLIANCE_HOURS_LEFT, default=0)

    @entry_wrapper.Wrapper.xag_property(const.XAG.ADV)
    def mem_compliance_hours_left(self):
        """Integer num of memory compliance hours remaining.

        Number of hours remaining until the system is considered out of
        compliance in terms of mobile memory.

        Return default of 0 if it is not found.
        """
        return self._get_val_int(_PM_MEM_COMPLIANCE_HOURS_LEFT, default=0)

    @property
    def sys_name(self):
        """The name of the system that corresponds to this pool member."""
        return self._get_val_str(_PM_SYS_NAME)

    @property
    def sys_installed_procs(self):
        """Integer num of the installed proc units on the system."""
        return self._get_val_int(_PM_SYS_INSTALLED_PROCS)

    @property
    def sys_installed_mem(self):
        """Integer amount of installed memory (MB) on the system."""
        return self._get_val_int(_PM_SYS_INSTALLED_MEM)

    @property
    def sys_mtms(self):
        """The MTMS (machine type, model, serial number) of the system."""
        sys_mtms_element = self._find(_PM_SYS_MTMS)
        return mtms_wrapper.MTMS.wrap(sys_mtms_element)

    @property
    def sys_state(self):
        """The state of the system."""
        return self._get_val_str(_PM_SYS_STATE)

    @property
    def mgmt_consoles(self):
        """Returns a WrapperElemList of PoolMgmtConsole's."""
        elem = self._find_or_seed(_MGMT_CONSOLES)
        return entry_wrapper.WrapperElemList(
            elem, PoolMgmtConsole)


@entry_wrapper.ElementWrapper.pvm_type(_MGMT_CONSOLE,
                                       has_metadata=True)
class PoolMgmtConsole(entry_wrapper.ElementWrapper):
    """Wraps the PoolMgmtConsole elements."""

    @property
    def name(self):
        """String value for the name of the management console."""
        return self._get_val_str(_MGMT_CONSOLE_NAME)

    @property
    def mtms(self):
        """The MTMS (machine type, model, serial number) of the console."""
        return mtms_wrapper.MTMS.wrap(self.element.find(_MGMT_CONSOLE_MTMS))

    @property
    def is_master_console(self):
        """Boolean for whether or not this console is master for the pool."""
        return self._get_val_bool(_MGMT_CONSOLE_IS_MASTER_CONSOLE)

    @property
    def ip_addr(self):
        """String value for the IP address of the console."""
        return self._get_val_str(_MGMT_CONSOLE_IP_ADDR)