From 105142f76aa901d7bf5229de66d252318fc3058a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 22 Mar 2020 18:52:31 +0100 Subject: [PATCH] Add template for creating VMs --- .../commands/vm-create-snapshots.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 uncloud/uncloud_vm/management/commands/vm-create-snapshots.py diff --git a/uncloud/uncloud_vm/management/commands/vm-create-snapshots.py b/uncloud/uncloud_vm/management/commands/vm-create-snapshots.py new file mode 100644 index 0000000..bd3bb65 --- /dev/null +++ b/uncloud/uncloud_vm/management/commands/vm-create-snapshots.py @@ -0,0 +1,35 @@ +import json + +import uncloud.secrets as secrets + +from django.core.management.base import BaseCommand +from django.contrib.auth import get_user_model + +from uncloud_vm.models import VMSnapshotProduct +from datetime import datetime + +class Command(BaseCommand): + help = 'Select VM Host for VMs' + + def add_arguments(self, parser): + parser.add_argument('--this-hostname', required=True) + # parser.add_argument('--start-vms-here', action='store_true') + # parser.add_argument('--check-health', action='store_true') + # parser.add_argument('--vmhostname') + # print(parser) + + + def handle(self, *args, **options): + for snapshot in VMSnapshotProduct.objects.filter(status='PENDING'): + if not snapshot.extra_data: + snapshot.extra_data = {} + + # TODO: implement locking here + if 'creating_hostname' in snapshot.extra_data: + pass + + snapshot.extra_data['creating_hostname'] = options['this_hostname'] + snapshot.extra_data['creating_start'] = str(datetime.now()) + snapshot.save() + + print(snapshot)