forked from uncloud/uncloud
Introduce "extra_data" jsonfield
This commit is contained in:
parent
a32f7522b5
commit
10c5257f90
5 changed files with 100 additions and 6 deletions
22
uncloud/uncloud/models.py
Normal file
22
uncloud/uncloud/models.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
from django.db import models
|
||||||
|
from django.contrib.postgres.fields import JSONField
|
||||||
|
|
||||||
|
class UncloudModel(models.Model):
|
||||||
|
"""
|
||||||
|
This class extends the standard model with an
|
||||||
|
extra_data field that can be used to include public,
|
||||||
|
but internal information.
|
||||||
|
|
||||||
|
For instance if you migrate from an existing virtualisation
|
||||||
|
framework to uncloud.
|
||||||
|
|
||||||
|
The extra_data attribute should be considered a hack and whenever
|
||||||
|
data is necessary for running uncloud, it should **not** be stored
|
||||||
|
in there.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
extra_data = JSONField(editable=False, blank=True, null=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
|
@ -19,8 +19,7 @@ from decimal import Decimal
|
||||||
import uncloud_pay.stripe
|
import uncloud_pay.stripe
|
||||||
from uncloud_pay.helpers import beginning_of_month, end_of_month
|
from uncloud_pay.helpers import beginning_of_month, end_of_month
|
||||||
from uncloud import AMOUNT_DECIMALS, AMOUNT_MAX_DIGITS
|
from uncloud import AMOUNT_DECIMALS, AMOUNT_MAX_DIGITS
|
||||||
|
from uncloud.models import UncloudModel
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Used to generate bill due dates.
|
# Used to generate bill due dates.
|
||||||
|
@ -418,6 +417,7 @@ class OrderRecord(models.Model):
|
||||||
|
|
||||||
description = models.TextField()
|
description = models.TextField()
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def recurring_period(self):
|
def recurring_period(self):
|
||||||
return self.order.recurring_period
|
return self.order.recurring_period
|
||||||
|
@ -436,7 +436,7 @@ class OrderRecord(models.Model):
|
||||||
|
|
||||||
# Abstract (= no database representation) class used as parent for products
|
# Abstract (= no database representation) class used as parent for products
|
||||||
# (e.g. uncloud_vm.models.VMProduct).
|
# (e.g. uncloud_vm.models.VMProduct).
|
||||||
class Product(models.Model):
|
class Product(UncloudModel):
|
||||||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||||
owner = models.ForeignKey(get_user_model(),
|
owner = models.ForeignKey(get_user_model(),
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
|
|
50
uncloud/uncloud_vm/migrations/0005_auto_20200321_1058.py
Normal file
50
uncloud/uncloud_vm/migrations/0005_auto_20200321_1058.py
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
# Generated by Django 3.0.3 on 2020-03-21 10:58
|
||||||
|
|
||||||
|
import django.contrib.postgres.fields.jsonb
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('uncloud_vm', '0004_remove_vmproduct_vmid'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='vmdiskimageproduct',
|
||||||
|
name='extra_data',
|
||||||
|
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, editable=False, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='vmdiskproduct',
|
||||||
|
name='extra_data',
|
||||||
|
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, editable=False, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='vmhost',
|
||||||
|
name='extra_data',
|
||||||
|
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, editable=False, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='vmproduct',
|
||||||
|
name='extra_data',
|
||||||
|
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, editable=False, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='vmsnapshotproduct',
|
||||||
|
name='extra_data',
|
||||||
|
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, editable=False, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='vmdiskproduct',
|
||||||
|
name='vm',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='disks', to='uncloud_vm.VMProduct'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='vmsnapshotproduct',
|
||||||
|
name='vm',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='snapshots', to='uncloud_vm.VMProduct'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -3,10 +3,13 @@ import uuid
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
|
||||||
# Uncomment if you override model's clean method
|
# Uncomment if you override model's clean method
|
||||||
# from django.core.exceptions import ValidationError
|
# from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
from uncloud_pay.models import Product, RecurringPeriod
|
from uncloud_pay.models import Product, RecurringPeriod
|
||||||
|
from uncloud.models import UncloudModel
|
||||||
|
|
||||||
import uncloud_pay.models as pay_models
|
import uncloud_pay.models as pay_models
|
||||||
import uncloud_storage.models
|
import uncloud_storage.models
|
||||||
|
|
||||||
|
@ -22,7 +25,7 @@ STATUS_CHOICES = (
|
||||||
STATUS_DEFAULT = 'pending'
|
STATUS_DEFAULT = 'pending'
|
||||||
|
|
||||||
|
|
||||||
class VMHost(models.Model):
|
class VMHost(UncloudModel):
|
||||||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||||
|
|
||||||
# 253 is the maximum DNS name length
|
# 253 is the maximum DNS name length
|
||||||
|
@ -99,7 +102,7 @@ class VMWithOSProduct(VMProduct):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class VMDiskImageProduct(models.Model):
|
class VMDiskImageProduct(UncloudModel):
|
||||||
"""
|
"""
|
||||||
Images are used for cloning/linking.
|
Images are used for cloning/linking.
|
||||||
|
|
||||||
|
@ -138,7 +141,7 @@ class VMDiskImageProduct(models.Model):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class VMDiskProduct(models.Model):
|
class VMDiskProduct(UncloudModel):
|
||||||
"""
|
"""
|
||||||
The VMDiskProduct is attached to a VM.
|
The VMDiskProduct is attached to a VM.
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 3.0.3 on 2020-03-21 10:58
|
||||||
|
|
||||||
|
import django.contrib.postgres.fields.jsonb
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('ungleich_service', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='matrixserviceproduct',
|
||||||
|
name='extra_data',
|
||||||
|
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, editable=False, null=True),
|
||||||
|
),
|
||||||
|
]
|
Loading…
Reference in a new issue