Fix bug 2074 to delete properly unzipped packages during osm repo-index
[osm/osmclient.git] / README.md
1 <!--
2 Copyright 2020 ETSI
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 implied.
14 See the License for the specific language governing permissions and
15 limitations under the License
16 -->
17 # python-osmclient
18
19 OSM client library and console script
20
21 ## Installation
22
23 ### From git-repo
24
25 ```bash
26 # Ubuntu 18.04 pre-requirements
27 sudo apt-get install python3-pip libcurl4-openssl-dev libssl-dev
28 # CentOS pre-requirements
29 # sudo yum install python3-pip libcurl-devel gnutls-devel
30 sudo -H python3 -m pip install python-magic
31 # Install OSM Information model
32 sudo -H python3 -m pip install git+https://osm.etsi.org/gerrit/osm/IM --upgrade
33 # Install OSM client from the git repo.
34 # You can install the latest client from master branch in this way:
35 sudo -H python3 -m pip install git+https://osm.etsi.org/gerrit/osm/osmclient
36 # You could also install a specific tag/version in this way
37 # sudo -H python3 -m pip install git+https://osm.etsi.org/gerrit/osm/osmclient@v7.0.0rc1
38 ```
39
40 ### From cloned repo (for developers)
41
42 ```
43 # Ubuntu 18.04 pre-requirements
44 sudo apt-get install python3-pip libcurl4-openssl-dev libssl-dev
45 # Centos pre-requirements
46 # sudo yum install python3-pip libcurl-devel gnutls-devel
47 sudo -H python3 -m pip install python-magic
48 # Install OSM Information model
49 sudo -H python3 -m pip install git+https://osm.etsi.org/gerrit/osm/IM --upgrade
50 # Clone the osmclient repo and install OSM client from the git repo.
51 git clone https://osm.etsi.org/gerrit/osm/osmclient
52 cd osmclient
53 python3 -m pip install --user -e .
54 # logout and login so that PATH can be updated. Executable osm will be found in /home/ubuntu/.local/bin
55 ```
56
57 ## Setup
58
59 Set the OSM_HOSTNAME variable to the host of the OSM server (default: localhost).
60
61 ```bash
62 localhost$ export OSM_HOSTNAME=<hostname>
63 ```
64
65 ## Examples
66
67 ### upload vnfd
68
69 ```bash
70 localhost$ osm upload-package ubuntu_xenial_vnf.tar.gz
71 {'transaction_id': 'ec12af77-1b91-4c84-b233-60f2c2c16d14'}
72 localhost$ osm vnfd-list
73 +--------------------+--------------------+
74 | vnfd name          | id                 |
75 +--------------------+--------------------+
76 | ubuntu_xenial_vnfd | ubuntu_xenial_vnfd |
77 +--------------------+--------------------+
78 ```
79
80 ### upload nsd
81
82 ```bash
83 localhost$ osm upload-package ubuntu_xenial_ns.tar.gz
84 {'transaction_id': 'b560c9cb-43e1-49ef-a2da-af7aab24ce9d'}
85 localhost$ osm nsd-list
86 +-------------------+-------------------+
87 | nsd name          | id                |
88 +-------------------+-------------------+
89 | ubuntu_xenial_nsd | ubuntu_xenial_nsd |
90 +-------------------+-------------------+
91 ```
92
93 ### vim-list
94
95 ```bash
96 localhost$ osm vim-list
97 +-------------+-----------------+--------------------------------------+
98 | ro-account  | datacenter name | uuid                                 |
99 +-------------+-----------------+--------------------------------------+
100 | osmopenmano | openstack-site  | 2ea04690-0e4a-11e7-89bc-00163e59ff0c |
101 +-------------+-----------------+--------------------------------------+
102 ```
103
104 ### instantiate ns
105
106 ```bash
107 localhost$ osm ns-create ubuntu_xenial_nsd testns openstack-site
108 {'success': ''}
109 localhost$ osm ns-list
110 +------------------+--------------------------------------+-------------------+--------------------+---------------+
111 | ns instance name | id                                   | catalog name      | operational status | config status |
112 +------------------+--------------------------------------+-------------------+--------------------+---------------+
113 | testns           | 6b0d2906-13d4-11e7-aa01-b8ac6f7d0c77 | ubuntu_xenial_nsd | running            | configured    |
114 +------------------+--------------------------------------+-------------------+--------------------+---------------+
115 ```
116
117 ## Using osmclient as a library to interact with OSM
118
119 Assuming that you have installed python-osmclient package, it's pretty simple to write some Python code to interact with OSM.
120
121 ### Simple Python code to get the list of NS packages
122
123 ```python
124 from osmclient import client
125 from osmclient.common.exceptions import ClientException
126 hostname = "127.0.0.1"
127 myclient = client.Client(host=hostname, sol005=True)
128 resp = myclient.nsd.list()
129 print yaml.safe_dump(resp, indent=4, default_flow_style=False)
130 ```
131
132 ### Simple Python code to get the list of VNF packages from a specific user and project
133
134 The code will print for each package a pretty table, then the full details in yaml
135
136 ```python
137 from osmclient import client
138 from osmclient.common.exceptions import ClientException
139 import yaml
140 from prettytable import PrettyTable
141 hostname = "127.0.0.1"
142 user = admin
143 password = admin
144 project = admin
145 kwargs = {}
146 if user is not None:
147     kwargs['user']=user
148 if password is not None:
149     kwargs['password']=password
150 if project is not None:
151    kwargs['project']=project
152 myclient = client.Client(host=hostname, sol005=True, **kwargs)
153 resp = myclient.vnfd.list()
154 print yaml.safe_dump(resp, indent=4, default_flow_style=False)
155 ```
156
157 ## Enable autocompletion
158
159 You can enable autocompletion in OSM client by creating a file osm-complete.sh in the following way:
160
161 ```bash
162 mkdir -p $HOME/.bash_completion.d
163 _OSM_COMPLETE=source osm > $HOME/.bash_completion.d/osm-complete.sh
164 ```
165
166 Then you can add the following to your $HOME/.bashrc file:
167
168 ```bash
169 . .bash_completion.d/osm-complete.sh
170 ```
171