diff --git a/geant_service_orchestrator/main.py b/geant_service_orchestrator/main.py index 66357c213e8c8b6368767a9b7c4e652561113e8b..2e7800f185aef35a99fb9e09ffb602effa4484aa 100644 --- a/geant_service_orchestrator/main.py +++ b/geant_service_orchestrator/main.py @@ -2,8 +2,8 @@ from orchestrator import OrchestratorCore from orchestrator.cli.main import app as core_cli from orchestrator.settings import AppSettings -import products -import workflows +# import products +# import workflows app = OrchestratorCore(base_settings=AppSettings()) diff --git a/geant_service_orchestrator/oss-params-example.json b/geant_service_orchestrator/oss-params-example.json new file mode 100644 index 0000000000000000000000000000000000000000..32187e1f9b06bd7d60113065b2d705094b88ca85 --- /dev/null +++ b/geant_service_orchestrator/oss-params-example.json @@ -0,0 +1,20 @@ +{ + "RESOURCE_MANAGER_API_PREFIX": "http://localhost:44444", + "IPAM": { + "INFOBLOX": { + "scheme": "https", + "wapi_version": "v2.12", + "host": "10.0.0.1", + "username": "robot-user", + "password": "robot-user-password" + }, + "TRUNK": { + "V4": {"container": "1.1.0.0/19", "mask": 31}, + "V6": {"container": "dead:beef::/29", "mask": 96} + }, + "GEANT_IP": { + "V4": {"container": "1.1.8.0/19", "mask": 31}, + "V6": {"container": "dead:beef::/29", "mask": 96} + } + } +} \ No newline at end of file diff --git a/geant_service_orchestrator/products/product_blocks/__init__.py b/geant_service_orchestrator/products/product_blocks/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/geant_service_orchestrator/products/product_types/__init__.py b/geant_service_orchestrator/products/product_types/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/geant_service_orchestrator/services/__init__.py b/geant_service_orchestrator/services/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/geant_service_orchestrator/services/ipam.py b/geant_service_orchestrator/services/ipam.py new file mode 100644 index 0000000000000000000000000000000000000000..30d2a07b5edbeb4b5fb8ef9b7c45b7954b0737b8 --- /dev/null +++ b/geant_service_orchestrator/services/ipam.py @@ -0,0 +1,30 @@ +import ipaddress +from pydantic import BaseSettings +from geant_service_orchestrator import settings + + +class ServiceNetworks(BaseSettings): + v4: ipaddress.IPv4Network + v6: ipaddress.IPv6Network + + +class HostAddresses(BaseSettings): + v4: ipaddress.IPv4Address + v6: ipaddress.IPv6Address + + +def new_service_networks( + ipam: settings.IPAMParams, + service_params: settings.ServiceNetworkParams) -> ServiceNetworks: + # TODO: load from ipam + # cf. https://gitlab.geant.org/goat/gap-jenkins/-/blob/development/service-editor/gap_service_editor/ipam.py#L35-66 # noqa: E501 + return ServiceNetworks( + v4=ipaddress.IPv4Network('10.0.0.0/24'), + v6=ipaddress.IPv6Network('dead:beef::/120')) + + +def new_host_address(fqdn: str, networks: ServiceNetworks) -> HostAddresses: + # TODO: load from ipam + return HostAddresses( + v4=ipaddress.IPv4Address('10.0.0.1'), + v6=ipaddress.IPv6Address('dead:beef::1')) diff --git a/geant_service_orchestrator/services/resource_manager.py b/geant_service_orchestrator/services/resource_manager.py new file mode 100644 index 0000000000000000000000000000000000000000..f591e8a3ea96e7ac0b25366d104e6aafd83a2e34 --- /dev/null +++ b/geant_service_orchestrator/services/resource_manager.py @@ -0,0 +1,28 @@ +from geant_service_orchestrator import settings +import requests + + +def import_new_router(router_name, oss_params=settings.OSSParams): + r = requests.post( + f'{oss_params.RESOURCE_MANAGER_API_PREFIX}' + f'/api/interfaces/initialize-router/{router_name}') + r.raise_for_status() + + +def next_lag(router_name, oss_params=settings.OSSParams): + r = requests.post( + f'{oss_params.RESOURCE_MANAGER_API_PREFIX}' + f'/api/interfaces/next-lag/{router_name}') + r.raise_for_status() + response = r.json() + return response['name'] + + +def next_physical(router_name, lag_name, oss_params=settings.OSSParams): + # TODO: speed needed (if first interface) + r = requests.post( + f'{oss_params.RESOURCE_MANAGER_API_PREFIX}' + f'/api/interfaces/next-physical/{router_name}/{lag_name}') + r.raise_for_status() + response = r.json() + return response['name'] diff --git a/geant_service_orchestrator/settings.py b/geant_service_orchestrator/settings.py new file mode 100644 index 0000000000000000000000000000000000000000..a0c79368c937971dccf06b8cafdeb927d7cad62c --- /dev/null +++ b/geant_service_orchestrator/settings.py @@ -0,0 +1,51 @@ +import ipaddress +import json +import os +from pydantic import BaseSettings + + +class InfoBloxParams(BaseSettings): + scheme: str + wapi_version: str + host: str + username: str + password: str + + +class V4NetworkParams(BaseSettings): + container: ipaddress.IPv4Network + mask: int # TODO: validation on mask? + + +class V6NetworkParams(BaseSettings): + container: ipaddress.IPv6Network + mask: int # TODO: validation on mask? + + +class ServiceNetworkParams(BaseSettings): + V4: V4NetworkParams + V6: V6NetworkParams + + +class IPAMParams(BaseSettings): + INFOBLOX: InfoBloxParams + TRUNK: ServiceNetworkParams + GEANT_IP: ServiceNetworkParams + + +class OSSParams(BaseSettings): + IPAM: IPAMParams + RESOURCE_MANAGER_API_PREFIX: str # api prefix + + +def load_oss_params() -> OSSParams: + """ + look for OSS_PARAMS_FILENAME in the environment and load the + parameters from that file + """ + with open(os.environ['OSS_PARAMS_FILENAME']) as f: + return OSSParams(**json.loads(f.read())) + + +if __name__ == '__main__': + print(load_oss_params()) diff --git a/geant_service_orchestrator/workflows/trunk/__init__.py b/geant_service_orchestrator/workflows/trunk/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/geant_service_orchestrator/workflows/trunk_config/__init__.py b/geant_service_orchestrator/workflows/trunk_config/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/geant_service_orchestrator/workflows/trunk_config_common/__init__.py b/geant_service_orchestrator/workflows/trunk_config_common/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/geant_service_orchestrator/workflows/trunk_config_side/__init__.py b/geant_service_orchestrator/workflows/trunk_config_side/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/requirements.txt b/requirements.txt index 5b0787674542104bfce569a6a6c79d9ee40b2351..b575b478f50d48470257314b85f5d13a3aea56c7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ orchestrator-core +requests pytest