-
Notifications
You must be signed in to change notification settings - Fork 84
TPT-4527: Implemented changes for SLADE and CLEO projects #665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: proj/slade-cleo
Are you sure you want to change the base?
Changes from 7 commits
71544fc
a86328f
158df5c
37834a9
f517a71
82dd267
2304843
91f671f
b600db6
2fb48d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,6 +162,10 @@ def instance_create( | |
| interface_generation: Optional[Union[InterfaceGeneration, str]] = None, | ||
| network_helper: Optional[bool] = None, | ||
| maintenance_policy: Optional[str] = None, | ||
| root_pass: Optional[str] = None, | ||
| kernel: Optional[str] = None, | ||
| boot_size: Optional[int] = None, | ||
| authorized_users: Optional[List[str]] = None, | ||
| **kwargs, | ||
| ): | ||
| """ | ||
|
|
@@ -172,26 +176,29 @@ def instance_create( | |
| To create an Instance from an :any:`Image`, call `instance_create` with | ||
| a :any:`Type`, a :any:`Region`, and an :any:`Image`. All three of | ||
| these fields may be provided as either the ID or the appropriate object. | ||
| In this mode, a root password will be generated and returned with the | ||
| new Instance object. | ||
| When an Image is provided, at least one of ``root_pass``, ``authorized_users``, or | ||
| ``authorized_keys`` must also be given. If ``root_pass`` is provided, | ||
| the Instance and the password are returned as a tuple. | ||
|
|
||
| For example:: | ||
|
|
||
| new_linode, password = client.linode.instance_create( | ||
| "g6-standard-2", | ||
| "us-east", | ||
| image="linode/debian9") | ||
| image="linode/debian13", | ||
| root_pass="aComplex@Password123") | ||
|
|
||
| ltype = client.linode.types().first() | ||
| region = client.regions().first() | ||
| image = client.images().first() | ||
|
|
||
| another_linode, password = client.linode.instance_create( | ||
| another_linode = client.linode.instance_create( | ||
| ltype, | ||
| region, | ||
| image=image) | ||
| image=image, | ||
| authorized_keys="ssh-rsa AAAA") | ||
|
|
||
| To output the password from the above example: | ||
| To output the password from the first example above: | ||
| print(password) | ||
|
|
||
| To output the first IPv4 address of the new Linode: | ||
|
|
@@ -213,7 +220,8 @@ def instance_create( | |
| new_linode, password = client.linode.instance_create( | ||
| "g6-standard-2", | ||
| "us-east", | ||
| image="linode/debian9", | ||
| image="linode/debian13", | ||
| root_pass="aComplex@Password123", | ||
| stackscript=stackscript, | ||
| stackscript_data={"gh_username": "example"}) | ||
|
|
||
|
|
@@ -248,6 +256,7 @@ def instance_create( | |
| "g6-standard-1", | ||
| "us-mia", | ||
| image="linode/ubuntu24.04", | ||
| root_pass="aComplex@Password123", | ||
|
|
||
| # This can be configured as an account-wide default | ||
| interface_generation=InterfaceGeneration.LINODE, | ||
|
|
@@ -280,10 +289,16 @@ def instance_create( | |
| :type ltype: str or Type | ||
| :param region: The Region in which we are creating the Instance | ||
| :type region: str or Region | ||
| :param image: The Image to deploy to this Instance. If this is provided | ||
| and no root_pass is given, a password will be generated | ||
| and returned along with the new Instance. | ||
| :param image: The Image to deploy to this Instance. If this is provided, | ||
| at least one of root_pass, authorized_users, or authorized_keys must also be | ||
| provided. | ||
| :type image: str or Image | ||
| :param root_pass: The root password for the new Instance. If an image is | ||
| provided and root_pass is given, the Instance and password | ||
| will be returned as a tuple. If all of root_pass, authorized_users,and | ||
| authorized_keys are not provided when an image is specified, | ||
| a ValueError will be raised. | ||
| :type root_pass: str | ||
| :param stackscript: The StackScript to deploy to the new Instance. If | ||
| provided, "image" is required and must be compatible | ||
| with the chosen StackScript. | ||
|
|
@@ -300,6 +315,11 @@ def instance_create( | |
| be a single key, or a path to a file containing | ||
| the key. | ||
| :type authorized_keys: list or str | ||
| :param authorized_users: A list of usernames whose keys should be installed | ||
| as trusted for the root user. These user's keys | ||
| should already be set up, see :any:`ProfileGroup.ssh_keys` | ||
| for details. | ||
| :type authorized_users: list[str] | ||
| :param label: The display label for the new Instance | ||
| :type label: str | ||
| :param group: The display group for the new Instance | ||
|
|
@@ -336,26 +356,40 @@ def instance_create( | |
| :param maintenance_policy: The slug of the maintenance policy to apply during maintenance. | ||
| If not provided, the default policy (linode/migrate) will be applied. | ||
| :type maintenance_policy: str | ||
| :param kernel: The kernel to boot the Instance with. If provided, this will be used as the | ||
| kernel for the default configuration profile. | ||
| :type kernel: str | ||
| :param boot_size: The size of the boot disk in MB. If provided, this will be used to create | ||
| the boot disk for the Instance. | ||
| :type boot_size: int | ||
|
|
||
| :returns: A new Instance object, or a tuple containing the new Instance and | ||
| the generated password. | ||
| the password if both image and root_pass were provided. | ||
| :rtype: Instance or tuple(Instance, str) | ||
| :raises ApiError: If contacting the API fails | ||
| :raises UnexpectedResponseError: If the API response is somehow malformed. | ||
| This usually indicates that you are using | ||
| an outdated library. | ||
| """ | ||
|
|
||
| ret_pass = None | ||
| if image and not "root_pass" in kwargs: | ||
| ret_pass = Instance.generate_root_password() | ||
| kwargs["root_pass"] = ret_pass | ||
| if ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: I think the removal of the root password generation would be a breaking change. All good if that's how we want to move forward, just figured I'd call it out 🙂
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah true, but I think since the purpose of this project is to make passwords optional it would be odd to generate one even when the user intentionally does not provide one. |
||
| image | ||
| and not root_pass | ||
| and not authorized_keys | ||
| and not authorized_users | ||
| ): | ||
| raise ValueError( | ||
| "When creating an Instance from an Image, at least one of " | ||
| "root_pass, authorized_users, or authorized_keys must be provided." | ||
| ) | ||
|
|
||
| params = { | ||
| "type": ltype, | ||
| "region": region, | ||
| "image": image, | ||
| "root_pass": root_pass, | ||
| "authorized_keys": load_and_validate_keys(authorized_keys), | ||
| "authorized_users": authorized_users, | ||
| # These will automatically be flattened below | ||
| "firewall_id": firewall, | ||
| "backup_id": backup, | ||
|
|
@@ -373,6 +407,8 @@ def instance_create( | |
| "interfaces": interfaces, | ||
| "interface_generation": interface_generation, | ||
| "network_helper": network_helper, | ||
| "kernel": kernel, | ||
| "boot_size": boot_size, | ||
| } | ||
|
|
||
| params.update(kwargs) | ||
|
|
@@ -388,9 +424,9 @@ def instance_create( | |
| ) | ||
|
|
||
| l = Instance(self.client, result["id"], result) | ||
| if not ret_pass: | ||
| if not (image and root_pass): | ||
| return l | ||
| return l, ret_pass | ||
| return l, root_pass | ||
|
|
||
| @staticmethod | ||
| def build_instance_metadata(user_data=None, encode_user_data=True): | ||
|
|
@@ -403,6 +439,7 @@ def build_instance_metadata(user_data=None, encode_user_data=True): | |
| "g6-standard-2", | ||
| "us-east", | ||
| image="linode/ubuntu22.04", | ||
| root_pass="aComplex@Password123", | ||
| metadata=client.linode.build_instance_metadata(user_data="myuserdata") | ||
| ) | ||
| :param user_data: User-defined data to provide to the Linode Instance through | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.