Ejemplo n.º 1
0
def vrf_add_default_route(vrf_name, route_id, **kwargs):
    """

    :param vrf_name:
    :param route_id:
    :param kwargs:
    :return:
    """
    nh = kwargs.get('nh', None)
    network = kwargs.get('network', None)
    next_hop_last_octet = kwargs.get('next_hop_last_octet', '.1')
    json_data = vrf_get(vrf_name, **kwargs)
    json_data['vrf']['static_routes'] = {}
    json_data['vrf']['static_routes']['rt']['route_id'] = route_id
    json_data['vrf']['static_routes']['rt']['prefix']['ip_addr']['addr'] = '0.0.0.0'
    json_data['vrf']['static_routes']['rt']['prefix']['ip_addr']['type'] = 0
    json_data['vrf']['static_routes']['rt']['prefix']['mask'] = 0
    if nh:
        json_data['vrf']['static_routes']['rt']['next_hop']['addr'] = nh
    else:
        config = infra_utils.get_config()
        mode = config.get_mode()
        site_name = mode['site_name']
        nw_ip = config.testbed[site_name].networks_json[network]['ip']
        default_nh = ".".join(nw_ip.split('.')[0:3]) + next_hop_last_octet
        json_data['vrf']['static_routes']['rt']['next_hop']['addr'] = default_nh
        json_data['vrf']['static_routes']['rt']['next_hop']['type'] = 0
    rest.put('vrfcontext', data=json_data)
Ejemplo n.º 2
0
def delete_servers(pool_name, how_many, prefix, cleanup_backend=True):
    """

    :param pool_name:
    :param how_many:
    :param prefix:
    :param cleanup_backend:
    :return:
    """
    logger.info('delete servers from pool %s' % pool_name)
    config = infra_utils.get_config()
    context_key = config.get_context_key()
    pool = config.site_objs[context_key]['pool'].get(pool_name)

    for count in range(int(how_many)):
        handle = '%s%s' % (prefix, count + 1)
        _delete_server_backend(handle, pool, cleanup_backend)

    for count in range(int(how_many)):
        handle = '%s%s' % (prefix, count + 1)
        _delete_server_model(handle, pool)

    st, pool_json_ctrl = rest.get('pool', name=pool_name)
    pool_server_json = []
    pool_server_dict = pool.servers
    for pool_server in pool_server_dict.values():
        pool_server_json.append(pool_server.get_json())
    pool_json_ctrl['servers'] = pool_server_json
    rest.put('pool', name=pool_name, data=pool_json_ctrl)
Ejemplo n.º 3
0
def update_healthmonitor(hm_name, **kwargs):
    """

    :param hm_name:
    :param kwargs:
    :return:
    """
    logger.info('update healthmonitor %s' % hm_name)
    status_code, json_hm_data = rest.get('healthmonitor', name=hm_name)

    if kwargs.get('type'):
        json_hm_data['type'] = kwargs.get('type')

    if kwargs.get('send_interval'):
        json_hm_data['send_interval'] = kwargs.get('send_interval')

    if kwargs.get('receive_timeout'):
        json_hm_data['receive_timeout'] = kwargs.get('receive_timeout')

    if kwargs.get('successful_checks'):
        json_hm_data['successful_checks'] = kwargs.get('successful_checks')

    if kwargs.get('failed_checks'):
        json_hm_data['failed_checks'] = kwargs.get('failed_checks')

    rest.put('healthmonitor', name=hm_name, data=json_hm_data)
Ejemplo n.º 4
0
def negative_update_server(pool_name, handle, **kwargs):
    """

    :param pool_name:
    :param handle:
    :param kwargs:
    :return:
    """
    server = infra_utils.get_server_by_handle(handle)

    response_code, json_pool_data = rest.get('pool', name=pool_name)

    if kwargs.get('port'):
        for index, rest_server in enumerate(json_pool_data.get('servers')):
            json_server_data = server.get_json()
            server_ip = json_server_data.get('ip')
            if server_ip and server_ip.get(
                    'addr') == rest_server['ip']['addr']:
                json_pool_data['servers'][index]['port'] = kwargs.get('port')
    try:
        rest.put('pool', name=pool_name, data=json_pool_data)
        logger_utils.fail('No exception was raised in negative test case')
    except Exception as e:
        logger.info('Field port must be in the range 1-65535')
        return True
