示例#1
0
def add_host(ctx, env='Default', instance_type=None):
    '''Add Rancher host to cluster'''
    current_servers = terraform.count_resource(ctx, 'server')
    if current_servers == 0:
        print('')
        print('No Rancher server found. Server must')
        print('be created prior to adding hosts')
        return 1

    current_hosts = terraform.count_resource(ctx, 'host')
    hosts = current_hosts + 1

    url, image = rancher.get_agent_registration_data(ctx, env)
    if url is None:
        print('')
        print('No such environment: {0}'.format(env))
        return 1

    # target only this host (host count starts with 0)
    target = 'aws_instance.host[{0}]'.format(hosts - 1)

    terraform.apply(ctx,
                    hosts=hosts,
                    instance_type=instance_type,
                    agent_registration_url=url,
                    rancher_agent_image=image,
                    env=env,
                    target=target)
示例#2
0
def add_host(ctx, env='Default', instance_type=None):
    '''Add Rancher host to cluster'''
    current_servers = terraform.count_resource(ctx, 'server')
    if current_servers == 0:
        print('')
        print('No Rancher server found. Server must')
        print('be created prior to adding hosts')
        return 1

    current_hosts = terraform.count_resource(ctx, 'host')
    hosts = current_hosts + 1

    url, image = rancher.get_agent_registration_data(ctx, env)
    if url is None:
        print('')
        print('No such environment: {0}'.format(env))
        return 1

    # target only this host (host count starts with 0)
    target = 'aws_instance.host[{0}]'.format(hosts - 1)

    terraform.apply(
        ctx,
        hosts=hosts,
        instance_type=instance_type,
        agent_registration_url=url,
        rancher_agent_image=image,
        env=env,
        target=target
    )
示例#3
0
def list(ctx):
    '''Lists all server, host, and other active cluster resources'''
    servers = terraform.count_resource(ctx, res_type='server')
    hosts = terraform.count_resource(ctx, res_type='host')
    resources = terraform.count_resource(ctx, res_type='any')

    print('')
    print('Current Resources')
    print('-----------------')
    print('Servers:   {0}'.format(servers))
    print('Hosts:     {0}'.format(hosts))
    print('Resources: {0}'.format(resources))
    print('')
示例#4
0
def list(ctx):
    '''Lists all server, host, and other active cluster resources'''
    servers = terraform.count_resource(ctx, res_type='server')
    hosts = terraform.count_resource(ctx, res_type='host')
    resources = terraform.count_resource(ctx, res_type='any')

    print('')
    print('Current Resources')
    print('-----------------')
    print('Servers:   {0}'.format(servers))
    print('Hosts:     {0}'.format(hosts))
    print('Resources: {0}'.format(resources))
    print('')
示例#5
0
def remove_host(ctx, env='Default'):
    '''Remove a single host from the selected Rancher environment'''
    current_total_hosts = terraform.count_resource(ctx, 'host')
    new_total_hosts = current_total_hosts - 1
    hosts_in_env = terraform.get_hosts_by_environment(ctx, env)
    number_of_hosts_in_env = len(hosts_in_env)

    if number_of_hosts_in_env == 0:
        print()
        print('There are no hosts in environment: {0}'.format(env))
        print()
        return 1

    if new_total_hosts == 0:
        # This is a special case since terraform removes the host index when
        # there is only a single host instance
        target = ['aws_instance.host']
        terraform.destroy(ctx, target)
    else:
        # Grab the name of the last host in the list
        target_host = hosts_in_env.pop()
        # The part after the . is the host index
        target_host_index = target_host.rsplit('.', 1)[-1]
        # Target only that host
        target = ['aws_instance.host[{0}]'.format(target_host_index)]
        terraform.destroy(ctx, target)
示例#6
0
def remove_host(ctx, env='Default'):
    '''Remove a single host from the selected Rancher environment'''
    current_total_hosts = terraform.count_resource(ctx, 'host')
    new_total_hosts = current_total_hosts - 1
    hosts_in_env = terraform.get_hosts_by_environment(ctx, env)
    number_of_hosts_in_env = len(hosts_in_env)

    if number_of_hosts_in_env == 0:
        print()
        print('There are no hosts in environment: {0}'.format(env))
        print()
        return 1

    if new_total_hosts == 0:
        # This is a special case since terraform removes the host index when
        # there is only a single host instance
        target = ['aws_instance.host']
        terraform.destroy(ctx, target)
    else:
        # Grab the name of the last host in the list
        target_host = hosts_in_env.pop()
        # The part after the . is the host index
        target_host_index = target_host.rsplit('.', 1)[-1]
        # Target only that host
        target = ['aws_instance.host[{0}]'.format(target_host_index)]
        terraform.destroy(ctx, target)
示例#7
0
def add_servers(ctx, number, instance_type=None):
    '''Add Rancher servers to cluster'''
    current_servers = terraform.count_resource(ctx, 'server')
    servers_to_add = int(number)
    servers = current_servers + servers_to_add
    terraform.apply(ctx, servers=servers, instance_type=instance_type)

    session = rancher.create_rancher_http_session(ctx)
    rancher.wait_for_server(ctx, session)
示例#8
0
def add_servers(ctx, number, instance_type=None):
    '''Add Rancher servers to cluster'''
    current_servers = terraform.count_resource(ctx, 'server')
    servers_to_add = int(number)
    servers = current_servers + servers_to_add
    terraform.apply(ctx, servers=servers, instance_type=instance_type)

    session = rancher.create_rancher_http_session(ctx)
    rancher.wait_for_server(ctx, session)
示例#9
0
def build(ctx, hosts=None, servers=None, instance_type=None):
    '''Build cluster infrastructure and optionally add servers/hosts'''

    resource_count = terraform.count_resource(ctx, res_type='any')
    if resource_count is not 0:
        print('')
        print('Cluster already created!')
        list(ctx)
        return 1

    if servers is not None:
        add_servers(ctx, servers, instance_type=instance_type)

    if hosts is not None:
        for host in range(int(hosts)):
            add_host(ctx, instance_type=instance_type)
示例#10
0
def build(ctx, hosts=None, servers=None, instance_type=None):
    '''Build cluster infrastructure and optionally add servers/hosts'''

    resource_count = terraform.count_resource(ctx, res_type='any')
    if resource_count is not 0:
        print('')
        print('Cluster already created!')
        list(ctx)
        return 1

    if servers is not None:
        add_servers(ctx, servers, instance_type=instance_type)

    if hosts is not None:
        for host in range(int(hosts)):
            add_host(ctx, instance_type=instance_type)