]>
git.proxmox.com Git - ceph.git/blob - ceph/src/python-common/ceph/deployment/inventory.py
361adf3c36845f828bcef8e4c7f1c5067cf921eb
2 from typing
import List
, Optional
, Dict
, Any
4 pass # for type checking
11 A container for Device instances with reporting
14 def __init__(self
, devices
):
15 # type: (List[Device]) -> None
16 self
.devices
= devices
# type: List[Device]
18 def __eq__(self
, other
):
19 return self
.to_json() == other
.to_json()
22 # type: () -> List[dict]
23 return [d
.to_json() for d
in self
.devices
]
26 def from_json(cls
, input):
27 # type: (List[Dict[str, Any]]) -> Devices
28 return cls([Device
.from_json(i
) for i
in input])
31 return Devices(devices
=list(self
.devices
))
41 'human_readable_type',
47 sys_api
=None, # type: Optional[Dict[str, Any]]
48 available
=None, # type: Optional[bool]
49 rejected_reasons
=None, # type: Optional[List[str]]
50 lvs
=None, # type: Optional[List[str]]
51 device_id
=None, # type: Optional[str]
54 self
.sys_api
= sys_api
if sys_api
is not None else {} # type: Dict[str, Any]
55 self
.available
= available
56 self
.rejected_reasons
= rejected_reasons
if rejected_reasons
is not None else []
58 self
.device_id
= device_id
63 k
: getattr(self
, k
) for k
in self
.report_fields
67 def from_json(cls
, input):
68 # type: (Dict[str, Any]) -> Device
69 if not isinstance(input, dict):
70 raise ValueError('Device: Expected dict. Got `{}...`'.format(json
.dumps(input)[:10]))
73 key
: input.get(key
, None)
74 for key
in Device
.report_fields
75 if key
!= 'human_readable_type'
81 def human_readable_type(self
):
83 if self
.sys_api
is None or 'rotational' not in self
.sys_api
:
85 return 'hdd' if self
.sys_api
["rotational"] == "1" else 'ssd'