Skip to content

Commit

Permalink
feat(vm): Allow users to choose the VNC screen resolution. The defaul…
Browse files Browse the repository at this point in the history
…t resolution defined by bhyve is 1024x768.

Ticket: #23894
  • Loading branch information
araujobsd committed May 12, 2017
1 parent 9e11b11 commit aabd6e1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
9 changes: 9 additions & 0 deletions gui/choices.py
Expand Up @@ -1098,6 +1098,15 @@ def __iter__(self):
('E1000', _('Intel e82545 (e1000)')),
('VIRTIO', _('VirtIO')),
)
VNC_RESOLUTION = (
('1920x1080', _('1920x1080')),
('1400x1050', _('1400x1050')),
('1280x1024', _('1280x1024')),
('1280x960', _('1280x960')),
('1024x768', _('1024x768')),
('800x600', _('800x600')),
('640x480', _('640x480')),
)

VM_DISKMODETYPES = (
('AHCI', _('AHCI')),
Expand Down
3 changes: 3 additions & 0 deletions gui/freeadmin/static/lib/js/freeadmin.js
Expand Up @@ -1344,6 +1344,7 @@ require([
var nic_mac = registry.byId("id_NIC_mac").domNode.parentNode.parentNode;
var vnc_wait = registry.byId("id_VNC_wait").domNode.parentNode.parentNode;
var vnc_port = registry.byId("id_VNC_port").domNode.parentNode.parentNode;
var vnc_resolution = registry.byId("id_VNC_resolution").domNode.parentNode.parentNode;

domStyle.set(cdrom_path, "display", "none");
domStyle.set(disk_mode, "display", "none");
Expand All @@ -1352,6 +1353,7 @@ require([
domStyle.set(nic_mac, "display", "none");
domStyle.set(vnc_wait, "display", "none");
domStyle.set(vnc_port, "display", "none");
domStyle.set(vnc_resolution, "display", "none");

if(dtype.get('value') == 'DISK') {
domStyle.set(disk_mode, "display", "");
Expand All @@ -1362,6 +1364,7 @@ require([
domStyle.set(nic_type, "display", "");
domStyle.set(nic_mac, "display", "");
} else if(dtype.get('value') == 'VNC') {
domStyle.set(vnc_resolution, "display", "");
domStyle.set(vnc_port, "display", "");
domStyle.set(vnc_wait, "display", "");
}
Expand Down
9 changes: 9 additions & 0 deletions gui/vm/forms.py
Expand Up @@ -105,6 +105,12 @@ class DeviceForm(ModelForm):
validators=[RegexValidator("^([0-9a-fA-F]{2}([::]?|$)){6}$", "Invalid MAC format.")],
initial='00:a0:98:FF:FF:FF',
)
VNC_resolution = forms.ChoiceField(
label=_('Resolution'),
choices=choices.VNC_RESOLUTION,
required=False,
initial='1024x768',
)
VNC_port = forms.CharField(
label=_('VNC port'),
required=False,
Expand Down Expand Up @@ -151,6 +157,7 @@ def __init__(self, *args, **kwargs):
elif self.instance.dtype == 'VNC':
self.fields['VNC_wait'].initial = self.instance.attributes.get('wait')
self.fields['VNC_port'].initial = self.instance.attributes.get('vnc_port')
self.fields['VNC_resolution'].initial = self.instance.attributes.get('vnc_resolution')

def clean(self):
vm = self.cleaned_data.get('vm')
Expand Down Expand Up @@ -185,11 +192,13 @@ def save(self, *args, **kwargs):
obj.attributes = {
'wait': self.cleaned_data['VNC_wait'],
'vnc_port': self.cleaned_data['VNC_port'],
'vnc_resolution': self.cleaned_data['VNC_resolution'],
}
else:
self._errors['dtype'] = self.error_class([_('VNC is only allowed for UEFI')])
self.cleaned_data.pop('VNC_port', None)
self.cleaned_data.pop('VNC_wait', None)
self.cleaned_data.pop('VNC_resolution', None)
return obj

obj.save()
Expand Down
5 changes: 4 additions & 1 deletion src/middlewared/middlewared/plugins/vm.py
Expand Up @@ -116,10 +116,13 @@ def run(self):
else:
wait = ''

vnc_resolution = device['attributes'].get('vnc_resolution').split('x')
width = vnc_resolution[0]
height = vnc_resolution[1]
vnc_port = int(device['attributes'].get('vnc_port', 5900 + self.vm['id']))

args += [
'-s', '29,fbuf,tcp=0.0.0.0:{},w=1024,h=768,{}'.format(vnc_port, wait),
'-s', '29,fbuf,tcp=0.0.0.0:{},w={},h={},{}'.format(vnc_port, width, height, wait),
'-s', '30,xhci,tablet',
]

Expand Down

0 comments on commit aabd6e1

Please sign in to comment.