vm template prefix
This commit is contained in:
parent
cba53e0fe3
commit
a4ca17e2ed
6 changed files with 58 additions and 10 deletions
|
@ -2,7 +2,7 @@ from django.contrib import admin
|
||||||
from cms.admin.placeholderadmin import PlaceholderAdminMixin
|
from cms.admin.placeholderadmin import PlaceholderAdminMixin
|
||||||
from cms.extensions import PageExtensionAdmin
|
from cms.extensions import PageExtensionAdmin
|
||||||
from .cms_models import CMSIntegration, CMSFaviconExtension
|
from .cms_models import CMSIntegration, CMSFaviconExtension
|
||||||
from .models import VMPricing
|
from .models import VMPricing, VMTemplate
|
||||||
|
|
||||||
|
|
||||||
class CMSIntegrationAdmin(PlaceholderAdminMixin, admin.ModelAdmin):
|
class CMSIntegrationAdmin(PlaceholderAdminMixin, admin.ModelAdmin):
|
||||||
|
@ -16,3 +16,4 @@ class CMSFaviconExtensionAdmin(PageExtensionAdmin):
|
||||||
admin.site.register(CMSIntegration, CMSIntegrationAdmin)
|
admin.site.register(CMSIntegration, CMSIntegrationAdmin)
|
||||||
admin.site.register(CMSFaviconExtension, CMSFaviconExtensionAdmin)
|
admin.site.register(CMSFaviconExtension, CMSFaviconExtensionAdmin)
|
||||||
admin.site.register(VMPricing)
|
admin.site.register(VMPricing)
|
||||||
|
admin.site.register(VMTemplate)
|
||||||
|
|
|
@ -9,7 +9,7 @@ from djangocms_text_ckeditor.fields import HTMLField
|
||||||
from filer.fields.file import FilerFileField
|
from filer.fields.file import FilerFileField
|
||||||
from filer.fields.image import FilerImageField
|
from filer.fields.image import FilerImageField
|
||||||
|
|
||||||
from datacenterlight.models import VMPricing
|
from datacenterlight.models import VMPricing, VMTemplate
|
||||||
|
|
||||||
|
|
||||||
class CMSIntegration(models.Model):
|
class CMSIntegration(models.Model):
|
||||||
|
@ -299,3 +299,7 @@ class DCLCalculatorPluginModel(CMSPlugin):
|
||||||
help_text='Choose a pricing that will be associated with this '
|
help_text='Choose a pricing that will be associated with this '
|
||||||
'Calculator'
|
'Calculator'
|
||||||
)
|
)
|
||||||
|
vm_type = models.CharField(
|
||||||
|
max_length=50, choices=VMTemplate.VM_TYPE_CHOICES,
|
||||||
|
default=VMTemplate.PUBLIC
|
||||||
|
)
|
||||||
|
|
|
@ -88,7 +88,9 @@ class DCLCalculatorPlugin(CMSPluginBase):
|
||||||
context = super(DCLCalculatorPlugin, self).render(
|
context = super(DCLCalculatorPlugin, self).render(
|
||||||
context, instance, placeholder
|
context, instance, placeholder
|
||||||
)
|
)
|
||||||
context['templates'] = VMTemplate.objects.all()
|
context['templates'] = VMTemplate.objects.filter(
|
||||||
|
vm_type=instance.vm_type
|
||||||
|
)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
|
25
datacenterlight/migrations/0023_auto_20180524_0349.py
Normal file
25
datacenterlight/migrations/0023_auto_20180524_0349.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.9.4 on 2018-05-23 22:19
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('datacenterlight', '0022_auto_20180506_1950'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='dclcalculatorpluginmodel',
|
||||||
|
name='vm_type',
|
||||||
|
field=models.CharField(choices=[('public', 'Public'), ('ipv6only', 'Ipv6Only')], default='public', max_length=50),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='vmtemplate',
|
||||||
|
name='vm_type',
|
||||||
|
field=models.CharField(choices=[('public', 'Public'), ('ipv6only', 'Ipv6Only')], default='public', max_length=50),
|
||||||
|
),
|
||||||
|
]
|
|
@ -6,13 +6,29 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class VMTemplate(models.Model):
|
class VMTemplate(models.Model):
|
||||||
|
PUBLIC = 'public'
|
||||||
|
IPV6 = 'ipv6only'
|
||||||
|
VM_TYPE_CHOICES = (
|
||||||
|
(PUBLIC, PUBLIC.title()),
|
||||||
|
(IPV6, IPV6.title()),
|
||||||
|
)
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
opennebula_vm_template_id = models.IntegerField()
|
opennebula_vm_template_id = models.IntegerField()
|
||||||
|
vm_type = models.CharField(
|
||||||
|
max_length=50, choices=VM_TYPE_CHOICES, default=PUBLIC
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return '%s - %s - %s' % (
|
||||||
|
self.opennebula_vm_template_id, self.vm_type, self.name
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, name, opennebula_vm_template_id):
|
def create(cls, name, opennebula_vm_template_id, vm_type):
|
||||||
vm_template = cls(
|
vm_template = cls(
|
||||||
name=name, opennebula_vm_template_id=opennebula_vm_template_id)
|
name=name, opennebula_vm_template_id=opennebula_vm_template_id,
|
||||||
|
vm_type=vm_type
|
||||||
|
)
|
||||||
return vm_template
|
return vm_template
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ class OpenNebulaManager():
|
||||||
domain=settings.OPENNEBULA_DOMAIN,
|
domain=settings.OPENNEBULA_DOMAIN,
|
||||||
port=settings.OPENNEBULA_PORT,
|
port=settings.OPENNEBULA_PORT,
|
||||||
endpoint=settings.OPENNEBULA_ENDPOINT
|
endpoint=settings.OPENNEBULA_ENDPOINT
|
||||||
))
|
))
|
||||||
|
|
||||||
def _get_opennebula_client(self, username, password):
|
def _get_opennebula_client(self, username, password):
|
||||||
return oca.Client("{0}:{1}".format(
|
return oca.Client("{0}:{1}".format(
|
||||||
|
@ -73,7 +73,7 @@ class OpenNebulaManager():
|
||||||
domain=settings.OPENNEBULA_DOMAIN,
|
domain=settings.OPENNEBULA_DOMAIN,
|
||||||
port=settings.OPENNEBULA_PORT,
|
port=settings.OPENNEBULA_PORT,
|
||||||
endpoint=settings.OPENNEBULA_ENDPOINT
|
endpoint=settings.OPENNEBULA_ENDPOINT
|
||||||
))
|
))
|
||||||
|
|
||||||
def _get_user(self, user):
|
def _get_user(self, user):
|
||||||
"""Get the corresponding opennebula user for a CustomUser object
|
"""Get the corresponding opennebula user for a CustomUser object
|
||||||
|
@ -362,12 +362,12 @@ class OpenNebulaManager():
|
||||||
except:
|
except:
|
||||||
raise ConnectionRefusedError
|
raise ConnectionRefusedError
|
||||||
|
|
||||||
def get_templates(self):
|
def get_templates(self, prefix='public-'):
|
||||||
try:
|
try:
|
||||||
public_templates = [
|
public_templates = [
|
||||||
template
|
template
|
||||||
for template in self._get_template_pool()
|
for template in self._get_template_pool()
|
||||||
if template.name.startswith('public-')
|
if template.name.startswith(prefix)
|
||||||
]
|
]
|
||||||
return public_templates
|
return public_templates
|
||||||
except ConnectionRefusedError:
|
except ConnectionRefusedError:
|
||||||
|
@ -439,7 +439,7 @@ class OpenNebulaManager():
|
||||||
|
|
||||||
def delete_template(self, template_id):
|
def delete_template(self, template_id):
|
||||||
self.oneadmin_client.call(oca.VmTemplate.METHODS[
|
self.oneadmin_client.call(oca.VmTemplate.METHODS[
|
||||||
'delete'], template_id, False)
|
'delete'], template_id, False)
|
||||||
|
|
||||||
def change_user_password(self, passwd_hash):
|
def change_user_password(self, passwd_hash):
|
||||||
self.oneadmin_client.call(
|
self.oneadmin_client.call(
|
||||||
|
|
Loading…
Reference in a new issue