本文整理汇总了Python中helper.Helper.run_command方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.run_command方法的具体用法?Python Helper.run_command怎么用?Python Helper.run_command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helper.Helper
的用法示例。
在下文中一共展示了Helper.run_command方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: destroy
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import run_command [as 别名]
def destroy(dataset, snapshot):
"""
Destroyes a dataset
"""
command = 'zfs destroy {0}@{1}'.format(dataset, snapshot)
Helper.run_command(command, '/')
示例2: snapshot
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import run_command [as 别名]
def snapshot(dataset, name):
"""
Takes a snapshot
"""
command = 'zfs snapshot {0}@{1}'.format(dataset, name)
Helper.run_command(command, '/')
示例3: release
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import run_command [as 别名]
def release(target, snapshot, endpoint=''):
if endpoint == '':
command = 'zfs release zsm {0}@{1} || true'.format(target, snapshot)
Helper.run_command(command, '/')
else:
command = '{0} \'zfs release zsm {1}@{2} || true\''.format(endpoint, target, snapshot)
Helper.run_command(command, '/')
示例4: hold
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import run_command [as 别名]
def hold(target, snapshot, endpoint=''):
if endpoint == '':
command = 'zfs hold zsm {0}@{1}'.format(target, snapshot)
Helper.run_command(command, '/')
else:
command = '{0} \'zfs hold zsm {1}@{2}\''.format(endpoint, target, snapshot)
Helper.run_command(command, '/')
示例5: get_datasets
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import run_command [as 别名]
def get_datasets():
"""
Retreives all datasets
"""
output = Helper.run_command('zfs list -H', '/')
datasets = []
for line in filter(len, output.split('\n')):
parts = filter(len, line.split('\t'))
datasets.append(parts[0])
return datasets
示例6: replicate
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import run_command [as 别名]
def replicate(dataset, base_snapshot, last_snapshot, target, buffer_size, endpoint='', direction='push', compression=None):
"""
Replicates a dataset towards a given endpoint/target (push)
Replicates a dataset from a given endpoint to a local target (pull)
"""
delta = ''
if base_snapshot is not None:
delta = '-i {0}@{1} '.format(dataset, base_snapshot)
if compression is not None:
compress = '| {0} -c'.format(compression)
decompress = '| {0} -cd'.format(compression)
else:
compress = ''
decompress = ''
if endpoint == '':
# We're replicating to a local target
command = 'zfs send {0}{1}@{2} | zfs receive -F {3}'
command = command.format(delta, dataset, last_snapshot, target)
Helper.run_command(command, '/')
else:
if direction == 'push':
# We're replicating to a remote server
command = 'zfs send {0}{1}@{2} {3} | mbuffer -q -v 0 -s 128k -m {4} | {5} \'mbuffer -s 128k -m {4} {6} | zfs receive -F {7}\''
command = command.format(delta, dataset, last_snapshot, compress, buffer_size, endpoint, decompress, target)
Helper.run_command(command, '/')
elif direction == 'pull':
# We're pulling from a remote server
command = '{5} \'zfs send {0}{1}@{2} {3} | mbuffer -q -v 0 -s 128k -m {4}\' | mbuffer -s 128k -m {4} {6} | zfs receive -F {7}'
command = command.format(delta, dataset, last_snapshot, compress, buffer_size, endpoint, decompress, target)
Helper.run_command(command, '/')
示例7: replicate
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import run_command [as 别名]
def replicate(dataset, base_snapshot, last_snapshot, target, endpoint="", direction="push", compression=None):
"""
Replicates a dataset towards a given endpoint/target (push)
Replicates a dataset from a given endpoint to a local target (pull)
"""
delta = ""
if base_snapshot is not None:
delta = "-i {0}@{1} ".format(dataset, base_snapshot)
if compression is not None:
compress = "| {0} -c".format(compression)
decompress = "| {0} -cd".format(compression)
else:
compress = ""
decompress = ""
if endpoint == "":
# We're replicating to a local target
command = "zfs send {0}{1}@{2} | zfs receive -F {3}"
command = command.format(delta, dataset, last_snapshot, target)
Helper.run_command(command, "/")
else:
if direction == "push":
# We're replicating to a remote server
command = "zfs send {0}{1}@{2} {3} | mbuffer -q -v 0 -s 128k -m 512M | {4} 'mbuffer -s 128k -m 512M {5} | zfs receive -F {6}'"
command = command.format(delta, dataset, last_snapshot, compress, endpoint, decompress, target)
Helper.run_command(command, "/")
elif direction == "pull":
# We're pulling from a remote server
command = "{4} 'zfs send {0}{1}@{2} {3} | mbuffer -q -v 0 -s 128k -m 512M' | mbuffer -s 128k -m 512M {5} | zfs receive -F {6}"
command = command.format(delta, dataset, last_snapshot, compress, endpoint, decompress, target)
Helper.run_command(command, "/")
示例8: get_size
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import run_command [as 别名]
def get_size(dataset, base_snapshot, last_snapshot, endpoint=''):
"""
Executes a dry-run zfs send to calculate the size of the delta.
"""
delta = ''
if base_snapshot is not None:
delta = '-i {0}@{1} '.format(dataset, base_snapshot)
if endpoint == '':
command = 'zfs send -nv {0}{1}@{2}'
command = command.format(delta, dataset, last_snapshot)
else:
command = '{0} \'zfs send -nv {1}{2}@{3}\''
command = command.format(endpoint, delta, dataset, last_snapshot)
command = '{0} 2>&1 | grep \'total estimated size is\''.format(command)
output = Helper.run_command(command, '/')
size = output.strip().split(' ')[-1]
if size[-1].isdigit():
return '{0}B'.format(size)
return '{0}iB'.format(size)
示例9: get_size
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import run_command [as 别名]
def get_size(dataset, base_snapshot, last_snapshot, endpoint=""):
"""
Executes a dry-run zfs send to calculate the size of the delta.
"""
delta = ""
if base_snapshot is not None:
delta = "-i {0}@{1} ".format(dataset, base_snapshot)
if endpoint == "":
command = "zfs send -nv {0}{1}@{2}"
command = command.format(delta, dataset, last_snapshot)
else:
command = "{0} 'zfs send -nv {1}{2}@{3}'"
command = command.format(endpoint, delta, dataset, last_snapshot)
command = "{0} 2>&1 | grep 'total estimated size is'".format(command)
output = Helper.run_command(command, "/")
size = output.strip().split(" ")[-1]
if size[-1].isdigit():
return "{0}B".format(size)
return "{0}iB".format(size)
示例10: get_snapshots
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import run_command [as 别名]
def get_snapshots(dataset='', endpoint=''):
"""
Retreives a list of snapshots
"""
if endpoint == '':
command = 'zfs list -H -s creation -t snapshot{0}{1} || true'
else:
command = '{0} \'zfs list -H -s creation -t snapshot{1} || true\''
if dataset == '':
dataset_filter = ''
else:
dataset_filter = ' | grep {0}@'.format(dataset)
output = Helper.run_command(command.format(endpoint, dataset_filter), '/')
snapshots = {}
for line in filter(len, output.split('\n')):
parts = filter(len, line.split('\t'))
datasetname = parts[0].split('@')[0]
if datasetname not in snapshots:
snapshots[datasetname] = []
snapshots[datasetname].append(parts[0].split('@')[1])
return snapshots
示例11: get_snapshots
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import run_command [as 别名]
def get_snapshots(dataset="", endpoint=""):
"""
Retreives a list of snapshots
"""
if endpoint == "":
command = "zfs list -H -s creation -t snapshot{0}{1} || true"
else:
command = "{0} 'zfs list -H -s creation -t snapshot{1} || true'"
if dataset == "":
dataset_filter = ""
else:
dataset_filter = " | grep {0}@".format(dataset)
output = Helper.run_command(command.format(endpoint, dataset_filter), "/")
snapshots = {}
for line in filter(len, output.split("\n")):
parts = filter(len, line.split("\t"))
datasetname = parts[0].split("@")[0]
if datasetname not in snapshots:
snapshots[datasetname] = []
snapshots[datasetname].append(parts[0].split("@")[1])
return snapshots
示例12: run
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import run_command [as 别名]
def run(settings):
"""
Executes a single run where certain datasets might or might not be snapshotted
"""
now = datetime.now()
today = "{0:04d}{1:02d}{2:02d}".format(now.year, now.month, now.day)
snapshots = ZFS.get_snapshots()
datasets = ZFS.get_datasets()
for dataset in datasets:
if dataset in settings:
try:
dataset_settings = settings[dataset]
local_snapshots = snapshots.get(dataset, [])
take_snapshot = dataset_settings["snapshot"] is True
replicate = dataset_settings["replicate"] is not None
# Decide whether we need to handle this dataset
execute = False
if take_snapshot is True or replicate is True:
if dataset_settings["time"] == "trigger":
# We wait until we find a trigger file in the filesystem
trigger_filename = "{0}/.trigger".format(dataset_settings["mountpoint"])
if os.path.exists(trigger_filename):
Manager.logger.info("Trigger found on {0}".format(dataset))
os.remove(trigger_filename)
execute = True
else:
trigger_time = dataset_settings["time"].split(":")
hour = int(trigger_time[0])
minutes = int(trigger_time[1])
if (
now.hour > hour or (now.hour == hour and now.minute >= minutes)
) and today not in local_snapshots:
Manager.logger.info("Time passed for {0}".format(dataset))
execute = True
if execute is True:
# Pre exectution command
if dataset_settings["preexec"] is not None:
Helper.run_command(dataset_settings["preexec"], "/")
if take_snapshot is True:
# Take today's snapshotzfs
Manager.logger.info("Taking snapshot {0}@{1}".format(dataset, today))
ZFS.snapshot(dataset, today)
local_snapshots.append(today)
Manager.logger.info("Taking snapshot {0}@{1} complete".format(dataset, today))
# Replicating, if required
if replicate is True:
Manager.logger.info("Replicating {0}".format(dataset))
replicate_settings = dataset_settings["replicate"]
push = replicate_settings["target"] is not None
remote_dataset = replicate_settings["target"] if push else replicate_settings["source"]
remote_snapshots = ZFS.get_snapshots(remote_dataset, replicate_settings["endpoint"])
last_common_snapshot = None
if remote_dataset in remote_snapshots:
if (
push is True
): # If pushing, we search for the last local snapshot that is remotely available
for snapshot in local_snapshots:
if snapshot in remote_snapshots[remote_dataset]:
last_common_snapshot = snapshot
else: # Else, we search for the last remote snapshot that is locally available
for snapshot in remote_snapshots[remote_dataset]:
if snapshot in local_snapshots:
last_common_snapshot = snapshot
if last_common_snapshot is not None: # There's a common snapshot
previous_snapshot = None
if push is True:
for snapshot in local_snapshots:
if snapshot == last_common_snapshot:
previous_snapshot = last_common_snapshot
continue
if previous_snapshot is not None:
# There is a snapshot on this host that is not yet on the other side.
size = ZFS.get_size(dataset, previous_snapshot, snapshot)
Manager.logger.info(
" {0}@{1} > {0}@{2} ({3})".format(
dataset, previous_snapshot, snapshot, size
)
)
ZFS.replicate(
dataset,
previous_snapshot,
snapshot,
remote_dataset,
replicate_settings["endpoint"],
direction="push",
compression=replicate_settings["compression"],
)
previous_snapshot = snapshot
else:
for snapshot in remote_snapshots[remote_dataset]:
if snapshot == last_common_snapshot:
previous_snapshot = last_common_snapshot
continue
#.........这里部分代码省略.........
示例13: run
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import run_command [as 别名]
def run(settings):
"""
Executes a single run where certain datasets might or might not be snapshotted
"""
now = datetime.now()
yda = datetime.now() - timedelta(1)
today = '{0:04d}{1:02d}{2:02d}'.format(now.year, now.month, now.day)
yesterday = '{0:04d}{1:02d}{2:02d}'.format(yda.year, yda.month, yda.day)
snapshots = ZFS.get_snapshots()
datasets = ZFS.get_datasets()
for dataset in datasets:
if dataset in settings:
try:
dataset_settings = settings[dataset]
local_snapshots = snapshots.get(dataset, [])
take_snapshot = dataset_settings['snapshot'] is True
replicate = dataset_settings['replicate'] is not None
# Decide whether we need to handle this dataset
execute = False
if take_snapshot is True or replicate is True:
if dataset_settings['time'] == 'trigger':
# We wait until we find a trigger file in the filesystem
trigger_filename = '{0}/.trigger'.format(dataset_settings['mountpoint'])
if os.path.exists(trigger_filename):
Manager.logger.info('Trigger found on {0}'.format(dataset))
os.remove(trigger_filename)
execute = True
else:
trigger_time = dataset_settings['time'].split(':')
hour = int(trigger_time[0])
minutes = int(trigger_time[1])
if (now.hour > hour or (now.hour == hour and now.minute >= minutes)) and today not in local_snapshots:
Manager.logger.info('Time passed for {0}'.format(dataset))
execute = True
if execute is True:
# Pre exectution command
if dataset_settings['preexec'] is not None:
Helper.run_command(dataset_settings['preexec'], '/')
if take_snapshot is True:
# Take today's snapshotzfs
Manager.logger.info('Taking snapshot {0}@{1}'.format(dataset, today))
ZFS.snapshot(dataset, today)
local_snapshots.append(today)
Manager.logger.info('Taking snapshot {0}@{1} complete'.format(dataset, today))
# Replicating, if required
if replicate is True:
Manager.logger.info('Replicating {0}'.format(dataset))
replicate_settings = dataset_settings['replicate']
push = replicate_settings['target'] is not None
remote_dataset = replicate_settings['target'] if push else replicate_settings['source']
remote_snapshots = ZFS.get_snapshots(remote_dataset, replicate_settings['endpoint'])
last_common_snapshot = None
if remote_dataset in remote_snapshots:
if push is True: # If pushing, we search for the last local snapshot that is remotely available
for snapshot in local_snapshots:
if snapshot in remote_snapshots[remote_dataset]:
last_common_snapshot = snapshot
else: # Else, we search for the last remote snapshot that is locally available
for snapshot in remote_snapshots[remote_dataset]:
if snapshot in local_snapshots:
last_common_snapshot = snapshot
if last_common_snapshot is not None: # There's a common snapshot
previous_snapshot = None
if push is True:
for snapshot in local_snapshots:
if snapshot == last_common_snapshot:
previous_snapshot = last_common_snapshot
continue
if previous_snapshot is not None:
# There is a snapshot on this host that is not yet on the other side.
size = ZFS.get_size(dataset, previous_snapshot, snapshot)
Manager.logger.info(' {0}@{1} > {0}@{2} ({3})'.format(dataset, previous_snapshot, snapshot, size))
ZFS.replicate(dataset, previous_snapshot, snapshot, remote_dataset, replicate_settings.get('buffer_size', BUFFER_SIZE), replicate_settings['endpoint'], direction='push', compression=replicate_settings['compression'])
ZFS.hold(dataset, snapshot)
ZFS.hold(remote_dataset, snapshot, replicate_settings['endpoint'])
ZFS.release(dataset, previous_snapshot)
ZFS.release(remote_dataset, previous_snapshot, replicate_settings['endpoint'])
previous_snapshot = snapshot
else:
for snapshot in remote_snapshots[remote_dataset]:
if snapshot == last_common_snapshot:
previous_snapshot = last_common_snapshot
continue
if previous_snapshot is not None:
# There is a remote snapshot that is not yet on the local host.
size = ZFS.get_size(remote_dataset, previous_snapshot, snapshot, replicate_settings['endpoint'])
Manager.logger.info(' {0}@{1} > {0}@{2} ({3})'.format(remote_dataset, previous_snapshot, snapshot, size))
ZFS.replicate(remote_dataset, previous_snapshot, snapshot, dataset, replicate_settings.get('buffer_size', BUFFER_SIZE), replicate_settings['endpoint'], direction='pull', compression=replicate_settings['compression'])
ZFS.hold(dataset, snapshot)
ZFS.hold(remote_dataset, snapshot, replicate_settings['endpoint'])
ZFS.release(dataset, previous_snapshot)
ZFS.release(remote_dataset, previous_snapshot, replicate_settings['endpoint'])
previous_snapshot = snapshot
#.........这里部分代码省略.........
示例14: is_held
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import run_command [as 别名]
def is_held(target, snapshot, endpoint=''):
if endpoint == '':
command = 'zfs holds {0}@{1}'.format(target, snapshot)
return 'zsm' in Helper.run_command(command, '/')
command = '{0} \'zfs holds {1}@{2}\''.format(endpoint, target, snapshot)
return 'zsm' in Helper.run_command(command, '/')