def maintenance(request): """ System maintenance. """ context = collect_view_data(request, 'system_maintenance') context['system'] = call_api_view(request, 'GET', system_version).data.get('result', {}) context['node_list'] = Node.all() context['current_view'] = 'maintenance' context['status_form'] = NodeStatusForm(request, None) context['update_form'] = UpdateForm(request, None) context['node_update_form'] = NodeUpdateForm(request, None, prefix='node') return render(request, 'gui/system/maintenance.html', context)
def console(request, hostname): """ Page with remote VNC console of the server. """ context = collect_view_data(request, 'vm_list') context['vm'] = get_vm(request, hostname) context['vms'] = vms = get_vms(request) context['vms_tags'] = get_vms_tags(vms) context['can_edit'] = request.user.is_admin(request) view_vm_console.send(sender='gui.vm.views.console', request=request, context=context) return render(request, 'gui/vm/console.html', context)
def faq(request): """ Frequently Asked Questions view. """ dc_settings = request.dc.settings context = collect_view_data(request, 'faq') context['support_email'] = dc_settings.SUPPORT_EMAIL if dc_settings.SUPPORT_ENABLED: context['support_section_url'] = resolve_url('add_ticket') else: context['support_section_url'] = '#' view_faq.send(sender='faq', request=request, context=context) return render(request, 'gui/docs/faq.html', context)
def my_list(request): """ Page with list of all servers that were created by user. """ context = collect_view_data(request, 'vm_list') context['vms'] = vms = get_vms(request) context['vms_tags'] = get_vms_tags(vms) context['can_edit'] = request.user.is_admin(request) context['vms_node_online'] = not Vm.objects.filter(dc=request.dc, node__isnull=False)\ .exclude(node__status=Node.ONLINE)\ .exists() context[ 'stop_timeout_period'] = request.dc.settings.VMS_VM_STOP_TIMEOUT_DEFAULT return render(request, 'gui/vm/list.html', context)
def tasklog(request, hostname): """ Compute node related tasklog. """ context = collect_view_data(request, 'node_list') context['node'] = node = get_node(request, hostname) context['nodes'] = (node,) context['submenu_auto'] = '' nss = node.nodestorage_set.all().extra(select={'strid': 'CAST(id AS text)'}).values_list('strid', flat=True) log_query = ((Q(content_type=node.get_content_type()) & Q(object_pk=node.pk)) | (Q(content_type=NodeStorage.get_content_type()) & Q(object_pk__in=nss))) log = get_tasklog(request, context=context, base_query=log_query, filter_by_permissions=False) context['tasklog'] = context['pager'] = tasklog_items = get_pager(request, log, per_page=100) TaskLogEntry.prepare_queryset(tasklog_items) return render(request, 'gui/node/tasklog.html', context)
def tasklog(request, hostname): """ Page with server related tasklog. """ context = collect_view_data(request, 'vm_list') context['vm'] = vm = get_vm(request, hostname) context['vms'] = (vm,) context['submenu_auto'] = '' context['vms_tag_filter_disabled'] = True log_query = Q(content_type=ContentType.objects.get_for_model(vm)) & Q(object_pk=vm.pk) log = get_tasklog(request, context, base_query=log_query) context['tasklog'] = context['pager'] = get_pager(request, log, per_page=100) context['can_edit'] = request.user.is_admin(request) view_vm_tasklog.send(sender='gui.vm.views.tasklog', request=request, context=context) return render(request, 'gui/vm/tasklog.html', context)
def dc_user_profile(request, username): """ User Profile management. """ user = get_edited_user(request, username, sr=('dc_bound', 'userprofile')) profile = user.userprofile context = collect_view_data(request, 'dc_user_list') context['uform'] = AdminUserForm(request, user, init=True) context['upform'] = AdminUserProfileForm(request, profile, init=True) context['pform'] = AdminChangePasswordForm(user) context['sform'] = SSHKeyForm(request, user) context['user'] = user context['profile'] = profile context['ssh_keys'] = user.usersshkey_set.all().order_by('id') if not request.user.is_staff: context['disabled_api_key'] = True return render(request, 'gui/dc/profile/user_profile.html', context)
def index(request): """ User profile page. """ user = request.user profile = user.userprofile context = collect_view_data(request, 'profile') context['user'] = user context['profile'] = profile context['uform'] = UserForm(request, request.user, init=True) context['upform'] = UserProfileForm(request, profile, init=True) context['pform'] = ChangePasswordForm(request.user) context['sform'] = SSHKeyForm(request, request.user) context['ssh_keys'] = request.user.usersshkey_set.all().order_by('id') context['email_aform'] = EmailActivationProfileForm(profile.email_token) context['phone_aform'] = PhoneActivationProfileForm(profile.phone_token) return render(request, 'gui/profile/profile.html', context)
def dc_domain_list(request): """ DNS Domain/Record <-> Dc management. """ user = request.user domains = Domain.objects.order_by('name') dc_domain_ids = list(request.dc.domaindc_set.values_list('domain_id', flat=True)) context = collect_view_data(request, 'dc_domain_list') context['is_staff'] = is_staff = user.is_staff context['can_edit'] = can_edit = is_staff or user.has_permission(request, DnsAdminPermission.name) context['all'] = _all = is_staff and request.GET.get('all', False) context['deleted'] = _deleted = can_edit and request.GET.get('deleted', False) qs = get_query_string(request, all=_all, deleted=_deleted) qs.pop('domain', None) context['qs'] = qs = qs.urlencode() if _deleted: domains = domains.exclude(access=Domain.INTERNAL) else: domains = domains.exclude(access__in=Domain.INVISIBLE) if can_edit: domains = domains.annotate(records=Count('record', distinct=True)) if _all: context['domains'] = prefetch_domain_dcs(prefetch_domain_owner(domains)) else: context['domains'] = prefetch_domain_owner(domains.filter(id__in=dc_domain_ids)) if is_staff: if _all: # Uses set() because of optimized membership ("in") checking context['can_add'] = set(Domain.objects.exclude(id__in=dc_domain_ids).values_list('id', flat=True)) else: context['can_add'] = Domain.objects.exclude(id__in=dc_domain_ids).count() # Only SuperAdmins can create and edit domains context['form_dc'] = DcDomainForm(request, domains) context['form_admin'] = AdminDomainForm(request, None, prefix='adm', initial={'owner': user.username, 'access': Domain.PRIVATE, 'dc_bound': not is_staff}) context['url_form_dc'] = reverse('dc_domain_form', query_string=qs) context['url_form_admin'] = reverse('admin_domain_form', query_string=qs) return render(request, 'gui/dc/domain_list.html', context)
def alert_list(request): context = collect_view_data(request, 'mon_alert_list') data = request.GET.copy() data.pop('_', None) if not data and request.user.is_staff and request.dc.is_default(): data['show_nodes'] = True context['filters'] = form = BaseAlertFilterForm(request, data) context['init'] = True if form.is_valid( ) and form.api_data is not None: # new visit, or form submission context['alert_filter'] = form.api_data context['alert_filter_ok'] = True else: context['alert_filter_ok'] = False # Do not run javascript API TASKs! return render(request, 'gui/mon/alert_list.html', context)
def overview(request): """ Overview/stats of the whole system. """ context = collect_view_data(request, 'system_overview') context['stats'] = stats = SystemStatsView.get_stats() stats['dcs'] = [ GraphItem(label, data) for label, data in stats['dcs'].items() ] stats['nodes'] = [ GraphItem(label, data, color=NODE_STATS_COLORS[label]) for label, data in stats['nodes'].items() ] stats['vms'] = [ GraphItem(label, data, color=VM_STATS_COLORS[label]) for label, data in stats['vms'].items() ] return render(request, 'gui/system/overview.html', context)
def dc_group_list(request): """ Group -> Dc group management. """ user, dc = request.user, request.dc groups = Role.objects.order_by('name') context = collect_view_data(request, 'dc_group_list') context['is_staff'] = is_staff = user.is_staff context[ 'can_edit'] = can_edit = is_staff # No permission for edit (only staff) as other might promote himself context['all'] = _all = can_edit and request.GET.get('all', False) context['qs'] = qs = get_query_string( request, all=_all, ).urlencode() if _all: context['colspan'] = 5 context['groups'] = Role.objects.select_related('dc_bound').all()\ .prefetch_related('user_set', 'permissions', 'dc_set').order_by('name') else: context['colspan'] = 4 context['groups'] = dc.roles.select_related('dc_bound').all()\ .prefetch_related('user_set', 'permissions', 'dc_set').order_by('name') if can_edit: if _all: # Uses set() because of optimized membership ("in") checking context['can_add'] = set( groups.exclude(dc=dc).values_list('pk', flat=True)) else: # No need for item list context['can_add'] = groups.exclude(dc=dc).count() context['url_form_admin'] = reverse('admin_group_form', query_string=qs) context['form_admin'] = AdminGroupForm(request, None, prefix='adm', initial={'dc_bound': True}) context['form_dc'] = DcGroupForm(request, groups) context['url_form_dc'] = reverse('dc_group_form', query_string=qs) return render(request, 'gui/dc/group_list.html', context)
def alert_list_table(request): context = collect_view_data(request, 'mon_alert_list') try: api_data = json.loads(request.POST.get('alert_filter', None)) except (ValueError, TypeError): context['error'] = 'Unexpected error: could not parse alert filter.' else: context['alert_filter'] = api_data res = call_api_view(request, 'GET', mon_alert_list, data=api_data) if res.status_code == 200: context['alerts'] = res.data['result'] elif res.status_code == 201: context['error'] = 'Unexpected error: got into an API loop.' else: context['error'] = res.data.get('result', {}).get('error', res.data) return render(request, 'gui/mon/alert_table.html', context)
def vms(request, hostname, zpool=None): """ List of servers defined on this compute node, optionally filtered by storage (#952). """ context = collect_view_data(request, 'node_list') context['node'] = node = get_node(request, hostname) context['nodes'] = Node.all() context['node_online'] = node.is_online() context['can_edit'] = True context['storages'] = nss = node.nodestorage_set.select_related( 'storage').all().order_by('zpool') all_vms = node.vm_set.select_related( 'owner', 'dc', 'slavevm', 'slavevm__master_vm').order_by('hostname') context['vms_all_count'] = all_vms.count() _vms = [] if zpool and zpool not in {ns.zpool for ns in nss}: zpool = None for ns in nss: ns.vms_count = 0 for vm in all_vms: vm_zpools = vm.get_used_disk_pools() vm.resources = vm.get_cpu_ram_disk(zpool=zpool) for ns in nss: if ns.zpool in vm_zpools: ns.vms_count += 1 if zpool and zpool == ns.zpool: _vms.append(vm) if zpool: context['vms'] = _vms else: context['vms'] = all_vms context['zpool'] = zpool return render(request, 'gui/node/vms.html', context)
def dc_network_list(request): """ Network/IP<->Dc management and Network management. """ user, dc = request.user, request.dc nets = Subnet.objects.order_by('name') context = collect_view_data(request, 'dc_network_list') context['is_staff'] = is_staff = user.is_staff context['can_edit'] = can_edit = is_staff or user.has_permission(request, NetworkAdminPermission.name) context['all'] = _all = is_staff and request.GET.get('all', False) context['deleted'] = _deleted = can_edit and request.GET.get('deleted', False) context['qs'] = qs = get_query_string(request, all=_all, deleted=_deleted).urlencode() if _deleted: nets = nets.exclude(access=Subnet.INTERNAL) else: nets = nets.exclude(access__in=Subnet.INVISIBLE) if _all: _nets = nets.select_related('owner', 'dc_bound').prefetch_related('dc').all() else: _nets = nets.select_related('owner', 'dc_bound').filter(dc=dc) context['networks'] = _nets.extra(select=ExtendedNetworkSerializer.extra_select) if is_staff: if _all: # Uses set() because of optimized membership ("in") checking context['can_add'] = set(nets.exclude(dc=dc).values_list('pk', flat=True)) else: context['can_add'] = nets.exclude(dc=dc).count() context['form_dc'] = DcNetworkForm(request, nets) context['url_form_dc'] = reverse('dc_network_form', query_string=qs) if can_edit: context['url_form_admin'] = reverse('admin_network_form', query_string=qs) context['form_admin'] = AdminNetworkForm(request, None, prefix='adm', initial={'owner': user.username, 'access': Subnet.PRIVATE, 'dc_bound': not is_staff}) return render(request, 'gui/dc/network_list.html', context)
def details(request, hostname): """ Compute node details. """ dc1_settings = get_dc1_settings(request) context = collect_view_data(request, 'node_list') context['node'] = node = get_node(request, hostname, sr=('owner',)) context['nodes'] = Node.all() context['node_dcs'] = node.dc.all().values_list('alias', flat=True) context['node_vms'] = node.vm_set.count() context['node_real_vms'] = node.vm_set.filter(slavevm__isnull=True).count() context['form'] = NodeForm(request, node, initial=node.web_data) context['mon_sla_enabled'] = settings.MON_ZABBIX_ENABLED and dc1_settings.MON_ZABBIX_NODE_SLA if node.is_backup: context['node_backups'] = node.backup_set.count() else: context['node_backups'] = 0 view_node_details.send(sender='gui.node.views.details', request=request, context=context) return render(request, 'gui/node/details.html', context)
def backups(request, hostname): """ List of server backups stored on this node. """ context = collect_view_data(request, 'node_list') context['node'] = node = get_node(request, hostname) context['nodes'] = (node,) context['node_online'] = node.is_online() context['submenu_auto'] = '' context['lastbkp'] = [] context['can_edit'] = True context['bkp_node'] = True context['last_bkpid'] = request.GET.get('last_bkpid', None) # This could change the current DC _backup_list_context(request, node, context) context['bkpform_update'] = UpdateBackupForm(None, prefix='snap_update') context['bkpform_restore'] = RestoreBackupForm(get_vms(request, sr=(), prefetch_tags=False)) context['update_mod_source'] = reverse('node_backup_form', node.hostname, query_string=context['qs']) return render(request, 'gui/node/backups.html', context)
def dc_user_list(request): """ User -> Dc group management. """ user, dc = request.user, request.dc users = User.objects.order_by('username').filter(ExcludeInternalUsers) context = collect_view_data(request, 'dc_user_list') context['is_staff'] = is_staff = user.is_staff context['can_edit'] = can_edit = is_staff or user.has_permission(request, UserAdminPermission.name) context['all'] = _all = can_edit and request.GET.get('all', False) context['active'] = _active = not (can_edit and request.GET.get('inactive', False)) context['qs'] = qs = get_query_string(request, all=_all, inactive=_active).urlencode() if _all or dc.access == dc.PUBLIC: if _all: pr = ('roles', 'roles__dc_set') else: pr = ('roles',) context['users'] = users.select_related('dc_bound').filter(is_active=_active).prefetch_related(*pr) if dc.access == dc.PUBLIC: context['dc_users'] = AllIn() else: # Uses set() because of optimized membership ("in") checking context['dc_users'] = set(users.filter((Q(id=dc.owner.id) | Q(roles__in=dc.roles.all()))) .values_list('pk', flat=True)) else: context['users'] = users.select_related('dc_bound')\ .filter(is_active=_active)\ .filter(Q(id=dc.owner.id) | Q(roles__in=dc.roles.all()) | Q(dc_bound=dc))\ .prefetch_related('roles').distinct() if can_edit: context['url_form_admin'] = reverse('dc_user_modal_form', query_string=qs) context['form_admin'] = AdminUserModalForm(request, None, prefix='adm', initial={'dc_bound': True, 'is_active': True}) return render(request, 'gui/dc/user_list.html', context)
def dc_iso_list(request): """ Iso<->Dc management + Iso management. """ user, dc = request.user, request.dc isos = Iso.objects.order_by('name') context = collect_view_data(request, 'dc_iso_list') context['is_staff'] = is_staff = user.is_staff context['can_edit'] = can_edit = is_staff or user.has_permission(request, IsoAdminPermission.name) context['all'] = _all = is_staff and request.GET.get('all', False) context['deleted'] = _deleted = can_edit and request.GET.get('deleted', False) context['qs'] = qs = get_query_string(request, all=_all, deleted=_deleted).urlencode() if _deleted: isos = isos.exclude(access=Iso.INTERNAL) else: isos = isos.exclude(access__in=Iso.INVISIBLE) if _all: context['isos'] = isos.select_related('owner', 'dc_bound').prefetch_related('dc').all() else: context['isos'] = isos.select_related('owner', 'dc_bound').filter(dc=dc) if is_staff: if _all: # Uses set() because of optimized membership ("in") checking context['can_add'] = set(isos.exclude(dc=dc).values_list('pk', flat=True)) else: # No need for item list context['can_add'] = isos.exclude(dc=dc).count() context['form_dc'] = DcIsoForm(request, isos) context['url_form_dc'] = reverse('dc_iso_form', query_string=qs) if can_edit: context['url_form_admin'] = reverse('admin_iso_form', query_string=qs) context['form_admin'] = AdminIsoForm(request, None, prefix='adm', initial={'owner': user.username, 'access': Iso.PRIVATE, 'dc_bound': not is_staff}) return render(request, 'gui/dc/iso_list.html', context)
def dc_template_list(request): """ VmTemplate<->Dc management. """ user, dc = request.user, request.dc vmts = VmTemplate.objects.order_by('name') context = collect_view_data(request, 'dc_template_list') context['is_staff'] = is_staff = user.is_staff context['can_edit'] = can_edit = is_staff or user.has_permission( request, TemplateAdminPermission.name) context['all'] = _all = is_staff and request.GET.get('all', False) context['deleted'] = _deleted = can_edit and request.GET.get( 'deleted', False) context['qs'] = get_query_string(request, all=_all, deleted=_deleted).urlencode() if _deleted: vmts = vmts.exclude(access=VmTemplate.INTERNAL) else: vmts = vmts.exclude(access__in=VmTemplate.INVISIBLE) if _all: context['templates'] = vmts.select_related( 'owner', 'dc_bound').prefetch_related('dc').all() else: context['templates'] = vmts.select_related('owner', 'dc_bound').filter(dc=dc) if is_staff: context['form'] = TemplateForm(request, vmts) if _all: # Uses set() because of optimized membership ("in") checking context['can_add'] = set( vmts.exclude(dc=dc).values_list('pk', flat=True)) else: context['can_add'] = vmts.exclude(dc=dc).count() return render(request, 'gui/dc/template_list.html', context)
def dc_list(request): """ Datacenter management. """ context = collect_view_data(request, 'dc_list') context['can_edit'] = can_edit = request.user.is_staff # DC owners have read-only rights if can_edit: pr = ('roles',) context['all'] = _all = bool(request.GET.get('all', False)) context['form'] = DcForm(request, None, initial={'access': Dc.PRIVATE, 'owner': request.user.username}) context['settings_form'] = DcSettingsForm(request, None) context['can_add'] = settings.VMS_DC_ENABLED context['colspan'] = 9 else: _all = False pr = None # Groups are only visible by SuperAdmins context['colspan'] = 8 context['qs'] = get_query_string(request, all=_all).urlencode() context['dcs'] = get_dcs_extended(request, pr=pr) return render(request, 'gui/dc/dc_list.html', context)
def backup(request, hostname): """ Backup list and backup definitions. """ dc_settings = request.dc.settings context = collect_view_data(request, 'vm_list') context['vm'] = vm = get_vm(request, hostname, sr=('dc', 'owner', 'template', 'slavevm')) context['vms'] = vms = get_vms(request) context['vms_tags'] = get_vms_tags(vms) context['can_edit'] = request.user.is_admin(request) context['bkpdefs'] = bkpdefs = get_vm_bkpdefs(vm) context['lastbkp'] = [] context.update(get_vm_backups(request, vm)) # Add paginator if context['can_edit']: context['bkpform_create'] = CreateBackupForm(vm, bkpdefs, prefix='snap_create') context['bkpform_restore'] = RestoreBackupForm(vms) context['bkpform_update'] = UpdateBackupForm(vm, prefix='snap_update') context['bkpdeform_update'] = UpdateBackupDefineForm(request, vm) bkpdef_initial = { 'zpool': dc_settings.VMS_STORAGE_DEFAULT, 'type': BackupDefine.DATASET, 'disk_id': 1, 'active': True, 'compression': dc_settings.VMS_VM_BACKUP_COMPRESSION_DEFAULT } context['bkpdeform_create'] = CreateBackupDefineForm( request, vm, prefix='bkpdef_create', initial=bkpdef_initial) view_vm_backup.send(sender='gui.vm.views.backup', request=request, context=context) return render(request, 'gui/vm/backup.html', context)
def images(request, hostname): """ Redirect to list of images on default node storage. """ node = get_node(request, hostname) nss = node.nodestorage_set.all().values_list('zpool', flat=True).order_by('zpool') if nss: nz = node.zpool if nz and nz in nss: zpool_redirect = nz elif settings.VMS_STORAGE_DEFAULT in nss: zpool_redirect = settings.VMS_STORAGE_DEFAULT else: zpool_redirect = nss[0] return redirect('node_images_zpool', hostname, zpool_redirect) context = collect_view_data(request, 'node_list') context['nodes'] = Node.all() context['node'] = node return render(request, 'gui/node/images_disabled.html', context)
def images_zpool(request, hostname, zpool): """ List of images on node storages. """ context = collect_view_data(request, 'node_list') context['node'] = node = get_node(request, hostname) context['nodes'] = Node.all() try: context['ns'] = ns = NodeStorage.objects.select_related('storage').get( node=node, zpool=zpool) except NodeStorage.DoesNotExist: raise Http404 context['storages'] = node.nodestorage_set.select_related('storage').all().order_by('zpool').\ annotate(imgs=Count('images__uuid')) context['images'] = ns.images.select_related( 'owner', 'dc_bound').all().order_by('name').annotate(dcs=Count('dc')) image_vms = {} for vm in node.vm_set.select_related('dc').all().order_by('hostname'): for img_uuid in vm.get_image_uuids(zpool=zpool): image_vms.setdefault(img_uuid, []).append({ 'hostname': vm.hostname, 'dc': vm.dc.name }) context['image_vms'] = image_vms context['form'] = NodeStorageImageForm(ns, initial={ 'node': hostname, 'zpool': zpool }) context['last_img'] = request.GET.get('last_img', None) return render(request, 'gui/node/images.html', context)
def dc_domain_record_list(request): """ List/filter DNS records for a DNS domain (domain parameter in querystring). """ context = collect_view_data(request, 'dc_domain_list', dc_dns_only=True) context['is_staff'] = is_staff = request.user.is_staff qs = request.GET.copy() name = qs.get('flt-domain', None) context['all'] = _all = is_staff and request.GET.get('all', request.GET.get('flt-all', False)) qs['flt-all'] = '1' if _all else '' if not name: raise PermissionDenied context['domain'] = domain = get_domain(request, name) context['filters'] = filter_form = DnsRecordFilterForm(request, qs, _all=_all, prefix='flt') context['qs'] = qs.urlencode() context['order_by'], order_by = get_order_by(request, api_view=RecordView, db_default=('-id',), user_default=('-id',)) records = domain.record_set.order_by(*order_by) if filter_form.is_valid() and filter_form.has_changed(): q = filter_form.get_filters() if q: records = records.filter(q) context['records'] = context['pager'] = get_pager(request, records, per_page=50) context['form_record'] = DnsRecordForm(request, domain, None, initial={'prio': Record.PRIO, 'ttl': Record.TTL, 'type': Record.A, 'id': 0, 'disabled': False, 'name': '.%s' % domain.name}) context['form_records'] = MultiDnsRecordForm(request, domain, None) context['url_form_record'] = reverse('domain_record_form', name, query_string=qs) return render(request, 'gui/dc/domain_record_list.html', context)
def template_list(request): context = collect_view_data(request, 'mon_template_list') return render(request, 'gui/mon/template_list.html', context)
def hostgroup_list(request): context = collect_view_data(request, 'mon_hostgroup_list') return render(request, 'gui/mon/hostgroup_list.html', context)
def webcheck_list(request): context = collect_view_data(request, 'mon_webcheck_list') return render(request, 'gui/mon/webcheck_list.html', context)
def action_list(request): context = collect_view_data(request, 'mon_action_list') return render(request, 'gui/mon/action_list.html', context)
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)