本文整理汇总了Python中cattle.Config.home方法的典型用法代码示例。如果您正苦于以下问题:Python Config.home方法的具体用法?Python Config.home怎么用?Python Config.home使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cattle.Config
的用法示例。
在下文中一共展示了Config.home方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import home [as 别名]
def execute(self, event):
if not _should_handle(self, event):
return
if len(event.data.items) == 0:
return utils.reply(event)
item_names = []
for item in event.data.items:
# For development, don't let the server kill your agent
if item.name != 'pyagent' or Config.config_update_pyagent():
item_names.append(item.name)
home = Config.home()
env = dict(os.environ)
env['CATTLE_ACCESS_KEY'] = Config.access_key()
env['CATTLE_SECRET_KEY'] = Config.secret_key()
env['CATTLE_CONFIG_URL'] = Config.config_url()
env['CATTLE_HOME'] = home
args = [Config.config_sh()] + item_names
try:
output = utils.get_command_output(args, cwd=home, env=env)
return utils.reply(event, {
'exitCode': 0,
'output': output
})
except subprocess.CalledProcessError as e:
Progress(event).update('Update Failed', data={
'exitCode': e.returncode,
'output': e.output
})
示例2: ns_exec
# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import home [as 别名]
def ns_exec(pid, event):
script = os.path.join(Config.home(), 'events', event.name.split(';')[0])
cmd = ['nsenter',
'-F',
'-m',
'-u',
'-i',
'-n',
'-p',
'-t', str(pid),
'--', script]
marshaller = get_type(MARSHALLER)
input = marshaller.to_string(event)
data = None
env = {}
#in come customized docker like alidocker use with open('/host/proc/{}/environ'.format(pid)) as f:
with open('/proc/{}/environ'.format(pid)) as f:
for line in f.read().split('\0'):
if not len(line):
continue
kv = line.split('=', 1)
if kv[0].startswith('CATTLE'):
env[kv[0]] = kv[1]
env['PATH'] = os.environ['PATH']
env['CATTLE_CONFIG_URL'] = Config.config_url()
for i in range(3):
p = popen(cmd,
env=env,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
output, error = p.communicate(input=input)
retcode = p.poll()
if retcode == 0:
break
exists_cmd = cmd[:-1] + ['/usr/bin/test', '-e', script]
if popen(exists_cmd, env=env).wait() == 0:
break
# Sleep and try again if missing
time.sleep(1)
if retcode:
return retcode, output, None
text = []
for line in output.splitlines():
if line.startswith('{'):
data = marshaller.from_string(line)
break
text.append(line)
return retcode, ''.join(text), data
示例3: ns_exec
# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import home [as 别名]
def ns_exec(pid, event):
script = os.path.join(Config.home(), 'events', event.name.split(';')[0])
cmd = ['nsenter',
'-F',
'-m',
'-u',
'-i',
'-n',
'-p',
'-t', str(pid),
'--', script]
marshaller = get_type(MARSHALLER)
input = marshaller.to_string(event)
data = None
env = {}
with open('/proc/{}/environ'.format(pid)) as f:
for line in f.read().split('\0'):
if not len(line):
continue
kv = line.split('=', 1)
if kv[0].startswith('CATTLE'):
env[kv[0]] = kv[1]
env['PATH'] = os.environ['PATH']
p = popen(cmd,
env=env,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
output, error = p.communicate(input=input)
retcode = p.poll()
if retcode:
return retcode, output, None
text = []
for line in output.splitlines():
if line.startswith('{'):
data = marshaller.from_string(line)
break
text.append(line)
return retcode, ''.join(text), data
示例4: docker_uuid_file
# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import home [as 别名]
def docker_uuid_file():
def_value = '{0}/.docker_uuid'.format(Config.home())
return default_value('DOCKER_UUID_FILE', def_value)
示例5: websockify_session_dir
# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import home [as 别名]
def websockify_session_dir():
return default_value('LIBVIRT_WEBSOCKIFY_DIR',
os.path.join(Config.home(), 'websockify',
'session'))
示例6: libvirt_uuid_file
# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import home [as 别名]
def libvirt_uuid_file():
def_value = '{0}/.libvirt_uuid'.format(Config.home())
return default_value('LIBVIRT_UUID_FILE', def_value)
示例7: config_drive_directory
# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import home [as 别名]
def config_drive_directory():
return default_value('LIBVIRT_CONFIG_DRIVE_DIR',
path.join(Config.home(), 'pools/config-drive'))
示例8: pool_directories
# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import home [as 别名]
def pool_directories():
return default_value('LIBVIRT_POOL_DIRECTORIES',
path.join(Config.home(), 'pools/libvirt')).split()