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
def create_admin_user(self, user_id, displayname, cluster_name='ceph'): try: write_user_info = AddUserInfo() basic_io_structure = BasicIOInfoStructure() log.info('cluster name: %s' % cluster_name) cmd = 'radosgw-admin user create --uid=%s --display-name=%s --cluster %s' % ( user_id, displayname, 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_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(user_info) 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']) return user_details except subprocess.CalledProcessError as e: error = e.output + str(e.returncode) log.error(error) # traceback.print_exc(e) return False
def io_generator(fname, size, type='txt', op='create', **kwargs): finfo = {'name': fname, 'size': None, 'md5': None} # fname should include path, ex: /some/path/filename try: if op == 'create': log.info('in create') if type == 'txt': fcreate = 'base64 /dev/urandom | head -c %sM > %s' % (size, fname) created = utils.exec_shell_cmd(fcreate) finfo['md5'] = utils.get_md5(fname) finfo['size'] = os.stat(fname).st_size if created is False: raise RGWIOGenException("file %s creation error" % fname) return finfo if op == 'append': log.info('in modify or append') message = kwargs['message'] log.info('message to append: %s' % message) fappend = open(fname, 'a+') fappend.write(message) fappend.close() finfo['md5'] = utils.get_md5(fname) finfo['size'] = os.stat(fname).st_size return finfo except RGWIOGenException as e: log.error(e) return False
def resource_op(exec_info): log.info('resource Name: %s' % exec_info['resource']) obj = exec_info['obj'] resource = exec_info['resource'] result = None log.info('function tye: %s' % inspect.ismethod(getattr(obj, resource))) try: if inspect.ismethod(getattr(obj, resource)) or inspect.isfunction( getattr(obj, resource)): if exec_info.has_key("args"): log.info('in args') log.info('args_val: %s' % exec_info['args']) if exec_info['args'] is not None: result = getattr(obj, resource)(*tuple(exec_info['args'])) else: result = getattr(obj, resource)() if exec_info.has_key('kwargs'): log.info('in kwargs') log.info('kwargs value: %s' % exec_info['kwargs']) result = getattr(obj, resource)(**dict(exec_info['kwargs'])) else: log.info(' type is: %s' % type(getattr(obj, resource))) result = getattr(obj, resource) return result except (Exception, AttributeError) as e: log.error('Resource Execution failed') log.error(e) return False
def initialize(self, write_io_info=True): write_user_info = AddUserInfo() basic_io_structure = BasicIOInfoStructure() log.info('initializing NFS Ganesha') self.read_config() if self.rgw_user_info['user_id'] is None: log.info('rgw user does not exists') self.create_rgw_user() self.update_config() self.read_config() if write_io_info is True: log.info('user_id already exists, logging in for io_info') user_info = basic_io_structure.user( **{ 'user_id': self.rgw_user_info['user_id'], 'access_key': self.rgw_user_info['access_key'], 'secret_key': self.rgw_user_info['secret_key'] }) write_user_info.add_user_info(user_info) if not self.rgw_user_info['ganesha_config_exists']: log.info('ganesha config does not exists') self.create_ganesha_config() self.update_config() self.read_config() if not os.path.exists(self.rgw_user_info['nfs_mnt_point']): os.makedirs(self.rgw_user_info['nfs_mnt_point']) if not self.rgw_user_info['already_mounted']: try: log.info('mount needed') mounted = self.do_mount() if mounted is False: raise NFSGaneshaMountError("mount failed") self.rgw_user_info['already_mounted'] = True self.update_config() self.read_config() except NFSGaneshaMountError as e: log.error("mount failed") log.error(e) return False