예제 #1
0
def do_login(args, env):
    """The "ravello login" command."""
    username = args.username or args.user
    password = args.password
    if username is None:
        console.writeln('Enter your Ravello credentials.')
    if username is None:
        username = console.prompt('Username: '******'Password: '******'Successfully logged in.')
    return 0
예제 #2
0
파일: main.py 프로젝트: ravello/testmill
def main(argv=None):
    """The "ravtest" main entry point."""
    if sys.platform.startswith('win'):
        console.error('Windows is not currently supported by "ravtest".\n'
                      'Please use the Fabric front-end.')
        error.exit(1)
    parser = create_parser()
    args = parse_args(parser, argv)
    create_environment(args)
    setup_logging()
    command = subcommands[args.subcmd][0]
    try:
        ret = command(args, env)
    except KeyboardInterrupt:
        console.complete_partial_line()
        console.writeln('Exiting at user request.')
        ret = error.EX_INTERRUPTED
    except SystemExit as e:
        console.complete_partial_line()
        if env.debug:
            console.error('SystemExit caught')
            lines = traceback.format_exception(*sys.exc_info())
            console.writeln_err('Raised from:')
            console.writeln_err(''.join(lines))
        ret = e[0]
    except Exception as e:
        console.complete_partial_line()
        console.error(str(e))
        if env.debug:
            lines = ['An uncaught exception occurred:']
            lines += traceback.format_exception(*sys.exc_info())
            console.writeln_err()
            console.writeln_err(''.join(lines))
            console.writeln_err('Environment: {!r}'.format(env))
        ret = getattr(e, 'exitstatus', error.EX_SOFTWARE)
    return ret
예제 #3
0
파일: tasks.py 프로젝트: ravello/testmill
def show_output(task):
    """Show output for a completed task."""
    if task.interactive:
        return
    if task.quiet and not env.debug:
        return
    output = task.stdout
    if (not output or output.isspace()) and not env.debug:
        return
    console.writeln('\n== Output for task `{0}` on VM `{1}`:\n',
                    task.name, env.vm['name'])
    console.writeln(output)
    console.writeln()
예제 #4
0
def do_ps(args, env):
    """The "ravello ps" command."""
    with env.let(quiet=True):
        login.default_login()
        pubkey = keypair.default_keypair()
        manif = manifest.default_manifest(required=False)

    if manif is None and not args.all:
        error.raise_error('Project manifest ({0}) not found.\n'
                          "Use 'ravtest ps -a' to list all applications.",
                          manifest.manifest_name())
    if args.all:
        project = None
    else:
        project = manif['project']['name']
        console.info('Project name is `{0}`.', project)
    
    if args.blueprint:
        apps = cache.find_blueprints(project)
        what = 'blueprint'
    else:
        apps = cache.find_applications(project)
        what = 'application'

    apps = sorted(apps, key=lambda app: app['name'])
    objs = inflect.plural_noun(what)
    console.writeln('Currently available {0}:\n', objs)

    current_project = None
    for app in apps:
        parts = app['name'].split(':')
        if parts[0] != project and not args.all:
            continue
        if args.all and current_project != parts[0]:
            console.writeln("== Project: `{0}`", parts[0])
            current_project = parts[0]
        if args.full and not args.blueprint:
            app = cache.get_application(app['id'])

        cloud = app.get('cloud')
        region = app.get('regionName')
        started = app.get('totalStartedVms')
        publish_time = app.get('publishStartTime')
        creation_time = app.get('creationTime')
        created = publish_time or creation_time
        if created:
            now = time.time()
            created = util.format_timedelta(now - created/1000)
            created = '{0} ago'.format(created)
        else:
            created = ''
        if args.full and not args.blueprint:
            vms = [ vm['name'] for vm in application.get_vms(app) ]
            vms = '`{0}`'.format('`, `'.join(vms))
            state = application.get_application_state(app)
        else:
            state = app.get('state') or ''

        console.writeln('=== {0}: `{1}:{2}`', what.title(), parts[1], parts[2])
        what2 = inflect.plural_noun('VM', started)
        if state:
            console.writeln('    state: {0}', state)
        if started is not None:
            console.writeln('    {0} {1} running', started, what2)
        if cloud is not None:
            console.writeln('    published to {0}/{1}', cloud, region)
        if created:
            console.writeln('    created: {0}', created)
        if args.full and not args.blueprint:
            console.writeln('    VMs: {0}', vms)
        console.writeln()

    return error.EX_OK