Ejemplo n.º 1
0
    def _get_fixed_ip_address(self, port_uuid, client):
        """Get a Neutron port's fixed ip address.

        :param port_uuid: Neutron port id.
        :param client: Neutron client instance.
        :returns: Neutron port ip address.
        :raises: FailedToGetIPAddressOnPort
        :raises: InvalidIPv4Address
        """
        ip_address = None
        try:
            neutron_port = client.show_port(port_uuid).get('port')
        except neutron_client_exc.NeutronClientException:
            LOG.exception("Failed to Get IP address on Neutron port %s.",
                          port_uuid)
            raise exception.FailedToGetIPAddressOnPort(port_id=port_uuid)

        fixed_ips = neutron_port.get('fixed_ips')

        # NOTE(faizan) At present only the first fixed_ip assigned to this
        # neutron port will be used, since nova allocates only one fixed_ip
        # for the instance.
        if fixed_ips:
            ip_address = fixed_ips[0].get('ip_address', None)

        if ip_address:
            if netutils.is_valid_ipv4(ip_address):
                return ip_address
            else:
                LOG.error("Neutron returned invalid IPv4 address %s.",
                          ip_address)
                raise exception.InvalidIPv4Address(ip_address=ip_address)
        else:
            LOG.error("No IP address assigned to Neutron port %s.", port_uuid)
            raise exception.FailedToGetIPAddressOnPort(port_id=port_uuid)
Ejemplo n.º 2
0
    def _get_port_ip_address(self, task, p_obj, client):
        """Get ip address of ironic port/portgroup assigned by Neutron.

        :param task: a TaskManager instance.
        :param p_obj: Ironic port or portgroup object.
        :param client: Neutron client instance.
        :returns: List of Neutron vif ip address associated with
                  Node's port/portgroup.
        :raises: FailedToGetIPAddressOnPort
        :raises: InvalidIPv4Address
        """

        # NOTE(vdrok): We are booting the node only in one network at a time,
        # and presence of cleaning_vif_port_id means we're doing cleaning, of
        # provisioning_vif_port_id - provisioning. Otherwise it's a tenant
        # network
        vif = (p_obj.internal_info.get('cleaning_vif_port_id')
               or p_obj.internal_info.get('provisioning_vif_port_id')
               or p_obj.extra.get('vif_port_id'))
        if not vif:
            obj_name = 'portgroup'
            if isinstance(p_obj, objects.Port):
                obj_name = 'port'
            LOG.warning(
                _LW("No VIFs found for node %(node)s when attempting "
                    "to get IP address for %(obj_name)s: %(obj_id)."), {
                        'node': task.node.uuid,
                        'obj_name': obj_name,
                        'obj_id': p_obj.uuid
                    })
            raise exception.FailedToGetIPAddressOnPort(port_id=p_obj.uuid)

        vif_ip_address = self._get_fixed_ip_address(vif, client)
        return vif_ip_address
Ejemplo n.º 3
0
    def _get_port_ip_address(self, task, p_obj, client):
        """Get ip address of ironic port/portgroup assigned by Neutron.

        :param task: a TaskManager instance.
        :param p_obj: Ironic port or portgroup object.
        :param client: Neutron client instance.
        :returns: List of Neutron vif ip address associated with
                  Node's port/portgroup.
        :raises: FailedToGetIPAddressOnPort
        :raises: InvalidIPv4Address
        """

        vif = task.driver.network.get_current_vif(task, p_obj)
        if not vif:
            obj_name = 'portgroup'
            if isinstance(p_obj, objects.Port):
                obj_name = 'port'
            LOG.warning(
                "No VIFs found for node %(node)s when attempting "
                "to get IP address for %(obj_name)s: %(obj_id).", {
                    'node': task.node.uuid,
                    'obj_name': obj_name,
                    'obj_id': p_obj.uuid
                })
            raise exception.FailedToGetIPAddressOnPort(port_id=p_obj.uuid)

        vif_ip_address = self._get_fixed_ip_address(vif, client)
        return vif_ip_address
Ejemplo n.º 4
0
def _link_ip_address_pxe_configs(task, hex_form):
    """Link each IP address with the PXE configuration file.

    :param task: A TaskManager instance.
    :param hex_form: Boolean value indicating if the conf file name should be
                     hexadecimal equivalent of supplied ipv4 address.
    :raises: FailedToGetIPAddressOnPort
    :raises: InvalidIPv4Address

    """
    pxe_config_file_path = get_pxe_config_file_path(task.node.uuid)

    api = dhcp_factory.DHCPFactory().provider
    ip_addrs = api.get_ip_addresses(task)
    if not ip_addrs:
        raise exception.FailedToGetIPAddressOnPort(_(
            "Failed to get IP address for any port on node %s.") %
            task.node.uuid)
    for port_ip_address in ip_addrs:
        ip_address_path = _get_pxe_ip_address_path(port_ip_address,
                                                   hex_form)
        ironic_utils.unlink_without_raise(ip_address_path)
        relative_source_path = os.path.relpath(
            pxe_config_file_path, os.path.dirname(ip_address_path))
        utils.create_link_without_raise(relative_source_path,
                                        ip_address_path)
