Example #1
0
    def run(self):
        self.show_all()

        while 1:
            if Dialog.run(self) == gtk.RESPONSE_APPLY:
                self.apply_changes()
            elif len(self.new_node_attrs()):
                msg = ('New nodes have been created, but they have not been '
                       'applied to the cluster configuration. Do you want to '
                       'apply the changes now?')

                ask = gtk.MessageDialog(parent=self,
                                        flags=gtk.DIALOG_DESTROY_WITH_PARENT,
                                        type=gtk.MESSAGE_QUESTION,
                                        buttons=gtk.BUTTONS_YES_NO,
                                        message_format=msg)

                if ask.run() == gtk.RESPONSE_NO:
                    break
                elif self.apply_changes():
                    break
            else:
                break
Example #2
0
    def run(self):
        self.show_all()

        while 1:
            if Dialog.run(self) == gtk.RESPONSE_APPLY:
                self.apply_changes()
            elif len(self.new_node_attrs()):
                msg = ('New nodes have been created, but they have not been '
                       'applied to the cluster configuration. Do you want to '
                       'apply the changes now?')

                ask = gtk.MessageDialog(parent=self,
                                        flags=gtk.DIALOG_DESTROY_WITH_PARENT,
                                        type=gtk.MESSAGE_QUESTION,
                                        buttons=gtk.BUTTONS_YES_NO,
                                        message_format=msg)

                if ask.run() == gtk.RESPONSE_NO:
                    break
                elif self.apply_changes():
                    break
            else: 
                break
Example #3
0
def tune_action(widget_type, parent, device):
    try:
        widget = widget_type(device)
    except ocfs2.error:
        desc = widget_type.label.replace('_', '')
        desc = desc.lower()
        error_box(parent, 'Could not get current %s for device %s' %
                          (desc, device))
        return False

    dialog = Dialog(parent=parent, title=widget_type.title,
                    buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                             gtk.STOCK_OK,     gtk.RESPONSE_OK))

    dialog.set_alternative_button_order((gtk.RESPONSE_OK, gtk.RESPONSE_CANCEL))

    dialog.set_default_response(gtk.RESPONSE_OK)

    table = gtk.Table(rows=1, columns=2)
    set_props(table, row_spacing=6,
                     column_spacing=6,
                     border_width=6,
                     parent=dialog.vbox)

    label = gtk.Label()
    label.set_text_with_mnemonic(widget_type.label + ':')
    set_props(label, xalign=0.0)
    table.attach(label, 0, 1, 0, 1)

    label.set_mnemonic_widget(widget)
    table.attach(widget, 1, 2, 0, 1)

    if isinstance(widget, gtk.Entry):
        widget.set_activates_default(True)

    widget.grab_focus()

    dialog.show_all()

    while 1:
        if dialog.run() != gtk.RESPONSE_OK:
            dialog.destroy()
            return False

        new_label = widget.get_text()

        if not new_label:
            if widget_type.empty_ok:
                msg = ('Are you sure you want to clear the %s on %s?' %
                       (widget_type.lower(), device))

                ask = gtk.MessageDialog(parent=dialog,
                                        flags=gtk.DIALOG_DESTROY_WITH_PARENT,
                                        type=gtk.MESSAGE_QUESTION,
                                        buttons=gtk.BUTTONS_YES_NO,
                                        message_format=msg)
                        
                if ask.run() == gtk.RESPONSE_YES:
                    break
                else:
                    ask.destroy()
            else:
                error_box(dialog, '%s cannot be empty.' %
                                  widget_type.lower().ucfirst())
        else:
            break

    command = list(base_command)
    command.extend(widget.get_arg())

    command.append(device)

    dialog.destroy()

    tunefs = Process(command, widget_type.title, widget_type.action + '...',
                     parent, spin_now=True)
    success, output, k = tunefs.reap()

    if not success:
        error_box(parent, 'File system tune error: %s' % output)
        return False

    return True
Example #4
0
    def __init__(self, cluster_name=DEFAULT_CLUSTER_NAME, parent=None):
        self.cluster_name = cluster_name

        Dialog.__init__(self,
                        parent=parent,
                        title='Node Configuration',
                        buttons=(gtk.STOCK_APPLY, gtk.RESPONSE_APPLY,
                                 gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))

        if parent is None:
            self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)

        frame = gtk.Frame()
        frame.set_shadow_type(gtk.SHADOW_NONE)
        self.vbox.add(frame)

        label = gtk.Label()
        label.set_text_with_mnemonic('_Nodes:')
        frame.set_label_widget(label)

        hbox = gtk.HBox(spacing=4)
        hbox.set_border_width(4)
        frame.add(hbox)

        scrl_win = gtk.ScrolledWindow()
        scrl_win.set_policy(hscrollbar_policy=gtk.POLICY_AUTOMATIC,
                            vscrollbar_policy=gtk.POLICY_AUTOMATIC)
        hbox.pack_start(scrl_win)

        self.setup_treeview()
        label.set_mnemonic_widget(self.tv)
        scrl_win.add(self.tv)

        vbbox = gtk.VButtonBox()
        set_props(vbbox,
                  layout_style=gtk.BUTTONBOX_START,
                  spacing=5,
                  border_width=5)
        hbox.pack_end(vbbox, expand=False, fill=False)

        self.add_button = gtk.Button(stock=gtk.STOCK_ADD)
        self.add_button.connect('clicked', self.add_node)
        vbbox.add(self.add_button)

        try:
            edit_construct_args = {'stock': gtk.STOCK_EDIT}
        except AttributeError:
            edit_construct_args = {'label': '_Edit'}

        self.edit_button = gtk.Button(**edit_construct_args)
        self.edit_button.connect('clicked', self.edit_node)
        vbbox.add(self.edit_button)

        self.remove_button = gtk.Button(stock=gtk.STOCK_REMOVE)
        self.remove_button.connect('clicked', self.remove_node)
        vbbox.add(self.remove_button)

        self.can_edit(False)
        self.can_apply(False)

        self.sel = self.tv.get_selection()
        self.sel.connect('changed', self.on_select)

        self.tv.connect('row_activated', self.on_row_activated)

        self.load_cluster_state()
Example #5
0
    def node_query(self,
                   title='Node Attributes',
                   defaults=None,
                   editing=False):
        existing_names = {}
        existing_ip_addrs = {}

        for row in self.store:
            name = row[COLUMN_NAME]
            ip_addr = row[COLUMN_IP_ADDRESS]

            if not (editing and name == defaults[COLUMN_NAME]):
                existing_names[name] = 1

            if not (editing and ip_addr == defaults[COLUMN_IP_ADDRESS]):
                existing_ip_addrs[ip_addr] = name

        dialog = Dialog(parent=self,
                        title=title,
                        buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                 gtk.STOCK_OK, gtk.RESPONSE_OK))

        dialog.set_alternative_button_order(
            (gtk.RESPONSE_OK, gtk.RESPONSE_CANCEL))

        dialog.set_default_response(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 = []

        for row, field in enumerate(fields):
            if field.widget_type is None:
                widgets.append(None)
                continue

            label = gtk.Label(field.title + ':')
            set_props(label, xalign=1.0)
            table.attach(label, 0, 1, row, row + 1)

            widget = field.widget_type()
            table.attach(widget, 1, 2, row, row + 1)

            if field.column == COLUMN_NAME:
                widget.set_max_length(o2cb.O2NM_MAX_NAME_LEN)
            elif field.column == COLUMN_IP_PORT:
                widget.set_numeric(True)

                adjustment = gtk.Adjustment(PORT_DEFAULT, PORT_MINIMUM,
                                            PORT_MAXIMUM, 1, 100)

                widget.set_adjustment(adjustment)
                widget.set_value(PORT_DEFAULT)

            widgets.append(widget)

        if defaults:
            for w, d in zip(widgets, defaults):
                if w and d:
                    w.set_text(d)

        dialog.show_all()

        while 1:
            if dialog.run() != gtk.RESPONSE_OK:
                dialog.destroy()
                return None

            ip_port = widgets[COLUMN_IP_PORT].get_text()

            name = widgets[COLUMN_NAME].get_text()

            if not name:
                error_box(dialog, 'Node name not specified')
                continue

            try:
                ip_addr = widgets[COLUMN_IP_ADDRESS].get_text()
            except (IPMissing, IPError), msg:
                error_box(dialog, msg[0])
                continue

            if name in existing_names:
                error_box(dialog,
                          'Node %s already exists in the configuration' % name)
            elif ip_addr in existing_ip_addrs:
                error_box(
                    dialog, 'IP %s is already assigned to node %s' %
                    (ip_addr, existing_ip_addrs[ip_addr]))
            else:
                break
Example #6
0
def format_partition(parent, device):
    partitions = []

    def add_partition(device, fstype):
        partitions.append((device, fstype))

    partition_list(add_partition, unmounted=True)

    if not partitions:
        error_box(parent, 'No unmounted partitions')
        return False

    def sort_partition(x, y):
        return cmp(x[0], y[0])

    partitions.sort(sort_partition)

    dialog = Dialog(parent=parent, title='Format',
                    buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                             gtk.STOCK_OK,     gtk.RESPONSE_OK))

    dialog.set_alternative_button_order((gtk.RESPONSE_OK, gtk.RESPONSE_CANCEL))

    dialog.set_default_response(gtk.RESPONSE_OK)

    table = gtk.Table(rows=5, columns=2)
    set_props(table, row_spacing=6,
                     column_spacing=6,
                     border_width=6,
                     parent=dialog.vbox)

    widgets = []

    for row, widget_type in enumerate(entries):
        widget = widget_type()

        label = gtk.Label()
        label.set_text_with_mnemonic(widget_type.label + ':')
        label.set_mnemonic_widget(widget)
        set_props(label, xalign=0.0)
        table.attach(label, 0, 1, row, row + 1)

        if widget_type == Device:
            widget.fill(partitions, device)

        if isinstance(widget, gtk.Entry):
            widget.set_activates_default(True)

        if isinstance(widget, gtk.SpinButton):
            attach_widget = gtk.HBox()
            attach_widget.pack_start(widget, expand=False, fill=False)
        else:
            attach_widget = widget

        table.attach(attach_widget, 1, 2, row, row + 1)

        widgets.append(widget)

    widgets[0].grab_focus()

    dialog.show_all()

    while 1:
        if dialog.run() != gtk.RESPONSE_OK:
            dialog.destroy()
            return False

        dev = widgets[0].get_device()
        msg = 'Are you sure you want to format %s?' % dev

        ask = gtk.MessageDialog(parent=dialog,
                                flags=gtk.DIALOG_DESTROY_WITH_PARENT,
                                type=gtk.MESSAGE_QUESTION,
                                buttons=gtk.BUTTONS_YES_NO,
                                message_format=msg)

        if ask.run() == gtk.RESPONSE_YES:
            break
        else:
            ask.destroy()

    command = list(base_command)

    for widget in widgets[1:]:
        arg = widget.get_arg()

        if arg:
            command.extend(arg)

    command.append(dev)

    dialog.destroy()

    mkfs = Process(command, 'Format', 'Formatting...', parent, spin_now=True)
    success, output, k = mkfs.reap()

    if not success:
        error_box(parent, 'Format error: %s' % output)
        return False

    return True
Example #7
0
def format_partition(parent, device):
    partitions = []

    def add_partition(device, fstype):
        partitions.append((device, fstype))

    partition_list(add_partition, unmounted=True)

    if not partitions:
        error_box(parent, 'No unmounted partitions')
        return False

    def sort_partition(x, y):
        return cmp(x[0], y[0])

    partitions.sort(sort_partition)

    dialog = Dialog(parent=parent, title='Format',
                    buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                             gtk.STOCK_OK,     gtk.RESPONSE_OK))

    dialog.set_alternative_button_order((gtk.RESPONSE_OK, gtk.RESPONSE_CANCEL))

    dialog.set_default_response(gtk.RESPONSE_OK)

    table = gtk.Table(rows=5, columns=2)
    set_props(table, row_spacing=6,
                     column_spacing=6,
                     border_width=6,
                     parent=dialog.vbox)

    widgets = []

    for row, widget_type in enumerate(entries):
        widget = widget_type()

        label = gtk.Label()
        label.set_text_with_mnemonic(widget_type.label + ':')
        label.set_mnemonic_widget(widget)
        set_props(label, xalign=0.0)
        table.attach(label, 0, 1, row, row + 1)

        if widget_type == Device:
            widget.fill(partitions, device)

        if isinstance(widget, gtk.Entry):
            widget.set_activates_default(True)

        if isinstance(widget, gtk.SpinButton):
            attach_widget = gtk.HBox()
            attach_widget.pack_start(widget, expand=False, fill=False)
        else:
            attach_widget = widget

        table.attach(attach_widget, 1, 2, row, row + 1)

        widgets.append(widget)

    widgets[0].grab_focus()

    dialog.show_all()

    while 1:
        if dialog.run() != gtk.RESPONSE_OK:
            dialog.destroy()
            return False

        dev = widgets[0].get_device()
        msg = 'Are you sure you want to format %s?' % dev

        ask = gtk.MessageDialog(parent=dialog,
                                flags=gtk.DIALOG_DESTROY_WITH_PARENT,
                                type=gtk.MESSAGE_QUESTION,
                                buttons=gtk.BUTTONS_YES_NO,
                                message_format=msg)

        if ask.run() == gtk.RESPONSE_YES:
            break
        else:
            ask.destroy()

    command = list(base_command)

    for widget in widgets[1:]:
        arg = widget.get_arg()

        if arg:
            command.extend(arg)

    command.append(dev)

    dialog.destroy()

    mkfs = Process(command, 'Format', 'Formatting...', parent, spin_now=True)
    success, output, k = mkfs.reap()

    if not success:
        error_box(parent, 'Format error: %s' % output)
        return False

    return True
Example #8
0
def tune_action(widget_type, parent, device):
    try:
        widget = widget_type(device)
    except ocfs2.error:
        desc = widget_type.label.replace('_', '')
        desc = desc.lower()
        error_box(parent,
                  'Could not get current %s for device %s' % (desc, device))
        return False

    dialog = Dialog(parent=parent,
                    title=widget_type.title,
                    buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                             gtk.STOCK_OK, gtk.RESPONSE_OK))

    dialog.set_alternative_button_order((gtk.RESPONSE_OK, gtk.RESPONSE_CANCEL))

    dialog.set_default_response(gtk.RESPONSE_OK)

    table = gtk.Table(rows=1, columns=2)
    set_props(table,
              row_spacing=6,
              column_spacing=6,
              border_width=6,
              parent=dialog.vbox)

    label = gtk.Label()
    label.set_text_with_mnemonic(widget_type.label + ':')
    set_props(label, xalign=0.0)
    table.attach(label, 0, 1, 0, 1)

    label.set_mnemonic_widget(widget)
    table.attach(widget, 1, 2, 0, 1)

    if isinstance(widget, gtk.Entry):
        widget.set_activates_default(True)

    widget.grab_focus()

    dialog.show_all()

    while 1:
        if dialog.run() != gtk.RESPONSE_OK:
            dialog.destroy()
            return False

        new_label = widget.get_text()

        if not new_label:
            if widget_type.empty_ok:
                msg = ('Are you sure you want to clear the %s on %s?' %
                       (widget_type.lower(), device))

                ask = gtk.MessageDialog(parent=dialog,
                                        flags=gtk.DIALOG_DESTROY_WITH_PARENT,
                                        type=gtk.MESSAGE_QUESTION,
                                        buttons=gtk.BUTTONS_YES_NO,
                                        message_format=msg)

                if ask.run() == gtk.RESPONSE_YES:
                    break
                else:
                    ask.destroy()
            else:
                error_box(
                    dialog,
                    '%s cannot be empty.' % widget_type.lower().ucfirst())
        else:
            break

    command = list(base_command)
    command.extend(widget.get_arg())

    command.append(device)

    dialog.destroy()

    tunefs = Process(command,
                     widget_type.title,
                     widget_type.action + '...',
                     parent,
                     spin_now=True)
    success, output, k = tunefs.reap()

    if not success:
        error_box(parent, 'File system tune error: %s' % output)
        return False

    return True
Example #9
0
    def __init__(self, cluster_name=DEFAULT_CLUSTER_NAME, parent=None):
        self.cluster_name = cluster_name

        Dialog.__init__(self, parent=parent, title='Node Configuration',
                        buttons=(gtk.STOCK_APPLY, gtk.RESPONSE_APPLY,
                                 gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))

        if parent is None:
            self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)

        frame = gtk.Frame()
        frame.set_shadow_type(gtk.SHADOW_NONE)
        self.vbox.add(frame)

        label = gtk.Label()
        label.set_text_with_mnemonic('_Nodes:')
        frame.set_label_widget(label)

        hbox = gtk.HBox(spacing=4)
        hbox.set_border_width(4)
        frame.add(hbox)

        scrl_win = gtk.ScrolledWindow()     
        scrl_win.set_policy(hscrollbar_policy=gtk.POLICY_AUTOMATIC,
                            vscrollbar_policy=gtk.POLICY_AUTOMATIC)
        hbox.pack_start(scrl_win)

        self.setup_treeview()
        label.set_mnemonic_widget(self.tv)
        scrl_win.add(self.tv)

        vbbox = gtk.VButtonBox()
        set_props(vbbox, layout_style=gtk.BUTTONBOX_START,
                         spacing=5,
                         border_width=5)
        hbox.pack_end(vbbox, expand=False, fill=False)

        self.add_button = gtk.Button(stock=gtk.STOCK_ADD)
        self.add_button.connect('clicked', self.add_node)
        vbbox.add(self.add_button)

        try:
            edit_construct_args = {'stock': gtk.STOCK_EDIT}
        except AttributeError:
            edit_construct_args = {'label': '_Edit'}

        self.edit_button = gtk.Button(**edit_construct_args)
        self.edit_button.connect('clicked', self.edit_node)
        vbbox.add(self.edit_button)
        
        self.remove_button = gtk.Button(stock=gtk.STOCK_REMOVE)
        self.remove_button.connect('clicked', self.remove_node)
        vbbox.add(self.remove_button)

        self.can_edit(False)
        self.can_apply(False)
 
        self.sel = self.tv.get_selection()
        self.sel.connect('changed', self.on_select)

        self.tv.connect('row_activated', self.on_row_activated)

        self.load_cluster_state()
Example #10
0
    def node_query(self, title='Node Attributes', defaults=None, editing=False):
        existing_names = {}
        existing_ip_addrs = {}

        for row in self.store:
            name = row[COLUMN_NAME]
            ip_addr = row[COLUMN_IP_ADDRESS]

            if not (editing and name == defaults[COLUMN_NAME]):
                existing_names[name] = 1

            if not (editing and ip_addr == defaults[COLUMN_IP_ADDRESS]):
                existing_ip_addrs[ip_addr] = name

        dialog = Dialog(parent=self, title=title,
                        buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                 gtk.STOCK_OK,     gtk.RESPONSE_OK))

        dialog.set_alternative_button_order((gtk.RESPONSE_OK,
                                             gtk.RESPONSE_CANCEL))

        dialog.set_default_response(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 = []

        for row, field in enumerate(fields):
            if field.widget_type is None:
                widgets.append(None)
                continue

            label = gtk.Label(field.title + ':')
            set_props(label, xalign=1.0)
            table.attach(label, 0, 1, row, row + 1)

            widget = field.widget_type()
            table.attach(widget, 1, 2, row, row + 1)

            if field.column == COLUMN_NAME:
                widget.set_max_length(o2cb.O2NM_MAX_NAME_LEN)
            elif field.column == COLUMN_IP_PORT:
                widget.set_numeric(True)

                adjustment = gtk.Adjustment(PORT_DEFAULT,
                                            PORT_MINIMUM, PORT_MAXIMUM,
                                            1, 100) 

                widget.set_adjustment(adjustment)
                widget.set_value(PORT_DEFAULT)

            widgets.append(widget)

        if defaults:
            for w, d in zip(widgets, defaults):
                if w and d:
                    w.set_text(d)

        dialog.show_all()

        while 1:
            if dialog.run() != gtk.RESPONSE_OK:
                dialog.destroy()
                return None

            ip_port = widgets[COLUMN_IP_PORT].get_text()

            name = widgets[COLUMN_NAME].get_text()

            if not name:
                error_box(dialog, 'Node name not specified')
                continue

            try:
                ip_addr = widgets[COLUMN_IP_ADDRESS].get_text()
            except (IPMissing, IPError), msg:
                error_box(dialog, msg[0])
                continue

            if name in existing_names:
                error_box(dialog,
                          'Node %s already exists in the configuration' % name)
            elif ip_addr in existing_ip_addrs:
                error_box(dialog,
                          'IP %s is already assigned to node %s' %
                          (ip_addr, existing_ip_addrs[ip_addr]))
            else:
                break