File: //proc/863910/root/usr/lib/tklbam/hub.pyc
�
+��dc @ s� d Z d d l Z d d l Z d d l Z d d l m Z d d l Z d d l m Z d d l m
Z
d e f d � � YZ d e e j f d � � YZ
d
e f d � � YZ d e f d
� � YZ d e f d � � YZ d e
f d � � YZ d e
f d � � YZ d d d � � YZ d d d � � YZ d d d � � YZ d d l m Z e j j d � s�e j j e j j e j d � � r�d d l m Z n d S(! s� TurnKey Hub API - Backup
Notes:
- Default URL: https://hub.turnkeylinux.org/api/backup/
- REST compliant (GET, POST, PUT)
- Responses are returned in application/json format
- API subkey must be sent in the header for all calls (except subkey/)
subkey/
method: GET
fields: apikey
return: subkey
credentials/
method: GET
fields:
return: accesskey, secretkey, usertoken, producttoken
record/create/
method: POST
fields: key, turnkey_version, [server_id]
return: backuprecord
record/update/
method: PUT
fields: address
return: <response_code>
record/<backup_id>/
method: GET
fields:
return: backuprecord
record/<backup_id>/
method: PUT
fields: key
return: backuprecord
records/
method: GET
fields:
return: [ backuprecord, ... ]
archive/
method: GET
fields: turnkey_version
return: archive_content
archive/timestamp/
method: GET
fields: turnkey_version
return: archive_timestamp
Exceptions::
400 Request.MissingHeader
400 Request.MissingArgument
401 HubAccount.Forbidden
400 HubAccount.InvalidApiKey
400 BackupAccount.InvalidSubKey
401 BackupAccount.MalformedSubKey
404 BackupAccount.NotFound
401 BackupAccount.NotSubscribed
404 BackupRecord.NotFound
401 BackupRecord.LimitExceeded
400 BackupRecord.ServerIDNotFound
404 BackupArchive.NotFound
i����N( t datetime( t API( t AttrDictt Errorc B s e Z d � Z d � Z RS( c G s t j | | | � | | _ d S( N( t Exceptiont __init__t description( t selfR t args( ( s /usr/lib/tklbam/hub.pyR \ s c C s | j S( N( R ( R ( ( s /usr/lib/tklbam/hub.pyt __str__` s ( t __name__t
__module__R R ( ( ( s /usr/lib/tklbam/hub.pyR [ s t APIErrorc B s e Z d � Z RS( c C s t j j | | | | � d S( N( t _APIR R ( R t codet nameR ( ( s /usr/lib/tklbam/hub.pyR d s ( R
R R ( ( ( s /usr/lib/tklbam/hub.pyR c s t
NotSubscribedc B s e Z d Z e d � Z RS( s| Backups are not yet enabled for your TurnKey Hub account. Log
into the Hub and go to the "Backups" section for instructions.c C s t j | | � d S( N( R R ( R t desc( ( s /usr/lib/tklbam/hub.pyR l s ( R
R t DESCR ( ( ( s /usr/lib/tklbam/hub.pyR g s t InvalidBackupErrorc B s e Z RS( ( R
R ( ( ( s /usr/lib/tklbam/hub.pyR o s R c B s e Z i i d � Z RS( c C s� y t j | | | | | � SWnm | j k
r� } | j d k rS t | j � � n | j d k rn t � � n t | j | j | j � � n Xd S( Ns BackupRecord.NotFounds BackupAccount.NotSubscribeds BackupAccount.NotFound( s BackupAccount.NotSubscribeds BackupAccount.NotFound( R
t requestR R R R R R R ( R t methodt urlt attrst headerst e( ( s /usr/lib/tklbam/hub.pyR s s ( R
R R ( ( ( s /usr/lib/tklbam/hub.pyR r s t BackupRecordc B s e Z e d � � Z d � Z RS( c C s | s
d St j | d � S( Ns %Y-%m-%d %H:%M:%S( t NoneR t strptime( t s( ( s /usr/lib/tklbam/hub.pyt _parse_datetime� s c C s� | d | _ | d | _ | d | _ | d | _ | d | _ | j | d � | _ | j | d � | _ t | d � | _ | d | _
g | _ t j
| � d S(
Nt keyt addresst backup_idt server_idt turnkey_versiont date_createdt date_updatedt sizeR ( R R R! R"