Commit 7a2d1912 by Szabolcs Gelencser

Add storage profile creation on first datastore save.

parent 797305ce
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('storage', '0002_disk_bus'),
]
operations = [
migrations.AddField(
model_name='datastore',
name='azure_id',
field=models.TextField(null=True, verbose_name='azure id'),
),
]
......@@ -26,13 +26,14 @@ import re
from celery.contrib.abortable import AbortableAsyncResult
from django.db.models import (Model, BooleanField, CharField, DateTimeField,
ForeignKey)
ForeignKey, TextField)
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _, ugettext_noop
from model_utils.models import TimeStampedModel
from sizefield.models import FileSizeField
from django.db.models.signals import post_save
from .tasks import local_tasks, storage_tasks
from celery.exceptions import TimeoutError
......@@ -51,6 +52,7 @@ class DataStore(Model):
path = CharField(max_length=200, unique=True, verbose_name=_('path'))
hostname = CharField(max_length=40, unique=True,
verbose_name=_('hostname'))
azure_id = TextField(verbose_name=_('azure id'), null=True)
class Meta:
ordering = ['name']
......@@ -543,3 +545,20 @@ class Disk(TimeStampedModel):
@property
def is_resizable(self):
return self.type in ('qcow2-norm', 'raw-rw', 'qcow2-snap', )
def save_datastore_sender(sender, instance, created=False, **kwargs):
if not instance.azure_id:
logger.debug(
"Send azure create_azure_storage_profile task.")
azure_id = storage_tasks.create_azure_storage_profile.apply_async(
queue='localhost.storage.fast',
args=[instance.name]).get(timeout=60)
if azure_id:
logger.debug("created storage profile with id: %s" % azure_id)
instance.azure_id = azure_id
instance.save()
else:
logger.error("couldn't create storage profile")
#TODO: implement update
post_save.connect(save_datastore_sender, sender=DataStore)
\ No newline at end of file
......@@ -18,6 +18,10 @@
from manager.mancelery import celery
@celery.task(name='storagedriver.create_azure_storage_profile')
def create_azure_storage_profile(name):
pass
@celery.task(name='storagedriver.list')
def list(dir):
pass
......
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