Skip to content

Commit b600db6

Browse files
Drop root_pass from returned fields for instance_create, rebuild, and disk_create
1 parent 91f671f commit b600db6

15 files changed

Lines changed: 88 additions & 81 deletions

File tree

linode_api4/groups/linode.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,11 @@ def instance_create(
177177
a :any:`Type`, a :any:`Region`, and an :any:`Image`. All three of
178178
these fields may be provided as either the ID or the appropriate object.
179179
When an Image is provided, at least one of ``root_pass``, ``authorized_users``, or
180-
``authorized_keys`` must also be given. If ``root_pass`` is provided,
181-
the Instance and the password are returned as a tuple.
180+
``authorized_keys`` must also be given.
182181
183182
For example::
184183
185-
new_linode, password = client.linode.instance_create(
184+
new_linode = client.linode.instance_create(
186185
"g6-standard-2",
187186
"us-east",
188187
image="linode/debian13",
@@ -198,9 +197,6 @@ def instance_create(
198197
image=image,
199198
authorized_keys="ssh-rsa AAAA")
200199
201-
To output the password from the first example above:
202-
print(password)
203-
204200
To output the first IPv4 address of the new Linode:
205201
print(new_linode.ipv4[0])
206202
@@ -217,7 +213,7 @@ def instance_create(
217213
218214
stackscript = StackScript(client, 10079)
219215
220-
new_linode, password = client.linode.instance_create(
216+
new_linode = client.linode.instance_create(
221217
"g6-standard-2",
222218
"us-east",
223219
image="linode/debian13",
@@ -252,7 +248,7 @@ def instance_create(
252248
To create a new Instance with explicit interfaces, provide list of
253249
LinodeInterfaceOptions objects or dicts to the "interfaces" field::
254250
255-
linode, password = client.linode.instance_create(
251+
linode = client.linode.instance_create(
256252
"g6-standard-1",
257253
"us-mia",
258254
image="linode/ubuntu24.04",
@@ -293,11 +289,9 @@ def instance_create(
293289
at least one of root_pass, authorized_users, or authorized_keys must also be
294290
provided.
295291
:type image: str or Image
296-
:param root_pass: The root password for the new Instance. If an image is
297-
provided and root_pass is given, the Instance and password
298-
will be returned as a tuple. If all of root_pass, authorized_users, and
299-
authorized_keys are not provided when an image is specified,
300-
a ValueError will be raised.
292+
:param root_pass: The root password for the new Instance. Required when
293+
an image is provided and neither authorized_users nor
294+
authorized_keys are given.
301295
:type root_pass: str
302296
:param stackscript: The StackScript to deploy to the new Instance. If
303297
provided, "image" is required and must be compatible
@@ -363,9 +357,8 @@ def instance_create(
363357
the boot disk for the Instance.
364358
:type boot_size: int
365359
366-
:returns: A new Instance object, or a tuple containing the new Instance and
367-
the password if both image and root_pass were provided.
368-
:rtype: Instance or tuple(Instance, str)
360+
:returns: A new Instance object
361+
:rtype: Instance
369362
:raises ApiError: If contacting the API fails
370363
:raises UnexpectedResponseError: If the API response is somehow malformed.
371364
This usually indicates that you are using
@@ -423,10 +416,7 @@ def instance_create(
423416
"Unexpected response when creating linode!", json=result
424417
)
425418

426-
l = Instance(self.client, result["id"], result)
427-
if not (image and root_pass):
428-
return l
429-
return l, root_pass
419+
return Instance(self.client, result["id"], result)
430420

431421
@staticmethod
432422
def build_instance_metadata(user_data=None, encode_user_data=True):
@@ -435,7 +425,7 @@ def build_instance_metadata(user_data=None, encode_user_data=True):
435425
the :any:`instance_create` method. This helper can also be used
436426
when cloning and rebuilding Instances.
437427
**Creating an Instance with User Data**::
438-
new_linode, password = client.linode.instance_create(
428+
new_linode = client.linode.instance_create(
439429
"g6-standard-2",
440430
"us-east",
441431
image="linode/ubuntu22.04",

linode_api4/objects/linode.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,9 +1398,7 @@ def disk_create(
13981398
:param image: The Image to deploy to the disk. If provided, at least one of
13991399
root_pass, authorized_users or authorized_keys must also be given.
14001400
:param root_pass: The password to configure for the root user when deploying an
1401-
image to this disk. Not used if image is not given. If an
1402-
image is given and root_pass is provided, it will be returned
1403-
alongside the new disk as a tuple.
1401+
image to this disk. Not used if image is not given.
14041402
:param authorized_keys: A list of SSH keys to install as trusted for the root user.
14051403
:param authorized_users: A list of usernames whose keys should be installed
14061404
as trusted for the root user. These user's keys
@@ -1414,9 +1412,8 @@ def disk_create(
14141412
:param **stackscript_args: Any arguments to pass to the StackScript, as defined
14151413
by its User Defined Fields.
14161414
1417-
:returns: A new Disk object, or a tuple containing the new Disk and the
1418-
password if both image and root_pass were provided.
1419-
:rtype: Disk or tuple(Disk, str)
1415+
:returns: A new Disk object.
1416+
:rtype: Disk
14201417
"""
14211418

14221419
if (
@@ -1475,11 +1472,7 @@ def disk_create(
14751472
"Unexpected response creating disk!", json=result
14761473
)
14771474

1478-
d = Disk(self._client, result["id"], self.id, result)
1479-
1480-
if image and root_pass:
1481-
return d, root_pass
1482-
return d
1475+
return Disk(self._client, result["id"], self.id, result)
14831476

14841477
def enable_backups(self):
14851478
"""
@@ -1620,8 +1613,8 @@ def rebuild(
16201613
NOTE: Disk encryption may not currently be available to all users.
16211614
:type disk_encryption: InstanceDiskEncryptionType or str
16221615
1623-
:returns: The root_pass if provided, otherwise True.
1624-
:rtype: str or bool
1616+
:returns: True.
1617+
:rtype: bool
16251618
"""
16261619
if not root_pass and not authorized_keys and not authorized_users:
16271620
raise ValueError(
@@ -1657,8 +1650,6 @@ def rebuild(
16571650
# update ourself with the newly-returned information
16581651
self._populate(result)
16591652

1660-
if root_pass:
1661-
return root_pass
16621653
return True
16631654

16641655
def rescue(self, *disks):

test/integration/conftest.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,13 @@ def create_linode(test_linode_client, e2e_test_firewall):
223223
region = get_region(client, {"Linodes", "Cloud Firewall"}, site_type="core")
224224
label = get_test_label(length=8)
225225

226-
linode_instance, password = client.linode.instance_create(
226+
linode_instance = client.linode.instance_create(
227227
"g6-nanode-1",
228228
region,
229229
image="linode/debian12",
230230
label=label,
231231
firewall=e2e_test_firewall,
232+
root_pass="aComplex@Password123",
232233
)
233234

234235
yield linode_instance
@@ -242,13 +243,15 @@ def create_linode_for_pass_reset(test_linode_client, e2e_test_firewall):
242243

243244
region = get_region(client, {"Linodes", "Cloud Firewall"}, site_type="core")
244245
label = get_test_label(length=8)
246+
password = "aComplex@Password123"
245247

246-
linode_instance, password = client.linode.instance_create(
248+
linode_instance = client.linode.instance_create(
247249
"g6-nanode-1",
248250
region,
249251
image="linode/debian12",
250252
label=label,
251253
firewall=e2e_test_firewall,
254+
root_pass=password,
252255
)
253256

254257
yield linode_instance, password
@@ -488,15 +491,16 @@ def create_vpc_with_subnet_and_linode(
488491

489492
label = get_test_label(length=8)
490493

491-
instance, password = test_linode_client.linode.instance_create(
494+
instance = test_linode_client.linode.instance_create(
492495
"g6-standard-1",
493496
vpc.region,
494497
image="linode/debian11",
495498
label=label,
496499
firewall=e2e_test_firewall,
500+
root_pass="aComplex@Password123",
497501
)
498502

499-
yield vpc, subnet, instance, password
503+
yield vpc, subnet, instance
500504

501505
instance.delete()
502506

@@ -579,12 +583,13 @@ def linode_for_vlan_tests(test_linode_client, e2e_test_firewall):
579583
region = get_region(client, {"Linodes", "Vlans"}, site_type="core")
580584
label = get_test_label(length=8)
581585

582-
linode_instance, password = client.linode.instance_create(
586+
linode_instance = client.linode.instance_create(
583587
"g6-nanode-1",
584588
region,
585589
image="linode/debian12",
586590
label=label,
587591
firewall=e2e_test_firewall,
592+
root_pass="aComplex@Password123",
588593
)
589594

590595
yield linode_instance
@@ -628,13 +633,14 @@ def linode_with_linode_interfaces(
628633
region = vpc.region
629634
label = get_test_label()
630635

631-
instance, _ = client.linode.instance_create(
636+
instance = client.linode.instance_create(
632637
"g6-nanode-1",
633638
region,
634639
image="linode/debian12",
635640
label=label,
636641
booted=False,
637642
interface_generation=InterfaceGeneration.LINODE,
643+
root_pass="aComplex@Password123",
638644
interfaces=[
639645
LinodeInterfaceOptions(
640646
firewall_id=e2e_test_firewall.id,

test/integration/linode_client/test_linode_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ def setup_client_and_linode(test_linode_client, e2e_test_firewall):
1616

1717
label = get_test_label()
1818

19-
linode_instance, password = client.linode.instance_create(
19+
linode_instance = client.linode.instance_create(
2020
"g6-nanode-1",
2121
region,
2222
image="linode/debian12",
2323
label=label,
2424
firewall=e2e_test_firewall,
25+
root_pass="aComplex@Password123"
2526
)
2627

2728
yield client, linode_instance
@@ -258,7 +259,7 @@ def test_create_linode_with_interfaces(test_linode_client):
258259
region = get_region(client, {"Vlans", "Linodes"}, site_type="core").id
259260
label = get_test_label()
260261

261-
linode_instance, password = client.linode.instance_create(
262+
linode_instance = client.linode.instance_create(
262263
"g6-nanode-1",
263264
region,
264265
label=label,
@@ -269,6 +270,7 @@ def test_create_linode_with_interfaces(test_linode_client):
269270
purpose="vlan", label="cool-vlan", ipam_address="10.0.0.4/32"
270271
),
271272
],
273+
root_pass="aComplex@Password123",
272274
)
273275

274276
assert len(linode_instance.configs[0].interfaces) == 2

test/integration/models/account/test_account.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,13 @@ def test_latest_get_event(test_linode_client, e2e_test_firewall):
9898
region = get_region(client, {"Linodes", "Cloud Firewall"}, site_type="core")
9999
label = get_test_label()
100100

101-
linode, password = client.linode.instance_create(
101+
linode = client.linode.instance_create(
102102
"g6-nanode-1",
103103
region,
104104
image="linode/debian12",
105105
label=label,
106106
firewall=e2e_test_firewall,
107+
root_pass="aComplex@Password123",
107108
)
108109

109110
def get_linode_status():

test/integration/models/firewall/test_firewall.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ def linode_fw(test_linode_client):
1313
region = get_region(client, {"Linodes", "Cloud Firewall"}, site_type="core")
1414
label = get_test_label()
1515

16-
linode_instance, password = client.linode.instance_create(
17-
"g6-nanode-1", region, image="linode/debian12", label=label
16+
linode_instance = client.linode.instance_create(
17+
"g6-nanode-1", region, image="linode/debian12", label=label,
18+
root_pass="aComplex@Password123",
1819
)
1920

2021
yield linode_instance

0 commit comments

Comments
 (0)