mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
add cobbler api authentication options
add cobbler api authentication options: username and password, which can be provided if authentication is enabled or cobbler api is behind a proxy that needs authentication.
This commit is contained in:
parent
ff0296f98a
commit
9278591758
2 changed files with 17 additions and 2 deletions
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue