- if name not in _name_worker: _name_worker[name] = Worker(name)
- return _name_worker[name]
- finally: _name_worker_lock.release()
-
-
-def install_keys(rec):
- """Write <rec['keys']> to <rec['name']>'s authorized_keys file."""
- name = rec['name']
- dot_ssh = '/home/%s/.ssh' % name
- def do_installation():
- if not os.access(dot_ssh, os.F_OK): os.mkdir(dot_ssh)
- tools.write_file(dot_ssh + '/authorized_keys', lambda thefile: thefile.write(rec['keys']))
- logger.log('%s: installing ssh keys' % name)
- tools.fork_as(name, do_installation)
+ if name not in name_worker: name_worker[name] = Worker(name)
+ return name_worker[name]
+ finally: name_worker_lock.release()
+
+
+class Account:
+ def __init__(self, rec):
+ logger.verbose('Initing account %s'%rec['name'])
+ self.name = rec['name']
+ self.keys = ''
+ self.initscriptchanged = False
+ self.configure(rec)
+
+ @staticmethod
+ def create(name, vref = None): abstract
+ @staticmethod
+ def destroy(name): abstract
+
+ def configure(self, rec):
+ """Write <rec['keys']> to my authorized_keys file."""
+ logger.verbose('in accounts:configure for %s'%self.name)
+ new_keys = rec['keys']
+ if new_keys != self.keys:
+ self.keys = new_keys
+ dot_ssh = '/home/%s/.ssh' % self.name
+ def do_installation():
+ if not os.access(dot_ssh, os.F_OK): os.mkdir(dot_ssh)
+ os.chmod(dot_ssh, 0700)
+ tools.write_file(dot_ssh + '/authorized_keys', lambda f: f.write(new_keys))
+ logger.verbose('%s: installing ssh keys' % self.name)
+ tools.fork_as(self.name, do_installation)
+
+ def start(self, delay=0): pass
+ def stop(self): pass