merged latest from develop
This commit is contained in:
commit
dafd5dff9f
6 changed files with 42 additions and 14 deletions
|
@ -141,7 +141,7 @@ class CoreGrpcClient:
|
|||
Provides convenience methods for interfacing with the CORE grpc server.
|
||||
"""
|
||||
|
||||
def __init__(self, address: str = "localhost:50051") -> None:
|
||||
def __init__(self, address: str = "localhost:50051", proxy: bool = False) -> None:
|
||||
"""
|
||||
Creates a CoreGrpcClient instance.
|
||||
|
||||
|
@ -150,6 +150,7 @@ class CoreGrpcClient:
|
|||
self.address = address
|
||||
self.stub = None
|
||||
self.channel = None
|
||||
self.proxy = proxy
|
||||
|
||||
def start_session(
|
||||
self,
|
||||
|
@ -1130,7 +1131,9 @@ class CoreGrpcClient:
|
|||
|
||||
:return: nothing
|
||||
"""
|
||||
self.channel = grpc.insecure_channel(self.address)
|
||||
self.channel = grpc.insecure_channel(
|
||||
self.address, options=[("grpc.enable_http_proxy", self.proxy)]
|
||||
)
|
||||
self.stub = core_pb2_grpc.CoreApiStub(self.channel)
|
||||
|
||||
def close(self) -> None:
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
@ -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,
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -8,7 +8,7 @@ function install_python_depencencies() {
|
|||
}
|
||||
|
||||
function install_python_dev_dependencies() {
|
||||
sudp pip install pipenv grpcio-tools
|
||||
sudo python3 -m pip install pipenv grpcio-tools
|
||||
}
|
||||
|
||||
function install_ospf_mdr() {
|
||||
|
|
Loading…
Reference in a new issue