aboutsummaryrefslogtreecommitdiffstats
path: root/src/onapsdk/sdc/pnf.py
blob: 3fe46578d60d51d12e16e16f74f321d57ff939cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""Pnf module."""
#   Copyright 2022 Orange, Deutsche Telekom AG
#
#   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 typing import Dict, List, Union
from onapsdk.exceptions import ParameterError

from onapsdk.sdc.sdc_resource import SdcResource
from onapsdk.sdc.properties import NestedInput, Property
import onapsdk.constants as const
from onapsdk.sdc.vendor import Vendor
from onapsdk.sdc.vsp import Vsp


class Pnf(SdcResource):
    """
    ONAP PNF Object used for SDC operations.

    Attributes:
        name (str): the name of the pnf. Defaults to "ONAP-test-PNF".
        identifier (str): the unique ID of the pnf from SDC.
        status (str): the status of the pnf from SDC.
        version (str): the version ID of the vendor from SDC.
        uuid (str): the UUID of the PNF (which is different from identifier,
                    don't ask why...)
        unique_identifier (str): Yet Another ID, just to puzzle us...
        vendor (optional): the vendor of the PNF
        vsp (optional): the vsp related to the PNF

    """

    def __init__(self, name: str = None, version: str = None, vendor: Vendor = None, # pylint: disable=too-many-arguments
                 sdc_values: Dict[str, str] = None, vsp: Vsp = None,
                 properties: List[Property] = None, inputs: Union[Property, NestedInput] = None,
                 category: str = None, subcategory: str = None):
        """
        Initialize pnf object.

        Args:
            name (optional): the name of the pnf
            version (str, optional): the version of a PNF object

        """
        super().__init__(sdc_values=sdc_values, version=version, properties=properties,
                         inputs=inputs, category=category, subcategory=subcategory)
        self.name: str = name or "ONAP-test-PNF"
        self.vendor: Vendor = vendor
        self.vsp: Vsp = vsp

    def create(self) -> None:
        """Create the PNF in SDC if not already existing."""
        if not self.vsp and not self.vendor:
            raise ParameterError("Neither Vsp nor Vendor provided.")
        self._create("pnf_create.json.j2",
                     name=self.name,
                     vsp=self.vsp,
                     vendor=self.vendor,
                     category=self.category)

    def _really_submit(self) -> None:
        """Really submit the SDC PNF in order to enable it."""
        result = self._action_to_sdc(const.CERTIFY, "lifecycleState")
        if result:
            self.load()