Created
January 24, 2012 00:01
-
-
Save Christophe31/1666616 to your computer and use it in GitHub Desktop.
ovh api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import settings | |
from SOAPpy import WSDL | |
ovh_server = WSDL.Proxy('https://www.ovh.com/soapi/soapi-re-1.26.wsdl') | |
def ovh_in_request(view_func): | |
"""django decorator""" | |
def _wrapped(request,*args,**kwargs): | |
with Ovh() as ovh: | |
request.ovh = ovh | |
return view_func(request, *args, **kwargs) | |
return _wrapped | |
class _SessionCaller(object): | |
def __init__(self, ovh): | |
self.ovh = ovh | |
def _add_session(self, func): | |
def _wrapped(*args, **kwargs): | |
return func(self.ovh.session, self.ovh.sms_account, | |
*args, **kwargs) | |
return _wrapped | |
def __getattr__(self, name): | |
return self._add_session(getattr(ovh_server, name)) | |
class Ovh(object): | |
def __enter__(self): | |
self.session = ovh_server.login(**settings.OVH_INFOS) | |
self.sms_account = settings.OVH_SMS_ACCOUNT | |
self.launch = _SessionCaller(self) | |
return self | |
def __exit__(self, *args, **kwargs): | |
ovh_server.logout(self.session) | |
def api_call(self): | |
return self.launch.apiOvhCall() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment