#!/usr/bin/python2.5 """ Copyright (C) 2008 Norman Messtorff This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. """ import xmlrpclib from socket import gethostname from Configuration import Configuration class TransportClient(Configuration): """Provides transport methodes - the client side""" def __init__(self): Configuration.__init__(self, "node") self.cli = xmlrpclib.ServerProxy(self.config["server"]["url"]) self.registered = False self.debug(4, "Class TransportClient initialized") def __del__(self): if self.registered: self.unregister() def register(self): """Register node to DebMan""" if self.config["local"]["nodeid"] == "0" and self.config["local"]["password"]: new_credentials = self.cli.register(self.config["local"]["nodeid"], self.config["local"]["hostname"], self.config["local"]["password"]) if not new_credentials: self.debug(1, "Could not request new credentials!") return False self.cfg_write_item("local", "nodeid", str(new_credentials[0])) self.cfg_write_item("local", "password", str(new_credentials[1])) self.registered = True self.debug(3, "Register success, got new credentials: "+ self.config["local"]["hostname"] +"["+ self.config["local"]["nodeid"] + "]") elif self.cli.register(self.config["local"]["nodeid"], self.config["local"]["hostname"], self.config["local"]["password"]): self.registered = True self.debug(3, "Register success: "+ self.config["local"]["hostname"] +"[" + self.config["local"]["nodeid"]+"]") return 0 else: self.debug(1, "Could not register node: " + self.config["local"]["hostname"]) return False def unregister(self): """Unregister node from DebMan""" if self.cli.unregister(self.config["local"]["hostname"]): self.registered = False self.debug(3, "Unregister success: " + self.config["local"]["hostname"]) return True else: self.debug(1, "Unknown register state!") return False def transmit_init(self): return self.cli.transmit_init() def transmit_append(self, pkg): return self.cli.transmit_append(pkg) def transmit_exec(self, distname, distver, component, arch): return self.cli.transmit_exec(distname, distver, component, arch) def transmit(self, packageinfo): """Transmit package information""" self.cli.transmit(packageinfo) return 0 def set_updated(self): """Set LAST_UPD info...""" return self.cli.set_updated() def last_update(self): """Return the date and IP-Address of last transmission""" return self.cli.last_update() def mark_inactive(self): """Mark current node as inactive""" return self.cli.mark_inactive() def mgmt_nodeinfo_brief(self): """Get a brief overview of all nodes""" return self.cli.mgmt_nodeinfo_brief()