Skip to content

Release v5.15.1 #402

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
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/release-cross-repo-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ jobs:
with:
python-version: '3.10'

- name: Install linode_api4
run: make install

- name: checkout repo
uses: actions/checkout@v3
with:
Expand All @@ -48,12 +45,15 @@ jobs:
cd .ansible/collections/ansible_collections/linode/cloud
make install

- name: Install linode_api4 # Need to install from source after all ansible dependencies have been installed
run: make install

- name: replace existing keys
run: |
cd .ansible/collections/ansible_collections/linode/cloud
rm -rf ~/.ansible/test && mkdir -p ~/.ansible/test && ssh-keygen -m PEM -q -t rsa -N '' -f ~/.ansible/test/id_rsa

- name: run tests
- name: Run Ansible Tests
run: |
cd .ansible/collections/ansible_collections/linode/cloud
make testall
Expand Down
27 changes: 24 additions & 3 deletions linode_api4/objects/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
from datetime import datetime, timedelta
from typing import Any, Dict, Optional

from linode_api4.objects.serializable import JSONObject

Expand Down Expand Up @@ -99,6 +100,18 @@ def _expand_vals(self, target, **vals):
def __repr__(self):
return "Mapping containing {}".format(vars(self).keys())

@staticmethod
def _flatten_base_subclass(obj: "Base") -> Optional[Dict[str, Any]]:
if obj is None:
return None

# If the object hasn't already been lazy-loaded,
# manually refresh it
if not getattr(obj, "_populated", False):
obj._api_get()

return obj._raw_json

@property
def dict(self):
result = vars(self).copy()
Expand All @@ -112,12 +125,17 @@ def dict(self):
(
item.dict
if isinstance(item, cls)
else item._raw_json if isinstance(item, Base) else item
else (
self._flatten_base_subclass(item)
if isinstance(item, Base)
else item
)
)
for item in v
]
elif isinstance(v, Base):
result[k] = v._raw_json
result[k] = self._flatten_base_subclass(v)

return result


Expand All @@ -140,7 +158,10 @@ def __init__(self, client: object, id: object, json: object = {}) -> object:
#: be updated on access.
self._set("_raw_json", None)

for k in type(self).properties:
for k, v in type(self).properties.items():
if v.identifier:
continue

self._set(k, None)

self._set("id", id)
Expand Down
4 changes: 2 additions & 2 deletions linode_api4/objects/dbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class DerivedBase(Base):
parent_id_name = "parent_id" # override in child classes

def __init__(self, client, id, parent_id, json={}):
Base.__init__(self, client, id, json=json)

self._set(type(self).parent_id_name, parent_id)

Base.__init__(self, client, id, json=json)

@classmethod
def _api_get_derived(cls, parent, client):
base_url = "{}/{}".format(
Expand Down
4 changes: 2 additions & 2 deletions linode_api4/objects/object_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class ObjectStorageBucket(DerivedBase):
id_attribute = "label"

properties = {
"cluster": Property(),
"cluster": Property(identifier=True),
"created": Property(is_datetime=True),
"hostname": Property(),
"label": Property(),
"label": Property(identifier=True),
"objects": Property(),
"size": Property(),
}
Expand Down
8 changes: 8 additions & 0 deletions test/unit/objects/linode_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,14 @@ def test_interface_ipv4(self):
self.assertEqual(ipv4.vpc, "10.0.0.1")
self.assertEqual(ipv4.nat_1_1, "any")

def test_config_devices_unwrap(self):
"""
Tests that config devices can be successfully converted to a dict.
"""

inst = Instance(self.client, 123)
assert inst.configs[0].devices.dict.get("sda").get("id") == 12345


class StackScriptTest(ClientBaseCase):
"""
Expand Down
Loading