Skip to content

Commit 00db88f

Browse files
Updated maintenance_policy_id to maintenance_polic
1 parent a2a1a56 commit 00db88f

File tree

11 files changed

+127
-83
lines changed

11 files changed

+127
-83
lines changed

linode_api4/groups/linode.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def instance_create(
153153
int,
154154
]
155155
] = None,
156-
maintenance_policy_id: Optional[int] = None,
156+
maintenance_policy: Optional[str] = None,
157157
**kwargs,
158158
):
159159
"""
@@ -297,9 +297,9 @@ def instance_create(
297297
:type interfaces: list[ConfigInterface] or list[dict[str, Any]]
298298
:param placement_group: A Placement Group to create this Linode under.
299299
:type placement_group: Union[InstancePlacementGroupAssignment, PlacementGroup, Dict[str, Any], int]
300-
:param maintenance_policy_id: The ID of the maintenance policy to apply during maintenance.
301-
If not provided, the default policy (migrate) will be applied.
302-
:type maintenance_policy_id: int
300+
:param maintenance_policy: The slug of the maintenance policy to apply during maintenance.
301+
If not provided, the default policy (linode/migrate) will be applied.
302+
:type maintenance_policy: str
303303
304304
:returns: A new Instance object, or a tuple containing the new Instance and
305305
the generated password.
@@ -331,7 +331,7 @@ def instance_create(
331331
"firewall_id": firewall,
332332
"backup_id": backup,
333333
"stackscript_id": stackscript,
334-
"maintenance_policy_id": maintenance_policy_id,
334+
"maintenance_policy": maintenance_policy,
335335
# Special cases
336336
"disk_encryption": (
337337
str(disk_encryption) if disk_encryption else None

linode_api4/objects/account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class AccountSettings(Base):
197197
),
198198
"object_storage": Property(),
199199
"backups_enabled": Property(mutable=True),
200-
"maintenance_policy_id": Property(mutable=True),
200+
"maintenance_policy": Property(mutable=True),
201201
}
202202

203203

linode_api4/objects/linode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ class Instance(Base):
686686
"disk_encryption": Property(),
687687
"lke_cluster_id": Property(),
688688
"capabilities": Property(unordered=True),
689-
"maintenance_policy_id": Property(mutable=True),
689+
"maintenance_policy": Property(mutable=True),
690690
}
691691

692692
@property
Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
{
22
"pages": 1,
33
"page": 1,
4-
"results": 1,
4+
"results": 2,
55
"data": [
66
{
7-
"body": "Scheduled upgrade to faster NVMe hardware. This will affect Linode #1234.",
87
"entity": {
98
"id": 1234,
109
"label": "Linode #1234",
1110
"type": "linode",
1211
"url": "/linodes/1234"
1312
},
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",
13+
"reason": "Scheduled upgrade to faster NVMe hardware.",
14+
"type": "linode_migrate",
15+
"maintenance_policy_set": "linode/power_off_on",
2016
"description": "Scheduled Maintenance",
2117
"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"
18+
"not_before": "2025-03-25T10:00:00Z",
19+
"start_time": "2025-03-25T12:00:00Z",
20+
"complete_time": "2025-03-25T14:00:00Z",
21+
"status": "scheduled"
22+
},
23+
{
24+
"entity": {
25+
"id": 1234,
26+
"label": "Linode #1234",
27+
"type": "linode",
28+
"url": "/linodes/1234"
29+
},
30+
"reason": "Pending migration of Linode #1234 to a new host.",
31+
"type": "linode_migrate",
32+
"maintenance_policy_set": "linode/migrate",
33+
"description": "Emergency Maintenance",
34+
"source": "user",
35+
"not_before": "2025-03-26T15:00:00Z",
36+
"start_time": "2025-03-26T15:00:00Z",
37+
"complete_time": "2025-03-26T17:00:00Z",
38+
"status": "in-progress"
2839
}
2940
]
30-
}
41+
}

test/fixtures/account_settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
"network_helper": false,
55
"object_storage": "active",
66
"backups_enabled": true,
7-
"maintenance_policy_id": 1
7+
"maintenance_policy": "linode/migrate"
88
}

test/fixtures/linode_instances.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"placement_group_type": "anti_affinity:local",
5050
"placement_group_policy": "strict"
5151
},
52-
"maintenance_policy_id" : 1
52+
"maintenance_policy" : "linode/migrate"
5353
},
5454
{
5555
"group": "test",
@@ -92,7 +92,7 @@
9292
"disk_encryption": "enabled",
9393
"lke_cluster_id": 18881,
9494
"placement_group": null,
95-
"maintenance_policy_id" : 2
95+
"maintenance_policy" : "linode/power_off_on"
9696
}
9797
]
9898
}
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
[
22
{
3-
"id": "1",
4-
"name": "Default Migrate",
5-
"description": "predefined maintenance policy default for all linodes",
3+
"slug": "linode/migrate",
4+
"label": "Migrate",
5+
"description": "Migrates the Linode to a new host while it remains fully operational. Recommended for maximizing availability.",
66
"type": "migrate",
77
"notification_period_sec": 3600,
88
"is_default": true
99
},
1010
{
11-
"id": "2",
12-
"name": "Default Power On/Off",
13-
"description": "predefined maintenance policy for general use cases",
14-
"type": "power on/off",
11+
"slug": "linode/power_off_on",
12+
"label": "Power Off/Power On",
13+
"description": "Powers off the Linode at the start of the maintenance event and reboots it once the maintenance finishes. Recommended for maximizing performance.",
14+
"type": "power_off_on",
1515
"notification_period_sec": 1800,
1616
"is_default": false
17+
},
18+
{
19+
"slug": "private/12345",
20+
"label": "Critical Workload - Avoid Migration",
21+
"description": "Custom policy designed to power off and perform maintenance during user-defined windows only.",
22+
"type": "power_off_on",
23+
"notification_period_sec": 7200,
24+
"is_default": false
1725
}
1826
]

test/unit/groups/linode_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_create_with_placement_group(self):
9696
m.call_data["placement_group"], {"id": 123, "compliant_only": True}
9797
)
9898

99-
def test_create_with_mainteance_policy_id(self):
99+
def test_create_with_maintenance_policy(self):
100100
"""
101101
Tests that you can create a Linode with a maintenance policy
102102
"""
@@ -105,10 +105,10 @@ def test_create_with_mainteance_policy_id(self):
105105
self.client.linode.instance_create(
106106
"g6-nanode-1",
107107
"eu-west",
108-
maintenance_policy_id=1,
108+
maintenance_policy="linode/migrate",
109109
)
110110

111-
self.assertEqual(m.call_data["maintenance_policy_id"], 1)
111+
self.assertEqual(m.call_data["maintenance_policy"], "linode/migrate")
112112

113113

114114
class TypeTest(ClientBaseCase):

test/unit/linode_client_test.py

Lines changed: 67 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -315,41 +315,49 @@ class MaintenanceGroupTest(ClientBaseCase):
315315
def test_maintenance(self):
316316
"""
317317
Tests that maintenance can be retrieved
318+
Tests that maintenance can be retrieved
318319
"""
319320
with self.mock_get("/maintenance/policies") as m:
320321
result = self.client.maintenance.maintenance_policies()
321322

322323
self.assertEqual(m.call_url, "/maintenance/policies")
323-
self.assertEqual(len(result), 2)
324+
self.assertEqual(len(result), 3)
324325

325-
policy_default_migrate = result[0]
326-
policy_default_power_on_off = result[1]
326+
policy_migrate = result[0]
327+
policy_power_off_on = result[1]
328+
policy_custom = result[2]
327329

328-
self.assertEqual(policy_default_migrate.id, "1")
329-
self.assertEqual(policy_default_migrate.name, "Default Migrate")
330-
self.assertEqual(
331-
policy_default_migrate.description,
332-
"predefined maintenance policy default for all linodes",
333-
)
334-
self.assertEqual(policy_default_migrate.type, "migrate")
330+
self.assertEqual(policy_migrate.slug, "linode/migrate")
331+
self.assertEqual(policy_migrate.label, "Migrate")
335332
self.assertEqual(
336-
policy_default_migrate.notification_period_sec, 3600
333+
policy_migrate.description,
334+
"Migrates the Linode to a new host while it remains fully operational. Recommended for maximizing availability.",
337335
)
338-
self.assertEqual(policy_default_migrate.is_default, True)
336+
self.assertEqual(policy_migrate.type, "migrate")
337+
self.assertEqual(policy_migrate.notification_period_sec, 3600)
338+
self.assertTrue(policy_migrate.is_default)
339339

340-
self.assertEqual(policy_default_power_on_off.id, "2")
340+
self.assertEqual(policy_power_off_on.slug, "linode/power_off_on")
341+
self.assertEqual(policy_power_off_on.label, "Power Off/Power On")
341342
self.assertEqual(
342-
policy_default_power_on_off.name, "Default Power On/Off"
343+
policy_power_off_on.description,
344+
"Powers off the Linode at the start of the maintenance event and reboots it once the maintenance finishes. Recommended for maximizing performance.",
343345
)
346+
self.assertEqual(policy_power_off_on.type, "power_off_on")
347+
self.assertEqual(policy_power_off_on.notification_period_sec, 1800)
348+
self.assertFalse(policy_power_off_on.is_default)
349+
350+
self.assertEqual(policy_custom.slug, "private/12345")
344351
self.assertEqual(
345-
policy_default_power_on_off.description,
346-
"predefined maintenance policy for general use cases",
352+
policy_custom.label, "Critical Workload - Avoid Migration"
347353
)
348-
self.assertEqual(policy_default_power_on_off.type, "power on/off")
349354
self.assertEqual(
350-
policy_default_power_on_off.notification_period_sec, 1800
355+
policy_custom.description,
356+
"Custom policy designed to power off and perform maintenance during user-defined windows only.",
351357
)
352-
self.assertEqual(policy_default_power_on_off.is_default, False)
358+
self.assertEqual(policy_custom.type, "power_off_on")
359+
self.assertEqual(policy_custom.notification_period_sec, 7200)
360+
self.assertFalse(policy_custom.is_default)
353361

354362

355363
class AccountGroupTest(ClientBaseCase):
@@ -400,37 +408,54 @@ def test_maintenance(self):
400408
result = self.client.account.maintenance()
401409

402410
self.assertEqual(m.call_url, "/account/maintenance")
403-
self.assertEqual(len(result), 1)
411+
self.assertEqual(len(result), 2)
412+
413+
maintenance_1 = result[0]
414+
maintenance_2 = result[1]
404415

405-
maintenance = result[0]
416+
# First maintenance
417+
self.assertEqual(
418+
maintenance_1.reason,
419+
"Scheduled upgrade to faster NVMe hardware.",
420+
)
421+
self.assertEqual(maintenance_1.entity.id, 1234)
422+
self.assertEqual(maintenance_1.entity.label, "Linode #1234")
423+
self.assertEqual(maintenance_1.entity.type, "linode")
424+
self.assertEqual(maintenance_1.entity.url, "/linodes/1234")
425+
self.assertEqual(
426+
maintenance_1.maintenance_policy_set, "linode/power_off_on"
427+
)
428+
self.assertEqual(maintenance_1.description, "Scheduled Maintenance")
429+
self.assertEqual(maintenance_1.source, "platform")
430+
self.assertEqual(maintenance_1.not_before, "2025-03-25T10:00:00Z")
431+
self.assertEqual(maintenance_1.start_time, "2025-03-25T12:00:00Z")
432+
self.assertEqual(
433+
maintenance_1.complete_time, "2025-03-25T14:00:00Z"
434+
)
435+
self.assertEqual(maintenance_1.status, "scheduled")
436+
self.assertEqual(maintenance_1.type, "linode_migrate")
406437

438+
# Second maintenance
407439
self.assertEqual(
408-
maintenance.body,
409-
"Scheduled upgrade to faster NVMe hardware. This will affect Linode #1234.",
440+
maintenance_2.reason,
441+
"Pending migration of Linode #1234 to a new host.",
410442
)
411-
self.assertEqual(maintenance.entity.id, 1234)
412-
self.assertEqual(maintenance.entity.label, "Linode #1234")
413-
self.assertEqual(maintenance.entity.type, "linode")
414-
self.assertEqual(maintenance.entity.url, "/linodes/1234")
443+
self.assertEqual(maintenance_2.entity.id, 1234)
444+
self.assertEqual(maintenance_2.entity.label, "Linode #1234")
445+
self.assertEqual(maintenance_2.entity.type, "linode")
446+
self.assertEqual(maintenance_2.entity.url, "/linodes/1234")
415447
self.assertEqual(
416-
maintenance.label, "Scheduled Maintenance for Linode #1234"
448+
maintenance_2.maintenance_policy_set, "linode/migrate"
417449
)
450+
self.assertEqual(maintenance_2.description, "Emergency Maintenance")
451+
self.assertEqual(maintenance_2.source, "user")
452+
self.assertEqual(maintenance_2.not_before, "2025-03-26T15:00:00Z")
453+
self.assertEqual(maintenance_2.start_time, "2025-03-26T15:00:00Z")
418454
self.assertEqual(
419-
maintenance.message,
420-
"Scheduled upgrade to faster NVMe hardware.",
455+
maintenance_2.complete_time, "2025-03-26T17:00:00Z"
421456
)
422-
self.assertEqual(maintenance.severity, "major")
423-
self.assertEqual(maintenance.type, "maintenance_scheduled")
424-
self.assertEqual(maintenance.event_type, "linode_migrate")
425-
self.assertEqual(maintenance.maintenance_policy_set, "Power on/off")
426-
self.assertEqual(maintenance.description, "Scheduled Maintenance")
427-
self.assertEqual(maintenance.source, "platform")
428-
self.assertEqual(maintenance.not_before, "2025-03-25T10:00:00")
429-
self.assertEqual(maintenance.start_time, "2025-03-25T12:00:00")
430-
self.assertEqual(maintenance.complete_time, "2025-03-25T14:00:00")
431-
self.assertEqual(maintenance.status, "scheduled")
432-
self.assertEqual(maintenance.when, "2025-03-25T12:00:00")
433-
self.assertEqual(maintenance.until, "2025-03-25T14:00:00")
457+
self.assertEqual(maintenance_2.status, "in-progress")
458+
self.assertEqual(maintenance_2.type, "linode_migrate")
434459

435460
def test_notifications(self):
436461
"""

test/unit/objects/account_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ 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)
124+
self.assertEqual(settings.maintenance_policy, "linode/migrate")
125125

126126
def test_update_account_settings(self):
127127
"""
@@ -130,14 +130,14 @@ def test_update_account_settings(self):
130130
with self.mock_put("account/settings") as m:
131131
settings = AccountSettings(self.client, False, {})
132132

133-
settings.maintenance_policy_id = 1
133+
settings.maintenance_policy = "linode/migrate"
134134
settings.save()
135135

136136
self.assertEqual(m.call_url, "/account/settings")
137137
self.assertEqual(
138138
m.call_data,
139139
{
140-
"maintenance_policy_id": 1,
140+
"maintenance_policy": "linode/migrate",
141141
},
142142
)
143143

0 commit comments

Comments
 (0)