Skip to content

Commit

Permalink
Merge branch '2015.2' into merge-forward-develop
Browse files Browse the repository at this point in the history
Conflicts:
	salt/utils/reactor.py
	tests/jenkins-ng.py
  • Loading branch information
basepi committed Jan 6, 2015
2 parents d88cb37 + b4a0c2b commit c5cdc57
Show file tree
Hide file tree
Showing 31 changed files with 1,000 additions and 1,361 deletions.
30 changes: 30 additions & 0 deletions doc/topics/cloud/rackspace.rst
Expand Up @@ -170,3 +170,33 @@ configuration please add:
size: 512 MB Standard
image: FreeBSD 9.0
force_first_gen: True
Private Subnets
--------------------------------
By default salt-cloud will not add Rackspace private networks to new servers. To enable
a private network to a server instantiated by salt cloud, add the following section
to the provider file (typically ``/etc/salt/cloud.providers.d/rackspace.conf``)

.. code-block:: yaml
networks:
- fixed:
# This is the private network
- private-network-id
# This is Rackspace's "PublicNet"
- 00000000-0000-0000-0000-000000000000
# This is Rackspace's "ServiceNet"
- 11111111-1111-1111-1111-111111111111
To get the Rackspace private network ID, go to Networking, Networks and hover over the private network name.

The order of the networks in the above code block does not map to the order of the
ethernet devices on newly created servers. Public IP will always be first ( eth0 )
followed by servicenet ( eth1 ) and then private networks.

Enabling the private network per above gives the option of using the private subnet for
all master-minion communication, including the bootstrap install of salt-minion. To
enable the minion to use the private subnet, update the master: line in the minion:
section of the providers file. To configure the master to only listen on the private
subnet IP, update the interface: line in the /etc/salt/master file to be the private
subnet IP of the salt master.
39 changes: 38 additions & 1 deletion doc/topics/mine/index.rst
Expand Up @@ -62,6 +62,43 @@ be adjusted for the minion via the `mine_interval` option:
mine_interval: 60
Mine in Salt-SSH
================

As of the 2015.2 release of salt, salt-ssh supports ``mine.get``.

Because the minions cannot provide their own ``mine_functions`` configuration,
we retrieve the args for specified mine functions in one of three places,
searched in the following order:

1. Roster data
2. Pillar
3. Master config

The ``mine_functions`` are formatted exactly the same as in normal salt, just
stored in a different location. Here is an example of a flat roster containing
``mine_functions``:

.. code-block:: yaml
test:
host: 104.237.131.248
user: root
mine_functions:
cmd.run: ['echo "hello!"']
network.ip_addrs:
interface: eth0
.. note::

Because of the differences in the architecture of salt-ssh, ``mine.get``
calls are somewhat inefficient. Salt must make a new salt-ssh call to each
of the minions in question to retrieve the requested data, much like a
publish call. However, unlike publish, it must run the requested function
as a wrapper function, so we can retrieve the function args from the pillar
of the minion in question. This results in a non-trivial delay in
retrieving the requested data.

Example
=======

Expand Down Expand Up @@ -111,4 +148,4 @@ to add them to the pool of load balanced servers.
server {{ server }} {{ addrs[0] }}:80 check
{% endfor %}
<...file contents snipped...>
<...file contents snipped...>
2 changes: 1 addition & 1 deletion salt/cli/api.py
Expand Up @@ -2,7 +2,7 @@
from __future__ import print_function
from __future__ import absolute_import

import six
import salt.ext.six as six
import sys
import logging

Expand Down
6 changes: 5 additions & 1 deletion salt/daemons/masterapi.py
Expand Up @@ -18,6 +18,7 @@
# In case a non-master needs to import this module
pass

import tempfile

# Import salt libs
import salt.crypt
Expand Down Expand Up @@ -687,12 +688,15 @@ def _pillar(self, load):
if not os.path.isdir(cdir):
os.makedirs(cdir)
datap = os.path.join(cdir, 'data.p')
with salt.utils.fopen(datap, 'w+b') as fp_:
tmpfh, tmpfname = tempfile.mkstemp(dir=cdir)
os.close(tmpfh)
with salt.utils.fopen(tmpfname, 'w+b') as fp_:
fp_.write(
self.serial.dumps(
{'grains': load['grains'],
'pillar': data})
)
os.rename(tmpfname, datap)
return data

def _minion_event(self, load):
Expand Down
6 changes: 3 additions & 3 deletions salt/grains/core.py
Expand Up @@ -348,7 +348,7 @@ def _sunos_cpudata():

grains['cpuarch'] = __salt__['cmd.run']('uname -p')
psrinfo = '/usr/sbin/psrinfo 2>/dev/null'
grains['num_cpus'] = len(__salt__['cmd.run'](psrinfo).splitlines())
grains['num_cpus'] = len(__salt__['cmd.run'](psrinfo, python_shell=True).splitlines())
kstat_info = 'kstat -p cpu_info:0:*:brand'
for line in __salt__['cmd.run'](kstat_info).splitlines():
match = re.match(r'(\w+:\d+:\w+\d+:\w+)\s+(.+)', line)
Expand Down Expand Up @@ -394,7 +394,7 @@ def _memdata(osdata):
grains['mem_total'] = int(mem) / 1024 / 1024
elif osdata['kernel'] == 'SunOS':
prtconf = '/usr/sbin/prtconf 2>/dev/null'
for line in __salt__['cmd.run'](prtconf).splitlines():
for line in __salt__['cmd.run'](prtconf, python_shell=True).splitlines():
comps = line.split(' ')
if comps[0].strip() == 'Memory' and comps[1].strip() == 'size:':
grains['mem_total'] = int(comps[2].strip())
Expand Down Expand Up @@ -1691,7 +1691,7 @@ def _smartos_zone_data():
grains['pkgsrcpath'] = 'Unknown'

