示例#1
0
    def __init__(self, request, obj, *args, **kwargs):
        self._disable_globals = kwargs.pop('disable_globals', False)

        self.table = kwargs.pop('table', False)
        if self.table:
            self._field_text_class = ''

        super(DcSettingsForm, self).__init__(request, obj, *args, **kwargs)

        from pdns.models import Domain
        self.fields['VMS_VM_DOMAIN_DEFAULT'].choices = Domain.objects.exclude(Domain.QServerExclude)\
            .values_list('name', 'name').order_by('name')
        self.fields['VMS_DISK_IMAGE_DEFAULT'].choices = [
            ('', _('(none)'))
        ] + list(
            get_images(request, ostype=None).values_list('name', 'alias'))
        self.fields['VMS_DISK_IMAGE_ZONE_DEFAULT'].choices = list(
            get_images(request,
                       ostype=Image.SUNOS_ZONE).values_list('name', 'alias'))
        self.fields['VMS_DISK_IMAGE_LX_ZONE_DEFAULT'].choices = list(
            get_images(request,
                       ostype=Image.LINUX_ZONE).values_list('name', 'alias'))
        self.fields['VMS_NET_DEFAULT'].choices = get_subnets(
            request).values_list('name', 'alias')
        self.fields['VMS_STORAGE_DEFAULT'].choices = get_zpools(request).values_list('zpool', 'storage__alias')\
                                                                        .distinct()
        self.fields['VMS_VM_SNAPSHOT_SIZE_LIMIT'].addon = ' MB'
        self.fields['VMS_VM_SNAPSHOT_SIZE_LIMIT_DEFAULT'].addon = ' MB'
        self.fields['VMS_VM_SNAPSHOT_DC_SIZE_LIMIT'].addon = ' MB'
        self.fields['VMS_VM_BACKUP_DC_SIZE_LIMIT'].addon = ' MB'
示例#2
0
    def __init__(self, request, vm, *args, **kwargs):
        super(AdminServerDiskSettingsForm, self).__init__(request, vm, *args, **kwargs)
        if vm.is_deployed():
            self.fields['image'].widget.attrs['disabled'] = 'disabled'
            self.fields['zpool'].widget.attrs['class'] += ' disable_created2'
            # Bug #chili-625
            img_inc = [disk['image_uuid'] for disk in vm.json_active_get_disks() if 'image_uuid' in disk]
        else:
            img_inc = None

        if vm.is_kvm():
            images = [('', _('(none)'))]
            self.max_disks = DISK_ID_MAX
            self.fields['zpool'].help_text = _('Setting first disk storage to different value than '
                                               'server settings storage (%s) is not recommended.') % vm.zpool
        else:
            del self.fields['boot']
            self.fields['size'].required = False
            images = []
            if vm.is_deployed():
                self.max_disks = 0  # Disable creating of new disks if zone is deployed
            else:
                self.max_disks = DISK_ID_MAX_OS

        images.extend([(i.name, i) for i in get_images(request, ostype=vm.ostype, include=img_inc)])
        self.fields['image'].choices = images
        self.fields['zpool'].choices = get_zpools(request).values_list('zpool', 'storage__alias').distinct()
示例#3
0
    def generate_images(self, column_index, row_index=1, label='Image'):
        self.update_cell(self.sheet_data, column_index, row_index, label, color=self.header_color,
                         bgcolor=self.header_bgcolor)

        for row_index, image in enumerate(get_images(self.request), start=row_index + 1):
            self.update_cell(self.sheet_data, column_index, row_index, image.name)

        self.add_validation(column_index, row_index, self.get_column_index(label))
示例#4
0
    def generate_disks(self):
        disks = []
        images = get_images(self.request, ostype=1)
        zpools = get_zpools(self.request).distinct('zpool')
        for i in range(0, random.randint(1, 2)):
            if len(zpools) > 0:
                random_zpool = random.randint(0, len(zpools) - 1)
                zpool = zpools[random_zpool].zpool
            else:
                zpool = ''

            disk = {
                'zpool': zpool,
                'size': random.choice((10245, 15365, 20485, 25605)),
                'image': '',
            }

            if i == 0 and len(images) > 0:
                random_image = random.randint(0, len(images) - 1)
                disk['image'] = images[random_image].name

            disks.append(disk)

        return disks