Esempio n. 1
0
 def _get_port(self, tenant_id, network_id, port_id):
     net = self._get_network(tenant_id, network_id)
     try:
         port = db.port_get(port_id, network_id)
     except:
         raise exc.PortNotFound(net_id=network_id, port_id=port_id)
     # Port must exist and belong to the appropriate network.
     if port['network_id'] != net['uuid']:
         raise exc.PortNotFound(net_id=network_id, port_id=port_id)
     return port
Esempio n. 2
0
 def _get_port(self, context, id, verbose=None):
     try:
         port = self._get_by_id(context, models_v2.Port, id,
                                verbose=verbose)
     except exc.NoResultFound:
         # NOTE(jkoelker) The PortNotFound exceptions requires net_id
         #                kwarg in order to set the message correctly
         raise q_exc.PortNotFound(port_id=id, net_id=None)
     except exc.MultipleResultsFound:
         LOG.error('Multiple ports match for %s' % id)
         raise q_exc.PortNotFound(port_id=id)
     return port
Esempio n. 3
0
def plug_interface(controller, network, port, type, attachment=None):
    uri = "/ws.v1/lswitch/" + network + "/lport/" + port + "/attachment"

    lport_obj = {}
    if attachment:
        lport_obj["vif_uuid"] = attachment

    lport_obj["type"] = type
    try:
        resp_obj = do_single_request("PUT",
                                     uri,
                                     jsonutils.dumps(lport_obj),
                                     controller=controller)
    except NvpApiClient.ResourceNotFound as e:
        LOG.error("Port or Network not found, Error: %s" % str(e))
        raise exception.PortNotFound(port_id=port, net_id=network)
    except NvpApiClient.Conflict as e:
        LOG.error("Conflict while making attachment to port, "
                  "Error: %s" % str(e))
        raise exception.AlreadyAttached(att_id=attachment,
                                        port_id=port,
                                        net_id=network,
                                        att_port_id="UNKNOWN")
    except NvpApiClient.NvpApiException as e:
        raise exception.QuantumException()

    result = jsonutils.dumps(resp_obj)
    return result
Esempio n. 4
0
def update_port(network, port_id, **params):
    controller = params["controller"]
    lport_obj = {}

    if "state" in params:
        state = params["state"]
        check_port_state(state)
        admin_status = True
        if state == "DOWN":
            admin_status = False
        lport_obj["admin_status_enabled"] = admin_status

    uri = "/ws.v1/lswitch/" + network + "/lport/" + port_id
    try:
        resp_obj = do_single_request("PUT",
                                     uri,
                                     jsonutils.dumps(lport_obj),
                                     controller=controller)
    except NvpApiClient.ResourceNotFound as e:
        LOG.error("Port or Network not found, Error: %s" % str(e))
        raise exception.PortNotFound(port_id=port_id, net_id=network)
    except NvpApiClient.NvpApiException as e:
        raise exception.QuantumException()

    obj = jsonutils.loads(resp_obj)
    obj["port-op-status"] = get_port_status(controller, network, obj["uuid"])
    return obj
Esempio n. 5
0
def update_port(network, port_id, **params):
    cluster = params["cluster"]
    lport_obj = {}

    admin_state_up = params['port'].get('admin_state_up')
    name = params["port"].get("name")
    device_id = params["port"].get("device_id")
    if admin_state_up:
        lport_obj["admin_status_enabled"] = admin_state_up
    if name:
        lport_obj["display_name"] = name

    if device_id:
        # device_id can be longer than 40 so we rehash it
        device_id = hashlib.sha1(device_id).hexdigest()
        lport_obj["tags"] = (
            [dict(scope='os_tid', tag=params["port"].get("tenant_id")),
             dict(scope='q_port_id', tag=params["port"]["id"]),
             dict(scope='vm_id', tag=device_id)])

    uri = "/ws.v1/lswitch/" + network + "/lport/" + port_id
    try:
        resp_obj = do_single_request("PUT", uri, json.dumps(lport_obj),
                                     cluster=cluster)
    except NvpApiClient.ResourceNotFound as e:
        LOG.error("Port or Network not found, Error: %s" % str(e))
        raise exception.PortNotFound(port_id=port_id, net_id=network)
    except NvpApiClient.NvpApiException as e:
        raise exception.QuantumException()

    obj = json.loads(resp_obj)
    obj["port-op-status"] = get_port_status(cluster, network, obj["uuid"])
    return obj