grains['zonename'] = __salt__['cmd.run']('zonename')
grains['zoneid'] = __salt__['cmd.run']('zoneadm list -p').split()[1]
grains['zoneid'] = __salt__['cmd.run']('zoneadm list -p | awk -F: \'{ print $1 }\'', python_shell=True)
grains['hypervisor_uuid'] = __salt__['cmd.run']('mdata-get sdc:server_uuid')
grains['datacenter'] = __salt__['cmd.run']('mdata-get sdc:datacenter_name')
if "FAILURE" in grains['datacenter'] or "No metadata" in grains['datacenter']:
Expand Down
21 changes: 17 additions & 4 deletions salt/master.py
Expand Up @@ -18,6 +18,7 @@
import resource
import multiprocessing
import sys
import tempfile

# Import third party libs
import zmq
Expand Down Expand Up @@ -1220,12 +1221,15 @@ def _pillar(self, load):
if not os.path.isdir(cdir):
os.makedirs(cdir)
datap = os.path.join(cdir, 'data.p')
with salt.utils.fopen(datap, 'w+b') as fp_:
tmpfh, tmpfname = tempfile.mkstemp(dir=cdir)
os.close(tmpfh)
with salt.utils.fopen(tmpfname, 'w+b') as fp_:
fp_.write(
self.serial.dumps(
{'grains': load['grains'],
'pillar': data})
)
os.rename(tmpfname, datap)
for mod in mods:
sys.modules[mod].__grains__ = self.opts['grains']
return data
Expand Down Expand Up @@ -1788,11 +1792,20 @@ def _auth(self, load):

log.info('Authentication accepted from {id}'.format(**load))
# only write to disk if you are adding the file, and in open mode,
# which implies we accept any key from a minion (key needs to be
# written every time because what's on disk is used for encrypting)
if not os.path.isfile(pubfn) or self.opts['open_mode']:
# which implies we accept any key from a minion.
if not os.path.isfile(pubfn) and not self.opts['open_mode']:
with salt.utils.fopen(pubfn, 'w+') as fp_:
fp_.write(load['pub'])
elif self.opts['open_mode']:
disk_key = ''
if os.path.isfile(pubfn):
with salt.utils.fopen(pubfn, 'r') as fp_:
disk_key = fp_.read()
if load['pub'] and load['pub'] != disk_key:
log.debug('Host key change detected in open mode.')
with salt.utils.fopen(pubfn, 'w+') as fp_:
fp_.write(load['pub'])

pub = None

# the con_cache is enabled, send the minion id to the cache
Expand Down
19 changes: 19 additions & 0 deletions salt/minion.py
Expand Up @@ -592,6 +592,7 @@ def __init__(self, opts, timeout=60, safe=True): # pylint: disable=W0231
Pass in the options dict
'''
self._running = None
self.win_proc = []

# Warn if ZMQ < 3.2
if HAS_ZMQ:
Expand Down Expand Up @@ -1017,6 +1018,8 @@ def _handle_decoded_payload(self, data):
process.start()
if not sys.platform.startswith('win'):
process.join()
else:
self.win_proc.append(process)

@classmethod
def _thread_return(cls, minion_instance, opts, data):
Expand Down Expand Up @@ -1662,6 +1665,21 @@ def handle_event(self, package):
log.debug('Forwarding salt error event tag={tag}'.format(tag=tag))
self._fire_master(data, tag)

def _windows_thread_cleanup(self):
'''
Cleanup Windows threads
'''
if not salt.utils.is_windows():
return
for thread in self.win_proc:
if not thread.is_alive():
thread.join()
try:
self.win_proc.remove(thread)
del thread
except (ValueError, NameError):
pass

# Main Minion Tune In
def tune_in(self):
'''
Expand Down Expand Up @@ -1727,6 +1745,7 @@ def tune_in(self):

while self._running is True:
loop_interval = self.process_schedule(self, loop_interval)
self._windows_thread_cleanup()
try:
socks = self._do_poll(loop_interval)

Expand Down
3 changes: 3 additions & 0 deletions salt/modules/cmdmod.py
Expand Up @@ -17,6 +17,7 @@
import subprocess
import sys
import traceback
import shlex
from salt.utils import vt

# Import salt libs
Expand Down Expand Up @@ -360,6 +361,8 @@ def _run(cmd,
.format(cwd)
)

if python_shell is not True and not isinstance(cmd, list):
cmd = shlex.split(cmd)
if not use_vt:
# This is where the magic happens
try:
Expand Down
2 changes: 1 addition & 1 deletion salt/modules/parted.py
Expand Up @@ -465,7 +465,7 @@ def mkpart(device, part_type, fs_type=None, start=None, end=None):
.. code-block:: bash
salt '*' partition.mkpart /dev/sda primary fat32 0 639
salt '*' partition.mkpart /dev/sda primary fs_type=fat32 start=0 end=639
salt '*' partition.mkpart /dev/sda primary start=0 end=639
'''
_validate_device(device)
Expand Down

0 comments on commit c5cdc57

Please sign in to comment.