aboutsummaryrefslogtreecommitdiffstats
path: root/docs/usage/usage/cloud_configuration.rst
blob: b048c0a5bff0fba56bfc8aa2a15159d68a956d98 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
Cloud configuration
###################

Create a complex
----------------

.. code:: Python

    from onapsdk.aai.cloud_infrastructure import Complex
    cmplx = Complex.create(
        physical_location_id=COMPLEX_PHYSICAL_LOCATION_ID,
        data_center_code=COMPLEX_DATA_CENTER_CODE,
        name=COMPLEX_PHYSICAL_LOCATION_ID
    )

Create cloud region
-------------------

.. code:: Python

    from onapsdk.aai.cloud_infrastructure import CloudRegion
    cloud_region = CloudRegion.create(
        cloud_owner=CLOUD_OWNER,
        cloud_region_id=CLOUD_REGION,
        orchestration_disabled=False,
        in_maint=False,
        cloud_type=CLOUD_TYPE,
        cloud_region_version=CLOUD_REGION_VERSION
    )

Link cloud region to complex
----------------------------

.. code:: Python

    from onapsdk.aai.cloud_infrastructure import CloudRegion, Complex
    # We assume that complex has been already created
    cmplx = Complex(
        physical_location_id=COMPLEX_PHYSICAL_LOCATION_ID,
        name=COMPLEX_PHYSICAL_LOCATION_ID
    )
    cloud_region = CloudRegion.create(
        cloud_owner=CLOUD_OWNER,
        cloud_region_id=CLOUD_REGION,
        orchestration_disabled=False,
        in_maint=False,
        cloud_type=CLOUD_TYPE,
        cloud_region_version=CLOUD_REGION_VERSION
    )
    cloud_region.link_to_complex(cmplx)

Add ESR Info to cloud region
----------------------------

.. code:: Python

    from uuid import uuid4
    from onapsdk.aai.cloud_infrastructure import CloudRegion
    # We assume that cloud region has been already created
    cloud_region = CloudRegion.get_by_id(
        cloud_owner=CLOUD_OWNER,
        cloud_region_id=CLOUD_REGION
    )
    cloud_region.add_esr_system_info(
        esr_system_info_id=str(uuid4()),
        user_name=VIM_USERNAME,
        password=VIM_PASSWORD,
        system_type=CLOUD_TYPE,
        service_url=VIM_SERVICE_URL,
        cloud_domain=CLOUD_DOMAIN
    )

Register cloud to MultiCloud
----------------------------

.. code:: Python

    from uuid import uuid4
    from onapsdk.aai.cloud_infrastructure import CloudRegion
    # We assume that cloud region has been already created
    cloud_region = CloudRegion.get_by_id(
        cloud_owner=CLOUD_OWNER,
        cloud_region_id=CLOUD_REGION
    )
    cloud_region.add_esr_system_info(
        esr_system_info_id=str(uuid4()),
        user_name=VIM_USERNAME,
        password=VIM_PASSWORD,
        system_type=CLOUD_TYPE,
        service_url=VIM_SERVICE_URL,
        cloud_domain=CLOUD_DOMAIN
    )
    cloud_region.register_to_multicloud()

Get cloud region tenant
-----------------------

.. code:: Python

    # We assume that cloud region has been already created
    # and connected to multicloud
    from onapsdk.aai.cloud_infrastructure import CloudRegion
    cloud_region = CloudRegion.get_by_id(
        cloud_owner=CLOUD_OWNER,
        cloud_region_id=CLOUD_REGION
    )
    try:
        tenant = next(cloud_region.tenant)
    except StopIteration
        # No Tenant found in cloud region

Create customer
---------------

.. code:: Python

    from onapsdk.aai.business import Customer
    customer = Customer.create(GLOBAL_CUSTOMER_ID, GLOBAL_CUSTOMER_ID, "INFRA")

Create customer service subscription
------------------------------------

.. code:: Python

    # We assume here that the service has been already onboarded
    # and customer created
    from onapsdk.aai.business import Customer

    customer = Customer.get_by_global_customer_id(GLOBAL_CUSTOMER_ID)
    customer.subscribe_service("service_type")

    # Service subscriptions can be also created during Customer
    # creation
    from onapsdk.aai.business import Customer

    customer = Customer.create(GLOBAL_CUSTOMER_ID, GLOBAL_CUSTOMER_ID, "INFRA", service_subscriptions=["service_type"])

Connect service subscription to cloud region and tenant
-------------------------------------------------------

.. code:: Python

    # We assume here that the service subscription has been already created
    # and cloud region has a tenant
    from onapsdk.aai.business import Customer
    from onapsdk.aai.cloud_infrastructure import CloudRegion, Tenant

    customer = Customer.get_by_global_customer_id(GLOBAL_CUSTOMER_ID)
    service_subscription = next(customer.service_subscriptions)
    cloud_region = CloudRegion.get_by_id(
        cloud_owner=CLOUD_OWNER,
        cloud_region_id=CLOUD_REGION
    )
    tenant = next(cloud_region.tenants)
    service_subscription.link_to_cloud_region_and_tenant(cloud_region, tenant)

Add Cloud SIte entry to SO Catalog DB
-------------------------------------------------------

.. code:: Python

    from onapsdk.so.so_db_adapter import IdentityService, SoDbAdapter

    identity_service = IdentityService(identity_id="mc_test_identity_1_KEYSTONE",
                                       url="http://test:5000/v3",
                                       mso_id="test_user",
                                       mso_pass="test_password_encrypted",
                                       roject_domain_name="Default",
                                       user_domain_name="Default",
                                       identity_server_type="KEYSTONE_V3")
    response = SoDbAdapter.add_cloud_site(cloud_region_id="test_region_1",
                                          complex_id="test_clli_1",
                                          identity_service=identity_service,
                                          orchestrator="NULL")

Use A&AI bulk API (experimental)
--------------------------------

.. code:: Python

    from onapsdk.aai.bulk import AaiBulk, AaiBulkRequest
    from onapsdk.aai.cloud_infrastructure.cloud_region import CloudRegion
    from onapsdk.utils.jinja import jinja_env


    for resp in AaiBulk.single_transaction(
        [
            AaiBulkRequest(
                action="put",
                uri=f"/cloud-infrastructure/cloud-regions/cloud-region/aai_bulk_test_cloud_owner_1/aai_bulk_test_cloud_region_id_1",
                body=jinja_env().get_template("cloud_region_create.json.j2").render(cloud_region=CloudRegion(
                        cloud_owner="aai_bulk_test_cloud_owner_1",
                        cloud_region_id="aai_bulk_test_cloud_region_id_1",
                        orchestration_disabled=False,
                        in_maint=False
                    ))
            ),
            AaiBulkRequest(
                action="put",
                uri=f"/cloud-infrastructure/cloud-regions/cloud-region/aai_bulk_test_cloud_owner_2/aai_bulk_test_cloud_region_id_2",
                body=jinja_env().get_template("cloud_region_create.json.j2").render(cloud_region=CloudRegion(
                        cloud_owner="aai_bulk_test_cloud_owner_2",
                        cloud_region_id="aai_bulk_test_cloud_region_id_2",
                        orchestration_disabled=False,
                        in_maint=False
                    ))
            )
        ]
    ):
        print(resp)