remotedev: Add option to recreate droplets.

This commit is contained in:
Vishnu Ks 2017-11-23 20:59:08 +05:30 committed by Tim Abbott
parent 938892db8f
commit def573cde3
2 changed files with 20 additions and 6 deletions

View File

@ -68,6 +68,15 @@ may contain letters, numbers, colons, dashes, and underscores.
You'll need to run this from the Zulip development environment (e.g. in
Vagrant).
If you want to recreate a droplet for a user you can pass the
`--recreate` flag.
```
$ python3 create.py <username> --recreate
```
This will destroy the old droplet and create a new droplet for
the user.
In order for the script to work, the GitHub user must have:
- forked the [zulip/zulip][zulip-zulip] repository, and

View File

@ -31,6 +31,7 @@ from typing import Any, Dict, List
parser = argparse.ArgumentParser(description='Create a Zulip devopment VM Digital Ocean droplet.')
parser.add_argument("username", help="Github username for whom you want to create a Zulip dev droplet")
parser.add_argument('--tags', nargs='+', default=[])
parser.add_argument('-f', '--recreate', dest='recreate', action="store_true", default=False)
def get_config():
# type: () -> configparser.ConfigParser
@ -83,16 +84,20 @@ def fork_exists(username):
print("Has user {0} forked zulip/zulip?".format(username))
sys.exit(1)
def exit_if_droplet_exists(my_token, username):
# type: (str, str) -> None
def exit_if_droplet_exists(my_token: str, username: str, recreate: bool) -> None:
print("Checking to see if droplet for {0} already exists...".format(username))
manager = digitalocean.Manager(token=my_token)
my_droplets = manager.get_all_droplets()
for droplet in my_droplets:
if droplet.name == "{0}.zulipdev.org".format(username):
print("Droplet for user {0} already exists.".format(username))
print("Delete droplet AND dns entry via Digital Ocean control panel if you need to re-create.")
sys.exit(1)
if not recreate:
print("Droplet for user {0} already exists. Pass --recreate if you "
"need to recreate the droplet.".format(username))
sys.exit(1)
else:
print("Deleting existing droplet for {0}.".format(username))
droplet.destroy()
return
print("...No droplet found...proceeding.")
def set_user_data(username, userkeys):
@ -235,7 +240,7 @@ if __name__ == '__main__':
api_token = config['digitalocean']['api_token']
# does the droplet already exist?
exit_if_droplet_exists(my_token=api_token, username=args.username)
exit_if_droplet_exists(my_token=api_token, username=args.username, recreate=args.recreate)
# set user_data
user_data = set_user_data(username=args.username, userkeys=public_keys)