Beispiel #1
0
def pool_del(pool_name, **kwargs):
    """
    List all cephx authorization keys

    CLI Example:

        salt '*' sesceph.pool_del pool_name \\
                '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.
    """
    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:
        raise Error("Cant connect to cluster.")
    mur.pool_list()
    return mur.pool_del(pool_name)
Beispiel #2
0
def keyring_present_type(**kwargs):
    """
    Check if keyring exists on disk

    CLI Example:

        salt '*' sesceph.keyring_admin_save \\
                '[mon.]\n\tkey = AQA/vZ9WyDwsKRAAxQ6wjGJH6WV8fDJeyzxHrg==\n\tcaps mon = \"allow *\"\n' \\
                '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
        Set the keyring type
    """
    keyring_type = kwargs.get("keyring_type")
    if (keyring_type is None):
        raise Error("keyring_type is None")
    m = model.model(**kwargs)
    u = mdl_updater.model_updater(m)
    u.hostname_refresh()
    try:
        u.defaults_refresh()
    except:
        pass
    keyobj = keyring.keyring_facard(m)
    keyobj.key_type = keyring_type
    return keyobj.present()
Beispiel #3
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()
 def update(self):
     self.updater = mdl_updater.model_updater(self.model)
     self.updater.hostname_refresh()
     try:
         self.updater.defaults_refresh()
     except utils.Error, e:
         log.error(e)
Beispiel #5
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 keyring_present_type(**kwargs):
    """
    Check if keyring exists on disk

    CLI Example:

        salt '*' sesceph.keyring_admin_save \\
                '[mon.]\n\tkey = AQA/vZ9WyDwsKRAAxQ6wjGJH6WV8fDJeyzxHrg==\n\tcaps mon = \"allow *\"\n' \\
                '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
        Set the keyring type
    """
    keyring_type = kwargs.get("keyring_type")
    if (keyring_type is None):
        raise Error("keyring_type is None")
    m = model.model(**kwargs)
    u = mdl_updater.model_updater(m)
    u.hostname_refresh()
    try:
        u.defaults_refresh()
    except:
        pass
    keyobj = keyring.keyring_facard(m)
    keyobj.key_type = keyring_type
    return keyobj.present()
Beispiel #7
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()
Beispiel #8
0
def update_model(mdl):
    # Utility function to update model for osd_ctrl
    u = mdl_updater.model_updater(mdl)
    u.symlinks_refresh()
    u.defaults_refresh()
    u.partitions_all_refresh()
    u.discover_partitions_refresh()
Beispiel #9
0
def pool_del(pool_name, **kwargs):
    """
    List all cephx authorization keys

    CLI Example:

        salt '*' sesceph.pool_del pool_name \\
                '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.
    """
    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:
        raise Error("Cant connect to cluster.")
    mur.pool_list()
    return mur.pool_del(pool_name)
Beispiel #10
0
 def update(self):
     self.updater = mdl_updater.model_updater(self.model)
     self.updater.hostname_refresh()
     try:
         self.updater.defaults_refresh()
     except utils.Error, e:
         log.error(e)
Beispiel #11
0
def cluster_status(**kwargs):
    """
    Get the cluster status

    CLI Example:

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

    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:
        raise Error("Cant connect to cluster.")
    p = presenter.mdl_presentor(m)
    return p.cluster_status()
Beispiel #12
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()
Beispiel #13
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()
Beispiel #14
0
def cluster_status(**kwargs):
    """
    Get the cluster status

    CLI Example:

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

    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:
        raise Error("Cant connect to cluster.")
    p = presenter.mdl_presentor(m)
    return p.cluster_status()
Beispiel #15
0
def keyring_auth_list(**kwargs):
    """
    List all cephx authorization keys

    CLI Example:

        salt '*' sesceph.auth_list \\
                '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.
    """
    m = model.model(**kwargs)
    u = mdl_updater.model_updater(m)
    u.hostname_refresh()
    try:
        u.defaults_refresh()
    except:
        return {}
    u.load_confg(m.cluster_name)
    u.mon_members_refresh()
    u.auth_list()
    p = presenter.mdl_presentor(m)
    return p.auth_list()
Beispiel #16
0
def pool_del(pool_name, **kwargs):
    """
    List all cephx authorization keys

    CLI Example:

        salt '*' sesceph.pool_del pool_name \
                '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.
    """
    m = model.model(**kwargs)
    u = mdl_updater.model_updater(m)
    u.hostname_refresh()
    try:
        u.defaults_refresh()
    except:
        return {}
    u.load_confg(m.cluster_name)
    u.mon_members_refresh()
    u.pool_list()
    u.pool_del(pool_name)
    return True
