예제 #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()
예제 #2
0
파일: tests.py 프로젝트: 30loops/libthirty
    def test_uri_construction(self):
        action = ActionHandler(action='deploy')
        env.label = 'app'
        env.appname = "thirtyblog"
        env.account = '30loops'

        expected = "https://api.30loops.net/0.9/30loops/apps/thirtyblog"

        eq_(expected, action.uri())
예제 #3
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()
예제 #4
0
def deploy(args):
    """Deploy an app resource."""
    cmd = {'action': 'deploy', 'options': {}}
    cmd['options']['environment'] = args.environment

    env.account = args.account
    env.label = 'app'
    env.resource = args.name
    env.username = args.username
    env.password = args.password

    action = ActionHandler(**cmd)

    try:
        # Lets queue the action
        action.queue()
    except HttpReturnError as e:
        #FIXME: push this into its own formatting method
        error = {
                "code": e[0],
                "message": e[1]
                }
        sys.stderr.write(json.dumps(error, indent=4))
        sys.stderr.flush()
        sys.exit(1)

    if action.response.status_code >= 500:
        sys.stderr.write(action.response.content)
        sys.stderr.flush()
        sys.exit(1)

    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[0],
                "message": e[1]
                }
        sys.stderr.write(json.dumps(error, indent=4))
        sys.stderr.flush()
        sys.exit(1)

    sys.stdout.flush()
예제 #5
0
파일: tests.py 프로젝트: 30loops/libthirty
    def test_queue_action(self):
        env.label = 'app'
        env.account = '30loops'
        env.resource = 'thirtyblog'

        response = Mock()
        response.status_code = 202
        response.headers = {'Location': 'http://location/uuid'}

        self.mock_requests.request.return_value = response

        action = ActionHandler('deploy', {})
        action.queue()

        self.mock_requests.request.assert_called_once_with(
                url=action.uri(), method='post',
                verify='/path/ssl/StartSSL_CA.pem',
                data=json.dumps({'action': 'deploy', 'options': {}})
                )