Ejemplo n.º 5
0
def set_systemconfiguration(**kwargs):
    logger.info('-- set_systemconfiguration -- \n')
    _, data = get('systemconfiguration')

    data['portal_configuration']['password_strength_check'] = False
    logger.info('Data after: %s---' % data)

    if kwargs.get('dns_configuration', 'True') == 'True':
        ip_addr = {'addr': '10.10.0.100',
                   'type': 'V4'}

        data['dns_configuration']['server_list'] = []
        data['dns_configuration']['server_list'].append(ip_addr)

        data['dns_virtualservice_uuids'] = []

    if kwargs.get('dns_virtualservice_uuids'):
        vs_uuid = get_uuid_by_name('virtualservice',
                                   kwargs.get('dns_virtualservice_uuids'))  # REVIEW how does this work?
        data['dns_virtualservice_uuids'].append(vs_uuid)

    try:
        put('systemconfiguration', data=json.dumps(data))
    except Exception as e:
        logger.info('put failed %s. Retrying' % e)
        put('systemconfiguration', data=json.dumps(data))

    try:
        _, r = get('systemconfiguration')
    except Exception as e:
        logger.info('get systemconfiguration failed with %s. Retrying' % e)
        _, r = get('systemconfiguration')
    logger.info('\n --- Get system configuration: %s --- \n' % r)
Ejemplo n.º 6
0
def resize_subnet(name, **kwargs):
    _, json_data = rest.get('network', name=name)
    subnet_ip = kwargs.get('subnet_ip', None)
    s_mask = kwargs.get('subnet_mask', None)
    new_subnet_mask = kwargs.get('new_subnet_mask', None)
    stat_ip = kwargs.get('static_ip', None)
    del_stat_ip = kwargs.get('delete_stat_ip', None)
    subnet_mask = int(s_mask)
    for index, subnet in enumerate(json_data['configured_subnets']):
        if subnet['prefix']['mask'] == subnet_mask and subnet['prefix'][
                'ip_addr']['addr'] == subnet_ip:
            if new_subnet_mask:
                json_data['configured_subnets'][index]['prefix'][
                    'mask'] = new_subnet_mask
            if stat_ip:
                stat_ip_dict = {'type': "V4", 'addr': stat_ip}
                if 'static_ips' in subnet.keys():
                    json_data['configured_subnets'][index][
                        'static_ips'].append(stat_ip_dict)
                else:
                    json_data['configured_subnets'][index]['static_ips'] = [
                        stat_ip_dict
                    ]
            if del_stat_ip:
                for static_ip in subnet['static_ips']:
                    if static_ip['addr'] == del_stat_ip:
                        json_data['configured_subnets'][index][
                            'static_ips'].remove(static_ip)
    rest.put('network', name=json_data['name'], data=json_data)
Ejemplo n.º 7
0
def add_east_west_to_cloud(ipam_name=None, dns_name=None, **kwargs):
    """

    :param ipam_name:
    :param dns_name:
    :param tenant:
    :param kwargs:
    :return:
    """
    cloud_name = kwargs.get('cloud', infra_utils.get_mode()['cloud'])
    tenant = kwargs.get('tenant', infra_utils.get_mode()['tenant'])
    status_code, json_data = rest.get('cloud', name=cloud_name)
    logger.info('add ipam: %s to cloud: %s' % (ipam_name, json_data['name']))

    if ipam_name:
        logger.info('add ipam: %s to cloud: %s' %
                    (ipam_name, json_data.get('name')))
        json_data[
            'east_west_ipam_provider_ref'] = '/api/ipamdnsproviderprofile?name=%s' % ipam_name

    if dns_name:
        logger.info('add dns: %s to cloud: %s' %
                    (dns_name, json_data.get('name')))
        json_data[
            'east_west_dns_provider_ref'] = '/api/ipamdnsproviderprofile?name=%s' % dns_name

    rest.put('cloud',
             name=json_data.get('name'),
             data=json_data,
             tenant=tenant)
