Exemplo n.º 1
0
def scalein(vmware_settings, *args):
    """
    Deletes an instance from vmware and removes it from the Pool
    :param vmware_settings: dictionary of vmware settings keys [vmware_access_key_id,
    vmware_secret_access_key, ec2_region, security_group_ids, instance_type,
    image_id]
    :param args: The args passed down as part of the alert.
    """
    api = getAviApiSession()
    autoscale_dump(*args)
    alert_info = json.loads(args[1])
    # Perform actual scaleout
    pool_name, pool_uuid, pool_obj, num_autoscale = \
        scaleout_params('scalein', alert_info, api=api)
    print(pool_name, ':', pool_uuid, ' num_scaleout', num_autoscale)
    scalein_server = pool_obj['servers'][-1]
    instance_ids = [scalein_server['hostname']]
    pool_obj['servers'] = pool_obj['servers'][:-1]
    # call controller API to update the pool
    print 'new pool obj', pool_obj
    resp = api.put('pool/%s' % pool_uuid, data=json.dumps(pool_obj))
    print 'updated pool', pool_obj['name'], resp.status_code
    if resp.status_code in (200, 201, 204):
        print 'deleting the instance from the vmware - ', instance_ids
        delete_vmware_instance(vmware_settings, instance_ids)
Exemplo n.º 2
0
def scalein(aws_settings, *args):
    """
    Deletes an instance from AWS and removes it from the Pool
    :param aws_settings: dictionary of aws settings keys [aws_access_key_id,
    aws_secret_access_key, ec2_region, security_group_ids, instance_type,
    image_id]
    :param args: The args passed down as part of the alert.
    """
    tenant = aws_settings.get('tenant', 'admin')
    api = getAviApiSession(tenant)
    autoscale_dump(*args)
    alert_info = json.loads(args[1])
    # Perform actual scaleout
    pool_name, pool_uuid, pool_obj, num_autoscale = \
        scaleout_params('scalein', alert_info, api=api, tenant=tenant)
    print((pool_name, ':', pool_uuid, ' num_scaleout', num_autoscale))
    scalein_server = pool_obj['servers'][-1]
    autoscaling_group = get_autoscaling_group(api, pool_obj)
    try:
        instance_ids = [scalein_server['external_uuid']]
    except KeyError:
        vm_ref = scalein_server['vm_ref']
        # https://10.130.129.34/api/vimgrvmruntime/i-08ddf0d2
        vm_uuid = vm_ref.split('/api/vimgrvmruntime/')[1].split('#')[0]
        instance_ids = [vm_uuid]
    pool_obj['servers'] = pool_obj['servers'][:-1]
    # call controller API to update the pool
    print('pool %s scalein server %s' % (pool_name, scalein_server))
    api = getAviApiSession()
    resp = api.put('pool/%s' % pool_uuid, tenant=tenant, data=pool_obj)
    print('updated pool', pool_obj['name'], resp.status_code)
    if resp.status_code in (200, 201, 204):
        print('deleting the instance from the aws - ', instance_ids)
        delete_aws_autoscaling_instance(aws_settings, autoscaling_group,
                                        instance_ids)
Exemplo n.º 3
0
def scaleout(vmware_settings, *args):
    """
    1. Creates an instance in vmware
    2. Registers that instance as a Pool Member
    :param vmware_settings: dictionary of vmware settings keys
        [vmware_access_key_id, vmware_secret_access_key, ec2_region,
        security_group_ids, instance_type, image_id]
    :param args: The args passed down as part of the alert.
    """
    # print all the args passed down
    autoscale_dump(*args)
    alert_info = json.loads(args[1])
    # Perform actual scaleout
    api = getAviApiSession()
    pool_name, pool_uuid, pool_obj, num_scaleout = \
        scaleout_params('scaleout', alert_info, api=api)
    # create vmware instance using these two ids.
    print pool_name, 'scaleout', num_scaleout
    hostname, ip_addr = create_vmware_instance(vmware_settings, pool_name)
    if not (hostname or ip_addr):
        print 'not performing scaleout as could not create vm'
    new_server = {
        'ip': {
            'addr': ip_addr,
            'type': 'V4'
        },
        'port': 0,
        'hostname': hostname,
    }
    # add new server to the pool
    pool_obj['servers'].append(new_server)
    # call controller API to update the pool
    print 'new pool obj', pool_obj
    resp = api.put('pool/%s' % pool_uuid, data=json.dumps(pool_obj))
    print 'updated pool', pool_obj['name'], resp.status_code
Exemplo n.º 4
0
def scaleout(vmware_settings, *args):
    """
    1. Creates an instance in vmware
    2. Registers that instance as a Pool Member
    :param vmware_settings: dictionary of vmware settings keys [vmware_access_key_id,
    vmware_secret_access_key, ec2_region, security_group_ids, instance_type,
    image_id]
    :param args: The args passed down as part of the alert.
    """
    # print all the args passed down
    autoscale_dump(*args)
    alert_info = json.loads(args[1])
    # Perform actual scaleout
    pool_name, pool_uuid, pool_obj, num_scaleout = \
        scaleout_params('scaleout', alert_info)
    # create vmware instance using these two ids.
    print pool_name, 'scaleout', num_scaleout
    hostname, ip_addr = create_vmware_instance(vmware_settings, pool_name)
    if not (hostname or ip_addr):
        print 'not performing scaleout as could not create vm'
    new_server = {
        'ip': {'addr': ip_addr, 'type': 'V4'},
        'port': 0,
        'hostname': hostname,
    }
    # add new server to the pool
    pool_obj['servers'].append(new_server)
    # call controller API to update the pool
    print 'new pool obj', pool_obj
    api = getAviApiSession()
    resp = api.put('pool/%s' % pool_uuid, data=json.dumps(pool_obj))
    print 'updated pool', pool_obj['name'], resp.status_code
Exemplo n.º 5
0
def scalein(vmware_settings, *args):
    """
    Deletes an instance from vmware and removes it from the Pool
    :param vmware_settings: dictionary of vmware settings keys [vmware_access_key_id,
    vmware_secret_access_key, ec2_region, security_group_ids, instance_type,
    image_id]
    :param args: The args passed down as part of the alert.
    """
    autoscale_dump(*args)
    alert_info = json.loads(args[1])
    # Perform actual scaleout
    pool_name, pool_uuid, pool_obj, num_autoscale = \
        scaleout_params('scalein', alert_info)
    print (pool_name, ':', pool_uuid, ' num_scaleout', num_autoscale)
    scalein_server = pool_obj['servers'][-1]
    instance_ids = [scalein_server['hostname']]
    pool_obj['servers'] = pool_obj['servers'][:-1]
    # call controller API to update the pool
    print 'new pool obj', pool_obj
    api = getAviApiSession()
    resp = api.put('pool/%s' % pool_uuid, data=json.dumps(pool_obj))
    print 'updated pool', pool_obj['name'], resp.status_code
    if resp.status_code in (200, 201, 204):
        print 'deleting the instance from the vmware - ', instance_ids
        delete_vmware_instance(vmware_settings, instance_ids)
Exemplo n.º 6
0
def scalein(aws_settings, *args):
    """
    Deletes an instance from AWS and removes it from the Pool
    :param aws_settings: dictionary of aws settings keys [aws_access_key_id,
    aws_secret_access_key, ec2_region, security_group_ids, instance_type,
    image_id]
    :param args: The args passed down as part of the alert.
    """
    tenant = aws_settings.get('tenant', 'admin')
    api = getAviApiSession(tenant)
    autoscale_dump(*args)
    alert_info = json.loads(args[1])
    # Perform actual scaleout
    pool_name, pool_uuid, pool_obj, num_autoscale = \
        scaleout_params('scalein', alert_info, api=api, tenant=tenant)
    print((pool_name, ':', pool_uuid, ' num_scaleout', num_autoscale))
    scalein_server = pool_obj['servers'][-1]
    autoscaling_group = get_autoscaling_group(api, pool_obj)
    try:
        instance_ids = [scalein_server['external_uuid']]
    except KeyError:
        vm_ref = scalein_server['vm_ref']
        # https://10.130.129.34/api/vimgrvmruntime/i-08ddf0d2
        vm_uuid = vm_ref.split('/api/vimgrvmruntime/')[1].split('#')[0]
        instance_ids = [vm_uuid]
    pool_obj['servers'] = pool_obj['servers'][:-1]
    # call controller API to update the pool
    print('pool %s scalein server %s' % (pool_name, scalein_server))
    api = getAviApiSession()
    resp = api.put('pool/%s' % pool_uuid, tenant=tenant, data=pool_obj)
    print('updated pool', pool_obj['name'], resp.status_code)
    if resp.status_code in (200, 201, 204):
        print('deleting the instance from the aws - ', instance_ids)
        delete_aws_autoscaling_instance(
            aws_settings, autoscaling_group, instance_ids)
Exemplo n.º 7
0
def scaleout(aws_settings, *args):
    """
    1. Creates an instance in AWS
    2. Registers that instance as a Pool Member
    :param aws_settings: dictionary of aws settings keys [aws_access_key_id,
    aws_secret_access_key, ec2_region, security_group_ids, instance_type,
    image_id]
    :param args: The args passed down as part of the alert.
    """
    # print all the args passed down
    autoscale_dump(*args)
    alert_info = json.loads(args[1])
    # Perform actual scaleout
    pool_name, pool_uuid, pool_obj, num_scaleout = \
        scaleout_params('scaleout', alert_info)
    # create AWS instance using these two ids.
    print pool_name, 'scaleout', num_scaleout
    insid, ip_addr, hostname = create_aws_instance(aws_settings)
    new_server = {
        'ip': {
            'addr': ip_addr,
            'type': 'V4'
        },
        'port': 0,
        'hostname': hostname,
        'external_uuid': insid
    }
    # add new server to the pool
    pool_obj['servers'].append(new_server)
    # call controller API to update the pool
    print 'new pool obj', pool_obj
    api = getAviApiSession()
    resp = api.put('pool/%s' % pool_uuid, data=json.dumps(pool_obj))
    print 'updated pool', pool_obj['name'], resp.status_code
