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(): # 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)