1111 VmDetailsNetworkInterface ,
1212 VmDetailsProperty ,
1313)
14-
1514from 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
2421from cloudshell .cp .proxmox .utils .units_converter import format_bytes
2522
2623if 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
3128logger = logging .getLogger (__name__ )
3229
33- APP_MODEL_TYPES = Union [
34- BaseProxmoxDeployApp , BaseProxmoxDeployedApp
35- ]
30+ APP_MODEL_TYPES = Union [BaseProxmoxDeployApp , BaseProxmoxDeployedApp ]
3631
3732
3833class 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:" )
0 commit comments