"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "salt/modules/consul.py" between
salt-3002.1.tar.gz and salt-3002.2.tar.gz

About: SaltStack is a systems management software for data center automation, cloud orchestration, server provisioning, configuration management and more. Community version.

consul.py  (salt-3002.1):consul.py  (salt-3002.2)
# -*- coding: utf-8 -*-
""" """
Interact with Consul Interact with Consul
https://www.consul.io https://www.consul.io
""" """
# Import Python Libs
from __future__ import absolute_import, print_function, unicode_literals
import base64 import base64
import http.client
import logging import logging
import urllib
# Import salt libs
import salt.utils.http import salt.utils.http
import salt.utils.json import salt.utils.json
from salt.exceptions import SaltInvocationError from salt.exceptions import SaltInvocationError
# Import 3rd-party libs
from salt.ext import six
from salt.ext.six.moves import http_client, urllib
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
# Don't shadow built-ins. # Don't shadow built-ins.
__func_alias__ = {"list_": "list"} __func_alias__ = {"list_": "list"}
__virtualname__ = "consul" __virtualname__ = "consul"
def _get_config(): def _get_config():
""" """
Retrieve Consul configuration Retrieve Consul configuration
skipping to change at line 74 skipping to change at line 67
if not query_params: if not query_params:
query_params = {} query_params = {}
ret = {"data": "", "res": True} ret = {"data": "", "res": True}
if not token: if not token:
token = _get_token() token = _get_token()
headers = {"X-Consul-Token": token, "Content-Type": "application/json"} headers = {"X-Consul-Token": token, "Content-Type": "application/json"}
base_url = urllib.parse.urljoin(consul_url, "{0}/".format(api_version)) base_url = urllib.parse.urljoin(consul_url, "{}/".format(api_version))
url = urllib.parse.urljoin(base_url, function, False) url = urllib.parse.urljoin(base_url, function, False)
if method == "GET": if method == "GET":
data = None data = None
else: else:
if data is None: if data is None:
data = {} data = {}
data = salt.utils.json.dumps(data) data = salt.utils.json.dumps(data)
result = salt.utils.http.query( result = salt.utils.http.query(
url, url,
method=method, method=method,
params=query_params, params=query_params,
data=data, data=data,
decode=True, decode=True,
status=True, status=True,
header_dict=headers, header_dict=headers,
opts=__opts__, opts=__opts__,
) )
if result.get("status", None) == http_client.OK: if result.get("status", None) == http.client.OK:
ret["data"] = result.get("dict", result) ret["data"] = result.get("dict", result)
ret["res"] = True ret["res"] = True
elif result.get("status", None) == http_client.NO_CONTENT: elif result.get("status", None) == http.client.NO_CONTENT:
ret["res"] = False ret["res"] = False
elif result.get("status", None) == http_client.NOT_FOUND: elif result.get("status", None) == http.client.NOT_FOUND:
ret["data"] = "Key not found." ret["data"] = "Key not found."
ret["res"] = False ret["res"] = False
else: else:
if result: if result:
ret["data"] = result ret["data"] = result
ret["res"] = True ret["res"] = True
else: else:
ret["res"] = False ret["res"] = False
return ret return ret
skipping to change at line 147 skipping to change at line 140
query_params = {} query_params = {}
if "recurse" in kwargs: if "recurse" in kwargs:
query_params["recurse"] = "True" query_params["recurse"] = "True"
# No key so recurse and show all values # No key so recurse and show all values
if not key: if not key:
query_params["recurse"] = "True" query_params["recurse"] = "True"
function = "kv/" function = "kv/"
else: else:
function = "kv/{0}".format(key) function = "kv/{}".format(key)
query_params["keys"] = "True" query_params["keys"] = "True"
query_params["separator"] = "/" query_params["separator"] = "/"
ret = _query( ret = _query(
consul_url=consul_url, function=function, token=token, query_params=quer y_params consul_url=consul_url, function=function, token=token, query_params=quer y_params
) )
return ret return ret
def get(consul_url=None, key=None, token=None, recurse=False, decode=False, raw= False): def get(consul_url=None, key=None, token=None, recurse=False, decode=False, raw= False):
""" """
skipping to change at line 200 skipping to change at line 193
if not consul_url: if not consul_url:
log.error("No Consul URL found.") log.error("No Consul URL found.")
ret["message"] = "No Consul URL found." ret["message"] = "No Consul URL found."
ret["res"] = False ret["res"] = False
return ret return ret
if not key: if not key:
raise SaltInvocationError('Required argument "key" is missing.') raise SaltInvocationError('Required argument "key" is missing.')
query_params = {} query_params = {}
function = "kv/{0}".format(key) function = "kv/{}".format(key)
if recurse: if recurse:
query_params["recurse"] = "True" query_params["recurse"] = "True"
if raw: if raw:
query_params["raw"] = True query_params["raw"] = True
ret = _query( ret = _query(
consul_url=consul_url, function=function, token=token, query_params=quer y_params consul_url=consul_url, function=function, token=token, query_params=quer y_params
) )
if ret["res"]: if ret["res"]:
if decode: if decode:
skipping to change at line 265 skipping to change at line 258
if not key: if not key:
raise SaltInvocationError('Required argument "key" is missing.') raise SaltInvocationError('Required argument "key" is missing.')
# Invalid to specified these together # Invalid to specified these together
conflicting_args = ["cas", "release", "acquire"] conflicting_args = ["cas", "release", "acquire"]
for _l1 in conflicting_args: for _l1 in conflicting_args:
for _l2 in conflicting_args: for _l2 in conflicting_args:
if _l1 in kwargs and _l2 in kwargs and _l1 != _l2: if _l1 in kwargs and _l2 in kwargs and _l1 != _l2:
raise SaltInvocationError( raise SaltInvocationError(
"Using arguments `{0}` and `{1}`" "Using arguments `{}` and `{}`"
" together is invalid.".format(_l1, _l2) " together is invalid.".format(_l1, _l2)
) )
query_params = {} query_params = {}
available_sessions = session_list(consul_url=consul_url, return_list=True) available_sessions = session_list(consul_url=consul_url, return_list=True)
_current = get(consul_url=consul_url, key=key) _current = get(consul_url=consul_url, key=key)
if "flags" in kwargs: if "flags" in kwargs:
if kwargs["flags"] >= 0 and kwargs["flags"] <= 2 ** 64: if kwargs["flags"] >= 0 and kwargs["flags"] <= 2 ** 64:
query_params["flags"] = kwargs["flags"] query_params["flags"] = kwargs["flags"]
if "cas" in kwargs: if "cas" in kwargs:
if _current["res"]: if _current["res"]:
if kwargs["cas"] == 0: if kwargs["cas"] == 0:
ret["message"] = "Key {0} exists, index " "must be non-zero.".fo ret["message"] = "Key {} exists, index " "must be non-zero.".for
rmat( mat(key)
key
)
ret["res"] = False ret["res"] = False
return ret return ret
if kwargs["cas"] != _current["data"]["ModifyIndex"]: if kwargs["cas"] != _current["data"]["ModifyIndex"]:
ret["message"] = "Key {0} exists, but indexes " "do not match.". format( ret["message"] = "Key {} exists, but indexes " "do not match.".f ormat(
key key
) )
ret["res"] = False ret["res"] = False
return ret return ret
query_params["cas"] = kwargs["cas"] query_params["cas"] = kwargs["cas"]
else: else:
ret[ ret[
"message" "message"
] = "Key {0} does not exists, " "CAS argument can not be used.".form at(key) ] = "Key {} does not exists, " "CAS argument can not be used.".forma t(key)
ret["res"] = False ret["res"] = False
return ret return ret
if "acquire" in kwargs: if "acquire" in kwargs:
if kwargs["acquire"] not in available_sessions: if kwargs["acquire"] not in available_sessions:
ret["message"] = "{0} is not a valid session.".format(kwargs["acquir e"]) ret["message"] = "{} is not a valid session.".format(kwargs["acquire "])
ret["res"] = False ret["res"] = False
return ret return ret
query_params["acquire"] = kwargs["acquire"] query_params["acquire"] = kwargs["acquire"]
if "release" in kwargs: if "release" in kwargs:
if _current["res"]: if _current["res"]:
if "Session" in _current["data"]: if "Session" in _current["data"]:
if _current["data"]["Session"] == kwargs["release"]: if _current["data"]["Session"] == kwargs["release"]:
query_params["release"] = kwargs["release"] query_params["release"] = kwargs["release"]
else: else:
ret["message"] = "{0} locked by another session.".format(key ) ret["message"] = "{} locked by another session.".format(key)
ret["res"] = False ret["res"] = False
return ret return ret
else: else:
ret["message"] = "{0} is not a valid session.".format(kwargs["ac quire"]) ret["message"] = "{} is not a valid session.".format(kwargs["acq uire"])
ret["res"] = False ret["res"] = False
else: else:
log.error("Key {0} does not exist. Skipping release.") log.error("Key {0} does not exist. Skipping release.")
data = value data = value
function = "kv/{0}".format(key) function = "kv/{}".format(key)
method = "PUT" method = "PUT"
ret = _query( ret = _query(
consul_url=consul_url, consul_url=consul_url,
token=token, token=token,
function=function, function=function,
method=method, method=method,
data=data, data=data,
query_params=query_params, query_params=query_params,
) )
if ret["res"]: if ret["res"]:
ret["res"] = True ret["res"] = True
ret["data"] = "Added key {0} with value {1}.".format(key, value) ret["data"] = "Added key {} with value {}.".format(key, value)
else: else:
ret["res"] = False ret["res"] = False
ret["data"] = "Unable to add key {0} with value {1}.".format(key, value) ret["data"] = "Unable to add key {} with value {}.".format(key, value)
return ret return ret
def delete(consul_url=None, token=None, key=None, **kwargs): def delete(consul_url=None, token=None, key=None, **kwargs):
""" """
Delete values from Consul Delete values from Consul
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:param key: The key to use as the starting point for the list. :param key: The key to use as the starting point for the list.
:param recurse: Delete values recursively beginning at the value of key. :param recurse: Delete values recursively beginning at the value of key.
:param cas: This flag is used to turn the DELETE into :param cas: This flag is used to turn the DELETE into
skipping to change at line 392 skipping to change at line 383
if kwargs["cas"] > 0: if kwargs["cas"] > 0:
query_params["cas"] = kwargs["cas"] query_params["cas"] = kwargs["cas"]
else: else:
ret["message"] = ( ret["message"] = (
"Check and Set Operation ", "Check and Set Operation ",
"value must be greater than 0.", "value must be greater than 0.",
) )
ret["res"] = False ret["res"] = False
return ret return ret
function = "kv/{0}".format(key) function = "kv/{}".format(key)
ret = _query( ret = _query(
consul_url=consul_url, consul_url=consul_url,
token=token, token=token,
function=function, function=function,
method="DELETE", method="DELETE",
query_params=query_params, query_params=query_params,
) )
if ret["res"]: if ret["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Deleted key {0}.".format(key) ret["message"] = "Deleted key {}.".format(key)
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Unable to delete key {0}.".format(key) ret["message"] = "Unable to delete key {}.".format(key)
return ret return ret
def agent_checks(consul_url=None, token=None): def agent_checks(consul_url=None, token=None):
""" """
Returns the checks the local agent is managing Returns the checks the local agent is managing
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:return: Returns the checks the local agent is managing :return: Returns the checks the local agent is managing
CLI Example: CLI Example:
skipping to change at line 585 skipping to change at line 576
function = "agent/maintenance" function = "agent/maintenance"
res = _query( res = _query(
consul_url=consul_url, consul_url=consul_url,
function=function, function=function,
token=token, token=token,
method="PUT", method="PUT",
query_params=query_params, query_params=query_params,
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Agent maintenance mode " "{0}ed.".format(kwargs["enabl e"]) ret["message"] = "Agent maintenance mode " "{}ed.".format(kwargs["enable "])
else: else:
ret["res"] = True ret["res"] = True
ret["message"] = "Unable to change maintenance mode for agent." ret["message"] = "Unable to change maintenance mode for agent."
return ret return ret
def agent_join(consul_url=None, token=None, address=None, **kwargs): def agent_join(consul_url=None, token=None, address=None, **kwargs):
""" """
Triggers the local agent to join a node Triggers the local agent to join a node
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
skipping to change at line 623 skipping to change at line 614
ret["message"] = "No Consul URL found." ret["message"] = "No Consul URL found."
ret["res"] = False ret["res"] = False
return ret return ret
if not address: if not address:
raise SaltInvocationError('Required argument "address" is missing.') raise SaltInvocationError('Required argument "address" is missing.')
if "wan" in kwargs: if "wan" in kwargs:
query_params["wan"] = kwargs["wan"] query_params["wan"] = kwargs["wan"]
function = "agent/join/{0}".format(address) function = "agent/join/{}".format(address)
res = _query( res = _query(
consul_url=consul_url, consul_url=consul_url,
function=function, function=function,
token=token, token=token,
method="GET", method="GET",
query_params=query_params, query_params=query_params,
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Agent joined the cluster" ret["message"] = "Agent joined the cluster"
skipping to change at line 667 skipping to change at line 658
consul_url = _get_config() consul_url = _get_config()
if not consul_url: if not consul_url:
log.error("No Consul URL found.") log.error("No Consul URL found.")
ret["message"] = "No Consul URL found." ret["message"] = "No Consul URL found."
ret["res"] = False ret["res"] = False
return ret return ret
if not node: if not node:
raise SaltInvocationError('Required argument "node" is missing.') raise SaltInvocationError('Required argument "node" is missing.')
function = "agent/force-leave/{0}".format(node) function = "agent/force-leave/{}".format(node)
res = _query( res = _query(
consul_url=consul_url, consul_url=consul_url,
function=function, function=function,
token=token, token=token,
method="GET", method="GET",
query_params=query_params, query_params=query_params,
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Node {0} put in leave state.".format(node) ret["message"] = "Node {} put in leave state.".format(node)
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Unable to change state for {0}.".format(node) ret["message"] = "Unable to change state for {}.".format(node)
return ret return ret
def agent_check_register(consul_url=None, token=None, **kwargs): def agent_check_register(consul_url=None, token=None, **kwargs):
""" """
The register endpoint is used to add a new check to the local agent. The register endpoint is used to add a new check to the local agent.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:param name: The description of what the check is for. :param name: The description of what the check is for.
:param id: The unique name to use for the check, if not :param id: The unique name to use for the check, if not
provided 'name' is used. provided 'name' is used.
skipping to change at line 762 skipping to change at line 753
if "ttl" in kwargs: if "ttl" in kwargs:
data["TTL"] = kwargs["ttl"] data["TTL"] = kwargs["ttl"]
function = "agent/check/register" function = "agent/check/register"
res = _query( res = _query(
consul_url=consul_url, function=function, token=token, method="PUT", dat a=data consul_url=consul_url, function=function, token=token, method="PUT", dat a=data
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Check {0} added to agent.".format(kwargs["name"]) ret["message"] = "Check {} added to agent.".format(kwargs["name"])
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Unable to add check to agent." ret["message"] = "Unable to add check to agent."
return ret return ret
def agent_check_deregister(consul_url=None, token=None, checkid=None): def agent_check_deregister(consul_url=None, token=None, checkid=None):
""" """
The agent will take care of deregistering the check from the Catalog. The agent will take care of deregistering the check from the Catalog.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
skipping to change at line 795 skipping to change at line 786
consul_url = _get_config() consul_url = _get_config()
if not consul_url: if not consul_url:
log.error("No Consul URL found.") log.error("No Consul URL found.")
ret["message"] = "No Consul URL found." ret["message"] = "No Consul URL found."
ret["res"] = False ret["res"] = False
return ret return ret
if not checkid: if not checkid:
raise SaltInvocationError('Required argument "checkid" is missing.') raise SaltInvocationError('Required argument "checkid" is missing.')
function = "agent/check/deregister/{0}".format(checkid) function = "agent/check/deregister/{}".format(checkid)
res = _query(consul_url=consul_url, function=function, token=token, method=" GET") res = _query(consul_url=consul_url, function=function, token=token, method=" GET")
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Check {0} removed from agent.".format(checkid) ret["message"] = "Check {} removed from agent.".format(checkid)
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Unable to remove check from agent." ret["message"] = "Unable to remove check from agent."
return ret return ret
def agent_check_pass(consul_url=None, token=None, checkid=None, **kwargs): def agent_check_pass(consul_url=None, token=None, checkid=None, **kwargs):
""" """
This endpoint is used with a check that is of the TTL type. When this This endpoint is used with a check that is of the TTL type. When this
is called, the status of the check is set to passing and the TTL is called, the status of the check is set to passing and the TTL
clock is reset. clock is reset.
skipping to change at line 839 skipping to change at line 830
ret["message"] = "No Consul URL found." ret["message"] = "No Consul URL found."
ret["res"] = False ret["res"] = False
return ret return ret
if not checkid: if not checkid:
raise SaltInvocationError('Required argument "checkid" is missing.') raise SaltInvocationError('Required argument "checkid" is missing.')
if "note" in kwargs: if "note" in kwargs:
query_params["note"] = kwargs["note"] query_params["note"] = kwargs["note"]
function = "agent/check/pass/{0}".format(checkid) function = "agent/check/pass/{}".format(checkid)
res = _query( res = _query(
consul_url=consul_url, consul_url=consul_url,
function=function, function=function,
token=token, token=token,
query_params=query_params, query_params=query_params,
method="GET", method="GET",
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Check {0} marked as passing.".format(checkid) ret["message"] = "Check {} marked as passing.".format(checkid)
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Unable to update check {0}.".format(checkid) ret["message"] = "Unable to update check {}.".format(checkid)
return ret return ret
def agent_check_warn(consul_url=None, token=None, checkid=None, **kwargs): def agent_check_warn(consul_url=None, token=None, checkid=None, **kwargs):
""" """
This endpoint is used with a check that is of the TTL type. When this This endpoint is used with a check that is of the TTL type. When this
is called, the status of the check is set to warning and the TTL is called, the status of the check is set to warning and the TTL
clock is reset. clock is reset.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:param checkid: The ID of the check to deregister from Consul. :param checkid: The ID of the check to deregister from Consul.
skipping to change at line 889 skipping to change at line 880
ret["message"] = "No Consul URL found." ret["message"] = "No Consul URL found."
ret["res"] = False ret["res"] = False
return ret return ret
if not checkid: if not checkid:
raise SaltInvocationError('Required argument "checkid" is missing.') raise SaltInvocationError('Required argument "checkid" is missing.')
if "note" in kwargs: if "note" in kwargs:
query_params["note"] = kwargs["note"] query_params["note"] = kwargs["note"]
function = "agent/check/warn/{0}".format(checkid) function = "agent/check/warn/{}".format(checkid)
res = _query( res = _query(
consul_url=consul_url, consul_url=consul_url,
function=function, function=function,
token=token, token=token,
query_params=query_params, query_params=query_params,
method="GET", method="GET",
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Check {0} marked as warning.".format(checkid) ret["message"] = "Check {} marked as warning.".format(checkid)
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Unable to update check {0}.".format(checkid) ret["message"] = "Unable to update check {}.".format(checkid)
return ret return ret
def agent_check_fail(consul_url=None, token=None, checkid=None, **kwargs): def agent_check_fail(consul_url=None, token=None, checkid=None, **kwargs):
""" """
This endpoint is used with a check that is of the TTL type. When this This endpoint is used with a check that is of the TTL type. When this
is called, the status of the check is set to critical and the is called, the status of the check is set to critical and the
TTL clock is reset. TTL clock is reset.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:param checkid: The ID of the check to deregister from Consul. :param checkid: The ID of the check to deregister from Consul.
skipping to change at line 939 skipping to change at line 930
ret["message"] = "No Consul URL found." ret["message"] = "No Consul URL found."
ret["res"] = False ret["res"] = False
return ret return ret
if not checkid: if not checkid:
raise SaltInvocationError('Required argument "checkid" is missing.') raise SaltInvocationError('Required argument "checkid" is missing.')
if "note" in kwargs: if "note" in kwargs:
query_params["note"] = kwargs["note"] query_params["note"] = kwargs["note"]
function = "agent/check/fail/{0}".format(checkid) function = "agent/check/fail/{}".format(checkid)
res = _query( res = _query(
consul_url=consul_url, consul_url=consul_url,
function=function, function=function,
token=token, token=token,
query_params=query_params, query_params=query_params,
method="GET", method="GET",
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Check {0} marked as critical.".format(checkid) ret["message"] = "Check {} marked as critical.".format(checkid)
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Unable to update check {0}.".format(checkid) ret["message"] = "Unable to update check {}.".format(checkid)
return ret return ret
def agent_service_register(consul_url=None, token=None, **kwargs): def agent_service_register(consul_url=None, token=None, **kwargs):
""" """
The used to add a new service, with an optional The used to add a new service, with an optional
health check, to the local agent. health check, to the local agent.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:param name: A name describing the service. :param name: A name describing the service.
:param address: The address used by the service, defaults :param address: The address used by the service, defaults
skipping to change at line 998 skipping to change at line 989
data = {} data = {}
if not consul_url: if not consul_url:
consul_url = _get_config() consul_url = _get_config()
if not consul_url: if not consul_url:
log.error("No Consul URL found.") log.error("No Consul URL found.")
ret["message"] = "No Consul URL found." ret["message"] = "No Consul URL found."
ret["res"] = False ret["res"] = False
return ret return ret
lc_kwargs = dict() lc_kwargs = dict()
for k, v in six.iteritems(kwargs): for k, v in kwargs.items():
lc_kwargs[k.lower()] = v lc_kwargs[k.lower()] = v
if "name" in lc_kwargs: if "name" in lc_kwargs:
data["Name"] = lc_kwargs["name"] data["Name"] = lc_kwargs["name"]
else: else:
raise SaltInvocationError('Required argument "name" is missing.') raise SaltInvocationError('Required argument "name" is missing.')
if "address" in lc_kwargs: if "address" in lc_kwargs:
data["Address"] = lc_kwargs["address"] data["Address"] = lc_kwargs["address"]
skipping to change at line 1026 skipping to change at line 1017
_tags = lc_kwargs["tags"] _tags = lc_kwargs["tags"]
if not isinstance(_tags, list): if not isinstance(_tags, list):
_tags = [_tags] _tags = [_tags]
data["Tags"] = _tags data["Tags"] = _tags
if "enabletagoverride" in lc_kwargs: if "enabletagoverride" in lc_kwargs:
data["EnableTagOverride"] = lc_kwargs["enabletagoverride"] data["EnableTagOverride"] = lc_kwargs["enabletagoverride"]
if "check" in lc_kwargs: if "check" in lc_kwargs:
dd = dict() dd = dict()
for k, v in six.iteritems(lc_kwargs["check"]): for k, v in lc_kwargs["check"].items():
dd[k.lower()] = v dd[k.lower()] = v
interval_required = False interval_required = False
check_dd = dict() check_dd = dict()
if "script" in dd: if "script" in dd:
interval_required = True interval_required = True
check_dd["Script"] = dd["script"] check_dd["Script"] = dd["script"]
if "http" in dd: if "http" in dd:
interval_required = True interval_required = True
check_dd["HTTP"] = dd["http"] check_dd["HTTP"] = dd["http"]
skipping to change at line 1051 skipping to change at line 1042
if interval_required: if interval_required:
if "Interval" not in check_dd: if "Interval" not in check_dd:
ret["message"] = 'Required parameter "interval" is missing.' ret["message"] = 'Required parameter "interval" is missing.'
ret["res"] = False ret["res"] = False
return ret return ret
else: else:
if "Interval" in check_dd: if "Interval" in check_dd:
del check_dd["Interval"] # not required, so ignore it del check_dd["Interval"] # not required, so ignore it
if check_dd > 0: if check_dd:
data["Check"] = check_dd # if empty, ignore it data["Check"] = check_dd # if empty, ignore it
function = "agent/service/register" function = "agent/service/register"
res = _query( res = _query(
consul_url=consul_url, function=function, token=token, method="PUT", dat a=data consul_url=consul_url, function=function, token=token, method="PUT", dat a=data
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Service {0} registered on agent.".format(kwargs["name" ]) ret["message"] = "Service {} registered on agent.".format(kwargs["name"] )
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Unable to register service {0}.".format(kwargs["name"] ) ret["message"] = "Unable to register service {}.".format(kwargs["name"])
return ret return ret
def agent_service_deregister(consul_url=None, token=None, serviceid=None): def agent_service_deregister(consul_url=None, token=None, serviceid=None):
""" """
Used to remove a service. Used to remove a service.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:param serviceid: A serviceid describing the service. :param serviceid: A serviceid describing the service.
:return: Boolean and message indicating success or failure. :return: Boolean and message indicating success or failure.
skipping to change at line 1094 skipping to change at line 1085
consul_url = _get_config() consul_url = _get_config()
if not consul_url: if not consul_url:
log.error("No Consul URL found.") log.error("No Consul URL found.")
ret["message"] = "No Consul URL found." ret["message"] = "No Consul URL found."
ret["res"] = False ret["res"] = False
return ret return ret
if not serviceid: if not serviceid:
raise SaltInvocationError('Required argument "serviceid" is missing.') raise SaltInvocationError('Required argument "serviceid" is missing.')
function = "agent/service/deregister/{0}".format(serviceid) function = "agent/service/deregister/{}".format(serviceid)
res = _query( res = _query(
consul_url=consul_url, function=function, token=token, method="PUT", dat a=data consul_url=consul_url, function=function, token=token, method="PUT", dat a=data
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Service {0} removed from agent.".format(serviceid) ret["message"] = "Service {} removed from agent.".format(serviceid)
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Unable to remove service {0}.".format(serviceid) ret["message"] = "Unable to remove service {}.".format(serviceid)
return ret return ret
def agent_service_maintenance(consul_url=None, token=None, serviceid=None, **kwa rgs): def agent_service_maintenance(consul_url=None, token=None, serviceid=None, **kwa rgs):
""" """
Used to place a service into maintenance mode. Used to place a service into maintenance mode.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:param serviceid: A name of the service. :param serviceid: A name of the service.
:param enable: Whether the service should be enabled or disabled. :param enable: Whether the service should be enabled or disabled.
:param reason: A human readable message of why the service was :param reason: A human readable message of why the service was
skipping to change at line 1147 skipping to change at line 1138
if "enable" in kwargs: if "enable" in kwargs:
query_params["enable"] = kwargs["enable"] query_params["enable"] = kwargs["enable"]
else: else:
ret["message"] = 'Required parameter "enable" is missing.' ret["message"] = 'Required parameter "enable" is missing.'
ret["res"] = False ret["res"] = False
return ret return ret
if "reason" in kwargs: if "reason" in kwargs:
query_params["reason"] = kwargs["reason"] query_params["reason"] = kwargs["reason"]
function = "agent/service/maintenance/{0}".format(serviceid) function = "agent/service/maintenance/{}".format(serviceid)
res = _query( res = _query(
consul_url=consul_url, token=token, function=function, query_params=quer y_params consul_url=consul_url, token=token, function=function, query_params=quer y_params
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Service {0} set in " "maintenance mode.".format(servic eid) ret["message"] = "Service {} set in " "maintenance mode.".format(service id)
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Unable to set service " "{0} to maintenance mode.".for mat( ret["message"] = "Unable to set service " "{} to maintenance mode.".form at(
serviceid serviceid
) )
return ret return ret
def session_create(consul_url=None, token=None, **kwargs): def session_create(consul_url=None, token=None, **kwargs):
""" """
Used to create a session. Used to create a session.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:param lockdelay: Duration string using a "s" suffix for seconds. :param lockdelay: Duration string using a "s" suffix for seconds.
skipping to change at line 1226 skipping to change at line 1217
if "behavior" in kwargs: if "behavior" in kwargs:
if not kwargs["behavior"] in ("delete", "release"): if not kwargs["behavior"] in ("delete", "release"):
ret["message"] = ("Behavior must be ", "either delete or release.") ret["message"] = ("Behavior must be ", "either delete or release.")
ret["res"] = False ret["res"] = False
return ret return ret
data["Behavior"] = kwargs["behavior"] data["Behavior"] = kwargs["behavior"]
if "ttl" in kwargs: if "ttl" in kwargs:
_ttl = kwargs["ttl"] _ttl = kwargs["ttl"]
if six.text_type(_ttl).endswith("s"): if str(_ttl).endswith("s"):
_ttl = _ttl[:-1] _ttl = _ttl[:-1]
if int(_ttl) < 0 or int(_ttl) > 3600: if int(_ttl) < 0 or int(_ttl) > 3600:
ret["message"] = ("TTL must be ", "between 0 and 3600.") ret["message"] = ("TTL must be ", "between 0 and 3600.")
ret["res"] = False ret["res"] = False
return ret return ret
data["TTL"] = "{0}s".format(_ttl) data["TTL"] = "{}s".format(_ttl)
function = "session/create" function = "session/create"
res = _query( res = _query(
consul_url=consul_url, function=function, token=token, method="PUT", dat a=data consul_url=consul_url, function=function, token=token, method="PUT", dat a=data
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Created session {0}.".format(kwargs["name"]) ret["message"] = "Created session {}.".format(kwargs["name"])
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Unable to create session {0}.".format(kwargs["name"]) ret["message"] = "Unable to create session {}.".format(kwargs["name"])
return ret return ret
def session_list(consul_url=None, token=None, return_list=False, **kwargs): def session_list(consul_url=None, token=None, return_list=False, **kwargs):
""" """
Used to list sessions. Used to list sessions.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:param dc: By default, the datacenter of the agent is queried; :param dc: By default, the datacenter of the agent is queried;
however, the dc can be provided using the "dc" parameter. however, the dc can be provided using the "dc" parameter.
:param return_list: By default, all information about the sessions is :param return_list: By default, all information about the sessions is
skipping to change at line 1327 skipping to change at line 1318
return ret return ret
if not session: if not session:
raise SaltInvocationError('Required argument "session" is missing.') raise SaltInvocationError('Required argument "session" is missing.')
query_params = {} query_params = {}
if "dc" in kwargs: if "dc" in kwargs:
query_params["dc"] = kwargs["dc"] query_params["dc"] = kwargs["dc"]
function = "session/destroy/{0}".format(session) function = "session/destroy/{}".format(session)
res = _query( res = _query(
consul_url=consul_url, function=function, token=token, query_params=quer y_params consul_url=consul_url, function=function, token=token, query_params=quer y_params
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Created Service {0}.".format(kwargs["name"]) ret["message"] = "Created Service {}.".format(kwargs["name"])
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Unable to create service {0}.".format(kwargs["name"]) ret["message"] = "Unable to create service {}.".format(kwargs["name"])
return ret return ret
def session_info(consul_url=None, token=None, session=None, **kwargs): def session_info(consul_url=None, token=None, session=None, **kwargs):
""" """
Information about a session Information about a session
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:param session: The ID of the session to return information about. :param session: The ID of the session to return information about.
:param dc: By default, the datacenter of the agent is queried; :param dc: By default, the datacenter of the agent is queried;
however, the dc can be provided using the "dc" parameter. however, the dc can be provided using the "dc" parameter.
skipping to change at line 1373 skipping to change at line 1364
return ret return ret
if not session: if not session:
raise SaltInvocationError('Required argument "session" is missing.') raise SaltInvocationError('Required argument "session" is missing.')
query_params = {} query_params = {}
if "dc" in kwargs: if "dc" in kwargs:
query_params["dc"] = kwargs["dc"] query_params["dc"] = kwargs["dc"]
function = "session/info/{0}".format(session) function = "session/info/{}".format(session)
ret = _query( ret = _query(
consul_url=consul_url, function=function, token=token, query_params=quer y_params consul_url=consul_url, function=function, token=token, query_params=quer y_params
) )
return ret return ret
def catalog_register(consul_url=None, token=None, **kwargs): def catalog_register(consul_url=None, token=None, **kwargs):
""" """
Registers a new node, service, or check Registers a new node, service, or check
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
skipping to change at line 1535 skipping to change at line 1526
if "check_notes" in kwargs: if "check_notes" in kwargs:
data["Check"]["Notes"] = kwargs["check_notes"] data["Check"]["Notes"] = kwargs["check_notes"]
function = "catalog/register" function = "catalog/register"
res = _query( res = _query(
consul_url=consul_url, function=function, token=token, method="PUT", dat a=data consul_url=consul_url, function=function, token=token, method="PUT", dat a=data
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Catalog registration " "for {0} successful.".format( ret["message"] = "Catalog registration " "for {} successful.".format(
kwargs["node"] kwargs["node"]
) )
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Catalog registration " "for {0} failed.".format( ret["message"] = "Catalog registration " "for {} failed.".format(kwargs[
kwargs["node"] "node"])
)
ret["data"] = data ret["data"] = data
return ret return ret
def catalog_deregister(consul_url=None, token=None, **kwargs): def catalog_deregister(consul_url=None, token=None, **kwargs):
""" """
Deregisters a node, service, or check Deregisters a node, service, or check
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:param node: The node to deregister. :param node: The node to deregister.
:param datacenter: By default, the datacenter of the agent is queried; :param datacenter: By default, the datacenter of the agent is queried;
skipping to change at line 1598 skipping to change at line 1587
if "serviceid" in kwargs: if "serviceid" in kwargs:
data["ServiceID"] = kwargs["serviceid"] data["ServiceID"] = kwargs["serviceid"]
function = "catalog/deregister" function = "catalog/deregister"
res = _query( res = _query(
consul_url=consul_url, function=function, token=token, method="PUT", dat a=data consul_url=consul_url, function=function, token=token, method="PUT", dat a=data
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Catalog item {0} removed.".format(kwargs["node"]) ret["message"] = "Catalog item {} removed.".format(kwargs["node"])
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Removing Catalog " "item {0} failed.".format(kwargs["n ode"]) ret["message"] = "Removing Catalog " "item {} failed.".format(kwargs["no de"])
return ret return ret
def catalog_datacenters(consul_url=None, token=None): def catalog_datacenters(consul_url=None, token=None):
""" """
Return list of available datacenters from catalog. Return list of available datacenters from catalog.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:return: The list of available datacenters. :return: The list of available datacenters.
CLI Example: CLI Example:
skipping to change at line 1737 skipping to change at line 1726
if not service: if not service:
raise SaltInvocationError('Required argument "service" is missing.') raise SaltInvocationError('Required argument "service" is missing.')
if "dc" in kwargs: if "dc" in kwargs:
query_params["dc"] = kwargs["dc"] query_params["dc"] = kwargs["dc"]
if "tag" in kwargs: if "tag" in kwargs:
query_params["tag"] = kwargs["tag"] query_params["tag"] = kwargs["tag"]
function = "catalog/service/{0}".format(service) function = "catalog/service/{}".format(service)
ret = _query( ret = _query(
consul_url=consul_url, function=function, token=token, query_params=quer y_params consul_url=consul_url, function=function, token=token, query_params=quer y_params
) )
return ret return ret
def catalog_node(consul_url=None, token=None, node=None, **kwargs): def catalog_node(consul_url=None, token=None, node=None, **kwargs):
""" """
Information about the registered node. Information about the registered node.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
skipping to change at line 1776 skipping to change at line 1765
ret["message"] = "No Consul URL found." ret["message"] = "No Consul URL found."
ret["res"] = False ret["res"] = False
return ret return ret
if not node: if not node:
raise SaltInvocationError('Required argument "node" is missing.') raise SaltInvocationError('Required argument "node" is missing.')
if "dc" in kwargs: if "dc" in kwargs:
query_params["dc"] = kwargs["dc"] query_params["dc"] = kwargs["dc"]
function = "catalog/node/{0}".format(node) function = "catalog/node/{}".format(node)
ret = _query( ret = _query(
consul_url=consul_url, function=function, token=token, query_params=quer y_params consul_url=consul_url, function=function, token=token, query_params=quer y_params
) )
return ret return ret
def health_node(consul_url=None, token=None, node=None, **kwargs): def health_node(consul_url=None, token=None, node=None, **kwargs):
""" """
Health information about the registered node. Health information about the registered node.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
skipping to change at line 1815 skipping to change at line 1804
ret["message"] = "No Consul URL found." ret["message"] = "No Consul URL found."
ret["res"] = False ret["res"] = False
return ret return ret
if not node: if not node:
raise SaltInvocationError('Required argument "node" is missing.') raise SaltInvocationError('Required argument "node" is missing.')
if "dc" in kwargs: if "dc" in kwargs:
query_params["dc"] = kwargs["dc"] query_params["dc"] = kwargs["dc"]
function = "health/node/{0}".format(node) function = "health/node/{}".format(node)
ret = _query( ret = _query(
consul_url=consul_url, function=function, token=token, query_params=quer y_params consul_url=consul_url, function=function, token=token, query_params=quer y_params
) )
return ret return ret
def health_checks(consul_url=None, token=None, service=None, **kwargs): def health_checks(consul_url=None, token=None, service=None, **kwargs):
""" """
Health information about the registered service. Health information about the registered service.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
skipping to change at line 1854 skipping to change at line 1843
ret["message"] = "No Consul URL found." ret["message"] = "No Consul URL found."
ret["res"] = False ret["res"] = False
return ret return ret
if not service: if not service:
raise SaltInvocationError('Required argument "service" is missing.') raise SaltInvocationError('Required argument "service" is missing.')
if "dc" in kwargs: if "dc" in kwargs:
query_params["dc"] = kwargs["dc"] query_params["dc"] = kwargs["dc"]
function = "health/checks/{0}".format(service) function = "health/checks/{}".format(service)
ret = _query( ret = _query(
consul_url=consul_url, function=function, token=token, query_params=quer y_params consul_url=consul_url, function=function, token=token, query_params=quer y_params
) )
return ret return ret
def health_service(consul_url=None, token=None, service=None, **kwargs): def health_service(consul_url=None, token=None, service=None, **kwargs):
""" """
Health information about the registered service. Health information about the registered service.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
skipping to change at line 1904 skipping to change at line 1893
if "dc" in kwargs: if "dc" in kwargs:
query_params["dc"] = kwargs["dc"] query_params["dc"] = kwargs["dc"]
if "tag" in kwargs: if "tag" in kwargs:
query_params["tag"] = kwargs["tag"] query_params["tag"] = kwargs["tag"]
if "passing" in kwargs: if "passing" in kwargs:
query_params["passing"] = kwargs["passing"] query_params["passing"] = kwargs["passing"]
function = "health/service/{0}".format(service) function = "health/service/{}".format(service)
ret = _query( ret = _query(
consul_url=consul_url, function=function, token=token, query_params=quer y_params consul_url=consul_url, function=function, token=token, query_params=quer y_params
) )
return ret return ret
def health_state(consul_url=None, token=None, state=None, **kwargs): def health_state(consul_url=None, token=None, state=None, **kwargs):
""" """
Returns the checks in the state provided on the path. Returns the checks in the state provided on the path.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
skipping to change at line 1953 skipping to change at line 1942
raise SaltInvocationError('Required argument "state" is missing.') raise SaltInvocationError('Required argument "state" is missing.')
if "dc" in kwargs: if "dc" in kwargs:
query_params["dc"] = kwargs["dc"] query_params["dc"] = kwargs["dc"]
if state not in ("any", "unknown", "passing", "warning", "critical"): if state not in ("any", "unknown", "passing", "warning", "critical"):
ret["message"] = "State must be any, unknown, passing, warning, or criti cal." ret["message"] = "State must be any, unknown, passing, warning, or criti cal."
ret["res"] = False ret["res"] = False
return ret return ret
function = "health/state/{0}".format(state) function = "health/state/{}".format(state)
ret = _query( ret = _query(
consul_url=consul_url, function=function, token=token, query_params=quer y_params consul_url=consul_url, function=function, token=token, query_params=quer y_params
) )
return ret return ret
def status_leader(consul_url=None, token=None): def status_leader(consul_url=None, token=None):
""" """
Returns the current Raft leader Returns the current Raft leader
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
skipping to change at line 2062 skipping to change at line 2051
if "rules" in kwargs: if "rules" in kwargs:
data["Rules"] = kwargs["rules"] data["Rules"] = kwargs["rules"]
function = "acl/create" function = "acl/create"
res = _query( res = _query(
consul_url=consul_url, token=token, data=data, method="PUT", function=fu nction consul_url=consul_url, token=token, data=data, method="PUT", function=fu nction
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "ACL {0} created.".format(kwargs["name"]) ret["message"] = "ACL {} created.".format(kwargs["name"])
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Removing Catalog " "item {0} failed.".format(kwargs["n ame"]) ret["message"] = "Removing Catalog " "item {} failed.".format(kwargs["na me"])
return ret return ret
def acl_update(consul_url=None, token=None, **kwargs): def acl_update(consul_url=None, token=None, **kwargs):
""" """
Update an ACL token. Update an ACL token.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:param name: Meaningful indicator of the ACL's purpose. :param name: Meaningful indicator of the ACL's purpose.
:param id: Unique identifier for the ACL to update. :param id: Unique identifier for the ACL to update.
:param type: Type is either client or management. A management :param type: Type is either client or management. A management
skipping to change at line 2124 skipping to change at line 2113
if "rules" in kwargs: if "rules" in kwargs:
data["Rules"] = kwargs["rules"] data["Rules"] = kwargs["rules"]
function = "acl/update" function = "acl/update"
res = _query( res = _query(
consul_url=consul_url, token=token, data=data, method="PUT", function=fu nction consul_url=consul_url, token=token, data=data, method="PUT", function=fu nction
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "ACL {0} created.".format(kwargs["name"]) ret["message"] = "ACL {} created.".format(kwargs["name"])
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Adding ACL " "{0} failed.".format(kwargs["name"]) ret["message"] = "Adding ACL " "{} failed.".format(kwargs["name"])
return ret return ret
def acl_delete(consul_url=None, token=None, **kwargs): def acl_delete(consul_url=None, token=None, **kwargs):
""" """
Delete an ACL token. Delete an ACL token.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:param id: Unique identifier for the ACL to update. :param id: Unique identifier for the ACL to update.
:return: Boolean & message of success or failure. :return: Boolean & message of success or failure.
skipping to change at line 2161 skipping to change at line 2150
log.error("No Consul URL found.") log.error("No Consul URL found.")
ret["message"] = "No Consul URL found." ret["message"] = "No Consul URL found."
ret["res"] = False ret["res"] = False
return ret return ret
if "id" not in kwargs: if "id" not in kwargs:
ret["message"] = 'Required parameter "id" is missing.' ret["message"] = 'Required parameter "id" is missing.'
ret["res"] = False ret["res"] = False
return ret return ret
function = "acl/delete/{0}".format(kwargs["id"]) function = "acl/delete/{}".format(kwargs["id"])
res = _query( res = _query(
consul_url=consul_url, token=token, data=data, method="PUT", function=fu nction consul_url=consul_url, token=token, data=data, method="PUT", function=fu nction
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "ACL {0} deleted.".format(kwargs["id"]) ret["message"] = "ACL {} deleted.".format(kwargs["id"])
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Removing ACL " "{0} failed.".format(kwargs["id"]) ret["message"] = "Removing ACL " "{} failed.".format(kwargs["id"])
return ret return ret
def acl_info(consul_url=None, **kwargs): def acl_info(consul_url=None, **kwargs):
""" """
Information about an ACL token. Information about an ACL token.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:param id: Unique identifier for the ACL to update. :param id: Unique identifier for the ACL to update.
:return: Information about the ACL requested. :return: Information about the ACL requested.
skipping to change at line 2205 skipping to change at line 2194
log.error("No Consul URL found.") log.error("No Consul URL found.")
ret["message"] = "No Consul URL found." ret["message"] = "No Consul URL found."
ret["res"] = False ret["res"] = False
return ret return ret
if "id" not in kwargs: if "id" not in kwargs:
ret["message"] = 'Required parameter "id" is missing.' ret["message"] = 'Required parameter "id" is missing.'
ret["res"] = False ret["res"] = False
return ret return ret
function = "acl/info/{0}".format(kwargs["id"]) function = "acl/info/{}".format(kwargs["id"])
ret = _query(consul_url=consul_url, data=data, method="GET", function=functi on) ret = _query(consul_url=consul_url, data=data, method="GET", function=functi on)
return ret return ret
def acl_clone(consul_url=None, token=None, **kwargs): def acl_clone(consul_url=None, token=None, **kwargs):
""" """
Information about an ACL token. Information about an ACL token.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:param id: Unique identifier for the ACL to update. :param id: Unique identifier for the ACL to update.
:return: Boolean, message of success or :return: Boolean, message of success or
skipping to change at line 2240 skipping to change at line 2229
log.error("No Consul URL found.") log.error("No Consul URL found.")
ret["message"] = "No Consul URL found." ret["message"] = "No Consul URL found."
ret["res"] = False ret["res"] = False
return ret return ret
if "id" not in kwargs: if "id" not in kwargs:
ret["message"] = 'Required parameter "id" is missing.' ret["message"] = 'Required parameter "id" is missing.'
ret["res"] = False ret["res"] = False
return ret return ret
function = "acl/clone/{0}".format(kwargs["id"]) function = "acl/clone/{}".format(kwargs["id"])
res = _query( res = _query(
consul_url=consul_url, token=token, data=data, method="PUT", function=fu nction consul_url=consul_url, token=token, data=data, method="PUT", function=fu nction
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "ACL {0} cloned.".format(kwargs["name"]) ret["message"] = "ACL {} cloned.".format(kwargs["name"])
ret["ID"] = ret["data"] ret["ID"] = ret["data"]
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Cloning ACL" "item {0} failed.".format(kwargs["name"]) ret["message"] = "Cloning ACL" "item {} failed.".format(kwargs["name"])
return ret return ret
def acl_list(consul_url=None, token=None, **kwargs): def acl_list(consul_url=None, token=None, **kwargs):
""" """
List the ACL tokens. List the ACL tokens.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:return: List of ACLs :return: List of ACLs
CLI Example: CLI Example:
skipping to change at line 2333 skipping to change at line 2322
if "node" in kwargs: if "node" in kwargs:
query_params = kwargs["node"] query_params = kwargs["node"]
if "service" in kwargs: if "service" in kwargs:
query_params = kwargs["service"] query_params = kwargs["service"]
if "tag" in kwargs: if "tag" in kwargs:
query_params = kwargs["tag"] query_params = kwargs["tag"]
function = "event/fire/{0}".format(name) function = "event/fire/{}".format(name)
res = _query( res = _query(
consul_url=consul_url, consul_url=consul_url,
token=token, token=token,
query_params=query_params, query_params=query_params,
method="PUT", method="PUT",
function=function, function=function,
) )
if res["res"]: if res["res"]:
ret["res"] = True ret["res"] = True
ret["message"] = "Event {0} fired.".format(name) ret["message"] = "Event {} fired.".format(name)
ret["data"] = ret["data"] ret["data"] = ret["data"]
else: else:
ret["res"] = False ret["res"] = False
ret["message"] = "Cloning ACL" "item {0} failed.".format(kwargs["name"]) ret["message"] = "Cloning ACL" "item {} failed.".format(kwargs["name"])
return ret return ret
def event_list(consul_url=None, token=None, **kwargs): def event_list(consul_url=None, token=None, **kwargs):
""" """
List the recent events. List the recent events.
:param consul_url: The Consul server URL. :param consul_url: The Consul server URL.
:param name: The name of the event to fire. :param name: The name of the event to fire.
:return: List of ACLs :return: List of ACLs
 End of changes. 85 change blocks. 
93 lines changed or deleted 83 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)