def configuredProxyManagerFactory(configuration): """ A factory for generating a ProxyManager, complete with pre-created services, groups, and data from a configuration file. Most of the work here is mapping configuration to models. The collection of models is what is passed to the proxyManagerFactory. """ services = [] # build services from configuration for serviceName, serviceConf in configuration.services.items(): addresses = [util.splitHostPort(x) for x in serviceConf.listen] pservice = model.ProxyService(serviceName, addresses=addresses) # build groups for groupName, groupConf in serviceConf.groups.items(): # build hosts pgroup = model.ProxyGroup( groupName, groupConf.scheduler, groupConf.isEnabled) for hostName, hostConf in groupConf.hosts.items(): host, port = util.splitHostPort(hostConf.ip) phost = model.ProxyHost(hostName, host, port, hostConf.weight) # add the host to the group pgroup.addHost(phost) # add the group to the service pservice.addGroup(pgroup) # add the service to the service collection services.append(pservice) # call the proxyManagerFactory and return it return manager.proxyManagerFactory(services)
def configuredProxyManagerFactory(configuration): """ A factory for generating a ProxyManager, complete with pre-created services, groups, and data from a configuration file. Most of the work here is mapping configuration to models. The collection of models is what is passed to the proxyManagerFactory. """ services = [] # build services from configuration for serviceName, serviceConf in configuration.services.items(): addresses = [util.splitHostPort(x) for x in serviceConf.listen] pservice = model.ProxyService(serviceName, addresses=addresses) # build groups for groupName, groupConf in serviceConf.groups.items(): # build hosts pgroup = model.ProxyGroup(groupName, groupConf.scheduler, groupConf.isEnabled()) for hostName, hostConf in groupConf.hosts.items(): host, port = util.splitHostPort(hostConf.ip) phost = model.ProxyHost(hostName, host, port, hostConf.weight) # add the host to the group pgroup.addHost(phost) # add the group to the service pservice.addGroup(pgroup) # add the service to the service collection services.append(pservice) # call the proxyManagerFactory and return it return manager.proxyManagerFactory(services)
def __init__(self, proxyName='proxy1', proxy=[], groupName='group1', lbType=leastc, host='', address='', enabled=True, weight=1): if isinstance(proxy, str): proxy = [proxy] self.proxyName = proxyName self.proxyAddresses = [util.splitHostPort(x) for x in proxy] self.groupName = groupName self.lbType = lbType self.hostName = host self.hostAddress = util.splitHostPort(address) self.groupEnabled = enabled self.hostWeight = weight
def __init__(self, proxy='', addresses=[], group='', lbType='', host='', address='', enabled=None, weight=1): if isinstance(addresses, str): addresses = [addresses] self.proxyName = proxy self.proxyAddresses = [util.splitHostPort(x) for x in addresses] self.groupName = group self.lbType = lbType self.hostName = host self.hostAddress = util.splitHostPort(address) self.groupEnabled = enabled self.hostWeight = weight
def setupAdminSSHServer(configuration, director, services): """ Set up a server that will enable an admin user to SSH into the load-balancers's running Python Interpreter. """ if not configuration.admin.sshEnable: return host, port = util.splitHostPort(configuration.admin.sshListen) # set up a manhole def getManhole(serverProtocol): startingNamespace = { 'config': configuration, 'services': services, } return manhole.Manhole(util.getNamespace(startingNamespace)) realm = manhole_ssh.TerminalRealm() realm.chainedProtocolFactory.protocolFactory = getManhole p = portal.Portal(realm) p.registerChecker(auth.LBAdminAuthChecker(configuration.admin)) factory = manhole_ssh.ConchFactory(p) admin = internet.TCPServer(port, factory, interface=host) admin.setName('adminSSH') return admin
def delHost(self, ip=None, name=None, activegroup=0): """ remove a host """ if ip is not None: if type(ip) is not type(()): ip = util.splitHostPort(ip) elif name is not None: for ip in self.hostnames.keys(): if self.hostnames[ip] == name: break raise ValueError, "No host named %s"%(name) else: raise ValueError, "Neither ip nor name supplied" if activegroup and len(self.hosts) == 1: return 0 if ip in self.hosts: self.hosts.remove(ip) del self.hostnames[ip] del self.available[ip] if self.failed.has_key(ip): del self.failed[ip] del self.totalconns[ip] elif self.badhosts.has_key(ip): del self.badhosts[ip] else: raise ValueError, "Couldn't find host" return 1
def delHost(self, ip=None, name=None, activegroup=0): """ remove a host """ if ip is not None: if type(ip) is not type(()): ip = util.splitHostPort(ip) elif name is not None: for ip in self.hostnames.keys(): if self.hostnames[ip] == name: break raise ValueError, "No host named %s"%(name) else: raise ValueError, "Neither ip nor name supplied" if activegroup and len(self.hosts) == 1: return 0 if ip in self.hosts: self.hosts.remove(ip) del self.hostnames[ip] del self.available[ip] if self.failed.has_key(ip): del self.failed[ip] del self.totalconns[ip] del self.avg_process_time[ip] elif self.badhosts.has_key(ip): del self.badhosts[ip] else: raise ValueError, "Couldn't find host" return 1
def test_splitHostPart(self): """ Make sure host strings get split appropriately. """ hosts = ['localhost:8080', '127.0.0.1', '*:80', ':53'] answers = [('localhost', 8080), ('127.0.0.1', 0), ('', 80), ('', 53)] for host, expected in zip(hosts, answers): self.assertEquals(util.splitHostPort(host), expected)
def test_splitHostPart(self): """ Make sure host strings get split appropriately. """ hosts = ["localhost:8080", "127.0.0.1", "*:80", ":53"] answers = [("localhost", 8080), ("127.0.0.1", 0), ("", 80), ("", 53)] for host, expected in zip(hosts, answers): self.assertEquals(util.splitHostPort(host), expected)
def newHost(self, ip, name): if type(ip) is not type(()): ip = util.splitHostPort(ip) self.hosts.append(ip) self.hostnames[ip] = name # XXX why is this needed too? self.hostnames['%s:%d' % ip] = name self.available[ip] = 0 self.totalconns[ip] = 0
def getHostByHostame(self, hostname): """ A convenience method for getting a host proxy from the group proxy, given its hostname. """ host, port = util.splitHostPort(hostname) for host in self.hosts.values(): if host.hostname == host and host.port == port: return host
def addHost(self, serviceName, groupName, proxiedName, ip, weight=1): """ This method updates not only the tracker data, but the models as well. """ tracker = self.getTracker(serviceName=serviceName, groupName=groupName) # XXX does the tracker need to know about weights? tracker.newHost(name=proxiedName, ip=ip) # add modeling information host, port = util.splitHostPort(ip) proxiedHost = model.ProxyHost(proxiedName, host, port, weight) self.getGroup(serviceName, groupName).addHost(proxiedHost)
def setupAdminWebUIServer(configuration, director): """ Given the director, set up a potentially SSL-enabled admin web UI on the configured port. """ if not configuration.admin.webEnable: return root = pages.AdminServer(configuration, director) site = server.Site(root) host, port = util.splitHostPort(configuration.admin.webListen) if configuration.admin.webSecure: util.setupServerCert() context = ssl.DefaultOpenSSLContextFactory(util.privKeyFile, util.certFile) admin = internet.SSLServer(port, site, context, interface=host) else: admin = internet.TCPServer(port, site, interface=host) admin.setName('adminWeb') return admin
def setupAdminWebUIServer(configuration, director): """ Given the director, set up a potentially SSL-enabled admin web UI on the configured port. """ if not configuration.admin.webEnable: return root = pages.AdminServer(configuration, director) site = server.Site(root) host, port = util.splitHostPort(configuration.admin.webListen) if configuration.admin.webSecure: util.setupServerCert() context = ssl.DefaultOpenSSLContextFactory( util.privKeyFile, util.certFile) admin = internet.SSLServer(port, site, context, interface=host) else: admin = internet.TCPServer(port, site, interface=host) admin.setName('adminWeb') return admin