Saltstack module consul 详解

consul.session_create

Used to create a session.

:param consul_url: The Consul server URL.
:param lockdelay: Duration string using a "s" suffix for seconds.
                  The default is 15s.
:param node: Must refer to a node that is already registered,
             if specified. By default, the agent's own node
             name is used.
:param name: A human-readable name for the session
:param checks: A list of associated health checks. It is highly
               recommended that, if you override this list, you
               include the default "serfHealth".
:param behavior: Can be set to either release or delete. This controls
                 the behavior when a session is invalidated. By default,
                 this is release, causing any locks that are held to be
                 released. Changing this to delete causes any locks that
                 are held to be deleted. delete is useful for creating
                 ephemeral key/value entries.
:param ttl: Session is invalidated if it is not renewed before
            the TTL expires
:return: Boolean and message indicating success or failure.

CLI Example:

    salt '*' consul.session_create node='node1' name='my-session' behavior='delete' ttl='3600s'

consul.catalog_service

Information about the registered service.

:param consul_url: The Consul server URL.
:param dc: By default, the datacenter of the agent is queried;
           however, the dc can be provided using the "dc" parameter.
:param tag: Filter returned services with tag parameter.
:return: Information about the requested service.

CLI Example:

    salt '*' consul.catalog_service service='redis'

consul.put

Put values into Consul

:param consul_url: The Consul server URL.
:param key: The key to use as the starting point for the list.
:param value: The value to set the key to.
:param flags: This can be used to specify an unsigned value
              between 0 and 2^64-1. Clients can choose to use
              this however makes sense for their application.
:param cas: This flag is used to turn the PUT into a
            Check-And-Set operation.
:param acquire: This flag is used to turn the PUT into a
                lock acquisition operation.
:param release: This flag is used to turn the PUT into a
                lock release operation.
:return: Boolean & message of success or failure.

CLI Example:

    salt '*' consul.put key='web/key1' value="Hello there"

    salt '*' consul.put key='web/key1' value="Hello there" acquire='d5d371f4-c380-5280-12fd-8810be175592'

    salt '*' consul.put key='web/key1' value="Hello there" release='d5d371f4-c380-5280-12fd-8810be175592'

consul.acl_create

Create a new ACL token.

:param consul_url: The Consul server URL.
:param name: Meaningful indicator of the ACL's purpose.
:param type: Type is either client or management. A management
             token is comparable to a root user and has the
             ability to perform any action including creating,
             modifying, and deleting ACLs.
:param rules: The Consul server URL.
:return: Boolean & message of success or failure.

CLI Example:

    salt '*' consul.acl_create

consul.health_checks

Health information about the registered service.

:param consul_url: The Consul server URL.
:param service: The service to request health information about.
:param dc: By default, the datacenter of the agent is queried;
           however, the dc can be provided using the "dc" parameter.
:return: Health information about the requested node.

CLI Example:

    salt '*' consul.health_checks service='redis1'

consul.event_list

List the recent events.

:param consul_url: The Consul server URL.
:param name: The name of the event to fire.
:return: List of ACLs

CLI Example:

    salt '*' consul.event_list

consul.catalog_nodes

Return list of available nodes from catalog.

:param consul_url: The Consul server URL.
:param dc: By default, the datacenter of the agent is queried;
           however, the dc can be provided using the "dc" parameter.
:return: The list of available nodes.

CLI Example:

    salt '*' consul.catalog_nodes

consul.acl_info

Information about an ACL token.

:param consul_url: The Consul server URL.
:param id: Unique identifier for the ACL to update.
:return: Information about the ACL requested.

CLI Example:

    salt '*' consul.acl_info id='c1c4d223-91cb-3d1f-1ee8-f2af9e7b6716'

consul.session_info

Information about a session

:param consul_url: The Consul server URL.
:param session: The ID of the session to return information about.
:param dc: By default, the datacenter of the agent is queried;
           however, the dc can be provided using the "dc" parameter.
:return: Boolean & message of success or failure.

CLI Example:

    salt '*' consul.session_info session='c1c4d223-91cb-3d1f-1ee8-f2af9e7b6716'

consul.agent_check_fail

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
TTL clock is reset.

:param consul_url: The Consul server URL.
:param checkid: The ID of the check to deregister from Consul.
:param note: A human-readable message with the status of the check.
:return: Boolean and message indicating success or failure.

CLI Example:

    salt '*' consul.agent_check_fail checkid='redis_check1' note='Forcing check into critical state.'

