def pdict(): for profile, opt_dict in mc.list_profiles( self.base_directory).iteritems(): path_ = os.path.join(self.base_directory, 'profiles', profile) run_as = os.path.join(path_, opt_dict['run_as']) save_as = os.path.join(path_, opt_dict['save_as']) profile_info = opt_dict profile_info['profile'] = profile if 'url' in profile_info: profile_info['version'] = mc.server_version( run_as, profile_info['url']) else: profile_info['url'] = '' profile_info['version'] = '' try: profile_info['save_as_md5'] = mc._md5sum(save_as) profile_info['save_as_mtime'] = mc._mtime(save_as) except IOError: profile_info['save_as_md5'] = '' profile_info['save_as_mtime'] = '' try: profile_info['run_as_mtime'] = mc._mtime(run_as) profile_info['run_as_md5'] = mc._md5sum(run_as) except IOError: profile_info['run_as_mtime'] = '' profile_info['run_as_md5'] = '' yield profile_info
def pdict(): for profile, opt_dict in mc.list_profiles(self.base_directory).iteritems(): path_ = os.path.join(self.base_directory, 'profiles', profile) run_as = os.path.join(path_,opt_dict['run_as']) save_as = os.path.join(path_,opt_dict['save_as']) profile_info = opt_dict profile_info['profile'] = profile if 'url' in profile_info: profile_info['version'] = mc.server_version(run_as, profile_info['url']) else: profile_info['url'] = '' profile_info['version'] = '' try: profile_info['save_as_md5'] = mc._md5sum(save_as) profile_info['save_as_mtime'] = mc._mtime(save_as) except IOError: profile_info['save_as_md5'] = '' profile_info['save_as_mtime'] = '' try: profile_info['run_as_mtime'] = mc._mtime(run_as) profile_info['run_as_md5'] = mc._md5sum(run_as) except IOError: profile_info['run_as_mtime'] = '' profile_info['run_as_md5'] = '' yield profile_info
def pdict(): for profile, opt_dict in mc.list_profiles( self.base_directory).iteritems(): path_ = os.path.join(self.base_directory, 'profiles', profile) profile_info = opt_dict profile_info['profile'] = profile try: profile_info['save_as_md5'] = mc._md5sum( os.path.join(path_, opt_dict['save_as'])) profile_info['save_as_mtime'] = mc._mtime( os.path.join(path_, opt_dict['save_as'])) except IOError: profile_info['save_as_md5'] = '' profile_info['save_as_mtime'] = '' try: profile_info['run_as_mtime'] = mc._mtime( os.path.join(path_, opt_dict['run_as'])) profile_info['run_as_md5'] = mc._md5sum( os.path.join(path_, opt_dict['run_as'])) except IOError: profile_info['run_as_mtime'] = '' profile_info['run_as_md5'] = '' yield profile_info
def host(self, **raw_args): args = {k: str(v) for k, v in raw_args.iteritems()} command = args.pop('cmd') retval = None response = {'result': None, 'cmd': command, 'payload': None} try: if command == 'define_profile': mc.has_ownership( self.login, os.path.join(self.base_directory, mc.DEFAULT_PATHS['profiles'], 'profile.config')) from json import loads from urllib import unquote definition_unicode = loads(args['profile_dict']) definition = { str(k): str(v) for k, v in definition_unicode.iteritems() } try: definition['url'] = unquote(definition['url']) except KeyError: pass if definition['name'] in mc.list_profiles( self.base_directory).keys(): raise KeyError('Profiles may not be modified once created') instance = mc('throwaway', None, self.base_directory) retval = instance.define_profile(definition) elif command == 'update_profile': mc.has_ownership( self.login, os.path.join(self.base_directory, mc.DEFAULT_PATHS['profiles'], 'profile.config')) instance = mc('throwaway', None, self.base_directory) retval = instance.update_profile(**args) elif command == 'remove_profile': for i in mc.list_servers(self.base_directory): if mc(i, None, self.base_directory).profile == args['profile']: raise KeyError( 'May not remove profiles in use by 1 or more servers' ) instance = mc('throwaway', None, self.base_directory) retval = instance.remove_profile(**args) elif command == 'stock_profile': from stock_profiles import STOCK_PROFILES profile = iter([ i for i in STOCK_PROFILES if i['name'] == args['profile'] ]).next() mc('throwaway', None, self.base_directory).define_profile(profile) retval = '%s profile created' % profile['name'] elif command == 'modify_profile': mc('throwaway', None, self.base_directory).modify_profile(args['option'], args['value'], args['section']) retval = '%s profile updated' % args['section'] elif command in self.METHODS: import inspect try: if 'base_directory' in inspect.getargspec( getattr(mc, command)).args: retval = getattr(mc, command)( base_directory=init_args['base_directory'], **args) else: retval = getattr(mc, command)(**args) except TypeError as ex: raise RuntimeError(ex.message) else: raise RuntimeWarning( 'Command not found: should this be to a server?') except (RuntimeError, KeyError, OSError, NotImplementedError) as ex: response['result'] = 'error' retval = ex.message except CalledProcessError as ex: response['result'] = 'error' retval = ex.output except RuntimeWarning as ex: response['result'] = 'warning' retval = ex.message else: response['result'] = 'success' response['payload'] = to_jsonable_type(retval) return response
def host(self, **raw_args): args = {k:str(v) for k,v in raw_args.iteritems()} command = args.pop('cmd') retval = None response = { 'result': None, 'cmd': command, 'payload': None } try: if command == 'define_profile': mc.has_ownership(self.login, os.path.join(self.base_directory, mc.DEFAULT_PATHS['profiles'], 'profile.config')) from json import loads from urllib import unquote definition_unicode = loads(args['profile_dict']) definition = {str(k):str(v) for k,v in definition_unicode.iteritems()} try: definition['url'] = unquote(definition['url']) except KeyError: pass if definition['name'] in mc.list_profiles(self.base_directory).keys(): raise KeyError('Profiles may not be modified once created') instance = mc('throwaway', None, self.base_directory) retval = instance.define_profile(definition) elif command == 'update_profile': mc.has_ownership(self.login, os.path.join(self.base_directory, mc.DEFAULT_PATHS['profiles'], 'profile.config')) instance = mc('throwaway', None, self.base_directory) retval = instance.update_profile(**args) elif command == 'remove_profile': for i in mc.list_servers(self.base_directory): if mc(i, None, self.base_directory).profile == args['profile']: raise KeyError('May not remove profiles in use by 1 or more servers') instance = mc('throwaway', None, self.base_directory) retval = instance.remove_profile(**args) elif command == 'stock_profile': from stock_profiles import STOCK_PROFILES profile = iter([i for i in STOCK_PROFILES if i['name'] == args['profile']]).next() mc('throwaway', None, self.base_directory).define_profile(profile) retval = '%s profile created' % profile['name'] elif command == 'modify_profile': mc('throwaway', None, self.base_directory).modify_profile(args['option'],args['value'],args['section']) retval = '%s profile updated' % args['section'] elif command in self.METHODS: import inspect try: if 'base_directory' in inspect.getargspec(getattr(mc, command)).args: retval = getattr(mc, command)(base_directory=init_args['base_directory'], **args) else: retval = getattr(mc, command)(**args) except TypeError as ex: raise RuntimeError(ex.message) else: raise RuntimeWarning('Command not found: should this be to a server?') except (RuntimeError, KeyError, OSError, NotImplementedError) as ex: response['result'] = 'error' retval = ex.message except CalledProcessError as ex: response['result'] = 'error' retval = ex.output except RuntimeWarning as ex: response['result'] = 'warning' retval = ex.message else: response['result'] = 'success' response['payload'] = to_jsonable_type(retval) return response