88
99from mfd_common_libs import add_logging_level , log_levels
1010from mfd_connect import RPyCConnection , Connection
11+ from mfd_host import Host
12+
1113from mfd_hyperv .attributes .vm_params import VMParams
1214from mfd_hyperv .exceptions import HyperVException
1315from mfd_hyperv .hypervisor import VMProcessorAttributes
2426add_logging_level (level_name = "MODULE_DEBUG" , level_value = log_levels .MODULE_DEBUG )
2527
2628
27- class VM :
28- """VM class."""
29+ class VM (Host ):
30+ """VM class that inherits from Host."""
31+
32+ def __new__ (cls , connection : "Connection" , vm_params : VMParams , * args , ** kwargs ):
33+ """Override __new__ to bypass Host's factory pattern for VM instances."""
34+ return object .__new__ (cls )
2935
3036 def __init__ (
3137 self ,
@@ -34,15 +40,15 @@ def __init__(
3440 owner : NetworkAdapterOwner = None ,
3541 hyperv : "HyperV" = None ,
3642 connection_timeout : int = None ,
43+ ** kwargs
3744 ):
3845 """VM constructor."""
39- self . connection = connection
46+ super (). __init__ ( connection = connection , ** kwargs )
4047 self .guest = NetworkAdapterOwner (connection = connection )
4148 self .attributes = {}
4249 self .owner = owner
4350 self ._hyperv = None
4451 self .hyperv = hyperv
45-
4652 self .connection_timeout = connection_timeout
4753 self ._propagate_params (vm_params )
4854
@@ -51,7 +57,7 @@ def __str__(self) -> str:
5157
5258 @property
5359 def hyperv (self ) -> "HyperV" :
54- """Hyperv property representing host's hyperv object.
60+ """HyperV property representing host's HyperV object.
5561
5662 :raises: HyperVException when this property is empty
5763 """
@@ -63,7 +69,7 @@ def hyperv(self) -> "HyperV":
6369
6470 @property
6571 def interfaces (self ) -> List ["VMNetworkInterface" ]:
66- """Hyperv property representing VM interfaces.
72+ """HyperV property representing VM interfaces.
6773
6874 :raises: HyperVException when this property is empty
6975 """
@@ -130,7 +136,7 @@ def reboot(self, timeout: int = 300) -> None:
130136 self .wait_functional (timeout )
131137
132138 def wait_functional (self , timeout : int = 300 ) -> None :
133- """Wait untill this VM can be pinged.
139+ """Wait until this VM can be pinged.
134140
135141 :param timeout: time given for VM to reach functional state
136142 """
@@ -171,7 +177,7 @@ def _get_ifaces_from_vm(self) -> Dict[str, str]:
171177 def _check_vnic_correct_matching (self , created_vm_interfaces : List ["VMNetworkInterface" ]) -> None :
172178 """Check if matching was successful, if not raise Exception.
173179
174- :param created_vm_interfaces: list of vnics after matching VM interfaces witt VM Guest OS interfaces
180+ :param created_vm_interfaces: list of vNICs after matching VM interfaces with VM Guest OS interfaces
175181 """
176182 all_have_iface = all (hasattr (vnic , "interface" ) for vnic in created_vm_interfaces )
177183 if not all_have_iface :
0 commit comments