示例#1
0
def cluster_quorum(**kwargs):
    """
    Get the cluster status

    CLI Example:

        salt '*' sesceph.cluster_status \\
                'cluster_name'='ceph' \\
                'cluster_uuid'='cluster_uuid'
    Notes:
    Get the cluster quorum status.

    Scope:
    Cluster wide

    Arguments:

    cluster_uuid
        Set the cluster UUID. Defaults to value found in ceph config file.

    cluster_name
        Set the cluster name. Defaults to "ceph".
    """
    m = model.model(**kwargs)
    u = mdl_updater.model_updater(m)
    u.hostname_refresh()
    u.defaults_refresh()
    u.load_confg(m.cluster_name)
    u.mon_members_refresh()
    mur = mdl_updater_remote.model_updater_remote(m)
    can_connect = mur.connect()
    if not can_connect:
        return False
    q = mdl_query.mdl_query(m)
    return q.cluster_quorum()
示例#2
0
def cluster_quorum(**kwargs):
    """
    Get the cluster status

    CLI Example:

        salt '*' sesceph.cluster_status \\
                'cluster_name'='ceph' \\
                'cluster_uuid'='cluster_uuid'
    Notes:
    Get the cluster quorum status.

    Scope:
    Cluster wide

    Arguments:

    cluster_uuid
        Set the cluster UUID. Defaults to value found in ceph config file.

    cluster_name
        Set the cluster name. Defaults to "ceph".
    """
    m = model.model(**kwargs)
    u = mdl_updater.model_updater(m)
    u.hostname_refresh()
    u.defaults_refresh()
    u.load_confg(m.cluster_name)
    u.mon_members_refresh()
    mur = mdl_updater_remote.model_updater_remote(m)
    can_connect = mur.connect()
    if not can_connect:
        return False
    q = mdl_query.mdl_query(m)
    return q.cluster_quorum()
    def auth_add(self, keyring_type):
        """
        Authorise keyring
        """
        keyringobj = keyring.keyring_facard(self.model)
        keyringobj.key_type = keyring_type


        if not keyringobj.present():
            raise Error("rgw keyring not found")
        q = mdl_query.mdl_query(self.model)
        if q.mon_is() and q.mon_quorum() is False:
            raise Error("mon daemon is not in quorum")
        arguments = [
                "ceph",
                "auth",
                "import",
                "-i",
                keyringobj.keyring_path_get()
                ]
        output = utils.execute_local_command(arguments)
        if output["retcode"] != 0:
            raise Error("Failed executing '%s' Error rc=%s, stdout=%s stderr=%s" % (
                        " ".join(arguments),
                        output["retcode"],
                        output["stdout"],
                        output["stderr"])
                        )
        return True
示例#4
0
 def __init__(self, **kwargs):
     self.model = model.model(**kwargs)
     self._clear_implementation()
     u = mdl_updater.model_updater(self.model)
     u.ceph_version_refresh()
     q = mdl_query.mdl_query(self.model)
     self.ceph_daemon_user = q.ceph_daemon_user()
示例#5
0
 def auth_del(self, **kwargs):
     """
     Remove Authorised keyring
     """
     self.model.kargs_apply(**kwargs)
     u = mdl_updater.model_updater(m)
     u.hostname_refresh()
     if m.cluster_name == None:
         u.defaults_refresh()
     self.cluster_name = m.cluster_name
     u.load_confg(m.cluster_name)
     u.mon_members_refresh()
     q = mdl_query.mdl_query(m)
     if not q.mon_is():
         raise Error("Not ruining a mon daemon")
     u.mon_status()
     if not q.mon_quorum():
         raise Error("mon daemon is not in quorum")
     arguments = [
             "ceph",
             "auth",
             "del",
             self.keyring_name
             ]
     cmd_out = utils.execute_local_command(arguments)
     return True
示例#6
0
 def auth_add(self, **kwargs):
     """
     Authorise keyring
     """
     self.model.kargs_apply(**kwargs)
     u = mdl_updater.model_updater(self.model)
     u.hostname_refresh()
     if self.model.cluster_name == None:
         u.defaults_refresh()
     keyring_path = self.get_path_keyring()
     if not os.path.isfile(keyring_path):
         raise Error("rgw keyring not found")
     u.load_confg(self.model.cluster_name)
     u.mon_members_refresh()
     q = mdl_query.mdl_query(self.model)
     if not q.mon_is():
         raise Error("Not ruining a mon daemon")
     u.mon_status()
     if not q.mon_quorum():
         raise Error("mon daemon is not in quorum")
     arguments = [
             "ceph",
             "auth",
             "import",
             "-i",
             keyring_path
             ]
     cmd_out = utils.execute_local_command(arguments)
     return True
示例#7
0
    def mon_is(self, **kwargs):
        """
        Is this a mon node

        CLI Example:

            salt '*' sesceph.keys_create
                    'cluster_name'='ceph' \
                    'cluster_uuid'='cluster_uuid' \
        Notes:

        cluster_name
            Set the cluster name. Defaults to "ceph".

        cluster_uuid
            Set the cluster UUID. Defaults to value found in ceph config file.
        """
        u = mdl_updater.model_updater(self.model)
        u.hostname_refresh()
        try:
            u.defaults_refresh()
        except:
            return False
        u.load_confg(self.model.cluster_name)
        u.mon_members_refresh()
        q = mdl_query.mdl_query(self.model)
        return q.mon_is()
示例#8
0
    def quorum(self, **kwargs):
        """
        Is mon deamon in quorum

        CLI Example:

            salt '*' sesceph.prepare
                    'cluster_name'='ceph' \
                    'cluster_uuid'='cluster_uuid' \
        Notes:

        cluster_uuid
            Set the cluster UUID. Defaults to value found in ceph config file.

        cluster_name
            Set the cluster name. Defaults to "ceph".
        """

        hostname = platform.node()
        u = mdl_updater.model_updater(self.model)
        u.hostname_refresh()
        try:
            u.defaults_refresh()
        except:
            raise Error("Could not get cluster details")
        u.load_confg(self.model.cluster_name)
        u.mon_members_refresh()
        u.mon_status()
        q = mdl_query.mdl_query(self.model)
        return q.mon_quorum()
示例#9
0
    def status(self, **kwargs):
        """
        Get status from mon deamon

        CLI Example:

            salt '*' sesceph.prepare
                    'cluster_name'='ceph' \
                    'cluster_uuid'='cluster_uuid' \
        Notes:

        cluster_uuid
            Set the cluster UUID. Defaults to value found in ceph config file.

        cluster_name
            Set the cluster name. Defaults to "ceph".
        """

        hostname = platform.node()
        u = mdl_updater.model_updater(self.model)
        u.hostname_refresh()
        try:
            u.defaults_refresh()
        except:
            return {}
        u.load_confg(self.model.cluster_name)
        u.mon_members_refresh()
        q = mdl_query.mdl_query(self.model)
        if not q.mon_is():
            raise Error("Not a mon node")
        u.mon_status()
        p = presenter.mdl_presentor(self.model)
        return p.mon_status()
示例#10
0
 def active(self, **kwargs):
     """
     Is mon deamon running
     """
     u = mdl_updater.model_updater(self.model)
     u.hostname_refresh()
     q = mdl_query.mdl_query(self.model)
     return q.mon_active()
示例#11
0
 def auth_del(self, **kwargs):
     """
     Remove Authorised keyring
     """
     keyringobj = keyring.keyring_facard(self.model)
     keyringobj.key_type = keyring_type
     q = mdl_query.mdl_query(self.model)
     if q.mon_is() and q.mon_quorum() is False:
         raise Error("mon daemon is not in quorum")
     arguments = ["ceph", "auth", "del", keyringobj.keyring_path_get()]
     cmd_out = utils.execute_local_command(arguments)
     return True