Ejemplo n.º 8
0
def set_ha_mode_best_effort():
    logger.info('-- set_ha_mode_best_effort -- \n')

    # REVIEW is this used anywhere?
    @aretry(retry=10, delay=60, period=10)
    def get_serviceenginegroup():
        return get('serviceenginegroup')

    _, data = get('serviceenginegroup')
    for _data in data['results']:
        _data['ha_mode'] = 'HA_MODE_SHARED'
        _data['algo'] = 'PLACEMENT_ALGO_DISTRIBUTED'
        _data['buffer_se'] = 1
        _data['min_scaleout_per_vs'] = 1

        logger.info('Data after changing, before post: %s---' % _data)
        try:
            r = put('serviceenginegroup', uuid=_data['uuid'], data=json.dumps(_data))
        except Exception as e:
            logger.info('put failed %s. Retrying' % e)
            r = put('serviceenginegroup', uuid=_data['uuid'], data=json.dumps(_data))

        try:
            _, r = get('serviceenginegroup')
        except Exception as e:
            logger.info('put failed %s. Retrying' % e)
            _, r = get('serviceenginegroup')

        logger.info('\n --- Get serviceenginegroup: %s --- \n' % r)
Ejemplo n.º 9
0
def update_ip_addr_group(name, access, **kwargs):
    '''

    :param name:
    :param access:
    :param kwargs:
    :return:
    '''
    access_object, systemconfiguration, mgmt_ip_access_control = \
        get_mgmt_access_objects(access)
    mgmt_ip_access_control = systemconfiguration.get('mgmt_ip_access_control')
    if not mgmt_ip_access_control:
        systemconfiguration['mgmt_ip_access_control'] = {}
    access_object = systemconfiguration.get('mgmt_ip_access_control').get(
        access)
    status_code, response = rest.get('ipaddrgroup', name=name)
    if not access_object:
        access_object = {}

    access_object['match_criteria'] = 0
    if not access_object.get('group_refs'):
        access_object['group_refs'] = []
    access_object['group_refs'].append(response.get('url'))
    systemconfiguration['mgmt_ip_access_control'][access] = access_object
    rest.put('systemconfiguration', data=systemconfiguration)
Ejemplo n.º 10
0
def update_ip_addr_prefix(start, prefix, access, **kwargs):
    '''

    :param start:
    :param prefix:
    :param access:
    :param kwargs:
    :return:
    '''
    access_object, systemconfiguration, mgmt_ip_access_control = \
        get_mgmt_access_objects(access)
    mgmt_ip_access_control = systemconfiguration.get('mgmt_ip_access_control')
    if not mgmt_ip_access_control:
        systemconfiguration['mgmt_ip_access_control'] = {}
    access_object = systemconfiguration.get('mgmt_ip_access_control').get(
        access)
    if not access_object:
        access_object = {}
    access_object['match_criteria'] = 0
    access_object['prefixes'] = []
    access_object['prefixes'].append({
        'ip_addr': {
            'type': 0,
            'addr': start
        },
        'mask': int(prefix)
    })
    systemconfiguration['mgmt_ip_access_control'][access] = access_object
    rest.put('systemconfiguration', data=systemconfiguration)
Ejemplo n.º 11
0
def remove_ip_addr_group(name, access, **kwargs):
    '''

    :param name:
    :param access:
    :param kwargs:
    :return:
    '''
    access_object, systemconfiguration, mgmt_ip_access_control = \
        get_mgmt_access_objects(access)
    mgmt_ip_access_control = systemconfiguration.get('mgmt_ip_access_control')
    if not mgmt_ip_access_control:
        systemconfiguration['mgmt_ip_access_control'] = {}
    access_object = systemconfiguration.get('mgmt_ip_access_control').get(
        access)
    status_code, response = rest.get('ipaddrgroup', name=name)
    if status_code >= 300:
        logger_utils.fail('Error in retrieving IP address group')

    ip_addr_group_ref = response.get("url")
    for group_ref in access_object['group_refs']:
        if ip_addr_group_ref == group_ref:
            access_object['group_refs'].remove(group_ref)

    rest.put('systemconfiguration', data=systemconfiguration)
Ejemplo n.º 12
0
def set_basic_dns_configuration(search_domain='avi.local',
                                dns_server_addr='10.10.0.100',
                                **kwargs):
    """
    Adds some dns settings to systemconfiguration
    :param search_domain:
    :param dns_server_addr:
    :param kwargs:
    :return:
    """

    status_code, response = rest.get('systemconfiguration')
    response['dns_configuration']['search_domain'] = search_domain
    dns_server_already_exists = False
    if not 'server_list' in response['dns_configuration']:
        response['dns_configuration']['server_list'] = []
    dns_server_list = response['dns_configuration'][
        'server_list']  # s.dns_configuration.server_list
    for dns_server in dns_server_list:
        if dns_server['addr'] == dns_server_addr:
            dns_server_already_exists = True
    if not dns_server_already_exists:
        dns_server = {'addr': dns_server_addr, 'type': 'V4'}
        response['dns_configuration']['server_list'].append(dns_server)
        rest.put('systemconfiguration', data=response)
