- def __init__(self, hosts):
- r"Initialize HostHandler object, see class documentation for details."
- self.hosts = hosts
-
- @handler(u'Add a new host')
- def add(self, name, ip, mac):
- r"add(name, ip, mac) -> None :: Add a host to the hosts list."
- if name in self.hosts:
- raise HostAlreadyExistsError(name)
- self.hosts[name] = Host(name, ip, mac)
-
- @handler(u'Update a host')
- def update(self, name, ip=None, mac=None):
- r"update(name[, ip[, mac]]) -> None :: Update a host of the hosts list."
- if not name in self.hosts:
- raise HostNotFoundError(name)
- if ip is not None:
- self.hosts[name].ip = ip
- if mac is not None:
- self.hosts[name].mac = mac
-
- @handler(u'Delete a host')
- def delete(self, name):
- r"delete(name) -> None :: Delete a host of the hosts list."
- if not name in self.hosts:
- raise HostNotFoundError(name)
- del self.hosts[name]
-
- @handler(u'Get information about a host')
- def get(self, name):
- r"get(name) -> Host :: List all the information of a host."
- if not name in self.hosts:
- raise HostNotFoundError(name)
- return self.hosts[name]
-
- @handler(u'List hosts')
- def list(self):
- r"list() -> tuple :: List all the hostnames."
- return self.hosts.keys()
-
- @handler(u'Get information about all hosts')
- def show(self):
- r"show() -> list of Hosts :: List all the complete hosts information."
- return self.hosts.values()
-