def _process_special(self, who, key): if key == 'ip' and who == 'auto': return utils.get_host_ip() if key == 'user' and who == 'auto': return sh.getuser() if who == 'auto': raise KeyError("Unknown auto key type %s" % (key)) return None
def _resolve_value(self, section, option, value_gotten): if not value_gotten: if section == "host" and option == "ip": LOG.debug( "Host ip from configuration/environment was empty, programatically attempting to determine it." ) value_gotten = utils.get_host_ip() LOG.debug("Determined your host ip to be: %r" % (value_gotten)) return value_gotten
def test_load__auto_reference(self): self.sample = """ ip: "$(auto:ip)" host: "$(auto:hostname)" home: "$(auto:home)" """ self._write_samples() processed = self.loader.load('sample') self.assertTrue(isinstance(processed, utils.OrderedDict)) self.assertEqual(len(processed), 3) self.assertEqual(processed['ip'], utils.get_host_ip()) self.assertEqual(processed['host'], shell.hostname()) self.assertEqual(processed['home'], shell.gethomedir())
def get_option(self, option, *options, **kwargs): if option == 'db': src = { option: { 'host': 'localhost', 'port': 3306, 'type': 'mysql', 'user': '******' }, } elif option == 'ip': return utils.get_host_ip() elif utils.has_any(option, 'extra_flags', 'extra_opts', 'instances_path'): return '' else: # Make a fake dictionary hierachy src = make_fakey([option] + list(options)) return utils.get_deep(src, [option] + list(options))