linode / linode_api4-python

Official Python bindings for the Linode API
https://linode-api4.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
135 stars 75 forks source link

[Feature]: enable swap_size in module #333

Closed jmcalvar closed 1 month ago

jmcalvar commented 11 months ago

Description

Currently it is possible to define swap size creating an instance with the API. From https://www.linode.com/docs/api/linode-instances/#linode-create :

A default config with two Disks, one being a 512 swap disk, is created. swap_size can be used to customize the swap disk size.

I'm using linode_api4-python with an ansible-playbook, and when I added to the params "swap_size" it stopped with errors showing that "swap_size" is not supported.

Is it possible to add the param swap_size?

lgarber-akamai commented 11 months ago

Hello @jmcalvar, thanks for the feature request! Could you provide an example snippet from your playbook to reproduce the error mentioned above?

jmcalvar commented 11 months ago

If I add the swap_size parameter to the playbook it fails and it indicates the parameter doesn't exist:

    linode_v4:
      access_token: "{{ token }}"
      label: "{{ item.key }}"
      type: "{{ server_type }}"
      region: "{{server_region }}"
      image: "{{ server_image }}"
      root_pass: "{{ password }}"
      authorized_keys: "{{ ssh_keys }}"
      group: example_group
      #tags: "Test-{{item.value.site}}"
      tags: "testjose-lab"
      state: present
      private_ip: true
      swap_size: 2500
    loop: "{{ query('dict', nodes) }}"

The error that it produces is this:

TASK [Create a new Linode.] ***********************************************************************************************************************************************************************************************************************
failed: [localhost] (item={'key': 'testjose-kafka', 'value': {'site': 'DC', 'roles': ['kafka', 'nom-kvs']}}) => {"ansible_loop_var": "item", "changed": false, "item": {"key": "testjose-kafka", "value": {"roles": ["kafka", "nom-kvs"], "site": "DC"}}, "msg": "Unsupported parameters for (linode_v4) module: swap_size. Supported parameters include: access_token, authorized_keys, group, image, label, private_ip, region, root_pass, stackscript_data, stackscript_id, state, tags, type."}
failed: [localhost] (item={'key': 'testjose-vertica', 'value': {'site': 'DC', 'roles': ['vertica', 'nom-data-loader']}}) => {"ansible_loop_var": "item", "changed": false, "item": {"key": "testjose-vertica", "value": {"roles": ["vertica", "nom-data-loader"], "site": "DC"}}, "msg": "Unsupported parameters for (linode_v4) module: swap_size. Supported parameters include: access_token, authorized_keys, group, image, label, private_ip, region, root_pass, stackscript_data, stackscript_id, state, tags, type."}

If I hardcode the parameter in the code it works, but of course I have to remove from the playbook, and I have to modify it in the module itself. Then if I delete the "swap_file" parameter from my playbook and add it to the file site-packages/linode_api4/groups/linode.py it works:


    # create things
    def instance_create(
        self, ltype, region, image=None, authorized_keys=None,swap_size=2500, **kwargs
    ):
        """
        Creates a new Linode Instance. This function has several modes of operation:```
yec-akamai commented 4 months ago

Hi @jmcalvar,

Sorry for the delay!

linode_api4-python actually supports this param swap_size. If you'd like to use our SDK directly, you can create a linode with swap_size like this:

    linode, _ = client.linode.instance_create(
        "g6-nanode-1",
        "us-mia",
        label="test-instance",
        image="linode/alpine3.19",
        swap_size=2500,
    )

We'll also support this feature in ansible soon. However, instead of the community collection linode_v4, we'll add it to our official collection: https://github.com/linode/ansible_linode. We'll let you know when this feature is released. We highly recommend you to use our official collection, which we maintain directly on a regular basis. Feel free to drop any linode ansible related question there. Thank you so much for your support!

yec-akamai commented 1 month ago

We just updated the instance config in ansible_linode. It'll be released in the next version. Thank you for reporting this issue!