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


Python hookenv.unit_get方法代码示例

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


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

示例1: write_prometheus_config_def

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import unit_get [as 别名]
def write_prometheus_config_def():
    config = hookenv.config()
    port = config.get('port', '9090')
    check_ports(port)
    if config.get('external_url', False):
        vars = {
            'private_address': hookenv.unit_get('private-address'),
            'public_address': hookenv.unit_get('public-address'),
            # prometheus default:
            'port': port,
        }
        runtime_args('-web.external-url',
                     config['external_url'].format(**vars))
    args = runtime_args()
    hookenv.log('runtime_args: {}'.format(args))
    if args:
        render(source=PROMETHEUS_DEF_TMPL,
               target=PROMETHEUS_DEF,
               context={'args': args},
               )
    set_state('prometheus.do-restart')
    remove_state('prometheus.do-reconfig-def') 
开发者ID:tasdomas,项目名称:juju-charm-prometheus,代码行数:24,代码来源:prometheus.py

示例2: provide_data

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import unit_get [as 别名]
def provide_data(self):
        return {
            'host': hookenv.unit_get('private-address'),
            'port': 80,
        } 
开发者ID:openstack,项目名称:charm-plumgrid-gateway,代码行数:7,代码来源:helpers.py

示例3: sniff_iface

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import unit_get [as 别名]
def sniff_iface(f):
    """Ensure decorated function is called with a value for iface.

    If no iface provided, inject net iface inferred from unit private address.
    """
    def iface_sniffer(*args, **kwargs):
        if not kwargs.get('iface', None):
            kwargs['iface'] = get_iface_from_addr(unit_get('private-address'))

        return f(*args, **kwargs)

    return iface_sniffer 
开发者ID:openstack,项目名称:charm-plumgrid-gateway,代码行数:14,代码来源:ip.py

示例4: get_local_ip

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import unit_get [as 别名]
def get_local_ip() -> Result:
    """
    Returns the local IPAddr address associated with this server
    # Failures
    Returns a GlusterError representing any failure that may have happened
    while trying to
    query this information.
    """
    ip_addr = get_host_ip(unit_get('private-address'))
    try:
        parsed = ip_address(address=ip_addr)
        return Ok(parsed)  # Resolves a str hostname into a ip address.
    except ValueError:
        return Err("failed to parse ip address: {}".format(ip_addr)) 
开发者ID:openstack,项目名称:charm-glusterfs,代码行数:16,代码来源:volume.py

示例5: get_database_setup

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import unit_get [as 别名]
def get_database_setup(self):
        """Provide the default database credentials as a list of 3-tuples

        returns a structure of:
        [
            {'database': <database>,
             'username': <username>,
             'hostname': <hostname of this unit>
             'prefix': <the optional prefix for the database>, },
        ]

        :returns [{'database': ...}, ...]: credentials for multiple databases
        """
        host = None
        try:
            host = hookenv.network_get_primary_address('shared-db')
        except NotImplementedError:
            host = hookenv.unit_get('private-address')

        return [
            dict(
                database=self.config['database'],
                username=self.config['database-user'],
                hostname=host, )
        ]


# Determine the charm class by the supported release 
开发者ID:openstack,项目名称:charm-trove,代码行数:30,代码来源:trove.py

示例6: write_prometheus_config_yml

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import unit_get [as 别名]
def write_prometheus_config_yml():
    config = hookenv.config()
    target_jobs = unitdata.kv().get('target_jobs', [])
    scrape_jobs = unitdata.kv().get('scrape_jobs', [])

    # transform eg. 'h1:p1 ,  h2:p2' (string), to ['h1:p1', 'h2:p2'] (list)
    static_targets = None
    if config.get('static-targets'):
        static_targets = [x.strip()
                          for x in config.get('static-targets', '').split(',')]

    default_monitor_name = '{}-monitor'.format(hookenv.service_name())
    options = {
        'scrape_interval': config['scrape-interval'],
        'evaluation_interval': config['evaluation-interval'],
        'static_targets': static_targets,
        'private_address': hookenv.unit_get('private-address'),
        'monitor_name': config.get('monitor_name', default_monitor_name),
        'jobs': target_jobs,
        'scrape_jobs': scrape_jobs,
    }

    # custom-rules content must be passed verbatim with e.g.
    #   juju set prometheus custom-rules @my.rules
    if config.get('custom-rules'):
        custom_rules = config['custom-rules']
        with open(CUSTOM_RULES_PATH, 'w') as fh:
            fh.write(custom_rules)
        options['custom_rules_file'] = CUSTOM_RULES_PATH

    render(source=PROMETHEUS_YML_TMPL,
           target=PROMETHEUS_YML,
           context=options
           )
    validate_config()
    set_state('prometheus.do-restart')
    remove_state('prometheus.do-reconfig-yml') 
开发者ID:tasdomas,项目名称:juju-charm-prometheus,代码行数:39,代码来源:prometheus.py


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