def __init__(self, *args, **kwargs): super(DeviceForm, self).__init__(*args, **kwargs) self.fields['dtype'].widget.attrs['onChange'] = ("deviceTypeToggle();") self.fields['VNC_bind'].choices = self.ipv4_list() self.fields['NIC_attach'].choices = choices.NICChoices( exclude_configured=False, include_vlan_parent=True, include_lagg_parent=False, ) diskchoices = {} with client as c: for zvol in c.call('pool.dataset.query', [('type', '=', 'VOLUME')]): diskchoices[f'zvol/{zvol["name"]}'] = "%s (%s)" % ( zvol['name'], humanize_size(zvol['volsize']['parsed'])) self.fields['DISK_zvol'].choices = diskchoices.items() if self.instance.id: if self.instance.dtype == 'CDROM': self.fields[ 'CDROM_path'].initial = self.instance.attributes.get( 'path', '') elif self.instance.dtype == 'DISK': self.fields[ 'DISK_zvol'].initial = self.instance.attributes.get( 'path', '').replace('/dev/', '') self.fields[ 'DISK_mode'].initial = self.instance.attributes.get('type') self.fields[ 'DISK_sectorsize'].initial = self.instance.attributes.get( 'sectorsize', 0) elif self.instance.dtype == 'RAW': self.fields['DISK_raw'].initial = self.instance.attributes.get( 'path', '') self.fields[ 'DISK_mode'].initial = self.instance.attributes.get('type') self.fields[ 'DISK_sectorsize'].initial = self.instance.attributes.get( 'sectorsize', 0) if self.instance.vm.vm_type == 'Container Provider': self.fields['DISK_raw_boot'].widget = forms.CheckboxInput() self.fields['DISK_raw_size'].widget = forms.TextInput() self.fields['ROOT_password'].widget = forms.PasswordInput( render_value=True, ) self.fields[ 'DISK_raw_boot'].initial = self.instance.attributes.get( 'boot', False) self.fields[ 'DISK_raw_size'].initial = self.instance.attributes.get( 'size', '') self.fields[ 'ROOT_password'].initial = self.instance.attributes.get( 'rootpwd', '') elif self.instance.dtype == 'NIC': self.fields['NIC_type'].initial = self.instance.attributes.get( 'type') self.fields['NIC_mac'].initial = self.instance.attributes.get( 'mac') self.fields[ 'NIC_attach'].initial = self.instance.attributes.get( 'nic_attach') elif self.instance.dtype == 'VNC': vnc_port = self.instance.attributes.get('vnc_port') vnc_port = 0 if vnc_port is None else vnc_port self.fields['VNC_wait'].initial = self.instance.attributes.get( 'wait') self.fields['VNC_port'].initial = vnc_port self.fields[ 'VNC_resolution'].initial = self.instance.attributes.get( 'vnc_resolution') self.fields['VNC_bind'].initial = self.instance.attributes.get( 'vnc_bind') self.fields[ 'VNC_password'].initial = self.instance.attributes.get( 'vnc_password') self.fields['VNC_web'].initial = self.instance.attributes.get( 'vnc_web')
def __init__(self, *args, **kwargs): super(DeviceForm, self).__init__(*args, **kwargs) self.fields['dtype'].widget.attrs['onChange'] = ("deviceTypeToggle();") self.fields['VNC_bind'].choices = self.ipv4_list() diskchoices = {} _n = notifier() used_zvol = [] for volume in Volume.objects.filter(): zvols = _n.list_zfs_vols(volume.vol_name, sort='name') for zvol, attrs in zvols.items(): if "zvol/" + zvol not in used_zvol: diskchoices["zvol/" + zvol] = "%s (%s)" % ( zvol, humanize_size(attrs['volsize'])) self.fields['DISK_zvol'].choices = diskchoices.items() if self.instance.id: if self.instance.dtype == 'CDROM': self.fields[ 'CDROM_path'].initial = self.instance.attributes.get( 'path', '') elif self.instance.dtype == 'DISK': self.fields[ 'DISK_zvol'].initial = self.instance.attributes.get( 'path', '').replace('/dev/', '') self.fields[ 'DISK_mode'].initial = self.instance.attributes.get('type') self.fields[ 'DISK_sectorsize'].initial = self.instance.attributes.get( 'sectorsize', 0) elif self.instance.dtype == 'RAW': self.fields['DISK_raw'].initial = self.instance.attributes.get( 'path', '') self.fields[ 'DISK_mode'].initial = self.instance.attributes.get('type') self.fields[ 'DISK_sectorsize'].initial = self.instance.attributes.get( 'sectorsize', 0) if self.instance.vm.vm_type == 'Container Provider': self.fields['DISK_raw_boot'].widget = forms.CheckboxInput() self.fields['DISK_raw_size'].widget = forms.TextInput() self.fields['ROOT_password'].widget = forms.PasswordInput( render_value=True, ) self.fields[ 'DISK_raw_boot'].initial = self.instance.attributes.get( 'boot', False) self.fields[ 'DISK_raw_size'].initial = self.instance.attributes.get( 'size', '') self.fields[ 'ROOT_password'].initial = self.instance.attributes.get( 'rootpwd', '') elif self.instance.dtype == 'NIC': self.fields['NIC_type'].initial = self.instance.attributes.get( 'type') self.fields['NIC_mac'].initial = self.instance.attributes.get( 'mac') self.fields[ 'NIC_attach'].initial = self.instance.attributes.get( 'nic_attach') elif self.instance.dtype == 'VNC': vnc_port = self.instance.attributes.get('vnc_port') vnc_port = 0 if vnc_port is None else vnc_port self.fields['VNC_wait'].initial = self.instance.attributes.get( 'wait') self.fields['VNC_port'].initial = vnc_port self.fields[ 'VNC_resolution'].initial = self.instance.attributes.get( 'vnc_resolution') self.fields['VNC_bind'].initial = self.instance.attributes.get( 'vnc_bind') self.fields[ 'VNC_password'].initial = self.instance.attributes.get( 'vnc_password') self.fields['VNC_web'].initial = self.instance.attributes.get( 'vnc_web')