Skip to content

Commit

Permalink
Merge pull request #36 from 6G-SANDBOX/staging
Browse files Browse the repository at this point in the history
New release v0.3.1
  • Loading branch information
CarlosAndreo authored Oct 4, 2024
2 parents 692e5f8 + b3a6a57 commit 3c0e599
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
FLASK_ENV="production"

# TNLCM
TNLCM_ADMIN_USER=""
TNLCM_ADMIN_PASSWORD=""
TNLCM_ADMIN_EMAIL=""
TNLCM_HOST=""
TNLCM_PORT=5000
TNLCM_CALLBACK="http://${TNLCM_HOST}:${TNLCM_PORT}/tnlcm/callback"
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## [v0.3.1] - 2024-10-04

### Added

- Creation of an administrator user when instantiating the mongo database for the first time.

### Fixed

- Types of input values in the test descriptors of the `tn_template_lib` folder.
- Check if the site entered to deploy a trial network is correct.

## [v0.3.0] - 2024-09-25

### Added
Expand Down Expand Up @@ -110,6 +121,7 @@

- Frontend implementation.

[v0.3.1]: https://github.com/6G-SANDBOX/TNLCM/compare/v0.3.0...v0.3.1
[v0.3.0]: https://github.com/6G-SANDBOX/TNLCM/compare/v0.2.1...v0.3.0
[v0.2.1]: https://github.com/6G-SANDBOX/TNLCM/compare/v0.2.0...v0.2.1
[v0.2.0]: https://github.com/6G-SANDBOX/TNLCM/compare/v0.1.0...v0.2.0
Expand Down
11 changes: 10 additions & 1 deletion conf/tnlcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@ class TnlcmSettings:

log_handler.info("Load TNLCM configuration")

TNLCM_ADMIN_USER = os.getenv("TNLCM_ADMIN_USER")
TNLCM_ADMIN_PASSWORD = os.getenv("TNLCM_ADMIN_PASSWORD")
TNLCM_ADMIN_EMAIL = os.getenv("TNLCM_ADMIN_EMAIL")
TNLCM_HOST = os.getenv("TNLCM_HOST")
TNLCM_PORT = os.getenv("TNLCM_PORT")
TNLCM_CALLBACK = os.getenv("TNLCM_CALLBACK")
missing_variables = []
if not TNLCM_ADMIN_USER:
missing_variables.append("TNLCM_ADMIN_USER")
if not TNLCM_ADMIN_PASSWORD:
missing_variables.append("TNLCM_ADMIN_PASSWORD")
if not TNLCM_ADMIN_EMAIL:
missing_variables.append("TNLCM_ADMIN_EMAIL")
if not TNLCM_HOST:
missing_variables.append("TNLCM_HOST")
if not TNLCM_PORT:
Expand All @@ -24,7 +33,7 @@ class TnlcmSettings:
raise UndefinedEnvVariableError(missing_variables)

