當前位置: 首頁>>代碼示例>>Python>>正文


Python hookenv.charm_dir方法代碼示例

本文整理匯總了Python中charmhelpers.core.hookenv.charm_dir方法的典型用法代碼示例。如果您正苦於以下問題:Python hookenv.charm_dir方法的具體用法?Python hookenv.charm_dir怎麽用?Python hookenv.charm_dir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在charmhelpers.core.hookenv的用法示例。


在下文中一共展示了hookenv.charm_dir方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import charm_dir [as 別名]
def __init__(self, *args):
        self.required_options = args
        self['config'] = hookenv.config()
        with open(os.path.join(hookenv.charm_dir(), 'config.yaml')) as fp:
            self.config = yaml.load(fp).get('options', {}) 
開發者ID:openstack,項目名稱:charm-plumgrid-gateway,代碼行數:7,代碼來源:helpers.py

示例2: __call__

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import charm_dir [as 別名]
def __call__(self, manager, service_name, event_name):
        service = manager.get_service(service_name)
        new_ports = service.get('ports', [])
        port_file = os.path.join(hookenv.charm_dir(), '.{}.ports'.format(service_name))
        if os.path.exists(port_file):
            with open(port_file) as fp:
                old_ports = fp.read().split(',')
            for old_port in old_ports:
                if bool(old_port):
                    old_port = int(old_port)
                    if old_port not in new_ports:
                        hookenv.close_port(old_port)
        with open(port_file, 'w') as fp:
            fp.write(','.join(str(port) for port in new_ports))
        for port in new_ports:
            if event_name == 'start':
                hookenv.open_port(port)
            elif event_name == 'stop':
                hookenv.close_port(port) 
開發者ID:openstack,項目名稱:charm-plumgrid-gateway,代碼行數:21,代碼來源:base.py

示例3: __call__

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import charm_dir [as 別名]
def __call__(self):
        from charmhelpers.core import hookenv
        hook_name = hookenv.hook_name()

        with self.kv.hook_scope(hook_name):
            self._record_charm_version(hookenv.charm_dir())
            delta_config, delta_relation = self._record_hook(hookenv)
            yield self.kv, delta_config, delta_relation 
開發者ID:openstack,項目名稱:charm-plumgrid-gateway,代碼行數:10,代碼來源:unitdata.py

示例4: _record_charm_version

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import charm_dir [as 別名]
def _record_charm_version(self, charm_dir):
        # Record revisions.. charm revisions are meaningless
        # to charm authors as they don't control the revision.
        # so logic dependnent on revision is not particularly
        # useful, however it is useful for debugging analysis.
        charm_rev = open(
            os.path.join(charm_dir, 'revision')).read().strip()
        charm_rev = charm_rev or '0'
        revs = self.kv.get('charm_revisions', [])
        if charm_rev not in revs:
            revs.append(charm_rev.strip() or '0')
            self.kv.set('charm_revisions', revs) 
開發者ID:openstack,項目名稱:charm-plumgrid-gateway,代碼行數:14,代碼來源:unitdata.py

示例5: store_context

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import charm_dir [as 別名]
def store_context(self, file_name, config_data):
        if not os.path.isabs(file_name):
            file_name = os.path.join(hookenv.charm_dir(), file_name)
        with open(file_name, 'w') as file_stream:
            os.fchmod(file_stream.fileno(), 0o600)
            yaml.dump(config_data, file_stream) 
開發者ID:openstack,項目名稱:charm-plumgrid-gateway,代碼行數:8,代碼來源:helpers.py

示例6: pip_create_virtualenv

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import charm_dir [as 別名]
def pip_create_virtualenv(path=None):
    """Create an isolated Python environment."""
    apt_install('python-virtualenv')

    if path:
        venv_path = path
    else:
        venv_path = os.path.join(charm_dir(), 'venv')

    if not os.path.exists(venv_path):
        subprocess.check_call(['virtualenv', venv_path]) 
開發者ID:openstack,項目名稱:charm-plumgrid-gateway,代碼行數:13,代碼來源:packages.py

示例7: read_context

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import charm_dir [as 別名]
def read_context(self, file_name):
        if not os.path.isabs(file_name):
            file_name = os.path.join(hookenv.charm_dir(), file_name)
        with open(file_name, 'r') as file_stream:
            data = yaml.load(file_stream)
            if not data:
                raise OSError("%s is empty" % file_name)
            return data 
開發者ID:openstack,項目名稱:charm-swift-proxy,代碼行數:10,代碼來源:helpers.py

示例8: pip_create_virtualenv

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import charm_dir [as 別名]
def pip_create_virtualenv(path=None):
    """Create an isolated Python environment."""
    if six.PY2:
        apt_install('python-virtualenv')
    else:
        apt_install('python3-virtualenv')

    if path:
        venv_path = path
    else:
        venv_path = os.path.join(charm_dir(), 'venv')

    if not os.path.exists(venv_path):
        subprocess.check_call(['virtualenv', venv_path]) 
開發者ID:openstack,項目名稱:charm-swift-proxy,代碼行數:16,代碼來源:packages.py


注:本文中的charmhelpers.core.hookenv.charm_dir方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。