-
Notifications
You must be signed in to change notification settings - Fork 37
fix(ibm): Fix get_instance #488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hammerstefan
merged 2 commits into
canonical:main
from
hammerstefan:ibm/fix-find-instance
Jul 25, 2025
Merged
fix(ibm): Fix get_instance #488
hammerstefan
merged 2 commits into
canonical:main
from
hammerstefan:ibm/fix-find-instance
Jul 25, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
|
mypy linting failure is unrelated to this PR |
blackboxsw
approved these changes
Jul 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM based on .tox/.testenv/lib/python3.12/site-packages/ibm_cloud_sdk_core/detailed_response.py values.
Also we can fix mypy with
--- a/pycloudlib/azure/instance.py
+++ b/pycloudlib/azure/instance.py
@@ -301,6 +301,7 @@ class AzureInstance(BaseInstance):
vm_nics_ids = [nic.id for nic in self._instance["vm"].network_profile.network_interfaces]
all_nics: List[NetworkInterface] = list(self._network_client.network_interfaces.list_all())
vm_nics = [nic for nic in all_nics if nic.id in vm_nics_ids]
+ primary_nic : Optional[NetworkInterface] = None
primary_nic = [nic for nic in vm_nics if nic.primary][0]
nic_params = []
nic_to_remove: Optional[NetworkInterface] = None|
Let me get a separate PR up to fix the linting error. |
Gisaldjo
pushed a commit
to Gisaldjo/pycloudlib
that referenced
this pull request
Jul 28, 2025
## 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
```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Test Steps
Create an instance and perform a get_instance