utils.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:ceph-iscsi-config 作者: ceph 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号