M版dashboard前端页面增加网络端口的时候是不能定义IP的,只能通过DHCP地址池分配或者用命令行模式指定IP,如下图:
Openstack Mitaka dashboard 增加自定义IP功能


修改部分:
使用的horizon版本:openstack-dashboard-9.0.1-1.el7.noarch
只需修改一个文件:
/usr/share/openstack-dashboard/openstack_dashboard/dashboards/admin/networks/ports/forms.py
(1)在CreatePort()类后面增加加IP获取方式和IP地址表单项目,如下图红色框内容:
Openstack Mitaka dashboard 增加自定义IP功能

#Add start
specify_ip = forms.ChoiceField(
    label=_("Floating IPs"),
    help_text=_("To specify a fixed IP, select any options."),
    required=False,
    choices=[('', "DHCP"),
             ('fixed_ip', _("Fixed IPs"))],
    widget=forms.SelectWidget(attrs={
        'class': 'switchable',
        'data-slug': 'specify_ip',
    }))
fixed_ip = forms.IPField(
    label=_("IP Address"),
    required=False,
    help_text=_("Specify the IP address for the new port"),
    version=forms.IPv4 | forms.IPv6,
    widget=forms.TextInput(attrs={
        'class': 'switched',
        'data-switch-on': 'specify_ip',
        'data-specify_ip-fixed_ip': _("IP Address"),
    }))
#Add end

(2)同样在CreatePort()类下面 handle() 函数中,在执行创建端口之前(api.neutron.port_create())修改传递的参数,增加指定IP参数(参数格式为 kwargs['fixed_ips'] = [{'ip_address':'x.x.x.x','subnet_id':'subnet-id'}]),如下图红色框内容:
Openstack Mitaka dashboard 增加自定义IP功能

#Add start
if data['specify_ip']:
    subnet_List = network.to_dict()['subnets']
    if len(subnet_List) == 1:
        subnetId = subnet_List[0]['id']
        data['fixed_ips'] = [{'ip_address':data['fixed_ip'],'subnet_id':subnetId}]
del data['fixed_ip']
del data['specify_ip']
#Add End

这里添加了判断当前网络下是否只有一个子网,如果一个网络下面有多个子网的话则会执行DHCP方式获取。修改后reload一下Apache:
systemctl reload httpd
dashboard效果如下图:
Openstack Mitaka dashboard 增加自定义IP功能Openstack Mitaka dashboard 增加自定义IP功能