Update Cisco ASA object group with netmiko

This is a demo of configuring ASA with netmiko, there is a use case when a server is provisioned, the server’s hostname and ip addresses are assigned automatically by Vrealize, and run a python script to update the object-group of the server.

Here’s the code:

from netmiko import ConnectHandler
from getpass import getpass
import logging

usr = input("Username: ")
pwd = getpass()
asav = {  'device_type': 'cisco_asa',
    'ip': '192.168.1.15',
    'username': usr,
    'password': pwd,
    'secret': pwd,
    'port': '22', }

config_set = ['object network member1', 'host 1.1.1.1 ', 'exit', 'object network member2', 'host 2.2.2.2', 'exit', 'object-group network Group1',
           'network-object object member1', 'network-object object member2' ]

logging.basicConfig(level=logging.DEBUG)
with ConnectHandler(**asav) as m:
    m.enable()
    m.config_mode()
    m.send_config_set(config_set, True)
    m.send_command_expect('write memory')
Advertisements
This entry was posted in Python, Scripting and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s