From: Steven Van Rossem Date: Tue, 31 Oct 2017 12:27:16 +0000 (+0100) Subject: update rest api to add/remove interface to E-LAN X-Git-Tag: v3.1~1^2~6 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=2c301b1409ff9b5e7b3ff258002d7222902fcf53;p=osm%2Fvim-emu.git update rest api to add/remove interface to E-LAN --- diff --git a/src/emuvim/api/rest/network.py b/src/emuvim/api/rest/network.py index 9aab1e6..46d1ea1 100755 --- a/src/emuvim/api/rest/network.py +++ b/src/emuvim/api/rest/network.py @@ -122,6 +122,64 @@ class NetworkAction(Resource): logging.exception("API error.") return ex.message, 500, CORS_HEADER +class NetworkLAN(Resource): + """ + Add or remove VNF interfaces to an existing LAN, by manipulating the vlan tag of the connected datacenter interface + :param vnf_name: VNF name of the source of the link + :param vnf_interface: VNF interface name of the source of the link + :param vlan_tag: vlan tag (integer > 0) or thsi interface + """ + global net + + def put(self): + logging.debug("REST CALL: network LAN add") + + try: + + data = request.json + if data is None: + data = request.args + if data is None: + data = {} + + vnf_name = data.get("vnf_name") + vnf_interface = data.get("vnf_interface") + vlan_tag = data.get("vlan_tag") + + vnf_list = [{'name':vnf_name, 'interface':vnf_interface}] + + c = net.setLAN(vnf_list, vlan=vlan_tag, action='add') + # return setChain response + return str(c), 200, CORS_HEADER + + except Exception as ex: + logging.exception("API error.") + return ex.message, 500, CORS_HEADER + + def delete(self): + logging.debug("REST CALL: network LAN remove") + + try: + + data = request.json + if data is None: + data = request.args + if data is None: + data = {} + + vnf_name = data.get("vnf_name") + vnf_interface = data.get("vnf_interface") + vlan_tag = data.get("vlan_tag") + + vnf_list = [{'name': vnf_name, 'interface': vnf_interface}] + + c = net.setLAN(vnf_list, vlan=vlan_tag, action='delete') + # return setChain response + return str(c), 200, CORS_HEADER + + except Exception as ex: + logging.exception("API error.") + return ex.message, 500, CORS_HEADER class DrawD3jsgraph(Resource): diff --git a/src/emuvim/api/rest/rest_api_endpoint.py b/src/emuvim/api/rest/rest_api_endpoint.py index 0539e7d..cd4e1a0 100755 --- a/src/emuvim/api/rest/rest_api_endpoint.py +++ b/src/emuvim/api/rest/rest_api_endpoint.py @@ -38,7 +38,7 @@ from compute import dcs, ComputeList, Compute, ComputeResources, DatacenterList, # need to import total module to set its global variable net import network -from network import NetworkAction, DrawD3jsgraph +from network import NetworkAction, NetworkLAN, DrawD3jsgraph import monitor from monitor import MonitorInterfaceAction, MonitorFlowAction, MonitorLinkAction, MonitorSkewAction, MonitorTerminal @@ -88,6 +88,8 @@ class RestApiEndpoint(object): # network related actions (setup chaining between VNFs) self.api.add_resource(NetworkAction, "/restapi/network") + self.api.add_resource(NetworkLAN, + "/restapi/networkLAN") self.api.add_resource(DrawD3jsgraph, "/restapi/network/d3jsgraph") diff --git a/src/emuvim/cli/rest/network.py b/src/emuvim/cli/rest/network.py index 82fe99f..d5450e7 100755 --- a/src/emuvim/cli/rest/network.py +++ b/src/emuvim/cli/rest/network.py @@ -73,6 +73,26 @@ class RestApiClient(): params=params) print(self._nice_print(response.text)) + def addLAN(self, args): + params = self._create_dict( + vnf_name=self._parse_vnf_name(args.get("source")), + vnf_interface=self._parse_vnf_interface(args.get("source")), + vlan_tag=args.get("vlan")) + + response = put("{0}/restapi/networkLAN".format(args.get("endpoint")), + params=params) + print(self._nice_print(response.text)) + + def removeLAN(self, args): + params = self._create_dict( + vnf_src_name=self._parse_vnf_name(args.get("source")), + vnf_src_interface=self._parse_vnf_interface(args.get("source")), + vlan=args.get("vlan")) + + response = delete("{0}/restapi/networkLAN".format(args.get("endpoint")), + params=params) + print(self._nice_print(response.text)) + def _parse_vnf_name(self, vnf_name_str): vnf_name = vnf_name_str.split(':')[0] return vnf_name @@ -97,17 +117,17 @@ class RestApiClient(): parser = argparse.ArgumentParser(description='son-emu-cli network') parser.add_argument( "command", - choices=['add', 'remove'], + choices=['add', 'remove', 'addLAN', 'removeLAN'], help="Action to be executed.") parser.add_argument( "--datacenter", "-d", dest="datacenter", help="Data center to in which the network action should be initiated") parser.add_argument( "--source", "-src", dest="source", - help="vnf name of the source of the chain") + help="vnf name:interface of the source of the chain") parser.add_argument( "--destination", "-dst", dest="destination", - help="vnf name of the destination of the chain") + help="vnf name:interface of the destination of the chain") parser.add_argument( "--weight", "-w", dest="weight", help="weight edge attribute to calculate the path") @@ -123,6 +143,9 @@ parser.add_argument( parser.add_argument( "--cookie", "-c", dest="cookie", default="10", help="cookie for this flow, as easy to use identifier (eg. per tenant/service)") +parser.add_argument( + "--vlan", "-vl", dest="vlan", + help="vlan tag to be used with the specified LAN interface") parser.add_argument( "--endpoint", "-e", dest="endpoint", default="http://127.0.0.1:5001",