I have wrritten a function that can get cisco commands from database.
now i can reveive commands in this format
enable
configure terminal
interface fa(fanumber)/(fanumber)
ip adress (ip) (subnet mask)
no shutdown
As you know ,in the ip adress (ip) (subnet mask) we need to input two parameters into (ip) (subnet mask) Moreover, sometime i need to input only one parameter such as: (this is the result of my function.) enable configure terminal vlan (VLAN IDs) name (vlan name)
In these commands , I need to input one parameter into vlan (VLAN IDs) and one parameter into name (vlan name)
But now I cant find a method to write a good function to solve my problem. I would like to provide my function and database structure and hope someone could help me.
this is my function:
def readciscodevice(function, device):
conn = sqlite3.connect('server.db')
cur = conn.cursor()
if device == "switch":
cur.execute(
"SELECT DISTINCT command FROM switch WHERE function =? or function='configure terminal' or function='enable' ORDER BY key ASC",
(function,))
read = cur.fetchall()
return read
elif device == "router":
cur.execute(
"SELECT DISTINCT command FROM router WHERE function =? or function='configure terminal' or function='enable' ORDER BY key ASC",
(function,))
read = cur.fetchall()
return read;
elif device == "showcommand":
cur.execute(
"SELECT DISTINCT command FROM showcommand WHERE function =? or function='enable' ORDER BY key ASC",
(function,))
read = cur.fetchall()
return read;
a = input("function:")
b = input("device:")
for result in readciscodevice(a,b):
print(result[0])
my database structure are keynumber(the number of my field), command(the full command that i get from cisco devices) and function (the function is to describe the set of commands that I combine, like)
Should i add a field like parameter to calulate how many parameter in my command?
I hope that I can find a way to present my answer like this:
enable
configure terminal
vlan 1
name VLAN1
and
enable
configure terminal
interface fa 0/1
ip adress 192.168.0.1 255.255.255.0
no shutdown
Aucun commentaire:
Enregistrer un commentaire