Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sample apps for SR mapping configuration
Includes four boilerplate apps and five custom apps to configure segment routing SID mappings (IPv4 and IPv6): nc-create-xr-segment-routing-ms-cfg-10-ydk.py - create boilerplate nc-create-xr-segment-routing-ms-cfg-20-ydk.py - IPv4 single mapping nc-create-xr-segment-routing-ms-cfg-21-ydk.py - IPv6 single mapping nc-create-xr-segment-routing-ms-cfg-22-ydk.py - IPv4 multiple mappings nc-create-xr-segment-routing-ms-cfg-23-ydk.py - IPv6 multiple mappings nc-delete-xr-segment-routing-ms-cfg-10-ydk.py - delete boilerplate nc-delete-xr-segment-routing-ms-cfg-20-ydk.py - delete all mapping cfg nc-read-xr-segment-routing-ms-cfg-10-ydk.py - read boilerplate nc-update-xr-segment-routing-ms-cfg-10-ydk.py - update boilerplate
- Loading branch information
Showing
17 changed files
with
882 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
...-ios-xr/Cisco-IOS-XR-segment-routing-ms-cfg/nc-create-xr-segment-routing-ms-cfg-10-ydk.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright 2016 Cisco Systems, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
""" | ||
Create configuration for model Cisco-IOS-XR-segment-routing-ms-cfg. | ||
usage: nc-create-xr-segment-routing-ms-cfg-10-ydk.py [-h] [-v] device | ||
positional arguments: | ||
device NETCONF device (ssh://user:password@host:port) | ||
optional arguments: | ||
-h, --help show this help message and exit | ||
-v, --verbose print debugging messages | ||
""" | ||
|
||
from argparse import ArgumentParser | ||
from urlparse import urlparse | ||
|
||
from ydk.services import CRUDService | ||
from ydk.providers import NetconfServiceProvider | ||
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_segment_routing_ms_cfg \ | ||
as xr_segment_routing_ms_cfg | ||
import logging | ||
|
||
|
||
def config_sr(sr): | ||
"""Add config data to sr object.""" | ||
pass | ||
|
||
|
||
if __name__ == "__main__": | ||
"""Execute main program.""" | ||
parser = ArgumentParser() | ||
parser.add_argument("-v", "--verbose", help="print debugging messages", | ||
action="store_true") | ||
parser.add_argument("device", | ||
help="NETCONF device (ssh://user:password@host:port)") | ||
args = parser.parse_args() | ||
device = urlparse(args.device) | ||
|
||
# log debug messages if verbose argument specified | ||
if args.verbose: | ||
logger = logging.getLogger("ydk") | ||
logger.setLevel(logging.DEBUG) | ||
handler = logging.StreamHandler() | ||
formatter = logging.Formatter(("%(asctime)s - %(name)s - " | ||
"%(levelname)s - %(message)s")) | ||
handler.setFormatter(formatter) | ||
logger.addHandler(handler) | ||
|
||
# create NETCONF provider | ||
provider = NetconfServiceProvider(address=device.hostname, | ||
port=device.port, | ||
username=device.username, | ||
password=device.password, | ||
protocol=device.scheme) | ||
# create CRUD service | ||
crud = CRUDService() | ||
|
||
sr = xr_segment_routing_ms_cfg.Sr() # create object | ||
config_sr(sr) # add object configuration | ||
|
||
# create configuration on NETCONF device | ||
# crud.create(provider, sr) | ||
|
||
provider.close() | ||
exit() | ||
# End of script |
88 changes: 88 additions & 0 deletions
88
...-ios-xr/Cisco-IOS-XR-segment-routing-ms-cfg/nc-create-xr-segment-routing-ms-cfg-20-ydk.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright 2016 Cisco Systems, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
""" | ||
Create configuration for model Cisco-IOS-XR-segment-routing-ms-cfg. | ||
usage: nc-create-xr-segment-routing-ms-cfg-20-ydk.py [-h] [-v] device | ||
positional arguments: | ||
device NETCONF device (ssh://user:password@host:port) | ||
optional arguments: | ||
-h, --help show this help message and exit | ||
-v, --verbose print debugging messages | ||
""" | ||
|
||
from argparse import ArgumentParser | ||
from urlparse import urlparse | ||
|
||
from ydk.services import CRUDService | ||
from ydk.providers import NetconfServiceProvider | ||
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_segment_routing_ms_cfg \ | ||
as xr_segment_routing_ms_cfg | ||
import logging | ||
|
||
|
||
def config_sr(sr): | ||
"""Add config data to sr object.""" | ||
mapping = sr.mappings.Mapping() | ||
mapping.af = "ipv4" | ||
mapping.ip = "172.16.255.1" | ||
mapping.mask = 32 | ||
mapping.sid_start = 4041 | ||
mapping.sid_range = 1 | ||
sr.mappings.mapping.append(mapping) | ||
|
||
if __name__ == "__main__": | ||
"""Execute main program.""" | ||
parser = ArgumentParser() | ||
parser.add_argument("-v", "--verbose", help="print debugging messages", | ||
action="store_true") | ||
parser.add_argument("device", | ||
help="NETCONF device (ssh://user:password@host:port)") | ||
args = parser.parse_args() | ||
device = urlparse(args.device) | ||
|
||
# log debug messages if verbose argument specified | ||
if args.verbose: | ||
logger = logging.getLogger("ydk") | ||
logger.setLevel(logging.DEBUG) | ||
handler = logging.StreamHandler() | ||
formatter = logging.Formatter(("%(asctime)s - %(name)s - " | ||
"%(levelname)s - %(message)s")) | ||
handler.setFormatter(formatter) | ||
logger.addHandler(handler) | ||
|
||
# create NETCONF provider | ||
provider = NetconfServiceProvider(address=device.hostname, | ||
port=device.port, | ||
username=device.username, | ||
password=device.password, | ||
protocol=device.scheme) | ||
# create CRUD service | ||
crud = CRUDService() | ||
|
||
sr = xr_segment_routing_ms_cfg.Sr() # create object | ||
config_sr(sr) # add object configuration | ||
|
||
# create configuration on NETCONF device | ||
crud.create(provider, sr) | ||
|
||
provider.close() | ||
exit() | ||
# End of script |
11 changes: 11 additions & 0 deletions
11
...ios-xr/Cisco-IOS-XR-segment-routing-ms-cfg/nc-create-xr-segment-routing-ms-cfg-20-ydk.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
!! IOS XR Configuration version = 6.1.2 | ||
segment-routing | ||
mapping-server | ||
prefix-sid-map | ||
address-family ipv4 | ||
172.16.255.1/32 4041 range 1 | ||
! | ||
! | ||
! | ||
! | ||
end |
12 changes: 12 additions & 0 deletions
12
...ios-xr/Cisco-IOS-XR-segment-routing-ms-cfg/nc-create-xr-segment-routing-ms-cfg-20-ydk.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<sr xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-segment-routing-ms-cfg"> | ||
<mappings> | ||
<mapping> | ||
<af>ipv4</af> | ||
<ip>172.16.255.1</ip> | ||
<mask>32</mask> | ||
<sid-range>1</sid-range> | ||
<sid-start>4041</sid-start> | ||
</mapping> | ||
</mappings> | ||
</sr> | ||
|
89 changes: 89 additions & 0 deletions
89
...-ios-xr/Cisco-IOS-XR-segment-routing-ms-cfg/nc-create-xr-segment-routing-ms-cfg-21-ydk.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright 2016 Cisco Systems, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
""" | ||
Create configuration for model Cisco-IOS-XR-segment-routing-ms-cfg. | ||
usage: nc-create-xr-segment-routing-ms-cfg-21-ydk.py [-h] [-v] device | ||
positional arguments: | ||
device NETCONF device (ssh://user:password@host:port) | ||
optional arguments: | ||
-h, --help show this help message and exit | ||
-v, --verbose print debugging messages | ||
""" | ||
|
||
from argparse import ArgumentParser | ||
from urlparse import urlparse | ||
|
||
from ydk.services import CRUDService | ||
from ydk.providers import NetconfServiceProvider | ||
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_segment_routing_ms_cfg \ | ||
as xr_segment_routing_ms_cfg | ||
import logging | ||
|
||
|
||
def config_sr(sr): | ||
"""Add config data to sr object.""" | ||
mapping = sr.mappings.Mapping() | ||
mapping.af = "ipv6" | ||
mapping.ip = "2001:db8::ff:1" | ||
mapping.mask = 128 | ||
mapping.sid_start = 4061 | ||
mapping.sid_range = 1 | ||
sr.mappings.mapping.append(mapping) | ||
|
||
|
||
if __name__ == "__main__": | ||
"""Execute main program.""" | ||
parser = ArgumentParser() | ||
parser.add_argument("-v", "--verbose", help="print debugging messages", | ||
action="store_true") | ||
parser.add_argument("device", | ||
help="NETCONF device (ssh://user:password@host:port)") | ||
args = parser.parse_args() | ||
device = urlparse(args.device) | ||
|
||
# log debug messages if verbose argument specified | ||
if args.verbose: | ||
logger = logging.getLogger("ydk") | ||
logger.setLevel(logging.DEBUG) | ||
handler = logging.StreamHandler() | ||
formatter = logging.Formatter(("%(asctime)s - %(name)s - " | ||
"%(levelname)s - %(message)s")) | ||
handler.setFormatter(formatter) | ||
logger.addHandler(handler) | ||
|
||
# create NETCONF provider | ||
provider = NetconfServiceProvider(address=device.hostname, | ||
port=device.port, | ||
username=device.username, | ||
password=device.password, | ||
protocol=device.scheme) | ||
# create CRUD service | ||
crud = CRUDService() | ||
|
||
sr = xr_segment_routing_ms_cfg.Sr() # create object | ||
config_sr(sr) # add object configuration | ||
|
||
# create configuration on NETCONF device | ||
crud.create(provider, sr) | ||
|
||
provider.close() | ||
exit() | ||
# End of script |
11 changes: 11 additions & 0 deletions
11
...ios-xr/Cisco-IOS-XR-segment-routing-ms-cfg/nc-create-xr-segment-routing-ms-cfg-21-ydk.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
!! IOS XR Configuration version = 6.1.2 | ||
segment-routing | ||
mapping-server | ||
prefix-sid-map | ||
address-family ipv6 | ||
2001:db8::ff:1/128 4061 range 1 | ||
! | ||
! | ||
! | ||
! | ||
end |
12 changes: 12 additions & 0 deletions
12
...ios-xr/Cisco-IOS-XR-segment-routing-ms-cfg/nc-create-xr-segment-routing-ms-cfg-21-ydk.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<sr xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-segment-routing-ms-cfg"> | ||
<mappings> | ||
<mapping> | ||
<af>ipv6</af> | ||
<ip>2001:db8::ff:1</ip> | ||
<mask>128</mask> | ||
<sid-range>1</sid-range> | ||
<sid-start>4061</sid-start> | ||
</mapping> | ||
</mappings> | ||
</sr> | ||
|
Oops, something went wrong.