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, ScriptDeployment,
SSHKeyDeployment SSHKeyDeployment
) )
# pylint: enable-msg=W0611 # pylint: enable=W0611
# Import salt libs # Import salt libs

View File

@ -11,6 +11,7 @@ import salt.utils
import salt.utils.decorators as decorators import salt.utils.decorators as decorators
from salt.exceptions import SaltException from salt.exceptions import SaltException
# Cache the output of running which('ipvsadm') # Cache the output of running which('ipvsadm')
@decorators.memoize @decorators.memoize
def __detect_os(): def __detect_os():
@ -26,6 +27,7 @@ def __virtual__():
return 'lvs' return 'lvs'
def _build_cmd(**kwargs): def _build_cmd(**kwargs):
''' '''
@ -59,26 +61,24 @@ def _build_cmd(**kwargs):
if kwargs['server_address']: if kwargs['server_address']:
cmd += ' -r {0}'.format(kwargs['server_address']) cmd += ' -r {0}'.format(kwargs['server_address'])
if 'packet_forward_method' in kwargs and kwargs['packet_forward_method']: if 'packet_forward_method' in kwargs and kwargs['packet_forward_method']:
if kwargs['packet_forward_method'] == 'dr': if kwargs['packet_forward_method'] == 'dr':
cmd += ' -g' cmd += ' -g'
elif kwargs['packet_forward_method'] == 'tunnel': elif kwargs['packet_forward_method'] == 'tunnel':
cmd += ' -i' cmd += ' -i'
elif kwargs['packet_forward_method'] == 'nat': elif kwargs['packet_forward_method'] == 'nat':
cmd += ' -m' cmd += ' -m'
else: else:
raise SaltException('Error: only support dr, tunnel and nat') raise SaltException('Error: only support dr, tunnel and nat')
del kwargs['packet_forward_method'] del kwargs['packet_forward_method']
if 'weight' in kwargs and kwargs['weight']: if 'weight' in kwargs and kwargs['weight']:
cmd += ' -w {0}'.format(kwargs['weight']) cmd += ' -w {0}'.format(kwargs['weight'])
del kwargs['weight'] del kwargs['weight']
else: else:
raise SaltException('Error: server_address should specified') raise SaltException('Error: server_address should specified')
del kwargs['server_address'] del kwargs['server_address']
return cmd return cmd
def add_service(protocol=None, service_address=None, scheduler='wlc'): 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 salt '*' lvs.add_service tcp 1.1.1.1:80 rr
''' '''
cmd = '{0} -A {1}'.format(__detect_os(), cmd = '{0} -A {1}'.format(__detect_os(),
_build_cmd(protocol=protocol, _build_cmd(protocol=protocol,
service_address=service_address, 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 salt '*' lvs.edit_service tcp 1.1.1.1:80 rr
''' '''
cmd = '{0} -E {1}'.format(__detect_os(), cmd = '{0} -E {1}'.format(__detect_os(),
_build_cmd(protocol=protocol, _build_cmd(protocol=protocol,
service_address=service_address, service_address=service_address,
@ -160,12 +160,12 @@ def delete_service(protocol=None, service_address=None):
service_address service_address
The LVS service address. The LVS service address.
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
salt '*' lvs.delete_service tcp 1.1.1.1:80 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 server_address
The real server address. The real server address.
packet_forward_method packet_forward_method
The LVS packet forwarding method(``dr`` for direct routing, ``tunnel`` for tunneling, ``nat`` for network access translation). The LVS packet forwarding method(``dr`` for direct routing, ``tunnel`` for tunneling, ``nat`` for network access translation).
weight weight
The capacity of a server relative to the others in the pool. The capacity of a server relative to the others in the pool.
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
salt '*' lvs.add_server tcp 1.1.1.1:80 192.168.0.11:8080 nat 1 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 server_address
The real server address. The real server address.
packet_forward_method packet_forward_method
The LVS packet forwarding method(``dr`` for direct routing, ``tunnel`` for tunneling, ``nat`` for network access translation). The LVS packet forwarding method(``dr`` for direct routing, ``tunnel`` for tunneling, ``nat`` for network access translation).
weight weight
The capacity of a server relative to the others in the pool. The capacity of a server relative to the others in the pool.
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
salt '*' lvs.edit_server tcp 1.1.1.1:80 192.168.0.11:8080 nat 1 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 server_address
The real server address. The real server address.
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
salt '*' lvs.delete_server tcp 1.1.1.1:80 192.168.0.11:8080 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(): def clear():
''' '''
Clear the virtual server table Clear the virtual server table
CLI Example: CLI Example:
@ -334,11 +334,11 @@ def clear():
def get_rules(): def get_rules():
''' '''
Get the virtual server rules Get the virtual server rules
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
salt '*' lvs.get_rules 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. List the virtual server table if service_address is not specified. If a service_address is selected, list this service only.
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
salt '*' lvs.list salt '*' lvs.list
''' '''
if service_address: if service_address:
cmd = '{0} -L {1} -n'.format(__detect_os(), cmd = '{0} -L {1} -n'.format(__detect_os(),
_build_cmd(protocol=protocol, _build_cmd(protocol=protocol,
@ -378,15 +378,16 @@ def list(protocol=None, service_address=None):
return ret return ret
def zero(protocol=None, service_address=None): def zero(protocol=None, service_address=None):
''' '''
Zero the packet, byte and rate counters in a service or all services. Zero the packet, byte and rate counters in a service or all services.
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
salt '*' lvs.zero salt '*' lvs.zero
''' '''
@ -410,7 +411,7 @@ def check_service(protocol=None, service_address=None, **kwargs):
''' '''
Check the virtual service exists. Check the virtual service exists.
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
@ -423,7 +424,7 @@ def check_service(protocol=None, service_address=None, **kwargs):
**kwargs)) **kwargs))
# Exact match # Exact match
if not kwargs: if not kwargs:
cmd += ' ' cmd += ' '
all_rules = get_rules() all_rules = get_rules()
out = all_rules.find(cmd) out = all_rules.find(cmd)
@ -434,6 +435,7 @@ def check_service(protocol=None, service_address=None, **kwargs):
ret = 'Error: service not exists' ret = 'Error: service not exists'
return ret return ret
def check_server(protocol=None, service_address=None, server_address=None, **kwargs): 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:: .. warning::
This module has been completely rewritten. Up to and includng version 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 ``pkgng.delete``, etc.), but moving forward this module will no longer be
available as ``pkgng``, as it will behave like a normal Salt ``pkg`` available as ``pkgng``, as it will behave like a normal Salt ``pkg``
provider. The documentation below should not be considered to apply to this 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 module in versions <= 0.17.x. If your minion is running a 0.17.x release or
versions, then the documentation for this module can be viewed using the older, then the documentation for this module can be viewed using the
:mod:`sys.doc <salt.modules.sys.doc>` function: :mod:`sys.doc <salt.modules.sys.doc>` function:
.. code-block:: bash .. code-block:: bash

View File

@ -504,7 +504,7 @@ def pid(sig):
cmd = "{0[ps]} | grep {1} | grep -v grep | awk '{{print $2}}'".format( cmd = "{0[ps]} | grep {1} | grep -v grep | awk '{{print $2}}'".format(
__grains__, sig) __grains__, sig)
return (__salt__['cmd.run_stdout'](cmd) or '') return (__salt__['cmd.run_stdout'](cmd) or '')
def version(): def version():
''' '''
@ -522,6 +522,3 @@ def version():
ret = salt.utils.fopen(procf, 'r').read().strip() ret = salt.utils.fopen(procf, 'r').read().strip()
return ret 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. 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__(): def __virtual__():
''' '''
@ -14,12 +15,13 @@ def __virtual__():
''' '''
return 'lvs_server' if 'lvs.get_rules' in __salt__ else False return 'lvs_server' if 'lvs.get_rules' in __salt__ else False
def present(name, def present(name,
protocol=None, protocol=None,
service_address=None, service_address=None,
server_address=None, server_address=None,
packet_forward_method='dr', packet_forward_method='dr',
weight=1 weight=1
): ):
''' '''
Ensure that the named service is present. Ensure that the named service is present.
@ -35,7 +37,7 @@ def present(name,
server_address server_address
The real server address. The real server address.
packet_forward_method packet_forward_method
The LVS packet forwarding method(``dr`` for direct routing, ``tunnel`` for tunneling, ``nat`` for network access translation). 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
return ret return ret
def absent(name, protocol=None, service_address=None, server_address=None): def absent(name, protocol=None, service_address=None, server_address=None):
''' '''
Ensure the LVS Real Server in specified service is absent. Ensure the LVS Real Server in specified service is absent.
name name
The name of the LVS server. The name of the LVS server.
protocol protocol
The service protocol(only support ``tcp``, ``udp`` and ``fwmark`` service). The service protocol(only support ``tcp``, ``udp`` and ``fwmark`` service).
service_address service_address
The LVS service adress. The LVS service adress.
server_address server_address
The LVS real server address. The LVS real server address.
''' '''
@ -134,7 +136,7 @@ def absent(name, protocol=None, service_address=None, server_address=None):
'changes': {}, 'changes': {},
'result': True, 'result': True,
'comment': ''} 'comment': ''}
#check if server exists and remove it #check if server exists and remove it
server_check = __salt__['lvs.check_server'](protocol=protocol, server_check = __salt__['lvs.check_server'](protocol=protocol,
service_address=service_address, 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. This lvs_service module is used to create and manage LVS Service. Service can be set as either absent or present.
''' '''
def __virtual__(): def __virtual__():
''' '''
@ -14,6 +15,7 @@ def __virtual__():
''' '''
return 'lvs_service' if 'lvs.get_rules' in __salt__ else False return 'lvs_service' if 'lvs.get_rules' in __salt__ else False
def present(name, def present(name,
protocol=None, protocol=None,
service_address=None, service_address=None,
@ -93,11 +95,11 @@ def present(name,
return ret return ret
return ret return ret
def absent(name, protocol=None, service_address=None): def absent(name, protocol=None, service_address=None):
''' '''
Ensure the LVS service is absent. Ensure the LVS service is absent.
name name
@ -113,7 +115,7 @@ def absent(name, protocol=None, service_address=None):
'changes': {}, 'changes': {},
'result': True, 'result': True,
'comment': ''} 'comment': ''}
#check if service exists and remove it #check if service exists and remove it
service_check = __salt__['lvs.check_service'](protocol=protocol, service_check = __salt__['lvs.check_service'](protocol=protocol,
service_address=service_address) service_address=service_address)

View File

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