Commit edf318bc by Chif Gergő

Add network_id field to template

parent 350011be
...@@ -143,12 +143,11 @@ class Instance(models.Model): ...@@ -143,12 +143,11 @@ class Instance(models.Model):
disks, networks, flavor): disks, networks, flavor):
# TODO: attach disks when the remote instance created # TODO: attach disks when the remote instance created
try: try:
remote_inst = interface.create_vm_from_template(params["name"], remote_id = interface.create_vm_from_template(params["name"],
template.image.remote_id, template.image.remote_id,
flavor.remote_id, flavor.remote_id,
networks, networks,
) )
remote_id = remote_inst.id
new_inst = cls.create(lease, owner, flavor, template, new_inst = cls.create(lease, owner, flavor, template,
remote_id, params) remote_id, params)
return new_inst return new_inst
......
...@@ -45,7 +45,7 @@ class InstanceViewSet(ViewSet): ...@@ -45,7 +45,7 @@ class InstanceViewSet(ViewSet):
"system": data["system"], "system": data["system"],
}, },
lease=template.lease, lease=template.lease,
networks=[{"uuid": "7485b41f-2524-4399-a20b-4b2c7ee9fd01"}], networks=[{"uuid": template.network_id}],
template=template, template=template,
flavor=template.flavor, flavor=template.flavor,
owner=request.user, owner=request.user,
......
# Generated by Django 2.2.3 on 2019-08-07 12:19
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('template', '0006_auto_20190719_1416'),
]
operations = [
migrations.AddField(
model_name='basetemplate',
name='network_id',
field=models.CharField(blank=True, help_text='The new instance will be in this network.', max_length=100, null=True, verbose_name='network_id'),
),
]
...@@ -44,6 +44,13 @@ class BaseTemplate(models.Model): ...@@ -44,6 +44,13 @@ class BaseTemplate(models.Model):
related_name='templates') related_name='templates')
lease = models.ForeignKey(Lease, on_delete="CASCADE", lease = models.ForeignKey(Lease, on_delete="CASCADE",
related_name='templates') related_name='templates')
network_id = models.CharField(
max_length=100,
verbose_name="network_id",
help_text="The new instance will be in this network.",
null=True,
blank=True
)
class DiskTemplate(BaseTemplate): class DiskTemplate(BaseTemplate):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment