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"])
Beispiel #2
0
    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"])
Beispiel #3
0
            'res_monitor': 'op monitor interval="60s"',
        }
        clones = {
            'cl_monitor': 'res_monitor meta interleave="true"',
        }

        relation_set(corosync_bindiface=cluster_config['ha-bindiface'],
                     corosync_mcastport=cluster_config['ha-mcastport'],
                     resources=resources,
                     resource_params=resource_params,
                     clones=clones)


@hooks.hook('ha-relation-departed')
def ha_relation_destroyed():
    # If e.g. we want to upgrade to Juno and use native Neutron HA support then
    # we need to un-corosync-cluster to enable the transition.
    if config('ha-legacy-mode'):
        stop_neutron_ha_monitor_daemon()
        remove_legacy_ha_files()


if __name__ == '__main__':
    try:
        hooks.execute(sys.argv)
    except UnregisteredHookError as e:
        log('Unknown hook {} - skipping.'.format(e))
    set_os_workload_status(CONFIGS,
                           REQUIRED_INTERFACES,
                           charm_func=check_optional_relations)
        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)
Beispiel #5
0

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)