Example #1
0
    def __init__(self, request, slave_vm, *args, **kwargs):
        self.img_required = None
        self.reserve_resources_changed = False
        self._detail_dict = {}

        super(VmReplicaSerializer, self).__init__(request, slave_vm, *args,
                                                  **kwargs)

        if request.method == 'POST':
            vm = slave_vm.vm
            dc_settings = request.dc.settings
            self.fields[
                'reserve_resources'].default = dc_settings.VMS_VM_REPLICA_RESERVATION_DEFAULT
            self.fields['node'].queryset = get_nodes(request, is_compute=True)
            self._disks = vm.json_get_disks()

            if vm.is_hvm():
                self.fields['disk_zpools'].max_items = len(self._disks)
            else:
                del self.fields['disk_zpools']
        else:
            self.fields['node'].required = False
            self.fields['node'].read_only = True
            self.fields['root_zpool'].read_only = True
            self.fields['disk_zpools'].read_only = True
Example #2
0
    def __init__(self, request, vm, *args, **kwargs):
        super(AdminServerSettingsForm, self).__init__(request, vm, *args,
                                                      **kwargs)
        dc_settings = request.dc.settings
        self.is_kvm = is_kvm(vm, self.data, prefix='opt-')
        # Set choices
        self.vm_nodes = get_nodes(request, is_compute=True)
        # TODO: node.color
        self.fields['node'].choices = [('', _('(auto)'))] + [
            (i.hostname, i.hostname) for i in self.vm_nodes
        ]
        self.fields['owner'].choices = get_owners(request).values_list(
            'username', 'username')
        self.fields['zpool'].choices = get_zpools(request).values_list(
            'zpool', 'storage__alias').distinct()

        if not request.user.is_staff:
            self.fields['cpu_shares'].widget.attrs['disabled'] = 'disabled'
            self.fields['cpu_shares'].widget.attrs[
                'class'] += ' uneditable-input'
            self.fields['zfs_io_priority'].widget.attrs[
                'disabled'] = 'disabled'
            self.fields['zfs_io_priority'].widget.attrs[
                'class'] += ' uneditable-input'

        if dc_settings.MON_ZABBIX_TEMPLATES_VM_RESTRICT:
            self.fields[
                'monitoring_templates'].widget.tag_choices = dc_settings.MON_ZABBIX_TEMPLATES_VM_ALLOWED

        if dc_settings.MON_ZABBIX_HOSTGROUPS_VM_RESTRICT:
            self.fields[
                'monitoring_hostgroups'].widget.tag_choices = dc_settings.MON_ZABBIX_HOSTGROUPS_VM_ALLOWED

        if vm:
            empty_template_data = {}
            self.fields['ostype'].widget.attrs['disabled'] = 'disabled'
            if vm.is_deployed():
                self.fields['node'].widget.attrs[
                    'class'] += ' disable_created2'
                self.fields['zpool'].widget.attrs[
                    'class'] += ' disable_created2'
        else:
            empty_template_data = self.initial
            ostype = Vm.OSTYPE

            # Disable zone support _only_ when adding new VM (zone must be available in edit mode) - Issue #chili-461
            if not dc_settings.VMS_ZONE_ENABLED:
                # Remove SunOS Zone support
                ostype = [i for i in ostype if i[0] not in Vm.ZONE]

            self.fields['ostype'].choices = ostype

        empty_template = AttrDict({
            'alias': _('(none)'),
            'desc': '',
            'web_data': empty_template_data
        })
        self.fields['template'].choices = [('', empty_template)] + [
            (i.name, i) for i in get_templates(request)
        ]
Example #3
0
 def __init__(self, request, vm, slave_vm, *args, **kwargs):
     self.slave_vm = slave_vm
     vm_nodes = kwargs.pop('vm_nodes', None)
     super(ServerReplicaForm, self).__init__(request, vm, *args, **kwargs)
     if not vm_nodes:
         vm_nodes = get_nodes(request, is_compute=True)
     self.fields['node'].choices = [(i.hostname, i.hostname)
                                    for i in vm_nodes]
Example #4
0
 def __init__(self, request, vm, *args, **kwargs):
     super(BackupDefineForm, self).__init__(request, vm, *args, **kwargs)
     self.fields['retention'].help_text = _(
         'Maximum number of backups to keep.')
     self.fields['node'].choices = get_nodes(request,
                                             is_backup=True).values_list(
                                                 'hostname', 'hostname')
     self.fields['zpool'].choices = get_zpools(request).filter(node__is_backup=True) \
         .values_list('zpool', 'storage__alias').distinct()
Example #5
0
    def generate_nodes(self, column_index, row_index=1, label='Node', color=False):
        self.update_cell(self.sheet_data, column_index, row_index, label, color=self.header_color,
                         bgcolor=self.header_bgcolor)

        for row_index, node in enumerate(get_nodes(self.request), start=row_index + 1):
            if color:
                self.update_cell(self.sheet_data, column_index, row_index, None, color=node.color.replace('#', 'FF'))
            else:
                self.update_cell(self.sheet_data, column_index, row_index, node.hostname)

        self.add_validation(column_index, row_index, self.get_column_index(label))
Example #6
0
    def __init__(self, request, vm, *args, **kwargs):
        self.img_required = None
        self.request = request
        self.vm = vm

        super(VmMigrateSerializer, self).__init__(*args, **kwargs)
        self.fields['node'].queryset = get_nodes(request, is_compute=True)
        self._disks = vm.json_active_get_disks()

        if vm.is_kvm():
            self.fields['disk_zpools'].max_items = len(self._disks)
        else:
            del self.fields['disk_zpools']
Example #7
0
    def __init__(self, request, instance, *args, **kwargs):
        vm_template = kwargs.pop('vm_template', False)
        self._update_fields_ = list(self._update_fields_)
        super(BackupDefineSerializer, self).__init__(request, instance, *args,
                                                     **kwargs)

        if not kwargs.get('many', False):
            dc_settings = request.dc.settings
            backup_nodes = get_nodes(request, is_backup=True)
            self.fields['node'].queryset = backup_nodes
            self.fields['zpool'].default = dc_settings.VMS_STORAGE_DEFAULT
            self.fields[
                'compression'].default = dc_settings.VMS_VM_BACKUP_COMPRESSION_DEFAULT

            # Set first backup node and backup node storage available in DC
            # (used only when called by VmDefineBackup.create_from_template())
            if vm_template:
                try:
                    self.fields['node'].default = first_node = backup_nodes[0]
                except IndexError:
                    pass
                else:
                    first_node_zpools = get_zpools(request).filter(
                        node=first_node).values_list('zpool', flat=True)

                    if first_node_zpools and dc_settings.VMS_STORAGE_DEFAULT not in first_node_zpools:
                        self.fields['zpool'].default = first_node_zpools[0]

            if request.method != 'POST':
                self.fields['type'].read_only = True

            # Limit maximum number of backups - Issue #chili-447
            if dc_settings.VMS_VM_BACKUP_LIMIT is None:
                min_count, max_count = RETENTION_MIN, RETENTION_MAX
            else:
                min_count, max_count = 1, int(dc_settings.VMS_VM_BACKUP_LIMIT)
            self.fields['retention'].validators.append(
                validators.MinValueValidator(min_count))
            self.fields['retention'].validators.append(
                validators.MaxValueValidator(max_count))

            if instance.vm.is_kvm():
                self._update_fields_.append('fsfreeze')