def __init__(self, request, iso, *args, **kwargs): super(AdminIsoForm, self).__init__(request, iso, *args, **kwargs) self.fields['owner'].choices = get_owners(request).values_list( 'username', 'username') if not request.user.is_staff: self.fields['dc_bound'].widget.attrs['disabled'] = 'disabled'
def __init__(self, request, img, *args, **kwargs): super(ImageSerializer, self).__init__(request, img, *args, **kwargs) if not kwargs.get('many', False): self.update_manifest = True self._dc_bound = img.dc_bound self.fields['owner'].queryset = get_owners(request, all=True)
def __init__(self, request, net, *args, **kwargs): super(AdminNetworkForm, self).__init__(request, net, *args, **kwargs) self.fields['owner'].choices = get_owners(request).values_list('username', 'username') self.fields['nic_tag'].choices = [(i, i) for i in sorted(DefaultDc().settings.VMS_NET_NIC_TAGS)] if not request.user.is_staff: self.fields['dc_bound'].widget.attrs['disabled'] = 'disabled'
def __init__(self, request, dc, *args, **kwargs): super(DcForm, self).__init__(request, dc, *args, **kwargs) self.fields['owner'].choices = get_owners(request, all=True).values_list( 'username', 'username') self.fields['groups'].choices = Role.objects.all().values_list( 'name', 'alias')
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) ]
def __init__(self, request, net, *args, **kwargs): super(AdminNetworkForm, self).__init__(request, net, *args, **kwargs) self.fields['owner'].choices = get_owners(request).values_list( 'username', 'username') self.fields['nic_tag'].choices = Node.all_nictags_choices() if not request.user.is_staff: self.fields['dc_bound'].widget.attrs['disabled'] = 'disabled'
def __init__(self, request, img, *args, **kwargs): super(_ImageForm, self).__init__(request, img, *args, **kwargs) self.fields['owner'].choices = get_owners(request).values_list( 'username', 'username') self.fields['tags'].tag_choices = TagVm.objects.distinct().filter( content_object__in=Vm.objects.filter( dc=request.dc)).order_by('tag__name').values_list('tag__name', flat=True)
def __init__(self, request, net, *args, **kwargs): super(NetworkSerializer, self).__init__(request, net, *args, **kwargs) if not kwargs.get('many', False): self._dc_bound = net.dc_bound self.fields['owner'].queryset = get_owners(request, all=True) self.fields['nic_tag'].choices = [ (i, i) for i in DefaultDc().settings.VMS_NET_NIC_TAGS ]
def __init__(self, request, node, *args, **kwargs): super(NodeForm, self).__init__(request, node, *args, **kwargs) self.fields['owner'].choices = get_owners(request).values_list( 'username', 'username') if node.is_unlicensed(): self.fields['status'].choices = Node.STATUS_DB self.fields['status'].widget.attrs['disabled'] = 'disabled' elif node.is_unreachable(): self.fields['status'].choices = Node.STATUS_DB[:-1] self.fields['status'].widget.attrs['disabled'] = 'disabled'
def __init__(self, request, node, ns, *args, **kwargs): super(NodeStorageForm, self).__init__(request, ns, *args, **kwargs) self.fields['owner'].choices = get_owners(request).values_list('username', 'username') node_zpools = node.zpools zpools = [(k, '%s (%s)' % (k, filesizeformat(int(v['size']) * 1048576))) for k, v in node_zpools.items()] # Add zpools for NodeStorage objects that have vanished from compute node (Issue #chili-27) for zpool in node.nodestorage_set.exclude(zpool__in=node_zpools.keys()).values_list('zpool', flat=True): zpools.append((zpool, '%s (???)' % zpool)) self.fields['zpool'].choices = zpools
def __init__(self, request, instance, *args, **kwargs): self._update_fields_ = ['alias', 'owner', 'access', 'desc', 'type', 'size_coef'] super(NodeStorageSerializer, self).__init__(request, instance, *args, **kwargs) if not kwargs.get('many', False): self._size_coef = instance.storage.size_coef self.fields['owner'].queryset = get_owners(request) if request.method == 'POST': self.fields['zpool'].choices = [(i, i) for i in instance.node.zpools.keys()] self._update_fields_.append('zpool') else: self.fields['zpool'].read_only = True
def __init__(self, request, instance, *args, **kwargs): super(NodeDefineSerializer, self).__init__(request, instance, *args, **kwargs) self.clear_cache = False self.status_changed = False self.monitoring_changed = False if not kwargs.get('many', False): # Used for update_node_resources() self._cpu_coef = instance.cpu_coef self._ram_coef = instance.ram_coef # Only active users self.fields['owner'].queryset = get_owners(request)
def __init__(self, request, node, *args, **kwargs): super(NodeForm, self).__init__(request, node, *args, **kwargs) self.fields['owner'].choices = get_owners(request).values_list('username', 'username') self.fields['address'].choices = [(ip, ip) for ip in node.ips] dc1_settings = get_dc1_settings(request) if dc1_settings.MON_ZABBIX_HOSTGROUPS_NODE: self.fields['monitoring_hostgroups'].help_text += _(' Automatically added hostgroups: ') \ + ', '.join(dc1_settings.MON_ZABBIX_HOSTGROUPS_NODE) if node.is_unlicensed(): self.fields['status'].choices = Node.STATUS_DB self.fields['status'].widget.attrs['disabled'] = 'disabled' elif node.is_unreachable(): self.fields['status'].choices = Node.STATUS_DB[:-1] self.fields['status'].widget.attrs['disabled'] = 'disabled'
def __init__(self, request, instance, *args, **kwargs): super(DcSerializer, self).__init__(request, instance, *args, **kwargs) if not kwargs.get('many', False): self.fields['owner'].default = request.user.username # Does not work self.fields['owner'].queryset = get_owners(request, all=True)
def __init__(self, request, iso, *args, **kwargs): super(IsoSerializer, self).__init__(request, iso, *args, **kwargs) if not kwargs.get('many', False): self._dc_bound = iso.dc_bound self.fields['owner'].queryset = get_owners(request, all=True)
def __init__(self, request, net, *args, **kwargs): super(NetworkSerializer, self).__init__(request, net, *args, **kwargs) if not kwargs.get('many', False): self._dc_bound = net.dc_bound self.fields['owner'].queryset = get_owners(request, all=True) self.fields['nic_tag'].choices = Node.all_nictags_choices()