def test_list_hosts(self): expected = dict(hosts=[dict(name=self.testhost)]) obj = Actions(self.cli, db_engine=self.engine, db_session=self.session) ret = obj.list_hosts() del (ret['hosts'][0]['created']) self.assertEqual(ret, expected)
def main(): opts = Config().docopt_convert(docopt.docopt(__doc__)) Syslog.logger = Syslog(opts) obj = Actions(opts) result = {} status = 'ok' if (opts['list-hosts']): result = obj.list_hosts() elif (opts['list-savesets']): result = obj.list_savesets() elif (opts['list-volumes']): result = obj.list_volumes() elif (opts['verify']): result = obj.verify(opts['verify']) elif (opts['version']): result = dict(version=[dict(name='secondshot %s' % __version__)]) elif (opts['action'] == 'start'): result = obj.start(obj.hosts, obj.volume) status = result['start']['status'] elif (opts['action'] == 'rotate'): result = obj.rotate(opts['interval']) elif (opts['action'] == 'schema-update'): result = obj.schema_update() status = result['status'] else: sys.exit('Unknown action: %s' % opts['action']) if (opts['format'] == 'json'): sys.stdout.write(json.dumps(result) + '\n') elif (opts['format'] == 'text' and result and next(iter(result.keys())) in ['hosts', 'savesets', 'schema-update', 'version', 'volumes']): for item in result[next(iter(result.keys()))]: sys.stdout.write(item['name'] + '\n') if (status != 'ok'): exit(1)