示例#12
0
 def _create_check_responding(self):
     """
     Check the mon service is runnign and responding.
     """
     q = mdl_query.mdl_query(self.model)
     if not q.mon_active():
         raise Error("mon service has died.")
     u = mdl_updater.model_updater(self.model)
     try:
         u.mon_status()
     except mdl_updater.Error:
         return False
     return True
 def auth_del(self, **kwargs):
     """
     Remove Authorised keyring
     """
     keyringobj = keyring.keyring_facard(self.model)
     keyringobj.key_type = keyring_type
     q = mdl_query.mdl_query(self.model)
     if q.mon_is() and q.mon_quorum() is False:
         raise Error("mon daemon is not in quorum")
     arguments = [
             "ceph",
             "auth",
             "del",
             keyringobj.keyring_path_get()
             ]
     cmd_out = utils.execute_local_command(arguments)
     return True
示例#14
0
    def auth_add(self, keyring_type):
        """
        Authorise keyring
        """
        keyringobj = keyring.keyring_facard(self.model)
        keyringobj.key_type = keyring_type

        if not keyringobj.present():
            raise Error("rgw keyring not found")
        q = mdl_query.mdl_query(self.model)
        if q.mon_is() and q.mon_quorum() is False:
            raise Error("mon daemon is not in quorum")
        arguments = [
            "ceph", "auth", "import", "-i",
            keyringobj.keyring_path_get()
        ]
        cmd_out = utils.execute_local_command(arguments)
        return True
示例#15
0
def keyring_auth_del_type(**kwargs):
    """
    Write rgw keyring for cluster

    CLI Example:

        salt '*' sesceph.keyring_mds_auth_del \\
                'cluster_name'='ceph' \\
                'cluster_uuid'='cluster_uuid'
    Notes:

    cluster_uuid
        Set the cluster UUID. Defaults to value found in ceph config file.

    cluster_name
        Set the cluster name. Defaults to "ceph".
    """
    keyring_type = kwargs.get("keyring_type")
    if (keyring_type is None):
        raise Error("keyring_type is None")
    if (keyring_type in set(["mon", "admin"])):
        raise Error("keyring_type is %s" % (keyring_type))
    m = model.model(**kwargs)
    u = mdl_updater.model_updater(m)
    u.hostname_refresh()
    u.defaults_refresh()
    u.load_confg(m.cluster_name)
    u.mon_members_refresh()
    q = mdl_query.mdl_query(m)
    if q.mon_is():
        u.mon_status()
    keyobj = keyring.keyring_facard(m)
    keyobj.key_type = keyring_type
    if not keyobj.present():
        raise Error("keyring not present")
    mur = mdl_updater_remote.model_updater_remote(m)
    can_connect = mur.connect()
    if not can_connect:
        raise Error("Cant connect to cluster.")
    return mur.auth_del(keyring_type)
示例#16
0
def keyring_auth_del_type(**kwargs):
    """
    Write rgw keyring for cluster

    CLI Example:

        salt '*' sesceph.keyring_mds_auth_del \\
                'cluster_name'='ceph' \\
                'cluster_uuid'='cluster_uuid'
    Notes:

    cluster_uuid
        Set the cluster UUID. Defaults to value found in ceph config file.

    cluster_name
        Set the cluster name. Defaults to "ceph".
    """
    keyring_type = kwargs.get("keyring_type")
    if (keyring_type is None):
        raise Error("keyring_type is None")
    if (keyring_type in set(["mon","admin"])):
        raise Error("keyring_type is %s" % (keyring_type))
    m = model.model(**kwargs)
    u = mdl_updater.model_updater(m)
    u.hostname_refresh()
    u.defaults_refresh()
    u.load_confg(m.cluster_name)
    u.mon_members_refresh()
    q = mdl_query.mdl_query(m)
    if q.mon_is():
        u.mon_status()
    keyobj = keyring.keyring_facard(m)
    keyobj.key_type = keyring_type
    if not keyobj.present():
        raise Error("keyring not present")
    mur = mdl_updater_remote.model_updater_remote(m)
    can_connect = mur.connect()
    if not can_connect:
        raise Error("Cant connect to cluster.")
    return mur.auth_del(keyring_type)
    def auth_add(self, keyring_type):
        """
        Authorise keyring
        """
        keyringobj = keyring.keyring_facard(self.model)
        keyringobj.key_type = keyring_type


        if not keyringobj.present():
            raise Error("rgw keyring not found")
        q = mdl_query.mdl_query(self.model)
        if q.mon_is() and q.mon_quorum() is False:
            raise Error("mon daemon is not in quorum")
        arguments = [
                "ceph",
                "auth",
                "import",
                "-i",
                keyringobj.keyring_path_get()
                ]
        cmd_out = utils.execute_local_command(arguments)
        return True
