Fix proxyobject confusion, now called proxymodule

This commit is contained in:
C. R. Oldham 2015-04-15 13:27:14 -06:00
parent 9b1599d436
commit dd0b7c6937
6 changed files with 44 additions and 22 deletions

View file

@ -415,8 +415,8 @@ class ProxyMinion(parsers.MinionOptionParser):
'''
If sub-classed, run any shutdown operations on this method.
'''
if 'proxy' in self.minion.opts:
self.minion.opts['proxyobject'].shutdown(self.minion.opts)
if 'proxymodule' in self.minion.opts:
self.minion.opts['proxymodule']['shutdown'](self.minion.opts)
logger.info('The proxy minion is shut down')

View file

@ -5,10 +5,13 @@ NOTE this is a little complicated--junos can only be accessed via salt-proxy-min
Thus, some grains make sense to get them from the minion (PYTHONPATH), but others
don't (ip_interfaces)
'''
import logging
import json
__proxyenabled__ = ['junos']
__virtualname__ = 'junos'
log = logging.getLogger(__name__)
def __virtual__():
if 'proxy' not in __opts__:
@ -16,17 +19,28 @@ def __virtual__():
else:
return __virtualname__
def _remove_complex_types(dictionary):
'''
Linode-python is now returning some complex types that
are not serializable by msgpack. Kill those.
'''
def location():
return {'location': 'dc-1-europe'}
for k, v in dictionary.iteritems():
if isinstance(v, dict):
dictionary[k] = remove_complex_types(v)
elif hasattr(v, 'to_eng_string'):
dictionary[k] = v.to_eng_string()
def defaults():
return {'os': 'proxy', 'kernel':'unknown', 'osrelease':'proxy'}
def facts():
log.debug('----------- Trying to get facts')
facts = __opts__['proxymodule']['junos.facts']()
facts['version_info'] = 'override'
return facts
log.debug('----------- Facts call to junos returned')
def os_family():
return {'os_family': 'junos'}
def os_data():
facts = {}
facts['version_info'] = {'major': '12,1', 'type': 'I', 'minor': '20131108_srx_12q1_x46_intgr', 'build': '0-613414'}
facts['os_family'] = 'proxy'
return facts

View file

@ -2907,7 +2907,6 @@ class ProxyMinion(Minion):
'''
Pass in the options dict
'''
self._running = None
self.win_proc = []
self.loaded_base_name = loaded_base_name
@ -2931,7 +2930,6 @@ class ProxyMinion(Minion):
)
# Late setup the of the opts grains, so we can log from the grains
# module
opts['grains'] = salt.loader.grains(opts)
opts['master'] = self.eval_master(opts,
timeout,
safe)
@ -2945,6 +2943,7 @@ class ProxyMinion(Minion):
log.debug('{0}'.format(self.proxymodule))
# log.debug('{0}'.format(self.proxymodule['init']))
opts['proxymodule'] = self.proxymodule
opts['grains'] = salt.loader.grains(opts)
opts['id'] = opts['proxymodule']['junos.id'](opts)
opts.update(resolve_dns(opts))
self.opts = opts

View file

@ -11,7 +11,7 @@ from __future__ import absolute_import
import logging
# Juniper interface libraries
# https://github.com/jeremyschulman/py-junos-eznc
# https://github.com/Juniper/py-junos-eznc
try:
@ -37,7 +37,7 @@ __proxyenabled__ = ['junos']
def __virtual__():
'''
We need the Junos adapter libraries for this
module to work. We also need a proxyobject object
module to work. We also need a proxymodule entry in __opts__
in the opts dictionary
'''
if HAS_JUNOS and 'proxy' in __opts__:
@ -52,13 +52,13 @@ def facts_refresh():
if the device configuration is changed by some other actor.
'''
return __opts__['proxyobject'].refresh
return __opts__['proxymodule']['junos.conn']().refresh()
def set_hostname(hostname=None, commit_change=True):
ret = dict()
conn = __opts__['proxyobject']
conn = __opts__['proxymodule']['junos.conn']()
if hostname is None:
ret['out'] = False
return ret
@ -79,7 +79,7 @@ def set_hostname(hostname=None, commit_change=True):
def commit():
conn = __opts__['proxyobject']
conn = __opts__['proxymodule']['junos.conn']()
ret = {}
commit_ok = conn.cu.commit_check()
@ -99,7 +99,7 @@ def commit():
def rollback():
conn = __opts__['proxyobject']
conn = __opts__['proxymodule']['junos.conn']()
ret = dict()
ret['out'] = conn.cu.rollback(0)
@ -115,7 +115,7 @@ def rollback():
def diff():
ret = dict()
conn = __opts__['proxyobject']
conn = __opts__['proxymodule']['junos.conn']()
ret['out'] = True
ret['message'] = conn.cu.diff()
@ -125,6 +125,6 @@ def diff():
def ping():
ret = dict()
conn = __opts__['proxyobject']
conn = __opts__['proxymodule']['junos.conn']()
ret['message'] = conn.cli('show system uptime')
ret['out'] = True

View file

@ -105,8 +105,8 @@ def ping():
salt '*' test.ping
'''
if 'proxyobject' in __opts__:
return __opts__['proxyobject'].ping()
if 'proxymodule' in __opts__:
return __opts__['proxymodule']['junos.ping']()
else:
return True

View file

@ -33,6 +33,15 @@ def __init__(opts):
thisproxy['conn'].open()
thisproxy['conn'].bind(cu=jnpr.junos.utils.config.Config)
def conn():
return thisproxy['conn']
def facts():
return thisproxy['conn'].facts
def refresh():
return thisproxy['conn'].refresh()
def proxytype():
'''
Returns the name of this proxy