Commit e837067b by Karsa Zoltán István

cloud init beta

parent 325a7ee9
......@@ -169,14 +169,6 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
networks=networks,
tags=tags, req_traits=req_traits)
if post['cloud_init']:
disk = Disk.create_ci_disk(meta_data=post['ci_meta_data'], user_data=post['ci_user_data'], user=request.user)
disk.full_clean()
disk.save()
inst.disks.add(disk)
inst._attach_disk(disk=disk)
return HttpResponseRedirect("%s#resources" %
inst.get_absolute_url())
......
......@@ -450,14 +450,17 @@ class Disk(TimeStampedModel):
@classmethod
def create_ci_disk(cls, meta_data, user_data, user = None, **params):
params.setdefault('name', 'ci-disk')
params.setdefault('type', 'iso')
params.setdefault('size', 200)
params.setdefault('type', 'raw-ro')
params.setdefault('size', None)
disk = cls.__create(params=params, user=user)
queue_name = disk.get_remote_queue_name('storage', priority="fast")
disk_desc = disk.get_disk_desc()
storage_tasks.create_ci_disk.apply_async(args=[disk_desc, user_data, meta_data],
result = storage_tasks.create_ci_disk.apply_async(args=[disk_desc, meta_data, user_data],
queue=queue_name
).get(timeout=15)
disk.size = result['size']
disk.type = 'raw-ro'
disk.checksum = result['checksum']
disk.is_ready = True
disk.save()
return disk
......
# Generated by Django 3.2.3 on 2022-07-21 07:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('vm', '0007_auto_20220720_1312'),
]
operations = [
migrations.AlterField(
model_name='instance',
name='cloud_init',
field=models.BooleanField(default=False, help_text='VM use cloud-init, set user- and meta-data below', verbose_name='Use Cloud-init'),
),
migrations.AlterField(
model_name='instancetemplate',
name='cloud_init',
field=models.BooleanField(default=False, help_text='VM use cloud-init, set user- and meta-data below', verbose_name='Use Cloud-init'),
),
]
# Generated by Django 3.2.3 on 2022-07-21 11:18
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('vm', '0008_auto_20220721_0756'),
]
operations = [
migrations.AlterField(
model_name='instance',
name='ci_meta_data',
field=models.TextField(blank=True, default='empty', help_text='When cloud-init is active, set meta-data (YAML format)', verbose_name='ci_meta_data'),
),
migrations.AlterField(
model_name='instance',
name='ci_user_data',
field=models.TextField(blank=True, default='empty', help_text='When cloud-init is active, set user-data (YAML format)', verbose_name='ci_user_data'),
),
migrations.AlterField(
model_name='instancetemplate',
name='ci_meta_data',
field=models.TextField(blank=True, default='empty', help_text='When cloud-init is active, set meta-data (YAML format)', verbose_name='ci_meta_data'),
),
migrations.AlterField(
model_name='instancetemplate',
name='ci_user_data',
field=models.TextField(blank=True, default='empty', help_text='When cloud-init is active, set user-data (YAML format)', verbose_name='ci_user_data'),
),
]
......@@ -117,9 +117,9 @@ class VirtualMachineDescModel(BaseResourceConfigModel):
help_text=_(
'VM use cloud-init, set user- and meta-data below'))
ci_meta_data = TextField(verbose_name=_('ci_meta_data'), blank=True, help_text=_(
'When cloud-init is active, set meta-data (YAML format)'))
'When cloud-init is active, set meta-data (YAML format)'), default='empty')
ci_user_data = TextField(verbose_name=_('ci_user_data'), blank=True, help_text=_(
'When cloud-init is active, set user-data (YAML format)'))
'When cloud-init is active, set user-data (YAML format)'), default='empty')
req_traits = ManyToManyField(Trait, blank=True,
help_text=_("A set of traits required for a "
"node to declare to be suitable "
......
......@@ -21,6 +21,7 @@ from io import StringIO
from base64 import encodestring
from hashlib import md5
from logging import getLogger
import logging
from string import ascii_lowercase
from tarfile import TarFile, TarInfo
from urllib.parse import urlsplit
......@@ -435,6 +436,9 @@ class DeployOperation(InstanceOperation):
else:
self.instance.allocate_node()
if self.instance.cloud_init:
self.instance._create_ci_image(parent_activity=activity)
# Deploy virtual images
try:
self.instance._deploy_disks(parent_activity=activity)
......@@ -482,6 +486,22 @@ class DeployOperation(InstanceOperation):
ugettext_noop("deploy vm to %(node)s"),
node=self.instance.node)
@register_operation
class CreateCloudInitImage(SubOperationMixin, InstanceOperation):
id = "_create_ci_image"
name = _("create cloud-init image")
description = _("create cloud init iso from user and meta-data")
acl_level = "owner"
def _operation(self, user, activity, name=None):
logger.info('create ci image')
disk = Disk.create_ci_disk(meta_data=self.instance.ci_meta_data,
user_data=self.instance.ci_user_data)
disk.full_clean()
disk.save()
self.instance.disks.add(disk)
# self.instance._attach_disk(disk=disk, parent_activity=activity)
@register_operation
class DeployDisksOperation(SubOperationMixin, InstanceOperation):
id = "_deploy_disks"
......@@ -815,7 +835,11 @@ class SaveAsTemplateOperation(InstanceOperation):
'ram_size': self.instance.ram_size,
'raw_data': self.instance.raw_data,
'system': self.instance.system,
'cloud_init': self.instance.cloud_init,
'ci_meta_data': self.instance.ci_meta_data,
'ci_user_data': self.instance.ci_user_data,
}
print(params)
params.update(kwargs)
params.pop("parent_activity", None)
......
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