Add futureproofing to roster_defaults to support roster dictionary options

This commit is contained in:
Corvin Mcpherson 2017-10-05 19:04:05 -04:00
parent aebe76b6f8
commit fefd28d896
6 changed files with 13 additions and 7 deletions

View File

@ -98,6 +98,7 @@ from __future__ import absolute_import
# Python # Python
import logging import logging
import re import re
import copy
# Salt libs # Salt libs
import salt.utils.minions import salt.utils.minions
@ -151,7 +152,7 @@ def targets(tgt, tgt_type='glob', **kwargs): # pylint: disable=W0613
except LookupError: except LookupError:
continue continue
minion_res = __opts__.get('roster_defaults', {}).copy() minion_res = copy.deepcopy(__opts__.get('roster_defaults', {}))
for param, order in roster_order.items(): for param, order in roster_order.items():
if not isinstance(order, (list, tuple)): if not isinstance(order, (list, tuple)):
order = [order] order = [order]

View File

@ -21,6 +21,7 @@ usually located at /etc/salt/cloud. For example, add the following:
# Import python libs # Import python libs
from __future__ import absolute_import from __future__ import absolute_import
import os import os
import copy
# Import Salt libs # Import Salt libs
import salt.loader import salt.loader
@ -63,7 +64,7 @@ def targets(tgt, tgt_type='glob', **kwargs): # pylint: disable=W0613
)) ))
preferred_ip = extract_ipv4(roster_order, ip_list) preferred_ip = extract_ipv4(roster_order, ip_list)
ret[minion_id] = __opts__.get('roster_defaults', {}).copy() ret[minion_id] = copy.deepcopy(__opts__.get('roster_defaults', {}))
ret[minion_id].update({'host': preferred_ip}) ret[minion_id].update({'host': preferred_ip})
ssh_username = salt.utils.cloud.ssh_usernames(vm_, cloud_opts) ssh_username = salt.utils.cloud.ssh_usernames(vm_, cloud_opts)

View File

@ -15,6 +15,7 @@ When you want to use host globs for target matching, use ``--roster clustershell
# Import python libs # Import python libs
from __future__ import absolute_import from __future__ import absolute_import
import socket import socket
import copy
from salt.ext.six.moves import map # pylint: disable=import-error,redefined-builtin from salt.ext.six.moves import map # pylint: disable=import-error,redefined-builtin
REQ_ERROR = None REQ_ERROR = None
@ -43,7 +44,7 @@ def targets(tgt, tgt_type='glob', **kwargs):
for host, addr in host_addrs.items(): for host, addr in host_addrs.items():
addr = str(addr) addr = str(addr)
ret[addr] = __opts__.get('roster_defaults', {}).copy() ret[addr] = copy.deepcopy(__opts__.get('roster_defaults', {}))
for port in ports: for port in ports:
try: try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

View File

@ -7,6 +7,7 @@ from __future__ import absolute_import
# Import python libs # Import python libs
import fnmatch import fnmatch
import re import re
import copy
# Try to import range from https://github.com/ytoolshed/range # Try to import range from https://github.com/ytoolshed/range
HAS_RANGE = False HAS_RANGE = False
@ -142,7 +143,7 @@ class RosterMatcher(object):
''' '''
Return the configured ip Return the configured ip
''' '''
ret = __opts__.get('roster_defaults', {}).copy() ret = copy.deepcopy(__opts__.get('roster_defaults', {}))
if isinstance(self.raw[minion], string_types): if isinstance(self.raw[minion], string_types):
ret.update({'host': self.raw[minion]}) ret.update({'host': self.raw[minion]})
return ret return ret

View File

@ -13,6 +13,7 @@ When you want to use a range query for target matching, use ``--roster range``.
''' '''
from __future__ import absolute_import from __future__ import absolute_import
import fnmatch import fnmatch
import copy
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -68,7 +69,7 @@ def targets(tgt, tgt_type='range', **kwargs):
def target_range(tgt, hosts): def target_range(tgt, hosts):
ret = {} ret = {}
for host in hosts: for host in hosts:
ret[host] = __opts__.get('roster_defaults', {}).copy() ret[host] = copy.deepcopy(__opts__.get('roster_defaults', {}))
ret[host].update({'host': host}) ret[host].update({'host': host})
if __opts__.get('ssh_user'): if __opts__.get('ssh_user'):
ret[host].update({'user': __opts__['ssh_user']}) ret[host].update({'user': __opts__['ssh_user']})
@ -79,7 +80,7 @@ def target_glob(tgt, hosts):
ret = {} ret = {}
for host in hosts: for host in hosts:
if fnmatch.fnmatch(tgt, host): if fnmatch.fnmatch(tgt, host):
ret[host] = __opts__.get('roster_defaults', {}).copy() ret[host] = copy.deepcopy(__opts__.get('roster_defaults', {}))
ret[host].update({'host': host}) ret[host].update({'host': host})
if __opts__.get('ssh_user'): if __opts__.get('ssh_user'):
ret[host].update({'user': __opts__['ssh_user']}) ret[host].update({'user': __opts__['ssh_user']})

View File

@ -7,6 +7,7 @@ Scan a netmask or ipaddr for open ssh ports
from __future__ import absolute_import from __future__ import absolute_import
import socket import socket
import logging import logging
import copy
# Import salt libs # Import salt libs
import salt.utils.network import salt.utils.network
@ -55,7 +56,7 @@ class RosterMatcher(object):
pass pass
for addr in addrs: for addr in addrs:
addr = str(addr) addr = str(addr)
ret[addr] = __opts__.get('roster_defaults', {}).copy() ret[addr] = copy.deepcopy(__opts__.get('roster_defaults', {}))
log.trace('Scanning host: {0}'.format(addr)) log.trace('Scanning host: {0}'.format(addr))
for port in ports: for port in ports:
log.trace('Scanning port: {0}'.format(port)) log.trace('Scanning port: {0}'.format(port))