a2bea07130b96129ba7c55f87ddb08ea56677609
[pti/o2.git] / docs / user-guide.rst
1 O-Cloud O2 Service User Guide
2 =============================
3
4 This guide will introduce the process that make O2 interface work with
5 SMO.
6
7 -  Assume you have an O-Cloud O2 environment
8
9    .. code:: bash
10
11       export OAM_IP=<INF_OAM_IP>
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          # export resource pool id
43          export resourcePoolId=`curl -X 'GET'   "http://${OAM_IP}:30205/o2ims_infrastructureInventory/v1/resourcePools"   -H 'accept: application/json' -H 'X-Fields: resourcePoolId' 2>/dev/null | jq .[].resourcePoolId | xargs echo`
44
45          echo ${resourcePoolId} # check the exported resource pool id
46
47    -  Resource type
48
49       Resource type defined what type is the specified resource, like a
50       physical machine, memory, or CPU
51
52       Show all resource type
53
54       .. code:: shell
55
56          curl -X 'GET' \
57            "http://${OAM_IP}:30205/o2ims_infrastructureInventory/v1/resourceTypes" \
58            -H 'accept: application/json'
59
60    -  Resource
61
62       Get the list of all resources, the value of *resourcePoolId* from
63       the result of resource pool interface
64
65       .. code:: shell
66
67          curl -X 'GET' \
68            "http://${OAM_IP}:30205/o2ims_infrastructureInventory/v1/resourcePools/${resourcePoolId}/resources" \
69            -H 'accept: application/json'
70
71       Get detail of one resource, need to export one specific resource
72       id that wants to check
73
74       .. code:: shell
75
76          curl -X 'GET' \
77            "http://${OAM_IP}:30205/o2ims_infrastructureInventory/v1/resourcePools/${resourcePoolId}/resources/${resourceId}" \
78            -H 'accept: application/json'
79
80    -  Deployment manager services endpoint
81
82       The Deployment Manager Service (DMS) that related to this IMS
83       information you can use below API to check
84
85       .. code:: shell
86
87          curl -X 'GET' \
88            "http://${OAM_IP}:30205/o2ims_infrastructureInventory/v1/deploymentManagers" \
89            -H 'accept: application/json'
90
91 -  Subscribe to the O-Cloud resource change notification
92
93    Assume you have a SMO, and the SMO have an API can be receive
94    callback request
95
96    -  Create subscription in O-Cloud IMS
97
98       .. code:: bash
99
100          curl -X 'POST' \
101            "http://${OAM_IP}:30205/o2ims_infrastructureInventory/v1/subscriptions" \
102            -H 'accept: application/json' \
103            -H 'Content-Type: application/json' \
104            -d '{
105            "callback": "http://SMO/address/to/callback",
106            "consumerSubscriptionId": "<ConsumerIdHelpSmoToIdentify>",
107            "filter": "<ResourceTypeNameSplitByComma,EmptyToGetAll>"
108          }'
109
110    -  Handle resource change notification
111
112       When the SMO callback API get the notification that the resource
113       of O-Cloud changing, use the URL to get the latest resource
114       information to update its database
115
116 -  Orchestrate CNF in helm chart
117
118    On this sample, we prepare a firewall chart to test the
119    orchestration.
120
121    We need to do some preparation to make the helm repo work and include
122    our firewall chart inside of the repository.
123
124       Get the DMS Id in the O-Cloud, and set it into bash environment
125
126       .. code:: bash
127
128          curl --location --request GET "http://${OAM_IP}:30205/o2ims_infrastructureInventory/v1/deploymentManagers"
129
130          export dmsId=`curl --location --request GET "http://${OAM_IP}:30205/o2ims_infrastructureInventory/v1/deploymentManagers" 2>/dev/null | jq .[].deploymentManagerId | xargs echo`
131
132          echo ${dmsId} # check the exported DMS id
133
134       Using helm to deploy a chartmuseum to the INF
135
136       .. code:: bash
137
138          helm repo add chartmuseum https://chartmuseum.github.io/charts
139          helm repo update
140          helm pull chartmuseum/chartmuseum # download chartmuseum-3.4.0.tgz to local
141          tar zxvf chartmuseum-3.4.0.tgz
142          cat <<EOF>chartmuseum-override.yaml
143          env:
144            open:
145              DISABLE_API: false
146          service:
147            type: NodePort
148            nodePort: 30330
149          EOF
150
151          helm install chartmuseumrepo chartmuseum/chartmuseum -f chartmuseum-override.yaml
152          kubectl get pods
153          Kubectl get services
154
155       Update the helm repo and add the chartmusem into the repository
156
157       .. code:: bash
158
159          helm repo add o2imsrepo http://${NODE_IP}:30330
160          helm repo update
161
162       Download the firewall chart and push it into the repository
163
164       .. code:: bash
165
166          git clone https://github.com/biny993/firewall-host-netdevice.git
167          tar -zcvf firewall-host-netdevice-1.0.0.tgz firewall-host-netdevice/
168          helm plugin install https://github.com/chartmuseum/helm-push.git
169          helm cm-push firewall-host-netdevice-1.0.0.tgz o2imsrepo
170          helm repo update
171          helm search repo firewall
172
173       Setup host net device over INF
174
175       .. code:: bash
176
177          ssh sysadmin@<INF OAM IP>
178          sudo ip link add name veth11 type veth peer name veth12
179          sudo ip link add name veth21 type veth peer name veth22
180          sudo ip link |grep veth
181          exit
182
183    -  Create NfDeploymentDescriptor
184
185       .. code:: bash
186
187          curl --location --request POST "http://${OAM_IP}:30205/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeploymentDescriptor" \
188          --header 'Content-Type: application/json' \
189          --data-raw '{
190            "name": "cfwdesc1",
191            "description": "demo nf deployment descriptor",
192            "artifactRepoUrl": "http://'${NODE_IP}':30330",
193            "artifactName": "firewall-host-netdevice",
194            "inputParams": 
195            "{\n  \"image\": {\n    \"repository\": \"ubuntu\",\n    \"tag\": 18.04,\n    \"pullPolicy\": \"IfNotPresent\"\n  },\n  \"resources\": {\n    \"cpu\": 2,\n    \"memory\": \"2Gi\",\n    \"hugepage\": \"0Mi\",\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}",
196            "outputParams": "{\"output1\": 100}"
197          }'
198
199          curl --location --request GET "http://${OAM_IP}:30205/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeploymentDescriptor"
200
201          export descId=` curl -X 'GET'   "http://${OAM_IP}:30205/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeploymentDescriptor"   -H 'accept: application/json'   -H 'X-Fields: id' 2>/dev/null | jq .[].id | xargs echo`
202
203          echo ${descId} # check the exported descriptor id
204
205    -  Create NfDeployment
206
207       When you have an descriptor of deployment, you can create a
208       NfDeployment, it will trigger an event inside of the IMS/DMS, and
209       use the K8S API to create a real pod of the firewall sample
210
211       .. code:: bash
212
213          curl --location --request POST "http://${OAM_IP}:30205/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeployment" \
214          --header 'Content-Type: application/json' \
215          --data-raw '{
216            "name": "cfw100",
217            "description": "demo nf deployment",
218            "descriptorId": "'${descId}'",
219            "parentDeploymentId": ""
220          }'
221
222          curl --location --request GET "http://${OAM_IP}:30205/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeployment"
223
224    -  Check pods of the firewall sample
225
226       .. code:: bash
227
228          kubectl get pods
229
230    -  Delete the deployment we just created
231
232       .. code:: shell
233
234          export NfDeploymentId=`curl --location --request GET "http://${OAM_IP}:30205/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeployment" 2>/dev/null | jq .[].id | xargs echo`
235
236          echo ${NfDeploymentId} # Check the exported deployment id
237
238          curl --location --request DELETE "http://${OAM_IP}:30205/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeployment/${NfDeploymentId}"