def __init__(self, request, vm, *args, **kwargs): super(AdminServerNicSettingsForm, self).__init__(request, vm, *args, **kwargs) if vm.is_deployed(): self.fields['mac'].widget.attrs['class'] += ' disable_created' # Bug #chili-625 net_inc = [ nic['network_uuid'] for nic in vm.json_active_get_nics() if 'network_uuid' in nic ] else: net_inc = None self.max_nics = NIC_ID_MAX self.fields['net'].choices = [ (i.name, i) for i in get_subnets(request, include=net_inc) ] self.fields['use_net_dns'].help_text += _( ' Current VM configuration: %(resolvers)s') % { 'resolvers': ', '.join(vm.resolvers), } if not request.user.is_staff: self.fields['allow_dhcp_spoofing'].widget.attrs[ 'disabled'] = 'disabled' self.fields['allow_ip_spoofing'].widget.attrs[ 'disabled'] = 'disabled' self.fields['allow_mac_spoofing'].widget.attrs[ 'disabled'] = 'disabled' self.fields['allow_restricted_traffic'].widget.attrs[ 'disabled'] = 'disabled'
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'
def generate_networks(self, column_index, row_index=1, label='Network'): self.update_cell(self.sheet_data, column_index, row_index, label, color=self.header_color, bgcolor=self.header_bgcolor) for row_index, network in enumerate(get_subnets(self.request), start=row_index + 1): self.update_cell(self.sheet_data, column_index, row_index, network.name) self.add_validation(column_index, row_index, self.get_column_index(label))
def generate_nics(self): nics = [] nets = get_subnets(self.request) for i in range(0, random.randint(1, 2)): if len(nets) > 0: random_net = random.randint(0, len(nets) - 1) net = nets[random_net].name else: net = '' nics.append({ 'net': net, 'ip': '' }) return nics