Skip to content

Commit

Permalink
feat(vm): Allow users to set the NIC Mac Address or let it be auto ge…
Browse files Browse the repository at this point in the history
…nerated with the fixed OUI 00:a0:98 and with the remaining bytes from an MD5 hash of the slot and function numbers and the device name.

Ticket: #23651
Ticket: #23819
  • Loading branch information
araujobsd committed May 12, 2017
1 parent 77a96fb commit 9e11b11
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions gui/freeadmin/static/lib/js/freeadmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1341,13 +1341,15 @@ require([
var disk_mode = registry.byId("id_DISK_mode").domNode.parentNode.parentNode;
var disk_zvol = registry.byId("id_DISK_zvol").domNode.parentNode.parentNode;
var nic_type = registry.byId("id_NIC_type").domNode.parentNode.parentNode;
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;

domStyle.set(cdrom_path, "display", "none");
domStyle.set(disk_mode, "display", "none");
domStyle.set(disk_zvol, "display", "none");
domStyle.set(nic_type, "display", "none");
domStyle.set(nic_mac, "display", "none");
domStyle.set(vnc_wait, "display", "none");
domStyle.set(vnc_port, "display", "none");

Expand All @@ -1358,6 +1360,7 @@ require([
domStyle.set(cdrom_path, "display", "");
} else if(dtype.get('value') == 'NIC') {
domStyle.set(nic_type, "display", "");
domStyle.set(nic_mac, "display", "");
} else if(dtype.get('value') == 'VNC') {
domStyle.set(vnc_port, "display", "");
domStyle.set(vnc_wait, "display", "");
Expand Down
9 changes: 9 additions & 0 deletions gui/vm/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ class DeviceForm(ModelForm):
required=False,
initial='E1000',
)
NIC_mac = forms.CharField(
label=_('Mac Address'),
required=False,
help_text=_("You can specify the adapter MAC Address or let it be auto generated."),
validators=[RegexValidator("^([0-9a-fA-F]{2}([::]?|$)){6}$", "Invalid MAC format.")],
initial='00:a0:98:FF:FF:FF',
)
VNC_port = forms.CharField(
label=_('VNC port'),
required=False,
Expand Down Expand Up @@ -140,6 +147,7 @@ def __init__(self, *args, **kwargs):
self.fields['DISK_mode'].initial = self.instance.attributes.get('type')
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')
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')
Expand Down Expand Up @@ -170,6 +178,7 @@ def save(self, *args, **kwargs):
elif self.cleaned_data['dtype'] == 'NIC':
obj.attributes = {
'type': self.cleaned_data['NIC_type'],
'mac': self.cleaned_data['NIC_mac'],
}
elif self.cleaned_data['dtype'] == 'VNC':
if vm.bootloader == 'UEFI':
Expand Down
6 changes: 5 additions & 1 deletion src/middlewared/middlewared/plugins/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ def run(self):
nictype = 'virtio-net'
else:
nictype = 'e1000'
args += ['-s', '{},{},{}'.format(nid(), nictype, tapname)]
mac_address = device['attributes'].get('mac')
if mac_address == '00:a0:98:FF:FF:FF':
args += ['-s', '{},{},{}'.format(nid(), nictype, tapname)]
else:
args += ['-s', '{},{},{},mac={}'.format(nid(), nictype, tapname, mac_address)]
elif device['dtype'] == 'VNC':
if device['attributes'].get('wait'):
wait = 'wait'
Expand Down

0 comments on commit 9e11b11

Please sign in to comment.