Commit 7e3d9ab5 by Szabolcs Gelencser

Add Azure VM Size model. Implement Azure VM size periodic import.

parent 9f04d2dc
......@@ -61,6 +61,12 @@ celery.conf.update(
'schedule': timedelta(hours=24),
'options': {'queue': 'localhost.man'}
},
'vm.update_azure_vm_sizes': {
'task': 'vm.tasks.local_periodic_tasks.'
'update_azure_vm_sizes',
'schedule': timedelta(hours=24),
'options': {'queue': 'localhost.man'}
},
}
)
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('vm', '0004_auto_20161006_2201'),
]
operations = [
migrations.CreateModel(
name='AzureVirtualMachineSize',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.TextField(verbose_name='name')),
('number_of_cores', models.IntegerField(verbose_name='number of cores')),
('os_disk_size_in_mb', models.IntegerField(verbose_name='os disk size in mb')),
('resource_disk_size_in_mb', models.IntegerField(verbose_name='resource disk size in mb')),
('memory_in_mb', models.IntegerField(verbose_name='memory in mb')),
('max_data_disk_count', models.IntegerField(verbose_name='max data disk count')),
],
options={
'db_table': 'vm_azure_vm_size',
},
),
]
......@@ -19,6 +19,7 @@ from .azure_builtin_template import AzureBuiltinPublisher
from .azure_builtin_template import AzureBuiltinOffer
from .azure_builtin_template import AzureBuiltinSKU
from .azure_builtin_template import AzureBuiltinVersion
from .azure_virtual_machine_size import AzureVirtualMachineSize
__all__ = [
'InstanceActivity', 'BaseResourceConfigModel',
......@@ -26,5 +27,5 @@ __all__ = [
'Instance', 'post_state_changed', 'pre_state_changed', 'InterfaceTemplate',
'Interface', 'Trait', 'Node', 'NodeActivity', 'Lease', 'node_activity',
'pwgen', 'AzureBuiltinPublisher', 'AzureBuiltinOffer', 'AzureBuiltinSKU',
'AzureBuiltinVersion',
'AzureBuiltinVersion', 'AzureVirtualMachineSize',
]
# Copyright 2014 Budapest University of Technology and Economics (BME IK)
#
# This file is part of CIRCLE Cloud.
#
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import, unicode_literals
from django.db import models
from django.utils.translation import ugettext_lazy as _
from logging import getLogger
logger = getLogger(__name__)
class AzureVirtualMachineSize(models.Model):
"""
Azure Virtual Machine size
"""
name = models.TextField(verbose_name=_('name'), unique=True)
number_of_cores = models.IntegerField(
verbose_name=_('number of cores'))
os_disk_size_in_mb = models.IntegerField(
verbose_name=_('os disk size in mb'))
resource_disk_size_in_mb = models.IntegerField(
verbose_name=_('resource disk size in mb'))
memory_in_mb = models.IntegerField(
verbose_name=_('memory in mb'))
max_data_disk_count = models.IntegerField(
verbose_name=_('max data disk count'))
class Meta:
app_label = 'vm'
db_table = 'vm_azure_vm_size'
def __unicode__(self):
return 'azure_vm_size-' + str(self.name)
\ No newline at end of file
......@@ -20,11 +20,13 @@ from os import getenv
from django.utils import timezone
from django.utils.translation import ugettext_noop
from django.core.exceptions import ObjectDoesNotExist
from manager.mancelery import celery
from vm.models import (
Node, Instance, AzureBuiltinPublisher,
AzureBuiltinOffer, AzureBuiltinSKU, AzureBuiltinVersion,
AzureVirtualMachineSize,
)
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.compute import ComputeManagementClient
......@@ -102,6 +104,39 @@ def garbage_collector(timeout=15):
logger.debug("Instance %d didn't expire." % i.pk)
@celery.task(ignore_result=True)
def update_azure_vm_sizes():
logger.info("beginning azure vm size imports")
vm_sizes = compute_client.virtual_machine_sizes.list(
REGION,
)
for vm_size in vm_sizes:
try:
old_vm_size = AzureVirtualMachineSize.objects.get(name=vm_size.name)
old_vm_size.name = vm_size.name
old_vm_size.number_of_cores = vm_size.number_of_cores
old_vm_size.os_disk_size_in_mb = vm_size.os_disk_size_in_mb
old_vm_size.resource_disk_size_in_mb = \
vm_size.resource_disk_size_in_mb
old_vm_size.memory_in_mb = vm_size.memory_in_mb
old_vm_size.max_data_disk_count = vm_size.max_data_disk_count
old_vm_size.save()
except ObjectDoesNotExist:
new_vm_size = AzureVirtualMachineSize(
name = vm_size.name,
number_of_cores = vm_size.number_of_cores,
os_disk_size_in_mb = vm_size.os_disk_size_in_mb,
resource_disk_size_in_mb = vm_size.resource_disk_size_in_mb,
memory_in_mb = vm_size.memory_in_mb,
max_data_disk_count = vm_size.max_data_disk_count,
)
new_vm_size.save()
logger.info("finished importing azure vm sizes")
@celery.task(ignore_result=True)
def update_azure_builtin_templates():
logger.info("beginning azure built-in template imports")
......
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