Includes features for REL0

Merge request reports

Loading
+0 −39
Changes for .github/workflows/federation-manager.yml: 0 added lines, 39 removed lines.
Original line number Diff line number Diff line
name: Build Docker Image

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Log in to GitHub Container Registry (GHCR)
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Lowercase github.repository
        run: |
          echo "REPO_NAME=${GITHUB_REPOSITORY@L}" >> ${GITHUB_ENV}

      - name: Build Docker image
        run: |
          docker build -t ghcr.io/${{ env.REPO_NAME }}:0.0.1 .

      - name: Push Docker image
        run: |
          docker push ghcr.io/${{ env.REPO_NAME }}:0.0.1
+24 −0
Changes for src/adapters/fm_adapter/__init__.py: 24 added lines, 0 removed lines.
Original line number Diff line number Diff line
# -------------------------------------------------------------------------- #
# Copyright 2025-present, Federation Manager, by Software Networks, i2CAT    #
#                                                                            #
# 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.                                             #
# -------------------------------------------------------------------------- #
import importlib
import pkgutil


package_name = __name__

for _, module_name, is_pkg in pkgutil.iter_modules(__path__):
    if not module_name.startswith("_"):
        importlib.import_module(f"{package_name}.{module_name}")
+299 −0
Changes for src/adapters/fm_adapter/application_deployment_management.py: 299 added lines, 0 removed lines.
Original line number Diff line number Diff line
# -------------------------------------------------------------------------- #
# Copyright 2025-present, Federation Manager, by Software Networks, i2CAT    #
#                                                                            #
# 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.                                             #
# -------------------------------------------------------------------------- #
from mongoengine.errors import ValidationError

from models.mongo_document import OriginatingOperatorPlatformOriginatingOP
from models.mongo_document import OriginatingApplicationDeploymentManagementOriginatingOP
from adapters.error import APIError
from clients import fed_manager as fm_client


def verify_required_header(partner_api_root):
    if not partner_api_root:
        raise APIError(400, "X-Partner-API-Root header is missing")


def get_all_app_instances(federation_context_id, app_id, app_provider_id, bearer_token, partner_api_root):  # noqa: E501
    """Retrieves all application instance of partner OP

     # noqa: E501

    :param federation_context_id:
    :type federation_context_id: dict | bytes
    :param app_id:
    :type app_id: dict | bytes
    :param app_provider_id:
    :type app_provider_id: dict | bytes

    :rtype: List[InlineResponse2009]
    """

    # Verify partner API root is provided
    verify_required_header(partner_api_root)

    try:
        # Find federation at originating OP
        originating_op_objects = OriginatingOperatorPlatformOriginatingOP.objects(id=federation_context_id)
        if not originating_op_objects:
            raise APIError(404, "Federation not found")
        originating_op_instance = originating_op_objects[0]
        
        # Find application deployment at partner
        deployment_response_data = fm_client.get_all_instances_deployment(
            originating_op_instance.partner_federation_id, app_id, app_provider_id, bearer_token, partner_api_root)
        
        # Check if the response contains an error from the partner API
        if "error" in deployment_response_data and "status_code" in deployment_response_data:
            status_code = deployment_response_data["status_code"]
            error_message = deployment_response_data["error"]
            raise APIError(status_code, f"Partner API error: {error_message}")
        
        info = ""
        if len(deployment_response_data) > 0:
            try:
                info = deployment_response_data[0]
            except:
                info = ""
        if "appInstanceInfo" in info:
            # Find all instances in originating operator
            if find_all_instances_originating_op(federation_context_id, app_id, app_provider_id):
               return deployment_response_data, 200
            else:
                raise APIError(409, "Application deployment exists at partner operator but not in originating operator")
        else:
            if find_all_instances_originating_op(federation_context_id, app_id, app_provider_id):
                raise APIError(409, "Application deployment exists in originating operator but not at partner operator")
            else:
                raise APIError(404, "Application deployment not found")
    except ValidationError:
        raise APIError(400, f"Invalid federation context ID format: {federation_context_id}")
    except APIError:
        raise  # Re-raise APIError as-is
    except Exception as error:
        raise APIError(500, f"Error while getting all app instances. Reason: {error}")


