コード例 #1
0
def mount_device(
    device_name,
    device_address,
    device_port,
    device_username,
    device_password
):
    request_content = _request_content_template % (device_name, device_address, device_port, device_username, device_password)
    odl_http_post(_bgp_url_suffix, 'application/xml', request_content)
コード例 #2
0
def static_route_create(device_name, destination_network, prefix_len, next_hop_address):

    route_list = static_route_json(device_name)
    for route in route_list:
        if route["prefix"] == destination_network:
            print("static_route_delete(%s, %s)" % (device_name, destination_network))
            static_route_delete(device_name, destination_network, prefix_len)
            break

    """ Create the specified 'static route' on the specified network device. """
    next_hop = {"next-hop-address": str(next_hop_address)}
    request_content = {
        "Cisco-IOS-XR-ip-static-cfg:vrf-prefix": [
            {
                "prefix": destination_network,
                "prefix-length": prefix_len,
                "vrf-route": {"vrf-next-hops": {"next-hop-address": [next_hop]}},
            }
        ]
    }
    print("static_route_create(%s, %s, %s)" % (device_name, destination_network, next_hop_address))
    response = odl_http_post(
        _static_route_url_template,
        {"node-id": device_name},
        "application/json",
        request_content,
        expected_status_code=[204, 409],
    )
    if response.status_code == 204:
        return True
    else:
        return False
        """
コード例 #3
0
def static_route_create2(device, destination_address,prefixlen, next_address, description=None):
    """ Create the specified 'static route' on the specified network device. """
    next_hop = {"next-hop-address" : str(next_address)}
    if description:
        next_hop["description"] = description

    request_content = {
        "Cisco-IOS-XR-ip-static-cfg:vrf-prefix": [
            {
                "prefix" : str(destination_address),
                "prefix-length": prefixlen,
                "vrf-route" : {
                    "vrf-next-hops" : {
                        "next-hop-address" : [next_hop]
                    }
                }
            }
        ]
    }
    response = odl_http_post(_static_route_url_template, {'node-id' : device}, 'application/json', request_content, expected_status_code=[204, 409,400])
    if response.status_code == 409:
        try:
            raise ValueError(response.json()['errors']['error'][0]['error-message'])
        except IndexError:
            pass
        except KeyError:
            pass
        raise ValueError('Already exists: static route to destination network %s on device %s' % (destination_address, device))
コード例 #4
0
def mount(node_id, device_address, device_port, device_username, device_password):
    """Add the specified network device to the topology of the Controller."""
    request_url = _url_mount.format(**{'config': 'config', 
                                       'topology-id': 'topology-netconf',
                                       })
    request_content = mountRequestJSON(node_id, device_address, device_port, device_username, device_password)
    return odl_http_post(request_url, {}, 'application/json', request_content)
コード例 #5
0
ファイル: routes.py プロジェクト: ingtiti/cosc-learning-labs
def static_route_create(device_name, destination_network, next_hop_address, description=None):
    """ Create the specified 'static route' on the specified network device. """
    next_hop = {"next-hop-address": str(next_hop_address)}
    if description:
        next_hop["description"] = description

    request_content = {
        "Cisco-IOS-XR-ip-static-cfg:vrf-prefix": [
            {
                "prefix": str(destination_network.network_address),
                "prefix-length": destination_network.prefixlen,
                "vrf-route": {"vrf-next-hops": {"next-hop-address": [next_hop]}},
            }
        ]
    }
    response = odl_http_post(
        _static_route_url_template,
        {"node-id": device_name},
        "application/json",
        request_content,
        expected_status_code=[204, 409],
    )
    if response.status_code == 409:
        try:
            raise ValueError(response.json()["errors"]["error"][0]["error-message"])
        except IndexError:
            pass
        except KeyError:
            pass
        raise ValueError(
            "Already exists: static route to destination network %s on device %s" % (destination_network, device_name)
        )
コード例 #6
0
ファイル: routes.py プロジェクト: CTOCHN/cosc-learning-labs
def static_route_create(device_name, destination_network, next_hop_address, description=None):
    """ Create the specified 'static route' on the specified network device. """
    if not description:
        description = 'static route to %s via %s' % (destination_network , next_hop_address)
    request_content = _static_route_content_template % (destination_network.network_address, destination_network.prefixlen, next_hop_address, description)
    url_suffix = _static_route_url_template % device_name
    return odl_http_post(url_suffix, contentType='application/json', content=request_content)
コード例 #7
0
def main():
    if not settings:
        print('Settings must be configured', file=stderr)
    
    render.print_table(odl_http.coordinates)
    print()
    
    config = {"config:module" : [
                        {
                        "type": "lldp-speaker:lldp-speaker",
                        "name": "lldp-speaker",
                        "lldp-speaker:address-destination": "01:23:00:00:00:00",
                        "lldp-speaker:rpc-registry":{
                                                        "name": "binding-rpc-broker",
                                                        "type": "opendaylight-md-sal-binding:binding-rpc-registry"
                                                    },
                        "lldp-speaker:data-broker": {
                                                        "name": "binding-data-broker",
                                                        "type": "opendaylight-md-sal-binding:binding-async-data-broker"
                                                    }
                        }
                        ]
    }
    
    config_str = json.dumps(config)
    try:
        response = odl_http_post(
                      url_suffix='operational/opendaylight-inventory:nodes/node/openflow:1',
                      url_params={},
                      contentType='application/json',
                      content=config_str)
        print(response)
    except Exception as e:
        print(e, file=stderr)
コード例 #8
0
def add_route_grant(device_name, prefix_address):
    request_content = _request_content_route_add_template % (prefix_address)
    response = odl_http_post(_url_template_route, {'node-id': device_name},
                             'application/json',
                             request_content,
                             expected_status_code=[204, 409])
    if response.status_code != 204:
        raise Exception(_error_message(response.json()))
コード例 #9
0
def add_route_grant(
    device_name,
    prefix_address
):
    request_content = _request_content_route_add_template % (prefix_address)
    response = odl_http_post(_url_template_route, {'node-id' : device_name}, 'application/json', request_content, expected_status_code=[204, 409])
    if response.status_code != 204:
        raise Exception(_error_message(response.json()))
コード例 #10
0
def device_mount_http(
    device_name,
    device_address,
    device_port,
    device_username,
    device_password
):
    request_content = _request_content_mount_template % (device_name, device_address, device_port, device_username, device_password)
    return odl_http_post(_url_mount, {}, 'application/xml', request_content)
コード例 #11
0
def acl_apply_packet_filter(device_name, interface_name, bound, acl_name):
    request_content = _request_content_acl_packet_filter_template % (
        interface_name, bound, acl_name)
    #     print url_suffix
    #     print json.dumps(json.loads(request_content),indent=2)
    response = odl_http_post(_url_apply_template, {'node-id': device_name},
                             'application/json', request_content)
    if response.status_code != 204:
        raise Exception(response.text)
コード例 #12
0
def acl_create_port_grant(device_name, acl_name, port, grant, protocol):
    request_content = _request_content_acl_port_grant_template % (
        grant, port.strip(), quote_plus(acl_name))
    response = odl_http_post(_url_template, {'node-id': device_name},
                             'application/json',
                             request_content,
                             expected_status_code=[204, 409])
    if response.status_code != 204:
        raise Exception(_error_message(response.json()))
コード例 #13
0
def cdp_enable_interface(device_name, interface_name):
    '''
        Description:
            This function will enable the cdp for every interface on device.
            
    '''
    url_suffix = _cdp_enable_interface_url_suffix.format(**{'node-id': quote_plus(device_name), })
    request_content = _cdp_enable_interface_request_content % (interface_name,_MAXMIUM_BANDWIDTH)
    return odl_http_post(url_suffix, 'application/json', request_content)
コード例 #14
0
def device_mount_http(
    device_name,
    device_address,
    device_port,
    device_username,
    device_password
):
    request_content = _request_content_mount_template % (device_name, device_address, device_port, device_username, device_password)
    return odl_http_post(_url_mount, 'application/xml', request_content)
コード例 #15
0
def mount(node_id, device_address, device_port, device_username,
          device_password):
    """Add the specified network device to the topology of the Controller."""
    request_url = _url_mount.format(**{
        'config': 'config',
        'topology-id': 'topology-netconf',
    })
    request_content = mountRequestJSON(node_id, device_address, device_port,
                                       device_username, device_password)
    return odl_http_post(request_url, {}, 'application/json', request_content)
コード例 #16
0
def acl_create_port_grant(device_name, acl_name, port, grant, protocol):
    request_content = _request_content_acl_port_grant_template % (
        quote_plus(acl_name), port, grant, protocol)
    url_suffix = _url_template % quote_plus(device_name)
    response = odl_http_post(url_suffix,
                             'application/json',
                             request_content,
                             expected_status_code=[204, 409])
    if response.status_code != 204:
        raise Exception(_error_message(response.json()))
コード例 #17
0
def acl_create_port_grant(
    device_name,
    acl_name,
    port,
    grant,
    protocol
):
    request_content = _request_content_acl_port_grant_template % (grant, port.strip(), quote_plus(acl_name))
    response = odl_http_post(_url_template, {'node-id' : device_name}, 'application/json', request_content, expected_status_code=[204, 409])
    if response.status_code != 204:
        raise Exception(_error_message(response.json()))
コード例 #18
0
ファイル: acl.py プロジェクト: CTOCHN/cosc-learning-labs
def acl_create_port_grant(
    device_name,
    acl_name,
    port,
    grant,
    protocol
):
    request_content = _request_content_acl_port_grant_template % (quote_plus(acl_name), port, grant, protocol)
    url_suffix = _url_template % quote_plus(device_name)
    response = odl_http_post(url_suffix, 'application/json', request_content, expected_status_code=[204, 409])
    if response.status_code != 204:
        raise Exception(_error_message(response.json()))
コード例 #19
0
def acl_apply_packet_filter(
    device_name,
    interface_name,
    bound,
    acl_name
):
    request_content = _request_content_acl_packet_filter_template % (interface_name, bound, acl_name)
#     print url_suffix
#     print json.dumps(json.loads(request_content),indent=2)
    response = odl_http_post(_url_apply_template, {'node-id' : device_name}, 'application/json', request_content)
    if response.status_code != 204:
        raise Exception(response.text)
コード例 #20
0
def cdp_enable_interface(device_name, interface_name):
    '''
        Description:
            This function will enable the cdp for every interface on device.
            
    '''
    url_suffix = _cdp_enable_interface_url_suffix.format(
        **{
            'node-id': quote_plus(device_name),
        })
    request_content = _cdp_enable_interface_request_content % (
        interface_name, _MAXMIUM_BANDWIDTH)
    return odl_http_post(url_suffix, 'application/json', request_content)
コード例 #21
0
def pcep_update_lsp():
    request_content = {
        "input": {
            "node": "pcc://27.27.27.27",
            "name": "FC2DC",
            "network-topology-ref":
            "/network-topology:network-topology/network-topology:topology[network-topology:topology-id=\"pcep-topology\"]",
            "arguments": {
                "pcep-ietf-stateful:lsp": {
                    "administrative": "true",
                    "delegate": "true"
                },
                "ero": {
                    "subobject": [{
                        "loose": "false",
                        "ip-prefix": {
                            "ip-prefix": "48.0.0.22/32"
                        }
                    }, {
                        "loose": "false",
                        "ip-prefix": {
                            "ip-prefix": "49.0.0.30/32"
                        }
                    }, {
                        "loose": "false",
                        "ip-prefix": {
                            "ip-prefix": "56.0.0.29/32"
                        }
                    }, {
                        "loose": "false",
                        "ip-prefix": {
                            "ip-prefix": "1.2.3.4/32"
                        }
                    }]
                }
            }
        }
    }

    response = odl_http_post(
        url_suffix="operations/network-topology-pcep:update-lsp",
        url_params={},
        contentType="application/json",
        content=request_content,
        accept='application/json',
        expected_status_code=200)
    print response
コード例 #22
0
ファイル: pod8.py プロジェクト: CTOCHN/cosc-learning-labs
def demonstrate(device_name):
    url_suffix = _url_template % quote_plus(device_name)
    contentType = 'application/json'
    accept = contentType
    expected_status_code = [204, 409]
    source_address = '1.0.0.0'
    source_wild_card_bits = '0.255.255.255'
    next_hop = '4.3.2.1'
    access_list_name = quote_plus('policy-route-http')
    content = _acl_route_request_content % (access_list_name, source_wild_card_bits, source_address, next_hop)
    print('acl_next_hop(%s)'%device_name)
    response = odl_http_post(url_suffix, contentType, content, accept, expected_status_code)
    if response.status_code != 204:
        print(response)
    else:
        print('ACLs:', acl_list(device_name))
        print(json.dumps(acl_json(device_name, access_list_name), indent=2))
コード例 #23
0
def pcep_update_lsp():
    request_content = {
        "input" : {
            "node" : "pcc://27.27.27.27",
            "name" : "FC2DC",
            "network-topology-ref": "/network-topology:network-topology/network-topology:topology[network-topology:topology-id=\"pcep-topology\"]",
            "arguments": {
                "pcep-ietf-stateful:lsp": {
                    "administrative": "true",
                    "delegate": "true"
                },
                "ero" : {
                    "subobject" : [
                        {
                            "loose" : "false",
                            "ip-prefix" : { "ip-prefix" : "48.0.0.22/32" }
                        },
                        {
                            "loose" : "false",
                            "ip-prefix" : { "ip-prefix" : "49.0.0.30/32" }
                        },
                        {
                            "loose" : "false",
                            "ip-prefix" : { "ip-prefix" : "56.0.0.29/32" }
                        },
                                            {
                            "loose" : "false",
                            "ip-prefix" : { "ip-prefix" : "1.2.3.4/32" }
                        }
                    ]
                }
            }
        }
    }
        
    
    response = odl_http_post(
        url_suffix = "operations/network-topology-pcep:update-lsp",
        url_params={},
        contentType = "application/json",
        content = request_content,
        accept='application/json',
        expected_status_code = 200
        )
    print response
コード例 #24
0
def demonstrate(device_name):
    url_suffix = _url_template % quote_plus(device_name)
    contentType = 'application/json'
    accept = contentType
    expected_status_code = [204, 409]
    source_address = '1.0.0.0'
    source_wild_card_bits = '0.255.255.255'
    next_hop = '4.3.2.1'
    access_list_name = quote_plus('policy-route-http')
    content = _acl_route_request_content % (
        access_list_name, source_wild_card_bits, source_address, next_hop)
    print('acl_next_hop(%s)' % device_name)
    response = odl_http_post(url_suffix, contentType, content, accept,
                             expected_status_code)
    if response.status_code != 204:
        print(response)
    else:
        print('ACLs:', acl_list(device_name))
        print(json.dumps(acl_json(device_name, access_list_name), indent=2))
コード例 #25
0
def static_route_create2(device,
                         destination_address,
                         prefixlen,
                         next_address,
                         description=None):
    """ Create the specified 'static route' on the specified network device. """
    next_hop = {"next-hop-address": str(next_address)}
    if description:
        next_hop["description"] = description

    request_content = {
        "Cisco-IOS-XR-ip-static-cfg:vrf-prefix": [{
            "prefix":
            str(destination_address),
            "prefix-length":
            prefixlen,
            "vrf-route": {
                "vrf-next-hops": {
                    "next-hop-address": [next_hop]
                }
            }
        }]
    }
    response = odl_http_post(_static_route_url_template, {'node-id': device},
                             'application/json',
                             request_content,
                             expected_status_code=[204, 409, 400])
    if response.status_code == 409:
        try:
            raise ValueError(
                response.json()['errors']['error'][0]['error-message'])
        except IndexError:
            pass
        except KeyError:
            pass
        raise ValueError(
            'Already exists: static route to destination network %s on device %s'
            % (destination_address, device))
コード例 #26
0
def cdp_enable_interface(device_name, interface_name):
    print('cdp_enable_interface(%s,%s)' % (device_name, interface_name))
    request_content = _cdp_enable_interface_request_content % (interface_name)
    return odl_http_post(_cdp_enable_interface_url_suffix, {'node-id': device_name}, 'application/json', request_content)
コード例 #27
0
ファイル: cdp.py プロジェクト: CTOCHN/cosc-learning-labs
def cdp_enable_interface(device_name, interface_name):
    print('cdp_enable_interface(%s,%s)' % (device_name, interface_name))
    url_suffix = _cdp_enable_interface_url_suffix.format(**{'node-id': quote_plus(device_name), })
    request_content = _cdp_enable_interface_request_content % (interface_name)
    return odl_http_post(url_suffix, 'application/json', request_content)
コード例 #28
0
_static_route_url_template = 'config/opendaylight-inventory:nodes/node/{node-id}/yang-ext:mount/Cisco-IOS-XR-ip-static-cfg:router-static/default-vrf/address-family/vrfipv4/vrf-unicast/vrf-prefixes'

if __name__ == '__main__':
    '''
    response = odl_http_get('config/sjtest:sjtest',accept='application/json', expected_status_code=200)
    print("the response is :"+response.text)
    
    request_content = "{'sjtest' : {'count' : 1} }"
    res = odl_http_post('config/sjtest:sjtest', {}, 'application/json', {'sjtest' : {'count' : 1} })
    print("the res is :"+res.text)
    '''
    
    #create static route :  iosxrv-1   iosxrv-5
    device_name1 = 'iosxrv-1'
    request_content1 = {'Cisco-IOS-XR-ip-static-cfg:vrf-prefix': [{'prefix': '27.27.27.27', 'vrf-route': {'vrf-next-hops': {'next-hop-address': [{'next-hop-address': '45.0.0.27'}]}}, 'prefix-length': 32}]}
    response1 = odl_http_post(_static_route_url_template, {'node-id' : device_name1}, 'application/json', request_content1, expected_status_code=[204, 409])
    
    device_name5 = 'iosxrv-5'
    request_content5 = {'Cisco-IOS-XR-ip-static-cfg:vrf-prefix': [{'prefix': '21.21.21.21', 'vrf-route': {'vrf-next-hops': {'next-hop-address': [{'next-hop-address': '45.0.0.21'}]}}, 'prefix-length': 32}]}
    response5 = odl_http_post(_static_route_url_template, {'node-id' : device_name5}, 'application/json', request_content5, expected_status_code=[204, 409])
    
    #read interface state for every 5 second
    count = 0
    for i in range(0,9):
        flag = True
        for device_name in topology.connected_nodes():
            #print('%s:' % device_name)
            
            if device_name == "iosxrv-1":
                for interface_name in topology_interface.interface_names(device_name):
                    #print('Interface Properties for %s:' % interface_name)
コード例 #29
0
def cdp_enable_interface(device_name, interface_name):
    print('cdp_enable_interface(%s,%s)' % (device_name, interface_name))
    request_content = _cdp_enable_interface_request_content % (interface_name)
    return odl_http_post(_cdp_enable_interface_url_suffix,
                         {'node-id': device_name}, 'application/json',
                         request_content)