Esempio n. 6
0
def get_port_status(controller, lswitch_id, port_id):
    """Retrieve the operational status of the port"""
    # Make sure the network exists first
    try:
        do_single_request("GET",
                          "/ws.v1/lswitch/%s" % (lswitch_id),
                          controller=controller)
    except NvpApiClient.ResourceNotFound as e:
        LOG.error("Network not found, Error: %s" % str(e))
        raise exception.NetworkNotFound(net_id=lswitch_id)
    except NvpApiClient.NvpApiException as e:
        raise exception.QuantumException()
    try:
        r = do_single_request("GET",
                              "/ws.v1/lswitch/%s/lport/%s/status" %
                              (lswitch_id, port_id),
                              controller=controller)
        r = jsonutils.loads(r)
    except NvpApiClient.ResourceNotFound as e:
        LOG.error("Port not found, Error: %s" % str(e))
        raise exception.PortNotFound(port_id=port_id, net_id=lswitch_id)
    except NvpApiClient.NvpApiException as e:
        raise exception.QuantumException()
    if r['link_status_up'] is True:
        return "UP"
    else:
        return "DOWN"
Esempio n. 7
0
def port_get_by_id(port_id):
    session = get_session()
    try:
        return  session.query(models.Port).\
          filter_by(uuid=port_id).one()
    except exc.NoResultFound:
        raise q_exc.PortNotFound(port_id=port_id)
Esempio n. 8
0
def set_port_status(session, port_id, status):
    try:
        port = session.query(models_v2.Port).filter_by(id=port_id).one()
        port['status'] = status
        session.merge(port)
        session.flush()
    except orm_exc.NoResultFound:
        raise q_exc.PortNotFound(port_id=port_id, net_id=None)
Esempio n. 9
0
def delete_port(cluster, port):
    try:
        do_single_request("DELETE", port['_href'], cluster=cluster)
    except NvpApiClient.ResourceNotFound as e:
        LOG.error("Port or Network not found, Error: %s" % str(e))
        raise exception.PortNotFound(port_id=port['uuid'])
    except NvpApiClient.NvpApiException as e:
        raise exception.QuantumException()
Esempio n. 10
0
 def set_port_status(self, port_id, status):
     session = db_api.get_session()
     try:
         port = session.query(models_v2.Port).filter_by(id=port_id).one()
         port['status'] = status
         session.merge(port)
         session.flush()
     except exc.NoResultFound:
         raise q_exc.PortNotFound(port_id=port_id)
Esempio n. 11
0
def port_get(net_id, port_id):
    # confirm network exists
    network_get(net_id)
    session = get_session()
    try:
        return (session.query(models.Port).filter_by(uuid=port_id).filter_by(
            network_id=net_id).one())
    except exc.NoResultFound:
        raise q_exc.PortNotFound(net_id=net_id, port_id=port_id)
Esempio n. 12
0
def delete_port(controller, network, port):
    uri = "/ws.v1/lswitch/" + network + "/lport/" + port
    try:
        do_single_request("DELETE", uri, controller=controller)
    except NvpApiClient.ResourceNotFound as e:
        LOG.error("Port or Network not found, Error: %s" % str(e))
        raise exception.PortNotFound(port_id=port, net_id=network)
    except NvpApiClient.NvpApiException as e:
        raise exception.QuantumException()
Esempio n. 13
0
def set_port_status(port_id, status):
    """Set the port status"""
    LOG.debug(_("set_port_status as %s called"), status)
    session = db.get_session()
    try:
        port = session.query(models_v2.Port).filter_by(id=port_id).one()
        port['status'] = status
        session.merge(port)
        session.flush()
    except exc.NoResultFound:
        raise q_exc.PortNotFound(port_id=port_id)
Esempio n. 14
0
def port_get(port_id, net_id, session=None):
    # confirm network exists
    network_get(net_id)
    if not session:
        session = get_session()
    try:
        return session.query(models.Port).\
          filter_by(uuid=port_id).\
          filter_by(network_id=net_id).\
          one()
    except exc.NoResultFound:
        raise q_exc.PortNotFound(net_id=net_id, port_id=port_id)
