def update_port(cluster, lswitch_uuid, lport_uuid, neutron_port_id, tenant_id, display_name, device_id, admin_status_enabled, mac_address=None, fixed_ips=None, port_security_enabled=None, security_profiles=None, queue_id=None, mac_learning_enabled=None, allowed_address_pairs=None): lport_obj = dict( admin_status_enabled=admin_status_enabled, display_name=utils.check_and_truncate(display_name), tags=utils.get_tags(os_tid=tenant_id, q_port_id=neutron_port_id, vm_id=utils.device_id_to_vm_id(device_id))) _configure_extensions(lport_obj, mac_address, fixed_ips, port_security_enabled, security_profiles, queue_id, mac_learning_enabled, allowed_address_pairs) path = "/ws.v1/lswitch/" + lswitch_uuid + "/lport/" + lport_uuid try: result = nsxlib.do_request(HTTP_PUT, path, jsonutils.dumps(lport_obj), cluster=cluster) LOG.debug("Updated logical port %(result)s " "on logical switch %(uuid)s", {'result': result['uuid'], 'uuid': lswitch_uuid}) return result except exception.NotFound as e: LOG.error(_LE("Port or Network not found, Error: %s"), str(e)) raise exception.PortNotFoundOnNetwork( port_id=lport_uuid, net_id=lswitch_uuid)
def delete_port(cluster, switch, port): uri = "/ws.v1/lswitch/" + switch + "/lport/" + port try: nsxlib.do_request(HTTP_DELETE, uri, cluster=cluster) except exception.NotFound as e: LOG.error("Port or Network not found, Error: %s", str(e)) raise exception.PortNotFoundOnNetwork(net_id=switch, port_id=port) except api_exc.NsxApiException: raise exception.NeutronException()
def get_port(cluster, network, port, relations=None): LOG.info(_LI("get_port() %(network)s %(port)s"), {'network': network, 'port': port}) uri = "/ws.v1/lswitch/" + network + "/lport/" + port + "?" if relations: uri += "relations=%s" % relations try: return nsxlib.do_request(HTTP_GET, uri, cluster=cluster) except exception.NotFound as e: LOG.error(_LE("Port or Network not found, Error: %s"), str(e)) raise exception.PortNotFoundOnNetwork( port_id=port, net_id=network)
def get_port_status(cluster, lswitch_id, port_id): """Retrieve the operational status of the port.""" try: r = nsxlib.do_request(HTTP_GET, "/ws.v1/lswitch/%s/lport/%s/status" % (lswitch_id, port_id), cluster=cluster) except exception.NotFound as e: LOG.error(_LE("Port not found, Error: %s"), str(e)) raise exception.PortNotFoundOnNetwork( port_id=port_id, net_id=lswitch_id) if r['link_status_up'] is True: return constants.PORT_STATUS_ACTIVE else: return constants.PORT_STATUS_DOWN
def create_ip_address(context, body): LOG.info("create_ip_address for tenant %s" % context.tenant_id) iptype = (ip_types.SHARED if _shared_ip_request(body) else ip_types.FIXED) if 'ip_address' not in body: raise n_exc.BadRequest(resource="ip_addresses", msg="Invalid request body.") if iptype == ip_types.FIXED and not CONF.QUARK.ipaddr_allow_fixed_ip: raise n_exc.BadRequest(resource="ip_addresses", msg="Only shared IPs may be made with " "this resource.") ip_dict = body.get("ip_address") port_ids = ip_dict.get('port_ids', []) network_id = ip_dict.get('network_id') device_ids = ip_dict.get('device_ids') ip_version = ip_dict.get('version') ip_address = ip_dict.get('ip_address') # If no version is passed, you would get what the network provides, # which could be both v4 and v6 addresses. Rather than allow for such # an ambiguous outcome, we'll raise instead if not ip_version: raise n_exc.BadRequest(resource="ip_addresses", msg="version is required.") if network_id is None: raise n_exc.BadRequest(resource="ip_addresses", msg="network_id is required.") if network_id == "": raise n_exc.NetworkNotFound(net_id=network_id) net = db_api.network_find(context, None, None, None, False, id=network_id, scope=db_api.ONE) if not net: raise n_exc.NetworkNotFound(net_id=network_id) if not port_ids and not device_ids: raise n_exc.BadRequest(resource="ip_addresses", msg="port_ids or device_ids required.") new_addresses = [] ports = [] by_device = False with context.session.begin(): if network_id and device_ids: by_device = True for device_id in device_ids: port = db_api.port_find(context, network_id=network_id, device_id=device_id, tenant_id=context.tenant_id, scope=db_api.ONE) if port is not None: ports.append(port) elif port_ids: for port_id in port_ids: port = db_api.port_find(context, id=port_id, tenant_id=context.tenant_id, scope=db_api.ONE) if port is not None: ports.append(port) if not ports: raise n_exc.PortNotFoundOnNetwork(port_id=port_ids, net_id=network_id) if ((by_device and len(device_ids) != len(ports)) or (not by_device and len(port_ids) != len(ports))): raise q_exc.NotAllPortOrDeviceFound() segment_id = validate_and_fetch_segment(ports, network_id) if iptype == ip_types.SHARED: old_addresses = db_api.ip_address_find(context, network_id=network_id, address_type=ip_types.SHARED, scope=db_api.ALL) validate_shared_ips_quotas(context, network_id, old_addresses) validate_port_ip_quotas(context, network_id, ports) # Shared Ips are only new IPs. Two use cases: if we got device_id # or if we got port_ids. We should check the case where we got port_ids # and device_ids. The device_id must have a port on the network, # and any port_ids must also be on that network already. If we have # more than one port by this step, it's considered a shared IP, # and therefore will be marked as unconfigured (enabled=False) # for all ports. ipam_driver.allocate_ip_address( context, new_addresses, network_id, None, CONF.QUARK.ipam_reuse_after, version=ip_version, ip_addresses=[ip_address] if ip_address else [], segment_id=segment_id, address_type=iptype) with context.session.begin(): address = new_addresses[0] new_address = db_api.port_associate_ip(context, ports, address) return v._make_ip_dict(new_address)