Exemplo n.º 1
0
def main():
    print "Using configuration file: %s" % config.get("Internal", "last_location")
    print
    print "Welcome to DataStax' Cassandra Cluster Launcher!"
    print "    The easiest way to get Apache Cassandra up and running in Amazon's EC2"
    print "    in under 5 minutes!"
    print

    global cli_options
    cli_options = common.parse_cli_options(options_tree)

    # Required handle for log purposes and future shared EC2 purposes
    check_cascading_options("handle")

    # Prompt the user with any outstanding running clusters
    if (
        check_cascading_options("aws_access_key_id")[0] == '"'
        or check_cascading_options("aws_secret_access_key")[0] == '"'
        or check_cascading_options("aws_access_key_id")[0] == "'"
        or check_cascading_options("aws_secret_access_key")[0] == "'"
    ):
        sys.stderr.write("None of the configurations should be wrapped in quotes.\n")
        sys.stderr.write("    EC2:aws_access_key_id or EC2:aws_secret_access_key appears to be.\n")
        sys.exit(1)

    if not cli_options["CLI_noprompts"]:
        ec2.terminate_cluster(
            check_cascading_options("aws_access_key_id"),
            check_cascading_options("aws_secret_access_key"),
            config.get("EC2", "placement"),
            check_cascading_options("handle"),
            prompt_continuation=True,
        )

    start_time = time.time()

    # Get basic information for both Community and Enterprise clusters
    clustername = check_cascading_options("clustername")
    clustername = "'%s'" % clustername.replace("'", "")

    # Ensure totalnodes > 0
    ignore_command_line = False
    while True:
        totalnodes = check_cascading_options("totalnodes", int, ignore_command_line=ignore_command_line)
        if totalnodes > 0:
            break
        else:
            config.set("Cassandra", "totalnodes")
            ignore_command_line = True

    version = check_cascading_options("version", choices=["Community", "Enterprise"]).title()
    user_data = "--clustername %s --totalnodes %s --version %s" % (clustername, totalnodes, version)

    if version == "Enterprise":
        ignore_command_line = False
        while True:
            # Get additional information for Enterprise clusters
            username = check_cascading_options("username", ignore_command_line=ignore_command_line)
            password = check_cascading_options("password", password=True, ignore_command_line=ignore_command_line)

            print "Confirming credentials..."
            if confirm_authentication(username, password):
                break
            else:
                config.set("Cassandra", "username")
                config.set("Cassandra", "password")
                ignore_command_line = True
                print "Authentication to DataStax server failed. Please try again."

        # Check the number of Analytics Nodes that will launch
        ignore_command_line = False
        while True:
            analyticsnodes = check_cascading_options("analyticsnodes", int, ignore_command_line=ignore_command_line)
            if analyticsnodes <= totalnodes:
                break
            else:
                print "Overallocation of the chosen %d nodes" % (totalnodes)
                # Clear the previous cfsreplicationfactor
                config.set("Cassandra", "analyticsnodes")
                ignore_command_line = True

        # Check the number of Search Nodes that will launch
        ignore_command_line = False
        while True:
            searchnodes = check_cascading_options("searchnodes", int, ignore_command_line=ignore_command_line)
            if analyticsnodes + searchnodes <= totalnodes:
                break
            else:
                print "Overallocation of the chosen %d nodes" % (totalnodes)
                # Clear the previous cfsreplicationfactor
                config.set("Cassandra", "searchnodes")
                ignore_command_line = True

        user_data += " --username %s --password %s --analyticsnodes %s --searchnodes %s" % (
            username,
            password,
            analyticsnodes,
            searchnodes,
        )

        # If Hadoop enabled nodes are launching, check the CFS replication factor
        if analyticsnodes > 0:
            ignore_command_line = False
            while True:
                cfsreplicationfactor = check_cascading_options(
                    "cfsreplicationfactor", int, ignore_command_line=ignore_command_line
                )
                if 1 <= cfsreplicationfactor and cfsreplicationfactor <= analyticsnodes:
                    break
                else:
                    print "1 <= CFS Replication Factor <= Number of Analytics Nodes"
                    # Clear the previous cfsreplicationfactor
                    config.set("Cassandra", "cfsreplicationfactor")
                    ignore_command_line = True

            user_data += " --cfsreplicationfactor %s" % (cfsreplicationfactor)
        print

    # Included for the experimental DemoService that requires demoservice.py to always be running
    demotime = -1
    if config.get("Cassandra", "demo") == "True":
        print "Your configuration file is set to launch a demo cluster for a specified time."
        demotime = check_cascading_options("demotime", float)
        print "If the demo service is running, this cluster will live for %s hour(s)." % demotime
        print

    if check_cascading_options("installopscenter", optional=True) == "False":
        user_data += " --opscenter no"

    if check_cascading_options("release", optional=True):
        user_data += " --release %s" % check_cascading_options("release")

    opscenterinterface = 8888
    if check_cascading_options("opscenterinterface", optional=True):
        opscenterinterface = check_cascading_options("opscenterinterface")
        user_data += " --opscenterinterface %s" % opscenterinterface

    # DataStax AMI specific options and formatting
    image = check_cascading_options("datastax_ami", optional=True)
    if not image:
        image = "ami-6139e708"

    tag = "{0} - DataStaxAMI Time: {1} Size: {2}".format(
        check_cascading_options("handle"), time.strftime("%m-%d-%y %H:%M", time.localtime()), totalnodes
    )
    user = "******"

    # Launch the cluster
    instance_type = check_cascading_options(
        "instance_type", choices=["m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge"]
    )
    clusterinfo = ec2.create_cluster(
        check_cascading_options("aws_access_key_id"),
        check_cascading_options("aws_secret_access_key"),
        totalnodes,
        image,
        tag,
        KEY_PAIR,
        instance_type,
        config.get("EC2", "placement"),
        PEM_HOME,
        user_data,
        cli_options["CLI_noprompts"],
        opscenterinterface,
    )

    # Save IPs
    global private_ips
    global public_ips
    private_ips, public_ips, reservation = clusterinfo

    # Log clusterinfo
    running_log(reservation, demotime)

    if check_cascading_options("installopscenter", optional=True) != "False":
        # Print OpsCenter url
        print "OpsCenter Address:"
        print "http://%s:%s" % (public_ips[0], opscenterinterface)
        print "Note: You must wait 60 seconds after Cassandra becomes active to access OpsCenter."
        print

    start_priming(user)

    if version == "Enterprise":
        global seed_index
        realtimenodes = totalnodes - analyticsnodes - searchnodes
        seed_index = [0, realtimenodes, realtimenodes + analyticsnodes]
        seed_index.reverse()

    global node_types
    node_type = "c"
    node_types = {"c": [], "a": [], "s": []}

    print "Primed Connection Strings:"
    for i, node in enumerate(public_ips):
        if version == "Enterprise" and i in seed_index:
            if seed_index.index(i) == 0:
                print "Search (Solr) Nodes:"
                node_type = "s"
            if seed_index.index(i) == 1:
                print "Analytics (Hadoop) Nodes:"
                node_type = "a"
            if seed_index.index(i) == 2:
                print "Realtime (Cassandra) Nodes:"
                node_type = "c"

        node_types[node_type].append(i)
        print "    {0} -i {1} -o UserKnownHostsFile={2} {3}@{4}".format(
            config.get("System", "ssh"), PEM_FILE, HOST_FILE, user, node
        )
    print

    print "Installing DataStax SSH on the cluster..."
    install_datastax_ssh(user)

    if cli_options["CLI_qa"]:
        print "Uploading smoke tests on the cluster..."
        upload_smoke_tests(user)

    print "Setting up the hosts file for the cluster..."
    install_hosts_appending(user)

    print "Setting up datastax_s3_store and datastax_s3_restore capabilities..."
    setup_s3_store_and_restore(user)

    install_opsc_agents(user)

    end_time = int(time.time() - start_time)
    print "Total Elapsed Time: %s minutes %s seconds" % (end_time / 60, end_time % 60)
    print

    if not cli_options["CLI_noprompts"]:
        ec2.terminate_cluster(
            check_cascading_options("aws_access_key_id"),
            check_cascading_options("aws_secret_access_key"),
            config.get("EC2", "placement"),
            check_cascading_options("handle"),
        )
    else:
        # Ensure the agents have time to start
        # installing before exiting the program
        time.sleep(10)
