Esempio n. 1
0
File: sell.py Progetto: shayanb/two1
def status(ctx, detail):
    """
Get status on running services.

\b
Get status on virtual machine and service.
$ 21 sell status
"""

    # pass Two1SellClient down in context
    manager = ctx.obj['manager']

    logger.info(click.style("\n21 SYSTEM STATUS", fg=cli_helpers.MENU_COLOR))
    logger.info(click.style(85*"-", fg=cli_helpers.MENU_COLOR))
    logger.info(click.style("NETWORKING", fg=cli_helpers.TITLE_COLOR))

    if isinstance(manager.machine, Two1MachineVirtual):
        if not cli_helpers.vm_running_check(manager.status_machine() == VmState.RUNNING,
                                            log_not_running=True):
            sys.exit()

    if not cli_helpers.zerotier_service_check(manager.status_networking(),
                                              log_not_running=True):
        sys.exit()

    if not cli_helpers.market_connected_check(manager.machine.host,
                                              log_not_running=True):
        sys.exit()

    logger.info(click.style("SERVER STATUS", fg=cli_helpers.TITLE_COLOR))

    if not cli_helpers.router_running_check(manager.status_router(),
                                            log_not_running=True):
        sys.exit()

    if not cli_helpers.payments_server_running_check(manager.composer.status_payments_server(),
                                                     log_not_running=True):
        sys.exit()

    service_status = manager.status_services(Two1Composer.GRID_SERVICES)
    for service in sorted(service_status):
        cli_helpers.print_str("%s" % service.title(),
                              [service_status[service]["message"]],
                              "TRUE" if service_status[service]["status"] == "Running" else "FALSE",
                              True if service_status[service]["status"] == "Running" else False)

    logger.info(click.style("TRANSACTION TOTALS", fg=cli_helpers.TITLE_COLOR))
    cli_helpers.service_earning_check(list(service_status.keys()), detail)

    if detail:
        logger.info(click.style("BALANCES", fg=cli_helpers.TITLE_COLOR))
        cli_helpers.service_balance_check(list(service_status.keys()))

    logger.info(click.style("EXAMPLE USAGE", fg=cli_helpers.TITLE_COLOR))
    cli_helpers.print_example_usage(list(service_status.keys()),
                                    manager.get_market_address(),
                                    manager.get_server_port())
Esempio n. 2
0
def status(ctx, detail):
    """
Get status on running services.

\b
Get status on virtual machine and service.
$ 21 sell status
"""

    # read Two1Manager from click context
    manager = ctx.obj['manager']

    logger.info(click.style(85*"-", fg=cli_helpers.MENU_COLOR))
    logger.info(click.style("21 SYSTEM STATUS", fg=cli_helpers.MENU_COLOR))
    logger.info(click.style(85*"-", fg=cli_helpers.MENU_COLOR))
    logger.info(click.style("NETWORKING", fg=cli_helpers.TITLE_COLOR))

    def running_hook(service_name):
        cli_helpers.print_str(service_name.capitalize(), ["Running"], "TRUE", True)

    def unknown_state_hook(service_name):
        cli_helpers.print_str(service_name.capitalize(), ["Unknown state"], "FALSE", False)

    if isinstance(manager.machine, Two1MachineVirtual):
        if not cli_helpers.vm_running_check(manager.status_machine() == VmState.RUNNING,
                                            log_not_running=True):
            sys.exit()

    cli_helpers.zerotier_service_check(manager.status_networking(), log_not_running=True)
    cli_helpers.market_connected_check(manager.machine.host, log_not_running=True)

    logger.info(click.style("SERVICES", fg=cli_helpers.TITLE_COLOR))
    try:
        manager.status_router(running_hook, unknown_state_hook)
    except:
        logger.info("Unable to get router status.", fg="magenta")
        sys.exit()
    try:
        manager.status_payments_server(running_hook, unknown_state_hook)
    except:
        logger.info("Unable to get payments server status.", fg="magenta")
        sys.exit()

    # fetch available services
    try:
        service_statuses = manager.status_services(manager.get_available_services())

        running_services = service_statuses['running']
        exited_services = service_statuses['exited']

        for running_service in running_services:
            cli_helpers.print_str(running_service.capitalize(), ["Running"], "TRUE", True)
        for exited_service in exited_services:
            cli_helpers.print_str(exited_service.captitalize(), ["Exited"], "FALSE", False)
    except:
        logger.info("Unable to get service status.", fg="magenta")
        sys.exit()

    if detail:
        logger.info(click.style("BALANCES", fg=cli_helpers.TITLE_COLOR))
        cli_helpers.service_balance_check()

    if len(running_services | exited_services) > 0:
        logger.info(click.style("TRANSACTION TOTALS", fg=cli_helpers.TITLE_COLOR))
        cli_helpers.service_earning_check(running_services | exited_services, detail)

    example_usages = cli_helpers.get_example_usage(running_services,
                                                   'http://' + manager.get_market_address(), manager.get_server_port())
    if len(example_usages) > 0:
        logger.info(click.style("EXAMPLE USAGE", fg=cli_helpers.TITLE_COLOR))
        for service, usage_string in example_usages.items():
            cli_helpers.print_str_no_label(service, [usage_string])

    # help tip message
    logger.info(click.style("\nTip: run ", fg=cli_helpers.PROMPT_COLOR) +
                click.style("`21 sell list`", bold=True, fg=cli_helpers.PROMPT_COLOR) +
                click.style(" to see available microservices you can sell.",
                            fg=cli_helpers.PROMPT_COLOR))
