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 ...@@ -7,7 +7,9 @@ from image.models import Disk
from interface_openstack.implementation.vm.instance import ( from interface_openstack.implementation.vm.instance import (
OSVirtualMachineManager OSVirtualMachineManager
) )
import logging
logger = logging.getLogger(__name__)
ACCESS_METHODS = tuple( ACCESS_METHODS = tuple(
[(key, val[0]) for key, val in settings.VM_ACCESS_PROTOCOLS.items()] [(key, val[0]) for key, val in settings.VM_ACCESS_PROTOCOLS.items()]
...@@ -43,13 +45,17 @@ class Flavor(models.Model): ...@@ -43,13 +45,17 @@ class Flavor(models.Model):
def create(cls, name, description, ram=0, vcpu=0, def create(cls, name, description, ram=0, vcpu=0,
initial_disk=0, priority=0): initial_disk=0, priority=0):
interface = OSVirtualMachineManager(settings.CONNECTION) interface = OSVirtualMachineManager(settings.CONNECTION)
try:
remote_flavor = interface.create_flavor(name, ram, vcpu, initial_disk) remote_flavor = interface.create_flavor(name, ram, vcpu, initial_disk)
flavor = cls(name=name, description=description, flavor = cls(name=name, description=description,
remote_id=remote_flavor.id, ram=ram, vcpu=vcpu, remote_id=remote_flavor.id, ram=ram, vcpu=vcpu,
initial_disk=initial_disk, priority=priority) initial_disk=initial_disk, priority=priority)
flavor.save() flavor.save()
return flavor return flavor
except Exception as e:
logger.error(str(e))
raise ValueError("Couldn't create Flavor in remote cloud.")
class Instance(models.Model): class Instance(models.Model):
...@@ -110,6 +116,7 @@ class Instance(models.Model): ...@@ -110,6 +116,7 @@ class Instance(models.Model):
inst.full_clean() inst.full_clean()
inst.save() inst.save()
logger.info("New instance created")
return inst return inst
@classmethod @classmethod
...@@ -117,6 +124,7 @@ class Instance(models.Model): ...@@ -117,6 +124,7 @@ 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
interface = OSVirtualMachineManager(settings.CONNECTION) interface = OSVirtualMachineManager(settings.CONNECTION)
try:
remote_inst = interface.create_vm_from_template(params["name"], remote_inst = interface.create_vm_from_template(params["name"],
template.remote_ID, template.remote_ID,
flavor.remote_id, flavor.remote_id,
...@@ -124,8 +132,11 @@ class Instance(models.Model): ...@@ -124,8 +132,11 @@ class Instance(models.Model):
) )
remote_id = remote_inst.id remote_id = remote_inst.id
new_inst = cls.create(lease, owner, flavor, remote_id, params) new_inst = cls.create(lease, owner, flavor, remote_id, params)
return new_inst 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): def clean(self, *args, **kwargs):
self.time_of_suspend, self.time_of_delete = self.get_renew_times() 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