def get_app_instance_details(federation_context_id, app_id, app_instance_id, zone_id, bearer_token, partner_api_root):  # noqa: E501
    """Retrieves an application instance details from partner OP.

     # noqa: E501

    :param federation_context_id:
    :type federation_context_id: dict | bytes
    :param app_id:
    :type app_id: dict | bytes
    :param app_instance_id:
    :type app_instance_id: dict | bytes
    :param zone_id:
    :type zone_id: dict | bytes

    :rtype: InlineResponse2008
    """

    # Verify partner API root is provided
    verify_required_header(partner_api_root)

    try:
        # Find federation at originating OP
        originating_op_objects = OriginatingOperatorPlatformOriginatingOP.objects(id=federation_context_id)
        if not originating_op_objects:
            raise APIError(404, "Federation not found")
        originating_op_instance = originating_op_objects[0]
        
        # Find application deployment details at partner
        deployment_response_data = fm_client.get_instance_details_deployment(
            originating_op_instance.partner_federation_id, app_id, app_instance_id, zone_id, bearer_token,
            partner_api_root)
        
        # Check if the response contains an error from the partner API
        if "error" in deployment_response_data and "status_code" in deployment_response_data:
            status_code = deployment_response_data["status_code"]
            error_message = deployment_response_data["error"]
            raise APIError(status_code, f"Partner API error: {error_message}")
        elif "appInstanceState" in deployment_response_data:
            # Find instance details in originating operator
            if find_instance_details(federation_context_id, app_id, app_instance_id, zone_id):
                return deployment_response_data, 200
            else:
                raise APIError(409, "Application Deployment exist at partner operator but not in originating operator")
        else:
            if find_instance_details(federation_context_id, app_id, app_instance_id, zone_id):
                raise APIError(409, "Application Deployment exist in originating operator but not at partner operator")
            else:
                raise APIError(404, "Application Deployment not found")
    except ValidationError:
        raise APIError(400, f"Invalid federation context ID format: {federation_context_id}")
    except APIError:
        raise  # Re-raise APIError as-is
    except Exception as error:
        raise APIError(500, f"Error while getting app instance details. Reason: {error}")


def install_app(federation_context_id, body, bearer_token, partner_api_root):  # noqa: E501
    """Instantiates an application on a partner OP zone.

     # noqa: E501

    :param federation_context_id:
    :type federation_context_id: dict | bytes
    :param body: Details about application and zones where application instance should be created. It also definea call back URI which the partner OP shall use update home OP about a change in instance status.
    :type body: dict | bytes

    :rtype: InlineResponse202
    """

    # Verify partner API root is provided
    verify_required_header(partner_api_root)

    try:
        # Find federation at originating OP
        originating_op_objects = OriginatingOperatorPlatformOriginatingOP.objects(id=federation_context_id)
        if not originating_op_objects:
            raise APIError(404, "Federation not found")
        originating_op_instance = originating_op_objects[0]

        # Create deployment at partner
        deployment_response_data = fm_client.install_app_deployment(originating_op_instance.partner_federation_id,
                                                                    body, bearer_token,
                                                                    partner_api_root)
        
        # Check if the response contains an error from the partner API
        if "error" in deployment_response_data and "status_code" in deployment_response_data:
            status_code = deployment_response_data["status_code"]
            error_message = deployment_response_data["error"]
            raise APIError(status_code, f"Partner API error: {error_message}")
        elif "appInstIdentifier" in deployment_response_data:
            install_app_originating_op(federation_context_id, originating_op_instance.partner_federation_id, body,
                                       deployment_response_data)
            return deployment_response_data, 202
        else:
            raise APIError(422, f"Unexpected response from partner API: {deployment_response_data}")
    except ValidationError:
        raise APIError(400, f"Invalid federation context ID format: {federation_context_id}")
    except APIError:
        raise  # Re-raise APIError as-is
    except Exception as error:
        raise APIError(500, f"Error installing application. Reason: {error}")


