コード例 #1
0
def restart_platform(plugin):
    if is_state('platform.started'):
        remove_state('platform.started')
    if is_state('platform.start.failed'):
        remove_state('platform.start.failed')
    remove_state('hpcc-plugins.restart.platform')

    platform = HPCCSystemsPlatformConfig()
    if platform.restart():
        set_state('platform.start.failed')
        hookenv.status_set('blocked', 'hpcc start failed')
    else:
        set_state('platform.started')
        hookenv.status_set('active', 'started')
コード例 #2
0
ファイル: iptables.py プロジェクト: phvalguima/layer-iptables
def ruleset_changed():
    if not is_state('iptables.started'):
        iptables_start()
    status_set('maintenance', 'Setting up IPTables')
    setup_rules()
    setup_policy()
    status_set('active', 'Policy: %s' % get_policy_name() )
コード例 #3
0
def save_and_notify(relation, data):
    if helpers.is_state('app.started') and not helpers.data_changed(
            relation, data):
        hookenv.log("!!! data IS NOT changed for {} {}".format(relation, data))
        return
    db.set(relation, data)
    hookenv.log("!!! data saved for {} {}".format(relation, data))
    reactive.set_state('app.changed')
コード例 #4
0
ファイル: iptables.py プロジェクト: phvalguima/layer-iptables
def connected(peers):
    log("peers.joined %s"%peers.units() )
    config = hookenv.config()
    addresses = get_all_addresses()
    peers.set_remote('addresses', ' '.join(addresses))
    if is_state('iptables.started'):
        hosts = get_peers()
        if data_changed('peers', hosts):
            ipset_update(peers_set_name(), hosts)
コード例 #5
0
def connected(peers):
    log("ssh-peers.joined")
    config = hookenv.config()
    addresses = get_all_addresses()
    peers.set_remote('addresses', ' '.join(addresses))
    if is_state('iptables.started'):
        hosts = get_ssh_peers()
        if data_changed('ssh-peers', hosts):
            ipset_update('ssh-peers', hosts)
コード例 #6
0
def submit_if_needed():
    """
    Retry collecting and/or submitting the data if the last attempt failed.
    """
    rdebug('update-status invoked')

    if not rhelpers.is_state('storpool-inventory.collected'):
        rdebug('triggering a new collection attempt')
        spstatus.reset()
        reactive.set_state('storpool-inventory.collecting')
    else:
        rdebug('already collected!')

    if not rhelpers.is_state('storpool-inventory.submitted'):
        rdebug('triggering a new submission attempt')
        spstatus.reset()
        reactive.set_state('storpool-inventory.submitting')
    else:
        rdebug('already submitted!')
コード例 #7
0
def iptables_stop():
    log('Stopping firewall')
    status_set('maintenance', 'Stopping IPTables')
    if is_state('enforcing'):
        not_enforce()
    ipset_destroy('ssh-peers')
    ipset_destroy('ssh-allow-hosts')
    ipset_destroy('ssh-allow-networks')
    remove_state('iptables.started')
    status_set('maintenance', 'Stopped')
コード例 #8
0
def install_platform():
    if is_state('platform.installed'):
        return
    platform = HPCCSystemsPlatformConfig()
    platform.install_prerequsites()
    platform.install_platform()
    # ssh keys?
    config = hookenv.config()
    if config['ssh-key-private']:
        install_keys_from_config(config)
    set_state('platform.installed')
コード例 #9
0
def have_config():
    """
    Check whether the `submit_url` configuration parameter has been set or
    changed; if so, trigger a collect-and-submit cycle.
    """
    rdebug('config-changed')
    config = hookenv.config()

    url = config.get('submit_url', None)
    if url is not None and url != '':
        if config.changed('submit_url') or \
           not rhelpers.is_state('storpool-inventory.configured'):
            spstatus.reset()
            reactive.set_state('storpool-inventory.configured')
            rdebug(
                'we have a new submission URL address: {url}'.format(url=url))
            reactive.set_state('storpool-inventory.submitting')
            reactive.remove_state('storpool-inventory.submitted')

            if not rhelpers.is_state('storpool-inventory.collected') and \
               not rhelpers.is_state('storpool-inventory.collecting'):
                rdebug('triggering another collection attempt')
                spstatus.npset('maintenance',
                               'about to try to collect data again')
                reactive.set_state('storpool-inventory.collecting')
            else:
                spstatus.npset('maintenance',
                               'about to resubmit any collected data')
        else:
            rdebug('the submission URL address seems to be the same as before')
    else:
        rdebug('we do not seem to have a submission URL address')
        reactive.remove_state('storpool-inventory.configured')
        reactive.remove_state('storpool-inventory.submitting')
        reactive.remove_state('storpool-inventory.submitted')
        spstatus.reset()
        spstatus.npset('maintenance', 'waiting for configuration')
