我有以下代码:
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
似乎你只是想绕着
xc.Server
转。只需使用函数而不是类那就做你该做的:
如果要自定义
xc.Server
对象,可以直接继承它:您需要将
def __init__
更新为定制的url
输入,但是您应该非常了解原始实现,因为您可能无意中覆盖了超类xc.Server
中的某些属性或实现细节在这个用例中,
AristaSwitch
基本上是带有定制实例化方法的xc.Server
,如果您愿意,您可以稍后使用自己的方法来补充它相关问题 更多 >
编程相关推荐