def load(self, name, logger=None): """ Loads a daemon from local storage. :param name: The name of the daemon to load. :param logger: a logger to be used by the daemon to log various operations. :return: A daemon instance. :rtype: cloudify_agent.api.pm.base.Daemon :raise CloudifyAgentNotFoundException: in case the daemon file does not exist. """ self.logger.debug('Loading daemon {0} from storage: {1}' .format(name, self.storage)) daemon_path = os.path.join( self.storage, '{0}.json'.format(name) ) if not os.path.exists(daemon_path): raise exceptions.DaemonNotFoundError(name) daemon_as_json = utils.json_load(daemon_path) self.logger.debug('Daemon {0} loaded: {1}'.format(name, json.dumps( daemon_as_json, indent=2))) process_management = daemon_as_json.pop('process_management') daemon = DaemonFactory._find_implementation(process_management) return daemon(logger=logger, **daemon_as_json)
def load_all(self, logger=None): """ Loads all daemons from local storage. :param logger: a logger to be used by the daemons to log various operations. :return: all daemons instances. :rtype: list """ if not os.path.exists(self.storage): return [] daemons = [] daemon_files = os.listdir(self.storage) for daemon_file in daemon_files: full_path = os.path.join( self.storage, daemon_file ) if full_path.endswith('json'): self.logger.debug('Loading daemon from: {0}'.format(full_path)) daemon_as_json = utils.json_load(full_path) process_management = daemon_as_json.pop('process_management') daemon = DaemonFactory._find_implementation(process_management) daemons.append(daemon(logger=logger, **daemon_as_json)) return daemons