33"""Vm class."""
44
55import logging
6- from dataclasses import asdict
76from time import sleep
87from typing import Dict , Union , List , TYPE_CHECKING
98
109from mfd_common_libs import add_logging_level , log_levels
1110from mfd_connect import RPyCConnection , Connection
12- from mfd_hyperv .attributes .vm_params import VMParams
13- from mfd_hyperv .exceptions import HyperVException
14- from mfd_hyperv .hypervisor import VMProcessorAttributes
11+ from mfd_host import Host
1512from mfd_network_adapter import NetworkAdapterOwner
1613from mfd_typing import MACAddress
1714from mfd_typing .network_interface import InterfaceType
1815
16+ from mfd_hyperv .attributes .vm_params import VMParams
17+ from mfd_hyperv .exceptions import HyperVException
18+ from mfd_hyperv .hypervisor import VMProcessorAttributes
19+
1920if TYPE_CHECKING :
2021 from mfd_hyperv import HyperV
2122 from mfd_hyperv .instances .vm_network_interface import VMNetworkInterface
2526add_logging_level (level_name = "MODULE_DEBUG" , level_value = log_levels .MODULE_DEBUG )
2627
2728
28- class VM :
29- """VM class."""
29+ class VM ( Host ) :
30+ """VM class that inherits from Host ."""
3031
3132 def __init__ (
3233 self ,
@@ -35,24 +36,26 @@ def __init__(
3536 owner : NetworkAdapterOwner = None ,
3637 hyperv : "HyperV" = None ,
3738 connection_timeout : int = None ,
39+ ** kwargs ,
3840 ):
3941 """VM constructor."""
40- self . connection = connection
42+ super (). __init__ ( connection = connection , ** kwargs )
4143 self .guest = NetworkAdapterOwner (connection = connection )
4244 self .attributes = {}
4345 self .owner = owner
4446 self ._hyperv = None
4547 self .hyperv = hyperv
46-
4748 self .connection_timeout = connection_timeout
48- self ._propagate_params (vm_params )
49+ self .mng_ip = vm_params .mng_ip
50+ self .name = vm_params .name
51+ self .vm_params = vm_params
4952
5053 def __str__ (self ) -> str :
5154 return f"{ self .name } "
5255
5356 @property
5457 def hyperv (self ) -> "HyperV" :
55- """Hyperv property representing host's hyperv object.
58+ """HyperV property representing host's HyperV object.
5659
5760 :raises: HyperVException when this property is empty
5861 """
@@ -64,7 +67,7 @@ def hyperv(self) -> "HyperV":
6467
6568 @property
6669 def interfaces (self ) -> List ["VMNetworkInterface" ]:
67- """Hyperv property representing VM interfaces.
70+ """HyperV property representing VM interfaces.
6871
6972 :raises: HyperVException when this property is empty
7073 """
@@ -79,11 +82,6 @@ def hyperv(self, value: "HyperV") -> None:
7982 """Hyperv property setter."""
8083 self ._hyperv = value
8184
82- def _propagate_params (self , params : VMParams ) -> None :
83- """Add VMParams as attributes of virtual machine object."""
84- for key , value in asdict (params ).items ():
85- setattr (self , key , value )
86-
8785 def get_attributes (self ) -> Dict [str , str ]:
8886 """Get Virtual machine attributes from host (hypervisor)."""
8987 self .attributes = self .hyperv .hypervisor .get_vm_attributes (self .name )
@@ -131,7 +129,7 @@ def reboot(self, timeout: int = 300) -> None:
131129 self .wait_functional (timeout )
132130
133131 def wait_functional (self , timeout : int = 300 ) -> None :
134- """Wait untill this VM can be pinged.
132+ """Wait until this VM can be pinged.
135133
136134 :param timeout: time given for VM to reach functional state
137135 """
@@ -166,13 +164,16 @@ def _get_ifaces_from_vm(self) -> Dict[str, str]:
166164 logger .log (level = log_levels .MODULE_DEBUG , msg = "Getting cached interfaces" )
167165 return self .hyperv .vm_network_interface_manager .all_vnics_attributes [self .name ]
168166 else :
169- logger .log (level = log_levels .MODULE_DEBUG , msg = "Retrieving Vm interfaces seen from Hypervisor" )
167+ logger .log (
168+ level = log_levels .MODULE_DEBUG ,
169+ msg = "Retrieving Vm interfaces seen from Hypervisor" ,
170+ )
170171 return self .get_vm_interfaces ()
171172
172173 def _check_vnic_correct_matching (self , created_vm_interfaces : List ["VMNetworkInterface" ]) -> None :
173174 """Check if matching was successful, if not raise Exception.
174175
175- :param created_vm_interfaces: list of vnics after matching VM interfaces witt VM Guest OS interfaces
176+ :param created_vm_interfaces: list of vNICs after matching VM interfaces with VM Guest OS interfaces
176177 """
177178 all_have_iface = all (hasattr (vnic , "interface" ) for vnic in created_vm_interfaces )
178179 if not all_have_iface :
0 commit comments