@@ -155,7 +155,7 @@ def deploy_lab(self, lab: Lab, selected_machines: Set[str] = None) -> None:
155155
156156 @privileged
157157 def connect_machine_to_link (self , machine : Machine , link : Link , mac_address : Optional [str ] = None ) -> None :
158- """Create a new interface and connect a Kathara device to a collision domain.
158+ """Create a new interface on a running Kathara device and connect it to a collision domain.
159159
160160 Args:
161161 machine (Kathara.model.Machine): A Kathara machine object.
@@ -174,7 +174,11 @@ def connect_machine_to_link(self, machine: Machine, link: Link, mac_address: Opt
174174 if not machine .lab :
175175 raise LabNotFoundError ("Device `%s` is not associated to a network scenario." % machine .name )
176176
177- if not machine .api_object or machine .api_object .status != "running" :
177+ if not machine .api_object :
178+ raise MachineNotRunningError (machine .name )
179+
180+ machine .api_object .reload ()
181+ if machine .api_object .status != "running" :
178182 raise MachineNotRunningError (machine .name )
179183
180184 if not link .lab :
@@ -192,23 +196,31 @@ def connect_machine_to_link(self, machine: Machine, link: Link, mac_address: Opt
192196
193197 @privileged
194198 def disconnect_machine_from_link (self , machine : Machine , link : Link ) -> None :
195- """Disconnect a Kathara device from a collision domain.
199+ """Disconnect a running Kathara device from a collision domain.
196200
197201 Args:
198202 machine (Kathara.model.Machine): A Kathara machine object.
199- link (Kathara.model.Link): The Kathara collision domain from which disconnect the device.
203+ link (Kathara.model.Link): The Kathara collision domain from which disconnect the running device.
200204
201205 Returns:
202206 None
203207
204208 Raises:
205209 LabNotFoundError: If the device specified is not associated to any network scenario.
210+ MachineNotRunningError: If the specified device is not running.
206211 LabNotFoundError: If the collision domain is not associated to any network scenario.
207212 MachineCollisionDomainConflictError: If the device is not connected to the collision domain.
208213 """
209214 if not machine .lab :
210215 raise LabNotFoundError (f"Device `{ machine .name } ` is not associated to a network scenario." )
211216
217+ if not machine .api_object :
218+ raise MachineNotRunningError (machine .name )
219+
220+ machine .api_object .reload ()
221+ if machine .api_object .status != "running" :
222+ raise MachineNotRunningError (machine .name )
223+
212224 if not link .lab :
213225 raise LabNotFoundError (f"Collision domain `{ link .name } ` is not associated to a network scenario." )
214226
0 commit comments