First pass at the add-opennebula-vm-orders management command
Command executes but still does not create bills
This commit is contained in:
parent
df4c0c3060
commit
f02f15f09b
7 changed files with 172 additions and 40 deletions
21
uncloud_vm/migrations/0002_vmproduct_owner.py
Normal file
21
uncloud_vm/migrations/0002_vmproduct_owner.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 3.1.4 on 2021-04-14 10:40
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('uncloud_vm', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='vmproduct',
|
||||
name='owner',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
||||
20
uncloud_vm/migrations/0003_vmproduct_created_order_at.py
Normal file
20
uncloud_vm/migrations/0003_vmproduct_created_order_at.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 3.1.4 on 2021-04-14 10:46
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('uncloud_vm', '0002_vmproduct_owner'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='vmproduct',
|
||||
name='created_order_at',
|
||||
field=models.DateTimeField(default=datetime.datetime(2021, 4, 14, 10, 46, 14, 96330, tzinfo=utc)),
|
||||
),
|
||||
]
|
||||
24
uncloud_vm/migrations/0004_auto_20210414_1048.py
Normal file
24
uncloud_vm/migrations/0004_auto_20210414_1048.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# Generated by Django 3.1.4 on 2021-04-14 10:48
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('uncloud_vm', '0003_vmproduct_created_order_at'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='vmproduct',
|
||||
name='created_order_at',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='vmproduct',
|
||||
name='create_order_at',
|
||||
field=models.DateTimeField(default=datetime.datetime(2021, 4, 14, 10, 48, 6, 641056, tzinfo=utc)),
|
||||
),
|
||||
]
|
||||
24
uncloud_vm/migrations/0005_auto_20210414_1119.py
Normal file
24
uncloud_vm/migrations/0005_auto_20210414_1119.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# Generated by Django 3.1.4 on 2021-04-14 11:19
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('uncloud_vm', '0004_auto_20210414_1048'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='vmproduct',
|
||||
name='create_order_at',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='vmproduct',
|
||||
name='created_order_at',
|
||||
field=models.DateTimeField(default=datetime.datetime(2021, 4, 14, 11, 19, 39, 447274, tzinfo=utc)),
|
||||
),
|
||||
]
|
||||
20
uncloud_vm/migrations/0006_auto_20210414_1122.py
Normal file
20
uncloud_vm/migrations/0006_auto_20210414_1122.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 3.1.4 on 2021-04-14 11:22
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('uncloud_vm', '0005_auto_20210414_1119'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='vmproduct',
|
||||
name='created_order_at',
|
||||
field=models.DateTimeField(default=datetime.datetime(2021, 4, 14, 11, 22, 11, 352536, tzinfo=utc)),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
import datetime
|
||||
from django.utils import timezone
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
|
|
@ -50,6 +53,8 @@ class VMHost(UncloudModel):
|
|||
|
||||
|
||||
class VMProduct(models.Model):
|
||||
owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE,
|
||||
blank=True, null=True)
|
||||
vmhost = models.ForeignKey(
|
||||
VMHost, on_delete=models.CASCADE, editable=False, blank=True, null=True
|
||||
)
|
||||
|
|
@ -61,6 +66,7 @@ class VMProduct(models.Model):
|
|||
name = models.CharField(max_length=32, blank=True, null=True)
|
||||
cores = models.IntegerField()
|
||||
ram_in_gb = models.FloatField()
|
||||
created_order_at = models.DateTimeField(default=timezone.make_aware(datetime.datetime.now()))
|
||||
|
||||
@property
|
||||
def recurring_price(self):
|
||||
|
|
@ -78,6 +84,11 @@ class VMProduct(models.Model):
|
|||
# RecurringPeriod.PER_30D, RecurringPeriod.PER_HOUR],
|
||||
# RecurringPeriod.choices))
|
||||
|
||||
def create_order_at(self, dt):
|
||||
self.created_order_at = dt
|
||||
|
||||
def create_or_update_order(self, when_to_start):
|
||||
self.created_order_at = when_to_start
|
||||
|
||||
def __str__(self):
|
||||
return f"VM id={self.id},name={self.name},cores={self.cores},ram_in_gb={self.ram_in_gb}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue