Setting linode name through Python API

Hi,
When I create a linode through the Python API, how can I set its name? When I create one, on my dashboard it shows as linode-xxxx and I'd like to change that name as the linode is created.
Thank you!

1 Reply

Hey -- When you create a new Linode with create_instance, you can specify a label like this:

new_linode, password = client.linode.create_instance("g6-standard-2", "us-east", label="new")

To rename an existing Linode, you need the LinodeID. Here's a basic example of how to grab the LinodeID -- this will print all of your Linodes by ID and label:

my_linodes = client.linode.get_instances()
for a_linode in my_linodes:
   print(a_linode.id, a_linode.label)

Once you have the ID, you can create a model, set the label attribute, and save the model. Assuming your Linode's ID was 5000:

my_linode = Linode(client, 5000)
my_linode.label = "New Label"
my_linode.save()

There's more great info in the docs, too:
Getting Started with Linode API for Python
Core Concepts

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct