Example #1
0
    def displayConfig(self):
        config = QHAObject.getInstance().hacfg
        if config.ha_type == PRIMARY:
            QMessageBox.warning(
                self,
                tr('High availability already configured'),
                tr('High availability status disallows editing the configuration'))
            return

        ha_wizard = ConfigWizard(self)
        ret = ha_wizard.exec_()
        if ret != QDialog.Accepted:
            return False

        qhaobject = QHAObject.getInstance()
        qhaobject.pre_modify()

        config = qhaobject.hacfg

        qnetobject = QNetObject.getInstance()
        qnetobject.pre_modify()
        net_cfg = qnetobject.netcfg

        old_type = config.ha_type
        new_config = ha_wizard.getData()
        config.ha_type = new_config.ha_type
        config.interface_id = new_config.interface_id
        config.interface_name = new_config.interface_name
        if config.ha_type in (PENDING_PRIMARY, PENDING_SECONDARY):
            iface = net_cfg.getIfaceByHardLabel(config.interface_id)
            configureHA(net_cfg, iface)
            network_modified = True
        elif config.ha_type != old_type:
            deconfigureHA(net_cfg)
            network_modified = True
            # XXX should not reconfigure now ?
        else:
            network_modified = False

        valid = qnetobject.post_modify()
        if not valid:
            qhaobject.revert()
        else:
            # FIXME: use post_modify() result?
            qhaobject.post_modify()
            self.setModified(True)
            if network_modified:
                network = self.mainwindow.getPage('network')
                network.setModified(True)
                dhcp = self.mainwindow.getPage('dhcp')
                dhcp.dhcp_widget.setModified(True)
                dhcp.dhcp_widget.fillView()

        self.setViewData()
        return True
Example #2
0
def prune_ha_net(manager):
    try:
        net_serialized = manager._modified_configuration.get('network')
    except ConfigError:
        return False

    if net_serialized is None:
        return False

    netcfg = deserialize(net_serialized)

    try:
        deconfigureHA(netcfg)
    except NetCfgError:
        #nothing to do
        return False

    net_serialized = netcfg.serialize()

    for block in (manager._running_configuration, manager._modified_configuration):
        del block['network']
        block.fromDict('network', net_serialized)
    return True