Beispiel #17
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
Beispiel #18
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
Beispiel #19
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()
Beispiel #20
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()
Beispiel #21
0
def ceph_version():
    """
    Get the version of ceph installed
    """
    m = model.model()
    u = mdl_updater.model_updater(m)
    u.ceph_version_refresh()
    p = presenter.mdl_presentor(m)
    return p.ceph_version()
Beispiel #22
0
def ceph_version():
    """
    Get the version of ceph installed
    """
    m = model.model()
    u = mdl_updater.model_updater(m)
    u.ceph_version_refresh()
    p = presenter.mdl_presentor(m)
    return p.ceph_version()
Beispiel #23
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 keyring_purge_type(**kwargs):
    keyring_type = kwargs.get("keyring_type", None)
    if (keyring_type is None):
        raise Error("keyring_type is not set")
    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()
    keyobj = keyring.keyring_facard(m)
    keyobj.key_type = keyring_type
    return keyobj.remove()
Beispiel #25
0
def keyring_purge_type(**kwargs):
    keyring_type = kwargs.get("keyring_type", None)
    if (keyring_type is None):
        raise Error("keyring_type is not set")
    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()
    keyobj = keyring.keyring_facard(m)
    keyobj.key_type = keyring_type
    return keyobj.remove()
Beispiel #26
0
def keyring_create_type(**kwargs):
    keyring_type = kwargs.get("keyring_type")
    if (keyring_type is None):
        raise Error("keyring_type is None")
    secret = kwargs.get("secret")
    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()
    keyobj = keyring.keyring_facard(m)
    keyobj.key_type = keyring_type
    return keyobj.create(secret=secret)
