def set(key, value): """ Sets the key to the vale @param key is the configuration key @param value is what to set it to """ global CONFIG if key in CONFIG.opts: # sometimes we gotta do stuff with the key if key == 'iface': if not util.verify_iface(value): util.Error('\'%s\' is not a valid interface.' % (value)) return # valid iface, set new ipconfig new_ip = util.get_local_ip(value) if new_ip is not None: set('iface',value) set('ip_addr', new_ip) else: res = util.eval_type(value, CONFIG.opts[key]['type']) if res[0]: CONFIG.opts[key]['value'] = res[1] elif key in CONFIG._opts: # options not available in CLI res = util.eval_type(value, CONFIG._opts[key]['type']) if res[0]: CONFIG._opts[key]['value'] = res[1] else: return else: util.Error('Key "%s" not found. \'opts\' for options.' % (key))
def set(key, value): """ Sets the key to the vale @param key is the configuration key @param value is what to set it to """ global CONFIG if key in CONFIG.opts: # sometimes we gotta do stuff with the key if key == "iface": if not util.verify_iface(value): util.Error("'%s' is not a valid interface." % (value)) return # valid iface, set new ipconfig new_ip = util.get_local_ip(value) if new_ip is not None: set("iface", value) set("ip_addr", new_ip) else: res = util.eval_type(value, CONFIG.opts[key]["type"]) if res[0]: CONFIG.opts[key]["value"] = res[1] elif key in CONFIG._opts: # options not available in CLI res = util.eval_type(value, CONFIG._opts[key]["type"]) if res[0]: CONFIG._opts[key]["value"] = res[1] else: return else: util.Error("Key \"%s\" not found. 'opts' for options." % (key))
def validate(self): """ Validates the object's value to ensure it conforms to whatever type the object dictates. """ rvals = eval_type(self.value, self.type) if rvals[0]: self.value = rvals[1] return True else: return False
def validate(self): """ Validates the object's value to ensure it conforms to whatever type the object dictates. """ for t in self.types: rvals = eval_type(self.value, t) if rvals[0]: self.value = rvals[1] self.type = t return True return False