Exemplo n.º 1
0
    def create_subuser(self, tenant_name, user_id, cluster_name="ceph"):
        try:
            write_user_info = AddUserInfo()
            basic_io_structure = BasicIOInfoStructure()
            tenant_info = TenantInfo()
            keys = utils.gen_access_key_secret_key(user_id)
            cmd = 'radosgw-admin subuser create --uid=%s$%s --subuser=%s:swift --tenant=%s --access=full --cluster %s' \
                  % (tenant_name, user_id, user_id, tenant_name, cluster_name)
            log.info('cmd to execute:\n%s' % cmd)
            variable = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
            v = variable.stdout.read()
            v_as_json = json.loads(v)
            log.info(v_as_json)
            user_details = {}
            user_details['user_id'] = v_as_json['subusers'][0]['id']
            user_details['key'] = v_as_json['swift_keys'][0]['secret_key']
            user_details['tenant'], _ = user_details['user_id'].split('$')
            user_info = basic_io_structure.user(**{'user_id': user_details['user_id'],
                                                   'secret_key': user_details['key'],
                                                   'access_key': ' '})
            write_user_info.add_user_info(dict(user_info, **tenant_info.tenant(user_details['tenant'])))
            log.info('secret_key: %s' % user_details['key'])
            log.info('user_id: %s' % user_details['user_id'])
            log.info('tenant: %s' % user_details['tenant'])
            return user_details

        except subprocess.CalledProcessError as e:
            error = e.output + str(e.returncode)
            log.error(error)
            return False
Exemplo n.º 2
0
    def create_subuser(self, tenant_name, user_id, cluster_name="ceph"):
        """
        Function to create an subuser under a tenant.

        To create an swift-interface user under tenant.
        Parameters:
             tenant_name (char): Name of the tenant
             user_id (char): id of the user
             cluster_name (char): Name of the ceph cluster. defaults to 'ceph'
        """
        try:
            write_user_info = AddUserInfo()
            basic_io_structure = BasicIOInfoStructure()
            tenant_info = TenantInfo()
            keys = utils.gen_access_key_secret_key(user_id)
            cmd = (
                "radosgw-admin subuser create --uid=%s$%s --subuser=%s:swift --tenant=%s --access=full --cluster %s"
                % (tenant_name, user_id, user_id, tenant_name, cluster_name))
            log.info("cmd to execute:\n%s" % cmd)
            variable = subprocess.Popen(cmd,
                                        stdout=subprocess.PIPE,
                                        shell=True)
            v = variable.stdout.read()
            v_as_json = json.loads(v)
            log.info(v_as_json)
            user_details = {}
            user_details["user_id"] = v_as_json["subusers"][0]["id"]
            user_details["key"] = v_as_json["swift_keys"][0]["secret_key"]
            user_details["tenant"], _ = user_details["user_id"].split("$")
            user_info = basic_io_structure.user(
                **{
                    "user_id": user_details["user_id"],
                    "secret_key": user_details["key"],
                    "access_key": " ",
                })
            write_user_info.add_user_info(
                dict(user_info, **tenant_info.tenant(user_details["tenant"])))
            log.info("secret_key: %s" % user_details["key"])
            log.info("user_id: %s" % user_details["user_id"])
            log.info("tenant: %s" % user_details["tenant"])
            return user_details

        except subprocess.CalledProcessError as e:
            error = e.output + str(e.returncode)
            log.error(error)
            return False
Exemplo n.º 3
0
    def create_tenant_user(self,
                           tenant_name,
                           user_id,
                           displayname,
                           cluster_name="ceph"):
        """
        Function to create an user under a tenant.

        To create an S3-interface user under tenant.

        Parameters:
            tenant_name (char): Name of the tenant
            user_id (char): id of the user
            displayname (char): Display Name of the user
            cluster_name (char): Name of the ceph cluster. defaults to 'ceph'

        Returns:
            user details, which contain the following
                - user_id
                - display_name
                - access_key
                - secret_key
                - tenant
        """
        try:
            write_user_info = AddUserInfo()
            basic_io_structure = BasicIOInfoStructure()
            tenant_info = TenantInfo()
            keys = utils.gen_access_key_secret_key(user_id)
            cmd = ('radosgw-admin --tenant %s --uid %s --display-name "%s" '
                   "--access_key %s --secret %s user create --cluster %s" % (
                       tenant_name,
                       user_id,
                       displayname,
                       keys["access_key"],
                       keys["secret_key"],
                       cluster_name,
                   ))
            log.info("cmd to execute:\n%s" % cmd)
            variable = subprocess.Popen(cmd,
                                        stdout=subprocess.PIPE,
                                        shell=True)
            v = variable.stdout.read()
            v_as_json = json.loads(v)
            log.info(v_as_json)
            user_details = {}
            user_details["user_id"] = v_as_json["user_id"]
            user_details["display_name"] = v_as_json["display_name"]
            user_details["access_key"] = v_as_json["keys"][0]["access_key"]
            user_details["secret_key"] = v_as_json["keys"][0]["secret_key"]
            user_details["tenant"], user_details["user_id"] = user_details[
                "user_id"].split("$")
            user_info = basic_io_structure.user(
                **{
                    "user_id": user_details["user_id"],
                    "access_key": user_details["access_key"],
                    "secret_key": user_details["secret_key"],
                })
            write_user_info.add_user_info(
                dict(user_info, **tenant_info.tenant(user_details["tenant"])))
            log.info("access_key: %s" % user_details["access_key"])
            log.info("secret_key: %s" % user_details["secret_key"])
            log.info("user_id: %s" % user_details["user_id"])
            log.info("tenant: %s" % user_details["tenant"])
            return user_details

        except subprocess.CalledProcessError as e:
            error = e.output + str(e.returncode)
            log.error(error)
            return False