koalalorenzo/python-digitalocean

Get droplet ID after droplet.create()

Closed this issue · 4 comments

How do I get a reference to the ID of a droplet after I create it?

droplet = digitalocean.Droplet(token=toke, name=thisdrop[0], ...)

droplet.create()
print droplet.id  # <=======

Maybe?

newdrop = droplet.create()
print newdrop.id

I would like to add a tag to a droplet at creation time and I see 2 possibilities.

  • Add another attribute to droplet
    digitalocean.Droplet(tag="my_tag_string", ...
  • Get the droplet ID at creation and use the syntax presented in the readme.

Thanks,
Chris.

Hey! I think you can help us!
If you think something is missing you can make a PR! :-)

tags can be added at creation time as an array of strings.

droplet = digitalocean.Droplet(token = redir_token, name = "test1", region = random.choice(regions).slug, image = "ubuntu-16-04-x64", size_slug = "1gb", ssh_key = redir_key, tags=["some_tag_name"], backups = "False")

This seems to work for pulling the droplet ID after creation.

droplet = digitalocean.Droplet(token = redir_token, name = "test2", region = random.choice(regions).slug, image = "ubuntu-16-04-x64", size_slug = "1gb", ssh_key = redir_key, tags=["redir","redteam"], backups = "False")
droplet.create()
all_actions = droplet.get_actions()
for action in all_actions:
     if action.wait(update_every_seconds=5):
             print(droplet.id)

Thank you. It works.