def remove_app(federation_context_id, app_id, app_instance_id, zone_id, bearer_token, partner_api_root):  # noqa: E501
    """Terminate an application instance on a partner OP zone.

     # noqa: E501

    :param federation_context_id:
    :type federation_context_id: dict | bytes
    :param app_id:
    :type app_id: dict | bytes
    :param app_instance_id:
    :type app_instance_id: dict | bytes
    :param zone_id:
    :type zone_id: dict | bytes

    :rtype: None
    """

    # Verify partner API root is provided
    verify_required_header(partner_api_root)

    try:
        # Find federation at originating OP
        originating_op_objects = OriginatingOperatorPlatformOriginatingOP.objects(id=federation_context_id)
        if not originating_op_objects:
            raise APIError(404, "Federation not found")
        originating_op_instance = originating_op_objects[0]
        
        # Find application deployment details at partner
        deployment_response_data = fm_client.get_instance_details_deployment(
            originating_op_instance.partner_federation_id, app_id, app_instance_id, zone_id, bearer_token,
            partner_api_root)

        # Check if the response contains an error from the partner API
        if "error" in deployment_response_data and "status_code" in deployment_response_data:
            status_code = deployment_response_data["status_code"]
            error_message = deployment_response_data["error"]
            raise APIError(status_code, f"Partner API error: {error_message}")
        elif "appInstanceState" in deployment_response_data:
            originating_ad_objects = find_instance_details(federation_context_id, app_id, app_instance_id, zone_id)
            if originating_ad_objects:
                # Delete application deployment at partner
                response_data = fm_client.remove_app_deployment(originating_op_instance.partner_federation_id, app_id,
                                                                app_instance_id, zone_id, bearer_token,
                                                                partner_api_root)
                
                # Check if the response contains an error from the partner API
                if "error" in response_data and "status_code" in response_data:
                    status_code = response_data["status_code"]
                    error_message = response_data["error"]
                    raise APIError(status_code, f"Partner API error: {error_message}")
                elif "termination" in response_data:
                    # If application deployment has been removed well, remove application deployment from originating
                    originating_ad_objects.delete()
                    return response_data, 200
                else:
                    raise APIError(422, f"Unexpected response from partner API: {response_data}")
            else:
                raise APIError(409, "Application Deployment exist at partner operator but not in originating operator")
        else:
            if find_instance_details(federation_context_id, app_id, app_instance_id, zone_id):
                raise APIError(409, "Application Deployment exist in originating operator but not at partner operator")
            else:
                raise APIError(404, "Application Deployment not found")
    except ValidationError:
        raise APIError(400, f"Invalid federation context ID format: {federation_context_id}")
    except APIError:
        raise  # Re-raise APIError as-is
    except Exception as error:
        raise APIError(500, f"Error removing application. Reason: {error}")


def install_app_originating_op(federation_id, partner_federation_id, body, response_partner):
    # Convert the original model instance to the MongoEngine document
    deployment_data = {
        "orig_ad_federation_context_id": federation_id,
        "orig_ad_instance_id": response_partner.get("appInstIdentifier"),
        "orig_ad_app_id": body.app_id,
        "orig_ad_app_version": body.app_version,
        "orig_ad_app_provider_id": body.app_provider_id,
        "orig_ad_zone_info_zone_id": response_partner.get("zoneId"),
        "orig_ad_zone_info_flavour_id": body.zone_info.flavour_id,
        "orig_ad_zone_info_resource_consumption": body.zone_info.resource_consumption,
        "orig_ad_zone_info_res_pool": body.zone_info.res_pool,
        "orig_ad_app_inst_callback_link": body.app_inst_callback_link,
        "partner_federation_id": partner_federation_id
    }
    # Create a new MongoEngine document and save it to MongoDB
    new_deployment = OriginatingApplicationDeploymentManagementOriginatingOP(**deployment_data)
    new_deployment.save()


