Docs: Add API docs from swagger json file; Add user guide document
[pti/o2.git] / docs / user-guide.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2 .. SPDX-License-Identifier: CC-BY-4.0
3 .. Copyright (C) 2021 Wind River Systems, Inc.
4
5 O-Cloud O2 Service User Guide
6 =============================
7
8 This guide will introduce the process that make O2 interface work with
9 SMO.
10
11 -  Assume you have an O-Cloud O2 environment
12
13 -  Discover O-Cloud inventory
14
15    -  O-Cloud auto discovery
16
17       After you installed the O-Cloud service, it will automatically
18       discover the INF through the parameters that you give from the
19       “*o2service-override.yaml*”
20
21       Below command can get the O-Cloud information
22
23       .. code:: shell
24
25          curl -X 'GET' \
26            'http://<OAM IP>:30205/o2ims_infrastructureInventory/v1/' \
27            -H 'accept: application/json'
28
29    -  Resource pool
30
31       One O-Cloud have one resource pool, all the resources that belong
32       to this O-Cloud will be organized into this resource pool
33
34       Get the resource pool information through this interface
35
36       .. code:: shell
37
38          curl -X 'GET' \
39            'http://<OAM IP>:30205/o2ims_infrastructureInventory/v1/resourcePools' \
40            -H 'accept: application/json'
41
42    -  Resource type
43
44       Resource type defined what type is the specified resource, like a
45       physical machine, memory, or CPU
46
47       Show all resource type
48
49       .. code:: shell
50
51          curl -X 'GET' \
52            'http://<OAM IP>:30205/o2ims_infrastructureInventory/v1/resourceTypes' \
53            -H 'accept: application/json'
54
55    -  Resource
56
57       Get the list of all resources, the value of *resourcePoolId* from
58       the result of resource pool interface
59
60       .. code:: shell
61
62          curl -X 'GET' \
63            "http://<OAM IP>:30205/o2ims_infrastructureInventory/v1/resourcePools/${resourcePoolId}/resources" \
64            -H 'accept: application/json'
65
66       Get detail of one resource
67
68       .. code:: shell
69
70          curl -X 'GET' \
71            "http://<OAM IP>:30205/o2ims_infrastructureInventory/v1/resourcePools/${resourcePoolId}/resources/${resourceId}" \
72            -H 'accept: application/json'
73
74    -  Deployment manager services endpoint
75
76       The Deployment Manager Service (DMS) that related to this IMS
77       information you can use below API to check
78
79       .. code:: shell
80
81          curl -X 'GET' \
82            'http://<OAM IP>:30205/o2ims_infrastructureInventory/v1/deploymentManagers' \
83            -H 'accept: application/json'
84
85 -  Subscribe to the O-Cloud resource change notification
86
87    Assume you have a SMO, and the SMO have an API can be receive
88    callback request
89
90    -  Create subscription in O-Cloud IMS
91
92       .. code:: bash
93
94          curl -X 'POST' \
95            'http://<OAM IP>:30205/o2ims_infrastructureInventory/v1/subscriptions' \
96            -H 'accept: application/json' \
97            -H 'Content-Type: application/json' \
98            -d '{
99            "callback": "http://SMO/address/to/callback",
100            "consumerSubscriptionId": "<ConsumerIdHelpSmoToIdentify>",
101            "filter": "<ResourceTypeNameSplitByComma,EmptyToGetAll>"
102          }'
103
104    -  Handle resource change notification
105
106       When the SMO callback API get the notification that the resource
107       of O-Cloud changing, use the URL to get the latest resource
108       information to update its database
109
110 -  Orchestrate CNF in helm chart
111
112    On this sample, we prepare a firewall chart to test the
113    orchestration.
114
115    We need to do some preparation to make the helm repo work and include
116    our firewall chart inside of the repository.
117
118       Get the DMS Id in the O-Cloud, and set it into bash environment
119
120       .. code:: bash
121
122          curl --location --request GET 'http://<OAM IP>:30205/o2ims_infrastructureInventory/v1/deploymentManagers'
123
124          export dmsId=`curl --location --request GET 'http://<OAM IP>:30205/o2ims_infrastructureInventory/v1/deploymentManagers' 2>/dev/null | jq .[].deploymentManagerId | xargs echo`
125
126       Using helm to deploy a chartmuseum to the INF
127
128       .. code:: bash
129
130          helm pull chartmuseum/chartmuseum # download chartmuseum-3.4.0.tgz to local
131          tar zxvf chartmuseum-3.4.0.tgz
132          cat <<EOF>chartmuseum-override.yaml
133          env:
134           open:
135             DISABLE_API: false
136          service:
137           type: NodePort
138           nodePort: 30330
139          EOF
140
141          helm install chartmuseumrepo chartmuseum/chartmuseum -f chartmuseum-override.yaml
142          kubectl get pods
143          Kubectl get services
144
145       Update the helm repo and add the chartmusem into the repository
146
147       .. code:: bash
148
149          helm repo add o2imsrepo http://${NODE_IP}:30330
150          helm repo update
151
152       Download the firewall chart and push it into the repository
153
154       .. code:: bash
155
156          git clone https://github.com/biny993/firewall-host-netdevice.git
157          tar -zcvf firewall-host-netdevice-1.0.0.tgz firewall-host-netdevice/
158          helm push firewall-host-netdevice-1.0.0.tgz o2imsrepo
159          helm repo update
160          helm search repo firewall
161
162    -  Create NfDeploymentDescriptor
163
164       .. code:: bash
165
166          curl --location --request POST "http://<OAM IP>:30205/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeploymentDescriptor" \
167          --header 'Content-Type: application/json' \
168          --data-raw '{
169            "name": "cfwdesc1",
170            "description": "demo nf deployment descriptor",
171            "artifactRepoUrl": "http://${NODE_IP}:30330",
172            "artifactName": "firewall-host-netdevice",
173            "inputParams": 
174            "{\n  \"image\": {\n    \"repository\": \"ubuntu\",\n    \"tag\": 18.04,\n    \"pullPolicy\": \"IfNotPresent\"\n  },\n  \"resources\": {\n    \"cpu\": 2,\n    \"memory\": \"2Gi\",\n    \"hugepage\": \"256Mi\",\n    \"unprotectedNetPortVpg\": \"veth11\",\n    \"unprotectedNetPortVfw\": \"veth12\",\n    \"unprotectedNetCidr\": \"10.10.1.0/24\",\n    \"unprotectedNetGwIp\": \"10.10.1.1\",\n    \"protectedNetPortVfw\": \"veth21\",\n    \"protectedNetPortVsn\": \"veth22\",\n    \"protectedNetCidr\": \"10.10.2.0/24\",\n    \"protectedNetGwIp\": \"10.10.2.1\",\n    \"vfwPrivateIp0\": \"10.10.1.1\",\n    \"vfwPrivateIp1\": \"10.10.2.1\",\n    \"vpgPrivateIp0\": \"10.10.1.2\",\n    \"vsnPrivateIp0\": \"10.10.2.2\"\n  }\n}",
175            "outputParams": "{\"output1\": 100}"
176          }'
177
178          curl --location --request GET "http://<OAM IP>:30205/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeploymentDescriptor"
179
180    -  Create NfDeployment
181
182       When you have an descriptor of deployment, you can create a
183       NfDeployment, it will trigger an event inside of the IMS/DMS, and
184       use the K8S API to create a real pod of the firewall sample
185
186       .. code:: bash
187
188          curl --location --request POST "http://<OAM IP>:30205/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeployment" \
189          --header 'Content-Type: application/json' \
190          --data-raw '{
191            "name": "cfw100",
192            "description": "demo nf deployment",
193            "descriptorId": "<Descriptor ID>",
194            "parentDeploymentId": ""
195          }'
196
197          curl --location --request GET "http://<OAM IP>:30205/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeployment"
198
199    -  Check pods of the firewall sample
200
201       .. code:: bash
202
203          kubectl get pods
204
205    -  Delete the deployment we just created
206
207       .. code:: shell
208
209          export NfDeploymentId=`curl --location --request GET 'http://<OAM IP>:30205/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeployment' 2>/dev/null | jq .[].id | xargs echo`
210
211          curl --location --request DELETE "http://<OAM IP>:30205/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeployment/${NfDeploymentId}"