Ejemplo n.º 13
0
def update_ssh_ciphers_and_hmac(ciphers, hmacs, **kwargs):
    '''

    :param ciphers:
    :param hmacs:
    :param kwargs:
    :return:
    '''
    systemconfiguration = get_system_configuration()

    if ciphers:
        # append if exist
        for cipher in ciphers:
            ssh_ciphers = systemconfiguration.get('ssh_ciphers', None)
            if not ssh_ciphers:
                systemconfiguration['ssh_ciphers'] = []
            systemconfiguration['ssh_ciphers'].append(cipher)

    if hmacs:
        # append if exist
        for hmac in hmacs:
            ssh_hmacs = systemconfiguration.get('ssh_hmacs', None)
            if not ssh_hmacs:
                systemconfiguration['ssh_hmacs'] = []
            systemconfiguration['ssh_hmacs'].append(hmac)

    rest.put('systemconfiguration', data=systemconfiguration)
Ejemplo n.º 14
0
def negative_update_pool(pool_name, expected_error=None, **kwargs):
    """

    :param pool_name:
    :param expected_error:
    :param kwargs:
    :return:
    """
    logger.info('update pool %s, fileds: %s' % (pool_name, kwargs))
    _, json_pool_data = rest.get('pool', name=pool_name)

    if kwargs.get('name') or kwargs.get('name') == '':
        json_pool_data['name'] = kwargs.get('name')

    if kwargs.get('default_server_port'):
        json_pool_data['default_server_port'] = kwargs.get(
            'default_server_port')

    if kwargs.get('graceful_disable_timeout'):
        json_pool_data['graceful_disable_timeout'] = kwargs.get(
            'graceful_disable_timeout')

    if kwargs.get('connection_ramp_duration'):
        json_pool_data['connection_ramp_duration'] = kwargs.get(
            'connection_ramp_duration')

    try:
        rest.put('pool', name=pool_name, data=json_pool_data)
        logger_utils.fail('No exception was raised in negative test case')
    except Exception as e:
        if expected_error:
            if expected_error.lower() not in str(e).lower():
                logger_utils.fail('Expected error %s did not occur\n%s' %
                                  (expected_error, str(e)))
        return True
Ejemplo n.º 15
0
def update_ip_addr_ranges(start, end, access, **kwargs):
    '''

    :param start:
    :param end:
    :param access:
    :param kwargs:
    :return:
    '''
    access_object, systemconfiguration, mgmt_ip_access_control = \
        get_mgmt_access_objects(access)
    mgmt_ip_access_control = systemconfiguration.get('mgmt_ip_access_control')
    if not mgmt_ip_access_control:
        systemconfiguration['mgmt_ip_access_control'] = {}
    access_object = systemconfiguration.get('mgmt_ip_access_control').get(
        access)
    if not access_object:
        access_object = {}
    access_object['match_criteria'] = 0
    access_object['ranges'] = []
    access_object['ranges'].append({
        'begin': {
            'type': 0,
            'addr': start
        },
        'end': {
            'type': 0,
            'addr': end
        }
    })
    systemconfiguration['mgmt_ip_access_control'][access] = access_object
    rest.put('systemconfiguration', data=systemconfiguration)
Ejemplo n.º 16
0
def update_pool_network(pool_name, network, ip=None, **kwargs):
    _, json_pool_data = rest.get('pool', name=pool_name)
    if ip:
        json_pool_data['servers'][0]['ip']['addr'] = ip
    else:
        new_ip = infra_utils.get_ip_for_network(network)
        json_pool_data['servers'][0]['ip']['addr'] = new_ip
    rest.put('pool', name=pool_name, data=json_pool_data)
Ejemplo n.º 17
0
def vrf_del_ibgp_profile(vrf_name):
    """

    :param vrf_name:
    :return:
    """
    json_vrf_data = vrf_get(vrf_name)
    del json_vrf_data['bgp_profile']
    rest.put('vrfcontext', name=vrf_name, data=json_vrf_data)
Ejemplo n.º 18
0
def network_set_subnet_static_range(net_name, ip_begin_octet, ip_end_octet):
    import string
    _, json_data = rest.get('network', name=net_name)
    json_subnet_found = None
    if 'configured_subnets' not in json_data:
        json_data['configured_subnets'] = list()
    if len(json_data['configured_subnets']) > 0:
        json_subnet_found = json_data['configured_subnets'][0]
    '''
    for json_subnet in json_data['configured_subnets']:
        if (json_subnet['prefix']['ip_addr']['addr'] == subnet_ip) and \
            (json_subnet['prefix']['mask'] == subnet_mask):
            json_subnet_found = json_subnet
    '''
    config = infra_utils.get_config()
    if json_subnet_found:
        ip = json_data['configured_subnets'][0]['prefix']['ip_addr']['addr']
    else:
        for network_name, network_data in config.testbed[
                config.site_name].networks_json.iteritems():
            if net_name == network_data.get('name'):
                ip = network_data.get('ip')
                break

    ip_parts = ip.split('.')[:-1]
    subnet_ip = string.join(ip_parts, '.') + '.0'

    if not json_subnet_found:
        json_subnet = dict()
        json_subnet['prefix'] = {
            'mask': 24,
            'ip_addr': {
                'addr': subnet_ip,
                'type': 'V4'
            }
        }
        json_data['configured_subnets'].append(json_subnet)
        json_subnet_found = json_subnet
    if 'static_ranges' in json_subnet_found.keys():
        del json_subnet_found['static_ranges']
    if 'static_ips' in json_subnet_found.keys():
        del json_subnet_found['static_ips']
    json_subnet_found['static_ranges'] = list()
    ip_range_begin = string.join(ip_parts, '.') + '.' + str(ip_begin_octet)
    ip_range_end = string.join(ip_parts, '.') + '.' + str(ip_end_octet)
    json_subnet_found['static_ranges'].append({
        'begin': {
            'addr': ip_range_begin,
            'type': 'V4'
        },
        'end': {
            'addr': ip_range_end,
            'type': 'V4'
        }
    })
    rest.put('network', name=net_name, data=json_data)
Ejemplo n.º 19
0
def autoscale_lower_max_size(pool_name, **kwargs):
    """
    pass the autoscale policy settings into the kwargs
    :param pool_name:
    :param kwargs:
    :return:
    """

    _, pool_obj = rest.get('pool', name=pool_name)
    asp_ref = pool_obj['autoscale_policy_ref']
    as_policy_uuid = asp_ref.split('serverautoscalepolicy/')[1].split('#')[0]

    _, autoscale_policy = rest.get('serverautoscalepolicy',
                                   uuid=as_policy_uuid)
    logger.info('received asp %s   type %s' %
                (autoscale_policy, type(autoscale_policy)))
    orig_max_size = autoscale_policy['max_size']
    orig_min_size = autoscale_policy['min_size']

    num_servers = len(pool_obj['servers'])
    for k, v in kwargs.iteritems():
        logger.info('k,v %s,%s' % (k, v))
        autoscale_policy[k] = v
    if num_servers < 2:
        logger_utils.fail('Number of servers is less than required %d' %
                          num_servers)
    autoscale_policy['max_size'] = num_servers - 1
    autoscale_policy['min_size'] = min(autoscale_policy['min_size'],
                                       autoscale_policy['max_size'])

    asp_json = json.dumps(autoscale_policy)
    logger.info('json: %s' % asp_json)
    rc, result = rest.put('serverautoscalepolicy',
                          uuid=as_policy_uuid,
                          data=asp_json)
    logger.info('updating as_policy %s' % autoscale_policy)
    as_info = get_autoscale_info(pool_name)
    assert as_info

    logger_utils.asleep(delay=AS_WAIT_TIME)
    for _ in xrange(12):
        logger_utils.asleep(delay=10)
        _, pool_obj = rest.get('pool', name=pool_name)
        new_num_servers = len(pool_obj['servers'])
        if new_num_servers <= num_servers:
            break
    _, autoscale_policy = rest.get('serverautoscalepolicy',
                                   uuid=as_policy_uuid)
    autoscale_policy['max_size'] = orig_max_size
    autoscale_policy['min_size'] = orig_min_size
    asp_json = json.dumps(autoscale_policy)
    rc, result = rest.put('serverautoscalepolicy',
                          uuid=as_policy_uuid,
                          data=asp_json)
    logger.info('json: %s rc: %s results: %s' % (asp_json, rc, result))
    return autoscale_policy['max_size']