Esempio n. 15
0
def port_binding_destroy(session, port_id, net_id):
    try:
        session.query(models_v2.Port).filter(
            models_v2.Port.network_id == net_id).filter(
                models_v2.Port.id == port_id).one()  # confirm port exists
        port_binding = session.query(ryu_models_v2.PortBinding).filter_by(
            network_id=net_id).filter_by(port_id=port_id).one()
        session.delete(port_binding)
        session.flush()
        return port_binding
    except orm_exc.NoResultFound:
        raise q_exc.PortNotFound(port_id=port_id, net_id=net_id)
Esempio n. 16
0
 def _get_blade_for_port(self, args):
     """
     Return the a dict with IP address of the blade
     on which a dynamic vnic was reserved for this port
     """
     tenant_id = args[0]
     net_id = args[1]
     port_id = args[2]
     rsvd_info = self._get_rsvd_blade_intf_by_port(tenant_id, port_id)
     if not rsvd_info:
         raise exc.PortNotFound(net_id=net_id, port_id=port_id)
     device_params = {const.DEVICE_IP: [rsvd_info[const.UCSM_IP]]}
     return device_params
Esempio n. 17
0
def get_port(controller, network, port, relations=None):
    uri = "/ws.v1/lswitch/" + network + "/lport/" + port + "?"
    if relations:
        uri += "relations=%s" % relations
    try:
        resp_obj = do_single_request("GET", uri, controller=controller)
        port = jsonutils.loads(resp_obj)
    except NvpApiClient.ResourceNotFound as e:
        LOG.error("Port or Network not found, Error: %s" % str(e))
        raise exception.PortNotFound(port_id=port, net_id=network)
    except NvpApiClient.NvpApiException as e:
        raise exception.QuantumException()
    return port
Esempio n. 18
0
def unplug_interface(controller, network, port):
    uri = "/ws.v1/lswitch/" + network + "/lport/" + port + "/attachment"
    lport_obj = {"type": "NoAttachment"}
    try:
        resp_obj = do_single_request("PUT",
                                     uri,
                                     jsonutils.dumps(lport_obj),
                                     controller=controller)
    except NvpApiClient.ResourceNotFound as e:
        LOG.error("Port or Network not found, Error: %s" % str(e))
        raise exception.PortNotFound(port_id=port, net_id=network)
    except NvpApiClient.NvpApiException as e:
        raise exception.QuantumException()
    return jsonutils.loads(resp_obj)
Esempio n. 19
0
def get_port_status(cluster, lswitch_id, port_id):
    """Retrieve the operational status of the port"""
    try:
        r = do_single_request("GET",
                              "/ws.v1/lswitch/%s/lport/%s/status" %
                              (lswitch_id, port_id), cluster=cluster)
        r = json.loads(r)
    except NvpApiClient.ResourceNotFound as e:
        LOG.error("Port not found, Error: %s" % str(e))
        raise exception.PortNotFound(port_id=port_id, net_id=lswitch_id)
    except NvpApiClient.NvpApiException as e:
        raise exception.QuantumException()
    if r['link_status_up'] is True:
        return constants.PORT_STATUS_ACTIVE
    else:
        return constants.PORT_STATUS_DOWN
Esempio n. 20
0
def port_destroy(net_id, port_id):
    # confirm network exists
    network_get(net_id)

    session = get_session()
    try:
        port = (session.query(models.Port).filter_by(uuid=port_id).filter_by(
            network_id=net_id).one())
        if port['interface_id']:
            raise q_exc.PortInUse(net_id=net_id,
                                  port_id=port_id,
                                  device_id=port['interface_id'])
        session.delete(port)
        session.flush()
        return port
    except exc.NoResultFound:
        raise q_exc.PortNotFound(port_id=port_id)
