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
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
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', })
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)
def get_controllers(): controllers = [] for endpoint in execution_environment()['env']['JUJU_API_ADDRESSES'].split(" "): ip,port=endpoint.split(':') controllers.append(ip) return controllers
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)