Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ WORKDIR /usr/src/app

COPY . /usr/src/app

COPY ./sense-o-auth.yaml.templat[e] /root/.sense-o-auth.yaml

# create a venv.
RUN python3 -m venv /opt/venv --upgrade-deps

Expand Down
5 changes: 5 additions & 0 deletions env.template
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ OXP_PROVISION_URL=http://192.168.201.205:8088/SDX-LC/1.0.0/provision
OXP_PULL_URL=http://192.168.201.205:8088/SDX-LC/1.0.0/topology
OXP_PULL_INTERVAL=180
OXP_CONNECTION_URL=http://192.168.201.205:8088/SDX-LC/1.0.0/connection

#OXP Client
CLIENT_PACKAGE=sense_sdx
CLIENT_FUNCTION=client.py
CLIENT_TOPOLOGY_TRANSLATOR=topology_translate
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ dependencies = [
"connexion[swagger-ui] == 2.14.2",
"asgiref >= 3.7.2",
"pymongo > 3.0",
"sdx-datamodel @ git+https://github.com/atlanticwave-sdx/datamodel@3.0.0.dev5",
"dotenv",
"sense-sdx @ git+https://github.com/atlanticwave-sdx/sense-sdx.git",
"sdx-datamodel @ git+https://github.com/atlanticwave-sdx/datamodel@3.0.0.dev13",
]

[project.optional-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion sdx_lc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def create_app():
logger.info(
f"SDX Local Controller starting up ("
f"name: {os.getenv('SDXLC_NAME')}, "
f"domain: {os.getenv('SDXLC_DOMAIN')})"
f"domain: {os.getenv('SDXLC_DOMAIN')}),"
f"client package:{os.getenv('CLIENT_PACKAGE')}"
)

# Run swagger service
Expand Down
67 changes: 41 additions & 26 deletions sdx_lc/jobs/pull_topo_changes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import importlib
import importlib.util
import json
import logging
import os.path
Expand All @@ -15,6 +17,10 @@
from messaging.rpc_queue_producer import RpcProducer
from utils.db_utils import DbUtils

CLIENT_PACKAGE = os.getenv("CLIENT_PACKAGE", None)
CLIENT_FUNCTION = os.getenv("CLIENT_FUNCTION", None)
CLIENT_TOPOLOGY_TRANSLATOR = os.getenv("CLIENT_TOPOLOGY_TRANSLATOR", None)

OXPO_USER = os.environ.get("OXPO_USER", None)
OXPO_PASS = os.environ.get("OXPO_PASS", None)
OXP_PULL_URL = os.environ.get("OXP_PULL_URL")
Expand Down Expand Up @@ -54,32 +60,41 @@ def process_domain_controller_topo(db_instance):
else:
logger.debug("Latest topology does not exist")

try:
response = requests.get(OXP_PULL_URL, auth=(OXPO_USER, OXPO_PASS))
pulled_topology = response.content
except (requests.ConnectionError, requests.HTTPError):
logger.debug("Error connecting to domain controller...")
continue

if not response.ok:
continue

logger.debug("Pulled request from domain controller")

try:
json_pulled_topology = response.json()
except ValueError:
logger.debug("Cannot parse pulled topology, invalid JSON")
continue

try:
pulled_topo_version = json_pulled_topology["version"]
except KeyError:
logger.debug("Error getting topo version")
continue

if latest_topology_exists and latest_topo_version == pulled_topo_version:
continue
if not CLIENT_PACKAGE:
try:
response = requests.get(OXP_PULL_URL, auth=(OXPO_USER, OXPO_PASS))
pulled_topology = response.content
if not response.ok:
continue
logger.debug("Pulled request from domain controller")
json_pulled_topology = response.json()
pulled_topo_version = json_pulled_topology["version"]
except (requests.ConnectionError, requests.HTTPError):
logger.debug("Error connecting to domain controller...")
continue
except ValueError:
logger.debug("Cannot parse pulled topology, invalid JSON")
continue
except KeyError:
logger.debug("Error getting topo version")
continue
if latest_topology_exists and latest_topo_version == pulled_topo_version:
continue
else:
try:
client_module = importlib.import_module(CLIENT_PACKAGE)
path = client_module.__dict__.get("__path__")[0]
spec = importlib.util.spec_from_file_location(
CLIENT_TOPOLOGY_TRANSLATOR, path + "/" + CLIENT_FUNCTION
)
client = importlib.util.module_from_spec(spec)
spec.loader.exec_module(client)
pulled_topology = client.topology_translate()
json_pulled_topology = json.loads(pulled_topology)
json_pulled_topology["version"] = 1
except Exception as e:
logger.error("Client Error:{e} \}")
continue

logger.debug("Pulled topo with different version. Adding pulled topo to db")
db_instance.add_key_value_pair_to_db(
Expand Down