Add create_vm_pricing management command

This commit is contained in:
PCoder 2018-04-12 08:01:43 +02:00
parent 588f513f2a
commit d50f282057

View file

@ -0,0 +1,36 @@
from django.core.management.base import BaseCommand
from datacenterlight.models import VMPricing
class Command(BaseCommand):
help = '''Creates default VMPricing object'''
DEFAULT_VMPRICING_NAME = 'default'
def handle(self, *args, **options):
self.create_default_vm_pricing()
def create_default_vm_pricing(self):
obj, created = VMPricing.objects.get_or_create(
name=self.DEFAULT_VMPRICING_NAME,
defaults={
"vat_inclusive": True,
"cores_unit_price": 5,
"ram_unit_price": 2,
"ssd_unit_price": 0.6,
"hdd_unit_price": 0.01
}
)
if created:
print(
'Successfully created {} VMPricing object'.format(
self.DEFAULT_VMPRICING_NAME
)
)
else:
print(
'{} VMPricing exists already.'.format(
self.DEFAULT_VMPRICING_NAME
)
)