Loading src/common/tools/object_factory/OpticalLink.py +14 −2 Original line number Diff line number Diff line Loading @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. import copy import copy , logging from common.proto.context_pb2 import TopologyDetails def convert_to_dict(single_val:int)->dict: slot= dict() Loading Loading @@ -85,3 +86,14 @@ def order_dict_v1 (dct:dict)->dict: if (len(ordered_lst)>0): return list_to_dict (ordered_lst) def extract_endpoint_names (topo_detail: TopologyDetails) -> dict : endpoint_names = {} if topo_detail is None : raise ValueError("Topology Details can not be of type None ") for device in topo_detail.devices : for ep in device.device_endpoints : ep_uuid = ep.endpoint_id.endpoint_uuid.uuid if ep_uuid not in endpoint_names: endpoint_names[ep_uuid]={'name':ep.name,'type':ep.endpoint_type} return endpoint_names No newline at end of file src/tapi/client/TapiClient.py +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ class TapiClient: self.channel = grpc.insecure_channel(self.endpoint) #self.channel = grpc.insecure_channel('10.30.7.61:30491') #self.channel = grpc.insecure_channel('10.30.7.61:32427') grpc.channel_ready_future(self.channel).result(timeout=5) self.stub = TapiServiceStub(self.channel) LOGGER.info("Successfully connected to gRPC server at %s", self.endpoint) Loading src/webui/service/__init__.py +5 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,10 @@ def get_working_context() -> str: def get_working_topology() -> str: return session['topology_uuid'] if 'topology_uuid' in session else '---' def get_remote_address () -> str : return session['tapi_endpoint'] if 'tapi_endpoint' in session else '---' def liveness(): pass Loading Loading @@ -131,6 +135,7 @@ def create_app(use_config=None, web_app_root=None): 'round' : round, 'get_working_context' : get_working_context, 'get_working_topology': get_working_topology, 'get_remote_address' : get_remote_address, 'is_deployed_bgpls' : is_deployed_bgpls, 'is_deployed_load_gen': is_deployed_load_gen, Loading src/webui/service/tapi/forms.py +12 −2 Original line number Diff line number Diff line Loading @@ -14,11 +14,21 @@ from flask_wtf import FlaskForm from wtforms import StringField , IntegerField ,SubmitField from flask_wtf.file import FileAllowed from wtforms import StringField , IntegerField ,SubmitField , FileField class SocketForm(FlaskForm): ip = StringField('Ip') port = IntegerField("Port") submit = SubmitField('Connect') class UploadService(FlaskForm): descriptors = FileField( 'Descriptors', validators=[ FileAllowed(['json'], 'JSON Descriptors only!') ]) submit = SubmitField('Submit') No newline at end of file src/webui/service/tapi/routes.py +77 −25 Original line number Diff line number Diff line Loading @@ -18,15 +18,17 @@ from flask import ( current_app, make_response ) from common.proto.context_pb2 import ( Empty, OpticalConfig, OpticalConfigId, OpticalConfigList , TopologyId Empty, ServiceList, OpticalLink , TopologyId ) from common.tools.object_factory.OpticalLink import extract_endpoint_names from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from service.client.ServiceClient import ServiceClient from slice.client.SliceClient import SliceClient from tapi.client.TapiClient import TapiClient from .forms import SocketForm from .forms import SocketForm , UploadService from google.protobuf.json_format import Parse tapi = Blueprint('tapi', __name__, url_prefix="/tapi") Loading @@ -40,20 +42,29 @@ LOGGER = logging.getLogger(__name__) DESCRIPTOR_LOADER_NUM_WORKERS = 10 @tapi.route('/tapi_main',methods=["GET"]) def tapi_main () : session.pop('tapi_endpoint',None) return redirect(url_for('tapi.home')) @tapi.route("/" , methods=['GET', 'POST']) def home() : topo_lsts = None # if 'context_uuid' not in session or 'topology_uuid' not in session: # flash("Please select a context!", "warning") # return redirect(url_for("main.home")) socket_form = SocketForm () ip = None port = None tapi_client=None if request.method == 'GET' : if 'tapi_endpoint' in session : ip,port = session['tapi_endpoint'].split(':') if socket_form.validate_on_submit(): ip = socket_form.ip.data port = socket_form.port.data if ip is not None and port is not None : try: tapi_client = TapiClient(ip , port) LOGGER.info(f'tapi started {ip }: {port} ') if tapi_client is not None : Loading @@ -71,6 +82,7 @@ def home() : flash(f'Connection is failed: `{str(err)}`', 'danger') finally: if tapi_client is not None : tapi_client.close() return render_template('tapi/home.html', socket_form=socket_form) Loading @@ -80,6 +92,7 @@ def home() : @tapi.route("/retmote_topo/<path:topo_uuid>/<path:context_uuid>" , methods=['GET', 'POST']) def get_retmote_topo (topo_uuid :str ,context_uuid :str) : topo=None endpoints_names={} if 'tapi_endpoint' in session : try: ip ,port = session['tapi_endpoint'].split(':') Loading @@ -92,17 +105,56 @@ def get_retmote_topo (topo_uuid :str ,context_uuid :str) : topo_id.context_id.context_uuid.uuid=context_uuid topo=tapi_client.GetTopology(topo_id) #topo_lsts = tapi_client.CheckConnectivity() endpoints_names = extract_endpoint_names(topo) LOGGER.info(f'topo existed {topo}') except Exception as err : LOGGER.info(f" error from connecting tapi {err}") flash(f'Connection is failed: `{str(err)}`', 'danger') finally: tapi_client.close() else : flash("Please Connect To Desired Machine First!", "warning") return redirect(url_for("tapi.home")) logging.info(f"endpoinst_names { endpoints_names}") return render_template( 'tapi/topo_detail.html',topo=topo,endpoints_names=endpoints_names) return render_template( 'tapi/topo_detail.html',topo=topo) @tapi.route("/set_retmote_service/<path:topo_uuid>/<path:context_uuid>" , methods=['GET', 'POST']) def add_service (topo_uuid :str ,context_uuid :str) : ip = None port = None service_form = UploadService() if 'tapi_endpoint' in session : ip,port = session['tapi_endpoint'].split(':') else : flash("Please Connect To Desired Machine First!", "warning") return redirect(url_for("tapi.home")) if service_form.validate_on_submit(): descriptors_file = request.files[service_form.descriptors.name] descriptors_data = descriptors_file.read() descriptors = json.loads(descriptors_data) request_message = Parse(json.dumps(descriptors), ServiceList()) tapi_client = TapiClient(ip , port) if tapi_client is not None : try: tapi_client.SetService(request_message) flash(f'Service is deployed successfully to {ip}:{port}', 'success') return redirect(url_for('tapi.tapi_main')) except Exception as err : LOGGER.info(f" error from connecting tapi {err}") flash(f'Connection is failed: `{str(err)}`', 'danger') finally: tapi_client.close() else : flash(f'Error in Connction ', 'danger') return render_template('tapi/add_service.html', service_form=service_form) No newline at end of file Loading
src/common/tools/object_factory/OpticalLink.py +14 −2 Original line number Diff line number Diff line Loading @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. import copy import copy , logging from common.proto.context_pb2 import TopologyDetails def convert_to_dict(single_val:int)->dict: slot= dict() Loading Loading @@ -85,3 +86,14 @@ def order_dict_v1 (dct:dict)->dict: if (len(ordered_lst)>0): return list_to_dict (ordered_lst) def extract_endpoint_names (topo_detail: TopologyDetails) -> dict : endpoint_names = {} if topo_detail is None : raise ValueError("Topology Details can not be of type None ") for device in topo_detail.devices : for ep in device.device_endpoints : ep_uuid = ep.endpoint_id.endpoint_uuid.uuid if ep_uuid not in endpoint_names: endpoint_names[ep_uuid]={'name':ep.name,'type':ep.endpoint_type} return endpoint_names No newline at end of file
src/tapi/client/TapiClient.py +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ class TapiClient: self.channel = grpc.insecure_channel(self.endpoint) #self.channel = grpc.insecure_channel('10.30.7.61:30491') #self.channel = grpc.insecure_channel('10.30.7.61:32427') grpc.channel_ready_future(self.channel).result(timeout=5) self.stub = TapiServiceStub(self.channel) LOGGER.info("Successfully connected to gRPC server at %s", self.endpoint) Loading
src/webui/service/__init__.py +5 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,10 @@ def get_working_context() -> str: def get_working_topology() -> str: return session['topology_uuid'] if 'topology_uuid' in session else '---' def get_remote_address () -> str : return session['tapi_endpoint'] if 'tapi_endpoint' in session else '---' def liveness(): pass Loading Loading @@ -131,6 +135,7 @@ def create_app(use_config=None, web_app_root=None): 'round' : round, 'get_working_context' : get_working_context, 'get_working_topology': get_working_topology, 'get_remote_address' : get_remote_address, 'is_deployed_bgpls' : is_deployed_bgpls, 'is_deployed_load_gen': is_deployed_load_gen, Loading
src/webui/service/tapi/forms.py +12 −2 Original line number Diff line number Diff line Loading @@ -14,11 +14,21 @@ from flask_wtf import FlaskForm from wtforms import StringField , IntegerField ,SubmitField from flask_wtf.file import FileAllowed from wtforms import StringField , IntegerField ,SubmitField , FileField class SocketForm(FlaskForm): ip = StringField('Ip') port = IntegerField("Port") submit = SubmitField('Connect') class UploadService(FlaskForm): descriptors = FileField( 'Descriptors', validators=[ FileAllowed(['json'], 'JSON Descriptors only!') ]) submit = SubmitField('Submit') No newline at end of file
src/webui/service/tapi/routes.py +77 −25 Original line number Diff line number Diff line Loading @@ -18,15 +18,17 @@ from flask import ( current_app, make_response ) from common.proto.context_pb2 import ( Empty, OpticalConfig, OpticalConfigId, OpticalConfigList , TopologyId Empty, ServiceList, OpticalLink , TopologyId ) from common.tools.object_factory.OpticalLink import extract_endpoint_names from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from service.client.ServiceClient import ServiceClient from slice.client.SliceClient import SliceClient from tapi.client.TapiClient import TapiClient from .forms import SocketForm from .forms import SocketForm , UploadService from google.protobuf.json_format import Parse tapi = Blueprint('tapi', __name__, url_prefix="/tapi") Loading @@ -40,20 +42,29 @@ LOGGER = logging.getLogger(__name__) DESCRIPTOR_LOADER_NUM_WORKERS = 10 @tapi.route('/tapi_main',methods=["GET"]) def tapi_main () : session.pop('tapi_endpoint',None) return redirect(url_for('tapi.home')) @tapi.route("/" , methods=['GET', 'POST']) def home() : topo_lsts = None # if 'context_uuid' not in session or 'topology_uuid' not in session: # flash("Please select a context!", "warning") # return redirect(url_for("main.home")) socket_form = SocketForm () ip = None port = None tapi_client=None if request.method == 'GET' : if 'tapi_endpoint' in session : ip,port = session['tapi_endpoint'].split(':') if socket_form.validate_on_submit(): ip = socket_form.ip.data port = socket_form.port.data if ip is not None and port is not None : try: tapi_client = TapiClient(ip , port) LOGGER.info(f'tapi started {ip }: {port} ') if tapi_client is not None : Loading @@ -71,6 +82,7 @@ def home() : flash(f'Connection is failed: `{str(err)}`', 'danger') finally: if tapi_client is not None : tapi_client.close() return render_template('tapi/home.html', socket_form=socket_form) Loading @@ -80,6 +92,7 @@ def home() : @tapi.route("/retmote_topo/<path:topo_uuid>/<path:context_uuid>" , methods=['GET', 'POST']) def get_retmote_topo (topo_uuid :str ,context_uuid :str) : topo=None endpoints_names={} if 'tapi_endpoint' in session : try: ip ,port = session['tapi_endpoint'].split(':') Loading @@ -92,17 +105,56 @@ def get_retmote_topo (topo_uuid :str ,context_uuid :str) : topo_id.context_id.context_uuid.uuid=context_uuid topo=tapi_client.GetTopology(topo_id) #topo_lsts = tapi_client.CheckConnectivity() endpoints_names = extract_endpoint_names(topo) LOGGER.info(f'topo existed {topo}') except Exception as err : LOGGER.info(f" error from connecting tapi {err}") flash(f'Connection is failed: `{str(err)}`', 'danger') finally: tapi_client.close() else : flash("Please Connect To Desired Machine First!", "warning") return redirect(url_for("tapi.home")) logging.info(f"endpoinst_names { endpoints_names}") return render_template( 'tapi/topo_detail.html',topo=topo,endpoints_names=endpoints_names) return render_template( 'tapi/topo_detail.html',topo=topo) @tapi.route("/set_retmote_service/<path:topo_uuid>/<path:context_uuid>" , methods=['GET', 'POST']) def add_service (topo_uuid :str ,context_uuid :str) : ip = None port = None service_form = UploadService() if 'tapi_endpoint' in session : ip,port = session['tapi_endpoint'].split(':') else : flash("Please Connect To Desired Machine First!", "warning") return redirect(url_for("tapi.home")) if service_form.validate_on_submit(): descriptors_file = request.files[service_form.descriptors.name] descriptors_data = descriptors_file.read() descriptors = json.loads(descriptors_data) request_message = Parse(json.dumps(descriptors), ServiceList()) tapi_client = TapiClient(ip , port) if tapi_client is not None : try: tapi_client.SetService(request_message) flash(f'Service is deployed successfully to {ip}:{port}', 'success') return redirect(url_for('tapi.tapi_main')) except Exception as err : LOGGER.info(f" error from connecting tapi {err}") flash(f'Connection is failed: `{str(err)}`', 'danger') finally: tapi_client.close() else : flash(f'Error in Connction ', 'danger') return render_template('tapi/add_service.html', service_form=service_form) No newline at end of file