+ def start(self, delay=0):
+ pass
+ def stop(self):
+ pass
+ def is_running(self):
+ pass
+ def needs_reimage(self, target_slicefamily):
+ stampname = "/vservers/{}/etc/slicefamily".format(self.name)
+ try:
+ with open(stampname) as f:
+ current_slicefamily = f.read().strip()
+ return current_slicefamily != target_slicefamily
+ except IOError as e:
+ logger.verbose("Account.needs_reimage: missing slicefamily {} - left as-is"
+ .format(self.name))
+ return False
+
+ ### this used to be a plain method but because it needs to be invoked by destroy
+ # which is a static method, they need to become static as well
+ # needs to be done before sliver starts (checked with vs and lxc)
+ @staticmethod
+ def mount_ssh_dir (slicename):
+ return Account._manage_ssh_dir (slicename, do_mount=True)
+ @staticmethod
+ def umount_ssh_dir (slicename):
+ return Account._manage_ssh_dir (slicename, do_mount=False)
+
+ # bind mount / umount root side dir to sliver side
+ @staticmethod
+ def _manage_ssh_dir (slicename, do_mount):
+ logger.log("_manage_ssh_dir, requested to " +
+ ( "mount" if do_mount else "umount" ) +
+ " ssh dir for "+ slicename)
+ try:
+ root_ssh = "/home/{}/.ssh".format(slicename)
+ sliver_ssh = "/vservers/{}/home/{}/.ssh".format(slicename, slicename)
+ def is_mounted (root_ssh):
+ with open('/proc/mounts') as mountsfile:
+ for mount_line in mountsfile.readlines():
+ if mount_line.find (root_ssh) >= 0:
+ return True
+ return False
+ if do_mount:
+ # any of both might not exist yet
+ for path in [root_ssh, sliver_ssh]:
+ if not os.path.exists (path):
+ os.mkdir(path)
+ if not os.path.isdir (path):
+ raise Exception
+ if not is_mounted(root_ssh):
+ command = ['mount', '--bind', '-o', 'ro', root_ssh, sliver_ssh]
+ mounted = logger.log_call (command)
+ msg = "OK" if mounted else "WARNING: FAILED"
+ logger.log("_manage_ssh_dir: mounted {} into slice {} - {}"
+ .format(root_ssh, slicename, msg))
+ else:
+ if is_mounted (sliver_ssh):
+ command = ['umount', sliver_ssh]
+ umounted = logger.log_call(command)
+ msg = "OK" if umounted else "WARNING: FAILED"
+ logger.log("_manage_ssh_dir: umounted {} - {}"
+ .format(sliver_ssh, msg))
+ except Exception as e:
+ logger.log_exc("_manage_ssh_dir failed : {}".format(e), name=slicename)