Esempio n. 3
0
def status(ctx, detail):
    """
Get status on running services.

\b
Get status on virtual machine and service.
$ 21 sell status
"""

    # read Two1Manager from click context
    manager = ctx.obj['manager']

    logger.info(click.style(85 * "-", fg=cli_helpers.MENU_COLOR))
    logger.info(click.style("21 SYSTEM STATUS", fg=cli_helpers.MENU_COLOR))
    logger.info(click.style(85 * "-", fg=cli_helpers.MENU_COLOR))
    logger.info(click.style("NETWORKING", fg=cli_helpers.TITLE_COLOR))

    def nonexistent_hook(service_name):
        cli_helpers.print_str(service_name.capitalize(), ["Nonexistent"],
                              "FALSE", False)

    def running_hook(service_name):
        cli_helpers.print_str(service_name.capitalize(), ["Running"], "TRUE",
                              True)

    def exited_hook(service_name):
        cli_helpers.print_str(service_name.captitalize(), ["Exited"], "FALSE",
                              False)

    def unknown_state_hook(service_name):
        cli_helpers.print_str(service_name.capitalize(), ["Unknown state"],
                              "FALSE", False)

    def composer_service_statuser(services):
        return manager.status_services(services, nonexistent_hook,
                                       running_hook, exited_hook,
                                       unknown_state_hook)

    def composer_router_statuser():
        return manager.status_router(running_hook, unknown_state_hook)

    def composer_payments_statuser():
        return manager.status_payments_server(running_hook, unknown_state_hook)

    if isinstance(manager.machine, Two1MachineVirtual):
        if not cli_helpers.vm_running_check(manager.status_machine()
                                            == VmState.RUNNING,
                                            log_not_running=True):
            sys.exit()

    cli_helpers.zerotier_service_check(manager.status_networking(),
                                       log_not_running=True)
    cli_helpers.market_connected_check(manager.machine.host,
                                       log_not_running=True)

    logger.info(click.style("SERVICES", fg=cli_helpers.TITLE_COLOR))
    try:
        composer_router_statuser()
    except Exception:
        logger.info("Unable to get router status.", fg="magenta")
        sys.exit()
    try:
        composer_payments_statuser()
    except Exception:
        logger.info("Unable to get payments server status.", fg="magenta")
        sys.exit()

    # fetch available services
    try:
        available_services = manager.list_available_services()
        composer_service_statuser(available_services)
    except Exception:
        logger.info("Unable to get service status.", fg="magenta")
        sys.exit()

    if detail:
        logger.info(click.style("BALANCES", fg=cli_helpers.TITLE_COLOR))
        cli_helpers.service_balance_check()

    logger.info(click.style("TRANSACTION TOTALS", fg=cli_helpers.TITLE_COLOR))
    cli_helpers.service_earning_check(available_services, detail)

    logger.info(click.style("EXAMPLE USAGE", fg=cli_helpers.TITLE_COLOR))
    cli_helpers.print_example_usage(available_services,
                                    'http://' + manager.get_market_address(),
                                    manager.get_server_port())

    # help tip message
    logger.info(
        click.style("\nTip: run ", fg=cli_helpers.PROMPT_COLOR) +
        click.style("`21 sell list`", bold=True, fg=cli_helpers.PROMPT_COLOR) +
        click.style(" to see available microservices you can sell.",
                    fg=cli_helpers.PROMPT_COLOR))