Exemplo n.º 2
0
def main():
    print "Using configuration file: %s" % config.get('Internal', 'last_location')
    print
    print "Welcome to DataStax' Cassandra Cluster Launcher!"
    print "    The easiest way to get Apache Cassandra up and running in Amazon's EC2"
    print "    in under 5 minutes!"
    print

    global cli_options
    cli_options = common.parse_cli_options(options_tree)

    # Required handle for log purposes and future shared EC2 purposes
    check_cascading_options('handle')

    # Prompt the user with any outstanding running clusters
    if (check_cascading_options('aws_access_key_id')[0] == '"' or check_cascading_options('aws_secret_access_key')[0] == '"' or
        check_cascading_options('aws_access_key_id')[0] == "'" or check_cascading_options('aws_secret_access_key')[0] == "'"):
        sys.stderr.write("None of the configurations should be wrapped in quotes.\n")
        sys.stderr.write("    EC2:aws_access_key_id or EC2:aws_secret_access_key appears to be.\n")
        sys.exit(1)

    if not cli_options['CLI_noprompts']:
        ec2.terminate_cluster(check_cascading_options('aws_access_key_id'), check_cascading_options('aws_secret_access_key'), config.get('EC2', 'placement'), check_cascading_options('handle'), prompt_continuation=True)

    start_time = time.time()

    # Get basic information for both Community and Enterprise clusters
    clustername = check_cascading_options('clustername')
    clustername = "'%s'" % clustername.replace("'", "")

    # Ensure totalnodes > 0
    ignore_command_line = False
    while True:
        totalnodes = check_cascading_options('totalnodes', int, ignore_command_line=ignore_command_line)
        if totalnodes > 0:
            break
        else:
            config.set('Cassandra', 'totalnodes')
            ignore_command_line = True

    version = check_cascading_options('version', choices=['Community', 'Enterprise']).title()
    user_data = '--clustername %s --totalnodes %s --version %s' % (clustername, totalnodes, version)

    if version == 'Enterprise':
        ignore_command_line = False
        while True:
            # Get additional information for Enterprise clusters
            username = check_cascading_options('username', ignore_command_line=ignore_command_line)
            password = check_cascading_options('password', password=True, ignore_command_line=ignore_command_line)

            print "Confirming credentials..."
            if confirm_authentication(username, password):
                break
            else:
                config.set('Cassandra', 'username')
                config.set('Cassandra', 'password')
                ignore_command_line = True
                print "Authentication to DataStax server failed. Please try again."

        # Check the number of Analytics Nodes that will launch
        ignore_command_line = False
        while True:
            analyticsnodes = check_cascading_options('analyticsnodes', int, ignore_command_line=ignore_command_line)
            if analyticsnodes <= totalnodes:
                break
            else:
                print "Overallocation of the chosen %d nodes" % (totalnodes)
                # Clear the previous cfsreplicationfactor
                config.set('Cassandra', 'analyticsnodes')
                ignore_command_line = True

        # Check the number of Search Nodes that will launch
        ignore_command_line = False
        while True:
            searchnodes = check_cascading_options('searchnodes', int, ignore_command_line=ignore_command_line)
            if analyticsnodes + searchnodes <= totalnodes:
                break
            else:
                print "Overallocation of the chosen %d nodes" % (totalnodes)
                # Clear the previous cfsreplicationfactor
                config.set('Cassandra', 'searchnodes')
                ignore_command_line = True

        user_data += ' --username %s --password %s --analyticsnodes %s --searchnodes %s' % (username, password, analyticsnodes, searchnodes)

        # If Hadoop enabled nodes are launching, check the CFS replication factor
        if analyticsnodes > 0:
            ignore_command_line = False
            while True:
                cfsreplicationfactor = check_cascading_options('cfsreplicationfactor', int, ignore_command_line=ignore_command_line)
                if 1 <= cfsreplicationfactor and cfsreplicationfactor <= analyticsnodes:
                    break
                else:
                    print "1 <= CFS Replication Factor <= Number of Analytics Nodes"
                    # Clear the previous cfsreplicationfactor
                    config.set('Cassandra', 'cfsreplicationfactor')
                    ignore_command_line = True

            user_data += ' --cfsreplicationfactor %s' % (cfsreplicationfactor)
        print

    # Included for the experimental DemoService that requires demoservice.py to always be running
    demotime = -1
    if config.get('Cassandra', 'demo') == 'True':
        print "Your configuration file is set to launch a demo cluster for a specified time."
        demotime = check_cascading_options('demotime', float)
        print "If the demo service is running, this cluster will live for %s hour(s)." % demotime
        print

    if check_cascading_options('installopscenter', optional=True) == 'False':
        user_data += ' --opscenter no'

    if check_cascading_options('release', optional=True):
        user_data += ' --release %s' % check_cascading_options('release')

    opscenterinterface = 8888
    if check_cascading_options('opscenterinterface', optional=True):
        opscenterinterface = check_cascading_options('opscenterinterface')
        user_data += ' --opscenterinterface %s' % opscenterinterface

    # DataStax AMI specific options and formatting
    image = check_cascading_options('datastax_ami', optional=True)
    if not image:
        image = 'ami-fd23ec94'

    tag = '{0} - DataStaxAMI Time: {1} Size: {2}'.format(check_cascading_options('handle'), time.strftime("%m-%d-%y %H:%M", time.localtime()), totalnodes)
    user = '******'

    # Launch the cluster
    instance_type = check_cascading_options('instance_type', choices=['m1.large', 'm1.xlarge', 'm2.xlarge', 'm2.2xlarge', 'm2.4xlarge'])
    clusterinfo = ec2.create_cluster(check_cascading_options('aws_access_key_id'), check_cascading_options('aws_secret_access_key'),
                                    totalnodes, image, tag, KEY_PAIR,
                                    instance_type, config.get('EC2', 'placement'), PEM_HOME,
                                    user_data, cli_options['CLI_noprompts'], opscenterinterface)

    # Save IPs
    global private_ips
    global public_ips
    private_ips, public_ips, reservation = clusterinfo

    # Log clusterinfo
    running_log(reservation, demotime)

    if check_cascading_options('installopscenter', optional=True) != 'False':
        # Print OpsCenter url
        print "OpsCenter Address:"
        print "http://%s:%s" % (public_ips[0], opscenterinterface)
        print "Note: You must wait 60 seconds after Cassandra becomes active to access OpsCenter."
        print

    start_priming(user)

    if version == 'Enterprise':
        global seed_index
        realtimenodes = totalnodes - analyticsnodes - searchnodes
        seed_index = [0, realtimenodes, realtimenodes + analyticsnodes]
        seed_index.reverse()

    global node_types
    node_type = 'c'
    node_types = {'c': [], 'a':[], 's':[]}

    print 'Primed Connection Strings:'
    for i, node in enumerate(public_ips):
        if version == 'Enterprise' and i in seed_index:
            if seed_index.index(i) == 0:
                print 'Search (Solr) Nodes:'
                node_type = 's'
            if seed_index.index(i) == 1:
                print 'Analytics (Hadoop) Nodes:'
                node_type = 'a'
            if seed_index.index(i) == 2:
                print 'Realtime (Cassandra) Nodes:'
                node_type = 'c'

        node_types[node_type].append(i)
        print '    {0} -i {1} -o UserKnownHostsFile={2} {3}@{4}'.format(config.get('System', 'ssh'), PEM_FILE, HOST_FILE, user, node)
    print

    print 'Installing DataStax SSH on the cluster...'
    install_datastax_ssh(user)

    if cli_options['CLI_qa']:
        print 'Uploading smoke tests on the cluster...'
        upload_smoke_tests(user)

    print 'Setting up the hosts file for the cluster...'
    install_hosts_appending(user)

    install_opsc_agents(user)

    end_time = int(time.time() - start_time)
    print 'Total Elapsed Time: %s minutes %s seconds' % (end_time / 60, end_time % 60)
    print

    if not cli_options['CLI_noprompts']:
        ec2.terminate_cluster(check_cascading_options('aws_access_key_id'), check_cascading_options('aws_secret_access_key'), config.get('EC2', 'placement'), check_cascading_options('handle'))
    else:
        # Ensure the agents have time to start
        # installing before exiting the program
        time.sleep(10)
