def get_ip_address(iscsi_network):
"""
Return an IP address assigned to the running host that matches the given
subnet address. This IP becomes the portal IP for the target portal group
:param iscsi_network: cidr network address
:return: IP address, or '' if the host does not have an interface on the
required subnet
"""
ip = ''
subnet = netaddr.IPSet([iscsi_network])
target_ip_range = [str(ip) for ip in subnet] # list where each element
# is an ip address
for local_ip in ipv4_address():
if local_ip in target_ip_range:
ip = local_ip
break
return ip
评论列表
文章目录