本文整理汇总了Python中cattle.Config类的典型用法代码示例。如果您正苦于以下问题:Python Config类的具体用法?Python Config怎么用?Python Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
if Config.setup_logger():
_setup_logger()
else:
logging.basicConfig(level=logging.INFO)
args = _args()
Config.set_access_key(args.access_key)
Config.set_secret_key(args.secret_key)
Config.set_api_url(args.url)
process_manager.init()
plugins.load()
log.info('API URL %s', Config.api_url())
client = EventClient(Config.api_url(), auth=Config.api_auth(),
workers=args.workers, agent_id=args.agent_id)
events = _gather_events()
log.info("Subscribing to %s", events)
for startup in get_type_list(LIFECYCLE):
startup.on_startup()
client.run(events)
sys.exit(0)
示例2: _run
def _run(self, events):
ppid = os.environ.get("AGENT_PARENT_PID")
headers = {}
args = {
"data": _data(events, self._agent_id),
"stream": True,
"headers": headers,
"timeout": Config.event_read_timeout()
}
if self._auth is not None:
if isinstance(self._auth, basestring):
headers["Authorization", self._auth]
else:
args["auth"] = self._auth
try:
drop_count = 0
ping_drop = 0
r = requests.post(self._url, **args)
if r.status_code != 201:
raise Exception(r.text)
self._start_children()
for line in r.iter_lines(chunk_size=1):
try:
ping = '"ping' in line
if len(line) > 0:
# TODO Need a better approach here
if ping:
self._ping_queue.put(line, block=False)
ping_drop = 0
else:
self._queue.put(line, block=False)
except Full:
log.info("Dropping request %s" % line)
drop_count += 1
max = Config.max_dropped_requests()
if ping:
ping_drop += 1
max = Config.max_dropped_ping()
if drop_count > max:
log.error('Max dropped requests [%s] exceeded', max)
break
if not _should_run(ppid):
log.info("Parent process has died or stamp changed,"
" exiting")
break
finally:
for child in self._children:
if hasattr(child, "terminate"):
try:
child.terminate()
except:
pass
sys.exit(0)
示例3: setup_cattle_config_url
def setup_cattle_config_url(instance, create_config):
if instance.get('agentId') is None:
return
if 'labels' not in create_config:
create_config['labels'] = {}
create_config['labels']['io.rancher.container.agent_id'] = \
str(instance.get('agentId'))
url = Config.config_url()
if url is not None:
parsed = urlparse(url)
if 'localhost' == parsed.hostname:
port = Config.api_proxy_listen_port()
add_to_env(create_config,
CATTLE_AGENT_INSTANCE='true',
CATTLE_CONFIG_URL_SCHEME=parsed.scheme,
CATTLE_CONFIG_URL_PATH=parsed.path,
CATTLE_CONFIG_URL_PORT=port)
else:
add_to_env(create_config, CATTLE_CONFIG_URL=url)
add_to_env(create_config, CATTLE_URL=url)
示例4: test_default_value
def test_default_value():
# evn var is unset, return default
var_name = uuid.uuid4().hex
cattlefied_var_name = 'CATTLE_{}'.format(var_name)
default = 'defaulted'
actual = default_value(var_name, default)
assert default == actual
# default is explicitly blank, return blank
actual = default_value(var_name, '')
assert '' == actual
# env var is set to blank, return default
os.environ[cattlefied_var_name] = ''
actual = default_value(var_name, default)
assert default == actual
# env var is set, return env var value
os.environ[cattlefied_var_name] = 'foobar'
actual = default_value(var_name, default)
assert 'foobar' == actual
# for completeness, set_secret_key which hits the CONFIG_OVERRIDE
# code path
Config.set_secret_key('override')
actual = default_value('SECRET_KEY', default)
assert 'override' == actual
示例5: on_message
def on_message(ws, message):
line = message.strip()
try:
ping = '"ping' in line
if len(line) > 0:
# TODO Need a better approach here
if ping:
self._ping_queue.put(line, block=False)
drops['ping_drop'] = 0
else:
self._queue.put(line, block=False)
except Full:
log.info("Dropping request %s" % line)
drops['drop_count'] += 1
drop_max = Config.max_dropped_requests()
drop_type = 'overall'
drop_test = drops['drop_count']
if ping:
drops['ping_drop'] += 1
drop_type = 'ping'
drop_test = drops['ping_drop']
drop_max = Config.max_dropped_ping()
if drop_test > drop_max:
log.error('Max of [%s] dropped [%s] requests exceeded',
drop_max, drop_type)
ws.close()
if not _should_run(ppid):
log.info("Parent process has died or stamp changed,"
" exiting")
ws.close()
示例6: post
def post(req, resp):
del resp['data']['instance']['+data']['dockerInspect']
docker_container = resp['data']['instance']['+data']['dockerContainer']
fields = resp['data']['instance']['+data']['+fields']
id = docker_container['Id']
del docker_container['Created']
del docker_container['Id']
del docker_container['Status']
docker_container = _sort_ports(docker_container)
del docker_container['Ports'][0]['PublicPort']
del docker_container['Ports'][1]['PublicPort']
del fields['dockerIp']
assert fields['dockerPorts']['8080/tcp'] is not None
assert fields['dockerPorts']['12201/udp'] is not None
fields['dockerPorts']['8080/tcp'] = '1234'
fields['dockerPorts']['12201/udp'] = '5678'
inspect = Client().inspect_container(id)
port = Config.api_proxy_listen_port()
assert 'CATTLE_CONFIG_URL={0}'.format(Config.config_url()) in \
inspect['Config']['Env']
assert 'CATTLE_CONFIG_URL_SCHEME=https' not in inspect['Config']['Env']
assert 'CATTLE_CONFIG_URL_PATH=/a/path' not in inspect['Config']['Env']
assert 'CATTLE_CONFIG_URL_PORT={0}'.format(port) not in \
inspect['Config']['Env']
assert 'ENV1=value1' in inspect['Config']['Env']
示例7: _get_volume
def _get_volume(vol_name, vol_size, instance_name, user):
path = _get_volume_dir(vol_name, user)
if os.path.exists(path):
volume_uuid = _get_volume_uuid(path)
create = False
if volume_uuid == "":
log.warning("Found volume directory but cannot find related \
volume! Create one")
create = True
assert _get_volume_instance_name(path) == instance_name
if not create:
mount_dir = os.path.join(path, volume_uuid)
if not service.mounted(mount_dir,
Config.volmgr_mount_namespace_fd()):
v.mount_volume(volume_uuid, mount_dir, False,
Config.volmgr_mount_namespace_fd())
return mount_dir
volume_uuid = v.create_volume(vol_size)
v.add_volume_to_blockstore(volume_uuid, blockstore_uuid)
mount_dir = os.path.join(path, volume_uuid)
os.makedirs(mount_dir)
f = open(os.path.join(path, INSTANCE_TAG_FILE), "w")
try:
f.write(instance_name)
finally:
f.close()
v.mount_volume(volume_uuid, mount_dir, True,
Config.volmgr_mount_namespace_fd())
return mount_dir
示例8: _add_resources
def _add_resources(self, ping, pong):
if not utils.ping_include_resources(ping):
return
physical_host = Config.physical_host()
compute = {
'type': 'host',
'kind': LIBVIRT_KIND,
'name': Config.hostname() + '/libvirt',
'uuid': LibvirtConfig.libvirt_uuid(),
'physicalHostUuid': physical_host['uuid'],
'data': {
'libvirt': {
'type': self.get_default_type()
}
}
}
resources = [physical_host, compute]
for driver in pool_drivers():
for pool in driver.discover(compute):
data = utils.get_map_value(pool, 'data', 'libvirt')
data['driver'] = driver.driver_name()
resources.append(pool)
utils.ping_add_resources(pong, *resources)
示例9: ns_exec
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
示例10: volume_exists
def volume_exists(path):
if not enabled():
return False
if not path.startswith(Config.volmgr_mount_dir()):
return False
if not os.path.exists(path):
return False
return service.mounted(path, Config.volmgr_mount_namespace_fd())
示例11: _get_host_labels
def _get_host_labels(self):
try:
labels = self.host_info.host_labels()
except:
log.exception("Error getting host labels")
if Config.labels():
labels.update(Config.labels())
return labels
示例12: on_startup
def on_startup(self):
cmd = [cadvisor_bin(),
'-logtostderr=true',
'-ip', Config.cadvisor_ip(),
'-port', str(Config.cadvisor_port())]
if os.path.exists('/host/proc/1/ns/mnt'):
cmd = ['nsenter', '--mount=/host/proc/1/ns/mnt', '--'] + cmd
background(cmd)
示例13: __init__
def __init__(self, docker_client=None):
self.unit = 1048576
self.cadvisor = CadvisorAPIClient(Config.cadvisor_ip(),
Config.cadvisor_port())
self.docker_client = docker_client
self.docker_storage_driver = None
if self.docker_client:
self.docker_storage_driver = \
self.docker_client.info().get("Driver", None)
示例14: on_startup
def on_startup(self):
env = dict(os.environ)
env['HOST_API_CONFIG_FILE'] = host_api_config()
url = 'http://{0}:{1}'.format(Config.cadvisor_ip(),
Config.cadvisor_port())
background(['host-api',
'-cadvisor-url', url,
'-logtostderr=true',
'-ip', Config.host_api_ip(),
'-port', str(Config.host_api_port())],
env=env)
示例15: _args
def _args():
parser = argparse.ArgumentParser(add_help=True)
parser.add_argument("--access-key", default=Config.access_key(),
help='Default value from CATTLE_ACCESS_KEY')
parser.add_argument("--secret-key", default=Config.secret_key(),
help='Default value from CATTLE_SECRET_KEY')
parser.add_argument("--url", default=Config.api_url(),
help='Default value from CATTLE_URL')
parser.add_argument("--workers", default=Config.workers(),
help='Default value from CATTLE_WORKERS')
parser.add_argument("--agent-id")
return parser.parse_args()