1+ #!/usr/bin/env python3
2+ """
3+ SPDX-License-Identifier: Apache-2.0
4+ Copyright Contributors to the ODPi Egeria project.
5+
6+
7+ A command line interface for Egeria operations.
8+
9+ This is an emerging capability based on the **click** package. Feedback welcome!
10+
11+ """
12+ import click
13+ from trogon import tui
14+ # from pyegeria import ServerOps
15+ from examples .widgets .cli .ops_config import Config
16+ from examples .widgets .operational .monitor_gov_eng_status import display_gov_eng_status
17+ from examples .widgets .operational .monitor_server_status import display_status as s_display_status
18+ from examples .widgets .operational .monitor_server_list import display_status as display_list
19+ from examples .widgets .operational .monitor_integ_daemon_status import display_integration_daemon_status
20+ from examples .widgets .operational .monitor_platform_status import display_status as p_display_status
21+ from examples .widgets .operational .monitor_engine_activity import display_engine_activity
22+ from examples .widgets .operational .refresh_integration_daemon import refresh_connector
23+ from examples .widgets .operational .restart_integration_daemon import restart_connector
24+ from examples .widgets .operational .integration_daemon_actions import (add_catalog_target ,remove_catalog_target ,
25+ update_catalog_target , stop_server , start_server )
26+
27+ from examples .widgets .operational .list_catalog_targets import display_catalog_targets
28+ # class Config(object):
29+ # def __init__(self, server: str = None, url: str = None, userid:str = None, password:str = None,
30+ # timeout:int = 30, paging: bool = False):
31+ # self.server = server
32+ # self.url = url
33+ # self.userid = userid
34+ # self.password = password
35+ # self.timeout = timeout
36+ # self.paging = paging
37+ #
38+ #
39+ # pass_config = click.make_pass_decorator(Config)
40+
41+ # @tui
42+ @tui ()
43+ @click .version_option ("0.0.1" , prog_name = "egeria_ops" )
44+ @click .group ()
45+ @click .option ('--server' , default = 'active-metadata-store' , envvar = 'EGERIA_METADATA_STORE' ,
46+ help = 'Egeria metadata store to work with' )
47+ @click .option ('--url' , default = 'https://localhost:9443' , envvar = 'EGERIA_PLATFORM_URL' ,
48+ help = 'URL of Egeria metadata store platform to connect to' )
49+ @click .option ('--integration-daemon' , default = 'integration-daemon' , envvar = 'EGERIA_INTEGRATION_DAEMON' ,
50+ help = 'Egeria integration daemon to work with' )
51+ @click .option ('--integration_daemon_url' , default = 'https://localhost:9443' , envvar = 'EGERIA_INTEGRATION_DAEMON_URL' ,
52+ help = 'URL of Egeria integration daemon platform to connect to' )
53+ @click .option ('--view_server' , default = 'view-server' , envvar = 'EGERIA_VIEW_SERVER' ,
54+ help = 'Egeria view server to work with' )
55+ @click .option ('--view_server_url' , default = 'https://localhost:9443' , envvar = 'EGERIA_VIEW_SERVER_URL' ,
56+ help = 'URL of Egeria view server platform to connect to' )
57+ @click .option ('--engine_host' , default = 'engine-host' , envvar = 'EGERIA_ENGINE_HOST' ,
58+ help = 'Egeria engine host to work with' )
59+ @click .option ('--engine_host_url' , default = 'https://localhost:9443' , envvar = 'EGERIA_ENGINE_HOST_URL' ,
60+ help = 'URL of Egeria engine host platform to connect to' )
61+ @click .option ('--admin_user' , default = 'garygeeke' , envvar = 'EGERIA_ADMIN_USER' , help = 'Egeria admin user' )
62+ @click .option ('--admin_user_password' , default = 'secret' , envvar = 'EGERIA_ADMIN_PASSWORD' ,
63+ help = 'Egeria admin password' )
64+ @click .option ('--userid' , default = 'garygeeke' , envvar = 'EGERIA_USER' , help = 'Egeria user' )
65+ @click .option ('--password' , default = 'secret' , envvar = 'EGERIA_PASSWORD' ,
66+ help = 'Egeria user password' )
67+ @click .option ('--timeout' , default = 60 , help = 'Number of seconds to wait' )
68+ @click .option ('--verbose' , is_flag = True , default = False , help = 'Enable verbose mode' )
69+ @click .option ('--paging' , is_flag = True , default = False , help = 'Enable paging snapshots vs live updates' )
70+ @click .pass_context
71+ def cli (ctx , server , url , view_server , view_server_url , integration_daemon , integration_daemon_url ,
72+ engine_host , engine_host_url , admin_user , admin_user_password , userid , password , timeout , paging , verbose ):
73+ """An Egeria Command Line interface for Operations """
74+ ctx .obj = Config (server , url , view_server , view_server_url , integration_daemon ,
75+ integration_daemon_url , engine_host , engine_host_url ,
76+ admin_user , admin_user_password ,userid , password ,
77+ timeout , paging , verbose )
78+ ctx .max_content_width = 200
79+ ctx .ensure_object (Config )
80+ if verbose :
81+ click .echo (f"we are in verbose mode - server is { server } " )
82+
83+
84+ @cli .group ("show" )
85+ @click .pass_context
86+ def show (ctx ):
87+ """Display an Egeria Object"""
88+ pass
89+
90+ @show .group ('platforms' )
91+ @click .pass_context
92+ def show_platform (ctx ):
93+ """Group of commands to show information about Egeria platforms"""
94+ pass
95+
96+ @show_platform .command ('status' )
97+ @click .pass_context
98+ def show_platform_status (ctx ):
99+ """Display a live status view of known platforms"""
100+ c = ctx .obj
101+ p_display_status (c .view_server ,c .view_server_url ,
102+ c .admin_user ,c .admin_user_password )
103+
104+
105+ @show .group ("servers" )
106+ @click .pass_context
107+ def show_server (ctx ):
108+ """Group of commands to show information about Egeria servers"""
109+ pass
110+
111+ @show_server .command ('status' )
112+ @click .option ('--full' , is_flag = True , default = False , help = 'If True, full server descriptions will be shown' )
113+ @click .pass_context
114+ def show_server_status (ctx , full ):
115+ """Display a live status view of Egeria servers for the specified Egeria platform"""
116+ c = ctx .obj
117+ if full :
118+ display_list (c .metadata_store , c .metadata_store_url , c .admin_user ,c .admin_user_password )
119+ else :
120+ s_display_status (c .metadata_store , c .metadata_store_url , c .admin_user ,c .admin_user_password )
121+
122+ @show .group ("engines" )
123+ @click .pass_context
124+ def engine_host (ctx ):
125+ """Group of commands to show information about Egeria engines"""
126+ pass
127+
128+ @engine_host .command ("status" )
129+ @click .option ('--list' , is_flag = True , default = False , help = 'If True, a paged list will be shown' )
130+ @click .pass_context
131+ def gov_eng_status (ctx ,list ):
132+ """Display engine-host status information"""
133+ c = ctx .obj
134+ display_gov_eng_status (c .engine_host , c .engine_host_url ,
135+ c .userid , c .password ,
136+ list )
137+
138+ @engine_host .command ('activity' )
139+ @click .option ('--list' , is_flag = True , default = False , help = 'If True, a paged list will be shown' )
140+ @click .pass_context
141+ def eng_activity_status (ctx ,list ):
142+ """Show Governance Activity in engine-host"""
143+ c = ctx .obj
144+ display_engine_activity (c .view_server , c .view_server_url ,
145+ c .userid , c .password ,
146+ list )
147+
148+
149+ @show .group ('integrations' )
150+ @click .pass_context
151+ def integrations (ctx ):
152+ """Group of commands to show information about Egeria integrations"""
153+ pass
154+
155+ @integrations .command ("status" )
156+ @click .option ('--list' , is_flag = True , default = False , help = 'If True, a paged list will be shown' )
157+ @click .pass_context
158+ def integrations_status (ctx ,list ):
159+ """Display integration-daemon status information"""
160+ c = ctx .obj
161+ display_integration_daemon_status (c .integration_daemon , c .integration_daemon_url ,
162+ c .view_server , c .view_server_url ,
163+ c .userid , c .password , list )
164+
165+ @integrations .command ("targets" )
166+ @click .pass_context
167+ @click .argument ('connector' ,nargs = 1 )
168+ def integrations_status (ctx ,connector ):
169+ """Display Catalog Targets for a connector"""
170+ c = ctx .obj
171+ display_catalog_targets (connector , c .view_server , c .view_server_url ,
172+ c .userid , c .password )
173+
174+ #
175+ # Tell
176+ #
177+
178+ @cli .group ('tell' )
179+ @click .pass_context
180+ def tell (ctx ):
181+ """Perform actions an Egeria Objects"""
182+ pass
183+
184+ @tell .group ('integration_daemon' )
185+ @click .pass_context
186+ def integration_daemon (ctx ):
187+ """Group of commands to an integration-daemon"""
188+ pass
189+
190+ @integration_daemon .command ('refresh' )
191+ @click .pass_context
192+ @click .option ('--connector' , default = 'all' , help = "Name of connector to refresh or 'all' to refresh all" )
193+ def refresh_connectors (ctx ,connector ):
194+ """Refresh the specified integration connector or ALL connectors if not specified"""
195+ c = ctx .obj
196+ refresh_connector (connector ,c .integration_daemon , c .integration_daemon_url ,
197+ c .userid , c .password )
198+
199+ @integration_daemon .command ('restart' )
200+ @click .pass_context
201+ @click .option ('--connector' , default = 'all' , help = "Name of connector to restart or 'all' to restart all" )
202+ def restart_connectors (ctx ,connector ):
203+ """Restart the specified integration connector or ALL connectors if not specified"""
204+ c = ctx .obj
205+ restart_connector (connector ,c .integration_daemon , c .integration_daemon_url ,
206+ c .userid , c .password )
207+
208+
209+ integration_daemon .add_command (add_catalog_target )
210+ integration_daemon .add_command (remove_catalog_target )
211+ integration_daemon .add_command (update_catalog_target )
212+ integration_daemon .add_command (stop_server )
213+ integration_daemon .add_command (start_server )
214+
215+
216+ if __name__ == '__main__' :
217+ cli ()
0 commit comments