Пример #1
0
def details(request, hostname):
    """
    Page with details of server.
    """
    dc_settings = request.dc.settings
    context = collect_view_data(request,
                                'vm_list',
                                mb_addon=SIZE_FIELD_MB_ADDON)
    context['vm'] = vm = get_vm(request,
                                hostname,
                                sr=('dc', 'owner', 'node', 'template',
                                    'slavevm'))
    context['vms'] = vms = get_vms(request)
    context['vms_tags'] = get_vms_tags(vms)
    context['vm_disks'] = vm_disks = get_vm_define_disk(request, vm)
    context['vm_nics'] = vm_nics = get_vm_define_nic(request, vm)
    context['ptrform'] = PTRForm(prefix='ptr')
    context['iso_rescuecd'] = dc_settings.VMS_ISO_RESCUECD
    context['mon_sla_enabled'] = (settings.MON_ZABBIX_ENABLED
                                  and DefaultDc().settings.MON_ZABBIX_ENABLED
                                  and dc_settings.MON_ZABBIX_VM_SLA)
    context['can_edit'] = request.user.is_admin(request)

    if vm.slave_vms:
        context['slave_vm'] = vm.slave_vm.select_related(
            'master_vm', 'vm', 'vm__node').exclude(name='').first()
    else:
        context['slave_vm'] = None

    if vm.is_kvm():
        context['iso_images'] = get_iso_images(request, vm.ostype)

    if vm.ostype == Vm.WINDOWS:
        context[
            'stop_timeout_period'] = dc_settings.VMS_VM_STOP_WIN_TIMEOUT_DEFAULT
    else:
        context[
            'stop_timeout_period'] = dc_settings.VMS_VM_STOP_TIMEOUT_DEFAULT

    if context['can_edit']:
        context['settingsform'] = AdminServerSettingsForm(request,
                                                          vm,
                                                          prefix='opt')

        initial_disk = {
            'disk_id': len(vm_disks) + 1,
            'zpool': vm.zpool,
            'model': dc_settings.VMS_DISK_MODEL_DEFAULT,
            'compression': dc_settings.VMS_DISK_COMPRESSION_DEFAULT,
            'image': dc_settings.VMS_DISK_IMAGE_DEFAULT,
        }
        if initial_disk['disk_id'] == 1:
            initial_disk['boot'] = True

        initial_nic = {
            'nic_id': len(vm_nics) + 1,
            'model': dc_settings.VMS_NIC_MODEL_DEFAULT,
            'net': dc_settings.VMS_NET_DEFAULT,
        }

        if initial_nic['nic_id'] == 1:
            initial_nic['dns'] = True
            initial_nic['primary'] = True

        if initial_nic['nic_id'] == dc_settings.VMS_NIC_MONITORING_DEFAULT:
            initial_nic['monitoring'] = True

        if vm.template:
            initial_disk.update(
                vm.template.get_vm_define_disk(initial_disk['disk_id']))
            initial_nic.update(
                vm.template.get_vm_define_nic(initial_nic['nic_id']))

        context['disk_settingsform'] = AdminServerDiskSettingsForm(
            request, vm, prefix='opt-disk', initial=initial_disk)
        context['nic_settingsform'] = AdminServerNicSettingsForm(
            request, vm, prefix='opt-nic', initial=initial_nic)

    else:
        context['settingsform'] = ServerSettingsForm(request, vm, prefix='opt')
        context['disk_settingsform'] = ServerDiskSettingsForm(
            request, vm, prefix='opt-disk')
        context['nic_settingsform'] = ServerNicSettingsForm(request,
                                                            vm,
                                                            prefix='opt-nic')

    view_vm_details.send(sender='gui.vm.views.details',
                         request=request,
                         context=context)
    return render(request, 'gui/vm/details.html', context)
Пример #2
0
 def _initial_data(self, request, vm):
     return get_vm_define_disk(request, vm, disk_id=int(request.POST['opt-disk-disk_id']) - 1)
Пример #3
0
    def generate_datacenter(self, request, sample=False, hostnames=None):
        row = 3
        row_color = self.even_row

        if sample:
            vms = []
            for i in range(0, 3):
                vms.append(SampleVm(request, number=i + 1))
        else:
            vms = get_vms(request).filter(hostname__in=hostnames)

        for vm in vms:
            # Decide what color row should have
            if row_color == self.even_row:
                row_color = self.odd_row
            else:
                row_color = self.even_row

            nic_row = disk_row = row
            str_row = str(row)
            self.set_row_color(self.sheet_dc, str_row, self.get_header(), bgcolor=row_color)

            # Store datacenter into sheet
            self.sheet_dc[self.get_column_index('Hostname') + str_row] = vm.hostname
            self.sheet_dc[self.get_column_index('Alias') + str_row] = vm.alias
            self.sheet_dc[self.get_column_index('Tags') + str_row] = ','.join([t for t in vm.tags.names()])
            if vm.node:
                if request.user.is_admin(request) and vm.node.hostname:
                    self.sheet_dc[self.get_column_index('Node') + str_row] = vm.node_hostname
                else:
                    self.update_cell(self.sheet_dc, self.get_column_index('Node'), str_row, '',
                                     bgcolor=vm.node.color.replace('#', 'FF'))

            self.sheet_dc[self.get_column_index('OS Type') + str_row] = vm.get_ostype_display()
            self.sheet_dc[self.get_column_index('vCPU') + str_row] = vm.vcpus
            self.sheet_dc[self.get_column_index('RAM') + str_row] = self._convert_to_gb(vm.ram)

            if sample:
                vm_nics = vm.generate_nics()
            else:
                vm_nics = get_vm_define_nic(request, vm)

            for vm_nic in vm_nics:
                if row < nic_row:
                    self.set_row_color(self.sheet_dc, nic_row, self.get_header(), bgcolor=row_color)
                self.sheet_dc[self.get_column_index('Network') + str(nic_row)] = vm_nic['net']
                self.sheet_dc[self.get_column_index('IP') + str(nic_row)] = vm_nic['ip']
                nic_row += 1

            if sample:
                vm_disks = vm.generate_disks()
            else:
                vm_disks = get_vm_define_disk(request, vm)

            for vm_disk in vm_disks:
                if row < disk_row:
                    self.set_row_color(self.sheet_dc, disk_row, self.get_header(), bgcolor=row_color)

                self.sheet_dc[self.get_column_index('Storage') + str(disk_row)] = vm_disk['zpool']
                self.sheet_dc[self.get_column_index('HDD Size') + str(disk_row)] = self._convert_to_gb(vm_disk['size'])
                if vm_disk['image'] is not None:
                    self.sheet_dc[self.get_column_index('Image') + str(disk_row)] = vm_disk['image']
                disk_row += 1

            if disk_row > nic_row:
                row = disk_row
            else:
                row = nic_row