Back to index

obnam  1.1
Public Member Functions | Public Attributes | Static Public Attributes
obnamlib.clientlist.ClientList Class Reference
Inheritance diagram for obnamlib.clientlist.ClientList:
Inheritance graph
[legend]
Collaboration diagram for obnamlib.clientlist.ClientList:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def hashfunc
def hashkey
def key
def unkey
def random_id
def list_clients
def find_client_id
def get_client_id
def add_client
def remove_client
def get_client_keyid
def set_client_keyid

Public Attributes

 hash_len
 fmt
 key_bytes
 minkey
 maxkey
 keep_just_one_tree

Static Public Attributes

int CLIENT_NAME = 0
int KEYID = 1
int SUBKEY_MAX = 255

Detailed Description

Repository's list of clients.

The list maps a client name to an arbitrary (string) identifier,
which is unique within the repository.

The list is implemented as a B-tree, with a three-part key:
128-bit MD5 of client name, 64-bit unique identifier, and subkey
identifier. The value depends on the subkey: it's either the
client's full name, or the public key identifier the client
uses to encrypt their backups.

The client's identifier is a random, unique 64-bit integer.

Definition at line 26 of file clientlist.py.


Constructor & Destructor Documentation

def obnamlib.clientlist.ClientList.__init__ (   self,
  fs,
  node_size,
  upload_queue_size,
  lru_size,
  hooks 
)

Definition at line 48 of file clientlist.py.

00048 
00049     def __init__(self, fs, node_size, upload_queue_size, lru_size, hooks):
00050         tracing.trace('new ClientList')
00051         self.hash_len = len(self.hashfunc(''))
00052         self.fmt = '!%dsQB' % self.hash_len
00053         self.key_bytes = len(self.key('', 0, 0))
00054         self.minkey = self.hashkey('\x00' * self.hash_len, 0, 0)
00055         self.maxkey = self.hashkey('\xff' * self.hash_len, obnamlib.MAX_ID, 
00056                                    self.SUBKEY_MAX)
00057         obnamlib.RepositoryTree.__init__(self, fs, 'clientlist', 
00058                                          self.key_bytes, node_size, 
00059                                          upload_queue_size, lru_size, hooks)
00060         self.keep_just_one_tree = True


Member Function Documentation

def obnamlib.clientlist.ClientList.add_client (   self,
  client_name 
)

Definition at line 101 of file clientlist.py.

00101 
00102     def add_client(self, client_name):
00103         logging.info('Adding client %s' % client_name)
00104         self.start_changes()
00105         if self.find_client_id(self.tree, client_name) is None:
00106             while True:
00107                 candidate_id = self.random_id()
00108                 key = self.key(client_name, candidate_id, self.CLIENT_NAME)
00109                 try:
00110                     self.tree.lookup(key)
00111                 except KeyError:
00112                     break
00113             key = self.key(client_name, candidate_id, self.CLIENT_NAME)
00114             self.tree.insert(key, client_name)
00115             logging.debug('Client %s has id %s' % (client_name, candidate_id))
        

Here is the call graph for this function:

def obnamlib.clientlist.ClientList.find_client_id (   self,
  t,
  client_name 
)

Definition at line 86 of file clientlist.py.

00086 
00087     def find_client_id(self, t, client_name):
00088         minkey = self.key(client_name, 0, 0)
00089         maxkey = self.key(client_name, obnamlib.MAX_ID, self.SUBKEY_MAX)
00090         for k, v in t.lookup_range(minkey, maxkey):
00091             checksum, client_id, subkey = self.unkey(k)
00092             if subkey == self.CLIENT_NAME and v == client_name:
00093                 return client_id
00094         return None

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.clientlist.ClientList.get_client_id (   self,
  client_name 
)

Definition at line 95 of file clientlist.py.

00095 
00096     def get_client_id(self, client_name):
00097         if not self.init_forest() or not self.forest.trees:
00098             return None
00099         t = self.forest.trees[-1]
00100         return self.find_client_id(t, client_name)

