++ fix opennebula migration

This commit is contained in:
Nico Schottelius 2020-03-17 16:03:41 +01:00
parent cc2efa5c14
commit b9473c1803
1 changed files with 20 additions and 11 deletions

View File

@ -5,6 +5,7 @@ from django.utils import timezone
from opennebula.models import VM as VMModel
from uncloud_vm.models import VMHost, VMProduct, VMNetworkCard, VMDiskImageProduct, VMDiskProduct
from uncloud_pay.models import Order
@ -82,7 +83,16 @@ class Command(BaseCommand):
def handle(self, *args, **options):
for one_vm in VMModel.objects.all():
vmhost = VMHost.objects.get(hostname=one_vm.last_host)
if not one_vm.last_host:
print("No VMHost for VM {} - VM might be on hold - skipping".format(one_vm.vmid))
continue
try:
vmhost = VMHost.objects.get(hostname=one_vm.last_host)
except VMHost.DoesNotExist:
print("VMHost {} does not exist, aborting".format(one_vm.last_host))
raise
cores = one_vm.cores
ram_in_gb = one_vm.ram_in_gb
owner = one_vm.owner
@ -91,15 +101,15 @@ class Command(BaseCommand):
# Total Amount of SSD Storage
# TODO: What would happen if the attached storage is not SSD but HDD?
ssd_size = sum([ disk['size_in_gb'] for disk in one.disks if disk['pool_name'] in ['ssd', 'one'] ])
hdd_size = sum([ disk['size_in_gb'] for disk in one.disks if disk['pool_name'] in ['hdd'] ])
ssd_size = sum([ disk['size_in_gb'] for disk in one_vm.disks if disk['pool_name'] in ['ssd', 'one'] ])
hdd_size = sum([ disk['size_in_gb'] for disk in one_vm.disks if disk['pool_name'] in ['hdd'] ])
# List of IPv4 addresses and Global IPv6 addresses
ipv4, ipv6 = one_vm.ips
# TODO: Insert actual/real creation_date, starting_date, ending_date
# instead of pseudo one we are putting currently
creation_date = starting_date = ending_date = datetime.now(tz=timezone.utc)
creation_date = starting_date = datetime.now(tz=timezone.utc)
# Price calculation based on datacenterlight.ch
one_time_price = 0
@ -114,19 +124,18 @@ class Command(BaseCommand):
order = Order.objects.create(
owner=owner,
creation_date=creation_date,
starting_date=starting_date,
ending_date=ending_date,
one_time_price=one_time_price,
recurring_price=recurring_price,
recurring_period=recurring_period
starting_date=starting_date
# one_time_price=one_time_price,
# recurring_price=recurring_price,
# recurring_period=recurring_period
)
vm_product, _ = VMProduct.objects.update_or_create(
name=
name=one_vm.uncloud_name,
defaults={
'cores': cores,
'ram_in_gb': ram_in_gb,
'owner': owner,
'vmhost': host,
'vmhost': vmhost,
'order': order,
'status': status
}