35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
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)
|