docs: fix example up so it's closer to real code

issue510
David Wilson 6 years ago
parent cd01957995
commit 8d7aefb1cf

@ -137,6 +137,9 @@ We could instead express the above using Mitogen:
:: ::
import shutil, os, subprocess
import mitogen
def run(*args): def run(*args):
return subprocess.check_call(args) return subprocess.check_call(args)
@ -144,22 +147,24 @@ We could instead express the above using Mitogen:
with open(path, 'rb') as fp: with open(path, 'rb') as fp:
return s in fp.read() return s in fp.read()
device = '/dev/sdb1' @mitogen.main()
mount_point = '/media/Media Volume' def main(router):
device = '/dev/sdb1'
bastion = router.ssh(hostname='bastion') mount_point = '/media/Media Volume'
bastion_sudo = router.sudo(via=bastion)
bastion = router.ssh(hostname='bastion')
if PROD: bastion_sudo = router.sudo(via=bastion)
fileserver = router.ssh(hostname='fileserver', via=bastion)
if fileserver.call(file_contains, device, '/proc/mounts'): if PROD:
print('{} already mounted!'.format(device)) fileserver = router.ssh(hostname='fileserver', via=bastion)
fileserver.call(run, 'umount', device) if fileserver.call(file_contains, device, '/proc/mounts'):
fileserver.call(shutil.rmtree, mount_point) print('{} already mounted!'.format(device))
fileserver.call(os.mkdir, mount_point, 0777) fileserver.call(run, 'umount', device)
fileserver.call(run, 'mount', device, mount_point) fileserver.call(shutil.rmtree, mount_point)
fileserver.call(os.mkdir, mount_point, 0777)
bastion_sudo.call(run, 'touch', '/var/run/start_backup') fileserver.call(run, 'mount', device, mount_point)
bastion_sudo.call(run, 'touch', '/var/run/start_backup')
* In which context must the ``PROD`` variable be defined? * In which context must the ``PROD`` variable be defined?
* On which machine is each step executed? * On which machine is each step executed?

Loading…
Cancel
Save