def _mmc_proxy_init(self): """Starts the cleint mmc proxy for remote calls """ proto = "https" if self.config.mmc.enablessl else "http" url = "%s://%s:%d/XMLRPC" % (proto, self.config.mmc.host, self.config.mmc.port, ) self.mmc_proxy = Proxy(url, self.config.mmc.user, self.config.mmc.passwd, )
def _build_proxy(self): """ Builds the XML-RPC proxy to MMC agent. """ log.debug("Building mmc-agent proxy") try: return Proxy(self._url, self._username, self._password) except Exception, err: log.error("Error while connecting to mmc-agent : %s" % err) return False
class MMCProxy(object): """ Provider to connect at mmc-agent """ def __init__(self): config = ConfigReader() self.scheduler_config = config.scheduler_config self.base_config = config.base_config self._url = None self._proxy = None self._username = self.scheduler_config.get("mmc_agent", "username") self._password = self.scheduler_config.get("mmc_agent", "password") self._build_url() def _build_url(self): """ URL building for XML-RPC proxy """ if not self.scheduler_config.has_section("mmc_agent") : log.error("Error while reading the config file: Section 'mmc_agent' not exists") return False host = self.scheduler_config.get("mmc_agent", "host") port = self.scheduler_config.get("mmc_agent", "port") log.debug("Building the connection URL at mmc-agent") self._url = 'https://%s:%s/XMLRPC' % (host, port) def _get_ldap_password(self): """ Password for LDAP authentification @return: string """ if not self.base_config.has_section("ldap") : log.error("Error while reading the config file: Section 'ldap'") return False return self.base_config.get("ldap","password") def _build_proxy(self): """ Builds the XML-RPC proxy to MMC agent. """ log.debug("Building mmc-agent proxy") try : self._proxy = Proxy(self._url, self._username, self._password) log.debug("LDAP Authentication") return self._proxy.callRemote('base.ldapAuth', 'root', self._get_ldap_password()) except Exception, err : log.error("Error while connecting to mmc-agent : %s" % err) return False
def _build_proxy(self): """ Builds the XML-RPC proxy to MMC agent. """ log.debug("Building mmc-agent proxy") try : self._proxy = Proxy(self._url, self._username, self._password) log.debug("LDAP Authentication") return self._proxy.callRemote('base.ldapAuth', 'root', self._get_ldap_password()) except Exception, err : log.error("Error while connecting to mmc-agent : %s" % err) return False
class Endpoint(object): """ Defines a base frame for objects which process the incoming requests. All methods to be call must be declared in an inherited class, otherwise the exception MethodNotFound will be throwed. Each endpoint defines a prefix. This parameter helps to resolve the name of method which will be called. That avoids the mistakes when a same method name is already defined in another endpoint. """ prefix = None config = None def __init__(self, config): self.config = config self.logger = logging.getLogger() self._mmc_proxy_init() def _mmc_proxy_init(self): """Starts the cleint mmc proxy for remote calls """ proto = "https" if self.config.mmc.enablessl else "http" url = "%s://%s:%d/XMLRPC" % (proto, self.config.mmc.host, self.config.mmc.port, ) self.mmc_proxy = Proxy(url, self.config.mmc.user, self.config.mmc.passwd, ) def call_method(self, name, *args): """ Calls a method defined in an inherited class @param method: method name @type method: str @param args: arguments @type args: list """ if hasattr(self, name): method = getattr(self, name) return method(*args) else: raise MethodNotFound(name) def _get_machine_uuid(self, hostname, macs): """ A remote call to get UUID of machine. @param hostname: hostname of machine @type hostname: str @param macs: list of active MAC addresses of machine @type macs: list @return: UUID of machine @rtype: Deferred """ d = self.mmc_proxy.callRemote("base.ldapAuth", self.config.mmc.ldap_user, self.config.mmc.ldap_passwd, ) @d.addCallback def cb(result): if result: method = "base.getComputerByHostnameAndMacs" return self.mmc_proxy.callRemote(method, hostname, macs) @d.addErrback def eb(failure): self.logger.error("MMC LDAP auth failed: %s" % str(failure)) return failure return d