From 2a7a22c2eeb5bab2ba9694d056ff0f545e3cbc1e Mon Sep 17 00:00:00 2001 From: Huy Pham <42948410+hpham@users.noreply.github.com> Date: Thu, 9 Jan 2020 13:10:45 -0800 Subject: [PATCH 1/6] change logging.warn to logging.warning --- daemon/core/gui/coreclient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon/core/gui/coreclient.py b/daemon/core/gui/coreclient.py index 4032d975..220719cb 100644 --- a/daemon/core/gui/coreclient.py +++ b/daemon/core/gui/coreclient.py @@ -134,7 +134,7 @@ class CoreClient: def handle_events(self, event): if event.session_id != self.session_id: - logging.warn( + logging.warning( "ignoring event session(%s) current(%s)", event.session_id, self.session_id, From 853d2828fe6d6f723e8b18b05982cb604b1bc956 Mon Sep 17 00:00:00 2001 From: Huy Pham <42948410+hpham@users.noreply.github.com> Date: Thu, 9 Jan 2020 15:31:35 -0800 Subject: [PATCH 2/6] add temp service file path --- daemon/core/gui/dialogs/copyserviceconfig.py | 24 ++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/daemon/core/gui/dialogs/copyserviceconfig.py b/daemon/core/gui/dialogs/copyserviceconfig.py index 68b04d03..39306db7 100644 --- a/daemon/core/gui/dialogs/copyserviceconfig.py +++ b/daemon/core/gui/dialogs/copyserviceconfig.py @@ -133,18 +133,28 @@ class CopyServiceConfigDialog(Dialog): if "file" in item["tags"]: nid, service = self.get_node_service(selected) data = self.file_configs[nid][service][item["text"]] - dialog = ViewConfigDialog(self, self.app, self.node_id, data) + dialog = ViewConfigDialog( + self, self.app, nid, data, item["text"].split("/")[-1] + ) dialog.show() if "cmd" in item["tags"]: nid, service = self.get_node_service(selected) cmds = self.service_configs[nid][service] if "up" in item["tags"]: data = f"({str(cmds.startup[:])[1:-1]})" + dialog = ViewConfigDialog( + self, self.app, self.node_id, data, "cmdup" + ) elif "down" in item["tags"]: data = f"({str(cmds.shutdown[:])[1:-1]})" + dialog = ViewConfigDialog( + self, self.app, self.node_id, data, "cmdup" + ) elif "val" in item["tags"]: data = f"({str(cmds.validate[:])[1:-1]})" - dialog = ViewConfigDialog(self, self.app, self.node_id, data) + dialog = ViewConfigDialog( + self, self.app, self.node_id, data, "cmdup" + ) dialog.show() def get_node_service(self, selected): @@ -156,18 +166,24 @@ class CopyServiceConfigDialog(Dialog): class ViewConfigDialog(Dialog): - def __init__(self, master, app, node_id, data): + def __init__(self, master, app, node_id, data, filename=None): super().__init__(master, app, f"n{node_id} config data", modal=True) self.data = data self.service_data = None + self.filepath = tk.StringVar(value=f"/tmp/services.tmp-n{node_id}-{filename}") self.draw() def draw(self): self.top.columnconfigure(0, weight=1) frame = ttk.Frame(self.top, padding=FRAME_PAD) - frame.grid(row=0, column=0) + frame.columnconfigure(0, weight=1) + frame.columnconfigure(1, weight=10) + frame.grid(row=0, column=0, sticky="ew") label = ttk.Label(frame, text="File: ") label.grid(row=0, column=0, sticky="ew", padx=PADX) + entry = ttk.Entry(frame, textvariable=self.filepath) + entry.config(state="disabled") + entry.grid(row=0, column=1, sticky="ew") self.service_data = CodeText(self.top) self.service_data.grid(row=1, column=0, sticky="nsew") From 583a552bdbcc36fd7751d93f940d39f1fd3b7106 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Fri, 10 Jan 2020 20:25:34 -0800 Subject: [PATCH 3/6] disable grpc client from using proxy settings --- daemon/core/api/grpc/client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/daemon/core/api/grpc/client.py b/daemon/core/api/grpc/client.py index a51f3724..61fa14cb 100644 --- a/daemon/core/api/grpc/client.py +++ b/daemon/core/api/grpc/client.py @@ -1035,7 +1035,9 @@ class CoreGrpcClient: :return: nothing """ - self.channel = grpc.insecure_channel(self.address) + self.channel = grpc.insecure_channel( + self.address, options=[("grpc.enable_http_proxy", 0)] + ) self.stub = core_pb2_grpc.CoreApiStub(self.channel) def close(self): From 35d5d5271b577aa4e21f9e03103dd91c11b32b1c Mon Sep 17 00:00:00 2001 From: Gabriel Somlo Date: Tue, 14 Jan 2020 13:26:24 -0500 Subject: [PATCH 4/6] Fix typo in installer --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index cb07ea85..41483405 100755 --- a/install.sh +++ b/install.sh @@ -8,7 +8,7 @@ function install_python_depencencies() { } function install_python_dev_dependencies() { - sudp pip install pipenv grpcio-tools + sudo pip install pipenv grpcio-tools } function install_ospf_mdr() { From d0180af0437c817be2aa01d92868bbdc3b53e909 Mon Sep 17 00:00:00 2001 From: Gabriel Somlo Date: Tue, 14 Jan 2020 16:26:44 -0500 Subject: [PATCH 5/6] update dependency installer to python3 --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 41483405..629079bc 100755 --- a/install.sh +++ b/install.sh @@ -8,7 +8,7 @@ function install_python_depencencies() { } function install_python_dev_dependencies() { - sudo pip install pipenv grpcio-tools + sudo python3 -m pip install pipenv grpcio-tools } function install_ospf_mdr() { From d4bce0d25ca801f84b3eef0b9e3530dc05f51b43 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Tue, 14 Jan 2020 22:15:00 -0800 Subject: [PATCH 6/6] updated grpc client to have a proxy flag, updated coretk script to have a flag to enable proxy, disabled by default --- daemon/core/api/grpc/client.py | 5 +++-- daemon/core/gui/app.py | 6 +++--- daemon/core/gui/coreclient.py | 4 ++-- daemon/scripts/coretk-gui | 11 ++++++++++- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/daemon/core/api/grpc/client.py b/daemon/core/api/grpc/client.py index 61fa14cb..6098db25 100644 --- a/daemon/core/api/grpc/client.py +++ b/daemon/core/api/grpc/client.py @@ -137,7 +137,7 @@ class CoreGrpcClient: Provides convenience methods for interfacing with the CORE grpc server. """ - def __init__(self, address="localhost:50051"): + def __init__(self, address="localhost:50051", proxy=False): """ Creates a CoreGrpcClient instance. @@ -146,6 +146,7 @@ class CoreGrpcClient: self.address = address self.stub = None self.channel = None + self.proxy = proxy def start_session( self, @@ -1036,7 +1037,7 @@ class CoreGrpcClient: :return: nothing """ self.channel = grpc.insecure_channel( - self.address, options=[("grpc.enable_http_proxy", 0)] + self.address, options=[("grpc.enable_http_proxy", self.proxy)] ) self.stub = core_pb2_grpc.CoreApiStub(self.channel) diff --git a/daemon/core/gui/app.py b/daemon/core/gui/app.py index dba22068..2596a411 100644 --- a/daemon/core/gui/app.py +++ b/daemon/core/gui/app.py @@ -17,8 +17,8 @@ HEIGHT = 800 class Application(tk.Frame): - def __init__(self, master=None): - super().__init__(master) + def __init__(self, proxy): + super().__init__(master=None) # load node icons NodeUtils.setup() @@ -33,7 +33,7 @@ class Application(tk.Frame): self.guiconfig = appconfig.read() self.style = ttk.Style() self.setup_theme() - self.core = CoreClient(self) + self.core = CoreClient(self, proxy) self.setup_app() self.draw() self.core.set_up() diff --git a/daemon/core/gui/coreclient.py b/daemon/core/gui/coreclient.py index 4032d975..534e97a1 100644 --- a/daemon/core/gui/coreclient.py +++ b/daemon/core/gui/coreclient.py @@ -47,11 +47,11 @@ class Observer: class CoreClient: - def __init__(self, app): + def __init__(self, app, proxy): """ Create a CoreGrpc instance """ - self.client = client.CoreGrpcClient() + self.client = client.CoreGrpcClient(proxy=proxy) self.session_id = None self.node_ids = [] self.app = app diff --git a/daemon/scripts/coretk-gui b/daemon/scripts/coretk-gui index 1ddb7526..4fc60d51 100755 --- a/daemon/scripts/coretk-gui +++ b/daemon/scripts/coretk-gui @@ -1,4 +1,5 @@ #!/usr/bin/env python +import argparse import logging from core.gui import appconfig @@ -6,10 +7,18 @@ from core.gui.app import Application from core.gui.images import Images if __name__ == "__main__": + # parse flags + parser = argparse.ArgumentParser(description=f"CORE Python Tk GUI") + parser.add_argument("-p", "--proxy", action="store_true", help="enable proxy") + args = parser.parse_args() + + # setup logging log_format = "%(asctime)s - %(levelname)s - %(module)s:%(funcName)s - %(message)s" logging.basicConfig(level=logging.DEBUG, format=log_format) logging.getLogger("PIL").setLevel(logging.ERROR) + + # start app Images.load_all() appconfig.check_directory() - app = Application() + app = Application(args.proxy) app.mainloop()