diff --git a/manifests/tapiservice.yaml b/manifests/tapiservice.yaml index 763bef36658562c9448ca6b58b6536cb4a53335c..5a50ec7800b67c29821d3d7f42a87732feea040a 100644 --- a/manifests/tapiservice.yaml +++ b/manifests/tapiservice.yaml @@ -40,10 +40,10 @@ spec: resources: requests: - cpu: 100m + cpu: 50m memory: 128Mi limits: - cpu: 100m + cpu: 1000m memory: 1024Mi --- apiVersion: v1 diff --git a/manifests/webuiservice.yaml b/manifests/webuiservice.yaml index a778605fdda7942f1951167e2accb77eafad69ca..e28b2bb64adb6b92e2e26a07c8a961460f49d2a3 100644 --- a/manifests/webuiservice.yaml +++ b/manifests/webuiservice.yaml @@ -65,12 +65,12 @@ spec: # image: grafana/grafana:8.5.22 # imagePullPolicy: IfNotPresent # ports: - # - containerPort: 3000 + # - containerPort: 3001 # name: http-grafana # protocol: TCP # env: # - name: GF_SERVER_ROOT_URL - # value: "http://0.0.0.0:3000/grafana/" + # value: "http://0.0.0.0:3001/grafana/" # - name: GF_SERVER_SERVE_FROM_SUB_PATH # value: "true" # readinessProbe: @@ -78,27 +78,27 @@ spec: # httpGet: # #path: /robots.txt # path: /login - # port: 3000 + # port: 3001 # scheme: HTTP - # initialDelaySeconds: 1 + # initialDelaySeconds: 10 # periodSeconds: 1 # successThreshold: 1 - # timeoutSeconds: 2 - livenessProbe: - failureThreshold: 60 - initialDelaySeconds: 1 - periodSeconds: 1 - successThreshold: 1 - tcpSocket: - port: 3000 - timeoutSeconds: 1 - resources: - requests: - cpu: 250m - memory: 512Mi - limits: - cpu: 500m - memory: 1024Mi + # timeoutSeconds: 5 + # livenessProbe: + # failureThreshold: 60 + # initialDelaySeconds: 10 + # periodSeconds: 1 + # successThreshold: 1 + # tcpSocket: + # port: 3001 + # timeoutSeconds: 1 + # resources: + # requests: + # cpu: 350m + # memory: 512Mi + # limits: + # cpu: 600m + # memory: 1024Mi --- apiVersion: v1 kind: Service @@ -115,8 +115,8 @@ spec: port: 8004 targetPort: 8004 # - name: grafana - # port: 3000 - # targetPort: 3000 + # port: 3001 + # targetPort: 3001 --- apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler diff --git a/my_deploy.sh b/my_deploy.sh index 789d3f8ea211643477d9d63210879c62f36561e3..73aaa0aa760eeb38e2aad640b293e500e0e0ac3c 100755 --- a/my_deploy.sh +++ b/my_deploy.sh @@ -20,7 +20,7 @@ export TFS_REGISTRY_IMAGES="http://localhost:32000/tfs/" # Set the list of components, separated by spaces, you want to build images for, and deploy. -export TFS_COMPONENTS="context device pathcomp opticalcontroller qkd_app service slice webui tapi " +export TFS_COMPONENTS="context device pathcomp opticalcontroller service slice webui tapi" # Uncomment to activate Monitoring (old) #export TFS_COMPONENTS="${TFS_COMPONENTS} monitoring" @@ -134,7 +134,7 @@ export CRDB_PASSWORD="tfs123" export CRDB_DEPLOY_MODE="single" # Disable flag for dropping database, if it exists. -export CRDB_DROP_DATABASE_IF_EXISTS="" +export CRDB_DROP_DATABASE_IF_EXISTS="YES" # Disable flag for re-deploying CockroachDB from scratch. export CRDB_REDEPLOY="" diff --git a/proto/tapi.proto b/proto/tapi.proto index fd35cd02d4b6a65500695fd4b55723816557b197..ccd4890c6a98eb0652de29c201890a987a334f30 100644 --- a/proto/tapi.proto +++ b/proto/tapi.proto @@ -21,6 +21,7 @@ import "context.proto"; service TapiService { rpc GetListTopologies (context.Empty ) returns ( context.TopologyList ) {} rpc GetTopology (context.TopologyId ) returns ( context.Topology ) {} + rpc SetService (context.ServiceList) returns (context.Empty) {} } diff --git a/scripts/cockroachdb_client.sh b/scripts/cockroachdb_client.sh index 07f4963376363d771521e5cba448d96a27ed4e69..eeafa409709304e5b869e74c10e3eb9d4922283f 100755 --- a/scripts/cockroachdb_client.sh +++ b/scripts/cockroachdb_client.sh @@ -37,7 +37,7 @@ export CRDB_DEPLOY_MODE=${CRDB_DEPLOY_MODE:-"single"} if [ "$CRDB_DEPLOY_MODE" == "single" ]; then CRDB_SQL_PORT=$(kubectl --namespace ${CRDB_NAMESPACE} get service cockroachdb-public -o 'jsonpath={.spec.ports[?(@.name=="sql")].port}') - CRDB_CLIENT_URL="postgresql://${CRDB_USERNAME}:${CRDB_PASSWORD}@cockroachdb-0:${CRDB_SQL_PORT}/defaultdb?sslmode=require" + CRDB_CLIENT_URL="postgresql://${CRDB_USERNAME}:${CRDB_PASSWORD}@cockroachdb-0:${CRDB_SQL_PORT}/tfs_context?sslmode=require" kubectl exec -it --namespace ${CRDB_NAMESPACE} cockroachdb-0 -- \ ./cockroach sql --certs-dir=/cockroach/cockroach-certs --url=${CRDB_CLIENT_URL} elif [ "$CRDB_DEPLOY_MODE" == "cluster" ]; then diff --git a/src/device/service/DeviceServiceServicerImpl.py b/src/device/service/DeviceServiceServicerImpl.py index b81ac4dc690105508c62ebb5320bda7776cb2bbf..d46efd9f3d01f6aff609f985eec6af02ffbfd63a 100644 --- a/src/device/service/DeviceServiceServicerImpl.py +++ b/src/device/service/DeviceServiceServicerImpl.py @@ -156,8 +156,9 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): #for endpoint in request.device_endpoints: # #endpoint.endpoint_id.device_id.CopyFrom(device.device_id) # pass - + if 'new_optical_config' in new_optical_configs and 'opticalconfig' in new_optical_configs["new_optical_config"]: + LOGGER.info(f"set optical device config {new_optical_configs}") context_client.SetOpticalConfig(new_optical_configs["new_optical_config"]['opticalconfig']) device_id = context_client.SetDevice(device) diff --git a/src/device/service/OpenConfigServicer.py b/src/device/service/OpenConfigServicer.py index 59c821a676f89d560a674313dfba8d6095e46050..fd0a8cde9a078720a2558e3af43dc62142df3c84 100644 --- a/src/device/service/OpenConfigServicer.py +++ b/src/device/service/OpenConfigServicer.py @@ -81,7 +81,9 @@ class OpenConfigServicer(DeviceServiceServicer): is_all_good = True config = json.loads(request.config) results = None - + + LOGGER.info(f"config from service {config}") + try: context_client = ContextClient() device = get_device( @@ -93,6 +95,7 @@ class OpenConfigServicer(DeviceServiceServicer): driver : _Driver = get_driver(self.driver_instance_cache, device) results = driver.SetConfig(resources=resources,conditions=conditions) + for result in results: if not result : is_all_good = False diff --git a/src/device/service/Tools.py b/src/device/service/Tools.py index aa14ec020aeefb8bf534b81d1be9ccc5f5561a79..e588c446f499955b757b99630b11b0f8f556fde6 100644 --- a/src/device/service/Tools.py +++ b/src/device/service/Tools.py @@ -289,6 +289,7 @@ def _raw_config_rules_to_grpc( def populate_config_rules(device : Device, driver : _Driver) -> List[str]: device_uuid = device.device_id.device_uuid.uuid results_getconfig = driver.GetConfig() + return _raw_config_rules_to_grpc( device_uuid, device.device_config, ERROR_GET, ConfigActionEnum.CONFIGACTION_SET, results_getconfig) diff --git a/src/tapi/Dockerfile b/src/tapi/Dockerfile index 384980cafab9feb29228a839acb63aaf1fe4d9ea..bd08a66a0a40c362940eaec67ffc77fdbf1eff5f 100644 --- a/src/tapi/Dockerfile +++ b/src/tapi/Dockerfile @@ -69,6 +69,9 @@ COPY src/tapi/. tapi/ COPY src/context/__init__.py context/__init__.py COPY src/context/client/. context/client/ +COPY src/service/__init__.py service/__init__.py +COPY src/service/client/. service/client/ + WORKDIR /var/teraflow # Start the service diff --git a/src/tapi/client/TapiClient.py b/src/tapi/client/TapiClient.py index e95fc0855f82c82ec3024a53da2167b50f2c6009..ecb587bd0640749ccbb77830ff8902f2f3364ab1 100644 --- a/src/tapi/client/TapiClient.py +++ b/src/tapi/client/TapiClient.py @@ -17,7 +17,8 @@ from common.Constants import ServiceNameEnum from common.Settings import get_service_host, get_service_port_grpc from common.proto.context_pb2 import ( Topology, - TopologyList, Empty + TopologyList, Empty, + Service, ServiceId,ServiceList ) from common.proto.tapi_pb2 import TapiRequest @@ -66,5 +67,14 @@ class TapiClient: response = self.stub.GetTopology(request) LOGGER.debug('GetTopology result: {:s}'.format(grpc_message_to_json_string(response))) return response + + + @RETRY_DECORATOR + def SetService(self, request : ServiceList) -> Empty: + LOGGER.debug('GetTopology request: {:s}'.format(grpc_message_to_json_string(request))) + response = self.stub.SetService(request) + LOGGER.debug('GetTopology result: {:s}'.format(grpc_message_to_json_string(response))) + return Empty() + \ No newline at end of file diff --git a/src/tapi/service/TapiServiceServicerImpl.py b/src/tapi/service/TapiServiceServicerImpl.py index b5b886d0f215892dd3ed4c5f0e6a6ab628daeb8f..f85ba8f39efa8a0e5e467c87d622dd3806512569 100644 --- a/src/tapi/service/TapiServiceServicerImpl.py +++ b/src/tapi/service/TapiServiceServicerImpl.py @@ -18,7 +18,8 @@ import grpc, logging, os, time from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method from common.proto.context_pb2 import ( - Topology,TopologyList ,TopologyId,Empty + Topology,TopologyList ,TopologyId,Empty, + Service, ServiceId , ServiceList ) from common.proto.tapi_pb2 import TapiRequest @@ -26,7 +27,8 @@ from common.proto.tapi_pb2_grpc import TapiService from common.tools.mutex_queues.MutexQueues import MutexQueues from context.client.ContextClient import ContextClient - +from service.client.ServiceClient import ServiceClient +from tapi.service.tools.service_handler import process_services LOGGER = logging.getLogger(__name__) @@ -40,7 +42,8 @@ class TapiServiceServicerImpl(TapiService): def __init__(self) -> None: LOGGER.debug('Creating Servicer...') - + self._ctxt = ContextClient() + self._svc = ServiceClient() self.mutex_queues = MutexQueues() LOGGER.debug('Servicer Created') @@ -52,14 +55,14 @@ class TapiServiceServicerImpl(TapiService): response = [] topology_list=TopologyList() - context_client = ContextClient() - context_list = context_client.ListContextIds(Empty()) + + context_list = self._ctxt.ListContextIds(Empty()) context_ids_list = context_list.context_ids try: for context_id in context_ids_list: - topology_list = context_client.ListTopologies(context_id) + topology_list = self._ctxt.ListTopologies(context_id) response.append(topology_list) @@ -72,9 +75,31 @@ class TapiServiceServicerImpl(TapiService): LOGGER.info(f"error in Tapi servicer {e}") - def GetTopology (self ,topology_id:TapiRequest) -> Topology : + def GetTopology (self ,topology_id : TapiRequest , context : grpc.ServicerContext) -> Topology : topology = Topology () return topology + + def SetService (self , services : ServiceList, context : grpc.ServicerContext)-> ServiceId : + + LOGGER.info(f"request {services}") + services_list = process_services(services) + LOGGER.info(f"request {services_list}") + results =[] + + try : + for tservice in services_list: + service_add,service = tservice + LOGGER.info(f"add service {service_add}") + LOGGER.info(f"set service {service}") + service_id = self._svc.CreateService(service_add) + if (service_id): service_id= self._svc.UpdateService(service) + results.append(service_id) + + return Empty() + except Exception as e : + + LOGGER.info(f"Tapi setservice error {e}") + diff --git a/src/tapi/service/__main__.py b/src/tapi/service/__main__.py index dd0d9dd178585f211d56212bd5b57c94e74a37a9..a62353af33485c5d458bd3dc897ba763738e7ae4 100644 --- a/src/tapi/service/__main__.py +++ b/src/tapi/service/__main__.py @@ -42,6 +42,8 @@ def main(): wait_for_environment_variables([ get_env_var_name(ServiceNameEnum.CONTEXT, ENVVAR_SUFIX_SERVICE_HOST ), get_env_var_name(ServiceNameEnum.CONTEXT, ENVVAR_SUFIX_SERVICE_PORT_GRPC), + get_env_var_name(ServiceNameEnum.SERVICE, ENVVAR_SUFIX_SERVICE_HOST ), + get_env_var_name(ServiceNameEnum.SERVICE, ENVVAR_SUFIX_SERVICE_PORT_GRPC), ]) signal.signal(signal.SIGINT, signal_handler) diff --git a/src/tapi/service/tools/__init__.py b/src/tapi/service/tools/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..53d5157f750bfb085125cbd33faff1cec5924e14 --- /dev/null +++ b/src/tapi/service/tools/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + diff --git a/src/tapi/service/tools/service_handler.py b/src/tapi/service/tools/service_handler.py new file mode 100644 index 0000000000000000000000000000000000000000..74caa459b1a9c2370888614e36cd9d3167824f84 --- /dev/null +++ b/src/tapi/service/tools/service_handler.py @@ -0,0 +1,30 @@ +from common.proto.context_pb2 import ( + Topology,TopologyList ,TopologyId,Empty, + Service, ServiceId , ServiceList +) +from google.protobuf.json_format import MessageToDict +from google.protobuf.json_format import ParseDict + +import copy + +def process_services (services:ServiceList) : + + + service_add = {} + service = {} + services_result = [] + + + dict_services= MessageToDict(services) + services_list=dict_services.get('services',[]) + for s in services_list: + + service_copy = copy.deepcopy(s) + service_copy['service_endpoint_ids'] = [] + service_copy['service_constraints'] = [] + service_copy['service_config'] = {'config_rules': []} + service_add = ParseDict(service_copy,Service()) + service = ParseDict(s,Service()) + + services_result.append((service_add , service)) + return services_result \ No newline at end of file diff --git a/src/tests/ofc24/roadms.sh b/src/tests/ofc24/roadms.sh index afa4f1c463b4ae179ebaed5eeec19b0afc09cfac..10ef5a3758a2b83ef12e42da83d0449b2db6bec6 100644 --- a/src/tests/ofc24/roadms.sh +++ b/src/tests/ofc24/roadms.sh @@ -23,4 +23,4 @@ docker rm na4 screen -dmS t3 -T xterm sh -c "docker run --name na3 -p 10.0.2.4:2025:2022 -v /home/tfs/tfs-ctrl/src/tests/ofc24/tempOC/files:/files -it asgamb1/flexscale-node.img:latest bash -c 'cp /files/platform_r1.xml demoECOC21.xml ; ./startNetconfAgent.sh'" -screen -dmS t4 -T xterm sh -c "docker run --name na4 -p 10.0.2.4:2026:2022 -v /home/tfs/tfs-ctrl/src/tests/ofc24/tempOC/files:/files -it asgamb1/flexscale-node.img:latest bash -c 'cp /files/platform_r2.xml demoECOC21.xml ; ./startNetconfAgent.sh'" \ No newline at end of file +#screen -dmS t4 -T xterm sh -c "docker run --name na4 -p 10.0.2.4:2026:2022 -v /home/tfs/tfs-ctrl/src/tests/ofc24/tempOC/files:/files -it asgamb1/flexscale-node.img:latest bash -c 'cp /files/platform_r2.xml demoECOC21.xml ; ./startNetconfAgent.sh'" \ No newline at end of file diff --git a/src/tests/ofc24/transponders.sh b/src/tests/ofc24/transponders.sh old mode 100644 new mode 100755 index 6af230b58cba5ed9db11494f9121e33a3d6a41a6..a771c0b107ac290170ae977ec5a23ccc88e64cdb --- a/src/tests/ofc24/transponders.sh +++ b/src/tests/ofc24/transponders.sh @@ -22,5 +22,5 @@ docker rm tna2 -screen -dmS tt1 -T xterm sh -c "docker run --name tna1 -p 10.0.2.4:2023:2022 -v /home/tfs/tfs-ctrl/src/tests/ofc24/tempOC/files:/files -it asgamb1/oc23bgp.img:latest bash -c 'cp /files/platform_t1.xml demoECOC21.xml ; ./startNetconfAgent.sh'" -screen -dmS tt2 -T xterm sh -c "docker run --name tna2 -p 10.0.2.4:2024:2022 -v /home/tfs/tfs-ctrl/src/tests/ofc24/tempOC/files:/files -it asgamb1/oc23bgp.img:latest bash -c 'cp /files/platform_t2.xml demoECOC21.xml ; ./startNetconfAgent.sh'" +screen -dmS t1 -T xterm sh -c "docker run --name tna1 -p 10.0.2.4:2023:2022 -v /home/tfs/tfs-ctrl/src/tests/ofc24/tempOC/files:/files -it asgamb1/oc23bgp.img:latest bash -c 'cp /files/platform_t1.xml demoECOC21.xml ; ./startNetconfAgent.sh'" +#screen -dmS tt2 -T xterm sh -c "docker run --name tna2 -p 10.0.2.4:2024:2022 -v /home/tfs/tfs-ctrl/src/tests/ofc24/tempOC/files:/files -it asgamb1/oc23bgp.img:latest bash -c 'cp /files/platform_t2.xml demoECOC21.xml ; ./startNetconfAgent.sh'" diff --git a/test.py b/test.py index acc58edbf5085bdafc39652ff613a59cf085e757..2e64accf11582f674f75ff92bb45269baf24ea4f 100644 --- a/test.py +++ b/test.py @@ -1,14 +1,45 @@ from ncclient import manager + +media_channel = ''' +<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> + <wavelength-router xmlns="http://openconfig.net/yang/wavelength-router"> + <media-channels> + <channel operation="create"> + <index>2</index> + <config> + <name>C_BAND</name> + <optical-band-parent xmlns="http://flex-scale-project.eu/yang/flex-scale-mg-on">1</optical-band-parent> + <index>2</index> + <lower-frequency>192006251</lower-frequency> + <upper-frequency>192056250</upper-frequency> + </config> + <dest> + <config> + <port-name>2</port-name> + </config> + </dest> + </channel> + </media-channels> + </wavelength-router> +</config> + +''' + + + + + + # Define device connection details device = { 'host': '10.0.2.4', # replace with the target device's hostname or IP address - 'port': 2023, # NETCONF default port + 'port': 2026, # NETCONF default port 'username': 'admin', # replace with your username 'password': 'admin', # replace with your password 'hostkey_verify': False , # disable host key verification (use only for testing) - "hostkey_verify": False, + "look_for_keys": False, "allow_agent": False, @@ -21,12 +52,11 @@ device = { with manager.connect(**device) as m: print("Connected to the device successfully!") config = m.get_config(source='running').data_xml + print("Device Configuration:") - print(config) - # Example RPC call to get the device's capabilities - capabilities = m.server_capabilities - for capability in capabilities: - print(capability) + with open('d.log', 'w') as log_file: + print(config,file=log_file) + # result = m.edit_config(target='running', config=media_channel) + # print (result) - # Close the connection