Skip to content

Commit cb5dc24

Browse files
committed
Merge branch '285-reload-api-objects' into develop
2 parents bb63cfd + bdad6c9 commit cb5dc24

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/Kathara/manager/docker/DockerMachine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ def connect_interface(machine: Machine, interface: Interface) -> None:
339339
DockerPluginError: If Kathara has been left in an inconsistent state.
340340
APIError: If the Docker APIs return an error.
341341
"""
342-
machine.api_object.reload()
343342
attached_networks = machine.api_object.attrs["NetworkSettings"]["Networks"]
344343

345344
if interface.link.api_object.name not in attached_networks:
@@ -369,7 +368,6 @@ def disconnect_from_link(machine: Machine, link: Link) -> None:
369368
Returns:
370369
None
371370
"""
372-
machine.api_object.reload()
373371
attached_networks = machine.api_object.attrs["NetworkSettings"]["Networks"]
374372

375373
if link.api_object.name in attached_networks:
@@ -466,6 +464,8 @@ def start(self, machine: Machine) -> None:
466464
f"Please specify a valid shell for this device."
467465
)
468466

467+
machine.api_object.reload()
468+
469469
def undeploy(self, lab_hash: str, selected_machines: Set[str] = None) -> None:
470470
"""Undeploy the devices contained in the network scenario defined by the lab_hash.
471471

src/Kathara/manager/docker/DockerManager.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)