Ejemplo n.º 20
0
def update_se_segroup(se_uuid, sg_name, **kwargs):
    logger.info('update segroup for se:%s to sg:%s' % (se_uuid, sg_name))
    _, json_data = get('serviceengine', uuid=se_uuid, **kwargs)
    if json_data.get('results'):
        json_data = json_data['results'][0]
    sg = json_data.get('se_group_ref')
    if not sg:
        fail('ERROR! Cannot get se_group from api')
    json_data['se_group_ref'] = '/api/serviceenginegroup?name=%s' % sg_name
    put('serviceengine', uuid=se_uuid, data=json.dumps(json_data), **kwargs)
Ejemplo n.º 21
0
def vrf_add_static_route_with_nh_ip(vrf_name, prefix_ip, mask, nh_ip, route_id):
    json_data = vrf_get(vrf_name)
    json_data['static_routes'] = []
    json_data['static_routes']['route_id'] = route_id
    json_data['static_routes']['prefix']['ip_addr']['addr'] = prefix_ip
    json_data['static_routes']['prefix']['ip_addr']['type'] = 0
    json_data['static_routes']['prefix']['mask'] = int(mask)
    json_data['static_routes']['next_hop']['addr'] = nh_ip
    json_data['static_routes']['next_hop']['type'] = 0
    rest.put('vrfcontext', name=vrf_name, data=json_data)
Ejemplo n.º 22
0
def set_action_group_config_with_autoscale(agc_name, enable):
    """

    :param agc_name:
    :param enable:
    :return:
    """

    _, agc_obj = rest.get('actiongroupconfig', name=agc_name)
    agc_obj['autoscale_trigger_notification'] = enable
    rest.put('actiongroupconfig', name=agc_name, data=agc_obj)
Ejemplo n.º 23
0
    def setup_openstack_rolemapping(self, **kwargs):
        cloud_name = get_cloud_context()
        _, data = get('cloud', name=cloud_name)

        role_mapping = []
        # sort the keys to force '*' to go to the end
        for kw in sorted(kwargs.keys(), reverse=True):
            role_mapping.append({'os_role': kw, 'avi_role': kwargs[kw]})
        data['openstack_configuration']['role_mapping'] = role_mapping
        put('cloud', name=cloud_name, data=data)
        from avi_objects.infra_utils import check_cloud_state
        check_cloud_state(cloud_name=cloud_name)
Ejemplo n.º 24
0
def set_dns_vs_system_configuration(vs_name):
    """

    :param vs_name:
    :return:
    """

    status_code, response = rest.get('systemconfiguration')
    if 'dns_virtualservice_uuids' not in response:
        response['dns_virtualservice_uuids'] = []
    response['dns_virtualservice_uuids'].append(
        rest.get_uuid_by_name('virtualservice', vs_name))
    rest.put('systemconfiguration', data=response)
Ejemplo n.º 25
0
def delete_dns_system_configuration():
    """
    
    :return: 
    """

    status_code, response = rest.get('systemconfiguration')
    response['dns_virtualservice_uuids'] = []
    if 'dns_virtualservice_refs' in response:
        del response['dns_virtualservice_refs']
    rest.put('systemconfiguration', data=response)

    logger_utils.asleep(delay=5)
Ejemplo n.º 26
0
def vrf_add_static_route(vrf_name, prefix, mask, nh, route_id):
    import lib.network_lib as network_lib
    json_data = vrf_get(vrf_name)
    json_data['static_routes'] = []
    json_data['static_routes']['route_id'] = route_id
    prefix_ip = infra_utils.get_ip_for_network(prefix)
    json_data['static_routes']['prefix']['ip_addr']['addr'] = prefix_ip
    json_data['static_routes']['prefix']['ip_addr']['type'] = 0
    json_data['static_routes']['prefix']['mask'] = int(mask)
    nh_ip = infra_utils.get_ip_for_network(nh)
    json_data['static_routes']['next_hop']['addr'] = nh_ip
    json_data['static_routes']['next_hop']['type'] = 0
    rest.put('vrfcontext', name=vrf_name, data=json_data)
