+class APIHelper:
+ def __init__(self, proxy, auth, method=None):
+ self.proxy = proxy
+ self.auth = auth
+ self.method = method
+
+ def __getattr__(self, name):
+ if name.startswith("_"):
+ return getattr(self, name)
+ else:
+ return APIHelper(self.proxy, self.auth, name)
+
+ def __call__(self, *args):
+ method = getattr(self.proxy, self.method)
+ return method(self.auth, *args)
+
+class CmiClient:
+ def __init__(self, hostname, port=8003, username="apiuser", password="apiuser"):
+ self.connect_api(hostname, port, username, password)
+
+ def connect_api(self, hostname, port=8003, username="apiuser", password="apiuser"):
+ #print "https://%s:%d/COAPI/" % (hostname, port)
+ cob = xmlrpclib.ServerProxy("https://%s:%d/COAPI/" % (hostname, port), allow_none=True)
+ cob_auth = {}
+ cob_auth["Username"] = username
+ cob_auth["AuthString"] = password
+ cob_auth["AuthMethod"] = "password"
+
+ onev = xmlrpclib.ServerProxy("https://%s:%d/ONEV_API/" % (hostname, port), allow_none=True)
+ onev_auth = {}
+ onev_auth["Username"] = username
+ onev_auth["AuthString"] = password
+ onev_auth["AuthMethod"] = "password"
+
+ self.cob = APIHelper(cob, cob_auth)
+ self.onev = APIHelper(onev, onev_auth)
+