diff --git a/contrib/inventory/cobbler.ini b/contrib/inventory/cobbler.ini index b7b63595dec..2dc8cd33794 100644 --- a/contrib/inventory/cobbler.ini +++ b/contrib/inventory/cobbler.ini @@ -5,6 +5,10 @@ host = http://PATH_TO_COBBLER_SERVER/cobbler_api +# If API needs authentication add 'username' and 'password' options here. +#username = foo +#password = bar + # API calls to Cobbler can be slow. For this reason, we cache the results of an API # call. Set this to the path you want cache files to be written to. Two files # will be written to this directory: diff --git a/contrib/inventory/cobbler.py b/contrib/inventory/cobbler.py index b5fcdeacbbe..89f9bf75b3a 100755 --- a/contrib/inventory/cobbler.py +++ b/contrib/inventory/cobbler.py @@ -120,6 +120,9 @@ class CobblerInventory(object): def _connect(self): if not self.conn: self.conn = xmlrpclib.Server(self.cobbler_host, allow_none=True) + self.token = None + if self.cobbler_username is not None: + self.token = self.conn.login(self.cobbler_username, self.cobbler_password) def is_cache_valid(self): """ Determines if the cache files have expired, or if it is still valid """ @@ -140,6 +143,12 @@ class CobblerInventory(object): config.read(os.path.dirname(os.path.realpath(__file__)) + '/cobbler.ini') self.cobbler_host = config.get('cobbler', 'host') + self.cobbler_username = None + self.cobbler_password = None + if config.has_option('cobbler', 'username'): + self.cobbler_username = config.get('cobbler', 'username') + if config.has_option('cobbler', 'password'): + self.cobbler_password = config.get('cobbler', 'password') # Cache related cache_path = config.get('cobbler', 'cache_path') @@ -163,8 +172,10 @@ class CobblerInventory(object): self._connect() self.groups = dict() self.hosts = dict() - - data = self.conn.get_systems() + if self.token is not None: + data = self.conn.get_systems(self.token) + else: + data = self.conn.get_systems() for host in data: # Get the FQDN for the host and add it to the right groups