Skip to content

Commit f42c79f

Browse files
Enhanced Interfaces: Add account-related fields (#525)
* Enhanced Interfaces: Add account-related fields * Add setting enum * Add LA notice * Drop residual print
1 parent 82a2772 commit f42c79f

File tree

6 files changed

+59
-3
lines changed

6 files changed

+59
-3
lines changed

linode_api4/objects/account.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from linode_api4.objects.networking import Firewall
1717
from linode_api4.objects.nodebalancer import NodeBalancer
1818
from linode_api4.objects.profile import PersonalAccessToken
19+
from linode_api4.objects.serializable import StrEnum
1920
from linode_api4.objects.support import SupportTicket
2021
from linode_api4.objects.volume import Volume
2122
from linode_api4.objects.vpc import VPC
@@ -179,6 +180,24 @@ class Login(Base):
179180
}
180181

181182

183+
class AccountSettingsInterfacesForNewLinodes(StrEnum):
184+
"""
185+
A string enum corresponding to valid values
186+
for the AccountSettings(...).interfaces_for_new_linodes field.
187+
188+
NOTE: This feature may not currently be available to all users.
189+
"""
190+
191+
legacy_config_only = "legacy_config_only"
192+
legacy_config_default_but_linode_allowed = (
193+
"legacy_config_default_but_linode_allowed"
194+
)
195+
linode_default_but_legacy_config_allowed = (
196+
"linode_default_but_legacy_config_allowed"
197+
)
198+
linode_only = "linode_only"
199+
200+
182201
class AccountSettings(Base):
183202
"""
184203
Information related to your Account settings.
@@ -197,6 +216,7 @@ class AccountSettings(Base):
197216
),
198217
"object_storage": Property(),
199218
"backups_enabled": Property(mutable=True),
219+
"interfaces_for_new_linodes": Property(mutable=True),
200220
}
201221

202222

test/fixtures/account.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"Linodes",
1717
"NodeBalancers",
1818
"Block Storage",
19-
"Object Storage"
19+
"Object Storage",
20+
"Linode Interfaces"
2021
],
2122
"active_promotions": [
2223
{

test/fixtures/account_settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"managed": false,
44
"network_helper": false,
55
"object_storage": "active",
6-
"backups_enabled": true
6+
"backups_enabled": true,
7+
"interfaces_for_new_linodes": "linode_default_but_legacy_config_allowed"
78
}

test/integration/models/account/test_account.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def test_get_account_settings(test_linode_client):
5959
assert "longview_subscription" in str(account_settings._raw_json)
6060
assert "backups_enabled" in str(account_settings._raw_json)
6161
assert "object_storage" in str(account_settings._raw_json)
62+
assert isinstance(account_settings.interfaces_for_new_linodes, str)
6263

6364

6465
@pytest.mark.smoke

test/unit/linode_client_test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ def test_get_account(self):
4444
self.assertEqual(a.balance, 0)
4545
self.assertEqual(
4646
a.capabilities,
47-
["Linodes", "NodeBalancers", "Block Storage", "Object Storage"],
47+
[
48+
"Linodes",
49+
"NodeBalancers",
50+
"Block Storage",
51+
"Object Storage",
52+
"Linode Interfaces",
53+
],
4854
)
4955

5056
def test_get_regions(self):

test/unit/objects/account_test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from datetime import datetime
44
from test.unit.base import ClientBaseCase
55

6+
from linode_api4 import AccountSettingsInterfacesForNewLinodes
67
from linode_api4.objects import (
78
Account,
89
AccountAvailability,
@@ -97,6 +98,7 @@ def test_get_account(self):
9798
self.assertEqual(account.balance_uninvoiced, 145)
9899
self.assertEqual(account.billing_source, "akamai")
99100
self.assertEqual(account.euuid, "E1AF5EEC-526F-487D-B317EBEB34C87D71")
101+
self.assertIn("Linode Interfaces", account.capabilities)
100102

101103
def test_get_login(self):
102104
"""
@@ -121,6 +123,31 @@ def test_get_account_settings(self):
121123
self.assertEqual(settings.network_helper, False)
122124
self.assertEqual(settings.object_storage, "active")
123125
self.assertEqual(settings.backups_enabled, True)
126+
self.assertEqual(
127+
settings.interfaces_for_new_linodes,
128+
AccountSettingsInterfacesForNewLinodes.linode_default_but_legacy_config_allowed,
129+
)
130+
131+
def test_post_account_settings(self):
132+
"""
133+
Tests that account settings can be updated successfully
134+
"""
135+
settings = self.client.account.settings()
136+
137+
settings.network_helper = True
138+
settings.backups_enabled = False
139+
settings.interfaces_for_new_linodes = (
140+
AccountSettingsInterfacesForNewLinodes.linode_only
141+
)
142+
143+
with self.mock_put("/account/settings") as m:
144+
settings.save()
145+
146+
assert m.call_data == {
147+
"network_helper": True,
148+
"backups_enabled": False,
149+
"interfaces_for_new_linodes": AccountSettingsInterfacesForNewLinodes.linode_only,
150+
}
124151

125152
def test_get_event(self):
126153
"""

0 commit comments

Comments
 (0)