Created
October 28, 2019 10:56
-
-
Save kpavlovsky/a8ea454acb2bc34ff999e44c647ed8df to your computer and use it in GitHub Desktop.
Create a Digital Ocean Droplet with Ubuntu 18.04 via Python 3 API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
manager = digitalocean.Manager(token=user.digital_ocean_token) | |
images = manager.get_global_images() | |
image_id = None | |
for i in images: | |
if i.slug == 'ubuntu-18-04-x64': | |
image_id = i.id | |
if not image_id: | |
return "Server creation failed, could not find a suitable image" | |
droplet = digitalocean.Droplet( | |
token=user.digital_ocean_token, | |
name=server_name, | |
region='nyc1', | |
image=image_id, | |
ssh_keys=keys, | |
size="s-2vcpu-4gb", | |
backups=True) | |
droplet.create() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment