- 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/%s/.ssh"%slicename
+ sliver_ssh="/vservers/%s/home/%s/.ssh"%(slicename,slicename)
+ def is_mounted (root_ssh):
+ for mount_line in file('/proc/mounts').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 %s into slice %s - %s"%(root_ssh,slicename,msg))
+ else:
+ if is_mounted (root_ssh):
+ command=['umount',root_ssh]
+ umounted=logger.log_call(command)
+ msg="OK" if unmounted else "WARNING: FAILED"
+ logger.log("_manage_ssh_dir: umounted %s - %s"%(root_ssh,msg))