Beispiel #27
0
 def write(self, key_content, **kwargs):
     """
     Persist 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 os.path.isfile(keyring_path):
         return True
     _keying_write(keyring_path, key_content)
     return True
def keyring_create_type(**kwargs):
    keyring_type = kwargs.get("keyring_type")
    if (keyring_type is None):
        raise Error("keyring_type is None")
    secret = kwargs.get("secret")
    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()
    keyobj = keyring.keyring_facard(m)
    keyobj.key_type = keyring_type
    return keyobj.create(secret=secret)
Beispiel #29
0
def partition_list():
    '''
    List partitions by disk

    CLI Example:

        salt '*' sesceph.partitions_all
    '''
    m = model.model()
    u = mdl_updater.model_updater(m)
    u.symlinks_refresh()
    u.partitions_all_refresh()
    u.partition_table_refresh()
    p = presenter.mdl_presentor(m)
    return p.partitions_all()
Beispiel #30
0
def partition_list_journal():
    '''
    List all OSD journal partitions by partition

    CLI Example:

        salt '*' sesceph.partitions_journal
    '''
    m = model.model()
    u = mdl_updater.model_updater(m)
    u.symlinks_refresh()
    u.partitions_all_refresh()
    u.discover_partitions_refresh()
    p = presenter.mdl_presentor(m)
    return p.discover_journal_partitions()
Beispiel #31
0
 def remove(self, **kwargs):
     """
     Delete keyring
     """
     self.model.kargs_apply(**kwargs)
     u = mdl_updater.model_updater(self.model)
     if self.model.cluster_name is None:
         u.defaults_refresh()
     keyring_path = self.get_path_keyring()
     if os.path.isfile(keyring_path):
         try:
             os.remove(keyring_path)
         except:
             raise Error("Keyring could not be deleted")
     return True
Beispiel #32
0
def partition_list_journal():
    '''
    List all OSD journal partitions by partition

    CLI Example:

        salt '*' sesceph.partitions_journal
    '''
    m = model.model()
    u = mdl_updater.model_updater(m)
    u.symlinks_refresh()
    u.partitions_all_refresh()
    u.discover_partitions_refresh()
    p = presenter.mdl_presentor(m)
    return p.discover_journal_partitions()
Beispiel #33
0
def partition_list():
    '''
    List partitions by disk

    CLI Example:

        salt '*' sesceph.partitions_all
    '''
    m = model.model()
    u = mdl_updater.model_updater(m)
    u.symlinks_refresh()
    u.partitions_all_refresh()
    u.partition_table_refresh()
    p = presenter.mdl_presentor(m)
    return p.partitions_all()
Beispiel #34
0
def purge(mdl, **kwargs):
    """
    purge ceph configuration on the node

    CLI Example:

        salt '*' sesceph.purge
    """
    service_shutdown_ceph()
    pur_ctrl = purger(mdl)
    updater = mdl_updater.model_updater(mdl)
    updater.hostname_refresh()
    try:
        updater.defaults_refresh()
    except utils.Error, e:
        log.error("exception self.updater.defaults_refresh()")
        log.error(e)
Beispiel #35
0
def purge(mdl, **kwargs):
    """
    purge ceph configuration on the node

    CLI Example:

        salt '*' sesceph.purge
    """
    service_shutdown_ceph()
    pur_ctrl = purger(mdl)
    updater = mdl_updater.model_updater(mdl)
    updater.hostname_refresh()
    try:
        updater.defaults_refresh()
    except utils.Error, e:
        log.error("exception self.updater.defaults_refresh()")
        log.error(e)
Beispiel #36
0
def osd_discover():
    """
    List all OSD by cluster

    CLI Example:

        salt '*' sesceph.osd_discover

    """
    m = model.model()
    u = mdl_updater.model_updater(m)

    u.symlinks_refresh()
    u.partitions_all_refresh()
    u.discover_partitions_refresh()
    p = presenter.mdl_presentor(m)
    return p.discover_osd()
Beispiel #37
0
def osd_discover():
    """
    List all OSD by cluster

    CLI Example:

        salt '*' sesceph.osd_discover

    """
    m = model.model()
    u = mdl_updater.model_updater(m)

    u.symlinks_refresh()
    u.partitions_all_refresh()
    u.discover_partitions_refresh()
    p = presenter.mdl_presentor(m)
    return p.discover_osd()
Beispiel #38
0
def keyring_save_type(**kwargs):
    keyring_type = kwargs.get("keyring_type")
    key_content = kwargs.get("key_content")
    secret = kwargs.get("secret")
    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()
    keyobj = keyring.keyring_facard(m)
    keyobj.key_type = keyring_type
    if secret is not None:
        utils.is_valid_base64(secret)
        return keyobj.write_secret(secret)
    if key_content is not None:
        return keyobj.write_content(key_content)
    raise Error("Set either the key_content or the key `secret`")
def keyring_save_type(**kwargs):
    keyring_type = kwargs.get("keyring_type")
    key_content = kwargs.get("key_content")
    secret = kwargs.get("secret")
    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()
    keyobj = keyring.keyring_facard(m)
    keyobj.key_type = keyring_type
    if secret is not None:
        utils.is_valid_base64(secret)
        return keyobj.write_secret(secret)
    if key_content is not None:
        return keyobj.write_content(key_content)
    raise Error("Set either the key_content or the key `secret`")
Beispiel #40
0
def pool_add(pool_name, **kwargs):
    """
    List all cephx authorization keys

    CLI Example:

        salt '*' sesceph.pool_add pool_name \
                '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.

    pg_num
        Default to 8

    pgp_num
        Default to pg_num

    pool_type
        can take values "replicated" or "erasure"

    erasure_code_profile
        Set the "erasure_code_profile"

    crush_ruleset
        Set the crush map rule set
    """
    m = model.model(**kwargs)
    u = mdl_updater.model_updater(m)
    u.hostname_refresh()
    try:
        u.defaults_refresh()
    except:
        return {}
    u.load_confg(m.cluster_name)
    u.mon_members_refresh()
    u.pool_list()
    u.pool_add(pool_name, **kwargs)
    return True
Beispiel #41
0
def pool_add(pool_name, **kwargs):
    """
    List all cephx authorization keys

    CLI Example:

        salt '*' sesceph.pool_add pool_name \\
                '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.

    pg_num
        Default to 8

    pgp_num
        Default to pg_num

    pool_type
        can take values "replicated" or "erasure"

    erasure_code_profile
        Set the "erasure_code_profile"

    crush_ruleset
        Set the crush map rule set
    """
    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:
        raise Error("Cant connect to cluster.")
    mur.pool_list()
    return mur.pool_add(pool_name, **kwargs)
Beispiel #42
0
def pool_add(pool_name, **kwargs):
    """
    List all cephx authorization keys

    CLI Example:

        salt '*' sesceph.pool_add pool_name \\
                '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.

    pg_num
        Default to 8

    pgp_num
        Default to pg_num

    pool_type
        can take values "replicated" or "erasure"

    erasure_code_profile
        Set the "erasure_code_profile"

    crush_ruleset
        Set the crush map rule set
    """
    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:
        raise Error("Cant connect to cluster.")
    mur.pool_list()
    return mur.pool_add(pool_name, **kwargs)
Beispiel #43
0
 def create(self, **kwargs):
     """
     Create 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 os.path.isfile(keyring_path):
         return _keying_read(keyring_path)
     try:
         tmpd = tempfile.mkdtemp()
         key_path = os.path.join(tmpd,"keyring")
         cmd_out = utils.execute_local_command(self.get_arguments_create(key_path))
         output = _keying_read(key_path)
     finally:
         shutil.rmtree(tmpd)
     return output
Beispiel #44
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 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)
Beispiel #46
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)
Beispiel #47
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