示例#18
0
def keyring_auth_add_type(**kwargs):
    keyring_type = kwargs.get("keyring_type")
    if (keyring_type is None):
        raise Error("keyring_type is None")
    if (keyring_type in set(["mon","admin"])):
        raise Error("keyring_type is %s" % (keyring_type))
    m = model.model(**kwargs)
    u = mdl_updater.model_updater(m)
    u.hostname_refresh()
    u.defaults_refresh()
    u.load_confg(m.cluster_name)
    u.mon_members_refresh()
    q = mdl_query.mdl_query(m)
    if q.mon_is():
        u.mon_status()
    keyobj = keyring.keyring_facard(m)
    keyobj.key_type = keyring_type
    if not keyobj.present():
        raise Error("keyring not present")
    mur = mdl_updater_remote.model_updater_remote(m)
    can_connect = mur.connect()
    if not can_connect:
        raise Error("Cant connect to cluster.")
    return mur.auth_add(keyring_type)
示例#19
0
def keyring_auth_add_type(**kwargs):
    keyring_type = kwargs.get("keyring_type")
    if (keyring_type is None):
        raise Error("keyring_type is None")
    if (keyring_type in set(["mon", "admin"])):
        raise Error("keyring_type is %s" % (keyring_type))
    m = model.model(**kwargs)
    u = mdl_updater.model_updater(m)
    u.hostname_refresh()
    u.defaults_refresh()
    u.load_confg(m.cluster_name)
    u.mon_members_refresh()
    q = mdl_query.mdl_query(m)
    if q.mon_is():
        u.mon_status()
    keyobj = keyring.keyring_facard(m)
    keyobj.key_type = keyring_type
    if not keyobj.present():
        raise Error("keyring not present")
    mur = mdl_updater_remote.model_updater_remote(m)
    can_connect = mur.connect()
    if not can_connect:
        raise Error("Cant connect to cluster.")
    return mur.auth_add(keyring_type)
