improve readability

This commit is contained in:
ahmadbilalkhalid 2020-03-03 23:53:45 +05:00
parent fea0568bb9
commit 88c10e2e4a

View file

@ -9,7 +9,7 @@ from uncloud_pay.models import Order
def get_vm_price(core, ram, storage, n_of_ipv4, n_of_ipv6): 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 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. # 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') mac_address = nic.get('MAC')
ip_address = nic.get('IP', None) or nic.get('IP6_GLOBAL', None) 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('.', '')
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) mac_address = int(mac_address, base=16)
VMNetworkCard.objects.create( VMNetworkCard.objects.create(
@ -84,20 +87,33 @@ class Command(BaseCommand):
# TODO: Insert actual/real creation_date, starting_date, ending_date # TODO: Insert actual/real creation_date, starting_date, ending_date
# instead of pseudo one we are putting currently # 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( order = Order.objects.create(
owner=one_vm.owner, owner=one_vm.owner,
creation_date=datetime.now(tz=timezone.utc), creation_date=creation_date,
starting_date=datetime.now(tz=timezone.utc), starting_date=starting_date,
ending_date=datetime.now(tz=timezone.utc), ending_date=ending_date,
one_time_price=0, one_time_price=one_time_price,
recurring_price=get_vm_price(cores, ram_in_gb, total_storage_in_gb, len(ipv4), len(ipv6)), recurring_price=recurring_price,
recurring_period='per_month' recurring_period=recurring_period
) )
vm_product = VMProduct.objects.create( vm_product = VMProduct.objects.create(
cores=cores, ram_in_gb=ram_in_gb, cores=cores,
owner=one_vm.owner, vmhost=host, ram_in_gb=ram_in_gb,
order=order, status=status owner=one_vm.owner,
vmhost=host,
order=order,
status=status
) )
# Create VMNetworkCards # Create VMNetworkCards