Skip to content

Commit

Permalink
Add basic apps for banner configuration
Browse files Browse the repository at this point in the history
Includes seven custom apps to create and delete banner configuration
(exec, incoming, motd, login, slip-ppp, prompt-timeout):
nc-create-xr-infra-infra-cfg-20-ydk.py - Exec banner
nc-create-xr-infra-infra-cfg-21-ydk.py - Incoming banner
nc-create-xr-infra-infra-cfg-22-ydk.py - MOTD banner
nc-create-xr-infra-infra-cfg-23-ydk.py - Login banner
nc-create-xr-infra-infra-cfg-24-ydk.py - SLIP/PPP banner
nc-create-xr-infra-infra-cfg-25-ydk.py - Prompt timeout banner
nc-delete-xr-infra-infra-cfg-20-ydk.py - delete all banners
  • Loading branch information
111pontes committed Feb 3, 2017
1 parent 2793fdb commit 6f0f017
Show file tree
Hide file tree
Showing 19 changed files with 734 additions and 0 deletions.
@@ -0,0 +1,90 @@
#!/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-infra-infra-cfg.
usage: nc-create-xr-infra-infra-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_infra_infra_cfg \
as xr_infra_infra_cfg
import logging


def config_banners(banners):
"""Add config data to banners object."""
banner = banners.Banner()
banner.banner_name = xr_infra_infra_cfg.BannerEnum.exec_
banner.banner_text = ";\n" \
"----------------------\n" \
" EXEC process created\n" \
"----------------------\n" \
";\n"
banners.banner.append(banner)


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()

banners = xr_infra_infra_cfg.Banners() # create object
config_banners(banners) # add object configuration

# create configuration on NETCONF device
crud.create(provider, banners)

provider.close()
exit()
# End of script
@@ -0,0 +1,7 @@
!! IOS XR Configuration version = 6.1.2
banner exec ;
----------------------
EXEC process created
----------------------
;
end
@@ -0,0 +1,12 @@
<banners xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-infra-infra-cfg">
<banner>
<banner-name>exec</banner-name>
<banner-text>;
----------------------
EXEC process created
----------------------
;
</banner-text>
</banner>
</banners>

@@ -0,0 +1,93 @@
#!/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-infra-infra-cfg.
usage: nc-create-xr-infra-infra-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_infra_infra_cfg \
as xr_infra_infra_cfg
import logging


def config_banners(banners):
"""Add config data to banners object."""
banner = banners.Banner()
banner.banner_name = xr_infra_infra_cfg.BannerEnum.incoming
banner.banner_text = ";\n" \
"----------------------------------------------" \
"---------------------\n" \
" Incoming connection to a terminal line from a" \
" host on the network\n" \
"----------------------------------------------" \
"---------------------\n" \
";\n"
banners.banner.append(banner)


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()

banners = xr_infra_infra_cfg.Banners() # create object
config_banners(banners) # add object configuration

# create configuration on NETCONF device
crud.create(provider, banners)

provider.close()
exit()
# End of script
@@ -0,0 +1,7 @@
!! IOS XR Configuration version = 6.1.2
banner incoming ;
-------------------------------------------------------------------
Incoming connection to a terminal line from a host on the network
-------------------------------------------------------------------
;
end
@@ -0,0 +1,12 @@
<banners xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-infra-infra-cfg">
<banner>
<banner-name>incoming</banner-name>
<banner-text>;
-------------------------------------------------------------------
Incoming connection to a terminal line from a host on the network
-------------------------------------------------------------------
;
</banner-text>
</banner>
</banners>

@@ -0,0 +1,90 @@
#!/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-infra-infra-cfg.
usage: nc-create-xr-infra-infra-cfg-22-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_infra_infra_cfg \
as xr_infra_infra_cfg
import logging


def config_banners(banners):
"""Add config data to banners object."""
banner = banners.Banner()
banner.banner_name = xr_infra_infra_cfg.BannerEnum.motd
banner.banner_text = ";\n" \
"--------------------\n" \
" Message of the day\n" \
"--------------------\n" \
";\n"
banners.banner.append(banner)


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()

banners = xr_infra_infra_cfg.Banners() # create object
config_banners(banners) # add object configuration

# create configuration on NETCONF device
crud.create(provider, banners)

provider.close()
exit()
# End of script
@@ -0,0 +1,7 @@
!! IOS XR Configuration version = 6.1.2
banner motd ;
--------------------
Message of the day
--------------------
;
end
@@ -0,0 +1,12 @@
<banners xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-infra-infra-cfg">
<banner>
<banner-name>motd</banner-name>
<banner-text>;
--------------------
Message of the day
--------------------
;
</banner-text>
</banner>
</banners>

0 comments on commit 6f0f017

Please sign in to comment.