consul.agent_join

Triggers the local agent to join a node

:param consul_url: The Consul server URL.
:param address: The address for the agent to connect to.
:param wan: Causes the agent to attempt to join using the WAN pool.
:return: Boolean and message indicating success or failure.

CLI Example:

    salt '*' consul.agent_join address='192.168.1.1'

consul.agent_members

Returns the members as seen by the local serf agent

:param consul_url: The Consul server URL.
:return: Returns the members as seen by the local serf agent

CLI Example:

    salt '*' consul.agent_members

consul.agent_check_warn

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
clock is reset.

:param consul_url: The Consul server URL.
:param checkid: The ID of the check to deregister from Consul.
:param note: A human-readable message with the status of the check.
:return: Boolean and message indicating success or failure.

CLI Example:

    salt '*' consul.agent_check_warn checkid='redis_check1' note='Forcing check into warning state.'

consul.agent_services

Returns the services the local agent is managing

:param consul_url: The Consul server URL.
:return: Returns the services the local agent is managing

CLI Example:

    salt '*' consul.agent_services

consul.session_destroy

Destroy session

:param consul_url: The Consul server URL.
:param session: The ID of the session to destroy.
:param dc: By default, the datacenter of the agent is queried;
           however, the dc can be provided using the "dc" parameter.
:return: Boolean & message of success or failure.

CLI Example:

    salt '*' consul.session_destroy session='c1c4d223-91cb-3d1f-1ee8-f2af9e7b6716'

consul.catalog_deregister

Deregisters a node, service, or check

:param consul_url: The Consul server URL.
:param node: The node to deregister.
:param datacenter: By default, the datacenter of the agent is queried;
           however, the dc can be provided using the "dc" parameter.
:param checkid: The ID of the health check to deregister.
:param serviceid: The ID of the service to deregister.
:return: Boolean & message of success or failure.

CLI Example:

    salt '*' consul.catalog_register node='node1' serviceid='redis_server1' checkid='redis_check1'

consul.agent_service_register

The used to add a new service, with an optional
health check, to the local agent.

:param consul_url: The Consul server URL.
:param name: A name describing the service.
:param address: The address used by the service, defaults
                to the address of the agent.
:param port: The port used by the service.
:param id: Unique ID to identify the service, if not
           provided the value of the name parameter is used.
:param tags: Identifying tags for service, string or list.
:param script: If script is provided, the check type is
               a script, and Consul will evaluate that script
               based on the interval parameter.
:param http: Check will perform an HTTP GET request against
             the value of HTTP (expected to be a URL) based
             on the interval parameter.
:param check_ttl: If a TTL type is used, then the TTL update
                  endpoint must be used periodically to update
                  the state of the check.
:param check_interval: Interval at which the check should run.
:return: Boolean and message indicating success or failure.

CLI Example:

    salt '*' consul.agent_service_register name='redis' tags='["master", "v1"]' address="127.0.0.1" port="8080" check_script="/usr/local/bin/check_redis.py" interval="10s"

consul.event_fire

List the ACL tokens.

:param consul_url: The Consul server URL.
:param name: The name of the event to fire.
:param dc: By default, the datacenter of the agent is queried;
           however, the dc can be provided using the "dc" parameter.
:param node: Filter by node name.
:param service: Filter by service name.
:param tag: Filter by tag name.
:return: List of ACLs

CLI Example:

    salt '*' consul.event_fire name='deploy'

consul.catalog_datacenters

Return list of available datacenters from catalog.

:param consul_url: The Consul server URL.
:return: The list of available datacenters.

CLI Example:

    salt '*' consul.catalog_datacenters

consul.health_service

Health information about the registered service.

:param consul_url: The Consul server URL.
:param service: The service to request health information about.
:param dc: By default, the datacenter of the agent is queried;
           however, the dc can be provided using the "dc" parameter.
:param tag: Filter returned services with tag parameter.
:param passing: Filter results to only nodes with all
                checks in the passing state.
:return: Health information about the requested node.

CLI Example:

    salt '*' consul.health_service service='redis1'

    salt '*' consul.health_service service='redis1' passing='True'

consul.agent_check_deregister

The agent will take care of deregistering the check from the Catalog.

:param consul_url: The Consul server URL.
:param checkid: The ID of the check to deregister from Consul.
:return: Boolean and message indicating success or failure.

CLI Example:

    salt '*' consul.agent_check_deregister checkid='Memory Utilization'