def main():
    print "Using configuration file: %s" % config.get('Internal', 'last_location')
    print
    print "Welcome to the Plain Image Launcher!"
    print "    The easiest way to interface with Amazon's EC2 and Rackspace's CloudServers"
    print "    and produce a plain instance (or cluster) in under 5 minutes!"
    print

    if not config.get('Shared', 'handle'):
        sys.stderr.write("Ensure {0} is appropriately set.\n".format(config.get('Internal', 'last_location')))
        sys.stderr.write("    'Shared:handle' is missing.\n")
        sys.exit(1)

    cloud = common.choose("Choose your Cloud Testing Host: ", clusterChoices.keys())

    # Ensure access keys are setup
    if cloud == 'EC2':
        if not config.get('EC2', 'aws_access_key_id') or not config.get('EC2', 'aws_secret_access_key'):
            sys.stderr.write("Ensure {0} is appropriately set.\n".format(config.get('Internal', 'last_location')))
            sys.stderr.write("    'EC2:aws_access_key_id|aws_secret_access_key' are missing.\n")
            sys.exit(1)
        if (config.get('EC2', 'aws_access_key_id')[0] == '"' or config.get('EC2', 'aws_secret_access_key')[0] == '"' or
            config.get('EC2', 'aws_access_key_id')[0] == "'" or config.get('EC2', 'aws_secret_access_key')[0] == "'"):
            sys.stderr.write("None of the configurations should be wrapped in quotes.\n")
            sys.stderr.write("    EC2:aws_access_key_id or EC2:aws_secret_access_key appears to be.\n")
            sys.exit(1)
    if cloud == 'Rackspace':
        if not config.get('Rax', 'rax_user') or not config.get('Rax', 'rax_api_key'):
            sys.stderr.write("Ensure {0} is appropriately set.\n".format(config.get('Internal', 'last_location')))
            sys.stderr.write("    'Rax:rax_user|rax_api_key' are missing.\n")
            sys.exit(1)
        if (config.get('Rax', 'rax_user')[0] == '"' or config.get('Rax', 'rax_api_key')[0] == '"' or
            config.get('Rax', 'rax_user')[0] == "'" or config.get('Rax', 'rax_api_key')[0] == "'"):
            sys.stderr.write("None of the configurations should be wrapped in quotes.\n")
            sys.stderr.write("    Rax:rax_user or Rax:rax_api_key appears to be.\n")
            sys.exit(1)

    action = common.choose("Choose your Cloud Command: ", ['Create', 'Destroy'])

    if action == 'Destroy':
        if cloud == 'EC2':
            ec2.terminate_cluster(config.get('EC2', 'aws_access_key_id'), config.get('EC2', 'aws_secret_access_key'), config.get('EC2', 'placement'), config.get('Shared', 'handle'))
        if cloud == 'Rackspace':
            rax.terminate_cluster(config.get('Rax', 'rax_user'), config.get('Rax', 'rax_api_key'), config.get('Shared', 'handle'))
        sys.exit()

    reservation_size = common.typed_input(int, "Choose your Cluster Size: ")
    print

    operating_system = common.choose("Choose your Testing Operating System: " , clusterChoices[cloud].keys())

    if cloud == 'EC2':
        if operating_system == '~Custom AMI':
            image = raw_input("Enter the AMI ID: ")
            user = raw_input("Enter the AMI's default user: "******"{3} - Time: {2} {0} Size: {1}".format(image, reservation_size, time.strftime("%m-%d-%y %H:%M", time.localtime()), config.get('Shared', 'handle'))
        else:
            provider = common.choose("Choose your Image Provider: ", clusterChoices[cloud][operating_system].keys())
            version = common.choose("Choose your Operating System Version: ", clusterChoices[cloud][operating_system][provider].keys())

            image = clusterChoices[cloud][operating_system][provider][version]['AMI']
            user = clusterChoices[cloud][operating_system][provider][version]['User']

            tag = "{5} - {0} Time: {4} {1} {2} Size: {3}".format(provider, operating_system, version, reservation_size, time.strftime("%m-%d-%y %H:%M", time.localtime()), config.get('Shared', 'handle'))

        user_data = raw_input("Enter EC2 user data: ")
        print

        instance_type = config.get('EC2', 'instance_type')
        if not instance_type:
            instance_type = common.choose('Choose your Instance Size:', ['m1.large', 'm1.xlarge', 'm2.xlarge', 'm2.2xlarge', 'm2.4xlarge'])

        clusterinfo = ec2.create_cluster(config.get('EC2', 'aws_access_key_id'), config.get('EC2', 'aws_secret_access_key'),
                                        reservation_size, image, tag, KEY_PAIR,
                                        instance_type, config.get('EC2', 'placement'), PEM_HOME, user_data)
        private_ips, public_ips, reservation = clusterinfo

        printConnections(user, private_ips, public_ips, PEM_FILE)
    
    if cloud == 'Rackspace':
        version = common.choose("Choose your Operating System Version: ", clusterChoices[cloud][operating_system].keys())

        image = clusterChoices[cloud][operating_system][version]['Image']
        tag = "{0} Time {4} {1} {2} Size {3}".format(config.get('Shared', 'handle'), operating_system, version, reservation_size, time.strftime("%m-%d-%y %H:%M", time.localtime())).replace(' ', '-').replace(':', '_').replace('.', '_')

        flavor_array = ['256', '512', '1GB', '2GB', '4GB', '8GB', '15.5GB', '30GB']
        flavor_choice = config.get('Rax', 'flavor')
        if not flavor_choice:
            flavor_choice = common.choose("Choose your Instance Size: ", flavor_array, sort=False)

        flavor_dict = {}
        for i, flavor in enumerate(flavor_array):
            flavor_dict[flavor] = i + 1
            flavor_dict[str(i + 1)] = i + 1 # For backward compliance
        flavor = flavor_dict[flavor_choice]

        private_ips, public_ips = rax.create_cluster(config.get('Rax', 'rax_user'), config.get('Rax', 'rax_api_key'),
                                                  reservation_size, image, tag, flavor)

        printConnections(config.get('Rax', 'user'), private_ips, public_ips)
def main():
    print "Using configuration file: %s" % config.get('Internal', 'last_location')
    print
    print "Welcome to DataStax' Cassandra Cluster Launcher!"
    print "    The easiest way to get Apache Cassandra up and running in Amazon's EC2"
    print "    in under 5 minutes!"
    print

    global cli_options
    cli_options = common.parse_cli_options(options_tree)

    # Required handle for log purposes and future shared EC2 purposes
    check_cascading_options('handle')

    # Prompt the user with any outstanding running clusters
    if (check_cascading_options('aws_access_key_id')[0] == '"' or check_cascading_options('aws_secret_access_key')[0] == '"' or
        check_cascading_options('aws_access_key_id')[0] == "'" or check_cascading_options('aws_secret_access_key')[0] == "'"):
        sys.stderr.write("None of the configurations should be wrapped in quotes.\n")
        sys.stderr.write("    EC2:aws_access_key_id or EC2:aws_secret_access_key appears to be.\n")
        sys.exit(1)

    if not cli_options['CLI_noprompts']:
        ec2.terminate_cluster(check_cascading_options('aws_access_key_id'), check_cascading_options('aws_secret_access_key'), config.get('EC2', 'placement'), check_cascading_options('handle'), prompt_continuation=True)

    start_time = time.time()

    # Get basic information for both Community and Enterprise clusters
    clustername = check_cascading_options('clustername')
    clustername = "'%s'" % clustername.replace("'", "")

    # Ensure totalnodes > 0
    ignore_command_line = False
    while True:
        totalnodes = check_cascading_options('totalnodes', int, ignore_command_line=ignore_command_line)
        if totalnodes > 0:
            break
        else:
            config.set('Cassandra', 'totalnodes')
            ignore_command_line = True

    version = check_cascading_options('version', choices=['Community', 'Enterprise']).title()
    user_data = '--clustername %s --totalnodes %s --version %s' % (clustername, totalnodes, version)

    if version == 'Enterprise':
        ignore_command_line = False
        while True:
            # Get additional information for Enterprise clusters
            username = check_cascading_options('username', ignore_command_line=ignore_command_line)
            password = check_cascading_options('password', password=True, ignore_command_line=ignore_command_line)

            print "Confirming credentials..."
            if confirm_authentication(username, password):
                break
            else:
                config.set('Cassandra', 'username')
                config.set('Cassandra', 'password')
                ignore_command_line = True
                print "Authentication to DataStax server failed. Please try again."

        # Check the number of Analytics Nodes that will launch
        ignore_command_line = False
        while True:
            analyticsnodes = check_cascading_options('analyticsnodes', int, ignore_command_line=ignore_command_line)
            if analyticsnodes <= totalnodes:
                break
            else:
                print "Overallocation of the chosen %d nodes" % (totalnodes)
                # Clear the previous cfsreplicationfactor
                config.set('Cassandra', 'analyticsnodes')
                ignore_command_line = True

        # Check the number of Search Nodes that will launch
        ignore_command_line = False
        while True:
            searchnodes = check_cascading_options('searchnodes', int, ignore_command_line=ignore_command_line)
            if analyticsnodes + searchnodes <= totalnodes:
                break
            else:
                print "Overallocation of the chosen %d nodes" % (totalnodes)
                # Clear the previous cfsreplicationfactor
                config.set('Cassandra', 'searchnodes')
                ignore_command_line = True

        user_data += ' --username %s --password %s --analyticsnodes %s --searchnodes %s' % (username, password, analyticsnodes, searchnodes)

        # If Hadoop enabled nodes are launching, check the CFS replication factor
        if analyticsnodes > 0:
            ignore_command_line = False
            while True:
                cfsreplicationfactor = check_cascading_options('cfsreplicationfactor', int, ignore_command_line=ignore_command_line)
                if 1 <= cfsreplicationfactor and cfsreplicationfactor <= analyticsnodes:
                    break
                else:
                    print "1 <= CFS Replication Factor <= Number of Analytics Nodes"
                    # Clear the previous cfsreplicationfactor
                    config.set('Cassandra', 'cfsreplicationfactor')
                    ignore_command_line = True

            user_data += ' --cfsreplicationfactor %s' % (cfsreplicationfactor)
        print

    # Included for the experimental DemoService that requires demoservice.py to always be running
    demotime = 0
    if config.get('Cassandra', 'demo') == 'True':
        print "Your configuration file is set to launch a demo cluster for a specified time."
        demotime = check_cascading_options('demotime', float)
        print "If demosercie is running, this cluster will live for %s seconds(s)." % demotime
        print

    if check_cascading_options('installopscenter', optional=True) == 'False':
        user_data += ' --opscenter no'

    if check_cascading_options('release', optional=True):
        user_data += ' --release %s' % check_cascading_options('release')

    opscenterinterface = 8888
    if check_cascading_options('opscenterinterface', optional=True):
        opscenterinterface = check_cascading_options('opscenterinterface')
        user_data += ' --opscenterinterface %s' % opscenterinterface

    # DataStax AMI specific options and formatting
    image = check_cascading_options('datastax_ami', optional=True)
    if not image:
        image = 'ami-6139e708'

    tag = '{0} - DataStaxAMI Time: {1} Size: {2}'.format(check_cascading_options('handle'), time.strftime("%m-%d-%y %H:%M", time.localtime()), totalnodes)
    user = '******'

    # Launch the cluster
    instance_type = check_cascading_options('instance_type', choices=['m1.large', 'm1.xlarge', 'm2.xlarge', 'm2.2xlarge', 'm2.4xlarge'])
    clusterinfo = ec2.create_cluster(check_cascading_options('aws_access_key_id'), check_cascading_options('aws_secret_access_key'),
                                    totalnodes, image, tag, KEY_PAIR,
                                    instance_type, config.get('EC2', 'placement'), PEM_HOME,
                                    user_data, cli_options['CLI_noprompts'], opscenterinterface)

    # Save IPs
    global private_ips
    global public_ips
    private_ips, public_ips, reservation = clusterinfo

    # Log clusterinfo
    if check_cascading_options('result_directory', optional=True):
        result_directory = check_cascading_options('result_directory')
        user_data += ' --result_directory %s' % result_directory

        launch_id = str(uuid.uuid4())
        if check_cascading_options('launch_id', optional=True):
            launch_id = check_cascading_options('launch_id')
            user_data += ' --launch_id %s' % launch_id

        if not os.path.exists(result_directory):
            os.mkdir(result_directory)

        tmpfile = os.path.join(result_directory, "%s.tmp" % launch_id)
        dstfile = os.path.join(result_directory, "%s.results" % launch_id)
        with open(tmpfile, 'w') as f:
            f.write("reservation_id=%s\n" % reservation.id)
            f.write("ttl_seconds=%s\n" % demotime)
            f.write("launch_time=%s\n" % time.time())
            if check_cascading_options('installopscenter', optional=True) != 'False':
                f.write("opsc_ip=%s\n" % public_ips[0])
                f.write("opsc_port=%s\n" % opscenterinterface)
        os.rename(tmpfile, dstfile)

    if check_cascading_options('installopscenter', optional=True) != 'False':
        # Print OpsCenter url
        url = "http://%s:%s" % (public_ips[0], opscenterinterface)
        print "OpsCenter URL: %s" % url
        print "Note: You must wait 60 seconds after Cassandra becomes active to access OpsCenter."
        print

        if cli_options['CLI_qa']:
            print "OPSCENTER_IP:%s" % public_ips[0]
            print "OPSCENTER_PORT:%s" % opscenterinterface

    start_priming(user)

    if version == 'Enterprise':
        global seed_index
        realtimenodes = totalnodes - analyticsnodes - searchnodes
        seed_index = [0, realtimenodes, realtimenodes + analyticsnodes]
        seed_index.reverse()

    global node_types
    node_type = 'c'
    node_types = {'c': [], 'a':[], 's':[]}

    print 'Primed Connection Strings:'
    for i, node in enumerate(public_ips):
        if version == 'Enterprise' and i in seed_index:
            if seed_index.index(i) == 0:
                print 'Search (Solr) Nodes:'
                node_type = 's'
            if seed_index.index(i) == 1:
                print 'Analytics (Hadoop) Nodes:'
                node_type = 'a'
            if seed_index.index(i) == 2:
                print 'Realtime (Cassandra) Nodes:'
                node_type = 'c'

        node_types[node_type].append(i)
        print '    {0} -i {1} -o UserKnownHostsFile={2} {3}@{4}'.format(config.get('System', 'ssh'), PEM_FILE, HOST_FILE, user, node)
    print

    print 'Installing DataStax SSH on the cluster...'
    install_datastax_ssh(user)

    if cli_options['CLI_qa']:
        print 'Uploading smoke tests on the cluster...'
        upload_smoke_tests(user)

    print 'Setting up the hosts file for the cluster...'
    install_hosts_appending(user)

    print 'Setting up datastax_s3_store and datastax_s3_restore capabilities...'
    setup_s3_store_and_restore(user)

    install_opsc_agents(user)

    end_time = int(time.time() - start_time)
    print 'Total Elapsed Time: %s minutes %s seconds' % (end_time / 60, end_time % 60)
    print

    if not cli_options['CLI_noprompts']:
        ec2.terminate_cluster(check_cascading_options('aws_access_key_id'), check_cascading_options('aws_secret_access_key'), config.get('EC2', 'placement'), check_cascading_options('handle'))
    else:
        # Ensure the agents have time to start
        # installing before exiting the program
        time.sleep(10)
def main():
    print "Using configuration file: %s" % config.get("Internal", "last_location")
    print
    print "Welcome to the Plain Image Launcher!"
    print "    The easiest way to interface with Amazon's EC2 and Rackspace's CloudServers"
    print "    and produce a plain instance (or cluster) in under 5 minutes!"
    print

    if not config.get("Shared", "handle"):
        sys.stderr.write("Ensure {0} is appropriately set.\n".format(config.get("Internal", "last_location")))
        sys.stderr.write("    'Shared:handle' is missing.\n")
        sys.exit(1)

    cloud = common.choose("Choose your Cloud Testing Host: ", clusterChoices.keys())

    # Ensure access keys are setup
    if cloud == "EC2":
        if not config.get("EC2", "aws_access_key_id") or not config.get("EC2", "aws_secret_access_key"):
            sys.stderr.write("Ensure {0} is appropriately set.\n".format(config.get("Internal", "last_location")))
            sys.stderr.write("    'EC2:aws_access_key_id|aws_secret_access_key' are missing.\n")
            sys.exit(1)
        if (
            config.get("EC2", "aws_access_key_id")[0] == '"'
            or config.get("EC2", "aws_secret_access_key")[0] == '"'
            or config.get("EC2", "aws_access_key_id")[0] == "'"
            or config.get("EC2", "aws_secret_access_key")[0] == "'"
        ):
            sys.stderr.write("None of the configurations should be wrapped in quotes.\n")
            sys.stderr.write("    EC2:aws_access_key_id or EC2:aws_secret_access_key appears to be.\n")
            sys.exit(1)
    if cloud == "Rackspace":
        if not config.get("Rax", "rax_user") or not config.get("Rax", "rax_api_key"):
            sys.stderr.write("Ensure {0} is appropriately set.\n".format(config.get("Internal", "last_location")))
            sys.stderr.write("    'Rax:rax_user|rax_api_key' are missing.\n")
            sys.exit(1)
        if (
            config.get("Rax", "rax_user")[0] == '"'
            or config.get("Rax", "rax_api_key")[0] == '"'
            or config.get("Rax", "rax_user")[0] == "'"
            or config.get("Rax", "rax_api_key")[0] == "'"
        ):
            sys.stderr.write("None of the configurations should be wrapped in quotes.\n")
            sys.stderr.write("    Rax:rax_user or Rax:rax_api_key appears to be.\n")
            sys.exit(1)

    action = common.choose("Choose your Cloud Command: ", ["Create", "Destroy"])

    if action == "Destroy":
        if cloud == "EC2":
            ec2.terminate_cluster(
                config.get("EC2", "aws_access_key_id"),
                config.get("EC2", "aws_secret_access_key"),
                config.get("EC2", "placement"),
                config.get("Shared", "handle"),
            )
        if cloud == "Rackspace":
            rax.terminate_cluster(
                config.get("Rax", "rax_user"), config.get("Rax", "rax_api_key"), config.get("Shared", "handle")
            )
        sys.exit()

    reservation_size = common.typed_input(int, "Choose your Cluster Size: ")
    print

    operating_system = common.choose("Choose your Testing Operating System: ", clusterChoices[cloud].keys())

    if cloud == "EC2":
        if operating_system == "~Custom AMI":
            image = raw_input("Enter the AMI ID: ")
            user = raw_input("Enter the AMI's default user: "******"{3} - Time: {2} {0} Size: {1}".format(
                image,
                reservation_size,
                time.strftime("%m-%d-%y %H:%M", time.localtime()),
                config.get("Shared", "handle"),
            )
        else:
            provider = common.choose("Choose your Image Provider: ", clusterChoices[cloud][operating_system].keys())
            version = common.choose(
                "Choose your Operating System Version: ", clusterChoices[cloud][operating_system][provider].keys()
            )

            image = clusterChoices[cloud][operating_system][provider][version]["AMI"]
            user = clusterChoices[cloud][operating_system][provider][version]["User"]

            tag = "{5} - {0} Time: {4} {1} {2} Size: {3}".format(
                provider,
                operating_system,
                version,
                reservation_size,
                time.strftime("%m-%d-%y %H:%M", time.localtime()),
                config.get("Shared", "handle"),
            )

        user_data = raw_input("Enter EC2 user data: ")
        print

        instance_type = config.get("EC2", "instance_type")
        if not instance_type:
            instance_type = common.choose(
                "Choose your Instance Size:", ["m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge"]
            )

        clusterinfo = ec2.create_cluster(
            config.get("EC2", "aws_access_key_id"),
            config.get("EC2", "aws_secret_access_key"),
            reservation_size,
            image,
            "imagelauncher",
            tag,
            KEY_PAIR,
            instance_type,
            config.get("EC2", "placement"),
            PEM_HOME,
            user_data,
        )
        private_ips, public_ips, reservation = clusterinfo

        printConnections(user, private_ips, public_ips, PEM_FILE)

    if cloud == "Rackspace":
        version = common.choose(
            "Choose your Operating System Version: ", clusterChoices[cloud][operating_system].keys()
        )

        image = clusterChoices[cloud][operating_system][version]["Image"]
        tag = (
            "{0} Time {4} {1} {2} Size {3}".format(
                config.get("Shared", "handle"),
                operating_system,
                version,
                reservation_size,
                time.strftime("%m-%d-%y %H:%M", time.localtime()),
            )
            .replace(" ", "-")
            .replace(":", "_")
            .replace(".", "_")
        )

        flavor_array = ["256", "512", "1GB", "2GB", "4GB", "8GB", "15.5GB", "30GB"]
        flavor_choice = config.get("Rax", "flavor")
        if not flavor_choice:
            flavor_choice = common.choose("Choose your Instance Size: ", flavor_array, sort=False)

        flavor_dict = {}
        for i, flavor in enumerate(flavor_array):
            flavor_dict[flavor] = i + 1
            flavor_dict[str(i + 1)] = i + 1  # For backward compliance
        flavor = flavor_dict[flavor_choice]

        private_ips, public_ips = rax.create_cluster(
            config.get("Rax", "rax_user"), config.get("Rax", "rax_api_key"), reservation_size, image, tag, flavor
        )

        printConnections(config.get("Rax", "user"), private_ips, public_ips)
Exemplo n.º 6
0
def main():
    print "Using configuration file: %s" % config.get('Internal',
                                                      'last_location')
    print
    print "Welcome to the Plain Image Launcher!"
    print "    The easiest way to interface with Amazon's EC2 and Rackspace's CloudServers"
    print "    and produce a plain instance (or cluster) in under 5 minutes!"
    print

    if not config.get('Shared', 'handle'):
        sys.stderr.write("Ensure {0} is appropriately set.\n".format(
            config.get('Internal', 'last_location')))
        sys.stderr.write("    'Shared:handle' is missing.\n")
        sys.exit(1)

    cloud = common.choose("Choose your Cloud Testing Host: ",
                          clusterChoices.keys())

    # Ensure access keys are setup
    if cloud == 'EC2':
        if not config.get('EC2', 'aws_access_key_id') or not config.get(
                'EC2', 'aws_secret_access_key'):
            sys.stderr.write("Ensure {0} is appropriately set.\n".format(
                config.get('Internal', 'last_location')))
            sys.stderr.write(
                "    'EC2:aws_access_key_id|aws_secret_access_key' are missing.\n"
            )
            sys.exit(1)
        if (config.get('EC2', 'aws_access_key_id')[0] == '"'
                or config.get('EC2', 'aws_secret_access_key')[0] == '"'
                or config.get('EC2', 'aws_access_key_id')[0] == "'"
                or config.get('EC2', 'aws_secret_access_key')[0] == "'"):
            sys.stderr.write(
                "None of the configurations should be wrapped in quotes.\n")
            sys.stderr.write(
                "    EC2:aws_access_key_id or EC2:aws_secret_access_key appears to be.\n"
            )
            sys.exit(1)
    if cloud == 'Rackspace':
        if not config.get('Rax', 'rax_user') or not config.get(
                'Rax', 'rax_api_key'):
            sys.stderr.write("Ensure {0} is appropriately set.\n".format(
                config.get('Internal', 'last_location')))
            sys.stderr.write("    'Rax:rax_user|rax_api_key' are missing.\n")
            sys.exit(1)
        if (config.get('Rax', 'rax_user')[0] == '"'
                or config.get('Rax', 'rax_api_key')[0] == '"'
                or config.get('Rax', 'rax_user')[0] == "'"
                or config.get('Rax', 'rax_api_key')[0] == "'"):
            sys.stderr.write(
                "None of the configurations should be wrapped in quotes.\n")
            sys.stderr.write(
                "    Rax:rax_user or Rax:rax_api_key appears to be.\n")
            sys.exit(1)

    action = common.choose("Choose your Cloud Command: ",
                           ['Create', 'Destroy'])

    if action == 'Destroy':
        if cloud == 'EC2':
            ec2.terminate_cluster(config.get('EC2', 'aws_access_key_id'),
                                  config.get('EC2', 'aws_secret_access_key'),
                                  config.get('EC2', 'placement'),
                                  config.get('Shared', 'handle'))
        if cloud == 'Rackspace':
            rax.terminate_cluster(config.get('Rax', 'rax_user'),
                                  config.get('Rax', 'rax_api_key'),
                                  config.get('Shared', 'handle'))
        sys.exit()

    reservation_size = common.typed_input(int, "Choose your Cluster Size: ")
    print

    operating_system = common.choose("Choose your Testing Operating System: ",
                                     clusterChoices[cloud].keys())

    if cloud == 'EC2':
        if operating_system == '~Custom AMI':
            image = raw_input("Enter the AMI ID: ")
            user = raw_input("Enter the AMI's default user: "******"{3} - Time: {2} {0} Size: {1}".format(
                image, reservation_size,
                time.strftime("%m-%d-%y %H:%M", time.localtime()),
                config.get('Shared', 'handle'))
        else:
            provider = common.choose(
                "Choose your Image Provider: ",
                clusterChoices[cloud][operating_system].keys())
            version = common.choose(
                "Choose your Operating System Version: ",
                clusterChoices[cloud][operating_system][provider].keys())

            image = clusterChoices[cloud][operating_system][provider][version][
                'AMI']
            user = clusterChoices[cloud][operating_system][provider][version][
                'User']

            tag = "{5} - {0} Time: {4} {1} {2} Size: {3}".format(
                provider, operating_system, version, reservation_size,
                time.strftime("%m-%d-%y %H:%M", time.localtime()),
                config.get('Shared', 'handle'))

        user_data = raw_input("Enter EC2 user data: ")
        print

        instance_type = config.get('EC2', 'instance_type')
        if not instance_type:
            instance_type = common.choose('Choose your Instance Size:', [
                'm1.large', 'm1.xlarge', 'm2.xlarge', 'm2.2xlarge',
                'm2.4xlarge'
            ])

        clusterinfo = ec2.create_cluster(
            config.get('EC2', 'aws_access_key_id'),
            config.get('EC2', 'aws_secret_access_key'),
            reservation_size, image, tag, KEY_PAIR, instance_type,
            config.get('EC2', 'placement'), PEM_HOME, user_data)
        private_ips, public_ips, reservation = clusterinfo

        printConnections(user, private_ips, public_ips, PEM_FILE)

    if cloud == 'Rackspace':
        version = common.choose("Choose your Operating System Version: ",
                                clusterChoices[cloud][operating_system].keys())

        image = clusterChoices[cloud][operating_system][version]['Image']
        tag = "{0} Time {4} {1} {2} Size {3}".format(
            config.get('Shared', 'handle'), operating_system,
            version, reservation_size,
            time.strftime("%m-%d-%y %H:%M", time.localtime())).replace(
                ' ', '-').replace(':', '_').replace('.', '_')

        flavor_array = [
            '256', '512', '1GB', '2GB', '4GB', '8GB', '15.5GB', '30GB'
        ]
        flavor_choice = config.get('Rax', 'flavor')
        if not flavor_choice:
            flavor_choice = common.choose("Choose your Instance Size: ",
                                          flavor_array,
                                          sort=False)

        flavor_dict = {}
        for i, flavor in enumerate(flavor_array):
            flavor_dict[flavor] = i + 1
            flavor_dict[str(i + 1)] = i + 1  # For backward compliance
        flavor = flavor_dict[flavor_choice]

        private_ips, public_ips = rax.create_cluster(
            config.get('Rax', 'rax_user'), config.get('Rax', 'rax_api_key'),
            reservation_size, image, tag, flavor)

        printConnections(config.get('Rax', 'user'), private_ips, public_ips)