Ejemplo n.º 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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def attach_policy(sc, **params):
    cluster_name = params.get('cluster_name', 'sur_cluster')
    
    # create scaling policy
    si_policy_name = cluster_name + '_si_policy'
    so_policy_name = cluster_name + '_so_policy'

    si_policy_spec = params.get('si_policy_spec', None)
    so_policy_spec = params.get('so_policy_spec', None)

    SIPolicy.policy_create(sc, si_policy_name, si_policy_spec)
    SOPolicy.policy_create(sc, so_policy_name, so_policy_spec)
    time.sleep(1)

    Cluster.cluster_policy_attach(sc, cluster_name, si_policy_name)
    Cluster.cluster_policy_attach(sc, cluster_name, so_policy_name)
Ejemplo n.º 4
0
def attach_policy(sc, **params):
    cluster_name = params.get('cluster_name', 'sur_cluster')

    # create scaling policy
    si_policy_name = cluster_name + '_si_policy'
    so_policy_name = cluster_name + '_so_policy'

    si_policy_spec = params.get('si_policy_spec', None)
    so_policy_spec = params.get('so_policy_spec', None)

    SIPolicy.policy_create(sc, si_policy_name, si_policy_spec)
    SOPolicy.policy_create(sc, so_policy_name, so_policy_spec)
    time.sleep(1)

    Cluster.cluster_policy_attach(sc, cluster_name, si_policy_name)
    Cluster.cluster_policy_attach(sc, cluster_name, so_policy_name)
Ejemplo n.º 5
0
def main():
    # setup senlin client
    sc = SURClient('localhost', '8778', '1').setup_client()

    # create loadbalancing policy
#     LBPolicy.policy_create(sc, 'coreos_lb', 'specs/lb_policy_lbaas.spec')

    # attach loadbalancing policy
#     Cluster.cluster_policy_attach(sc, 'coreos_cluster', 'coreos_lb')

    #create scaling policy
    SIPolicy.policy_create(sc, 'coreos_si', 'specs/scaling_policy.spec')
    SOPolicy.policy_create(sc, 'coreos_so', 'specs/scaling_policy.spec')
    time.sleep(1)

    # attach scaling policy
    Cluster.cluster_policy_attach(sc, 'coreos_cluster', 'coreos_si')
    Cluster.cluster_policy_attach(sc, 'coreos_cluster', 'coreos_so')
    time.sleep(1)

    # create scale-out webhook
    wb = Webhook.cluster_webhook_create(sc, 'so_webhook', 'coreos_cluster',
                                        'CLUSTER_SCALE_OUT', {})
    wb_url = wb['webhook']['url']
    
    # setup ceilometer client
    cc = SURClient('localhost', '8777', '2', 'ceilometer').setup_client()
    
    # create ceilometer threshold alarm
    alarm_args = {
        'name': 'test_alarm',
        'meter_name': 'cpu_util',
        'threshold': 50.0,
        'state': 'alarm',
        'severity': 'moderate',
        'enabled': True,
        'repeat_actions': False,
        'alarm_actions': [wb_url],
        'comparison_operator': 'gt',
        'statistic': 'max'
    }
    Alarm.alarm_threshold_create(cc, **alarm_args)
Ejemplo n.º 6
0
def main():
    # setup senlin client
    sc = SURClient('localhost', '8778', '1').setup_client()

    # create loadbalancing policy
    #     LBPolicy.policy_create(sc, 'coreos_lb', 'specs/lb_policy_lbaas.spec')

    # attach loadbalancing policy
    #     Cluster.cluster_policy_attach(sc, 'coreos_cluster', 'coreos_lb')

    #create scaling policy
    SIPolicy.policy_create(sc, 'coreos_si', 'specs/scaling_policy.spec')
    SOPolicy.policy_create(sc, 'coreos_so', 'specs/scaling_policy.spec')
    time.sleep(1)

    # attach scaling policy
    Cluster.cluster_policy_attach(sc, 'coreos_cluster', 'coreos_si')
    Cluster.cluster_policy_attach(sc, 'coreos_cluster', 'coreos_so')
    time.sleep(1)

    # create scale-out webhook
    wb = Webhook.cluster_webhook_create(sc, 'so_webhook', 'coreos_cluster',
                                        'CLUSTER_SCALE_OUT', {})
    wb_url = wb['webhook']['url']

    # setup ceilometer client
    cc = SURClient('localhost', '8777', '2', 'ceilometer').setup_client()

    # create ceilometer threshold alarm
    alarm_args = {
        'name': 'test_alarm',
        'meter_name': 'cpu_util',
        'threshold': 50.0,
        'state': 'alarm',
        'severity': 'moderate',
        'enabled': True,
        'repeat_actions': False,
        'alarm_actions': [wb_url],
        'comparison_operator': 'gt',
        'statistic': 'max'
    }
    Alarm.alarm_threshold_create(cc, **alarm_args)
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))