示例#20
0
    def create(self, **kwargs):
        """
        Create a mon node

        CLI Example:

            salt '*' sesceph.prepare
                    'cluster_name'='ceph' \
                    'cluster_uuid'='cluster_uuid' \
        Notes:

        cluster_uuid
            Set the cluster UUID. Defaults to value found in ceph config file.

        cluster_name
            Set the cluster name. Defaults to "ceph".
        """

        u = mdl_updater.model_updater(self.model)
        u.hostname_refresh()
        u.defaults_refresh()
        u.load_confg(self.model.cluster_name)
        u.mon_members_refresh()
        q = mdl_query.mdl_query(self.model)
        if not q.mon_is():
            raise Error("Not a mon node")
        p = presenter.mdl_presentor(self.model)

        path_done_file = "/var/lib/ceph/mon/%s-%s/done" % (
                self.model.cluster_name,
                self.model.hostname
            )
        keyring_path_mon = keyring._get_path_keyring_mon_bootstrap(self.model.cluster_name, self.model.hostname)
        path_adm_sock = "/var/run/ceph/%s-mon.%s.asok" % (
                self.model.cluster_name,
                self.model.hostname
            )
        path_mon_dir = "/var/lib/ceph/mon/%s-%s" % (
                self.model.cluster_name,
                self.model.hostname
            )

        path_admin_keyring = keyring._get_path_keyring_admin(self.model.cluster_name)

        path_monmap = "/var/lib/ceph/tmp/%s.monmap" % (
                self.model.cluster_name
            )
        path_tmp_keyring = "/var/lib/ceph/tmp/%s.keyring" % (
                self.model.cluster_name
            )
        if os.path.isfile(path_done_file):
            log.debug("Mon done file exists:%s" % (path_done_file))
            if q.mon_active():
                return True
            arguments = [
                constants._path_systemctl,
                "restart",
                "ceph-mon@%s" % (self.model.hostname)
                ]
            output = utils.execute_local_command(arguments)
            if output["retcode"] != 0:
                raise Error("Failed executing '%s' Error rc=%s, stdout=%s stderr=%s" % (
                    " ".join(arguments),
                    output["retcode"],
                    output["stdout"],
                    output["stderr"])
                    )

            # Error is servcie wont start
            if not q.mon_active():
                 raise Error("Failed to start monitor")
            return True

        if not os.path.isfile(keyring_path_mon):
            raise Error("Mon keyring missing")
        if not os.path.isfile(path_admin_keyring):
            raise Error("Admin keyring missing")

        try:
            tmpd = tempfile.mkdtemp()
            log.info("Create temp directory %s" %(tmpd))
            os.chown(tmpd, self.uid, self.gid)
            # In 'tmpd' we make the monmap and keyring.
            key_path = os.path.join(tmpd,"keyring")
            path_monmap = os.path.join(tmpd,"monmap")
            log.info("Create monmap %s" % (path_monmap))
            self._create_monmap(path_monmap)
            os.chown(path_monmap, self.uid, self.gid)
            arguments = [
                constants._path_ceph_authtool,
                "--create-keyring",
                key_path,
                "--import-keyring",
                keyring_path_mon,
                ]
            output = utils.execute_local_command(arguments)
            if output["retcode"] != 0:
                raise Error("Failed executing '%s' Error rc=%s, stdout=%s stderr=%s" % (
                    " ".join(arguments),
                    output["retcode"],
                    output["stdout"],
                    output["stderr"]
                    ))
            arguments = [
                constants._path_ceph_authtool,
                key_path,
                "--import-keyring",
                path_admin_keyring,
                ]
            output = utils.execute_local_command(arguments)
            if output["retcode"] != 0:
                raise Error("Failed executing '%s' Error rc=%s, stdout=%s stderr=%s" % (
                    " ".join(arguments),
                    output["retcode"],
                    output["stdout"],
                    output["stderr"]
                    ))
            # Now chown the new file
            os.chown(key_path, self.uid, self.gid)
            # Now clean the install area
            if os.path.isdir(path_mon_dir):
                log.info("Remove directory content %s" %(path_mon_dir))
                shutil.rmtree(path_mon_dir)
            if not os.path.isdir(path_mon_dir):
                log.info("Make directory %s" %(path_mon_dir))
                os.makedirs(path_mon_dir)
                os.chown(path_mon_dir, self.uid, self.gid)
            # now do install
            arguments = [
                    constants._path_ceph_mon,
                    "--mkfs",
                    "-i",
                    self.model.hostname,
                    "--monmap",
                    path_monmap,
                    '--keyring',
                    key_path
                    ]
            output = self._execute(arguments)
            if output["retcode"] != 0:
                raise Error("Failed executing '%s' Error rc=%s, stdout=%s stderr=%s" % (
                    " ".join(arguments),
                    output["retcode"],
                    output["stdout"],
                    output["stderr"]
                    ))
            # check keyring created:
            path_mon_key = os.path.join(path_mon_dir, "keyring")
            if not os.path.isfile(path_mon_key):
                raise Error("Failed to create '%s'" % (path_mon_key))
            # Now start the service
            arguments = {
                'identifier' : self.model.hostname,
                'service' : "ceph-mon",
            }
            self.init_system.restart(**arguments)
            self._create_check_retry()
            open(path_done_file, 'a').close()
        finally:
            log.info("Destroy temp directory %s" %(tmpd))
            shutil.rmtree(tmpd)
        return True