def add_lbr_to_nsx_edge(nsx_edges_dir, nsx_edge):

    template_dir = '.'

    iso_zones = nsx_edge['iso_zones']
    app_profiles = nsx_edge['app_profiles']
    ert_certId = nsx_edge['cert_id']

    # Link the iso cert id against the corresponding app profiles,
    # if they are using any ssl/secure protocol and are associated
    # with Ert or IsoZone switches
    for app_profile in app_profiles:
        switch_name = app_profile.get('switch')
        app_profile_name = app_profile['name']

        if app_profile['requires_cert']:
            if switch_name and 'ISOZONE' in switch_name.upper():
                for iso_zone in iso_zones:
                    if switch_name == iso_zone['name']:
                        app_profile['cert_id'] = iso_zone['cert_id']
                        continue
            # Use the same ert cert id for those not associated with any switches too
            else:  #if not switch_name or (switch_name and 'ERT' in switch_name.upper()):
                app_profile['cert_id'] = ert_certId
                continue

    nsx_edges_context = {
        'nsx_edge': nsx_edge,
        'app_profiles': app_profiles,
        'app_rules': nsx_edge['app_rules'],
        'monitor_list': nsx_edge['monitor_list'],
        'routed_components': nsx_edge['routed_components'],
        'files': []
    }

    template.render(
        os.path.join(nsx_edges_dir,
                     nsx_edge['name'] + '_lbr_config_put_payload.xml'),
        os.path.join(template_dir, 'edge_lbr_config_put_payload.xml'),
        nsx_edges_context)

    put_response = client.put_xml(
        NSX_URLS['esg']['all'] + '/' + nsx_edge['id'] +
        NSX_URLS['lbrConfig']['all'],
        os.path.join(nsx_edges_dir,
                     nsx_edge['name'] + '_lbr_config_put_payload.xml'),
        check=False)
    data = put_response.text

    if DEBUG:
        print('NSX Edge LBR Config Update response:{}\n'.format(data))

    if put_response.status_code < 400:
        print('Updated NSX Edge LBR Config for : {}\n'.format(
            nsx_edge['name']))
    else:
        print(
            'Update of NSX Edge LBR Config failed, details:{}\n'.format(data))
        raise Exception(
            'Update of NSX Edge LBR Config failed, details:\n {}'.format(data))
def add_ospf_to_nsx_dlr(nsx_dlrs_dir, context, nsx_dlr):

    map_nsx_esg_id([nsx_dlr])

    template_dir = '.'
    logical_switches = context['logical_switches']

    for lswitch in logical_switches:
        switch_name_upper = lswitch['name'].upper()
        if 'OSPF' in switch_name_upper:
            ospfLogicalSwitch = lswitch

    disable_ospf = False
    static_routes = nsxmanager['static_routes']
    disable_ospf = (static_routes is not None and len(static_routes) > 0)

    nsx_dlrs_context = {
        'context': context,
        'defaults': context['defaults'],
        'nsxmanager': context['nsxmanager'],
        'dlr': nsx_dlr,
        'logical_switches': logical_switches,
        'ospfLogicalSwitch': ospfLogicalSwitch,
        'disable_ospf': disable_ospf,
        'gateway_address': nsx_dlr['gateway_ip'],
        'files': []
    }

    template.render(
        os.path.join(nsx_dlrs_dir,
                     nsx_dlr['name'] + '_dlr_config_put_payload.xml'),
        os.path.join(template_dir, 'dlr_config_put_payload.xml'),
        nsx_dlrs_context)

    put_response = client.put_xml(
        NSX_URLS['esg']['all'] + '/' + nsx_dlr['id'],
        os.path.join(nsx_dlrs_dir,
                     nsx_dlr['name'] + '_dlr_config_put_payload.xml'),
        check=False)
    data = put_response.text

    if DEBUG:
        print('NSX DLR Config Update response:{}\n'.format(data))

    if put_response.status_code < 400:
        print('Updated NSX DLR Config for : {}\n'.format(nsx_dlr['name']))
    else:
        print('Update of NSX DLR Config failed, details:{}\n'.format(data))
        raise Exception(
            'Update of NSX DLR Config failed, details:\n {}'.format(data))
def add_lbr_to_nsx_edge_with_no_certs(nsx_edges_dir, nsx_edge):

    template_dir = '.'
    map_nsx_esg_id([nsx_edge])

    iso_zones = nsx_edge['iso_zones']
    app_profiles = nsx_edge['app_profiles']

    # Link the iso cert id against the corresponding app profiles,
    # if they are using any ssl/secure protocol and are associated
    # with Ert or IsoZone switches
    for app_profile in app_profiles:
        switch_name = app_profile.get('switch')
        app_profile_name = app_profile['name']

    nsx_edges_context = {
        'nsx_edge': nsx_edge,
        'app_profiles': app_profiles,
        'app_rules': nsx_edge['app_rules'],
        'monitor_list': nsx_edge['monitor_list'],
        'routed_components': nsx_edge['routed_components'],
        'files': []
    }

    template.render(
        os.path.join(nsx_edges_dir,
                     nsx_edge['name'] + '_lbr_config_put_payload.xml'),
        os.path.join(template_dir, 'edge_lbr_config_put_payload.xml'),
        nsx_edges_context)

    put_response = client.put_xml(
        NSX_URLS['esg']['all'] + '/' + nsx_edge['id'] +
        NSX_URLS['lbrConfig']['all'],
        os.path.join(nsx_edges_dir,
                     nsx_edge['name'] + '_lbr_config_put_payload.xml'),
        check=False)
    data = put_response.text

    if DEBUG:
        print('NSX Edge LBR Config Update response:{}\n'.format(data))

    if put_response.status_code < 400:
        print('Updated NSX Edge LBR Config for : {}\n'.format(
            nsx_edge['name']))
    else:
        print(
            'Update of NSX Edge LBR Config failed, details:{}\n'.format(data))
        raise Exception(
            'Update of NSX Edge LBR Config failed, details:\n {}'.format(data))
Example #4
0
def add_ospf_to_nsx_dlr(nsx_dlrs_dir, context, nsx_dlr):

    map_nsx_esg_id( [ nsx_dlr ] )

    template_dir = '.'
    logical_switches = context['logical_switches']
    
    nsx_dlrs_context = {
        'context': context,
        'defaults': context['defaults'],
        'nsxmanager': context['nsxmanager'],
        'dlr': nsx_dlr,
        'logical_switches': logical_switches,
        'gateway_address': nsx_dlr['gateway_ip'],
        'files': []
    }    


    template.render(
        os.path.join(nsx_dlrs_dir, nsx_dlr['name'] + '_dlr_config_put_payload.xml'),
        os.path.join(template_dir, 'dlr_config_put_payload.xml' ),
        nsx_dlrs_context
    )

    put_response = client.put_xml(NSX_URLS['esg']['all'] 
                                    + '/' + nsx_dlr['id'], 
                                    os.path.join(nsx_dlrs_dir, nsx_dlr['name'] 
                                    + '_dlr_config_put_payload.xml'), 
                                check=False)
    data = put_response.text

    if DEBUG:
        print('NSX DLR Config Update response:{}\n'.format(data))

    if put_response.status_code < 400: 
        print('Updated NSX DLR Config for : {}\n'.format(nsx_dlr['name']))      
    else:
        print('Update of NSX DLR Config failed, details:{}\n'.format(data))
        raise Exception('Update of NSX DLR Config failed, details:\n {}'.format(data))