Esempio n. 21
0
def get_port_by_display_name(clusters, lswitch, display_name):
    """Return (url, cluster_id) of port or raises ResourceNotFound
    """
    query = ("/ws.v1/lswitch/%s/lport?display_name=%s&fields=*" %
             (lswitch, display_name))
    LOG.debug("Looking for port with display_name \"%s\" on: %s"
              % (display_name, lswitch))
    for c in clusters:
        try:
            res_obj = do_single_request('GET', query, cluster=c)
        except Exception as e:
            continue
        res = json.loads(res_obj)
        if len(res["results"]) == 1:
            return (res["results"][0], c)

    LOG.error("Port or Network not found, Error: %s" % str(e))
    raise exception.PortNotFound(port_id=display_name, net_id=lswitch)
Esempio n. 22
0
def get_port_stats(controller, network_id, port_id):
    try:
        do_single_request("GET",
                          "/ws.v1/lswitch/%s" % (network_id),
                          controller=controller)
    except NvpApiClient.ResourceNotFound as e:
        LOG.error("Network not found, Error: %s" % str(e))
        raise exception.NetworkNotFound(net_id=network_id)
    try:
        path = "/ws.v1/lswitch/%s/lport/%s/statistic" % (network_id, port_id)
        resp = do_single_request("GET", path, controller=controller)
        stats = jsonutils.loads(resp)
    except NvpApiClient.ResourceNotFound as e:
        LOG.error("Port not found, Error: %s" % str(e))
        raise exception.PortNotFound(port_id=port_id, net_id=network_id)
    except NvpApiClient.NvpApiException as e:
        raise exception.QuantumException()
    LOG.debug("Returning stats for port \"%s\" on \"%s\": %s" %
              (port_id, network_id, stats))
    return stats
Esempio n. 23
0
def get_port_by_quantum_tag(clusters, lswitch, quantum_tag):
    """Return (url, cluster_id) of port or raises ResourceNotFound
    """
    query = ("/ws.v1/lswitch/%s/lport?fields=admin_status_enabled,"
             "fabric_status_up,uuid&tag=%s&tag_scope=q_port_id"
             "&relations=LogicalPortStatus" % (lswitch, quantum_tag))

    LOG.debug("Looking for port with q_tag \"%s\" on: %s"
              % (quantum_tag, lswitch))
    for c in clusters:
        try:
            res_obj = do_single_request('GET', query, cluster=c)
        except Exception as e:
            continue
        res = json.loads(res_obj)
        if len(res["results"]) == 1:
            return (res["results"][0], c)

    LOG.error("Port or Network not found, Error: %s" % str(e))
    raise exception.PortNotFound(port_id=quantum_tag, net_id=lswitch)
Esempio n. 24
0
    def delete_port(self, context, id):
        """
        Deletes a port on a specified Virtual Network,
        if the port contains a remote interface attachment,
        the remote interface is first un-plugged and then the port
        is deleted.

        :returns: None
        :raises: exception.PortInUse
        :raises: exception.PortNotFound
        :raises: exception.NetworkNotFound
        """

        port, cluster = nvplib.get_port_by_quantum_tag(self.clusters, '*', id)
        if port is None:
            raise exception.PortNotFound(port_id=id)
        # TODO(bgh): if this is a bridged network and the lswitch we just got
        # back will have zero ports after the delete we should garbage collect
        # the lswitch.
        nvplib.delete_port(cluster, port)

        LOG.debug("delete_port() completed for tenant: %s" % context.tenant_id)
        return super(NvpPluginV2, self).delete_port(context, id)
Esempio n. 25
0
def update_port(network, port_id, **params):
    cluster = params["cluster"]
    lport_obj = {}

    admin_state_up = params['port'].get('admin_state_up')
    name = params["port"].get("name")
    if admin_state_up:
        lport_obj["admin_status_enabled"] = admin_state_up
    if name:
        lport_obj["display_name"] = name

    uri = "/ws.v1/lswitch/" + network + "/lport/" + port_id
    try:
        resp_obj = do_single_request("PUT", uri, json.dumps(lport_obj),
                                     cluster=cluster)
    except NvpApiClient.ResourceNotFound as e:
        LOG.error("Port or Network not found, Error: %s" % str(e))
        raise exception.PortNotFound(port_id=port_id, net_id=network)
    except NvpApiClient.NvpApiException as e:
        raise exception.QuantumException()

    obj = json.loads(resp_obj)
    obj["port-op-status"] = get_port_status(cluster, network, obj["uuid"])
    return obj