def find_all_instances_originating_op(federation_id, app_id, app_provider_id):
    originating_ad_objects = OriginatingApplicationDeploymentManagementOriginatingOP.objects(
        orig_ad_federation_context_id=federation_id,
        orig_ad_app_id=app_id,
        orig_ad_app_provider_id=app_provider_id
    )
    return originating_ad_objects


def find_instance_details(federation_id, app_id, instance_id, zone_id):
    originating_ad_objects = OriginatingApplicationDeploymentManagementOriginatingOP.objects(
        orig_ad_federation_context_id=federation_id,
        orig_ad_app_id=app_id,
        orig_ad_instance_id=instance_id,
        orig_ad_zone_info_zone_id=zone_id
    )
    return originating_ad_objects
+395 −0

File added.

Preview size limit exceeded, changes collapsed.

+354 −0
Changes for src/adapters/fm_adapter/artefact_management.py: 354 added lines, 0 removed lines.
Original line number Diff line number Diff line
# -------------------------------------------------------------------------- #
# Copyright 2025-present, Federation Manager, by Software Networks, i2CAT    #
#                                                                            #
# 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.                                             #
# -------------------------------------------------------------------------- #
import json
from mongoengine.errors import ValidationError

from models.mongo_document import OriginatingOperatorPlatformOriginatingOP
from models.mongo_document import OriginatingArtefactManagementOriginatingOP
from adapters.error import APIError
from clients import fed_manager as fm_client


def verify_required_header(partner_api_root):
    if not partner_api_root:
        raise APIError(400, "X-Partner-API-Root header is missing")


def get_artefact(federation_context_id, artefact_id, bearer_token, partner_api_root):  # noqa: E501
    """Retrieves details about an artefact.

     # noqa: E501

    :param federation_context_id:
    :type federation_context_id: dict | bytes
    :param artefact_id:
    :type artefact_id: dict | bytes

    :rtype: InlineResponse2005
    """

    # Verify partner API root is provided
    verify_required_header(partner_api_root)

    try:
        # Find federation at originating OP
        originating_op_objects = OriginatingOperatorPlatformOriginatingOP.objects(id=federation_context_id)
        if not originating_op_objects:
            raise APIError(404, "Federation not found")
        originating_op_instance = originating_op_objects[0]

        # Find artefact at partner
        response_get = fm_client.get_artefact(originating_op_instance.partner_federation_id, artefact_id, bearer_token,
                                              partner_api_root)
        
        # Check if the response contains an error from the partner API
        if "error" in response_get and "status_code" in response_get:
            status_code = response_get["status_code"]
            error_message = response_get["error"]
            raise APIError(status_code, f"Partner API error: {error_message}")
        elif "artefactId" in response_get:
            if find_artefact_at_orig_op(federation_context_id, artefact_id):
                return response_get
            else:
                raise APIError(409, "Artefact exist at partner operator but not in originating operator")
        else:
            if find_artefact_at_orig_op(federation_context_id, artefact_id):
                raise APIError(409, "Artefact exist in originating operator but not in partner operator")
            else:
                raise APIError(404, "Artefact not Found")
    except ValidationError:
        raise APIError(400, f"Invalid federation context ID or artefact ID format: {federation_context_id}, {artefact_id}")
    except APIError:
        raise  # Re-raise APIError as-is
    except Exception as error:
        raise APIError(500, f"Error while getting Artefact. Reason: {error}")


