Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
    def _run_command(self, args, global_args, cmd):
        """Run an arbitrary command"""

        self._output_formatter(global_args)

        if args.service:
            env.service = args.service
        env.appname = args.appname

        action = ActionHandler(**cmd)

        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()