我试图在最终添加代码以创建区域和zone_set之前首先创建一个fc_alias。我能够进入设备并生成命令的初始部分以生成fc_alias。当我将str值(fc_alias)与浮点值(vsan_id)一起添加时,它不能很好地相互作用。我似乎找不到能够创建fc_alias的方法。
def fc_alias(self):
# store TEST switch info
cisco_asa = {
'device_type': 'cisco_nxos',
'ip': 'xxx.xx.xx.xxx',
'username': 'admin',
'password': 'xxxxx',
}
# Connect to TEST switch using Netmiko function "ConnectHandler"
net_connect = ConnectHandler(**cisco_asa)
print(net_connect.find_prompt())
#move to config menu
net_connect.config_mode()
print(net_connect.find_prompt())
#set fc_alias
fc_alias = "testname"
vsan_id = ("1")
output = net_connect.send_config_set("fcalias name","fc_alias","vsan",vsan_id)
print(output)
以下是产生的错误
Traceback (most recent call last):
File "Switches.py", line 43, in <module>
main()
File "Switches.py", line 39, in main
TestSwitch()
File "Switches.py", line 33, in __init__
str.vsan_id = ("1")
TypeError: can't set attributes of built-in/extension type 'str'
答案 0 :(得分:0)
似乎有一些问题。一个是我用引号中的变量fc_alias,所以它没有被正确调用。当我应该使用net_connect.send_command时,我也使用了错误的命令(net_connect.send_config_set)。我也试图使用字符串和浮点数,它无法自动将它们都转换为字符串。为了将它们都转换为字符串,我在发送命令之前将其存储在变量中。
def fc_alias(self):
# store TEST switch info
cisco_asa = {
'device_type': 'cisco_nxos',
'ip': 'xxx.xx.xx.xxx',
'username': 'admin',
'password': 'xxxxx',
}
# Connect to TEST switch using Netmiko function "ConnectHandler"
net_connect = ConnectHandler(**cisco_asa)
print(net_connect.find_prompt())
#move to config menu
net_connect.config_mode()
print(net_connect.find_prompt())
#set fc_alias
vsan_id = ("1")
fc_alias = "testname"
fc_alias2 = ("fcalias name "+fc_alias+ " vsan " +vsan_id)
output = net_connect.send_config_set(fc_alias2)
print(output)