aboutsummaryrefslogtreecommitdiffstats
path: root/src/onaptests/steps/cloud/cloud_region_create.py
blob: fcda2518997f26308abe7e288656baab86307418 (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
"""A&AI cloud region creation module."""
from onapsdk.aai.cloud_infrastructure import CloudRegion
from onapsdk.configuration import settings
from onapsdk.exceptions import ResourceNotFound

from ..base import BaseStep


class CloudRegionCreateStep(BaseStep):
    """Cloud region creation step."""

    def __init__(self):
        """Initialize step."""
        super().__init__(cleanup=BaseStep.HAS_NO_CLEANUP)

    @property
    def description(self) -> str:
        """Step description."""
        return "Create cloud region."

    @property
    def component(self) -> str:
        """Component name."""
        return "AAI"

    @BaseStep.store_state
    def execute(self):
        """Create cloud region.

        Use settings values:
         - CLOUD_REGION_CLOUD_OWNER,
         - CLOUD_REGION_ID,
         - CLOUD_REGION_TYPE,
         - CLOUD_REGION_VERSION,
         - CLOUD_OWNER_DEFINED_TYPE,
         - COMPLEX_PHYSICAL_LOCATION_ID.

        """
        super().execute()
        self._logger.info("*Check if cloud region exists *")
        try:
            CloudRegion.get_by_id(
                cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
                cloud_region_id=settings.CLOUD_REGION_ID,
            )
        except ResourceNotFound:
            CloudRegion.create(
                cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
                cloud_region_id=settings.CLOUD_REGION_ID,
                orchestration_disabled=False,
                in_maint=False,
                cloud_type=settings.CLOUD_REGION_TYPE,
                cloud_region_version=settings.CLOUD_REGION_VERSION,
                owner_defined_type=settings.CLOUD_OWNER_DEFINED_TYPE,
                complex_name=settings.COMPLEX_PHYSICAL_LOCATION_ID
            )