Here is the call graph for this function:

def obnamlib.clientlist.ClientList.get_client_keyid (   self,
  client_name 
)

Definition at line 124 of file clientlist.py.

00124 
00125     def get_client_keyid(self, client_name):
00126         if self.init_forest() and self.forest.trees:
00127             t = self.forest.trees[-1]
00128             client_id = self.find_client_id(t, client_name)
00129             if client_id is not None:
00130                 key = self.key(client_name, client_id, self.KEYID)
00131                 for k, v in t.lookup_range(key, key):
00132                     return v
00133         return None
        

Here is the call graph for this function:

def obnamlib.clientlist.ClientList.hashfunc (   self,
  string 
)

Definition at line 61 of file clientlist.py.

00061 
00062     def hashfunc(self, string):
00063         return hashlib.new('md5', string).digest()

Here is the caller graph for this function:

def obnamlib.clientlist.ClientList.hashkey (   self,
  namehash,
  client_id,
  subkey 
)

Definition at line 64 of file clientlist.py.

00064 
00065     def hashkey(self, namehash, client_id, subkey):
00066         return struct.pack(self.fmt, namehash, client_id, subkey)

Here is the caller graph for this function:

def obnamlib.clientlist.ClientList.key (   self,
  client_name,
  client_id,
  subkey 
)

Definition at line 67 of file clientlist.py.

00067 
00068     def key(self, client_name, client_id, subkey):
00069         h = self.hashfunc(client_name)
00070         return self.hashkey(h, client_id, subkey)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 77 of file clientlist.py.

00077 
00078     def list_clients(self):
00079         if self.init_forest() and self.forest.trees:
00080             t = self.forest.trees[-1]
00081             return [v 
00082                      for k, v in t.lookup_range(self.minkey, self.maxkey)
00083                      if self.unkey(k)[2] == self.CLIENT_NAME]
00084         else:
00085             return []

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 74 of file clientlist.py.

00074 
00075     def random_id(self):
00076         return random.randint(0, obnamlib.MAX_ID)

Here is the caller graph for this function:

def obnamlib.clientlist.ClientList.remove_client (   self,
  client_name 
)

Definition at line 116 of file clientlist.py.

00116 
00117     def remove_client(self, client_name):
00118         logging.info('Removing client %s' % client_name)
00119         self.start_changes()
00120         client_id = self.find_client_id(self.tree, client_name)
00121         if client_id is not None:
00122             key = self.key(client_name, client_id, self.CLIENT_NAME)
00123             self.tree.remove(key)

Here is the call graph for this function:

def obnamlib.clientlist.ClientList.set_client_keyid (   self,
  client_name,
  keyid 
)

Definition at line 134 of file clientlist.py.

00134 
00135     def set_client_keyid(self, client_name, keyid):
00136         logging.info('Setting client %s to use key %s' % (client_name, keyid))
00137         self.start_changes()
00138         client_id = self.find_client_id(self.tree, client_name)
00139         key = self.key(client_name, client_id, self.KEYID)
00140         if keyid is None:
00141             self.tree.remove_range(key, key)
00142         else:
00143             self.tree.insert(key, keyid)
00144 

Here is the call graph for this function:

def obnamlib.clientlist.ClientList.unkey (   self,
  key 
)

Definition at line 71 of file clientlist.py.

00071 
00072     def unkey(self, key):
00073         return struct.unpack(self.fmt, key)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 44 of file clientlist.py.

Definition at line 51 of file clientlist.py.

Definition at line 50 of file clientlist.py.

Definition at line 59 of file clientlist.py.

Definition at line 52 of file clientlist.py.

Definition at line 45 of file clientlist.py.

Definition at line 54 of file clientlist.py.

Definition at line 53 of file clientlist.py.

Definition at line 46 of file clientlist.py.


The documentation for this class was generated from the following file: