summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--man/bcfg2-server.84
-rw-r--r--src/lib/Server/Metadata.py21
-rwxr-xr-xsrc/sbin/bcfg2-server39
3 files changed, 34 insertions, 30 deletions
diff --git a/man/bcfg2-server.8 b/man/bcfg2-server.8
index 326b30974..67bac3755 100644
--- a/man/bcfg2-server.8
+++ b/man/bcfg2-server.8
@@ -22,10 +22,6 @@ Run bcfg2 in verbose mode.
.B "\-C <ConfigFile Path>"
.RS
Use an alternative path for bcfg2.conf. The default is /etc/bcfg2.conf
-.B "\-c <client>"
-.RS
-Statically set client. Useful for debugging problems with
-particular client's configs.
.RE
.B \-D
.RS
diff --git a/src/lib/Server/Metadata.py b/src/lib/Server/Metadata.py
index b4a5afd2a..9d232d7c5 100644
--- a/src/lib/Server/Metadata.py
+++ b/src/lib/Server/Metadata.py
@@ -1,7 +1,7 @@
'''This file stores persistent metadata for the BCFG Configuration Repository'''
__revision__ = '$Revision$'
-import logging, lxml.etree, os, time
+import logging, lxml.etree, os, socket, time
class MetadataConsistencyError(Exception):
'''This error gets raised when metadata is internally inconsistent'''
@@ -21,15 +21,16 @@ class ClientMetadata(object):
class Metadata:
'''This class contains data for bcfg2 server metadata'''
- __name__ = 'Metadata'
__version__ = '$Id$'
__author__ = 'bcfg-dev@mcs.anl.gov'
def __init__(self, fam, datastore):
+ self.__name__ = 'Metadata'
self.data = "%s/%s" % (datastore, self.__name__)
fam.AddMonitor("%s/%s" % (self.data, "groups.xml"), self)
fam.AddMonitor("%s/%s" % (self.data, "clients.xml"), self)
self.states = {'groups.xml':False, 'clients.xml':False}
+ self.addresses = {}
self.clients = {}
self.aliases = {}
self.groups = {}
@@ -58,6 +59,11 @@ class Metadata:
self.aliases = {}
self.clientdata = xdata
for client in xdata.findall('./Client'):
+ if address in client.attrib:
+ self.addresses[client.get('address')] = client.get('name')
+ for alias in [alias for alias in client.findall('Alias') if 'address' in alias.attrib]:
+ self.addresses[alias.get('address')] = client.get('name')
+
self.clients.update({client.get('name'): client.get('profile')})
[self.aliases.update({alias.get('name'): client.get('name')}) for alias in client.findall('Alias')]
else:
@@ -153,6 +159,17 @@ class Metadata:
'''Build the configuration header for a client configuration'''
return lxml.etree.Element("Configuration", version='2.0', toolset=self.find_toolset(client))
+ def resolve_client(self, address):
+ '''Lookup address locally or in DNS to get a hostname'''
+ if self.addresses.has_key(address):
+ return self.addresses[address]
+ try:
+ return socket.gethostbyaddr(address)[0]
+ except socket.herror:
+ warning = "address resolution error for %s" % (address)
+ self.logger.warning(warning)
+ raise MetadataConsistencyError
+
def get_metadata(self, client):
'''Return the metadata for a given client'''
if self.aliases.has_key(client):
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()