Commit ccb52b46 by Chif Gergő

instance: Import logging, handle eexceptions

parent 2772d615
Pipeline #780 failed with stages
in 2 minutes 16 seconds
# Generated by Django 2.2.3 on 2019-07-15 09:29
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('instance', '0008_auto_20190704_1310'),
]
operations = [
migrations.AlterField(
model_name='instance',
name='flavor',
field=models.ForeignKey(help_text='Reasources given to the vm', on_delete='CASCADE', related_name='instances', to='instance.Flavor', verbose_name='flavor'),
),
migrations.AlterField(
model_name='instance',
name='lease',
field=models.ForeignKey(on_delete='CASCADE', related_name='instances', to='instance.Lease'),
),
]
......@@ -7,7 +7,9 @@ from image.models import Disk
from interface_openstack.implementation.vm.instance import (
OSVirtualMachineManager
)
import logging
logger = logging.getLogger(__name__)
ACCESS_METHODS = tuple(
[(key, val[0]) for key, val in settings.VM_ACCESS_PROTOCOLS.items()]
......@@ -43,13 +45,17 @@ class Flavor(models.Model):
def create(cls, name, description, ram=0, vcpu=0,
initial_disk=0, priority=0):
interface = OSVirtualMachineManager(settings.CONNECTION)
remote_flavor = interface.create_flavor(name, ram, vcpu, initial_disk)
flavor = cls(name=name, description=description,
remote_id=remote_flavor.id, ram=ram, vcpu=vcpu,
initial_disk=initial_disk, priority=priority)
flavor.save()
try:
remote_flavor = interface.create_flavor(name, ram, vcpu, initial_disk)
return flavor
flavor = cls(name=name, description=description,
remote_id=remote_flavor.id, ram=ram, vcpu=vcpu,
initial_disk=initial_disk, priority=priority)
flavor.save()
return flavor
except Exception as e:
logger.error(str(e))
raise ValueError("Couldn't create Flavor in remote cloud.")
class Instance(models.Model):
......@@ -110,6 +116,7 @@ class Instance(models.Model):
inst.full_clean()
inst.save()
logger.info("New instance created")
return inst
@classmethod
......@@ -117,15 +124,19 @@ class Instance(models.Model):
disks, networks, flavor):
# TODO: attach disks when the remote instance created
interface = OSVirtualMachineManager(settings.CONNECTION)
remote_inst = interface.create_vm_from_template(params["name"],
template.remote_ID,
flavor.remote_id,
networks,
)
remote_id = remote_inst.id
new_inst = cls.create(lease, owner, flavor, remote_id, params)
return new_inst
try:
remote_inst = interface.create_vm_from_template(params["name"],
template.remote_ID,
flavor.remote_id,
networks,
)
remote_id = remote_inst.id
new_inst = cls.create(lease, owner, flavor, remote_id, params)
return new_inst
except Exception as e:
logger.error(str(e))
raise ValueError("Couldn't create Flavor in remote cloud."
"Search the logs for more detail.")
def clean(self, *args, **kwargs):
self.time_of_suspend, self.time_of_delete = self.get_renew_times()
......
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