【发布时间】:2018-11-26 14:57:50
【问题描述】:
我有以下代码:
import xmlrpc.client as xc
class AristaSwitch():
def __init__(self,devicename,user='admin',password='xxxxxx')
self.url="https://"+user+":"+password+"@"+devicename+"/command-api"
self.Server = xc.Server(self.url) **<----i know this is not correct**
more code below here
我希望能够编写如下代码:
as = AristaSwitch("192.168.1.1")
as.runCmds(1, [ "show hostname" ] )
他们这样做的方式是:
import xmlrpc.client as xc
switch = xc.Server( "https://admin:admin@172.16.130.16/command-api" )
response = switch.runCmds( 1, [ "show hostname" ] )
更新 我认为将其添加到 init 函数中应该可以做到这一点
self.InitializeRPCServer()
def InitializeRPCServer():
switch=xc.Server(self.url)
return switch
【问题讨论】:
-
大概你的意思是
def __init__在你的班级,而不仅仅是__init__ -
是的,这是正确的
-
我在 def 规则的末尾缺少一个 : ...
-
我没有看到手头的问题。你清楚地知道参数是如何工作的,所以你可以要求 IP 参数(在我添加的括号中),然后将其用作 IP,然后它应该可以工作......不是我擅长这个。我讨厌参数,我只是一个业余爱好者,