def add(self, ip_address, canonical_hostname, *args): """Add new hostname to the container. Each host is composed by: * IP address * Main hostname * Aliases to the main hostname At this moment multiple aliases are accepted and inserted but only one is used and saved back. :Results: None """ if not utils.isValidIP(ip_address): raise InvalidIPException("%s is not a valid IP address" % ip_address) sys.exit(1) if not utils.isValidHostname(canonical_hostname): raise InvalidHostnameException("%s is not a valid hostname" % canonical_hostname) sys.exit(1) self.__hosts.append({"ip_address": ip_address, "canonical_hostname": canonical_hostname, "aliases": args}) self.__save(self.hosts_file)
def delete(self, canonical_hostname): """Delete existing hostname. A valid hostname must be passed, no IP or alias are valid arguments. :Results: None """ if not utils.isValidHostname(canonical_hostname): raise InvalidHostnameException("%s is not a valid hostname" % canonical_hostname) sys.exit(1) self.__hosts = [{"ip_address": host["ip_address"], "canonical_hostname": host["canonical_hostname"], "aliases": host["aliases"]} for host in self.__hosts if host["canonical_hostname"] != canonical_hostname] self.__save(self.hosts_file)