[Ocfs2-tools-commits] manish commits r725 -
trunk/ocfs2console/ocfs2interface
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Mon Mar 21 17:29:53 CST 2005
Author: manish
Date: 2005-03-21 17:29:51 -0600 (Mon, 21 Mar 2005)
New Revision: 725
Modified:
trunk/ocfs2console/ocfs2interface/clconfig.py
Log:
Basic cluster configurator
Modified: trunk/ocfs2console/ocfs2interface/clconfig.py
===================================================================
--- trunk/ocfs2console/ocfs2interface/clconfig.py 2005-03-21 23:29:39 UTC (rev 724)
+++ trunk/ocfs2console/ocfs2interface/clconfig.py 2005-03-21 23:29:51 UTC (rev 725)
@@ -17,66 +17,200 @@
import gtk
+from cStringIO import StringIO
+
from guiutil import set_props, error_box
-COLUMN_NAME, COLUMN_NODE_NUM, COLUMN_IP_ADDR, COLUMN_IP_PORT = range(4)
+from process import Process
-def cluster_store():
- store = gtk.ListStore(str, int, str, int)
+COLUMN_NAME, COLUMN_NODE, COLUMN_IP_ADDR, COLUMN_IP_PORT = range(4)
- store.set_sort_column_id(COLUMN_NODE_NUM, gtk.SORT_ASCENDING)
+fields = (
+ (COLUMN_NAME, 'Name', gtk.Entry),
+ (COLUMN_NODE, 'Node', None),
+ (COLUMN_IP_ADDR, 'IP Address', gtk.Entry),
+ (COLUMN_IP_PORT, 'IP Port', gtk.SpinButton)
+)
-def cluster_configurator(parent):
- dialog = gtk.Dialog(parent=parent, title='Cluster Configurator',
- buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
- gtk.STOCK_OK, gtk.RESPONSE_OK))
+class ConfError(Exception):
+ pass
- hbox = gtk.HBox(spacing=4)
- hbox.set_border_width(4)
- dialog.vbox.add(hbox)
+class ClusterConf(gtk.HBox):
+ def __init__(self, toplevel=None):
+ self.toplevel = toplevel
- store = cluster_store()
+ self.get_cluster_state()
- tv = gtk.TreeView()
+ gtk.HBox.__init__(self, spacing=4)
+ self.set_border_width(4)
- tv.insert_column_with_attributes(-1, 'Node Name',
- gtk.CellRendererText(),
- text=COLUMN_NAME)
- tv.insert_column_with_attributes(-1, 'Node Number',
- gtk.CellRendererText(),
- text=COLUMN_NODE_NUM)
- tv.insert_column_with_attributes(-1, 'IP Address',
- gtk.CellRendererText(),
- text=COLUMN_IP_ADDR)
- tv.insert_column_with_attributes(-1, 'IP Port',
- gtk.CellRendererText(),
- text=COLUMN_IP_PORT)
+ self.tv = gtk.TreeView(self.store)
+ self.tv.set_size_request(350, 200)
- scrl_win = gtk.ScrolledWindow()
- set_props(scrl_win, hscrollbar_policy=gtk.POLICY_AUTOMATIC,
- vscrollbar_policy=gtk.POLICY_AUTOMATIC,
- parent=hbox)
+ for col, title, widget_type in fields:
+ self.tv.insert_column_with_attributes(-1, title,
+ gtk.CellRendererText(),
+ text=col)
- scrl_win.add(tv)
+ scrl_win = gtk.ScrolledWindow()
+ scrl_win.set_policy(hscrollbar_policy=gtk.POLICY_AUTOMATIC,
+ vscrollbar_policy=gtk.POLICY_AUTOMATIC)
+ self.pack_start(scrl_win)
- vbbox = gtk.VButtonBox()
- set_props(vbbox, layout_style=gtk.BUTTONBOX_START,
- spacing=5,
- border_width=5,
- parent=frame)
- hbox.pack_end(vbbox, expand=False, fill=False)
+ scrl_win.add(self.tv)
- button = gtk.Button(stock=gtk.STOCK_ADD)
- vbbox.add(button)
+ vbbox = gtk.VButtonBox()
+ set_props(vbbox, layout_style=gtk.BUTTONBOX_START,
+ spacing=5,
+ border_width=5)
+ self.pack_end(vbbox, expand=False, fill=False)
- dialog.show_all()
+ button = gtk.Button(stock=gtk.STOCK_ADD)
+ button.connect('clicked', self.add_node)
+ vbbox.add(button)
- if dialog.run() != gtk.RESPONSE_OK:
+# button = gtk.Button(stock=gtk.STOCK_APPLY)
+# button.connect('clicked', self.apply_changes)
+# vbbox.add(button)
+
+ def get_cluster_state(self):
+ command = ('o2cb_ctl', '-I', '-t', 'node', '-o')
+
+ o2cb_ctl = Process(command, 'Cluster Control', 'Querying nodes...',
+ self.toplevel, spin_now=False)
+ success, output, k = o2cb_ctl.reap()
+
+ if not success:
+ raise ConfError, output
+
+ self.store = gtk.ListStore(str, str, str, str)
+ self.store.set_sort_column_id(COLUMN_NODE, gtk.SORT_ASCENDING)
+
+ buffer = StringIO(output)
+
+ for line in buffer:
+ if line.startswith('#'):
+ continue
+
+ try:
+ name, cluster, node, ip_addr, ip_port, state = line.split(':')
+ except ValueError:
+ continue
+
+ if cluster == 'ocfs2':
+ iter = self.store.append((name, node, ip_addr, ip_port))
+
+ def add_node(self, b):
+ toplevel = self.get_toplevel()
+
+ dialog = gtk.Dialog(parent=toplevel, title='Add Node',
+ buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
+ gtk.STOCK_OK, gtk.RESPONSE_OK))
+
+ table = gtk.Table(rows=4, columns=2)
+ set_props(table, row_spacing=4,
+ column_spacing=4,
+ border_width=4,
+ parent=dialog.vbox)
+
+ widgets = []
+ row = 0
+
+ for col, title, widget_type in fields:
+ if widget_type is None:
+ widgets.append(None)
+ continue
+
+ label = gtk.Label(title + ':')
+ set_props(label, xalign=1.0)
+ table.attach(label, 0, 1, row, row + 1)
+
+ widget = widget_type()
+ table.attach(widget, 1, 2, row, row + 1)
+
+ if isinstance(widget, gtk.SpinButton):
+ widget.set_numeric(True)
+
+ adjustment = gtk.Adjustment(7777, 1000, 30000, 1, 100)
+ widget.set_adjustment(adjustment)
+
+ widget.set_value(7777)
+
+ widgets.append(widget)
+
+ row = row + 1
+
+ dialog.show_all()
+
+ while 1:
+ if dialog.run() != gtk.RESPONSE_OK:
+ dialog.destroy()
+ return
+
+ name = widgets[COLUMN_NAME].get_text()
+ ip_addr = widgets[COLUMN_IP_ADDR].get_text()
+ ip_port = widgets[COLUMN_IP_PORT].get_text()
+
+ if not name:
+ error_box(dialog, 'Node name not specified')
+ elif not ip_addr:
+ error_box(dialog, 'IP address not specified')
+ else:
+ break
+
dialog.destroy()
- return False
+ command = ('o2cb_ctl', '-I', '-t', 'cluster', '-n', 'ocfs2', '-o')
+ o2cb_ctl = Process(command, 'Cluster Control', 'Adding node...',
+ self.toplevel, spin_now=False)
+ success, output, k = o2cb_ctl.reap()
+
+ if not success:
+ command = ('o2cb_ctl', '-C', '-n', 'ocfs2', '-t', 'cluster', '-i')
+ success, output, k = o2cb_ctl.reap()
+
+ if not success:
+ error_box(self.toplevel,
+ '%s\nCould not create cluster' % output)
+ return
+
+
+ command = ('o2cb_ctl', '-C', '-n', name, '-t', 'node',
+ '-a', 'cluster=ocfs2',
+ '-a', 'ip_address=%s' % ip_addr,
+ '-a', 'ip_port=%s' % ip_port,
+ '-i')
+
+ o2cb_ctl = Process(command, 'Cluster Control', 'Adding node...',
+ self.toplevel, spin_now=False)
+ success, output, k = o2cb_ctl.reap()
+
+ if not success:
+ error_box(self.toplevel,
+ '%s\nCould not update configuration' % output)
+ return
+
+ self.get_cluster_state()
+ self.tv.set_model(self.store)
+
+ def apply_changes(self, b):
+ pass
+
+def cluster_configurator(parent):
+ try:
+ conf = ClusterConf(parent)
+ except ConfError, e:
+ error_box(parent, '%s: Could not query cluster configuration' % str(e))
+ return
+
+ dialog = gtk.Dialog(parent=parent, title='Cluster Configurator',
+ buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))
+
+ dialog.vbox.add(conf)
+ dialog.show_all()
+
+ dialog.run()
dialog.destroy()
- return True
def main():
cluster_configurator(None)
More information about the Ocfs2-tools-commits
mailing list