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(["osm", "helm-chart", "juju-bundle"]),
34 help="type of repo (osm for OSM repositories, helm-chart for Helm Charts, juju-bundle for Juju Bundles)",
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",
48 help="enable OCI (only for helm-chart repos, default: false, automatically set to true for oci:// URI)",
51 def repo_add(ctx
, **kwargs
):
54 NAME: name of the repo
57 kwargs
= {k
: v
for k
, v
in kwargs
.items() if v
is not None}
59 repo
["url"] = repo
.pop("uri")
60 if repo
["url"].startswith("oci://"):
62 if repo
["type"] in ["helm-chart", "juju-bundle"]:
63 ctx
.obj
.repo
.create(repo
["name"], repo
)
65 ctx
.obj
.osmrepo
.create(repo
["name"], repo
)
68 @click.command(name
="repo-update", short_help
="updates a repo in OSM")
69 @click.argument("name")
70 @click.option("--newname", help="New name for the repo")
71 @click.option("--uri", help="URI of the repo")
72 @click.option("--description", help="human readable description")
76 help="enable OCI (only for helm-chart repos, default: false, automatically set to true for oci:// URI)",
79 def repo_update(ctx
, name
, newname
, uri
, description
, oci
):
80 """updates a repo in OSM
82 NAME: name of the repo
84 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
87 repo
["name"] = newname
90 if uri
.startswith("oci://"):
93 repo
["description"] = description
97 ctx
.obj
.repo
.update(name
, repo
)
99 ctx
.obj
.osmrepo
.update(name
, repo
)
103 name
="repo-index", short_help
="Index a repository from a folder with artifacts"
106 "--origin", default
=".", help="origin path where the artifacts are located"
109 "--destination", default
=".", help="destination path where the index is deployed"
112 def repo_index(ctx
, origin
, destination
):
113 """Index a repository
115 NAME: name or ID of the repo to be deleted
117 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
118 ctx
.obj
.osmrepo
.repo_index(origin
, destination
)
121 @click.command(name
="repo-delete", short_help
="deletes a repo")
122 @click.argument("name")
124 "--force", is_flag
=True, help="forces the deletion from the DB (not recommended)"
127 def repo_delete(ctx
, name
, force
):
130 NAME: name or ID of the repo to be deleted
134 ctx
.obj
.repo
.delete(name
, force
=force
)
136 ctx
.obj
.osmrepo
.delete(name
, force
=force
)
139 @click.command(name
="repo-list")
144 help="restricts the list to the repos matching the filter",
146 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
148 def repo_list(ctx
, filter, literal
):
151 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
153 filter = "&".join(filter)
154 resp
= ctx
.obj
.repo
.list(filter)
155 resp
+= ctx
.obj
.osmrepo
.list(filter)
157 print(yaml
.safe_dump(resp
, indent
=4, default_flow_style
=False))
159 table
= PrettyTable(["Name", "Id", "Type", "URI", "Description"])
161 # cluster['k8s-nets'] = json.dumps(yaml.safe_load(cluster['k8s-nets']))
168 utils
.trunc_text(repo
.get("description") or "", 40),
175 @click.command(name
="repo-show", short_help
="shows the details of a repo")
176 @click.argument("name")
177 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
179 def repo_show(ctx
, name
, literal
):
180 """shows the details of a repo
182 NAME: name or ID of the repo
185 resp
= ctx
.obj
.repo
.get(name
)
187 resp
= ctx
.obj
.osmrepo
.get(name
)
191 print(yaml
.safe_dump(resp
, indent
=4, default_flow_style
=False))
193 table
= PrettyTable(["key", "attribute"])
195 for k
, v
in list(resp
.items()):
196 table
.add_row([k
, json
.dumps(v
, indent
=2)])
202 ########################
204 ########################
207 def pkg_repo_list(ctx
, pkgtype
, filter, repo
, long):
208 resp
= ctx
.obj
.osmrepo
.pkg_list(pkgtype
, filter, repo
)
211 ["nfpkg name", "vendor", "version", "latest", "description", "repository"]
214 table
= PrettyTable(["nfpkg name", "repository"])
216 name
= vnfd
.get("id", vnfd
.get("name", "-"))
217 repository
= vnfd
.get("repository")
219 vendor
= vnfd
.get("provider", vnfd
.get("vendor"))
220 version
= vnfd
.get("version")
221 description
= vnfd
.get("description")
222 latest
= vnfd
.get("latest")
223 table
.add_row([name
, vendor
, version
, latest
, description
, repository
])
225 table
.add_row([name
, repository
])
230 def pkg_repo_show(ctx
, pkgtype
, name
, repo
, version
, filter, literal
):
233 filter = "&".join(filter)
234 resp
= ctx
.obj
.osmrepo
.pkg_get(pkgtype
, name
, repo
, version
, filter)
237 print(yaml
.safe_dump(resp
, indent
=4, default_flow_style
=False))
240 catalog
= pkgtype
+ "-catalog"
241 full_catalog
= pkgtype
+ ":" + catalog
242 if resp
.get(catalog
):
243 resp
= resp
.pop(catalog
)[pkgtype
][0]
244 elif resp
.get(full_catalog
):
245 resp
= resp
.pop(full_catalog
)[pkgtype
][0]
247 table
= PrettyTable(["field", "value"])
248 for k
, v
in list(resp
.items()):
249 table
.add_row([k
, utils
.wrap_text(text
=json
.dumps(v
, indent
=2), width
=100)])
254 @click.command(name
="vnfpkg-repo-list", short_help
="list all xNF from OSM repositories")
259 help="restricts the list to the NFpkg matching the filter",
262 "--repo", default
=None, help="restricts the list to a particular OSM repository"
264 @click.option("--long", is_flag
=True, help="get more details")
266 def nfpkg_repo_list1(ctx
, filter, repo
, long):
267 """list xNF packages from OSM repositories"""
269 pkg_repo_list(ctx
, pkgtype
, filter, repo
, long)
272 @click.command(name
="nfpkg-repo-list", short_help
="list all xNF from OSM repositories")
277 help="restricts the list to the NFpkg matching the filter",
280 "--repo", default
=None, help="restricts the list to a particular OSM repository"
282 @click.option("--long", is_flag
=True, help="get more details")
284 def nfpkg_repo_list2(ctx
, filter, repo
, long):
285 """list xNF packages from OSM repositories"""
287 pkg_repo_list(ctx
, pkgtype
, filter, repo
, long)
290 @click.command(name
="nsd-repo-list", short_help
="list all NS from OSM repositories")
295 help="restricts the list to the NS matching the filter",
298 "--repo", default
=None, help="restricts the list to a particular OSM repository"
300 @click.option("--long", is_flag
=True, help="get more details")
302 def nspkg_repo_list(ctx
, filter, repo
, long):
303 """list xNF packages from OSM repositories"""
305 pkg_repo_list(ctx
, pkgtype
, filter, repo
, long)
308 @click.command(name
="nspkg-repo-list", short_help
="list all NS from OSM repositories")
313 help="restricts the list to the NS matching the filter",
316 "--repo", default
=None, help="restricts the list to a particular OSM repository"
318 @click.option("--long", is_flag
=True, help="get more details")
320 def nspkg_repo_list2(ctx
, filter, repo
, long):
321 """list xNF packages from OSM repositories"""
323 pkg_repo_list(ctx
, pkgtype
, filter, repo
, long)
327 name
="vnfpkg-repo-show",
328 short_help
="shows the details of a NF package in an OSM repository",
330 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
331 @click.option("--repo", required
=True, help="Repository name")
332 @click.argument("name")
333 @click.option("--filter", default
=None, multiple
=True, help="filter by fields")
334 @click.option("--version", default
="latest", help="package version")
336 def vnfd_show1(ctx
, name
, repo
, version
, literal
=None, filter=None):
337 """shows the content of a VNFD in a repository
339 NAME: name or ID of the VNFD/VNFpkg
342 pkg_repo_show(ctx
, pkgtype
, name
, repo
, version
, filter, literal
)
346 name
="nsd-repo-show",
347 short_help
="shows the details of a NS package in an OSM repository",
349 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
350 @click.option("--repo", required
=True, help="Repository name")
351 @click.argument("name")
352 @click.option("--filter", default
=None, multiple
=True, help="filter by fields")
353 @click.option("--version", default
="latest", help="package version")
355 def nsd_repo_show(ctx
, name
, repo
, version
, literal
=None, filter=None):
356 """shows the content of a VNFD in a repository
358 NAME: name or ID of the VNFD/VNFpkg
361 pkg_repo_show(ctx
, pkgtype
, name
, repo
, version
, filter, literal
)
365 name
="nspkg-repo-show",
366 short_help
="shows the details of a NS package in an OSM repository",
368 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
369 @click.option("--repo", required
=True, help="Repository name")
370 @click.argument("name")
371 @click.option("--filter", default
=None, multiple
=True, help="filter by fields")
372 @click.option("--version", default
="latest", help="package version")
374 def nsd_repo_show2(ctx
, name
, repo
, version
, literal
=None, filter=None):
375 """shows the content of a VNFD in a repository
377 NAME: name or ID of the VNFD/VNFpkg
380 pkg_repo_show(ctx
, pkgtype
, name
, repo
, version
, filter, literal
)
384 name
="nfpkg-repo-show",
385 short_help
="shows the details of a NF package in an OSM repository",
387 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
388 @click.option("--repo", required
=True, help="Repository name")
389 @click.argument("name")
390 @click.option("--filter", default
=None, multiple
=True, help="filter by fields")
391 @click.option("--version", default
="latest", help="package version")
393 def vnfd_show2(ctx
, name
, repo
, version
, literal
=None, filter=None):
394 """shows the content of a VNFD in a repository
396 NAME: name or ID of the VNFD/VNFpkg
399 pkg_repo_show(ctx
, pkgtype
, name
, repo
, version
, filter, literal
)