当前位置: 首页>>代码示例>>Python>>正文


Python Config.config_url方法代码示例

本文整理汇总了Python中cattle.Config.config_url方法的典型用法代码示例。如果您正苦于以下问题:Python Config.config_url方法的具体用法?Python Config.config_url怎么用?Python Config.config_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cattle.Config的用法示例。


在下文中一共展示了Config.config_url方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import config_url [as 别名]
    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']
开发者ID:assimilator101,项目名称:cattle,代码行数:31,代码来源:test_docker.py

示例2: execute

# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import config_url [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
            })
开发者ID:StrongMonkey,项目名称:python-agent,代码行数:37,代码来源:event_handlers.py

示例3: setup_cattle_config_url

# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import config_url [as 别名]
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)
开发者ID:cjellick,项目名称:python-agent,代码行数:27,代码来源:agent.py

示例4: ns_exec

# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import config_url [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
开发者ID:onehao,项目名称:rancheragent,代码行数:61,代码来源:delegate.py

示例5: post

# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import config_url [as 别名]
    def post(req, resp):
        id = resp['data']['instanceHostMap']['instance']
        id = id['+data']['dockerContainer']['Id']

        inspect = docker_client().inspect_container(id)
        instance_activate_common_validation(resp)

        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']
开发者ID:cloudnautique,项目名称:python-agent,代码行数:17,代码来源:test_docker.py

示例6: before_start

# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import config_url [as 别名]
    def before_start(self, instance, host, config, start_config):
        if instance.get('agentId') is None:
            return

        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(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(config, CATTLE_CONFIG_URL=url)
开发者ID:assimilator101,项目名称:cattle,代码行数:20,代码来源:delegate.py

示例7: on_startup

# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import config_url [as 别名]
    def on_startup(self):
        url = Config.config_url()

        if "localhost" not in url:
            return

        parsed = urlparse.urlparse(url)

        from_host = Config.api_proxy_listen_host()
        from_port = Config.api_proxy_listen_port()
        to_host_ip = socket.gethostbyname(parsed.hostname)
        to_port = get_url_port(url)

        log.info("Proxying %s:%s -> %s:%s", from_host, from_port, to_host_ip, to_port)
        listen = "TCP4-LISTEN:{0},fork,bind={1},reuseaddr".format(from_port, from_host)
        to = "TCP:{0}:{1}".format(to_host_ip, to_port)

        background(["socat", listen, to])
开发者ID:keras,项目名称:python-agent,代码行数:20,代码来源:api_proxy.py


注:本文中的cattle.Config.config_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。