mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Merge pull request #3951 from mgwilliams/cobbler
cobbler tops/pillar module improvements
This commit is contained in:
commit
61dc4b37f7
@ -1,18 +1,19 @@
|
||||
'''
|
||||
Cobbler Pillar
|
||||
==============
|
||||
A pillar module to pull data from Cobbler via its API
|
||||
into the pillar dictionary.
|
||||
A pillar module to pull data from Cobbler via its API into the pillar dictionary.
|
||||
The same cobbler.* parameters are used for both the Cobbler tops and Cobbler pillar
|
||||
modules.
|
||||
|
||||
.. code-block:: yaml
|
||||
ext_pillar:
|
||||
- cobbler:
|
||||
- url: https://example.com/ # Cobbler base URL. Default: http://localhost/
|
||||
- user: username # Cobbler username. Default is no username.
|
||||
- password: password # Cobbler password. Default is no password.
|
||||
- key: cobbler # Nest results within this key. By default, values are not nested.
|
||||
- only: [parameters] # Add only these keys to pillar.
|
||||
|
||||
cobbler.url: https://example.com/cobbler_api #default is http://localhost/cobbler_api
|
||||
cobbler.user: username # default is no username
|
||||
cobbler.password: password # default is no password
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
@ -20,20 +21,31 @@ import logging
|
||||
import xmlrpclib
|
||||
|
||||
|
||||
__opts__ = {'cobbler.url': 'http://localhost/cobbler_api',
|
||||
'cobbler.user': None,
|
||||
'cobbler.password': None
|
||||
}
|
||||
|
||||
|
||||
# Set up logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def ext_pillar(pillar, url='http://localhost/', user=None, password=None, key=None, only=[]):
|
||||
|
||||
def ext_pillar(pillar, key=None, only=[]):
|
||||
'''
|
||||
Read pillar data from Cobbler via its API.
|
||||
'''
|
||||
hostname = __opts__['id']
|
||||
log.info("Querying cobbler for information for %r", hostname)
|
||||
url = __opts__['cobbler.url']
|
||||
user = __opts__['cobbler.user']
|
||||
password = __opts__['cobbler.password']
|
||||
|
||||
minion_id = __opts__['id']
|
||||
log.info("Querying cobbler at %r for information for %r", url, minion_id)
|
||||
try:
|
||||
server = xmlrpclib.Server('%s/cobbler_api' % url, allow_none=True)
|
||||
server = xmlrpclib.Server(url, allow_none=True)
|
||||
if user:
|
||||
server = (server, server.login(user, password))
|
||||
result = server.get_blended_data(None, hostname)
|
||||
result = server.get_blended_data(None, minion_id)
|
||||
except Exception:
|
||||
log.exception(
|
||||
'Could not connect to cobbler.'
|
||||
|
@ -3,14 +3,16 @@ Cobbler Tops
|
||||
============
|
||||
|
||||
Cobbler Tops is a master tops subsystem used to look up mapping information
|
||||
from Cobbler via its API.
|
||||
from Cobbler via its API. The same cobbler.* parameters are used for both
|
||||
the Cobbler tops and Cobbler pillar modules.
|
||||
|
||||
.. code-block:: yaml
|
||||
master_tops:
|
||||
cobbler:
|
||||
- host: https://example.com/ #default is http://localhost/
|
||||
- user: username # default is no username
|
||||
- password: password # default is no password
|
||||
cobbler: {}
|
||||
|
||||
cobbler.url: https://example.com/cobbler_api #default is http://localhost/cobbler_api
|
||||
cobbler.user: username # default is no username
|
||||
cobbler.password: password # default is no password
|
||||
|
||||
'''
|
||||
|
||||
@ -22,31 +24,29 @@ import xmlrpclib
|
||||
# Set up logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Only run if properly configured
|
||||
'''
|
||||
if __opts__['master_tops'].get('cobbler'):
|
||||
return 'cobbler'
|
||||
return False
|
||||
|
||||
__opts__ = {'cobbler.url': 'http://localhost/cobbler_api',
|
||||
'cobbler.user': None,
|
||||
'cobbler.password': None
|
||||
}
|
||||
|
||||
|
||||
def top(**kwargs):
|
||||
'''
|
||||
Look up top data for a host in Cobbler
|
||||
Look up top data in Cobbler for for a minion.
|
||||
'''
|
||||
host = __opts__['master_tops']['cobbler'].get('host', 'http://localhost/')
|
||||
user = __opts__['master_tops']['cobbler'].get('user', None)
|
||||
password = __opts__['master_tops']['cobbler'].get('password', None)
|
||||
url = __opts__['cobbler.url']
|
||||
user = __opts__['cobbler.user']
|
||||
password = __opts__['cobbler.password']
|
||||
|
||||
hostname = kwargs['opts']['id']
|
||||
minion_id = kwargs['opts']['id']
|
||||
|
||||
log.info("Querying cobbler for information for %r", hostname)
|
||||
log.info("Querying cobbler for information for %r", minion_id)
|
||||
try:
|
||||
server = xmlrpclib.Server('%s/cobbler_api' % host, allow_none=True)
|
||||
server = xmlrpclib.Server(url, allow_none=True)
|
||||
if user:
|
||||
server = (server, server.login(user, password))
|
||||
data = server.get_blended_data(None, hostname)
|
||||
data = server.get_blended_data(None, minion_id)
|
||||
except Exception:
|
||||
log.exception(
|
||||
'Could not connect to cobbler.'
|
||||
|
Loading…
Reference in New Issue
Block a user