def remove_artefact(federation_context_id, artefact_id, bearer_token, partner_api_root):  # noqa: E501
    """Removes an artefact from partner OP.

     # noqa: E501

    :param federation_context_id:
    :type federation_context_id: dict | bytes
    :param artefact_id:
    :type artefact_id: dict | bytes

    :rtype: None
    """

    # Verify partner API root is provided
    verify_required_header(partner_api_root)

    try:
        # Find federation at originating OP
        originating_op_objects = OriginatingOperatorPlatformOriginatingOP.objects(id=federation_context_id)
        if not originating_op_objects:
            raise APIError(404, "Federation not found")
        originating_op_instance = originating_op_objects[0]

        # Find artefact at partner
        response_get = fm_client.get_artefact(originating_op_instance.partner_federation_id, artefact_id, bearer_token,
                                              partner_api_root)
        
        # Check if the response contains an error from the partner API
        if "error" in response_get and "status_code" in response_get:
            status_code = response_get["status_code"]
            error_message = response_get["error"]
            raise APIError(status_code, f"Partner API error: {error_message}")
        elif "artefactId" in response_get:
            originating_am_objects = find_artefact_at_orig_op(federation_context_id, artefact_id)
            if originating_am_objects:
                # Delete artefact from partner
                response_data = fm_client.delete_artefact(originating_op_instance.partner_federation_id, artefact_id,
                                                          bearer_token, partner_api_root)
                
                # Check if the response contains an error from the partner API
                if "error" in response_data and "status_code" in response_data:
                    status_code = response_data["status_code"]
                    error_message = response_data["error"]
                    raise APIError(status_code, f"Partner API error: {error_message}")
                elif "deletion" in response_data:
                    # If artefact has been removed, remove artefact from originating
                    originating_am_objects.delete()
                    return response_data, 200
                else:
                    raise APIError(422, f"Unexpected response from partner API: {response_data}")
            else:
                raise APIError(409, "Artefact exist at partner operator but not in originating operator")
        else:
            if find_artefact_at_orig_op(federation_context_id, artefact_id):
                raise APIError(409, "Artefact exist in originating operator but not in partner operator")
            else:
                raise APIError(404, "Artefact not Found")
    except ValidationError:
        raise APIError(400, f"Invalid federation context ID or artefact ID format: {federation_context_id}, {artefact_id}")
    except APIError:
        raise  # Re-raise APIError as-is
    except Exception as error:
        raise APIError(500, f"Error while deleting Artefact. Reason: {error}")


def upload_artefact(body, federation_context_id, bearer_token, partner_api_root):  # noqa: E501
    """Uploads application artefact on partner OP. Artefact is a zip file containing scripts and/or packaging files like Terraform or Helm which are required to create an instance of an application.

     # noqa: E501

    :param body:
    :type body: dict | bytes
    :param federation_context_id:
    :type federation_context_id: dict | bytes

    :rtype: None
    """

    # Verify partner API root is provided
    verify_required_header(partner_api_root)

    try:
        # Find federation at originating OP
        originating_op_objects = OriginatingOperatorPlatformOriginatingOP.objects(id=federation_context_id)
        if not originating_op_objects:
            raise APIError(404, "Federation not found")
        originating_op_instance = originating_op_objects[0]
        
        # Find artefact at partner
        response_get = fm_client.get_artefact(originating_op_instance.partner_federation_id, body.artefact_id,
                                              bearer_token, partner_api_root)
        
        # Check if the response contains an error from the partner API
        if "error" in response_get and "status_code" in response_get:
            # If it's a 404, that means artefact doesn't exist at partner, which is what we want for upload
            if response_get["status_code"] != 404:
                status_code = response_get["status_code"]
                error_message = response_get["error"]
                raise APIError(status_code, f"Partner API error: {error_message}")
            # 404 means artefact doesn't exist at partner, continue with upload logic
            if find_artefact_at_orig_op(federation_context_id, body.artefact_id):
                raise APIError(409, "Artefact exist in Originating Operator but not in Partner Operator")
            else:
                # Create artefact in partner
                response_data = fm_client.create_artefact(originating_op_instance.partner_federation_id, body,
                                                          bearer_token, partner_api_root)
                
                # Check if the response contains an error from the partner API
                if "error" in response_data and "status_code" in response_data:
                    status_code = response_data["status_code"]
                    error_message = response_data["error"]
                    raise APIError(status_code, f"Partner API error: {error_message}")
                elif "uploaded" in response_data:
                    # Create artefact in originating
                    create_artefact_originating_op(federation_context_id, originating_op_instance.partner_federation_id,
                                                   body)
                    return response_data, 200
                else:
                    raise APIError(422, f"Unexpected response from partner API: {response_data}")
        elif "artefactId" in response_get:
            if find_artefact_at_orig_op(federation_context_id, body.artefact_id):
                raise APIError(409, "Artefact already exists")
            else:
                raise APIError(409, "Artefact exist in Partner Operator but not in Originating Operator")
        else:
            if find_artefact_at_orig_op(federation_context_id, body.artefact_id):
                raise APIError(409, "Artefact exist in Originating Operator but not in Partner Operator")
            else:
                # Create artefact in partner
                response_data = fm_client.create_artefact(originating_op_instance.partner_federation_id, body,
                                                          bearer_token, partner_api_root)
                
                # Check if the response contains an error from the partner API
                if "error" in response_data and "status_code" in response_data:
                    status_code = response_data["status_code"]
                    error_message = response_data["error"]
                    raise APIError(status_code, f"Partner API error: {error_message}")
                elif "uploaded" in response_data:
                    # Create artefact in originating
                    create_artefact_originating_op(federation_context_id, originating_op_instance.partner_federation_id,
                                                   body)
                    return response_data, 200
                else:
                    raise APIError(422, f"Unexpected response from partner API: {response_data}")
    except ValidationError:
        raise APIError(400, f"Invalid federation context ID format: {federation_context_id}")
    except APIError:
        raise  # Re-raise APIError as-is
    except Exception as error:
        raise APIError(500, f"Error while creating Artefact. Reason: {error}")


def find_artefact_at_orig_op(federation_id, artefact_id):
    originating_am_objects = OriginatingArtefactManagementOriginatingOP.objects(
        orig_am_federation_context_id=federation_id,
        orig_am_artefact_id=artefact_id)

    return originating_am_objects


