diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2006-08-27 22:05:48 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2006-08-27 22:05:48 +0000 |
commit | b1cb80172f674e694d04ff9f85dbafda83f10629 (patch) | |
tree | 2a8eb432e36e95276a27730c4147c0b5308484d4 /src/sbin | |
parent | fd57f6e2bba71c71aeb614aa002499004253c612 (diff) | |
download | bcfg2-b1cb80172f674e694d04ff9f85dbafda83f10629.tar.gz bcfg2-b1cb80172f674e694d04ff9f85dbafda83f10629.tar.bz2 bcfg2-b1cb80172f674e694d04ff9f85dbafda83f10629.zip |
Refactor to allow manual address specification in clients.xml
* Move address resolution to Bcfg2.Server.Metadata
* Remove bcfg2-server -c option (can be done with bcfg2-info more easily
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2123 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/sbin')
-rwxr-xr-x | src/sbin/bcfg2-server | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/src/sbin/bcfg2-server b/src/sbin/bcfg2-server index 440ab53c6..a9ecb68db 100755 --- a/src/sbin/bcfg2-server +++ b/src/sbin/bcfg2-server @@ -112,23 +112,12 @@ class Bcfg2Serv(Bcfg2.Server.Component.Component): if self.socket in rsockinfo: return self.socket.accept() - def resolve_client(self, client): - if self.setup['client']: - return self.setup['client'] - try: - return socket.gethostbyaddr(client)[0] - except socket.herror: - warning = "host resolution error for %s" % (client) - self.logger.warning(warning) - raise Fault, (5, warning) - def Bcfg2GetProbes(self, address): '''Fetch probes for a particular client''' - client = self.resolve_client(address[0]) resp = Element('probes') - try: - meta = self.Core.metadata.get_metadata(client) + name = self.Core.metadata.resolve_client(address[0]) + meta = self.Core.metadata.get_metadata(name) for generator in self.Core.generators: for probe in generator.GetProbes(meta): @@ -144,16 +133,16 @@ class Bcfg2Serv(Bcfg2.Server.Component.Component): def Bcfg2RecvProbeData(self, address, probedata): '''Receive probe data from clients''' try: - client = self.resolve_client(address[0]) - meta = self.Core.metadata.get_metadata(client) - except Bcfg2.Server.metadata.MetadataConsistencyError: + name = self.Core.metadata.resolve_client(address[0]) + meta = self.Core.metadata.get_metadata(name) + except Bcfg2.Server.Metadata.MetadataConsistencyError: warning = 'metadata consistency error' self.logger.warning(warning) raise Fault, (6, warning) try: xpdata = XML(probedata) except: - self.logger.error("Failed to parse probe data from client %s" % (client)) + self.logger.error("Failed to parse probe data from client %s" % (address)) return False for data in xpdata: @@ -161,15 +150,15 @@ class Bcfg2Serv(Bcfg2.Server.Component.Component): try: self.Core.plugins[data.get('source')].ReceiveData(meta, data) except: - self.logger.error("Failed to process probe data from client %s" % (client), exc_info=1) + self.logger.error("Failed to process probe data from client %s" % (address), exc_info=1) else: self.logger.warning("Failed to locate plugin %s" % (data.get('source'))) return True def Bcfg2AssertProfile(self, address, profile): '''Set profile for a client''' - client = self.resolve_client(address[0]) try: + client = self.Core.metadata.resolve_client(address[0]) self.Core.metadata.set_profile(client, profile) except (Bcfg2.Server.Metadata.MetadataConsistencyError, Bcfg2.Server.Metadata.MetadataRuntimeError): warning = 'metadata consistency error' @@ -179,8 +168,12 @@ class Bcfg2Serv(Bcfg2.Server.Component.Component): def Bcfg2GetConfig(self, address, _=False, profile=False): '''Build config for a client''' - client = self.resolve_client(address[0]) - return tostring(self.Core.BuildConfiguration(client)) + try: + client = self.Core.metadata.resolve_client(address[0]) + return tostring(self.Core.BuildConfiguration(client)) + except Bcfg2.Server.Metadata.MetadataConsistencyError: + self.logger.warning("Metadata consistency failure for %s" % (address)) + raise Fault, (6, "Metadata consistency failure") def Bcfg2RecvStats(self, address, stats): '''Act on statistics upload''' @@ -188,7 +181,7 @@ class Bcfg2Serv(Bcfg2.Server.Component.Component): state = sdata.find(".//Statistics") # Versioned stats to prevent tied client/server upgrade if state.get('version') >= '2.0': - client = self.resolve_client(address[0]) + client = self.Core.metadata.resolve_client(address[0]) # Update statistics self.Core.stats.updateStats(sdata, client) @@ -214,8 +207,6 @@ if __name__ == '__main__': False, False, False, False), 'configfile': (('-C', '<conffile>', 'use this config file'), False, False, '/etc/bcfg2.conf', False), - 'client': (('-c', '<client>', 'hard set the client name (for debugging)'), - False, False, False, False) } SSETUP = Bcfg2.Options.OptionParser('bcfg2', OPTINFO).parse() |