M 版 dashboard 前端页面增加网络端口的时候是不能定义 IP 的, 只能通过 DHCP 地址池分配或者用命令行模式指定 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 地址表单项目, 如下图红色框内容:
- #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'}]), 如下图红色框内容:
- #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 效果如下图:
来源: http://blog.51cto.com/ouziyou/2103197