Example #1
0
    def do_delete(self, options):
        """Delete existing hostname.

        A valid hostname must be passed, no IP or alias are valid arguments.

        :Results: None
        """
        hosts = Hosts()
        try:
            hosts.delete(options.hostname)
        except IOError as e:
            if e.errno == 13:
                print("You don't have permissions to write '%s'. %s" % (hosts.hosts_file, "Did you forgot 'sudo'?"))
            else:
                raise IOError
            exit(1)
Example #2
0
    def do_add(self, options):
        """Add new host command.

        Each host is composed of three parts:

            * IP name
            * Main hostname
            * An alias to the main hostname.

        Both three arguments are requied.

        :Results: None
        """
        hosts = Hosts()
        try:
            hosts.add(options.ip, options.hostname, options.alias)
        except IOError as e:
            if e.errno == 13:
                print("You don't have permissions to write '%s'. %s" % (hosts.hosts_file, "Did you forgot 'sudo'?"))
            else:
                raise IOError
            exit(1)