def create_artefact_originating_op(federation_id, partner_federation_id, body):
    component_spec_list = []
    for c in body.component_spec:

        exposed_interfaces_list = []
        for e in c.exposed_interfaces or []:
            data_ei = {
                "orig_ei_interface_id": e.interface_id,
                "orig_ei_comm_protocol": e.comm_protocol,
                "orig_ei_comm_port": e.comm_port,
                "orig_ei_visibility_type": e.visibility_type,
                "orig_ei_network": e.network,
                "orig_ei_interface_name": e.interface_name
            }
            exposed_interfaces_list.append(data_ei)

        gpu_list = []
        for g in c.compute_resource_profile.gpu or []:
            data_gpu = {
                "orig_g_gpu_vendor_type": g.gpu_vendor_type,
                "orig_g_gpu_mode_name": g.gpu_mode_name,
                "orig_g_gpu_memory": g.gpu_memory,
                "orig_g_num_gpu": g.num_gpu,
            }
            gpu_list.append(data_gpu)

        huge_pages_list = []
        for h in c.compute_resource_profile.hugepages or []:
            data_hp = {
                "orig_h_page_size": h.page_size,
                "orig_h_number": h.number
            }
            huge_pages_list.append(data_hp)

        comp_env_params_list = []
        for cep in c.comp_env_params or []:
            data_comp = {
                "orig_cep_env_var_name": cep.env_var_name,
                "orig_cep_env_value_type": cep.env_value_type,
                "orig_cep_env_var_value": cep.env_var_value,
                "orig_cep_env_var_src": cep.env_var_src
            }
            comp_env_params_list.append(data_comp)

        pv_list = []
        for v in c.persistent_volumes or []:
            data_pv = {
                "orig_pv_volume_size": v.volume_size,
                "orig_pv_volume_mounth_path": v.volume_mount_path,
                "orig_pv_volume_name": v.volume_name,
                "orig_pv_ephemeral_type": v.ephemeral_type,
                "orig_pv_access_mode": v.access_mode,
                "orig_pv_sharing_policy": v.sharing_policy
            }
            pv_list.append(data_pv)

        command_line_params_command = None
        command_line_params_command_args = None
        if c.command_line_params:
            command_line_params_command = c.command_line_params.command
            command_line_params_command_args = c.command_line_params.command_args

        deployment_config_config_type = None
        deployment_config_contents = None
        if c.deployment_config:
            deployment_config_config_type = c.deployment_config.config_type
            deployment_config_contents = c.deployment_config.contents

        data_ce = {
            "orig_ce_component_name": c.component_name,
            "orig_ce_component_spec_images": c.images,
            "orig_ce_component_spec_num_of_instances": c.num_of_instances,
            "orig_ce_component_spec_restart_policy": c.restart_policy,
            "orig_ce_component_spec_command_line_params_command": command_line_params_command,
            "orig_ce_component_spec_command_line_params_command_args": command_line_params_command_args,
            "orig_ce_component_spec_exposed_interfaces": exposed_interfaces_list,
            "orig_ce_component_spec_compute_resource_profile_cpuarchtype": c.compute_resource_profile.cpu_arch_type,
            "orig_ce_component_spec_compute_resource_profile_numcpu": c.compute_resource_profile.num_cpu,
            "orig_ce_component_spec_compute_resource_profile_memory": c.compute_resource_profile.memory,
            "orig_ce_component_spec_compute_resource_profile_diskstorage": c.compute_resource_profile.disk_storage,
            "orig_ce_component_spec_compute_resource_profile_gpu": gpu_list,
            "orig_ce_component_spec_compute_resource_profile_vpu": c.compute_resource_profile.vpu,
            "orig_ce_component_spec_compute_resource_profile_fpga": c.compute_resource_profile.fpga,
            "orig_ce_component_spec_compute_resource_profile_hugepages": huge_pages_list,
            "orig_ce_component_spec_compute_resource_profile_cpuexclusivity": c.compute_resource_profile.cpu_exclusivity,
            "orig_ce_component_spec_comp_env_params": comp_env_params_list,
            "orig_ce_component_spec_deployment_config_config_type": deployment_config_config_type,
            "orig_ce_component_spec_deployment_config_contents": deployment_config_contents,
            "orig_ce_component_spec_persistent_volumes": pv_list
        }
        component_spec_list.append(data_ce)

    artefact_data = {
        "orig_am_federation_context_id": federation_id,
        "orig_am_artefact_id": body.artefact_id,
        "orig_am_app_provider_id": body.app_provider_id,
        "orig_am_artefact_name": body.artefact_name,
        "orig_am_artefact_version_info": body.artefact_version_info,
        "orig_am_artefact_description": body.artefact_description,
        "orig_am_artefact_virt_type": body.artefact_virt_type,
        "orig_am_artefact_filename": body.artefact_file_name,
        "orig_am_artefact_file_format": body.artefact_file_format,
        "orig_am_artefact_descriptor_type": body.artefact_descriptor_type,
        "orig_am_repo_type": body.repo_type,
        "orig_am_artefact_repo_location_repo_url": body.artefact_repo_location.repo_url,
        "orig_am_artefact_repo_location_user_name": body.artefact_repo_location.user_name,
        "orig_am_artefact_repo_location_password": body.artefact_repo_location.password,
        "orig_am_artefact_repo_location_token": body.artefact_repo_location.token,
        "orig_am_artefact_file": "",
        "orig_am_component_spec": json.dumps(component_spec_list),
        "partner_federation_id": partner_federation_id
    }
    # Create a new MongoEngine document and save it to MongoDB
    new_artefact = OriginatingArtefactManagementOriginatingOP(**artefact_data)
    new_artefact.save()
Loading
Loading