def touch(dest, is_local=False, owner='root:root', mode='775'): cmd_touch = 't={0} && touch $t'.format(dest) if is_local or env.is_local: cmd(cmd_touch) else: sudo('{0} && chmod {1} $t && chown {2} $t'.format( cmd_touch, mode, owner))
def mkdir(dest, is_local=False, owner='root:root', mode='775', use_sudo=True): cmd_mkdir = 't={0} && mkdir -p $t'.format(dest) if is_local or env.is_local: cmd(cmd_mkdir) elif use_sudo: sudo('{0} && chmod {1} $t && chown {2} $t'.format(cmd_mkdir, mode, owner)) else: run('{0} $t'.format(cmd_mkdir, mode, owner))
def mkdir(dest, is_local=False, owner='root:root', mode='775', use_sudo=True): cmd_mkdir = 't={0} && mkdir -p $t'.format(dest) if is_local or env.is_local: if use_sudo: sudo("sh -c '{0} && chmod {1} $t && chown {2} $t'".format( cmd_mkdir, mode, owner)) else: cmd(cmd_mkdir) elif use_sudo: sudo('{0} && chmod {1} $t && chown {2} $t'.format( cmd_mkdir, mode, owner)) else: run('{0} $t'.format(cmd_mkdir, mode, owner))
def exec_command(cluster, run, command, **kwargs): log.info('exec_command: {0}'.format(command)) action = command.split(' ', 1) result = 0 if action[0] == 'sh': result = cmd(action[1])[0] elif action[0] == 'create': env.is_local = True env.host = 'localhost' container.create(cluster[action[1]]) env.is_local = False elif action[0] == 'delete': env.is_local = True env.host = 'localhost' container.delete(cluster[action[1]]) env.is_local = False elif action[0] == 'setup': env.runs = [run] env.user = CONF.job_user env.password = CONF.job_password CONF.user = CONF.job_user CONF.password = CONF.job_password setup(**kwargs) elif action[0] == 'manage': env.runs = [run] env.user = CONF.job_user env.password = CONF.job_password CONF.user = CONF.job_user CONF.password = CONF.job_password manage(action[1], **kwargs) log.info('result_command: {0}({1})'.format(command, result)) return result
def exists(dest, is_local=False): cmd_exists = '[ -e {0} ]'.format(dest) if is_local or env.is_local: result, result_out = cmd(cmd_exists) return True if result == 0 else False else: with api.warn_only(): return True if sudo(cmd_exists).return_code == 0 else False
def check_basic(): if env.is_test: ip = { 'default': { 'ip': '192.168.1.1', 'dev': 'eth0', }, 'eth0': { 'ip': '127.0.0.1', 'dev': 'eth0', }, 'default_dev': { 'ip': '127.0.0.1', 'dev': 'eth0', }, } env.node['ip'] = ip env.node['os'] = 'CentOS 7' env.node['package_manager'] = 'yum' env.node['service_manager'] = 'systemd' return { 'msg': status.SUCCESS_CHECK_MSG, 'task_status': status.SUCCESS, } # Check ping result = cmd(cmd_ping.format(env.host), retry_ttl=2, retry_interval=1) if result[0] != 0: log.warning(status.FAILED_CHECK_PING_MSG) return { 'msg': status.FAILED_CHECK_PING_MSG, 'task_status': status.FAILED_CHECK_PING, } if not set_os(): log.warning(status.FAILED_CHECK_OS_MSG) return { 'msg': status.FAILED_CHECK_OS_MSG, 'task_status': status.FAILED_CHECK_OS, } # Set IP if not set_ip(): log.warning(status.FAILED_CHECK_SSH_MSG) return { 'msg': status.FAILED_CHECK_SSH_MSG, 'task_status': status.FAILED_CHECK_SSH, } log.info(status.SUCCESS_CHECK_MSG) return { 'msg': status.SUCCESS_CHECK_MSG, 'task_status': status.SUCCESS, }
def print_list(key=None): if key: path = os.path.join(CONF._databag_dir, key) else: path = CONF._databag_dir output = cmd('find {0}'.format(path)) RE_DATABAG_YAML = re.compile('{0}/(.*).yaml'.format(CONF._databag_dir)) bags = RE_DATABAG_YAML.findall(output[1]) if len(bags) == 0: print 'Databag was not found.' else: for bag in bags: print bag
def touch(dest, is_local=False, owner='root:root', mode='775'): cmd_touch = 't={0} && touch $t'.format(dest) if is_local or env.is_local: cmd(cmd_touch) else: sudo('{0} && chmod {1} $t && chown {2} $t'.format(cmd_touch, mode, owner))