Ejemplo n.º 1
0
def execute_payload(payload):
    LOG.info('Executing payload %r' % payload)
    vpc_id = payload['network_details'].get('env_sel_net')
    sec_grp = []
    if payload['network_details'].get(
            'env_net_conf') != 'Use Existing Network':
        LOG.info('Network creation task started')
        resp = ec.create_network(payload)
        LOG.info('Network creation task completed')
        LOG.debug('Network response %r' % resp)
        td.save_task('create_network', payload['u_request_type'],
                     payload['ritm_no'], payload['request_no'], 'Success', '',
                     resp)
        vpc_id = resp.get('output')[0].get('vpc').get('id')

        sec_grp = resp.get('output')[0].get('group_id')
        resp = ec.create_subnet(payload, vpc_id)
        LOG.info('Subnet creation task completed')
        LOG.debug('Subnet response %r' % resp)
        td.save_task('create_subnet', payload['u_request_type'],
                     payload['ritm_no'], payload['request_no'], 'Success', '',
                     resp)
    if payload['security_group'].get('Array_string') != None:
        LOG.info('Security Group creation task started')
        resp = ec.create_sec_group(payload, vpc_id)
        LOG.info('Sec Group creation task completed')
        LOG.debug('Sec Group response %r' % resp)
        td.save_task('create_sec_group', payload['u_request_type'],
                     payload['ritm_no'], payload['request_no'], 'Success', '',
                     resp)

    service = None
    if 'ser_cat_ws' in payload['service_info']:
        service = payload['service_info']['ws_typ_n'].lower()
    elif 'ser_cat_ds' in payload['service_info']:
        service = payload['service_info']['db_ser_typ_n'].lower()
    print 'Service %r' % service
    ports = get_service_ports(service)

    resp = ec.create_instances(payload, vpc_id, sec_grp, service)
    LOG.info('Instance creation task completed')
    LOG.debug('Instance response %r' % resp)
    td.save_task('create_instance', payload['u_request_type'],
                 payload['ritm_no'], payload['request_no'], 'Success', '',
                 resp)

    instance_ids = resp.get('output')[0].get('instance_ids')
    public_ips = []
    instance_ids = []
    for item in resp.get('output'):
        public_ips.append(item.get('public_ip'))
        instance_ids.append(item.get('instance_id'))
    print 'Public Ips : %r' % public_ips

    if payload['volume_details'].get('name') != None:
        resp = ec.create_volume(payload, public_ips)
        LOG.info('Volume creation task completed')
        LOG.debug('Volume response %r' % resp)
        td.save_task('create_volume', payload['u_request_type'],
                     payload['ritm_no'], payload['request_no'], 'Success', '',
                     resp)

    if payload['server_info']['quantity'] > 1:
        LOG.info('LB Creation started')
        resp = ec.create_lb(payload, instance_ids, [sec_grp], ports)
        LOG.info('LB creation task completed')
        LOG.debug('LB response %r' % resp)
        td.save_task('create_lb', payload['u_request_type'],
                     payload['ritm_no'], payload['request_no'], 'Success', '',
                     resp)

    need_k8 = payload['service_info'].get(
        'con_ws') or payload['service_info'].get('con_db') or 'No'
    LOG.info('Need Kubernetes: %s' % need_k8)
    if need_k8 == 'Yes':
        LOG.info('Waiting to finish instance creation steps')
        time.sleep(120)
        resp = ec.install_k8s(public_ips)
        LOG.info('Kubernetes creation task completed')
        LOG.debug('Kubernetes response %r' % resp)
        td.save_task('install_k8s', payload['u_request_type'],
                     payload['ritm_no'], payload['request_no'], 'Success', '',
                     resp)
        time.sleep(120)
        resp = ec.install_k8s_service(service, public_ips[0])
        LOG.info('Kubernetes service creation task completed')
        LOG.debug('Kubernetes service response %r' % resp)
        td.save_task('install_k8s_service', payload['u_request_type'],
                     payload['ritm_no'], payload['request_no'], 'Success', '',
                     resp)
    else:
        LOG.info('Installing service')
        time.sleep(120)
        LOG.info('Waiting to finish instance creation steps')
        resp = ec.install_service(service, public_ips)
        LOG.info('Service creation task completed')
        LOG.debug('Service response %r' % resp)
        td.save_task('install_service', payload['u_request_type'],
                     payload['ritm_no'], payload['request_no'], 'Success', '',
                     resp)

    if 'application_info' in payload:
        LOG.info('Triggering application')
        trigger_application(payload)
        LOG.info('Application creation task completed')
        LOG.debug('Application response %r' % resp)
        td.save_task('trigger_application', payload['u_request_type'],
                     payload['ritm_no'], payload['request_no'], 'Success', '',
                     resp)

    LOG.info('Sending final response to ServiceNow')
    resp = send_response_to_sn(payload, public_ips)
    td.save_task('send_response_to_sn', payload['u_request_type'],
                 payload['ritm_no'], payload['request_no'], 'Success', '',
                 resp)
Ejemplo n.º 2
0
def install_service(service, ip_list):
    LOG.info('Waiting to finish instance creation steps')
    resp = ec.install_service(service, ip_list)
    LOG.info('Service creation task completed')
    LOG.debug('Service response %r' % resp)
    print 'Service response %r' % resp