- root_ssh="/home/%s/.ssh"%self.name
- sliver_ssh="/vservers/%s/home/%s/.ssh"%(self.name,self.name)
- # 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
- mounts=file('/proc/mounts').read()
- if mounts.find(sliver_ssh)<0:
- # xxx perform mount
- subprocess.call("mount --bind -o ro %s %s"%(root_ssh,sliver_ssh),shell=True)
- logger.log("expose_ssh_dir: %s mounted into slice %s"%(root_ssh,self.name))
+ 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))