Ejemplo n.º 1
0
def get_vr_address():
    # Get the address of the virtual router via dhcp leases
    # If no virtual router is detected, fallback on default gateway.
    # See http://docs.cloudstack.apache.org/projects/cloudstack-administration/en/4.8/virtual_machines/user-data.html # noqa

    # Try networkd first...
    latest_address = dhcp.networkd_get_option_from_leases('SERVER_ADDRESS')
    if latest_address:
        LOG.debug("Found SERVER_ADDRESS '%s' via networkd_leases",
                  latest_address)
        return latest_address

    # Try dhcp lease files next...
    lease_file = get_latest_lease()
    if not lease_file:
        LOG.debug("No lease file found, using default gateway")
        return get_default_gateway()

    with open(lease_file, "r") as fd:
        for line in fd:
            if "dhcp-server-identifier" in line:
                words = line.strip(" ;\r\n").split(" ")
                if len(words) > 2:
                    dhcptok = words[2]
                    LOG.debug("Found DHCP identifier %s", dhcptok)
                    latest_address = dhcptok
    if not latest_address:
        # No virtual router found, fallback on default gateway
        LOG.debug("No DHCP found, using default gateway")
        return get_default_gateway()
    return latest_address
Ejemplo n.º 2
0
def get_vr_address():
    # Get the address of the virtual router via dhcp leases
    # If no virtual router is detected, fallback on default gateway.
    # See http://docs.cloudstack.apache.org/projects/cloudstack-administration/en/4.8/virtual_machines/user-data.html # noqa

    # Try networkd first...
    latest_address = dhcp.networkd_get_option_from_leases('SERVER_ADDRESS')
    if latest_address:
        LOG.debug("Found SERVER_ADDRESS '%s' via networkd_leases",
                  latest_address)
        return latest_address

    # Try dhcp lease files next...
    lease_file = get_latest_lease()
    if not lease_file:
        LOG.debug("No lease file found, using default gateway")
        return get_default_gateway()

    with open(lease_file, "r") as fd:
        for line in fd:
            if "dhcp-server-identifier" in line:
                words = line.strip(" ;\r\n").split(" ")
                if len(words) > 2:
                    dhcptok = words[2]
                    LOG.debug("Found DHCP identifier %s", dhcptok)
                    latest_address = dhcptok
    if not latest_address:
        # No virtual router found, fallback on default gateway
        LOG.debug("No DHCP found, using default gateway")
        return get_default_gateway()
    return latest_address
Ejemplo n.º 3
0
 def _networkd_get_value_from_leases(leases_d=None):
     return dhcp.networkd_get_option_from_leases('OPTION_245',
                                                 leases_d=leases_d)
Ejemplo n.º 4
0
 def _networkd_get_value_from_leases(leases_d=None):
     return dhcp.networkd_get_option_from_leases(
         'OPTION_245', leases_d=leases_d)