Example #1
0
def create_stack(sc, **params):
    master_profile_name = params.get('master_profile_name', 'master_profile')
    minion_profile_name = params.get('minion_profile_name', 'minion_profile')

    master_profile_spec = params.get('master_profile_spec', None)
    minion_profile_spec = params.get('minion_profile_spec', None)

    cluster_name = params.get('cluster_name', 'sur_cluster')

    # create master profile
    Profile.profile_create(sc, master_profile_name, 'os.heat.stack',
                           master_profile_spec, '')
    time.sleep(1)

    master_name = cluster_name + '_master'
    # create master
    Node.node_create(sc, master_name, None, master_profile_name)
    time.sleep(5)
    # wait master active
    wait_for_node_active(sc, master_name)

    master_stack_id = Node.node_show(sc, master_name)['node']['physical_id']
    LOG.info('Master create successfully! master_stack_id=%s' %
             master_stack_id)

    # create minion profile
    Profile.profile_create(sc, minion_profile_name, 'os.heat.stack',
                           minion_profile_spec, '')
    time.sleep(1)

    # create cluster
    Cluster.cluster_create(sc, cluster_name, minion_profile_name)
    time.sleep(1)

    # join master
    Node.node_join(sc, master_name, cluster_name)

    node_count = params.get('node_count', 1)

    # create minions
    for i in range(node_count):
        Node.node_create(sc, cluster_name + '_minion_' + str(i), cluster_name,
                         minion_profile_name)
        time.sleep(1)

    # attach scaling policy
    attach_policy(sc, **params)

    # create scale-out webhook
    wb = Webhook.cluster_webhook_create(sc, cluster_name + '_so_webhook',
                                        cluster_name, 'CLUSTER_SCALE_OUT', {})
    time.sleep(1)
    wb_url = wb['webhook']['url']
    LOG.info('webhook_url=%s' % wb_url)
def create_stack(sc, **params):
    master_profile_name = params.get('master_profile_name', 'master_profile')
    minion_profile_name = params.get('minion_profile_name', 'minion_profile')

    master_profile_spec = params.get('master_profile_spec', None)
    minion_profile_spec = params.get('minion_profile_spec', None)

    cluster_name = params.get('cluster_name', 'sur_cluster')

    # create master profile
    Profile.profile_create(sc, master_profile_name, 'os.heat.stack',
        master_profile_spec, '')
    time.sleep(1)

    master_name = cluster_name + '_master'
    # create master
    Node.node_create(sc, master_name, None, master_profile_name)
    time.sleep(5) 
    # wait master active
    wait_for_node_active(sc, master_name)

    master_stack_id = Node.node_show(sc, master_name)['node']['physical_id']
    LOG.info('Master create successfully! master_stack_id=%s' % master_stack_id)

    # create minion profile
    Profile.profile_create(sc, minion_profile_name, 'os.heat.stack',
        minion_profile_spec, '')
    time.sleep(1)

    # create cluster
    Cluster.cluster_create(sc, cluster_name, minion_profile_name)
    time.sleep(1)

    # join master
    Node.node_join(sc, master_name, cluster_name)

    node_count = params.get('node_count', 1)
    
    # create minions
    for i in range(node_count):
        Node.node_create(sc, cluster_name + '_minion_' + str(i), cluster_name,
            minion_profile_name)
        time.sleep(1)

    # attach scaling policy
    attach_policy(sc, **params)

    # create scale-out webhook
    wb = Webhook.cluster_webhook_create(sc, cluster_name + '_so_webhook',
        cluster_name, 'CLUSTER_SCALE_OUT', {})
    time.sleep(1)
    wb_url = wb['webhook']['url']
    LOG.info('webhook_url=%s' % wb_url)
def main():
    # parse arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("profile_name", help="the name of profile")
    parser.add_argument("spec_file", help="the location of spec file")
    parser.add_argument("cluster_name", help="the name of cluster")
    parser.add_argument("node_number", help="the number of nodes", type=int)
    args = parser.parse_args()

    LOG.info('Start build coreos cluster %s...' % (args.cluster_name))

    # setup client
    sc = SURClient().setup_client()

    # create profile
    LOG.info('Start create profile %s...' % (args.profile_name))
    result = Profile.profile_create(sc, args.profile_name, 'os.nova.server',
                                    args.spec_file, '1111')
    time.sleep(1)
    LOG.info(result)
    LOG.info('End create profile %s' % (args.profile_name))

    # create cluster
    LOG.info('Start create cluster %s...' % (args.cluster_name))
    result = Cluster.cluster_create(sc, args.cluster_name, args.profile_name)
    time.sleep(1)
    LOG.info(result)
    LOG.info('End create cluster %s' % (args.cluster_name))

    # create nodes
    for i in range(args.node_number):
        LOG.info('Creating node%s of cluster %s' % (i, args.cluster_name))
        result = Node.node_create(sc, '%s_node%s' % (args.cluster_name, i),
                                  args.cluster_name, args.profile_name)
        time.sleep(1)
        LOG.info(result)

    LOG.info('End build coreos cluster %s...' % (args.cluster_name))