コード例 #10
0
def install_platform():
    if is_state('platform.installed'):
        return
    hpccInstaller = HPCCInstallation()
    hpccInstaller.install()
    # ssh keys?
    #config = hookenv.config()
    #if config['ssh-key-private']:
    #    install_keys_from_config(config)

    config = hookenv.config()
    if (config['node-type'] == "standalone" ):
        hpcc_config = HPCCConfig()
        hpcc_config.open_ports()

    set_state('platform.installed')
コード例 #11
0
def handle(hk, attaching, data, rdebug=lambda s: s):
    """
    Handle a state change of the internal hook; update our state if needed.
    """
    rdebug('service_hook.handle for a {t} hook {name}, attaching {attaching}, '
           'data keys {ks}'.format(
               t=type(hk).__name__,
               name=hk.relation_name,
               attaching=attaching,
               ks=sorted(data.keys()) if data is not None else None))
    db = unitdata.kv()
    (state, changed) = get_state(db)
    rdebug('- current state: {state}'.format(state=state))
    rdebug('- changed even at the start: {changed}'.format(changed=changed))

    key = hk.conversation().key
    rdebug('- conversation key: {key}'.format(key=key))
    if attaching:
        rdebug('- attaching: adding new hosts as reported')
        for (name, value) in data.items():
            rdebug('  - processing name "{name}" value "{value}"'.format(
                name=name, value=value))
            if update_state(db, state, changed, key, name, value):
                changed = True
            rdebug('    - changed: {changed}'.format(changed=changed))
    else:
        if key in state:
            rdebug('- detaching: the conversation has been recorded, '
                   'removing it')
            del state[key]
            changed = True
            set_state(db, state)
        else:
            rdebug('- detaching, but we had no idea we were having '
                   'this conversation, so nah')

    if changed:
        rdebug('- updated state: {state}'.format(state=state))

    if changed or helpers.data_changed(kvdata.KEY_PRESENCE, state) or \
       not helpers.is_state('storpool-service.changed'):
        rdebug('- something changed, notifying whomever should care')
        reactive.set_state('storpool-service.change')
    return changed
コード例 #12
0
ファイル: iptables.py プロジェクト: phvalguima/layer-iptables
def nat_changed():
    if not is_state('iptables.started'):
        iptables_start()
    status_set('maintenance', 'Setting up NAT Table')
    setup_nat()
    status_set('active', 'ready' )
コード例 #13
0
ファイル: iptables.py プロジェクト: phvalguima/layer-iptables
def departed(peers):
    log("peers.departed %s"%peers.units() )
    if is_state('iptables.started'):
        hosts = get_peers()
        if data_changed('peers', hosts):
            ipset_update(peers_set_name(), hosts)
コード例 #14
0
def save_and_notify(relation, data):
    if helpers.is_state('app.started') and not helpers.data_changed(relation, data):
        return
    db.set(relation, data)
    reactive.set_state('app.changed')
コード例 #15
0
def ssh_allow_networks_changed():
    if is_state('iptables.started'):
        config = hookenv.config()
        hosts = config['ssh-allow-networks'].split()
        if data_changed('ssh-allow-networks', hosts):
            ipset_update('ssh-allow-networks', hosts)
コード例 #16
0
def departed(peers):
    log("ssh-peers.departed")
    if is_state('iptables.started'):
        hosts = get_ssh_peers()
        if data_changed('ssh-peers', hosts):
            ipset_update('ssh-peers', hosts)