From 88c10e2e4a0fda2b8c0965b88b7f8ee67d015dbb Mon Sep 17 00:00:00 2001 From: meow Date: Tue, 3 Mar 2020 23:53:45 +0500 Subject: [PATCH] improve readability --- .../commands/migrate-one-vm-to-regular.py | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/uncloud/opennebula/management/commands/migrate-one-vm-to-regular.py b/uncloud/opennebula/management/commands/migrate-one-vm-to-regular.py index 16a6449..13f292b 100644 --- a/uncloud/opennebula/management/commands/migrate-one-vm-to-regular.py +++ b/uncloud/opennebula/management/commands/migrate-one-vm-to-regular.py @@ -9,7 +9,7 @@ from uncloud_pay.models import Order def get_vm_price(core, ram, storage, n_of_ipv4, n_of_ipv6): - storage = storage / 10 + storage = storage / 10 # Division by 10 because our base storage unit is 10 GB total = 3 * core + 4 * ram + 3.5 * storage + 8 * n_of_ipv4 + 0 * n_of_ipv6 # TODO: Find some reason about the following magical subtraction. @@ -23,10 +23,13 @@ def create_nics(one_vm, vm_product): mac_address = nic.get('MAC') ip_address = nic.get('IP', None) or nic.get('IP6_GLOBAL', None) + # Remove octet connecting characters mac_address = mac_address.replace(':', '') mac_address = mac_address.replace('.', '') mac_address = mac_address.replace('-', '') mac_address = mac_address.replace(' ', '') + + # Parse the resulting number as hexadecimal mac_address = int(mac_address, base=16) VMNetworkCard.objects.create( @@ -84,20 +87,33 @@ class Command(BaseCommand): # 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) + + # Price calculation + + # TODO: Make the following non-hardcoded + one_time_price = 0 + recurring_period = 'per_month' + + recurring_price = get_vm_price(cores, ram_in_gb, total_storage_in_gb, len(ipv4), len(ipv6)) + order = Order.objects.create( owner=one_vm.owner, - creation_date=datetime.now(tz=timezone.utc), - starting_date=datetime.now(tz=timezone.utc), - ending_date=datetime.now(tz=timezone.utc), - one_time_price=0, - recurring_price=get_vm_price(cores, ram_in_gb, total_storage_in_gb, len(ipv4), len(ipv6)), - recurring_period='per_month' + 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 ) vm_product = VMProduct.objects.create( - cores=cores, ram_in_gb=ram_in_gb, - owner=one_vm.owner, vmhost=host, - order=order, status=status + cores=cores, + ram_in_gb=ram_in_gb, + owner=one_vm.owner, + vmhost=host, + order=order, + status=status ) # Create VMNetworkCards