Example #1
0
class Server:
    API_URL = 'https://hub.turnkeylinux.org/api/server/'

    HubClientApiError = HubClientApiError

    def __init__(self):
        self.api = API()

    def register_finalize(self, serverid):
        url = self.API_URL + "register/finalize/"
        attrs = {'serverid': serverid}

        response = self.api.request('POST', url, attrs)
        return response['subkey'], response['secret']

    def status(self, serverid, boot_status, comment=None):
        url = self.API_URL + f"status/{boot_status}/"
        attrs = {}

        if serverid:
            attrs['serverid'] = serverid

        if comment:
            attrs['comment'] = comment

        # workaround PUT issue: http://redmine.lighttpd.net/issues/1017
        response = self.api.request('PUT', url, attrs)
        return response
Example #2
0
class Server:
    API_URL = 'https://hub.turnkeylinux.org/api/server/'

    Error = Error

    def __init__(self):
        self.api = API()

    def register_finalize(self, serverid):
        url = self.API_URL + "register/finalize/"
        attrs = {'serverid': serverid}

        response = self.api.request('POST', url, attrs)
        return response['subkey'], response['secret']

    def status(self, serverid, boot_status, comment=None):
        url = self.API_URL + "status/%s/" % boot_status
        attrs = {}

        if serverid:
            attrs['serverid'] = serverid

        if comment:
            attrs['comment'] = comment

        # workaround PUT issue: http://redmine.lighttpd.net/issues/1017
        response = self.api.request('PUT', url, attrs)
        return response
Example #3
0
    def request(self, method, url, attrs={}, headers={}):
        try:
            return _API.request(self, method, url, attrs, headers)
        except self.Error, e:
            if e.name == "BackupRecord.NotFound":
                raise InvalidBackupError(e.description)

            if e.name in ("BackupAccount.NotSubscribed",
                         "BackupAccount.NotFound"):
                raise NotSubscribed()

            raise APIError(e.code, e.name, e.description)
Example #4
0
    def request(self, method, url, attrs={}, headers={}):
        try:
            return _API.request(self, method, url, attrs, headers)
        except self.Error, e:
            if e.name == "BackupRecord.NotFound":
                raise InvalidBackupError(e.description)

            if e.name in ("BackupAccount.NotSubscribed",
                          "BackupAccount.NotFound"):
                raise NotSubscribed()

            raise APIError(e.code, e.name, e.description)
Example #5
0
    def __init__(self, apikey=None, timeout=None, verbose=False):
        headers = {}
        if apikey:
            headers['apikey'] = apikey

        _api = API(timeout=timeout, verbose=verbose)

        def api(method, uri, attrs={}):
            return _api.request(method, self.API_URL + uri, attrs, headers)

        self.appliances = Appliances(api)
        self.servers = Servers(api)
        self.backups = Backups(api)
Example #6
0
class HubDNS:
    """API interface to access the TurnKey Hub API for HubDNS"""
    Error = API.Error

    API_URL = 'https://hub.turnkeylinux.org/api/hubdns/'

    def __init__(self, apikey=None, subkey=None):
        self.apikey = apikey
        self.subkey = subkey
        self.api = API()

    def _api(self, method, uri, attrs={}):
        headers = {}
        if self.apikey:
            headers['apikey'] = self.apikey
        if self.subkey:
            headers['subkey'] = self.subkey
        return self.api.request(method, self.API_URL + uri, attrs, headers)

    def get_subkey(self):
        """Get hubdns API subkey"""
        response = self._api('GET', 'subkey/')
        self.subkey = response['subkey']

        return self.subkey

    def get_ipaddress(self, fqdn):
        """Get IP address associated with FQDN"""
        response = self._api('GET', 'ipaddress/', {'fqdn': fqdn})
        return response['ipaddress']

    def capture(self, fqdn):
        """Capture FQDN but don't set IP address of client (only TKLAPP.com)"""
        self._api('POST', 'capture/', {'fqdn': fqdn})

    def release(self, fqdn):
        """Release DNS records associated with FQDN (only TKLAPP.com)"""
        self._api('DELETE', 'release/', {'fqdn': fqdn})

    def update(self, fqdn):
        """Update FQDN with IP address of client"""
        response = self._api('PUT', 'update/', {'fqdn': fqdn})
        return response['ipaddress']
Example #7
0
class HubDNS:
    """API interface to access the TurnKey Hub API for HubDNS"""
    Error = API.Error

    API_URL = 'https://hub.turnkeylinux.org/api/hubdns/'

    def __init__(self, apikey=None, subkey=None):
        self.apikey = apikey
        self.subkey = subkey
        self.api = API()

    def _api(self, method, uri, attrs={}):
        headers = {}
        if self.apikey:
            headers['apikey'] = self.apikey
        if self.subkey:
            headers['subkey'] = self.subkey
        return self.api.request(method, self.API_URL + uri, attrs, headers)

    def get_subkey(self):
        """Get hubdns API subkey"""
        response = self._api('GET', 'subkey/')
        self.subkey = response['subkey']

        return self.subkey

    def get_ipaddress(self, fqdn):
        """Get IP address associated with FQDN"""
        response = self._api('GET', 'ipaddress/', {'fqdn': fqdn})
        return response['ipaddress']

    def capture(self, fqdn):
        """Capture FQDN but don't set IP address of client (only TKLAPP.com)"""
        self._api('POST', 'capture/', {'fqdn': fqdn})
        
    def release(self, fqdn):
        """Release DNS records associated with FQDN (only TKLAPP.com)"""
        self._api('DELETE', 'release/', {'fqdn': fqdn})

    def update(self, fqdn):
        """Update FQDN with IP address of client"""
        response = self._api('PUT', 'update/', {'fqdn': fqdn})
        return response['ipaddress']
Example #8
0
 def __init__(self):
     self.api = API()
Example #9
0
 def __init__(self, apikey=None, subkey=None):
     self.apikey = apikey
     self.subkey = subkey
     self.api = API()
Example #10
0
 def __init__(self, apikey=None, subkey=None):
     self.apikey = apikey
     self.subkey = subkey
     self.api = API()
Example #11
0
 def __init__(self):
     self.api = API()