Ejemplo n.º 27
0
def add_network_in_ipamprofile(ipamprofile_name, network_to_add):
    ipam_status_code, ipam_status_data = rest.get('ipamdnsproviderprofile',
                                                  name=ipamprofile_name)
    networks_to_add = []
    if type(network_to_add) == list:
        for network in network_to_add:
            networks_to_add.append('/api/network/?name=%s' % network)
    else:
        networks_to_add.append('/api/network/?name=%s' % network_to_add)
    ipam_status_data['internal_profile']['usable_network_refs'].extend(
        networks_to_add)
    rest.put('ipamdnsproviderprofile',
             name=ipamprofile_name,
             data=ipam_status_data)
Ejemplo n.º 28
0
def delete_subnet_from_network(name, tenant='admin', **kwargs):
    status_code, json_data = rest.get('network', name=name)
    subnet_ip = kwargs.get('subnet_ip', None)
    subnet_mask = kwargs.get('subnet_mask', None)
    is_all_subnet = kwargs.get('remove_all', False)
    if is_all_subnet:
        json_data['configured_subnets'] = []
    else:
        subnet_mask = int(subnet_mask)
        for subnet in json_data['configured_subnets']:
            if subnet['prefix']['mask'] == subnet_mask and subnet['prefix'][
                    'ip_addr']['addr'] == subnet_ip:
                json_data['configured_subnets'].remove(subnet)
    rest.put('network', name=json_data['name'], data=json_data)
Ejemplo n.º 29
0
def add_subnet_to_network(name, **kwargs):
    status_code, json_data = rest.get('network', name=name)
    subnet_ip=kwargs.get('subnet_ip',None)
    subnet_mask=kwargs.get('subnet_mask',None)
    force = kwargs.get('force', False)
    add_configured_subnets = {'prefix': {'mask': subnet_mask, 'ip_addr': {'type': 0, 'addr': subnet_ip}}}
    if 'configured_subnets' in json_data.keys():
        json_data['configured_subnets'].append(add_configured_subnets)
    else:
        json_data['configured_subnets'] = [add_configured_subnets]
    if force:
        rest.put('network', name=json_data['name'], data=json_data, force = force)
    else:
        rest.put('network', name=json_data['name'], data=json_data)
Ejemplo n.º 30
0
def get_and_delete_all_configs(skip_cloud=False, check_status_code=False, tenant_list=[], fix_url=True, **kwargs):
    move_all_se_to_group('Default-Group')

    session = get_session()
    config = AviConfig.get_instance()
    defaults = get('default-values').json()
    logger.info(defaults)
    tenant_resp = get('tenant').json()
    if not tenant_list:
        tenants = []
        tenants = [str(entry['name']) for entry in tenant_resp.get('results', [])]
    else:
        tenants = tenant_list

    for _tenant in tenants:
        switch_mode(tenant=_tenant)
        for obj_type in reversed(obj_order):
            if (((obj_type == 'cloud' or obj_type == 'tenant') and skip_cloud) or
                    (obj_type in ['sslcertificaterequest', 'staticroute'])):
                continue
            status_code, data = get(obj_type, check_status_code=check_status_code)
            if status_code > 400:
                continue
            for d in data['results']:
                if obj_type == 'cloud' and d['name'] == 'Default-Cloud':
                    if d['vtype'] != 'CLOUD_NONE':
                        logger.info('Update Default-Cloud from %s to no-access' % d['vtype'])
                        if d.get('vcenter_configuration'):
                            d.pop('vcenter_configuration')
                        elif d.get('openstack_configuration'):
                            d.pop('openstack_configuration')
                        elif d.get('aws_configuration'):
                            d.pop('aws_configuration')
                        elif d.get('cloudstack_configuration'):
                            d.pop('cloudstack_configuration')
                        elif d.get('vca_configuration'):
                            d.pop('vca_configuration')
                        elif d.get('apic_configuration'):
                            d.pop('apic_configuration')
                        d['vtype'] = 'CLOUD_NONE'
                        put('cloud', name=d['name'], data=json.dumps(d))  # review can we use uuid=d['uuid']?
                if obj_type in defaults.get('default', []) and \
                                d['uuid'] in defaults['default'][obj_type]:
                    continue
                logger.info('Deleting: %s:%s' % (obj_type, d['name']))
                if obj_type in ['sslcertificaterequest', 'sslkeyandcertificate_import']:
                    delete('sslkeyandcertificate', name=d['name'], check_status_code=False)
                else:
                    delete(obj_type, name=d['name'], check_status_code=False)