consul.health_node

Health information about the registered node.

:param consul_url: The Consul server URL.
:param node: The node to request health information about.
:param dc: By default, the datacenter of the agent is queried;
           however, the dc can be provided using the "dc" parameter.
:return: Health information about the requested node.

CLI Example:

    salt '*' consul.health_node node='node1'

consul.agent_check_pass

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
clock is reset.

:param consul_url: The Consul server URL.
:param checkid: The ID of the check to mark as passing.
:param note: A human-readable message with the status of the check.
:return: Boolean and message indicating success or failure.

CLI Example:

    salt '*' consul.agent_check_pass checkid='redis_check1' note='Forcing check into passing state.'

consul.delete

Delete values from Consul

:param consul_url: The Consul server URL.
: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 cas: This flag is used to turn the DELETE into
            a Check-And-Set operation.
:return: Boolean & message of success or failure.

CLI Example:

    salt '*' consul.delete key='web'
    salt '*' consul.delete key='web' recurse='True'

consul.status_peers

Returns the current Raft peer set

:param consul_url: The Consul server URL.
:return: Retrieves the Raft peers for the
         datacenter in which the agent is running.

CLI Example:

    salt '*' consul.status_peers

consul.catalog_register

Registers a new node, service, or check

:param consul_url: The Consul server URL.
:param dc: By default, the datacenter of the agent is queried;
           however, the dc can be provided using the "dc" parameter.
:param node: The node to register.
:param address: The address of the node.
:param service: The service that will be registered.
:param service_address: The address that the service listens on.
:param service_port: The port for the service.
:param service_id: A unique identifier for the service, if this is not
                   provided "name" will be used.
:param service_tags: Any tags associated with the service.
:param check: The name of the health check to register
:param check_status: The initial status of the check,
                     must be one of unknown, passing, warning, or critical.
:param check_service: The service that the check is performed against.
:param check_id: Unique identifier for the service.
:param check_notes: An opaque field that is meant to hold human-readable text.
:return: Boolean & message of success or failure.

CLI Example:

    salt '*' consul.catalog_register node='node1' address='192.168.1.1' service='redis' service_address='127.0.0.1' service_port='8080' service_id='redis_server1'

consul.agent_self

Returns the local node configuration

:param consul_url: The Consul server URL.
:return: Returns the local node configuration

CLI Example:

    salt '*' consul.agent_self

consul.acl_delete

Delete an ACL token.

:param consul_url: The Consul server URL.
:param id: Unique identifier for the ACL to update.
:return: Boolean & message of success or failure.

CLI Example:

    salt '*' consul.acl_delete id='c1c4d223-91cb-3d1f-1ee8-f2af9e7b6716'

consul.health_state

Returns the checks in the state provided on the path.

:param consul_url: The Consul server URL.
:param state: The state to show checks for. The supported states
              are any, unknown, passing, warning, or critical.
              The any state is a wildcard that can be used to
              return all checks.
:param dc: By default, the datacenter of the agent is queried;
           however, the dc can be provided using the "dc" parameter.
:return: The checks in the provided state.

CLI Example:

    salt '*' consul.health_state state='redis1'

    salt '*' consul.health_state service='redis1' passing='True'

consul.status_leader

Returns the current Raft leader

:param consul_url: The Consul server URL.
:return: The address of the Raft leader.

CLI Example:

    salt '*' consul.status_leader

consul.agent_leave

Used to instruct the agent to force a node into the left state.

:param consul_url: The Consul server URL.
:param node: The node the agent will force into left state
:return: Boolean and message indicating success or failure.

CLI Example:

    salt '*' consul.agent_leave node='web1.example.com'

consul.agent_service_deregister

Used to remove a service.

:param consul_url: The Consul server URL.
:param serviceid: A serviceid describing the service.
:return: Boolean and message indicating success or failure.

CLI Example:

    salt '*' consul.agent_service_deregister serviceid='redis'

consul.agent_maintenance

Manages node maintenance mode

:param consul_url: The Consul server URL.
:param enable: The enable flag is required.
               Acceptable values are either true
               (to enter maintenance mode) or
               false (to resume normal operation).
:param reason: If provided, its value should be a
               text string explaining the reason for
               placing the node into maintenance mode.
:return: Boolean and message indicating success or failure.

CLI Example:

    salt '*' consul.agent_maintenance enable='False' reason='Upgrade in progress'

consul.catalog_node

Information about the registered node.

