Skip to content

Commit 802b680

Browse files
committed
fix pre-commit
1 parent 31acaa6 commit 802b680

37 files changed

+537
-562
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ target/
6565
.idea/
6666

6767
/vnc_websocket.py
68+
/_deploy.py

cloudshell/cp/proxmox/actions/validation.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
from __future__ import annotations
22

33
import logging
4-
from attrs import define
54
from collections.abc import Iterable
65
from typing import TYPE_CHECKING
76

7+
from attrs import define
88

9-
from cloudshell.cp.proxmox.exceptions import (
10-
InvalidAttributeException,
11-
)
9+
from cloudshell.cp.proxmox.exceptions import InvalidAttributeException
1210
from cloudshell.cp.proxmox.handlers.proxmox_handler import ProxmoxHandler
1311

1412
if TYPE_CHECKING:

cloudshell/cp/proxmox/actions/vm_details.py

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,38 @@
1111
VmDetailsNetworkInterface,
1212
VmDetailsProperty,
1313
)
14-
1514
from cloudshell.cp.proxmox.actions.vm_network import VMNetworkActions
16-
from cloudshell.cp.proxmox.exceptions import InstanceIsNotRunningException, \
17-
VMIPNotFoundException
18-
from cloudshell.cp.proxmox.models.deploy_app import (
19-
BaseProxmoxDeployApp,
20-
)
21-
from cloudshell.cp.proxmox.models.deployed_app import (
22-
BaseProxmoxDeployedApp,
15+
from cloudshell.cp.proxmox.exceptions import (
16+
InstanceIsNotRunningException,
17+
VMIPNotFoundException,
2318
)
19+
from cloudshell.cp.proxmox.models.deploy_app import BaseProxmoxDeployApp
20+
from cloudshell.cp.proxmox.models.deployed_app import BaseProxmoxDeployedApp
2421
from cloudshell.cp.proxmox.utils.units_converter import format_bytes
2522

2623
if TYPE_CHECKING:
27-
from cloudshell.cp.proxmox.handlers.proxmox_handler import ProxmoxHandler
2824
from cloudshell.cp.core.cancellation_manager import CancellationContextManager
25+
from cloudshell.cp.proxmox.handlers.proxmox_handler import ProxmoxHandler
2926
from cloudshell.cp.proxmox.resource_config import ProxmoxResourceConfig
3027

3128
logger = logging.getLogger(__name__)
3229

33-
APP_MODEL_TYPES = Union[
34-
BaseProxmoxDeployApp, BaseProxmoxDeployedApp
35-
]
30+
APP_MODEL_TYPES = Union[BaseProxmoxDeployApp, BaseProxmoxDeployedApp]
3631

3732

3833
class VMDetailsActions:
3934
def __init__(
40-
self,
41-
ph: ProxmoxHandler,
42-
resource_conf: ProxmoxResourceConfig,
43-
cancellation_manager: CancellationContextManager,
35+
self,
36+
ph: ProxmoxHandler,
37+
resource_conf: ProxmoxResourceConfig,
38+
cancellation_manager: CancellationContextManager,
4439
):
4540
self._ph = ph
4641
self._resource_conf = resource_conf
4742
self._cancellation_manager = cancellation_manager
4843

4944
def _prepare_common_vm_instance_data(
50-
self,
51-
instance_id: int,
52-
wait_for_results: bool = True
45+
self, instance_id: int, wait_for_results: bool = True
5346
) -> list[VmDetailsProperty]:
5447
vm_info = {}
5548
if wait_for_results:
@@ -62,39 +55,42 @@ def _prepare_common_vm_instance_data(
6255
VmDetailsProperty(key="CPU", value=f"{vm_info['CPU']} vCPU"),
6356
VmDetailsProperty(key="Memory", value=format_bytes(vm_info["Memory"])),
6457
VmDetailsProperty(key="Guest OS", value=vm_info["Guest OS"]),
65-
VmDetailsProperty(key="Disk Size", value=format_bytes(vm_info["Disk"]))
66-
58+
VmDetailsProperty(key="Disk Size", value=format_bytes(vm_info["Disk"])),
6759
]
6860
return data
6961

70-
def _get_instance_info_with_retries(self, instance_id: int, max_retries: int = 7,
71-
timeout: int = 7) \
72-
-> dict[str: str] | None:
62+
def _get_instance_info_with_retries(
63+
self, instance_id: int, max_retries: int = 7, timeout: int = 7
64+
) -> dict[str:str] | None:
7365
retry = -1
7466
while retry < max_retries:
7567
try:
7668
return self._ph.get_instance_info(instance_id=instance_id)
7769
except InstanceIsNotRunningException:
78-
logger.info(f"Instance {instance_id} is not running yet. "
79-
f"Retry in {timeout} seconds")
70+
logger.info(
71+
f"Instance {instance_id} is not running yet. "
72+
f"Retry in {timeout} seconds"
73+
)
8074
time.sleep(timeout)
8175
retry += 1
8276

8377
def _prepare_vm_network_data(
84-
self,
85-
instance_id: int,
86-
app_model: APP_MODEL_TYPES,
87-
wait_for_results: bool = True
78+
self,
79+
instance_id: int,
80+
app_model: APP_MODEL_TYPES,
81+
wait_for_results: bool = True,
8882
) -> list[VmDetailsNetworkInterface]:
8983
"""Prepare VM Network data."""
9084
logger.info(f"Preparing VM Details network data for the {instance_id}")
9185

9286
network_interfaces = []
93-
network_actions = VMNetworkActions(self._resource_conf,
94-
self._cancellation_manager)
87+
network_actions = VMNetworkActions(
88+
self._resource_conf, self._cancellation_manager
89+
)
9590

9691
vnics_data: dict = self._get_instance_interfaces_with_retries(
97-
instance_id=instance_id)
92+
instance_id=instance_id
93+
)
9894
primary_ip = None
9995
if wait_for_results:
10096
with suppress(VMIPNotFoundException):
@@ -114,10 +110,13 @@ def _prepare_vm_network_data(
114110
VmDetailsProperty(key="IP", value=iface.get("ipv4")),
115111
VmDetailsProperty(key="MAC Address", value=mac),
116112
VmDetailsProperty(key="vNIC Name", value=iface.get("name")),
117-
VmDetailsProperty(key="Guest Interface Name", value=iface[
118-
"guest_name"]),
119-
VmDetailsProperty(key="Firewall Enabled", value=str(int(
120-
iface.get("firewall", "0")) == 1)),
113+
VmDetailsProperty(
114+
key="Guest Interface Name", value=iface["guest_name"]
115+
),
116+
VmDetailsProperty(
117+
key="Firewall Enabled",
118+
value=str(int(iface.get("firewall", "0")) == 1),
119+
),
121120
]
122121

