Merge branch 'develop' of https://github.com/saltstack/salt into develop

This commit is contained in:
Eric Johnson 2013-11-22 18:19:26 +00:00
commit 5bb90ca188
7 changed files with 101 additions and 91 deletions

View File

@ -18,7 +18,7 @@ from libcloud.compute.deployment import (
ScriptDeployment,
SSHKeyDeployment
)
# pylint: enable-msg=W0611
# pylint: enable=W0611
# Import salt libs

View File

@ -11,6 +11,7 @@ import salt.utils
import salt.utils.decorators as decorators
from salt.exceptions import SaltException
# Cache the output of running which('ipvsadm')
@decorators.memoize
def __detect_os():
@ -26,6 +27,7 @@ def __virtual__():
return 'lvs'
def _build_cmd(**kwargs):
'''
@ -59,26 +61,24 @@ def _build_cmd(**kwargs):
if kwargs['server_address']:
cmd += ' -r {0}'.format(kwargs['server_address'])
if 'packet_forward_method' in kwargs and kwargs['packet_forward_method']:
if kwargs['packet_forward_method'] == 'dr':
cmd += ' -g'
elif kwargs['packet_forward_method'] == 'tunnel':
cmd += ' -i'
elif kwargs['packet_forward_method'] == 'nat':
cmd += ' -m'
else:
raise SaltException('Error: only support dr, tunnel and nat')
del kwargs['packet_forward_method']
if kwargs['packet_forward_method'] == 'dr':
cmd += ' -g'
elif kwargs['packet_forward_method'] == 'tunnel':
cmd += ' -i'
elif kwargs['packet_forward_method'] == 'nat':
cmd += ' -m'
else:
raise SaltException('Error: only support dr, tunnel and nat')
del kwargs['packet_forward_method']
if 'weight' in kwargs and kwargs['weight']:
cmd += ' -w {0}'.format(kwargs['weight'])
del kwargs['weight']
cmd += ' -w {0}'.format(kwargs['weight'])
del kwargs['weight']
else:
raise SaltException('Error: server_address should specified')
del kwargs['server_address']
return cmd
def add_service(protocol=None, service_address=None, scheduler='wlc'):
'''
@ -100,7 +100,7 @@ def add_service(protocol=None, service_address=None, scheduler='wlc'):
salt '*' lvs.add_service tcp 1.1.1.1:80 rr
'''
cmd = '{0} -A {1}'.format(__detect_os(),
_build_cmd(protocol=protocol,
service_address=service_address,
@ -135,7 +135,7 @@ def edit_service(protocol=None, service_address=None, scheduler=None):
salt '*' lvs.edit_service tcp 1.1.1.1:80 rr
'''
cmd = '{0} -E {1}'.format(__detect_os(),
_build_cmd(protocol=protocol,
service_address=service_address,
@ -160,12 +160,12 @@ def delete_service(protocol=None, service_address=None):
service_address
The LVS service address.
CLI Example:
.. code-block:: bash
salt '*' lvs.delete_service tcp 1.1.1.1:80
'''
@ -195,18 +195,18 @@ def add_server(protocol=None, service_address=None, server_address=None, packet_
server_address
The real server address.
packet_forward_method
The LVS packet forwarding method(``dr`` for direct routing, ``tunnel`` for tunneling, ``nat`` for network access translation).
weight
The capacity of a server relative to the others in the pool.
CLI Example:
.. code-block:: bash
salt '*' lvs.add_server tcp 1.1.1.1:80 192.168.0.11:8080 nat 1
'''
@ -240,18 +240,18 @@ def edit_server(protocol=None, service_address=None, server_address=None, packet
server_address
The real server address.
packet_forward_method
The LVS packet forwarding method(``dr`` for direct routing, ``tunnel`` for tunneling, ``nat`` for network access translation).
weight
The capacity of a server relative to the others in the pool.
CLI Example:
.. code-block:: bash
salt '*' lvs.edit_server tcp 1.1.1.1:80 192.168.0.11:8080 nat 1
'''
@ -285,12 +285,12 @@ def delete_server(protocol=None, service_address=None, server_address=None):
server_address
The real server address.
CLI Example:
.. code-block:: bash
salt '*' lvs.delete_server tcp 1.1.1.1:80 192.168.0.11:8080
'''
@ -310,7 +310,7 @@ def delete_server(protocol=None, service_address=None, server_address=None):
def clear():
'''
Clear the virtual server table
CLI Example:
@ -334,11 +334,11 @@ def clear():
def get_rules():
'''
Get the virtual server rules
CLI Example:
.. code-block:: bash
salt '*' lvs.get_rules
@ -356,12 +356,12 @@ def list(protocol=None, service_address=None):
List the virtual server table if service_address is not specified. If a service_address is selected, list this service only.
CLI Example:
.. code-block:: bash
salt '*' lvs.list
'''
'''
if service_address:
cmd = '{0} -L {1} -n'.format(__detect_os(),
_build_cmd(protocol=protocol,
@ -378,15 +378,16 @@ def list(protocol=None, service_address=None):
return ret
def zero(protocol=None, service_address=None):
'''
Zero the packet, byte and rate counters in a service or all services.
CLI Example:
.. code-block:: bash
salt '*' lvs.zero
'''
@ -410,7 +411,7 @@ def check_service(protocol=None, service_address=None, **kwargs):
'''
Check the virtual service exists.
CLI Example:
.. code-block:: bash
@ -423,7 +424,7 @@ def check_service(protocol=None, service_address=None, **kwargs):
**kwargs))
# Exact match
if not kwargs:
cmd += ' '
cmd += ' '
all_rules = get_rules()
out = all_rules.find(cmd)
@ -434,6 +435,7 @@ def check_service(protocol=None, service_address=None, **kwargs):
ret = 'Error: service not exists'
return ret
def check_server(protocol=None, service_address=None, server_address=None, **kwargs):
'''

View File

@ -5,12 +5,12 @@ Support for ``pkgng``, the new package manager for FreeBSD
.. warning::
This module has been completely rewritten. Up to and includng version
0.17.0, it was available as the ``pkgng`` module, (``pkgng.install``,
0.17.x, it was available as the ``pkgng`` module, (``pkgng.install``,
``pkgng.delete``, etc.), but moving forward this module will no longer be
available as ``pkgng``, as it will behave like a normal Salt ``pkg``
provider. The documentation below should not be considered to apply to this
module in versions <= 0.17.0. If your minion is running one of these
versions, then the documentation for this module can be viewed using the
module in versions <= 0.17.x. If your minion is running a 0.17.x release or
older, then the documentation for this module can be viewed using the
:mod:`sys.doc <salt.modules.sys.doc>` function:
.. code-block:: bash

View File

@ -504,7 +504,7 @@ def pid(sig):
cmd = "{0[ps]} | grep {1} | grep -v grep | awk '{{print $2}}'".format(
__grains__, sig)
return (__salt__['cmd.run_stdout'](cmd) or '')
def version():
'''
@ -522,6 +522,3 @@ def version():
ret = salt.utils.fopen(procf, 'r').read().strip()
return ret

View File

@ -7,6 +7,7 @@ Management of LVS(Linux Virtual Server) Real Server.
This lvs_server module is used to add and manage LVS Real Server in the specified service. Server can be set as either absent or present.
'''
def __virtual__():
'''
@ -14,12 +15,13 @@ def __virtual__():
'''
return 'lvs_server' if 'lvs.get_rules' in __salt__ else False
def present(name,
protocol=None,
service_address=None,
server_address=None,
packet_forward_method='dr',
weight=1
weight=1
):
'''
Ensure that the named service is present.
@ -35,7 +37,7 @@ def present(name,
server_address
The real server address.
packet_forward_method
The LVS packet forwarding method(``dr`` for direct routing, ``tunnel`` for tunneling, ``nat`` for network access translation).
@ -111,22 +113,22 @@ def present(name,
return ret
return ret
def absent(name, protocol=None, service_address=None, server_address=None):
'''
Ensure the LVS Real Server in specified service is absent.
name
The name of the LVS server.
protocol
The service protocol(only support ``tcp``, ``udp`` and ``fwmark`` service).
service_address
The LVS service adress.
server_address
The LVS real server address.
'''
@ -134,7 +136,7 @@ def absent(name, protocol=None, service_address=None, server_address=None):
'changes': {},
'result': True,
'comment': ''}
#check if server exists and remove it
server_check = __salt__['lvs.check_server'](protocol=protocol,
service_address=service_address,

View File

@ -7,6 +7,7 @@ Management of LVS(Linux Virtual Server) Service.
This lvs_service module is used to create and manage LVS Service. Service can be set as either absent or present.
'''
def __virtual__():
'''
@ -14,6 +15,7 @@ def __virtual__():
'''
return 'lvs_service' if 'lvs.get_rules' in __salt__ else False
def present(name,
protocol=None,
service_address=None,
@ -93,11 +95,11 @@ def present(name,
return ret
return ret
def absent(name, protocol=None, service_address=None):
'''
Ensure the LVS service is absent.
name
@ -113,7 +115,7 @@ def absent(name, protocol=None, service_address=None):
'changes': {},
'result': True,
'comment': ''}
#check if service exists and remove it
service_check = __salt__['lvs.check_service'](protocol=protocol,
service_address=service_address)

View File

@ -1465,10 +1465,13 @@ class SaltCMDOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
self.args[2] = self.args[2]
if self.options.list:
if ',' in self.args[0]:
self.config['tgt'] = self.args[0].split(',')
else:
self.config['tgt'] = self.args[0].split()
try:
if ',' in self.args[0]:
self.config['tgt'] = self.args[0].split(',')
else:
self.config['tgt'] = self.args[0].split()
except IndexError:
self.exit(42, '\nCannot execute command without defining a target.\n\n')
else:
try:
self.config['tgt'] = self.args[0]
@ -1476,35 +1479,39 @@ class SaltCMDOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
self.exit(42, '\nCannot execute command without defining a target.\n\n')
# Detect compound command and set up the data for it
if self.args:
if ',' in self.args[1]:
self.config['fun'] = self.args[1].split(',')
self.config['arg'] = [[]]
cmd_index = 0
if (self.args[2:].count(self.options.args_separator) ==
len(self.config['fun']) - 1):
# new style parsing: standalone argument separator
for arg in self.args[2:]:
if arg == self.options.args_separator:
cmd_index += 1
self.config['arg'].append([])
else:
self.config['arg'][cmd_index].append(arg)
else:
# old style parsing: argument separator can be inside args
for arg in self.args[2:]:
if self.options.args_separator in arg:
sub_args = arg.split(self.options.args_separator)
for sub_arg_index, sub_arg in enumerate(sub_args):
if sub_arg:
self.config['arg'][cmd_index].append(sub_arg)
if sub_arg_index != len(sub_args) - 1:
cmd_index += 1
self.config['arg'].append([])
else:
self.config['arg'][cmd_index].append(arg)
if len(self.config['fun']) != len(self.config['arg']):
self.exit(42, 'Cannot execute compound command without '
'defining all arguments.')
try:
if ',' in self.args[1]:
self.config['fun'] = self.args[1].split(',')
self.config['arg'] = [[]]
cmd_index = 0
if (self.args[2:].count(self.options.args_separator) ==
len(self.config['fun']) - 1):
# new style parsing: standalone argument separator
for arg in self.args[2:]:
if arg == self.options.args_separator:
cmd_index += 1
self.config['arg'].append([])
else:
self.config['arg'][cmd_index].append(arg)
else:
# old style parsing: argument separator can be inside args
for arg in self.args[2:]:
if self.options.args_separator in arg:
sub_args = arg.split(self.options.args_separator)
for sub_arg_index, sub_arg in enumerate(sub_args):
if sub_arg:
self.config['arg'][cmd_index].append(sub_arg)
if sub_arg_index != len(sub_args) - 1:
cmd_index += 1
self.config['arg'].append([])
else:
self.config['arg'][cmd_index].append(arg)
if len(self.config['fun']) != len(self.config['arg']):
self.exit(42, 'Cannot execute compound command without '
'defining all arguments.')
except IndexError:
self.exit(42, '\nIncomplete options passed.\n\n')
else:
self.config['fun'] = self.args[1]
self.config['arg'] = self.args[2:]