Ejemplo n.º 5
0
def _link_ip_address_pxe_configs(task, ipxe_enabled=False):
    """Link each IP address with the PXE configuration file.

    :param task: A TaskManager instance.
    :param ipxe_enabled: Default false boolean to indicate if ipxe
                         is in use by the caller.
    :raises: FailedToGetIPAddressOnPort
    :raises: InvalidIPv4Address

    """
    pxe_config_file_path = get_pxe_config_file_path(task.node.uuid,
                                                    ipxe_enabled=ipxe_enabled)

    api = dhcp_factory.DHCPFactory().provider
    ip_addrs = api.get_ip_addresses(task)
    if not ip_addrs:
        raise exception.FailedToGetIPAddressOnPort(
            _("Failed to get IP address for any port on node %s.") %
            task.node.uuid)
    for port_ip_address in ip_addrs:
        ip_address_path = _get_pxe_ip_address_path(port_ip_address)
        ironic_utils.unlink_without_raise(ip_address_path)
        relative_source_path = os.path.relpath(
            pxe_config_file_path, os.path.dirname(ip_address_path))
        utils.create_link_without_raise(relative_source_path, ip_address_path)
Ejemplo n.º 6
0
def _get_node_ip(task):
    api = dhcp_factory.DHCPFactory().provider
    ip_addrs = api.get_ip_addresses(task)
    if not ip_addrs:
        raise exception.FailedToGetIPAddressOnPort(
            _("Failed to get IP address for any port on node %s.") %
            task.node.uuid)
    if len(ip_addrs) > 1:
        error = _("Ansible driver does not support multiple IP addresses "
                  "during deploy or cleaning")
        raise exception.InstanceDeployFailure(reason=error)

    return ip_addrs[0]
Ejemplo n.º 7
0
    def _get_fixed_ip_address(self, port_id, client):
        """Get a Neutron port's fixed ip address.

        :param port_id: Neutron port id.
        :param client: Neutron client instance.
        :returns: Neutron port ip address.
        :raises: NetworkError
        :raises: InvalidIPv4Address
        :raises: FailedToGetIPAddressOnPort
        """
        ip_address = None
        try:
            neutron_port = client.get_port(port_id)
        except openstack_exc.OpenStackCloudException:
            raise exception.NetworkError(
                _('Could not retrieve neutron port: %s') % port_id)

        fixed_ips = neutron_port.get('fixed_ips')

        # NOTE(faizan) At present only the first fixed_ip assigned to this
        # neutron port will be used, since nova allocates only one fixed_ip
        # for the instance.
        if fixed_ips:
            ip_address = fixed_ips[0].get('ip_address', None)

        if ip_address:
            try:
                if (ipaddress.ip_address(ip_address).version == 4
                        or ipaddress.ip_address(ip_address).version == 6):
                    return ip_address
                else:
                    LOG.error(
                        "Neutron returned invalid IP "
                        "address %(ip_address)s on port %(port_id)s.", {
                            'ip_address': ip_address,
                            'port_id': port_id
                        })

                    raise exception.InvalidIPv4Address(ip_address=ip_address)
            except ValueError as exc:
                LOG.error(
                    "An Invalid IP address was supplied and failed "
                    "basic validation: %s", exc)
                raise exception.InvalidIPAddress(ip_address=ip_address)
        else:
            LOG.error("No IP address assigned to Neutron port %s.", port_id)
            raise exception.FailedToGetIPAddressOnPort(port_id=port_id)
Ejemplo n.º 8
0
def _link_ip_address_pxe_configs(task):
    """Link each IP address with the PXE configuration file.

    :param task: A TaskManager instance.
    :raises: FailedToGetIPAddressOnPort
    :raises: InvalidIPv4Address

    """
    pxe_config_file_path = get_pxe_config_file_path(task.node.uuid)

    api = dhcp_factory.DHCPFactory().provider
    ip_addrs = api.get_ip_addresses(task)
    if not ip_addrs:
        raise exception.FailedToGetIPAddressOnPort(
            _("Failed to get IP address for any port on node %s.") %
            task.node.uuid)
    for port_ip_address in ip_addrs:
        ip_address_path = _get_pxe_ip_address_path(port_ip_address)
        utils.unlink_without_raise(ip_address_path)
        utils.create_link_without_raise(pxe_config_file_path, ip_address_path)
Ejemplo n.º 9
0
    def _get_port_ip_address(self, task, port_id):
        """Get ip address of ironic port assigned by neutron.

        :param task: a TaskManager instance.
        :param port_id: ironic Node's port UUID.
        :returns:  Neutron port ip address associated with Node's port.
        :raises: FailedToGetIPAddressOnPort
        :raises: InvalidIPv4Address
        """

        vifs = network.get_node_vif_ids(task)
        if not vifs:
            LOG.warning(_LW("No VIFs found for node %(node)s when attempting "
                            " to get port IP address."),
                        {'node': task.node.uuid})
            raise exception.FailedToGetIPAddressOnPort(port_id=port_id)

        port_vif = vifs[port_id]

        port_ip_address = self._get_fixed_ip_address(port_vif)
        return port_ip_address