[7478] | 1 | #!/usr/bin/env python
|
---|
| 2 | #
|
---|
| 3 | # Copyright (c) 2010 Corey Goldberg (corey@goldb.org)
|
---|
| 4 | # License: GNU LGPLv3
|
---|
| 5 | #
|
---|
| 6 | # This file is part of Multi-Mechanize
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | """
|
---|
| 10 | Multi-Mechanize Grid Controller
|
---|
| 11 | sample gui application for controlling multi-mechanize instances via the remote management api
|
---|
| 12 | """
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | import socket
|
---|
| 16 | import ScrolledText
|
---|
| 17 | import Tkinter
|
---|
| 18 | import tkFileDialog
|
---|
| 19 | import xmlrpclib
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 |
|
---|
| 23 | # list of hosts:ports where multi-mechanize is listening
|
---|
| 24 | NODES = [
|
---|
| 25 | '192.168.1.2:9001',
|
---|
| 26 | '192.168.1.3:9001',
|
---|
| 27 | ]
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | class Application:
|
---|
| 32 | def __init__(self, root, hosts):
|
---|
| 33 | self.hosts = hosts
|
---|
| 34 | self.root = root
|
---|
| 35 | self.root.geometry('%dx%d%+d%+d' % (600, 400, 100, 100))
|
---|
| 36 | self.root.title('Multi-Mechanize Grid Controller')
|
---|
| 37 |
|
---|
| 38 | Tkinter.Button(self.root, text='List Nodes', command=self.list_nodes, width=15,).place(x=5, y=5)
|
---|
| 39 | Tkinter.Button(self.root, text='Check Tests', command=self.check_servers, width=15,).place(x=5, y=35)
|
---|
| 40 | Tkinter.Button(self.root, text='Get Project Names', command=self.get_project_names, width=15).place(x=5, y=65)
|
---|
| 41 | Tkinter.Button(self.root, text='Get Configs', command=self.get_configs, width=15).place(x=5, y=95)
|
---|
| 42 | Tkinter.Button(self.root, text='Update Configs', command=self.update_configs, width=15).place(x=5, y=125)
|
---|
| 43 | Tkinter.Button(self.root, text='Get Results', command=self.get_results, width=15).place(x=5, y=155)
|
---|
| 44 | Tkinter.Button(self.root, text='Run Tests', command=self.run_tests, width=15).place(x=5, y=185)
|
---|
| 45 |
|
---|
| 46 | self.text_box = ScrolledText.ScrolledText(self.root, width=59, height=24, font=('Helvetica', 9))
|
---|
| 47 | self.text_box.place(x=162, y=5)
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | def clear_window(self):
|
---|
| 51 | self.text_box.delete(1.0, Tkinter.END)
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | def list_nodes(self):
|
---|
| 55 | self.clear_window()
|
---|
| 56 | for host, port in self.hosts:
|
---|
| 57 | self.text_box.insert(Tkinter.END, '%s:%s\n' % (host, port))
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | def run_tests(self):
|
---|
| 61 | self.clear_window()
|
---|
| 62 | for host, port in self.hosts:
|
---|
| 63 | server = xmlrpclib.ServerProxy('http://%s:%s' % (host, port))
|
---|
| 64 | try:
|
---|
| 65 | status = server.run_test()
|
---|
| 66 | self.text_box.insert(Tkinter.END, '%s:%s:\n%s\n\n\n' % (host, port, status))
|
---|
| 67 | except socket.error:
|
---|
| 68 | self.text_box.insert(Tkinter.END, 'can not make connection to: %s:%s\n' % (host, port))
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 | def get_configs(self):
|
---|
| 72 | self.clear_window()
|
---|
| 73 | for host, port in self.hosts:
|
---|
| 74 | server = xmlrpclib.ServerProxy('http://%s:%s' % (host, port))
|
---|
| 75 | try:
|
---|
| 76 | config = server.get_config()
|
---|
| 77 | self.text_box.insert(Tkinter.END, '%s:%s config:\n%s\n\n\n' % (host, port, config))
|
---|
| 78 | except socket.error:
|
---|
| 79 | self.text_box.insert(Tkinter.END, 'can not make connection to: %s:%s\n' % (host, port))
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | def update_configs(self):
|
---|
| 83 | self.clear_window()
|
---|
| 84 | f = tkFileDialog.askopenfile(parent=self.root, initialdir='./', title='Select a Config File')
|
---|
| 85 | for host, port in self.hosts:
|
---|
| 86 | server = xmlrpclib.ServerProxy('http://%s:%s' % (host, port))
|
---|
| 87 | try:
|
---|
| 88 | status = server.update_config(f.read())
|
---|
| 89 | self.text_box.insert(Tkinter.END, '%s:%s config updated:\n%s\n\n' % (host, port, status))
|
---|
| 90 | except socket.error:
|
---|
| 91 | self.text_box.insert(Tkinter.END, 'can not make connection to: %s:%s\n' % (host, port))
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | def get_results(self):
|
---|
| 95 | self.clear_window()
|
---|
| 96 | for host, port in self.hosts:
|
---|
| 97 | server = xmlrpclib.ServerProxy('http://%s:%s' % (host, port))
|
---|
| 98 | try:
|
---|
| 99 | results = server.get_results()
|
---|
| 100 | self.text_box.insert(Tkinter.END, '%s:%s results:\n%s\n\n\n' % (host, port, results))
|
---|
| 101 | except socket.error:
|
---|
| 102 | self.text_box.insert(Tkinter.END, 'can not make connection to: %s:%s\n' % (host, port))
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 | def get_project_names(self):
|
---|
| 106 | self.clear_window()
|
---|
| 107 | for host, port in self.hosts:
|
---|
| 108 | server = xmlrpclib.ServerProxy('http://%s:%s' % (host, port))
|
---|
| 109 | try:
|
---|
| 110 | name = server.get_project_name()
|
---|
| 111 | self.text_box.insert(Tkinter.END, '%s:%s project name:\n%s\n\n' % (host, port, name))
|
---|
| 112 | except socket.error:
|
---|
| 113 | self.text_box.insert(Tkinter.END, 'can not make connection to: %s:%s\n' % (host, port))
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | def check_servers(self):
|
---|
| 117 | self.clear_window()
|
---|
| 118 | for host, port in self.hosts:
|
---|
| 119 | server = xmlrpclib.ServerProxy('http://%s:%s' % (host, port))
|
---|
| 120 | try:
|
---|
| 121 | is_running = server.check_test_running()
|
---|
| 122 | self.text_box.insert(Tkinter.END, '%s:%s test running:\n%s\n\n' % (host, port, is_running))
|
---|
| 123 | except socket.error:
|
---|
| 124 | self.text_box.insert(Tkinter.END, 'can not make connection to: %s:%s\n' % (host, port))
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 | def main():
|
---|
| 129 | hosts = [(host_port.split(':')[0], host_port.split(':')[1]) for host_port in NODES]
|
---|
| 130 | root = Tkinter.Tk()
|
---|
| 131 | app = Application(root, hosts)
|
---|
| 132 | root.mainloop()
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | if __name__ == '__main__':
|
---|
| 136 | main()
|
---|