TITLE = "Trial Network Life Cycle Manager - TNLCM"
VERSION = "0.3.0"
VERSION = "0.3.1"
DESCRIPTION = ("""
Welcome to the Trial Network Life Cycle Manager (TNLCM) API! This powerful tool facilitates the management and orchestration of network life cycles, designed specifically for the cutting-edge 6G Sandbox project.
Expand Down
35 changes: 34 additions & 1 deletion core/database/tnlcm-structure.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
const crypto = require('crypto');

var dbName = process.env.MONGO_DATABASE;
var adminUser = process.env.TNLCM_ADMIN_USER;
var adminPassword = process.env.TNLCM_ADMIN_PASSWORD;
var adminEmail = process.env.TNLCM_ADMIN_EMAIL;

// PBKDF2 parameters
const salt = crypto.randomBytes(16).toString('hex');
const iterations = 600000;
const keyLength = 32;
const digest = 'sha256';

// Generate password hash
const hash = crypto.pbkdf2Sync(adminPassword, salt, iterations, keyLength, digest).toString('hex');
const hashedPassword = `pbkdf2:sha256:${iterations}$${salt}$${hash}`;

var resourceManager = 'resource_manager';
var trialNetworks = 'trial_networks';
var trialNetworksTemplates = 'trial_networks_templates';
Expand All @@ -7,8 +23,25 @@ var verificationTokens = 'verification_tokens';

var db = db.getSiblingDB(dbName);

// Create collections
db.createCollection(resourceManager)
db.createCollection(trialNetworks);
db.createCollection(trialNetworksTemplates);
db.createCollection(users);
db.createCollection(verificationTokens);
db.createCollection(verificationTokens);

// Insert administrator user in the users collection
db.users.insertOne({
username: adminUser,
password: hashedPassword,
email: adminEmail,
role: "admin",
org: 'ADMIN'
});

// Insert a verification token into the collection verification_tokens
db.verification_tokens.insertOne({
new_account_email: adminEmail,
verification_token: Math.floor(Math.random() * 1000000),
creation_date: new Date()
});
1 change: 1 addition & 0 deletions core/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class UserModel(Document):
username = StringField(max_length=50, unique=True)
password = StringField(max_length=255)
email = EmailField(max_length=50, unique=True)
role = StringField(max_length=20, default="user")
org = StringField(max_length=50)

meta = {
Expand Down
20 changes: 16 additions & 4 deletions core/routes/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def post(self):
commit_id = self.parser_post.parse_args()["commit_id"]

current_user = get_current_user_from_jwt(get_jwt_identity())
trial_network = TrialNetworkModel.objects(user_created=current_user.username, tn_id=tn_id).first()
if current_user.role == "admin":
trial_network = TrialNetworkModel.objects(tn_id=tn_id).first()
else:
trial_network = TrialNetworkModel.objects(user_created=current_user.username, tn_id=tn_id).first()
trial_network.set_github_6g_library_commit_id(commit_id)
trial_network.save()
return {"message": "Commit successfully modified"}, 201
Expand All @@ -63,7 +66,10 @@ def post(self):
commit_id = self.parser_post.parse_args()["commit_id"]

current_user = get_current_user_from_jwt(get_jwt_identity())
trial_network = TrialNetworkModel.objects(user_created=current_user.username, tn_id=tn_id).first()
if current_user.role == "admin":
trial_network = TrialNetworkModel.objects(tn_id=tn_id).first()
else:
trial_network = TrialNetworkModel.objects(user_created=current_user.username, tn_id=tn_id).first()
trial_network.set_github_6g_sandbox_sites_commit_id(commit_id)
trial_network.save()
return {"message": "Commit successfully modified"}, 201
Expand All @@ -89,7 +95,10 @@ def post(self):
entity_name = self.parser_post.parse_args()["entity_name"]

current_user = get_current_user_from_jwt(get_jwt_identity())
trial_network = TrialNetworkModel.objects(user_created=current_user.username, tn_id=tn_id).first()
if current_user.role == "admin":
trial_network = TrialNetworkModel.objects(tn_id=tn_id).first()
else:
trial_network = TrialNetworkModel.objects(user_created=current_user.username, tn_id=tn_id).first()
tn_raw_descriptor = trial_network.json_to_descriptor(trial_network.tn_raw_descriptor)
tn_sorted_descriptor = trial_network.json_to_descriptor(trial_network.tn_sorted_descriptor)
tn_deployed_descriptor = trial_network.json_to_descriptor(trial_network.tn_deployed_descriptor)
Expand Down Expand Up @@ -123,7 +132,10 @@ def post(self):
entity_name = self.parser_post.parse_args()["entity_name"]

current_user = get_current_user_from_jwt(get_jwt_identity())
trial_network = TrialNetworkModel.objects(user_created=current_user.username, tn_id=tn_id).first()
if current_user.role == "admin":
trial_network = TrialNetworkModel.objects(tn_id=tn_id).first()
else:
trial_network = TrialNetworkModel.objects(user_created=current_user.username, tn_id=tn_id).first()
tn_raw_descriptor = trial_network.json_to_descriptor(trial_network.tn_raw_descriptor)
tn_sorted_descriptor = trial_network.json_to_descriptor(trial_network.tn_sorted_descriptor)
tn_deployed_descriptor = trial_network.json_to_descriptor(trial_network.tn_deployed_descriptor)
Expand Down
35 changes: 23 additions & 12 deletions core/routes/trial_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def post(self):
github_6g_sandbox_sites_reference_value = self.parser_post.parse_args()["github_6g_sandbox_sites_reference_value"]

current_user = get_current_user_from_jwt(get_jwt_identity())
trial_network = TrialNetworkModel(
user_created=current_user.username
)
trial_network = TrialNetworkModel(user_created=current_user.username)
sixg_sandbox_sites_handler = SixGSandboxSitesHandler(reference_type=github_6g_sandbox_sites_reference_type, reference_value=github_6g_sandbox_sites_reference_value)
sixg_sandbox_sites_handler.set_deployment_site(deployment_site)
site_available_components = sixg_sandbox_sites_handler.get_site_available_components()
Expand Down Expand Up @@ -94,7 +92,10 @@ def get(self, tn_id):
"""
try:
current_user = get_current_user_from_jwt(get_jwt_identity())
trial_network = TrialNetworkModel.objects(user_created=current_user.username, tn_id=tn_id).first()
if current_user.role == "admin":
trial_network = TrialNetworkModel.objects(tn_id=tn_id).first()
else:
trial_network = TrialNetworkModel.objects(user_created=current_user.username, tn_id=tn_id).first()
if not trial_network:
return abort(404, f"No trial network with the name '{tn_id}' created by the user '{current_user}'")
return trial_network.to_dict_full(), 200
Expand All @@ -116,7 +117,10 @@ def put(self, tn_id):
jenkins_deploy_pipeline = self.parser_put.parse_args()["jenkins_deploy_pipeline"]

current_user = get_current_user_from_jwt(get_jwt_identity())
trial_network = TrialNetworkModel.objects(user_created=current_user.username, tn_id=tn_id).first()
if current_user.role == "admin":
trial_network = TrialNetworkModel.objects(tn_id=tn_id).first()
else:
trial_network = TrialNetworkModel.objects(user_created=current_user.username, tn_id=tn_id).first()
if not trial_network:
return abort(404, f"No trial network with the name '{tn_id}' created by the user '{current_user}'")

Expand Down Expand Up @@ -185,13 +189,16 @@ def delete(self, tn_id):
jenkins_destroy_pipeline = self.parser_delete.parse_args()["jenkins_destroy_pipeline"]

current_user = get_current_user_from_jwt(get_jwt_identity())
trial_network = TrialNetworkModel.objects(user_created=current_user.username, tn_id=tn_id).first()
if current_user.role == "admin":
trial_network = TrialNetworkModel.objects(tn_id=tn_id).first()
else:
trial_network = TrialNetworkModel.objects(user_created=current_user.username, tn_id=tn_id).first()
if not trial_network:
return abort(404, f"No trial network with the name '{tn_id}' created by the user '{current_user}'")

tn_state = trial_network.tn_state
if tn_state != "activated":
return abort(400, f"Trial network cannot be destroyed")
return abort(400, f"Trial network cannot be destroyed because the current status of Trial Network is different to ACTIVATED")
callback_handler = CallbackHandler(trial_network=trial_network)
sixg_sandbox_sites_handler = SixGSandboxSitesHandler(reference_type="commit", reference_value=trial_network.github_6g_sandbox_sites_commit_id)
sixg_sandbox_sites_handler.set_deployment_site(trial_network.deployment_site)
Expand Down Expand Up @@ -220,7 +227,10 @@ def get(self, tn_id):
"""
try:
current_user = get_current_user_from_jwt(get_jwt_identity())
trial_network = TrialNetworkModel.objects(user_created=current_user.username, tn_id=tn_id).first()
if current_user.role == "admin":
trial_network = TrialNetworkModel.objects(tn_id=tn_id).first()
else:
trial_network = TrialNetworkModel.objects(user_created=current_user.username, tn_id=tn_id).first()
if not trial_network:
return abort(404, f"No trial network with the name '{tn_id}' created by the user '{current_user}'")
return {"tn_report": trial_network.tn_report}, 200
Expand All @@ -238,7 +248,10 @@ def get(self):
"""
try:
current_user = get_current_user_from_jwt(get_jwt_identity())
trial_networks = TrialNetworkModel.objects(user_created=current_user.username)
if current_user.role == "admin":
trial_networks = TrialNetworkModel.objects()
else:
trial_networks = TrialNetworkModel.objects(user_created=current_user.username)
return {'trial_networks': [tn.to_dict_full() for tn in trial_networks]}, 200
except CustomException as e:
return abort(e.error_code, str(e))
Expand All @@ -263,9 +276,7 @@ def post(self, tn_id):
tn_descriptor_file = self.parser_post.parse_args()["descriptor"]

current_user = get_current_user_from_jwt(get_jwt_identity())
trial_network_template = TrialNetworkTemplateModel(
user_created=current_user.username
)
trial_network_template = TrialNetworkTemplateModel(user_created=current_user.username)
trial_network_template.set_tn_id(tn_id=tn_id)
trial_network_template.set_tn_raw_descriptor(tn_descriptor_file)
trial_network_template.set_tn_sorted_descriptor()
Expand Down
2 changes: 1 addition & 1 deletion core/sixg_sandbox_sites/sixg_sandbox_sites_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ def get_sites(self):
"""
Return sites available to deploy trial networks
"""
return [site for site in os.listdir(self.github_6g_sandbox_sites_local_directory) if not site.startswith(".")]
return [site for site in os.listdir(self.github_6g_sandbox_sites_local_directory) if not site.startswith(".") and os.path.isdir(os.path.join(self.github_6g_sandbox_sites_local_directory, site))]
3 changes: 3 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ services:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
MONGO_DATABASE: ${MONGO_DATABASE}
TNLCM_ADMIN_USER: ${TNLCM_ADMIN_USER}
TNLCM_ADMIN_PASSWORD: ${TNLCM_ADMIN_PASSWORD}
TNLCM_ADMIN_EMAIL: ${TNLCM_ADMIN_EMAIL}

mongo-express:
container_name: ${MONGO_DATABASE}-frontend
Expand Down
11 changes: 7 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ TNLCM/ // main folder.

## :hourglass_flowing_sand: Current Status

TNLCM is currently able to deploy the following types of components corresponding with the [6G-Library](https://github.com/6G-SANDBOX/6G-Library): **tn_vxlan**, **tn_bastion**, **tn_init**, **vnet**, **tsn**, **vm_kvm**, **oneKE**, **open5gs**, **UERANSIM-gNB** and **UERANSIM-UE**.
TNLCM is currently able to deploy the following types of components corresponding with the [6G-Library](https://github.com/6G-SANDBOX/6G-Library): **tn_vxlan**, **tn_bastion**, **tn_init**, **vnet**, **tsn**, **vm_kvm**, **oneKE**, **open5gs**, **ueransim**, **elcm**, **nokia_radio**, **ocf**, **stf_ue** and **xrext**.

![CurrentStatus](./images/currentStatus.png)

Expand All @@ -109,7 +109,7 @@ TNLCM is currently able to deploy the following types of components correspondin
>
> | Repository | Branch | Release |
> | ---------------- | ----------------------------------------------------------------- | --------- |
> | 6G-Library | [develop](https://github.com/6G-SANDBOX/6G-Library/tree/develop) | - |
> | 6G-Library | [v0.3.0](https://github.com/6G-SANDBOX/6G-Library/tree/v0.3.0) | - |
> | 6G-Sandbox-Sites | [platform](https://github.com/6G-SANDBOX/6G-Sandbox-Sites) | - |
### :inbox_tray: Download or clone repository
Expand All @@ -127,6 +127,9 @@ git clone https://github.com/6G-SANDBOX/TNLCM
Create a `.env` file at the root level, using the structure and content provided in the [`.env.template`](../.env.template) file.

Mandatory update the values of the following variables according to the platform:
- `TNLCM_ADMIN_USER`
- `TNLCM_ADMIN_PASSWORD`
- `TNLCM_ADMIN_EMAIL`
- `TNLCM_HOST`
- `JENKINS_HOST`
- `JENKINS_USERNAME`
Expand Down Expand Up @@ -338,8 +341,8 @@ To deploy 6G-SANDBOX TOOLKIT in OpenNebula, the documentation can be accessed fr
<p align="right"><a href="#readme-top">Back to top&#x1F53C;</a></p>

<!-- Urls, Shields and Badges -->
[tnlcm-badge]: https://img.shields.io/badge/TNLCM-v0.3.0-blue
[tnlcm-url]: https://github.com/6G-SANDBOX/TNLCM/releases/tag/v0.3.0
[tnlcm-badge]: https://img.shields.io/badge/TNLCM-v0.3.1-blue
[tnlcm-url]: https://github.com/6G-SANDBOX/TNLCM/releases/tag/v0.3.1
[python-badge]: https://img.shields.io/badge/Python-3.12.6-blue?style=for-the-badge&logo=python&logoColor=white&labelColor=3776AB
[python-url]: https://www.python.org/downloads/release/python-3126/
[flask-badge]: https://img.shields.io/badge/Flask-3.0.3-brightgreen?style=for-the-badge&logo=flask&logoColor=white&labelColor=000000
Expand Down
2 changes: 1 addition & 1 deletion tn_template_lib/07_descriptor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ trial_network:
one_open5gs_s_nssai_sd: "1"
one_open5gs_amf_ip: "10.10.10.200"
one_open5gs_upf_ip: "10.10.10.201"
one_open5gs_webui_subdomain : "open5gs"
one_open5gs_webui_subdomain: "open5gs"
6 changes: 3 additions & 3 deletions tn_template_lib/08_descriptor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ trial_network:
one_open5gs_s_nssai_sd: "1"
one_open5gs_amf_ip: "10.10.10.200"
one_open5gs_upf_ip: "10.10.10.201"
one_open5gs_webui_subdomain : "open5gs"
one_open5gs_webui_subdomain: "open5gs"
ueransim-gnb:
type: "ueransim"
name: "gnb"
Expand All @@ -69,10 +69,10 @@ trial_network:
one_ueransim_gnb_proxy: ""
one_ueransim_gnb_mcc: "001"
one_ueransim_gnb_mnc: "01"
one_ueransim_gnb_tac: "200"
one_ueransim_gnb_tac: 200
one_ueransim_gnb_amf_address: "10.10.10.200"
one_ueransim_gnb_slices_sst: 1
one_ueransim_gnb_slices_sd: 1
one_ueransim_gnb_slices_sd: "1"
ueransim-ue:
type: "ueransim"
name: "ue"
Expand Down
6 changes: 3 additions & 3 deletions tn_template_lib/09_descriptor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ trial_network:
one_open5gs_s_nssai_sd: "1"
one_open5gs_amf_ip: "10.10.10.200"
one_open5gs_upf_ip: "10.10.10.201"
one_open5gs_webui_subdomain : "open5gs"
one_open5gs_webui_subdomain: "open5gs"
ueransim-both:
type: "ueransim"
name: "both"
Expand All @@ -69,10 +69,10 @@ trial_network:
one_ueransim_gnb_proxy: ""
one_ueransim_gnb_mcc: "001"
one_ueransim_gnb_mnc: "01"
one_ueransim_gnb_tac: "200"
one_ueransim_gnb_tac: 200
one_ueransim_gnb_amf_address: "10.10.10.200"
one_ueransim_gnb_slices_sst: 1
one_ueransim_gnb_slices_sd: 1
one_ueransim_gnb_slices_sd: "1"
one_ueransim_ue_supi: "imsi-001010000000001"
one_ueransim_ue_mcc: "001"
one_ueransim_ue_mnc: "01"
Expand Down
2 changes: 1 addition & 1 deletion tn_template_lib/12_descriptor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ trial_network:
one_open5gs_s_nssai_sd: "000009"
one_open5gs_amf_ip: "10.10.12.200"
one_open5gs_upf_ip: "10.10.12.201"
one_open5gs_webui_subdomain : "open5gs"
one_open5gs_webui_subdomain: "open5gs"
nokia_radio-cope:
type: "nokia_radio"
name: "cope"
Expand Down
18 changes: 18 additions & 0 deletions tn_template_lib/14_descriptor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Result: pass
# Platform: UMA, FOKUS, ATHENS, OULU
trial_network:

tn_init:
type: "tn_init"
dependencies: []
input: {}
elcm-exp:
type: "elcm"
name: "exp"
dependencies:
- "tn_init"
input:
one_elcm_influxdb_user: "admin"
one_elcm_influxdb_password: "admin"
one_elcm_influxdb_database: "elcmdb"
one_elcm_grafana_password: "admin"
Loading

0 comments on commit 3c0e599

Please sign in to comment.