def get_machine_id():
    """
    Get the Juju node ID from the environment; may return "None" if
    the environment settings are not as expected.
    """
    kv = unitdata.kv()
    val = kv.get(kvdata.KEY_MACHINE_ID, None)
    if val is None:
        env = hookenv.execution_environment()
        if "env" not in env:
            rdebug(
                'No "env" in the execution environment: {env}'.format(env=env)
            )
            val = ""
        elif "JUJU_MACHINE_ID" not in env["env"]:
            rdebug(
                "No JUJU_MACHINE_ID in the environment: {env}".format(
                    env=env["env"]
                )
            )
            val = ""
        else:
            val = env["env"]["JUJU_MACHINE_ID"]
        kv.set(kvdata.KEY_MACHINE_ID, val)

    return None if val == "" else val
예제 #2
0
 def _record_hook(self, hookenv):
     data = hookenv.execution_environment()
     self.conf = conf_delta = self.kv.delta(data['conf'], 'config')
     self.rels = rels_delta = self.kv.delta(data['rels'], 'rels')
     self.kv.set('env', dict(data['env']))
     self.kv.set('unit', data['unit'])
     self.kv.set('relid', data.get('relid'))
     return conf_delta, rels_delta
예제 #3
0
 def _record_hook(self, hookenv):
     data = hookenv.execution_environment()
     self.conf = conf_delta = self.kv.delta(data['conf'], 'config')
     self.rels = rels_delta = self.kv.delta(data['rels'], 'rels')
     self.kv.set('env', dict(data['env']))
     self.kv.set('unit', data['unit'])
     self.kv.set('relid', data.get('relid'))
     return conf_delta, rels_delta
예제 #4
0
    def test_gets_execution_environment_no_relation(self, os_, relations_get,
                                                    relations, relation_id,
                                                    local_unit, relation_type,
                                                    config):
        config.return_value = 'some-config'
        relation_type.return_value = 'some-type'
        local_unit.return_value = 'some-unit'
        relation_id.return_value = None
        relations.return_value = 'all-relations'
        relations_get.return_value = 'some-relations'
        os_.environ = 'some-environment'

        result = hookenv.execution_environment()

        self.assertEqual(
            result, {
                'conf': 'some-config',
                'unit': 'some-unit',
                'rels': 'all-relations',
                'env': 'some-environment',
            })
예제 #5
0
def render(template, extra={}, **kwargs):
    """Return the template rendered using Python's str.format()."""
    context = hookenv.execution_environment()
    context.update(extra)
    context.update(kwargs)
    return template.format(**context)
예제 #6
0
def get_controllers():
    controllers = []
    for endpoint in execution_environment()['env']['JUJU_API_ADDRESSES'].split(" "):
      ip,port=endpoint.split(':')
      controllers.append(ip)
    return controllers
예제 #7
0
def update_status():
    log("States %s"%get_states() )
    log("Env %s"% execution_environment()  )
    controllers = get_controllers()
    if data_changed('controllers', controllers):
        ipset_update(controllers_set_name(), controllers)
예제 #8
0
def render(template, extra={}, **kwargs):
    """Return the template rendered using Python's str.format()."""
    context = hookenv.execution_environment()
    context.update(extra)
    context.update(kwargs)
    return template.format(**context)