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


Python Hooks.execute方法代碼示例

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


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

示例1: joined

# 需要導入模塊: from charmhelpers.core.hookenv import Hooks [as 別名]
# 或者: from charmhelpers.core.hookenv.Hooks import execute [as 別名]
    def joined(self):
        """Indicate the relation is connected and install required plugins."""
        log("Installing and configuring gearman-plugin for Zuul communication")
        # zuul relation requires we install the required plugins and set the
        # address of the remote zuul/gearman service in the plugin setting.
        plugins = Plugins()
        plugins.install(PLUGINS)
        self.set_state("{relation_name}.connected")

        # Generate plugin config with address of remote unit.
        zuul_host = relation_get("private-address")
        zuul_config = ZUUL_CONFIG.format(zuul_host).encode("utf-8")
        write_file(
            GERMAN_PLUGIN, zuul_config, owner="jenkins", group="nogroup")

        # Restart jenkins so changes will take efect.
        service_restart("jenkins")

        # Trigger the extension hook to update it with zuul relation data, if
        # it's coded to do so.
        hooks = Hooks()
        hooks.execute(["extension-relation-joined"])
開發者ID:freeekanayaka,項目名稱:interface-jenkins-zuul,代碼行數:24,代碼來源:requires.py

示例2: stop_neutron_ha_monitor_daemon

# 需要導入模塊: from charmhelpers.core.hookenv import Hooks [as 別名]
# 或者: from charmhelpers.core.hookenv.Hooks import execute [as 別名]
        stop_neutron_ha_monitor_daemon()
        remove_legacy_ha_files()


@hooks.hook('update-status')
@harden()
def update_status():
    log('Updating status.')


@hooks.hook('pre-series-upgrade')
def pre_series_upgrade():
    log("Running prepare series upgrade hook", "INFO")
    series_upgrade_prepare(
        pause_unit_helper, CONFIGS)


@hooks.hook('post-series-upgrade')
def post_series_upgrade():
    log("Running complete series upgrade hook", "INFO")
    series_upgrade_complete(
        resume_unit_helper, CONFIGS)


if __name__ == '__main__':
    try:
        hooks.execute(sys.argv)
    except UnregisteredHookError as e:
        log('Unknown hook {} - skipping.'.format(e))
    assess_status(CONFIGS)
開發者ID:openstack,項目名稱:charm-neutron-gateway,代碼行數:32,代碼來源:neutron_hooks.py

示例3: fix_hostname_resolv

# 需要導入模塊: from charmhelpers.core.hookenv import Hooks [as 別名]
# 或者: from charmhelpers.core.hookenv.Hooks import execute [as 別名]

def fix_hostname_resolv():
    import socket
    hostname = socket.gethostname()
    # Make hostname resolvable
    add_line_to_file('127.0.0.1 {}\n'.format(hostname), '/etc/hosts')


def add_line_to_file(line, filepath):
    """appends line to file if not present"""
    filepath = os.path.realpath(filepath)
    if not os.path.isdir(os.path.dirname(filepath)):
        os.makedirs(os.path.dirname(filepath))
    found = False
    if os.path.isfile(filepath):
        with open(filepath, 'r+') as myfile:
            lst = myfile.readlines()
        for existingline in lst:
            if line in existingline:
                print("line already present")
                found = True
    if not found:
        myfile = open(filepath, 'a+')
        myfile.write(line+"\n")
        myfile.close()


if __name__ == "__main__":
    HOOKS.execute(sys.argv)
開發者ID:galgalesh,項目名稱:tengu-charms,代碼行數:31,代碼來源:hooks.py


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