Skip to content

Commit f8fa49b

Browse files
Added support for changes in Account Events, Maintenance, and Settings
1 parent 0ecf79a commit f8fa49b

File tree

7 files changed

+141
-52
lines changed

7 files changed

+141
-52
lines changed

linode_api4/groups/account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def maintenance(self):
201201
"""
202202
Returns a collection of Maintenance objects for any entity a user has permissions to view. Cancelled Maintenance objects are not returned.
203203
204-
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-account-logins
204+
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-maintenance
205205
206206
:returns: A list of Maintenance objects on this account.
207207
:rtype: List of Maintenance objects as MappedObjects

linode_api4/objects/account.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ class AccountSettings(Base):
197197
),
198198
"object_storage": Property(),
199199
"backups_enabled": Property(mutable=True),
200+
"maintenance_policy_id": Property(mutable=True),
200201
}
201202

202203

@@ -219,12 +220,18 @@ class Event(Base):
219220
"user_id": Property(),
220221
"username": Property(),
221222
"entity": Property(),
222-
"time_remaining": Property(),
223+
"time_remaining": Property(), # Deprecated
223224
"rate": Property(),
224225
"status": Property(),
225226
"duration": Property(),
226227
"secondary_entity": Property(),
227228
"message": Property(),
229+
"maintenance_policy_set": Property(),
230+
"description": Property(),
231+
"source": Property(),
232+
"not_before": Property(is_datetime=True),
233+
"start_time": Property(is_datetime=True),
234+
"complete_time": Property(is_datetime=True),
228235
}
229236

230237
@property
Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
{
2-
"action": "ticket_create",
3-
"created": "2018-01-01T00:01:01",
4-
"duration": 300.56,
5-
"entity": {
6-
"id": 11111,
7-
"label": "Problem booting my Linode",
8-
"type": "ticket",
9-
"url": "/v4/support/tickets/11111"
10-
},
11-
"id": 123,
12-
"message": "None",
13-
"percent_complete": null,
14-
"rate": null,
15-
"read": true,
16-
"secondary_entity": {
17-
"id": "linode/debian9",
18-
"label": "linode1234",
19-
"type": "linode",
20-
"url": "/v4/linode/instances/1234"
21-
},
22-
"seen": true,
23-
"status": null,
24-
"time_remaining": null,
25-
"username": "exampleUser"
26-
}
27-
2+
"action": "ticket_create",
3+
"created": "2025-03-25T12:00:00",
4+
"duration": 300.56,
5+
"entity": {
6+
"id": 11111,
7+
"label": "Problem booting my Linode",
8+
"type": "ticket",
9+
"url": "/v4/support/tickets/11111"
10+
},
11+
"id": 123,
12+
"message": "Ticket created for user issue.",
13+
"percent_complete": null,
14+
"rate": null,
15+
"read": true,
16+
"secondary_entity": {
17+
"id": "linode/debian9",
18+
"label": "linode1234",
19+
"type": "linode",
20+
"url": "/v4/linode/instances/1234"
21+
},
22+
"seen": true,
23+
"status": "completed",
24+
"username": "exampleUser",
25+
"maintenance_policy_set": "Tentative",
26+
"description": "Scheduled maintenance",
27+
"source": "user",
28+
"not_before": "2025-03-25T12:00:00",
29+
"start_time": "2025-03-25T12:30:00",
30+
"complete_time": "2025-03-25T13:00:00"
31+
}
Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
{
2-
"data": [
3-
{
4-
"entity": {
5-
"id": 123,
6-
"label": "demo-linode",
7-
"type": "Linode",
8-
"url": "https://api.linode.com/v4/linode/instances/{linodeId}"
9-
},
10-
"reason": "This maintenance will allow us to update the BIOS on the host's motherboard.",
11-
"status": "started",
12-
"type": "reboot",
13-
"when": "2020-07-09T00:01:01"
14-
}
15-
],
16-
"page": 1,
17-
"pages": 1,
18-
"results": 1
2+
"pages": 1,
3+
"page": 1,
4+
"results": 1,
5+
"data": [
6+
{
7+
"body": "Scheduled upgrade to faster NVMe hardware. This will affect Linode #1234.",
8+
"entity": {
9+
"id": 1234,
10+
"label": "Linode #1234",
11+
"type": "linode",
12+
"url": "/linodes/1234"
13+
},
14+
"label": "Scheduled Maintenance for Linode #1234",
15+
"message": "Scheduled upgrade to faster NVMe hardware.",
16+
"severity": "major",
17+
"type": "maintenance_scheduled",
18+
"event_type": "linode_migrate",
19+
"maintenance_policy_set": "Power on/off",
20+
"description": "Scheduled Maintenance",
21+
"source": "platform",
22+
"not_before": "2025-03-25T10:00:00",
23+
"start_time": "2025-03-25T12:00:00",
24+
"complete_time": "2025-03-25T14:00:00",
25+
"status": "scheduled",
26+
"when": "2025-03-25T12:00:00",
27+
"until": "2025-03-25T14:00:00"
28+
}
29+
]
1930
}

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+
"maintenance_policy_id": 1
78
}

test/unit/linode_client_test.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,39 @@ def test_maintenance(self):
353353
"""
354354
with self.mock_get("/account/maintenance") as m:
355355
result = self.client.account.maintenance()
356+
356357
self.assertEqual(m.call_url, "/account/maintenance")
357358
self.assertEqual(len(result), 1)
359+
360+
maintenance = result[0]
361+
362+
self.assertEqual(
363+
maintenance.body,
364+
"Scheduled upgrade to faster NVMe hardware. This will affect Linode #1234.",
365+
)
366+
self.assertEqual(maintenance.entity.id, 1234)
367+
self.assertEqual(maintenance.entity.label, "Linode #1234")
368+
self.assertEqual(maintenance.entity.type, "linode")
369+
self.assertEqual(maintenance.entity.url, "/linodes/1234")
370+
self.assertEqual(
371+
maintenance.label, "Scheduled Maintenance for Linode #1234"
372+
)
358373
self.assertEqual(
359-
result[0].reason,
360-
"This maintenance will allow us to update the BIOS on the host's motherboard.",
374+
maintenance.message,
375+
"Scheduled upgrade to faster NVMe hardware.",
361376
)
377+
self.assertEqual(maintenance.severity, "major")
378+
self.assertEqual(maintenance.type, "maintenance_scheduled")
379+
self.assertEqual(maintenance.event_type, "linode_migrate")
380+
self.assertEqual(maintenance.maintenance_policy_set, "Power on/off")
381+
self.assertEqual(maintenance.description, "Scheduled Maintenance")
382+
self.assertEqual(maintenance.source, "platform")
383+
self.assertEqual(maintenance.not_before, "2025-03-25T10:00:00")
384+
self.assertEqual(maintenance.start_time, "2025-03-25T12:00:00")
385+
self.assertEqual(maintenance.complete_time, "2025-03-25T14:00:00")
386+
self.assertEqual(maintenance.status, "scheduled")
387+
self.assertEqual(maintenance.when, "2025-03-25T12:00:00")
388+
self.assertEqual(maintenance.until, "2025-03-25T14:00:00")
362389

