1 # Copyright ETSI Contributors and Others.
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
17 from osmclient
.common
.exceptions
import NotFound
18 from osmclient
.cli_commands
import utils
19 from prettytable
import PrettyTable
24 logger
= logging
.getLogger("osmclient")
27 @click.command(name
="repo-add", short_help
="adds a repo to OSM")
28 @click.argument("name")
29 @click.argument("uri")
32 type=click
.Choice(["helm-chart", "juju-bundle", "osm"]),
34 help="type of repo (helm-chart for Helm Charts, juju-bundle for Juju Bundles, osm for OSM Repositories)",
36 @click.option("--description", default
=None, help="human readable description")
38 "--user", default
=None, help="OSM repository: The username of the OSM repository"
43 help="OSM repository: The password of the OSM repository",
46 def repo_add(ctx
, **kwargs
):
49 NAME: name of the repo
52 kwargs
= {k
: v
for k
, v
in kwargs
.items() if v
is not None}
54 repo
["url"] = repo
.pop("uri")
55 if repo
["type"] in ["helm-chart", "juju-bundle"]:
56 ctx
.obj
.repo
.create(repo
["name"], repo
)
58 ctx
.obj
.osmrepo
.create(repo
["name"], repo
)
61 @click.command(name
="repo-update", short_help
="updates a repo in OSM")
62 @click.argument("name")
63 @click.option("--newname", help="New name for the repo")
64 @click.option("--uri", help="URI of the repo")
65 @click.option("--description", help="human readable description")
67 def repo_update(ctx
, name
, newname
, uri
, description
):
68 """updates a repo in OSM
70 NAME: name of the repo
72 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
75 repo
["name"] = newname
79 repo
["description"] = description
81 ctx
.obj
.repo
.update(name
, repo
)
83 ctx
.obj
.osmrepo
.update(name
, repo
)
87 name
="repo-index", short_help
="Index a repository from a folder with artifacts"
90 "--origin", default
=".", help="origin path where the artifacts are located"
93 "--destination", default
=".", help="destination path where the index is deployed"
96 def repo_index(ctx
, origin
, destination
):
99 NAME: name or ID of the repo to be deleted
101 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
102 ctx
.obj
.osmrepo
.repo_index(origin
, destination
)
105 @click.command(name
="repo-delete", short_help
="deletes a repo")
106 @click.argument("name")
108 "--force", is_flag
=True, help="forces the deletion from the DB (not recommended)"
111 def repo_delete(ctx
, name
, force
):
114 NAME: name or ID of the repo to be deleted
118 ctx
.obj
.repo
.delete(name
, force
=force
)
120 ctx
.obj
.osmrepo
.delete(name
, force
=force
)
123 @click.command(name
="repo-list")
128 help="restricts the list to the repos matching the filter",
130 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
132 def repo_list(ctx
, filter, literal
):
135 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
137 filter = "&".join(filter)
138 resp
= ctx
.obj
.repo
.list(filter)
139 resp
+= ctx
.obj
.osmrepo
.list(filter)
141 print(yaml
.safe_dump(resp
, indent
=4, default_flow_style
=False))
143 table
= PrettyTable(["Name", "Id", "Type", "URI", "Description"])
145 # cluster['k8s-nets'] = json.dumps(yaml.safe_load(cluster['k8s-nets']))
152 utils
.trunc_text(repo
.get("description") or "", 40),
159 @click.command(name
="repo-show", short_help
="shows the details of a repo")
160 @click.argument("name")
161 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
163 def repo_show(ctx
, name
, literal
):
164 """shows the details of a repo
166 NAME: name or ID of the repo
169 resp
= ctx
.obj
.repo
.get(name
)
171 resp
= ctx
.obj
.osmrepo
.get(name
)
175 print(yaml
.safe_dump(resp
, indent
=4, default_flow_style
=False))
177 table
= PrettyTable(["key", "attribute"])
179 for k
, v
in list(resp
.items()):
180 table
.add_row([k
, json
.dumps(v
, indent
=2)])
186 ########################
188 ########################
191 def pkg_repo_list(ctx
, pkgtype
, filter, repo
, long):
192 resp
= ctx
.obj
.osmrepo
.pkg_list(pkgtype
, filter, repo
)
195 ["nfpkg name", "vendor", "version", "latest", "description", "repository"]
198 table
= PrettyTable(["nfpkg name", "repository"])
200 name
= vnfd
.get("id", vnfd
.get("name", "-"))
201 repository
= vnfd
.get("repository")
203 vendor
= vnfd
.get("provider", vnfd
.get("vendor"))
204 version
= vnfd
.get("version")
205 description
= vnfd
.get("description")
206 latest
= vnfd
.get("latest")
207 table
.add_row([name
, vendor
, version
, latest
, description
, repository
])
209 table
.add_row([name
, repository
])
214 def pkg_repo_show(ctx
, pkgtype
, name
, repo
, version
, filter, literal
):
217 filter = "&".join(filter)
218 resp
= ctx
.obj
.osmrepo
.pkg_get(pkgtype
, name
, repo
, version
, filter)
221 print(yaml
.safe_dump(resp
, indent
=4, default_flow_style
=False))
224 catalog
= pkgtype
+ "-catalog"
225 full_catalog
= pkgtype
+ ":" + catalog
226 if resp
.get(catalog
):
227 resp
= resp
.pop(catalog
)[pkgtype
][0]
228 elif resp
.get(full_catalog
):
229 resp
= resp
.pop(full_catalog
)[pkgtype
][0]
231 table
= PrettyTable(["field", "value"])
232 for k
, v
in list(resp
.items()):
233 table
.add_row([k
, utils
.wrap_text(text
=json
.dumps(v
, indent
=2), width
=100)])
238 @click.command(name
="vnfpkg-repo-list", short_help
="list all xNF from OSM repositories")
243 help="restricts the list to the NFpkg matching the filter",
246 "--repo", default
=None, help="restricts the list to a particular OSM repository"
248 @click.option("--long", is_flag
=True, help="get more details")
250 def nfpkg_repo_list1(ctx
, filter, repo
, long):
251 """list xNF packages from OSM repositories"""
253 pkg_repo_list(ctx
, pkgtype
, filter, repo
, long)
256 @click.command(name
="nfpkg-repo-list", short_help
="list all xNF from OSM repositories")
261 help="restricts the list to the NFpkg matching the filter",
264 "--repo", default
=None, help="restricts the list to a particular OSM repository"
266 @click.option("--long", is_flag
=True, help="get more details")
268 def nfpkg_repo_list2(ctx
, filter, repo
, long):
269 """list xNF packages from OSM repositories"""
271 pkg_repo_list(ctx
, pkgtype
, filter, repo
, long)
274 @click.command(name
="nsd-repo-list", short_help
="list all NS from OSM repositories")
279 help="restricts the list to the NS matching the filter",
282 "--repo", default
=None, help="restricts the list to a particular OSM repository"
284 @click.option("--long", is_flag
=True, help="get more details")
286 def nspkg_repo_list(ctx
, filter, repo
, long):
287 """list xNF packages from OSM repositories"""
289 pkg_repo_list(ctx
, pkgtype
, filter, repo
, long)
292 @click.command(name
="nspkg-repo-list", short_help
="list all NS from OSM repositories")
297 help="restricts the list to the NS matching the filter",
300 "--repo", default
=None, help="restricts the list to a particular OSM repository"
302 @click.option("--long", is_flag
=True, help="get more details")
304 def nspkg_repo_list2(ctx
, filter, repo
, long):
305 """list xNF packages from OSM repositories"""
307 pkg_repo_list(ctx
, pkgtype
, filter, repo
, long)
311 name
="vnfpkg-repo-show",
312 short_help
="shows the details of a NF package in an OSM repository",
314 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
315 @click.option("--repo", required
=True, help="Repository name")
316 @click.argument("name")
317 @click.option("--filter", default
=None, multiple
=True, help="filter by fields")
318 @click.option("--version", default
="latest", help="package version")
320 def vnfd_show1(ctx
, name
, repo
, version
, literal
=None, filter=None):
321 """shows the content of a VNFD in a repository
323 NAME: name or ID of the VNFD/VNFpkg
326 pkg_repo_show(ctx
, pkgtype
, name
, repo
, version
, filter, literal
)
330 name
="nsd-repo-show",
331 short_help
="shows the details of a NS package in an OSM repository",
333 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
334 @click.option("--repo", required
=True, help="Repository name")
335 @click.argument("name")
336 @click.option("--filter", default
=None, multiple
=True, help="filter by fields")
337 @click.option("--version", default
="latest", help="package version")
339 def nsd_repo_show(ctx
, name
, repo
, version
, literal
=None, filter=None):
340 """shows the content of a VNFD in a repository
342 NAME: name or ID of the VNFD/VNFpkg
345 pkg_repo_show(ctx
, pkgtype
, name
, repo
, version
, filter, literal
)
349 name
="nspkg-repo-show",
350 short_help
="shows the details of a NS package in an OSM repository",
352 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
353 @click.option("--repo", required
=True, help="Repository name")
354 @click.argument("name")
355 @click.option("--filter", default
=None, multiple
=True, help="filter by fields")
356 @click.option("--version", default
="latest", help="package version")
358 def nsd_repo_show2(ctx
, name
, repo
, version
, literal
=None, filter=None):
359 """shows the content of a VNFD in a repository
361 NAME: name or ID of the VNFD/VNFpkg
364 pkg_repo_show(ctx
, pkgtype
, name
, repo
, version
, filter, literal
)
368 name
="nfpkg-repo-show",
369 short_help
="shows the details of a NF package in an OSM repository",
371 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
372 @click.option("--repo", required
=True, help="Repository name")
373 @click.argument("name")
374 @click.option("--filter", default
=None, multiple
=True, help="filter by fields")
375 @click.option("--version", default
="latest", help="package version")
377 def vnfd_show2(ctx
, name
, repo
, version
, literal
=None, filter=None):
378 """shows the content of a VNFD in a repository
380 NAME: name or ID of the VNFD/VNFpkg
383 pkg_repo_show(ctx
, pkgtype
, name
, repo
, version
, filter, literal
)