Skip to content

Instantly share code, notes, and snippets.

@Christophe31
Created January 24, 2012 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Christophe31/1666616 to your computer and use it in GitHub Desktop.
Save Christophe31/1666616 to your computer and use it in GitHub Desktop.
ovh api
#!/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