예제 #1
0
def deploy_app(new_sess, neutron, keystone, new_project):
    # Rebuilding app
    new_project_obj = [
        prj for prj in keystone.projects.list() if prj.name == new_project
    ]
    neutron_resources = neutron.list_networks(project_id=new_project_obj[0].id)

    # Redeployng App
    #Assuming App management netwrk will have MGMT in the name and DataPlane for dp network
    mgmt = [
        net for net in neutron_resources['networks'] if 'MGMT' in net['name']
    ]
    dp = [
        net for net in neutron_resources['networks']
        if 'DataPlane' in net['name']
    ]
    resources_dict = {}
    resources_dict['Management_net'] = mgmt[0]['id']
    resources_dict['Mgmt_subnet'] = mgmt[0]['subnets'][0]
    resources_dict['DataPlane_net'] = dp[0]['id']
    resources_dict['DP_subnet'] = dp[0]['subnets'][0]

    heat = heat_client('1', session=new_sess)
    files, template = template_utils.process_template_path(
        'service-deployment.yaml')
    res = heat.stacks.create(stack_name='App',
                             template=template,
                             files=files,
                             parameters=resources_dict)
    print "App redeployment was started"
예제 #2
0
    def __init__(self,
                 username,
                 password,
                 tenant,
                 auth_url,
                 heat_url,
                 region=None):
        self.username = username
        self.password = password
        self.tenant = tenant
        self.auth_url = auth_url
        self.heat_url = heat_url
        self.region = region
        self.stack_list = []

        keystone = keystone_client(username=self.username,
                                   password=self.password,
                                   tenant_name=self.tenant,
                                   auth_url=self.auth_url)
        self.token = keystone.auth_token
        self.heat = heat_client('1',
                                endpoint=self.heat_url,
                                region_name=self.region,
                                token=self.token,
                                insecure=True)
예제 #3
0
def time_stack_list(username, password, tenant, auth_url, heat_url, region,
                    statsd_server):
    keystone = keystone_client(username=username, password=password,
                               tenant_name=tenant, auth_url=auth_url)
    token = keystone.auth_token
    heat = heat_client('1', endpoint=heat_url, region_name=region, token=token)
    statsd = StatsClient(host=statsd_server)

    with statsd.timer('uptime.{}'.format(region)):
        list(heat.stacks.list())
예제 #4
0
    def setUpClass(self):
        self.stack_name = 'test_elk_stack'
        ostack_config = self.config['openstack']
        self.keystone = ksclient.Client(auth_url="http://127.0.0.1:35357/v2.0",
                                   username=ostack_config['user'],
                                   password=ostack_config['password'],
                                   tenant_name=ostack_config['tenant_name'])
        endpoints = self.keystone.service_catalog.get_endpoints(service_type='orchestration')
        endpoints.update(self.keystone.service_catalog.get_endpoints(service_type='network'))

        self.heat_endpoint = endpoints['orchestration'][0]['publicURL']
        self.neutron_endpoint = endpoints['network'][0]['publicURL']

        token = self.keystone.auth_token

        if self.heat_endpoint is None or self.neutron_endpoint is None:
            raise Exception('No endpoint found for either heat or neutron')

        neutron = neutron_client.Client('2.0', endpoint_url=self.neutron_endpoint, token=token)
        pub_net = neutron.list_networks(name=ostack_config['net_name'])['networks'][0]
        heat = heat_client('1', endpoint=self.heat_endpoint, token=token)

        heat_params = self.config['heat_params']
        heat_params['floating-network-id'] = pub_net['id']
        
        fields = {
            'stack_name': self.stack_name,
            'timeout_mins': '120',
            'parameters': dict(heat_params)
        }

        template_data = ''
        with open('../elk-stack.yaml') as f:
            fields['template'] = f.read()

        with open('../env.yaml') as f:
            fields['environment'] = f.read()

        test_stack = heat.stacks.create(**fields)
        self.test_stack_id = test_stack['stack']['id']

        while True:
            self.stack_info = heat.stacks.get(self.test_stack_id)
            if self.stack_info.stack_status == 'CREATE_IN_PROGRESS':
                time.sleep(10)
                log.debug("Waiting for stack completion")
            elif self.stack_info.stack_status == 'CREATE_COMPLETE':
                log.debug("Stack successful")
                break
            else:
                log.debug("Stack failed")
                raise Exception(self.stack_info.stack_status, 'Stack failed with reason: %s' % self.stack_info.stack_status_reason)
예제 #5
0
def build_info(bot, trigger):
    '''Display build-info for a heat endpoint'''
    username = bot.config.heat.username
    password = bot.config.heat.password
    tenant_name = bot.config.heat.tenant_name
    auth_url = bot.config.heat.auth_url
    endpoint_input = trigger.group(2)
    regions = ['dfw', 'iad', 'ord', 'lon', 'syd', 'hkg']

    if endpoint_input is None:
        bot.say("Please give me an endpoint to get build-info from. See "
                ".heat-endpoints for a list.")
        return
    elif endpoint_input == 'all':
        endpoints_list = [endpoint for endpoint in ENDPOINTS]
    elif endpoint_input == 'active':
        endpoints_list = regions
    elif endpoint_input == 'inactive':
        endpoints_list = ['inactive.' + region for region in regions]
    elif endpoint_input in ENDPOINTS:
        endpoints_list = [endpoint_input]
    else:
        bot.say("{} isn't an endpoint name I recognize. See a list at "
                ".heat-endpoints".format(endpoint_input))
        return

    keystone = keystone_client(username=username,
                               password=password,
                               tenant_name=tenant_name,
                               auth_url=auth_url)
    token = keystone.auth_token

    for endpoint_label in sorted(endpoints_list):
        full_endpoint = 'https://{}/v1/{}'.format(ENDPOINTS[endpoint_label],
                                                  bot.config.heat.tenant_name)
        heat = heat_client('1',
                           endpoint=full_endpoint,
                           insecure=True,
                           token=token)

        build_info = heat.build_info.build_info()
        api_revision = build_info['api']['revision']
        engine_revision = build_info['engine']['revision']
        if 'fusion-api' in build_info:
            fusion_revision = build_info['fusion-api']['revision']
        else:
            fusion_revision = 'None'

        bot.say('{}: api: {}  engine: {}  fusion: {}'.format(
            endpoint_label, api_revision, engine_revision, fusion_revision))
예제 #6
0
def build_info(bot, trigger):
    '''Display build-info for a heat endpoint'''
    username = bot.config.heat.username
    password = bot.config.heat.password
    tenant_name = bot.config.heat.tenant_name
    auth_url = bot.config.heat.auth_url
    endpoint_label = trigger.group(2)

    if endpoint_label is None:
        bot.say("Please give me an endpoint to get build-info from. See "
                ".heat-endpoints for a list.")
        return

    if endpoint_label not in ENDPOINTS:
        bot.say("{} isn't an endpoint name I recognize. See a list at "
                ".heat-endpoints".format(endpoint_label))
        return

    keystone = keystone_client(username=username,
                               password=password,
                               tenant_name=tenant_name,
                               auth_url=auth_url)
    token = keystone.auth_token
    full_endpoint = 'https://{}/v1/{}'.format(ENDPOINTS[endpoint_label],
                                              bot.config.heat.tenant_name)
    heat = heat_client('1', endpoint=full_endpoint, insecure=True, token=token)

    build_info = heat.build_info.build_info()
    api_revision = build_info['api']['revision']
    engine_revision = build_info['engine']['revision']
    if 'fusion-api' in build_info:
        fusion_revision = build_info['fusion-api']['revision']
    else:
        fusion_revision = 'None'

    bot.say('api: {}  engine: {}  fusion: {}'.format(api_revision,
                                                     engine_revision,
                                                     fusion_revision))
def main():
    parser = argparse.ArgumentParser(description='Test a heat endpoint')
    parser.add_argument('-c',
                        '--config',
                        help='Path to config file',
                        default='/etc/heat-monitoring/heat_check.cfg')
    parser.add_argument('-e',
                        '--env',
                        help='Environment settings to get from '
                        'config')
    parser.add_argument('-u', '--user', help='Username')
    parser.add_argument('-p', '--password', help='Password')
    parser.add_argument('-t', '--tenant', help='Tenant name')
    parser.add_argument(
        '-a',
        '--auth_url',
        help='Authentication URL',
        default='https://identity.api.rackspacecloud.com/v2.0/')
    parser.add_argument('-U', '--heat_url', help='URL for Heat service')
    parser.add_argument('-r', '--region', help='Region for service catalog')
    parser.add_argument(
        '-T',
        '--template',
        choices=['wp_single', 'php_app_multi', 'django_clouddb'],
        default='wp_single',
        help='Template for stack preview')

    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument('-b',
                       '--basic',
                       action='store_false',
                       help='Runs '
                       'build_info, stack_list, and stack_show times')
    group.add_argument('-P',
                       '--preview',
                       action='store_true',
                       help='Runs '
                       'stack preview times for three templates')

    args = parser.parse_args()
    config_file = args.config
    section = args.env

    config = ConfigParser.ConfigParser()
    if os.path.exists(config_file):
        config.read(config_file)

    username = args.user if args.user else config.get(section, 'username')
    password = args.password if args.password else config.get(
        section, 'password')
    tenant_name = args.tenant if args.tenant else config.get(section, 'tenant')
    auth_url = args.auth_url if args.auth_url else config.get(
        section, 'auth_url')
    heat_url = args.heat_url if args.heat_url else config.get(
        section, 'heat_url')
    region = args.region if args.region else config.get(section, 'region')

    keystone = keystone_client(username=username,
                               password=password,
                               tenant_name=tenant_name,
                               auth_url=auth_url)
    token = keystone.auth_token
    heat = heat_client('1', endpoint=heat_url, region_name=region, token=token)

    check = HeatCheck(username, password, tenant_name, auth_url, heat_url,
                      region)

    if args.preview:
        preview_templates = {
            'wp_single':
            'https://raw.githubusercontent.com/rackspace-orchestration-templates/wordpress-single/master/wordpress-single.yaml',
            'php_app_multi':
            'https://raw.githubusercontent.com/rackspace-orchestration-templates/php-app-multi/master/php-app-multi.yaml',
            'django_clouddb':
            'https://raw.githubusercontent.com/rackspace-orchestration-templates/django-clouddb/master/django-multi.yaml'
        }

        template = args.template
        url = preview_templates[template]

        if template == 'django_clouddb':
            preview_time = check.stack_preview_time(
                url, parameters={'datastore_version': '5.1'})
        else:
            preview_time = check.stack_preview_time(url)

        print('metric preview_{} float {}'.format(template, preview_time))
    else:
        bi_time = check.build_info_time()
        sl_time = check.stack_list_time()
        ss_time = check.stack_show_time()

        print('metric build_info float {}'.format(bi_time))
        print('metric stack_list float {}'.format(sl_time))
        print('metric stack_show float {}'.format(ss_time))
예제 #8
0
 def tearDownClass(self):
     self.keystone.authenticate()
     token = self.keystone.auth_token
     heat = heat_client('1', endpoint=self.heat_endpoint, token=token)
     heat.stacks.delete(self.test_stack_id)