ironic对多网卡的支持
在实际生产环境中,标准的物理机一般会有4个或以上的网卡数量,那么openstack的ironic是如何支持多网卡的呢?
从代码中分析,nova-compute在获取node所有的port的mac地址后,放入了Set(集合)中,set是无序的,在最后取mac地址真正创建neutron port时,调用pop()方法,这样根本就是无序的。无序意味着根据mac地址创建的neutron port与裸金属真实的网卡是没有映射的,在创建的时候,非常有可能将指定ip分配给预料外的网卡上。
因此,ironic对裸金属真实网卡的映射在newton版本是不支持的。
从ironic的一篇官方文章中看到:
The mapping between logical ports in neutron and physical ports and portgroups in ironic has always been somewhat unpredictable [2]. The ironic-neutron integration work added support for local link information for ports and portgroups [3]. In the interface attach/detach API work [4] ironic moved the responsibility for attaching virtual interfaces from nova to ironic. In both of these features physical network-awareness was seen as out of scope.
This algorithm takes no account of the physical network to which the ports and portgroups are connected, and consequently can result in invalid mappings. Further, there is currently no standard way in ironic to specify the physical network to which a port or portgroup is connected.
Further, there is currently no standard way in ironic to specify the physical network to which a port or portgroup is connected.
翻译:此外,目前还没有标准的方式来指定连接端口或端口组的物理网络。
从上来看,ironic在newton版本仍没有标准的方案来解决这个问题。
在我们生产环境中,这个硬性要求带来了挑战。
我给出了一个临时的解决方案:在nova-compute创建neutron port之前,对存储mac地址的set中的元素进行排序:
- 取出set中所有的元素,每个元素都是字符串
- 放入list中进行字母排序,然后将第一个元素传给neutron
- 再将其余元素push进原来的set
- 然后依次循环(与原来逻辑相同)
多说无益,上代码:
@staticmethod
def _populate_mac_address(instance, port_req_body, available_macs):
# NOTE(johngarbutt) On port_update, this will cause us to override
# any previous mac address the port may have had.
if available_macs is not None:
if not available_macs:
raise exception.PortNotFree(
instance=instance.uuid)
#li-zr edit
macList = list(available_macs)
macList.sort()
mac_address = macList[0]
available_macs.discard(mac_address)
# mac_address = available_macs.pop()
LOG.info("billytest mac allocating: %s", mac_address)
port_req_body['port']['mac_address'] = mac_address
return mac_address
这样对于创建云主机(裸金属节点)的模块来说,就增加了一些工作量:需要对port进行记录并在创建之时进行相同的字母排序,这样就可以保证裸金属的网卡mac地址和指定ip的映射正确了。