Exemplo n.º 8
0
def scaleout(*args):
    """
    1. Creates an instance in vmware
    2. Registers that instance as a Pool Member
    :param args: The args passed down as part of the alert.
    """
    # print all the args passed down
    autoscale_dump(*args)
    alert_info = json.loads(args[1])
    # Perform actual scaleout
    api = getAviApiSession()
    pool_name, pool_uuid, pool_obj, num_scaleout, autoscale_info = \
        get_autoscale_event_info('scaleout', alert_info, api=api)
    # create vmware instance using these two ids.
    print(pool_name, 'num_scaleout', num_scaleout)
    # Find existing server that is disabled
    for s in pool_obj['servers']:
        if not num_scaleout:
            print ('no more servers needed to be scaledout')
            break
        if not s['enabled']:
            s['enabled'] = True
            num_scaleout = num_scaleout - 1
            print (pool_name, 'updated server ', s['hostname'], s['enabled'])
    if num_scaleout:
        print(pool_name, 'could not scaleout', num_scaleout, 'servers')
    # call controller API to update the pool
    resp = api.put('pool/%s' % pool_uuid, data=json.dumps(pool_obj))
    print('updated pool', pool_obj['name'], resp.status_code)
Exemplo n.º 9
0
def scalein(*args):
    """
    Deletes an instance from vmware and removes it from the Pool
    :param args: The args passed down as part of the alert.
    """
    api = getAviApiSession()
    autoscale_dump(*args)
    alert_info = json.loads(args[1])
    # Perform actual scaleout
    ev_info = get_autoscale_event_info('scalein', alert_info, api=api)
    num_scalein = ev_info.num_autoscale
    print(ev_info.pool_name, 'num_scalein', num_scalein)
    # Find existing server that is disabled
    # get the candidate servers and check if they are enabled.
    # if so then first try to disable them.

    scalein_servers = set()
    for ss in ev_info.autoscale_info['scalein_server_candidates']:
        scalein_servers.add((ss['ip']['addr'], ss['port']))

    for s in ev_info.pool_obj['servers']:
        s_port = (s['ip']['addr'],
                  s.get('port',
                        ev_info.pool_obj.get('default_server_port', 80)))
        if not num_scalein:
            break
        if s_port in scalein_servers and s['enabled']:
            num_scalein = num_scalein - 1
            s['enabled'] = False
            print (ev_info.pool_name, 'updated server ', s['hostname'],
                   s['enabled'])

    if num_scalein:
        num_servers = len(ev_info.pool_obj['servers'])
        for index in xrange(num_servers):
            s = ev_info.pool_obj['servers'][num_servers - index - 1]
            if s['enabled']:
                s['enabled'] = False
                num_scalein = num_scalein - 1
                print (ev_info.pool_name, 'updated server ', s['hostname'],
                       s['enabled'])
    if num_scalein:
        print(ev_info.pool_name, 'could not scalein', num_scalein, 'servers')
    # call controller API to update the pool
    resp = api.put('pool/%s' % ev_info.pool_uuid, data=ev_info.pool_obj)
    print('updated pool', ev_info.pool_name, resp.status_code)
Exemplo n.º 10
0
def scaleout(aws_settings, *args):
    """
    1. Creates an instance in AWS
    2. Registers that instance as a Pool Member
    :param aws_settings: dictionary of aws settings keys [aws_access_key_id,
    aws_secret_access_key, ec2_region, security_group_ids, instance_type,
    image_id]
    :param args: The args passed down as part of the alert.
    """
    # print all the args passed down
    tenant = aws_settings.get('tenant', 'admin')
    api = getAviApiSession(tenant)
    autoscale_dump(*args)
    alert_info = json.loads(args[1])
    # Perform actual scaleout
    pool_name, pool_uuid, pool_obj, num_scaleout = \
        scaleout_params('scaleout', alert_info, api=api, tenant=tenant)
    # create AWS instance using these two ids.
    print(pool_name, 'scaleout', num_scaleout)
    autoscaling_group = get_autoscaling_group(api, pool_obj)
    desired_capacity = len(pool_obj['servers']) + num_scaleout
    new_instances = aws_autoscaling_scaleout(
        aws_settings, pool_obj, autoscaling_group, desired_capacity,
        num_scaleout)
    for instance in new_instances:
        insid, ip_addr, hostname = instance
        new_server = {
            'ip': {'addr': ip_addr, 'type': 'V4'},
            'port': 0,
            'hostname': hostname,
            'external_uuid': insid,
            'vm_uuid': insid,
        }
        # add new server to the pool
        pool_obj['servers'].append(new_server)
    # call controller API to update the pool
    print('new pool obj', pool_obj)
    api = getAviApiSession()
    resp = api.put('pool/%s' % pool_uuid, tenant=tenant,
                   data=json.dumps(pool_obj))
    print('updated pool', pool_obj['name'], resp.status_code)