def _restore(self, args, global_args, cmd): """Restore a dump""" self._output_formatter(global_args) env.service = args.service env.appname = args.appname action = ActionHandler(**cmd) prompt = 'Do you really want to restore the %s of %s?' % ( args.service, args.appname) resp = confirm(prompt=prompt, resp=False) if not resp: if not global_args.raw: self.out.info("Restore aborted.") sys.exit(1) try: # Lets queue the action action.queue() except HttpReturnError as e: self.out.error(e.args[1]) sys.exit(1) if action.response.status_code >= 500: sys.stderr.write(action.response.content) sys.stderr.flush() sys.exit(1) else: ret = { 'code': action.response.status_code, 'message': action.response.content, 'logbook': action.response.headers['Location'] } if global_args.raw: # we dont poll the logbook in raw mode. sys.stdout.write(json.dumps(ret)) sys.stdout.flush() return try: utils._poll_logbook(action.uuid) except KeyboardInterrupt: sys.exit(1) except HttpReturnError as e: #FIXME: push this into its own formatting method error = { "code": e.args[0], "message": e.args[1] } sys.stderr.write(json.dumps(error, indent=4)) sys.stderr.flush() sys.exit(1) sys.stdout.flush()
def _delete_resource(self, args, global_args): """Delete a resource.""" self._output_formatter(global_args) env.appname = args.appname env.service = args.service App = utils._get_document('App') app = App({'name': args.appname}) try: app.fetch(username=env.username, password=env.password) except HttpBackendError as e: self.out.error(json.loads(e.args[1])) sys.exit(1) if not args.service: document = app prompt = 'Do you really want to delete app %s?' % args.appname else: if not getattr(app, args.service): self.out.info("App %s has no %s." % (args.appname, args.service)) sys.exit(1) document = getattr(app, args.service) prompt = 'Do you really want to delete the %s of app %s?' % ( args.service, args.appname) resp = confirm(prompt=prompt, resp=False) if not resp: if not global_args.raw: self.out.info("Delete aborted.") sys.exit(1) try: document.delete(username=env.username, password=env.password) except HttpBackendError as e: self.out.error(json.loads(e.args[1])) sys.exit(1) if not global_args.raw: self.out.info("%s %s is deleted!" % ( args.service.capitalize() if args.service else 'App', args.appname))