Skip to content

Commit 2acd3aa

Browse files
more wip
1 parent ead501b commit 2acd3aa

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

linode_api4/objects/linode.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,26 +1591,27 @@ def rebuild(
15911591
15921592
:param image: The Image to deploy to this Instance
15931593
:type image: str or Image
1594-
:param root_pass: The root password for the newly rebuilt Instance. If
1595-
omitted, a password will be generated and returned.
1594+
:param root_pass: The root password for the newly rebuilt Instance.
1595+
At least one of root_pass or authorized_keys is
1596+
required. Both may be provided.
15961597
:type root_pass: str
15971598
:param authorized_keys: The ssh public keys to install in the linode's
15981599
/root/.ssh/authorized_keys file. Each entry may
15991600
be a single key, or a path to a file containing
1600-
the key.
1601+
the key. At least one of authorized_keys or
1602+
root_pass is required.
16011603
:type authorized_keys: list or str
16021604
:param disk_encryption: The disk encryption policy for this Linode.
16031605
NOTE: Disk encryption may not currently be available to all users.
16041606
:type disk_encryption: InstanceDiskEncryptionType or str
16051607
1606-
:returns: The newly generated password, if one was not provided
1607-
(otherwise True)
1608-
:rtype: str or bool
1608+
:returns: True if the rebuild was successful.
1609+
:rtype: bool
16091610
"""
1610-
ret_pass = None
1611-
if not root_pass:
1612-
ret_pass = Instance.generate_root_password()
1613-
root_pass = ret_pass
1611+
if not root_pass and not authorized_keys:
1612+
raise ValueError(
1613+
"At least one of root_pass or authorized_keys is required."
1614+
)
16141615

16151616
authorized_keys = load_and_validate_keys(authorized_keys)
16161617

@@ -1639,10 +1640,7 @@ def rebuild(
16391640
# update ourself with the newly-returned information
16401641
self._populate(result)
16411642

1642-
if not ret_pass:
1643-
return True
1644-
else:
1645-
return ret_pass
1643+
return True
16461644

16471645
def rescue(self, *disks):
16481646
"""

test/unit/objects/linode_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,21 @@ def test_rebuild(self):
9393
linode = Instance(self.client, 123)
9494

9595
with self.mock_post("/linode/instances/123") as m:
96-
pw = linode.rebuild(
96+
result = linode.rebuild(
9797
"linode/debian9",
98+
root_pass="test123ABC!",
9899
disk_encryption=InstanceDiskEncryptionType.enabled,
99100
)
100101

101-
self.assertIsNotNone(pw)
102-
self.assertTrue(isinstance(pw, str))
102+
self.assertTrue(result)
103103

104104
self.assertEqual(m.call_url, "/linode/instances/123/rebuild")
105105

106106
self.assertEqual(
107107
m.call_data,
108108
{
109109
"image": "linode/debian9",
110-
"root_pass": pw,
110+
"root_pass": "test123ABC!",
111111
"disk_encryption": "enabled",
112112
},
113113
)

0 commit comments

Comments
 (0)