Skip to content

Commit ad3e7ef

Browse files
authored
fix(ibm): Fix get_instance (#488)
## Description IBM library get_instance returns a DetailedResponse object, not an instance dict directly. This fix gets the instance dict result from that object before passing it to from_existing. ## Additional Context and Relevant Issues Previous behavior throws a TypeError ``` File "/home/shammer/Canonical/git/tools/ubuntu-old-fashioned/scripts/ubuntu-bartender/ibm-provider.py", line 34, in <module> delete(args.id) File "/home/shammer/Canonical/git/tools/ubuntu-old-fashioned/scripts/ubuntu-bartender/ibm-provider.py", line 22, in delete instance = ibm.get_instance(instance_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/shammer/ubuntu-bartender-multipass.pedbPM1KcM/.venv/lib/python3.12/site-packages/pycloudlib/ibm/cloud.py", line 230, in get_instance return IBMInstance.find_existing( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/shammer/ubuntu-bartender-multipass.pedbPM1KcM/.venv/lib/python3.12/site-packages/pycloudlib/ibm/instance.py", line 702, in find_existing return cls.from_existing( ^^^^^^^^^^^^^^^^^^ File "/home/shammer/ubuntu-bartender-multipass.pedbPM1KcM/.venv/lib/python3.12/site-packages/pycloudlib/ibm/instance.py", line 675, in from_existing floating_ip = kwargs.pop("floating_ip", None) or cls._discover_floating_ip(client, instance) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/shammer/ubuntu-bartender-multipass.pedbPM1KcM/.venv/lib/python3.12/site-packages/pycloudlib/ibm/instance.py", line 773, in _discover_floating_ip nic_id = instance["primary_network_interface"]["id"] ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'DetailedResponse' object is not subscriptable ``` ## Test Steps Create an instance and perform a get_instance ```python import pycloudlib ibm = pycloudlib.IBM("test") imge = ibm.daily_image(release="noble") instance = ibm.launch(image_id=daily, instance_type="bx3d-2x10", name="test") id = instance._instance["id"] instance_find = ibm.get_instance(id) # previously would throw an exception here ```
1 parent 00a20b9 commit ad3e7ef

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1!10.13.0
1+
1!10.13.1

pycloudlib/ibm/instance.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,11 @@ def find_existing(
692692
**kwargs,
693693
) -> "IBMInstance":
694694
"""Find an instance by ID."""
695-
instance = _IBMInstanceType.VSI.get_instance(client, instance_id)
695+
response = _IBMInstanceType.VSI.get_instance(client, instance_id)
696+
instance = response.result
696697
if not instance:
697-
instance = _IBMInstanceType.BARE_METAL_SERVER.get_instance(client, instance_id)
698+
response = _IBMInstanceType.BARE_METAL_SERVER.get_instance(client, instance_id)
699+
instance = response.result
698700

699701
if not instance:
700702
raise IBMException(f"Instance not found: {instance_id}")

0 commit comments

Comments
 (0)