363390
def test_notifications(self):
364391
"""

test/unit/objects/account_test.py

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,25 @@ def test_get_account_settings(self):
121121
self.assertEqual(settings.network_helper, False)
122122
self.assertEqual(settings.object_storage, "active")
123123
self.assertEqual(settings.backups_enabled, True)
124+
self.assertEqual(settings.maintenance_policy_id, 1)
125+
126+
def test_update_account_settings(self):
127+
"""
128+
Tests that account settings can be updated
129+
"""
130+
with self.mock_put("account/settings") as m:
131+
settings = AccountSettings(self.client, False, {})
132+
133+
settings.maintenance_policy_id = 1
134+
settings.save()
135+
136+
self.assertEqual(m.call_url, "/account/settings")
137+
self.assertEqual(
138+
m.call_data,
139+
{
140+
"maintenance_policy_id": 1,
141+
},
142+
)
124143

125144
def test_get_event(self):
126145
"""
@@ -129,20 +148,40 @@ def test_get_event(self):
129148
event = Event(self.client, 123, {})
130149

131150
self.assertEqual(event.action, "ticket_create")
132-
self.assertEqual(event.created, datetime(2018, 1, 1, 0, 1, 1))
151+
self.assertEqual(event.created, datetime(2025, 3, 25, 12, 0, 0))
133152
self.assertEqual(event.duration, 300.56)
153+
134154
self.assertIsNotNone(event.entity)
155+
self.assertEqual(event.entity.id, 11111)
156+
self.assertEqual(event.entity.label, "Problem booting my Linode")
157+
self.assertEqual(event.entity.type, "ticket")
158+
self.assertEqual(event.entity.url, "/v4/support/tickets/11111")
159+
135160
self.assertEqual(event.id, 123)
136-
self.assertEqual(event.message, "None")
161+
self.assertEqual(event.message, "Ticket created for user issue.")
137162
self.assertIsNone(event.percent_complete)
138163
self.assertIsNone(event.rate)
139164
self.assertTrue(event.read)
165+
140166
self.assertIsNotNone(event.secondary_entity)
167+
self.assertEqual(event.secondary_entity.id, "linode/debian9")
168+
self.assertEqual(event.secondary_entity.label, "linode1234")
169+
self.assertEqual(event.secondary_entity.type, "linode")
170+
self.assertEqual(
171+
event.secondary_entity.url, "/v4/linode/instances/1234"
172+
)
173+
141174
self.assertTrue(event.seen)
142-
self.assertIsNone(event.status)
143-
self.assertIsNone(event.time_remaining)
175+
self.assertEqual(event.status, "completed")
144176
self.assertEqual(event.username, "exampleUser")
145177

178+
self.assertEqual(event.maintenance_policy_set, "Tentative")
179+
self.assertEqual(event.description, "Scheduled maintenance")
180+
self.assertEqual(event.source, "user")
181+
self.assertEqual(event.not_before, datetime(2025, 3, 25, 12, 0, 0))
182+
self.assertEqual(event.start_time, datetime(2025, 3, 25, 12, 30, 0))
183+
self.assertEqual(event.complete_time, datetime(2025, 3, 25, 13, 0, 0))
184+
146185
def test_get_invoice(self):
147186
"""
148187
Tests that an invoice is loaded correctly by ID

0 commit comments

Comments
 (0)