Esempio n. 1
0
    def status(self, args, options):
        master = ocf.ha_master_uname()
        myself = ocf.ha_node_uname(ocf.ha_uuid())

        status = "unknown"
        if master is None:
            status = "down"
        elif myself == master:
            status = "master"
        else:
            status = "slave"

        return status
Esempio n. 2
0
    def apply(self, args, options):
        # We follow the steps described at https://wiki.xivo.fr/index.php/Install_XiVO_HA
        self.log.debug("** apply HA changes **")
        out = ["** apply HA changes **"]

        """
            case #1: HA not starter (ha_master_uname == '')
              we cannot stand if we have another HA node
              : HA configuration is applied

            case #2: we are not master node
              : configuration not applied

            case #3: slave nodes are not stopped
              : configuration not applied
        """

        master = ocf.ha_node_uname(ocf.ha_uuid())
        if ocf.ha_master_uname() is not None and master != ocf.ha_master_uname():
            out.append("Changes not applied: current node MUST be master node")
            raise HttpReqError(500, "\n".join(out))

        slaves = ocf.ha_nodes_uname_except(master)
        if slaves is not None:
            for slave in slaves:
                if ocf.ha_node_status(slave) == "active":
                    out.append("Changes not applied: slave node '%s' is active" % slave)
                    raise HttpReqError(500, "\n".join(out))

        try:
            # 1. stop heartbeat
            self._exec("stopping heartbeat", ["/etc/init.d/heartbeat", "stop"], out)

            # 2. start mysql
            self._exec("start mysql", ["/etc/init.d/mysql", "start"], out)

            # 3.  execute update-pf-ha
            self._exec("executing update-pf-ha", ["/usr/sbin/update-pf-ha"], out)

            match = re.match(".*CIB file written:\s+(/tmp/cib.xml.[0-9]+).*", out[-1], re.S | re.M)
            if match is None:
                out.append("ERROR: no CIB file")
                raise HttpReqError(500, "\n".join(out))

            cibfile = match.group(1)
            if not os.path.isfile(cibfile):
                out.append("ERROR: CIB file %s not found" % cibfile)
                raise HttpReqError(500, "\n".join(out))

            # 4. stopping mysql
            self._exec("stop mysql", ["/etc/init.d/mysql", "stop"], out)

            # 5. verify CIB file
            self._exec("verify %s CIB file" % cibfile, ["/usr/sbin/crm_verify", "-V", "--xml-file=%s" % cibfile], out)

            # 6. clean heartbeat state
            self._exec("clean heartbeat CRM state", ["/bin/rm", "-Rf", "/var/lib/heartbeat/crm/*"], out)

            # 7. install cib file
            self._exec("install CIB file", ["cp", "-a", cibfile, "/var/lib/heartbeat/crm/cib.xml"], out)

            # 8. start heartbeat
            self._exec("start heartbeat", ["/etc/init.d/heartbeat", "start"], out)

        except OSError, e:
            traceback.print_exc()
            raise HttpReqError(500, "\n".join(out))