本文整理汇总了Python中device.Device.get_vlans_xml方法的典型用法代码示例。如果您正苦于以下问题:Python Device.get_vlans_xml方法的具体用法?Python Device.get_vlans_xml怎么用?Python Device.get_vlans_xml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类device.Device
的用法示例。
在下文中一共展示了Device.get_vlans_xml方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: vlans
# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import get_vlans_xml [as 别名]
def vlans():
devvlans = None
devgroups = None
g.db = connect_db()
if request.method == 'POST':
dev1 = Device("EALABSW00002", "10.1.11.75", "junos", "DSGadmin", "Password!")
if request.form['btn_vlans'] == "check":
devvlans = dev1.get_vlans_xml()
devgroups = dev1.get_groups_xml()
elif request.form['btn_vlans'] == "vlanadd":
# Declare VLAN variables
vlan_id = request.form['vlans_id']
vlan_description = request.form['vlans_description']
vlan_name = "VLAN"+vlan_id
# Adjust database
g.db.execute('insert into vlans (id, description) values (?, ?)', [vlan_id, vlan_description])
g.db.commit()
# Adjust device
dev1.set_vlan(vlan_name, vlan_id, vlan_description)
elif request.form['btn_vlans'] == "vlanedit":
# Declare VLAN variables
vlan_id = request.form['vlans_id']
vlan_description = request.form['vlans_description']
vlan_name = "VLAN"+vlan_id
# Adjust database
g.db.execute('update vlans set description = ? where id is ?', [vlan_description, vlan_id])
g.db.commit()
# Adjust device
dev1.set_vlan(vlan_name, vlan_id, vlan_description)
elif request.form['btn_vlans'] == "vlanremove":
# Declare VLAN variables
vlan_id = request.form['vlans_id']
vlan_name = "VLAN"+vlan_id
# Adjust database
g.db.execute('delete from vlans where id is ?', [vlan_id])
g.db.commit()
# Adjust device
dev1.del_vlan(vlan_name)
cur = g.db.execute('select * from vlans')
dbvlans = [dict(id=row[1], vlan=row[2]) for row in cur.fetchall()]
g.db.close()
return render_template('vlans.xhtml', vlans=dbvlans, devvlans=devvlans, devgroups=devgroups)