Debian Codegraph @

ansible_collections/community/general/plugins/module_utils/_hpe3par.py

raw
1 # Copyright (c) 2018, Hewlett Packard Enterprise Development LP
2 # Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
3 # SPDX-License-Identifier: BSD-2-Clause
4
5 # Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
6 # Do not use this from other collections or standalone plugins/modules!
7
8 from __future__ import annotations
9
10 import typing as t
11
12 from ansible.module_utils import basic
13
14
15 def convert_to_binary_multiple(size_with_unit: str | None) -> int:
16 if size_with_unit is None:
17 return -1
18 valid_units = ["MiB", "GiB", "TiB"]
19 valid_unit = False
20 for unit in valid_units:
21 if size_with_unit.strip().endswith(unit):
22 valid_unit = True
23 size = size_with_unit.split(unit)[0]
24 if float(size) < 0:
25 return -1
26 if not valid_unit:
27 raise ValueError(f"{size_with_unit} does not have a valid unit. The unit must be one of {valid_units}")
28
29 size = size_with_unit.replace(" ", "").split("iB")[0]
30 size_kib = basic.human_to_bytes(size)
31 return int(size_kib / (1024 * 1024))
32
33
34 storage_system_spec = {
35 "storage_system_ip": {"required": True, "type": "str"},
36 "storage_system_username": {"required": True, "type": "str", "no_log": True},
37 "storage_system_password": {"required": True, "type": "str", "no_log": True},
38 "secure": {"type": "bool", "default": False},
39 }
40
41
42 def cpg_argument_spec() -> dict[str, t.Any]:
43 spec = {
44 "state": {"required": True, "choices": ["present", "absent"], "type": "str"},
45 "cpg_name": {"required": True, "type": "str"},
46 "domain": {"type": "str"},
47 "growth_increment": {
48 "type": "str",
49 },
50 "growth_limit": {
51 "type": "str",
52 },
53 "growth_warning": {
54 "type": "str",
55 },
56 "raid_type": {"required": False, "type": "str", "choices": ["R0", "R1", "R5", "R6"]},
57 "set_size": {"required": False, "type": "int"},
58 "high_availability": {"type": "str", "choices": ["PORT", "CAGE", "MAG"]},
59 "disk_type": {"type": "str", "choices": ["FC", "NL", "SSD"]},
60 }
61 spec.update(storage_system_spec)
62 return spec