:param consul_url: The Consul server URL.
:param node: The node to request information about.
:param dc: By default, the datacenter of the agent is queried;
           however, the dc can be provided using the "dc" parameter.
:return: Information about the requested node.

CLI Example:

    salt '*' consul.catalog_service service='redis'

consul.catalog_services

Return list of available services rom catalog.

:param consul_url: The Consul server URL.
:param dc: By default, the datacenter of the agent is queried;
           however, the dc can be provided using the "dc" parameter.
:return: The list of available services.

CLI Example:

    salt '*' consul.catalog_services

consul.agent_checks

Returns the checks the local agent is managing

:param consul_url: The Consul server URL.
:return: Returns the checks the local agent is managing

CLI Example:

    salt '*' consul.agent_checks

consul.acl_list

List the ACL tokens.

:param consul_url: The Consul server URL.
:return: List of ACLs

CLI Example:

    salt '*' consul.acl_list

consul.acl_clone

Information about an ACL token.

:param consul_url: The Consul server URL.
:param id: Unique identifier for the ACL to update.
:return: Boolean, message of success or
         failure, and new ID of cloned ACL.

CLI Example:

    salt '*' consul.acl_info id='c1c4d223-91cb-3d1f-1ee8-f2af9e7b6716'

consul.agent_check_register

The register endpoint is used to add a new check to the local agent.

:param consul_url: The Consul server URL.
:param name: The description of what the check is for.
:param id: The unique name to use for the check, if not
           provided 'name' is used.
:param notes: Human readable description of the check.
:param script: If script is provided, the check type is
               a script, and Consul will evaluate that script
               based on the interval parameter.
:param http: Check will perform an HTTP GET request against
             the value of HTTP (expected to be a URL) based
             on the interval parameter.
:param ttl: If a TTL type is used, then the TTL update endpoint
            must be used periodically to update the state of the check.
:param interval: Interval at which the check should run.
:return: Boolean and message indicating success or failure.

CLI Example:

    salt '*' consul.agent_check_register name='Memory Utilization' script='/usr/local/bin/check_mem.py' interval='15s'

consul.acl_update

Update an ACL token.

:param consul_url: The Consul server URL.
:param name: Meaningful indicator of the ACL's purpose.
:param id: Unique identifier for the ACL to update.
:param type: Type is either client or management. A management
             token is comparable to a root user and has the
             ability to perform any action including creating,
             modifying, and deleting ACLs.
:param rules: The Consul server URL.
:return: Boolean & message of success or failure.

CLI Example:

    salt '*' consul.acl_update

consul.session_list

Used to list sessions.

:param consul_url: The Consul server URL.
:param dc: By default, the datacenter of the agent is queried;
           however, the dc can be provided using the "dc" parameter.
:param return_list: By default, all information about the sessions is
                    returned, using the return_list parameter will return
                    a list of session IDs.
:return: A list of all available sessions.

CLI Example:

    salt '*' consul.session_list

consul.get

Get key from Consul

:param consul_url: The Consul server URL.
:param key: The key to use as the starting point for the list.
:param recurse: Return values recursively beginning at the value of key.
:param decode: By default values are stored as Base64 encoded values,
               decode will return the whole key with the value decoded.
:param raw: Simply return the decoded value of the key.
:return: The keys in Consul.

CLI Example:

    salt '*' consul.get key='web/key1'
    salt '*' consul.get key='web' recurse=True
    salt '*' consul.get key='web' recurse=True decode=True

By default values stored in Consul are base64 encoded, passing the
decode option will show them as the decoded values.

    salt '*' consul.get key='web' recurse=True decode=True raw=True

By default Consult will return other information about the key, the raw
option will return only the raw value.

consul.agent_service_maintenance

Used to place a service into maintenance mode.

:param consul_url: The Consul server URL.
:param serviceid: A name of the service.
:param enable: Whether the service should be enabled or disabled.
:param reason: A human readable message of why the service was
               enabled or disabled.
:return: Boolean and message indicating success or failure.

CLI Example:

    salt '*' consul.agent_service_deregister serviceid='redis' enable='True' reason='Down for upgrade'

consul.list

List keys in Consul

:param consul_url: The Consul server URL.
:param key: The key to use as the starting point for the list.
:return: The list of keys.

CLI Example:

    salt '*' consul.list
    salt '*' consul.list key='web'
posted @ 2020-03-28 20:28  random_lee  阅读(244)  评论(0编辑  收藏  举报