# HTTP METHODS CONSTANTS
HTTP_GET = "GET"
HTTP_POST = "POST"
+HTTP_DELETE = "DELETE"
+HTTP_PUT = "PUT"
# Default transport type for logical switches
DEF_TRANSPORT_TYPE = "stt"
# Prefix to be used for all NVP API calls
LOG.debug(_("Looking for lswitch with port id "
"'%(port_id)s' on: %(c)s"), locals())
try:
- res = do_single_request('GET', query, cluster=c)
+ res = do_single_request(HTTP_GET, query, cluster=c)
except Exception as e:
LOG.error(_("get_port_cluster_and_url, exception: %s"), str(e))
continue
if "tags" in kwargs:
lswitch_obj["tags"].extend(kwargs["tags"])
try:
- resp_obj = do_single_request("PUT", uri, json.dumps(lswitch_obj),
+ resp_obj = do_single_request(HTTP_PUT, uri, json.dumps(lswitch_obj),
cluster=cluster)
except NvpApiClient.ResourceNotFound as e:
LOG.error(_("Network not found, Error: %s"), str(e))
"type": "LogicalRouterConfig"
}
try:
- return json.loads(do_single_request("POST",
+ return json.loads(do_single_request(HTTP_POST,
_build_uri_path(LROUTER_RESOURCE),
json.dumps(lrouter_obj),
cluster=cluster))
def delete_lrouter(cluster, lrouter_id):
try:
- do_single_request("DELETE",
+ do_single_request(HTTP_DELETE,
_build_uri_path(LROUTER_RESOURCE,
resource_id=lrouter_id),
cluster=cluster)
def get_lrouter(cluster, lrouter_id):
try:
- return json.loads(do_single_request("GET",
+ return json.loads(do_single_request(HTTP_GET,
_build_uri_path(LROUTER_RESOURCE,
resource_id=lrouter_id,
relations='LogicalRouterStatus'),
if nh_element:
nh_element["gateway_ip_address"] = nexthop
try:
- return json.loads(do_single_request("PUT",
+ return json.loads(do_single_request(HTTP_PUT,
_build_uri_path(LROUTER_RESOURCE,
resource_id=lrouter_id),
json.dumps(lrouter_obj),
"""
uri = "/ws.v1/lswitch?fields=*&tag=%s&tag_scope=os_tid" % tenant_id
try:
- resp_obj = do_single_request("GET", uri, cluster=cluster)
+ resp_obj = do_single_request(HTTP_GET, uri, cluster=cluster)
except NvpApiClient.NvpApiException:
raise exception.QuantumException()
if not resp_obj:
for t in tags:
uri += "&tag=%s&tag_scope=%s" % (t[0], t[1])
try:
- resp_obj = do_single_request("GET", uri, cluster=cluster)
+ resp_obj = do_single_request(HTTP_GET, uri, cluster=cluster)
except NvpApiClient.NvpApiException:
raise exception.QuantumException()
if not resp_obj:
path = "/ws.v1/lswitch/%s" % ls_id
try:
- do_single_request("DELETE", path, cluster=cluster)
+ do_single_request(HTTP_DELETE, path, cluster=cluster)
except NvpApiClient.ResourceNotFound as e:
LOG.error(_("Network not found, Error: %s"), str(e))
raise exception.NetworkNotFound(net_id=ls_id)
uri = _build_uri_path(LSWITCHPORT_RESOURCE, parent_resource_id=ls_uuid,
fields=fields, filters=filters, relations=relations)
try:
- resp_obj = do_single_request("GET", uri, cluster=cluster)
+ resp_obj = do_single_request(HTTP_GET, uri, cluster=cluster)
except NvpApiClient.ResourceNotFound:
LOG.exception(_("Logical switch: %s not found"), ls_uuid)
raise
uri = _build_uri_path(LROUTERPORT_RESOURCE, parent_resource_id=lr_uuid,
fields=fields, filters=filters, relations=relations)
try:
- resp_obj = do_single_request("GET", uri, cluster=cluster)
+ resp_obj = do_single_request(HTTP_GET, uri, cluster=cluster)
except NvpApiClient.ResourceNotFound:
LOG.exception(_("Logical router: %s not found"), lr_uuid)
raise
def delete_port(cluster, switch, port):
uri = "/ws.v1/lswitch/" + switch + "/lport/" + port
try:
- do_single_request("DELETE", uri, cluster=cluster)
+ do_single_request(HTTP_DELETE, uri, 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'])
query = ("/ws.v1/lswitch/" + switch + "/lport/"
+ port + "?relations=LogicalPortStatus")
try:
- res_obj = do_single_request('GET', query, cluster=cluster)
+ res_obj = do_single_request(HTTP_GET, query, cluster=cluster)
except NvpApiClient.ResourceNotFound as e:
LOG.error(_("Port or Network not found, Error: %s"), str(e))
raise exception.PortNotFound(port_id=port, net_id=switch)
"'%(display_name)s' on: %(lswitch)s"), locals())
for c in clusters:
try:
- res_obj = do_single_request('GET', query, cluster=c)
+ res_obj = do_single_request(HTTP_GET, query, cluster=c)
except Exception as e:
continue
res = json.loads(res_obj)
if relations:
uri += "relations=%s" % relations
try:
- resp_obj = do_single_request("GET", uri, cluster=cluster)
+ resp_obj = do_single_request(HTTP_GET, uri, cluster=cluster)
port = json.loads(resp_obj)
except NvpApiClient.ResourceNotFound as e:
LOG.error(_("Port or Network not found, Error: %s"), str(e))
path = "/ws.v1/lswitch/" + lswitch_uuid + "/lport/" + lport_uuid
try:
- resp_obj = do_single_request("PUT", path, json.dumps(lport_obj),
+ resp_obj = do_single_request(HTTP_PUT, path, json.dumps(lport_obj),
cluster=cluster)
except NvpApiClient.ResourceNotFound as e:
LOG.error(_("Port or Network not found, Error: %s"), str(e))
path = _build_uri_path(LSWITCHPORT_RESOURCE,
parent_resource_id=lswitch_uuid)
try:
- resp_obj = do_single_request("POST", path,
+ resp_obj = do_single_request(HTTP_POST, path,
json.dumps(lport_obj),
cluster=cluster)
except NvpApiClient.ResourceNotFound as e:
path = _build_uri_path(LROUTERPORT_RESOURCE,
parent_resource_id=lrouter_uuid)
try:
- resp_obj = do_single_request("POST", path,
+ resp_obj = do_single_request(HTTP_POST, path,
json.dumps(lport_obj),
cluster=cluster)
except NvpApiClient.ResourceNotFound as e:
lrouter_port_uuid,
parent_resource_id=lrouter_uuid)
try:
- resp_obj = do_single_request("PUT", path,
+ resp_obj = do_single_request(HTTP_PUT, path,
json.dumps(lport_obj),
cluster=cluster)
except NvpApiClient.ResourceNotFound as e:
""" Creates a logical port on the assigned logical router """
path = _build_uri_path(LROUTERPORT_RESOURCE, lport_uuid, lrouter_uuid)
try:
- do_single_request("DELETE", path, cluster=cluster)
+ do_single_request(HTTP_DELETE, path, cluster=cluster)
except NvpApiClient.ResourceNotFound as e:
LOG.error(_("Logical router not found, Error: %s"), str(e))
raise
nvp_attachment_type)
try:
resp_obj = do_single_request(
- "PUT", uri, json.dumps(attach_obj), cluster=cluster)
+ HTTP_PUT, uri, json.dumps(attach_obj), cluster=cluster)
except NvpApiClient.ResourceNotFound as e:
LOG.exception(_("Router Port not found, Error: %s"), str(e))
raise
def get_port_status(cluster, lswitch_id, port_id):
"""Retrieve the operational status of the port"""
try:
- r = do_single_request("GET",
+ r = do_single_request(HTTP_GET,
"/ws.v1/lswitch/%s/lport/%s/status" %
(lswitch_id, port_id), cluster=cluster)
r = json.loads(r)
lport_obj["type"] = type
try:
- resp_obj = do_single_request("PUT", uri, json.dumps(lport_obj),
+ resp_obj = do_single_request(HTTP_PUT, uri, json.dumps(lport_obj),
cluster=cluster)
except NvpApiClient.ResourceNotFound as e:
LOG.error(_("Port or Network not found, Error: %s"), str(e))
tags=tags, display_name=security_profile.get('name'),
logical_port_ingress_rules=dhcp['logical_port_ingress_rules'],
logical_port_egress_rules=dhcp['logical_port_egress_rules'])
- rsp = do_request("POST", path, body, cluster=cluster)
+ rsp = do_request(HTTP_POST, path, body, cluster=cluster)
except NvpApiClient.NvpApiException as e:
LOG.error(format_exception("Unknown", e, locals()))
raise exception.QuantumException()
body = mk_body(
logical_port_ingress_rules=rules['logical_port_ingress_rules'],
logical_port_egress_rules=rules['logical_port_egress_rules'])
- rsp = do_request("PUT", path, body, cluster=cluster)
+ rsp = do_request(HTTP_PUT, path, body, cluster=cluster)
except NvpApiClient.NvpApiException as e:
LOG.error(format_exception("Unknown", e, locals()))
raise exception.QuantumException()
path = "/ws.v1/security-profile/%s" % spid
try:
- do_request("DELETE", path, cluster=cluster)
+ do_request(HTTP_DELETE, path, cluster=cluster)
except NvpApiClient.NvpApiException as e:
LOG.error(format_exception("Unknown", e, locals()))
raise exception.QuantumException()
LOG.debug(_("Creating NAT rule: %s"), nat_rule_obj)
uri = _build_uri_path(LROUTERNAT_RESOURCE, parent_resource_id=router_id)
try:
- resp = do_single_request("POST", uri, json.dumps(nat_rule_obj),
+ resp = do_single_request(HTTP_POST, uri, json.dumps(nat_rule_obj),
cluster=cluster)
except NvpApiClient.ResourceNotFound:
LOG.exception(_("NVP Logical Router %s not found"), router_id)
def delete_router_nat_rule(cluster, router_id, rule_id):
uri = _build_uri_path(LROUTERNAT_RESOURCE, rule_id, router_id)
try:
- do_single_request("DELETE", uri, cluster=cluster)
+ do_single_request(HTTP_DELETE, uri, cluster=cluster)
except NvpApiClient.NvpApiException:
LOG.exception(_("An error occurred while removing NAT rule "
"'%(nat_rule_uuid)s' for logical "
def get_router_nat_rule(cluster, tenant_id, router_id, rule_id):
uri = _build_uri_path(LROUTERNAT_RESOURCE, rule_id, router_id)
try:
- resp = do_single_request("GET", uri, cluster=cluster)
+ resp = do_single_request(HTTP_GET, uri, cluster=cluster)
except NvpApiClient.ResourceNotFound:
LOG.exception(_("NAT rule %s not found"), rule_id)
raise
uri = _build_uri_path(LROUTERNAT_RESOURCE, parent_resource_id=router_id,
fields=fields, filters=filters)
try:
- resp = do_single_request("GET", uri, cluster=cluster)
+ resp = do_single_request(HTTP_GET, uri, cluster=cluster)
except NvpApiClient.ResourceNotFound:
LOG.exception(_("NVP Logical Router '%s' not found"), router_id)
raise
ips_to_add, ips_to_remove):
uri = _build_uri_path(LROUTERPORT_RESOURCE, lport_id, lrouter_id)
try:
- port = json.loads(do_single_request("GET", uri, cluster=cluster))
+ port = json.loads(do_single_request(HTTP_GET, uri, cluster=cluster))
# TODO(salvatore-orlando): Enforce ips_to_add intersection with
# ips_to_remove is empty
ip_address_set = set(port['ip_addresses'])
ip_address_set = ip_address_set | set(ips_to_add)
# Set is not JSON serializable - convert to list
port['ip_addresses'] = list(ip_address_set)
- do_single_request("PUT", uri, json.dumps(port), cluster=cluster)
+ do_single_request(HTTP_PUT, uri, json.dumps(port), cluster=cluster)
except NvpApiClient.ResourceNotFound as e:
msg = (_("Router Port %(lport_id)s not found on router "
"%(lrouter_id)s") % locals())