1 # ============LICENSE_START=======================================================
3 # ================================================================================
4 # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=========================================================
19 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 Queries onboarding catalog
26 from dcae_cli.commands import util
34 @catalog.command(name="list")
35 @click.option("--expanded", is_flag=True, default=False, help="Display the expanded view - show all versions and all status")
36 #TODO: @click.argument('query')
38 def action_list(obj, expanded):
39 # Query both components and data formats. Display both sets.
41 user, catalog = obj['config']['user'], obj['catalog']
43 only_latest = not expanded
44 only_published = not expanded
46 # TODO: Probably want to implement pagination
47 comps = catalog.list_components(latest=only_latest, only_published=only_published)
48 dfs = catalog.list_formats(latest=only_latest, only_published=only_published)
50 def format_record_component(obj):
51 when_published = obj["when_published"].date() \
52 if obj["when_published"] else ""
54 return (obj["name"], obj["version"], obj["component_type"],
55 util.format_description(obj["description"]), obj["owner"],
56 util.get_status_string(obj), when_published)
58 comps = [ format_record_component(comp) for comp in comps ]
61 click.echo("Components:")
62 click.echo(util.create_table(('Name', 'Version', 'Type', 'Description', 'Owner', 'Status',
65 def format_record_format(obj):
66 when_published = obj["when_published"].date() \
67 if obj["when_published"] else ""
69 return (obj["name"], obj["version"],
70 util.format_description(obj["description"]), obj["owner"],
71 util.get_status_string(obj), when_published)
73 dfs = [ format_record_format(df) for df in dfs ]
76 click.echo("Data formats:")
77 click.echo(util.create_table(('Name', 'Version', 'Description', 'Owner', 'Status',
81 @catalog.command(name="show")
82 @click.argument("resource", metavar="name:version")
84 def action_show(obj, resource):
85 # Query both components and data formats. Display both sets.
86 name, ver = util.parse_input(resource)
87 catalog = obj['catalog']
91 spec = catalog.get_component_spec(name, ver)
94 click.echo("Component specification")
95 click.echo("-----------------------")
96 click.echo(util.format_json(spec))
102 spec = obj['catalog'].get_format_spec(name, ver)
105 click.echo("Data format")
106 click.echo("-----------")
107 click.echo(util.format_json(spec))
113 click.echo("No matching component nor data format found")