123122
ip = None
@@ -140,26 +139,25 @@ def _prepare_vm_network_data(
140139
return network_interfaces
141140

142141
def _get_instance_interfaces_with_retries(
143-
self,
144-
instance_id: int,
145-
max_retries: int = 7,
146-
timeout: int = 5
147-
) -> dict[str: dict] | None:
142+
self, instance_id: int, max_retries: int = 7, timeout: int = 5
143+
) -> dict[str:dict] | None:
148144
retry = -1
149145
while retry < max_retries:
150146
try:
151147
return self._ph.get_instance_ifaces_info(instance_id=instance_id)
152148
except InstanceIsNotRunningException:
153-
logger.info(f"Instance {instance_id} is not running yet. "
154-
f"Retry in {timeout} seconds")
149+
logger.info(
150+
f"Instance {instance_id} is not running yet. "
151+
f"Retry in {timeout} seconds"
152+
)
155153
time.sleep(timeout)
156154
retry += 1
157155

158156
def create(
159-
self,
160-
instance_id: int,
161-
app_model: APP_MODEL_TYPES,
162-
wait_for_results: bool = True
157+
self,
158+
instance_id: int,
159+
app_model: APP_MODEL_TYPES,
160+
wait_for_results: bool = True,
163161
) -> VmDetailsData:
164162
try:
165163
app_name = app_model.app_name # DeployApp
@@ -169,13 +167,12 @@ def create(
169167
try:
170168
# instance_id = int(app_model.vmdetails.uid)
171169
instance_details = self._prepare_common_vm_instance_data(
172-
instance_id=instance_id,
173-
wait_for_results=wait_for_results
170+
instance_id=instance_id, wait_for_results=wait_for_results
174171
)
175172
network_details = self._prepare_vm_network_data(
176173
instance_id=instance_id,
177174
app_model=app_model,
178-
wait_for_results=wait_for_results
175+
wait_for_results=wait_for_results,
179176
)
180177
except Exception as e:
181178
logger.exception("Failed to created VM Details:")

cloudshell/cp/proxmox/actions/vm_network.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
if TYPE_CHECKING:
1414
from cloudshell.cp.core.cancellation_manager import CancellationContextManager
15-
1615
from cloudshell.cp.proxmox.resource_config import ProxmoxResourceConfig
1716

1817

cloudshell/cp/proxmox/cli/websocket_session.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
from typing import TYPE_CHECKING
55

66
import websocket
7+
78
from cloudshell.cli.session.session_exceptions import SessionReadTimeout
89
from cloudshell.cli.session.telnet_session import TelnetSession
9-
1010
from cloudshell.cp.proxmox.handlers.proxmox_handler import ProxmoxHandler
1111

12-
1312
if TYPE_CHECKING:
1413
from logging import Logger
1514

1615
from cloudshell.cli.types import T_ON_SESSION_START, T_TIMEOUT
1716

1817

19-
ansi_escape = re.compile(r'''
18+
ansi_escape = re.compile(
19+
r"""
2020
\x1B # ESC
2121
(?: # 7-bit C1 Fe (except CSI)
2222
[@-Z\\-_]
@@ -26,21 +26,23 @@
2626
[ -/]* # Intermediate bytes
2727
[@-~] # Final byte
2828
)
29-
''', re.VERBOSE)
29+
""",
30+
re.VERBOSE,
31+
)
3032

3133

3234
class WebSocketSession(TelnetSession):
3335
def __init__(
34-
self,
35-
host: str,
36-
username: str,
37-
password: str,
38-
node: str,
39-
port: int | None = None,
40-
on_session_start: T_ON_SESSION_START | None = None,
41-
proxmox_handler: ProxmoxHandler = None,
42-
*args,
43-
**kwargs,
36+
self,
37+
host: str,
38+
username: str,
39+
password: str,
40+
node: str,
41+
port: int | None = None,
42+
on_session_start: T_ON_SESSION_START | None = None,
43+
proxmox_handler: ProxmoxHandler = None,
44+
*args,
45+
**kwargs,
4446
):
4547
super().__init__(
4648
host,
@@ -55,10 +57,7 @@ def __init__(
5557
self._node = node
5658

5759
def _initialize_session(
58-
self,
59-
prompt: str,
60-
logger: Logger,
61-
proxmox_handler: ProxmoxHandler = None
60+
self, prompt: str, logger: Logger, proxmox_handler: ProxmoxHandler = None
6261
) -> None:
6362
if not proxmox_handler and not self.proxmox_handler:
6463
raise ValueError("Proxmox handler is not provided")
@@ -112,7 +111,7 @@ def _read_str_data(self) -> str:
112111
break
113112
else:
114113
str_data = byte_data.decode()
115-
return ansi_escape.sub('', str_data)
114+
return ansi_escape.sub("", str_data)
116115

117116
def disconnect(self) -> None:
118117
if self._handler:

cloudshell/cp/proxmox/constants.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
VM_FROM_VM_DEPLOYMENT_PATH = f"{SHELL_NAME}.Proxmox Instance From VM 2G"
99
VM_FROM_TEMPLATE_DEPLOYMENT_PATH = f"{SHELL_NAME}.Proxmox Instance From Template 2G"
10-
CONTAINER_FROM_IMAGE_DEPLOYMENT_PATH = (f"{SHELL_NAME}.Proxmox Instance From "
11-
f"Container Image 2G")
10+
CONTAINER_FROM_IMAGE_DEPLOYMENT_PATH = (
11+
f"{SHELL_NAME}.Proxmox Instance From " f"Container Image 2G"
12+
)
1213
VM_FROM_QEMU_DEPLOYMENT_PATH = f"{SHELL_NAME}.Proxmox Instance From QEMU Image 2G"
13-
CONTAINER_FROM_CONTAINER_DEPLOYMENT_PATH = (f"{SHELL_NAME}.Proxmox Instance From "
14-
f"Container 2G")
14+
CONTAINER_FROM_CONTAINER_DEPLOYMENT_PATH = (
15+
f"{SHELL_NAME}.Proxmox Instance From " f"Container 2G"
16+
)
1517

1618
COOKIES = "PVEAuthCookie"
1719
TOKEN = "CSRFPreventionToken"
@@ -36,4 +38,4 @@
3638

3739
INSTANCE_CFG_EXC_KEYS = [INSTANCE_CFG_TAGS, INSTANCE_CFG_DESCRIPTION]
3840

39-
MAC_REGEXP = re.compile(r"([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})+")
41+
MAC_REGEXP = re.compile(r"([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})+")

cloudshell/cp/proxmox/exceptions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from collections.abc import Iterable
4+
45
from attrs import define
56

67
from cloudshell.cp.proxmox.constants import SNAPSHOT_TYPE
@@ -26,6 +27,7 @@ def __init__(
2627
class AuthAPIException(BaseProxmoxException):
2728
"""Wrong ticket Exception."""
2829

30+
2931
class InstanceIsNotRunningException(BaseProxmoxException):
3032
"""Instance is not running."""
3133

cloudshell/cp/proxmox/flows/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22

33
from .autoload import ProxmoxAutoloadFlow
44
from .delete_instance import ProxmoxDeleteFlow
5-
# from .get_attribute_hints.command import get_hints
65
from .power_flow import ProxmoxPowerFlow
7-
# from .refresh_ip import refresh_ip
86
from .snapshots import ProxmoxSnapshotFlow
9-
# from .validate_attributes import validate_attributes
107
from .vm_details import ProxmoxGetVMDetailsFlow
118

129
__all__ = (
13-
# refresh_ip,
1410
ProxmoxAutoloadFlow,
1511
ProxmoxPowerFlow,
1612
ProxmoxDeleteFlow,
1713
ProxmoxSnapshotFlow,
1814
ProxmoxGetVMDetailsFlow,
19-
# get_hints,
20-
# validate_attributes,
2115
)

cloudshell/cp/proxmox/flows/autoload.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from __future__ import annotations
22

33
import logging
4-
5-
from attrs import define
64
from typing import TYPE_CHECKING
75

8-
from cloudshell.shell.core.driver_context import AutoLoadDetails
6+
from attrs import define
97

108
from cloudshell.cp.proxmox.actions.validation import ValidationActions
9+
from cloudshell.shell.core.driver_context import AutoLoadDetails
1110

1211
if TYPE_CHECKING:
1312
from cloudshell.cp.proxmox.handlers.proxmox_handler import ProxmoxHandler

0 commit comments

Comments
 (0)