github.com/yasker/longhorn-engine@v0.0.0-20160621014712-6ed6cfca0729/integration/data/cmd.py (about) 1 import json 2 import subprocess 3 from os import path 4 5 6 def _file(f): 7 return path.join(_base(), '../../{}'.format(f)) 8 9 10 def _base(): 11 return path.dirname(__file__) 12 13 14 def _bin(): 15 c = _file('bin/longhorn') 16 assert path.exists(c) 17 return c 18 19 20 def snapshot_create(): 21 cmd = [_bin(), '--debug', 'snapshot', 'create'] 22 return subprocess.check_output(cmd).strip() 23 24 25 def snapshot_rm(name): 26 cmd = [_bin(), '--debug', 'snapshot', 'rm', name] 27 subprocess.check_call(cmd) 28 29 30 def snapshot_revert(name): 31 cmd = [_bin(), '--debug', 'snapshot', 'revert', name] 32 subprocess.check_call(cmd) 33 34 35 def snapshot_ls(): 36 cmd = [_bin(), '--debug', 'snapshot', 'ls'] 37 return subprocess.check_output(cmd) 38 39 40 def backup_create(snapshot, dest): 41 cmd = [_bin(), '--debug', 'backup', 'create', snapshot, '--dest', dest] 42 return subprocess.check_output(cmd).strip() 43 44 45 def backup_rm(backup): 46 cmd = [_bin(), '--debug', 'backup', 'rm', backup] 47 return subprocess.check_call(cmd) 48 49 50 def backup_restore(backup): 51 cmd = [_bin(), '--debug', 'backup', 'restore', backup] 52 return subprocess.check_output(cmd).strip() 53 54 55 def backup_inspect(backup): 56 cmd = [_bin(), '--debug', 'backup', 'inspect', backup] 57 return json.loads(subprocess.check_output(cmd))