Ejemplo n.º 1
0
def solrcloud_cli(cli_args):
    parser = build_args_parser()
    args = parser.parse_args(cli_args)

    if not args.config:
        args.config = os.path.expanduser(DEFAULT_CONF_FILE)

    if not os.path.exists(args.config):
        print('Configuration file does not exist:', args.config)
        parser.print_usage()
        return

    with open(args.config, 'rb') as fd:
        settings = yaml.load(fd)

    senza_wrapper = SenzaWrapper(args.senza_configuration)
    if args.region:
        senza_wrapper.set_region(args.region)

    for key, value in settings.items():
        senza_wrapper.add_parameter(key, value)

    if args.command in ['bootstrap']:
        controller = ClusterBootstrapController(
            base_url=settings['SolrBaseUrl'],
            stack_name=settings['ApplicationId'],
            sharding_level=args.sharding_level,
            replication_factor=args.replication_level,
            image_version=args.image_version,
            oauth_token=args.token,
            senza_wrapper=senza_wrapper)
    elif args.command in [
            'deploy', 'create-new-cluster', 'delete-old-cluster',
            'add-new-nodes', 'delete-old-nodes', 'switch'
    ]:
        controller = ClusterDeploymentController(
            base_url=settings['SolrBaseUrl'],
            stack_name=settings['ApplicationId'],
            image_version=args.image_version,
            oauth_token=args.token,
            senza_wrapper=senza_wrapper)
    elif args.command in ['delete']:
        controller = ClusterDeleteController(
            base_url=settings['SolrBaseUrl'],
            stack_name=settings['ApplicationId'],
            oauth_token=args.token,
            senza_wrapper=senza_wrapper)
    else:
        print('Unknown command:', args.command)
        parser.print_usage()
        return

    if args.command == 'bootstrap':
        controller.bootstrap_cluster()
    elif args.command == 'deploy':
        controller.deploy_new_version()
    elif args.command == 'delete':
        controller.delete_cluster()
    elif args.command == 'create-new-cluster':
        controller.create_cluster()
    elif args.command == 'delete-old-cluster':
        controller.delete_cluster()
    elif args.command == 'add-new-nodes':
        controller.add_new_nodes_to_cluster()
    elif args.command == 'delete-old-nodes':
        controller.delete_old_nodes_from_cluster()
    elif args.command == 'switch':
        controller.switch_traffic()
Ejemplo n.º 2
0
def solrcloud_cli(cli_args):
    parser = build_args_parser()
    args = parser.parse_args(cli_args)

    if not args.config:
        args.config = os.path.expanduser(DEFAULT_CONF_FILE)

    if not os.path.exists(args.config):
        print("Configuration file does not exist:", args.config)
        parser.print_usage()
        return

    with open(args.config, "rb") as fd:
        settings = yaml.load(fd)

    senza_wrapper = SenzaWrapper(args.senza_configuration)
    for key, value in settings.items():
        senza_wrapper.add_parameter(key, value)

    if args.command in ["bootstrap"]:
        controller = ClusterBootstrapController(
            base_url=settings["SolrBaseUrl"],
            stack_name=settings["ApplicationId"],
            sharding_level=args.sharding_level,
            replication_factor=args.replication_level,
            image_version=args.image_version,
            oauth_token=args.token,
            senza_wrapper=senza_wrapper,
        )
    elif args.command in [
        "deploy",
        "create-new-cluster",
        "delete-old-cluster",
        "add-new-nodes",
        "delete-old-nodes",
        "switch",
    ]:
        controller = ClusterDeploymentController(
            base_url=settings["SolrBaseUrl"],
            stack_name=settings["ApplicationId"],
            image_version=args.image_version,
            oauth_token=args.token,
            senza_wrapper=senza_wrapper,
        )
    elif args.command in ["delete"]:
        controller = ClusterDeleteController(
            base_url=settings["SolrBaseUrl"],
            stack_name=settings["ApplicationId"],
            oauth_token=args.token,
            senza_wrapper=senza_wrapper,
        )
    else:
        print("Unknown command:", args.command)
        parser.print_usage()
        return

    if args.command == "bootstrap":
        controller.bootstrap_cluster()
    elif args.command == "deploy":
        controller.deploy_new_version()
    elif args.command == "delete":
        controller.delete_cluster()
    elif args.command == "create-new-cluster":
        controller.create_cluster()
    elif args.command == "delete-old-cluster":
        controller.delete_cluster()
    elif args.command == "add-new-nodes":
        controller.add_new_nodes_to_cluster()
    elif args.command == "delete-old-nodes":
        controller.delete_old_nodes_from_cluster()
    elif args.command == "switch":
        controller.switch_traffic()