Action Classes

See also

It is important to note that each action has a do_action() method, which accepts no arguments. This is the means by which all actions are executed.

Alias

class curator.actions.Alias(name=None, extra_settings={}, **kwargs)

Define the Alias object.

Parameters:
actions

The list of actions to perform. Populated by curator.actions.Alias.add and curator.actions.Alias.remove

add(ilo, warn_if_no_indices=False)

Create add statements for each index in ilo for alias, then append them to actions. Add any extras that may be there.

Parameters:

ilo – A curator.indexlist.IndexList object

body()

Return a body string suitable for use with the update_aliases API call.

client

Instance variable. The Elasticsearch Client object derived from ilo

do_action()

Run the API call update_aliases with the results of body()

do_dry_run()

Log what the output would be, but take no action.

extra_settings

Instance variable. Any extra things to add to the alias, like filters, or routing.

name

Instance variable The strftime parsed version of name.

remove(ilo, warn_if_no_indices=False)

Create remove statements for each index in ilo for alias, then append them to actions.

Parameters:

ilo – A curator.indexlist.IndexList object

warn_if_no_indices

Instance variable. Preset default value to False.

Allocation

class curator.actions.Allocation(ilo, key=None, value=None, allocation_type='require', wait_for_completion=False, wait_interval=3, max_wait=-1)
Parameters:
  • ilo – A curator.indexlist.IndexList object

  • key – An arbitrary metadata attribute key. Must match the key assigned to at least some of your nodes to have any effect.

  • value – An arbitrary metadata attribute value. Must correspond to values associated with key assigned to at least some of your nodes to have any effect. If a None value is provided, it will remove any setting associated with that key.

  • allocation_type – Type of allocation to apply. Default is require

  • wait_for_completion (bool) – Wait (or not) for the operation to complete before returning. (default: False)

  • wait_interval – How long in seconds to wait between checks for completion.

  • max_wait – Maximum number of seconds to wait_for_completion

client

Instance variable. The Elasticsearch Client object derived from ilo

do_action()

Change allocation settings for indices in index_list.indices with the settings in body.

do_dry_run()

Log what the output would be, but take no action.

index_list

Instance variable. Internal reference to ilo

max_wait

Instance variable. How long in seconds to wait_for_completion before returning with an exception. A value of -1 means wait forever.

wait_interval

Instance variable How many seconds to wait between checks for completion.

wfc

Instance variable. Internal reference to wait_for_completion

Close

class curator.actions.Close(ilo, delete_aliases=False, skip_flush=False, ignore_sync_failures=False)
Parameters:
  • ilo – A curator.indexlist.IndexList object

  • delete_aliases (bool) – If True, will delete any associated aliases before closing indices.

  • skip_flush (bool) – If True, will not flush indices before closing.

  • ignore_sync_failures (bool) – If True, will not fail if there are failures while attempting a synced flush.

client

Instance variable. The Elasticsearch Client object derived from ilo

delete_aliases

Instance variable. Internal reference to delete_aliases

do_action()

Close open indices in index_list.indices

do_dry_run()

Log what the output would be, but take no action.

ignore_sync_failures

Instance variable. Internal reference to ignore_sync_failures

index_list

Instance variable. Internal reference to ilo

skip_flush

Instance variable. Internal reference to skip_flush

ClusterRouting

class curator.actions.ClusterRouting(client, routing_type=None, setting=None, value=None, wait_for_completion=False, wait_interval=9, max_wait=-1)

For now, the cluster routing settings are hardcoded to be transient

Parameters:
  • client – An elasticsearch.Elasticsearch client object

  • routing_type – Type of routing to apply. Either allocation or rebalance

  • setting – Currently, the only acceptable value for setting is enable. This is here in case that changes.

  • value – Used only if setting is enable. Semi-dependent on routing_type. Acceptable values for allocation and rebalance are all, primaries, and none (string, not NoneType). If routing_type is allocation, this can also be new_primaries, and if rebalance, it can be replicas.

  • wait_for_completion (bool) – Wait (or not) for the operation to complete before returning. (default: False)

  • wait_interval – How long in seconds to wait between checks for completion.

  • max_wait – Maximum number of seconds to wait_for_completion

client

Instance variable. An elasticsearch.Elasticsearch client object

do_action()

Change cluster routing settings with the settings in body.

do_dry_run()

Log what the output would be, but take no action.

max_wait

Instance variable. How long in seconds to wait_for_completion before returning with an exception. A value of -1 means wait forever.

wait_interval

Instance variable How many seconds to wait between checks for completion.

wfc

Instance variable. Internal reference to wait_for_completion

CreateIndex

class curator.actions.CreateIndex(client, name, extra_settings={}, ignore_existing=False)
Parameters:
body

Instance variable. Extracted from the action yaml, it should be a dictionary of mappings and settings suitable for index creation.

client

Instance variable. An elasticsearch.Elasticsearch client object

do_action()

Create index identified by name with settings in body

do_dry_run()

Log what the output would be, but take no action.

ignore_existing

Instance variable. Extracted from the action yaml, it should be a boolean informing whether to ignore the error if the index already exists.

name

Instance variable. The parsed version of name

DeleteIndices

class curator.actions.DeleteIndices(ilo, master_timeout=30)
Parameters:
client

Instance variable. The Elasticsearch Client object derived from ilo

do_action()

Delete indices in index_list.indices

do_dry_run()

Log what the output would be, but take no action.

index_list

Instance variable. Internal reference to ilo

master_timeout

Instance variable. String value of master_timeout + ‘s’, for seconds.

DeleteSnapshots

class curator.actions.DeleteSnapshots(slo, retry_interval=120, retry_count=3)
Parameters:
  • slo – A curator.snapshotlist.SnapshotList object

  • retry_interval – Number of seconds to delay betwen retries. Default: 120 (seconds)

  • retry_count – Number of attempts to make. Default: 3

client

Instance variable. The Elasticsearch Client object derived from slo

do_action()

Delete snapshots in slo Retry up to retry_count times, pausing retry_interval seconds between retries.

do_dry_run()

Log what the output would be, but take no action.

repository

Instance variable. The repository name derived from slo

retry_count

Instance variable. Internally accessible copy of retry_count

retry_interval

Instance variable. Internally accessible copy of retry_interval

snapshot_list

Instance variable. Internal reference to slo

ForceMerge

class curator.actions.ForceMerge(ilo, max_num_segments=None, delay=0)
Parameters:
  • ilo – A curator.indexlist.IndexList object

  • max_num_segments – Number of segments per shard to forceMerge

  • delay – Number of seconds to delay between forceMerge operations

client

Instance variable. The Elasticsearch Client object derived from ilo

delay

Instance variable. Internally accessible copy of delay

do_action()

forcemerge indices in index_list.indices

do_dry_run()

Log what the output would be, but take no action.

index_list

Instance variable. Internal reference to ilo

max_num_segments

Instance variable. Internally accessible copy of max_num_segments

IndexSettings

class curator.actions.IndexSettings(ilo, index_settings={}, ignore_unavailable=False, preserve_existing=False)
Parameters:
  • ilo – A curator.indexlist.IndexList object

  • index_settings – A dictionary structure with one or more index settings to change.

  • ignore_unavailable – Whether specified concrete indices should be ignored when unavailable (missing or closed)

  • preserve_existing – Whether to update existing settings. If set to True existing settings on an index remain unchanged. The default is False

body

Instance variable. Internal reference to index_settings

client

Instance variable. The Elasticsearch Client object derived from ilo

do_dry_run()

Log what the output would be, but take no action.

ignore_unavailable

Instance variable. Internal reference to ignore_unavailable

index_list

Instance variable. Internal reference to ilo

preserve_existing

Instance variable. Internal reference to preserve_settings

Open

class curator.actions.Open(ilo)
Parameters:

ilo – A curator.indexlist.IndexList object

client

Instance variable. The Elasticsearch Client object derived from ilo

do_action()

Open closed indices in index_list.indices

do_dry_run()

Log what the output would be, but take no action.

index_list

Instance variable. Internal reference to ilo

Reindex

class curator.actions.Reindex(ilo, request_body, refresh=True, requests_per_second=-1, slices=1, timeout=60, wait_for_active_shards=1, wait_for_completion=True, max_wait=-1, wait_interval=9, remote_url_prefix=None, remote_ssl_no_validate=None, remote_certificate=None, remote_client_cert=None, remote_client_key=None, remote_aws_key=None, remote_aws_secret_key=None, remote_aws_region=None, remote_filters={}, migration_prefix='', migration_suffix='')
Parameters:
  • ilo – A curator.indexlist.IndexList object

  • request_body – The body to send to elasticsearch.Elasticsearch.reindex(), which must be complete and usable, as Curator will do no vetting of the request_body. If it fails to function, Curator will return an exception.

  • refresh (bool) – Whether to refresh the entire target index after the operation is complete. (default: True)

  • requests_per_second – The throttle to set on this request in sub-requests per second. -1 means set no throttle as does unlimited which is the only non-float this accepts. (default: -1)

  • slices – The number of slices this task should be divided into. 1 means the task will not be sliced into subtasks. (default: 1)

  • timeout – The length in seconds each individual bulk request should wait for shards that are unavailable. (default: 60)

  • wait_for_active_shards – Sets the number of shard copies that must be active before proceeding with the reindex operation. (default: 1) means the primary shard only. Set to all for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)

  • wait_for_completion (bool) – Wait (or not) for the operation to complete before returning. (default: True)

  • wait_interval – How long in seconds to wait between checks for completion.

  • max_wait – Maximum number of seconds to wait_for_completion

  • remote_url_prefix (str) – Optional url prefix, if needed to reach the Elasticsearch API (i.e., it’s not at the root level)

  • remote_ssl_no_validate (bool) – If True, do not validate the certificate chain. This is an insecure option and you will see warnings in the log output.

  • remote_certificate – Path to SSL/TLS certificate

  • remote_client_cert – Path to SSL/TLS client certificate (public key)

  • remote_client_key – Path to SSL/TLS private key

  • remote_aws_key – AWS IAM Access Key (Only used if the requests-aws4auth python module is installed)

  • remote_aws_secret_key – AWS IAM Secret Access Key (Only used if the requests-aws4auth python module is installed)

  • remote_aws_region – AWS Region (Only used if the requests-aws4auth python module is installed)

  • remote_filters – Apply these filters to the remote client for remote index selection.

  • migration_prefix – When migrating, prepend this value to the index name.

  • migration_suffix – When migrating, append this value to the index name.

body

Instance variable. Internal reference to request_body

client

Instance variable. The Elasticsearch Client object derived from ilo

do_action()

Execute elasticsearch.Elasticsearch.reindex() operation with the provided request_body and arguments.

do_dry_run()

Log what the output would be, but take no action.

get_processed_items(task_id)

This function calls client.tasks.get with the provided task_id. It will get the value from 'response.total' as the total number of elements processed during reindexing. If the value is not found, it will return -1

Parameters:

task_id – A task_id which ostensibly matches a task searchable in the tasks API.

index_list

Instance variable. Internal reference to ilo

max_wait

Instance variable. How long in seconds to wait_for_completion before returning with an exception. A value of -1 means wait forever.

mpfx

Instance variable. Internal reference to migration_prefix

msfx

Instance variable. Internal reference to migration_suffix

refresh

Instance variable. Internal reference to refresh

requests_per_second

Instance variable. Internal reference to requests_per_second

show_run_args(source, dest)

Show what will run

slices

Instance variable. Internal reference to slices

timeout

Instance variable. Internal reference to timeout, and add “s” for seconds.

wait_for_active_shards

Instance variable. Internal reference to wait_for_active_shards

wait_interval

Instance variable How many seconds to wait between checks for completion.

wfc

Instance variable. Internal reference to wait_for_completion

Replicas

class curator.actions.Replicas(ilo, count=None, wait_for_completion=False, wait_interval=9, max_wait=-1)
Parameters:
  • ilo – A curator.indexlist.IndexList object

  • count – The count of replicas per shard

  • wait_for_completion (bool) – Wait (or not) for the operation to complete before returning. (default: False)

  • wait_interval – How long in seconds to wait between checks for completion.

  • max_wait – Maximum number of seconds to wait_for_completion

client

Instance variable. The Elasticsearch Client object derived from ilo

count

Instance variable. Internally accessible copy of count

do_action()

Update the replica count of indices in index_list.indices

do_dry_run()

Log what the output would be, but take no action.

index_list

Instance variable. Internal reference to ilo

max_wait

Instance variable. How long in seconds to wait_for_completion before returning with an exception. A value of -1 means wait forever.

wait_interval

Instance variable How many seconds to wait between checks for completion.

wfc

Instance variable. Internal reference to wait_for_completion

Restore

class curator.actions.Restore(slo, name=None, indices=None, include_aliases=False, ignore_unavailable=False, include_global_state=False, partial=False, rename_pattern=None, rename_replacement=None, extra_settings={}, wait_for_completion=True, wait_interval=9, max_wait=-1, skip_repo_fs_check=False)
Parameters:
  • slo – A curator.snapshotlist.SnapshotList object

  • name (str) – Name of the snapshot to restore. If no name is provided, it will restore the most recent snapshot by age.

  • indices (list) – A list of indices to restore. If no indices are provided, it will restore all indices in the snapshot.

  • include_aliases (bool) – If set to True, restore aliases with the indices. (default: False)

  • ignore_unavailable (bool) – Ignore unavailable shards/indices. (default: False)

  • include_global_state (bool) – Restore cluster global state with snapshot. (default: False)

  • partial (bool) – Do not fail if primary shard is unavailable. (default: False)

  • rename_pattern (str) – A regular expression pattern with one or more captures, e.g. index_(.+)

  • rename_replacement (str) – A target index name pattern with $# numbered references to the captures in rename_pattern, e.g. restored_index_$1

  • extra_settings (dict, representing the settings.) – Extra settings, including shard count and settings to omit. For more information see https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_changing_index_settings_during_restore

  • wait_for_completion (bool) – Wait (or not) for the operation to complete before returning. (default: True)

  • wait_interval – How long in seconds to wait between checks for completion.

  • max_wait – Maximum number of seconds to wait_for_completion

  • skip_repo_fs_check (bool) – Do not validate write access to repository on all cluster nodes before proceeding. (default: False). Useful for shared filesystems where intermittent timeouts can affect validation, but won’t likely affect snapshot success.

body

Instance variable. Populated at instance creation time from the other options

client

Instance variable. The Elasticsearch Client object derived from slo

do_action()

Restore indices with options passed.

do_dry_run()

Log what the output would be, but take no action.

max_wait

Instance variable. How long in seconds to wait_for_completion before returning with an exception. A value of -1 means wait forever.

name

Instance variable. Will use a provided snapshot name, or the most recent snapshot in slo

py_rename_replacement

Also an instance variable version of rename_replacement but with Java regex group designations of $# converted to Python’s \\# style.

rename_pattern

Instance variable version of rename_pattern

rename_replacement

Instance variable version of rename_replacement

report_state()

Log the state of the restore This should only be done if wait_for_completion is True, and only after completing the restore.

repository

Instance variable. repository derived from slo

skip_repo_fs_check

Instance variable. Internally accessible copy of skip_repo_fs_check

snapshot_list

Instance variable. Internal reference to slo

wait_interval

Instance variable How many seconds to wait between checks for completion.

Rollover

class curator.actions.Rollover(client, name, conditions, new_index=None, extra_settings=None, wait_for_active_shards=1)
Parameters:
  • client – An elasticsearch.Elasticsearch client object

  • name – The name of the single-index-mapped alias to test for rollover conditions.

  • conditions – A dictionary of conditions to test

  • extra_settings – Must be either None, or a dictionary of settings to apply to the new index on rollover. This is used in place of settings in the Rollover API, mostly because it’s already existent in other places here in Curator

  • wait_for_active_shards – The number of shards expected to be active before returning.

New_index:

The new index name

body()

Create a body from conditions and settings

client

Instance variable. The Elasticsearch Client object

conditions

Instance variable. Internal reference to conditions

do_action()

Rollover the index referenced by alias name

do_dry_run()

Log what the output would be, but take no action.

doit(dry_run=False)

This exists solely to prevent having to have duplicate code in both do_dry_run and do_action

log_result(result)

Log the results based on whether the index rolled over or not

new_index

Instance variable. Internal reference to new_index

settings

Instance variable. Internal reference to extra_settings

wait_for_active_shards

Instance variable. Internal reference to wait_for_active_shards

Shrink

class curator.actions.Shrink(ilo, shrink_node='DETERMINISTIC', node_filters={}, number_of_shards=1, number_of_replicas=1, shrink_prefix='', shrink_suffix='-shrink', copy_aliases=False, delete_after=True, post_allocation={}, wait_for_active_shards=1, wait_for_rebalance=True, extra_settings={}, wait_for_completion=True, wait_interval=9, max_wait=-1)
Parameters:
  • ilo – A curator.indexlist.IndexList object

  • shrink_node – The node name to use as the shrink target, or DETERMINISTIC, which will use the values in node_filters to determine which node will be the shrink node.

  • node_filters (dict, representing the filters) – If the value of shrink_node is DETERMINISTIC, the values in node_filters will be used while determining which node to allocate the shards on before performing the shrink.

  • number_of_shards – The number of shards the shrunk index should have

  • number_of_replicas – The number of replicas for the shrunk index

  • shrink_prefix – Prepend the shrunk index with this value

  • shrink_suffix – Append the value to the shrunk index (default: -shrink)

  • copy_aliases (bool) – Whether to copy each source index aliases to target index after shrinking. the aliases will be added to target index and deleted from source index at the same time(default: False)

  • delete_after (bool) – Whether to delete each index after shrinking. (default: True)

  • post_allocation (dict, with keys allocation_type, key, and value) – If populated, the allocation_type, key, and value will be applied to the shrunk index to re-route it.

  • wait_for_active_shards – The number of shards expected to be active before returning.

  • extra_settings (dict) – Permitted root keys are settings and aliases. See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-shrink-index.html

  • wait_for_rebalance (bool) – Wait for rebalance. (default: True)

  • wait_for_active_shards – Wait for active shards before returning.

  • wait_for_completion (bool) – Wait (or not) for the operation to complete before returning. You should not normally change this, ever. (default: True)

  • wait_interval – How long in seconds to wait between checks for completion.

  • max_wait – Maximum number of seconds to wait_for_completion

client

Instance variable. The Elasticsearch Client object derived from ilo

copy_aliases

Instance variable. Internal reference to copy_aliases

delete_after

Instance variable. Internal reference to delete_after

do_dry_run()

Show what a regular run would do, but don’t actually do it.

index_list

Instance variable. Internal reference to ilo

max_wait

Instance variable. How long in seconds to wait_for_completion before returning with an exception. A value of -1 means wait forever.

most_available_node()

Determine which data node name has the most available free space, and meets the other node filters settings.

Parameters:

client – An elasticsearch.Elasticsearch client object

node_filters

Instance variable. Internal reference to node_filters

number_of_shards

Instance variable. Internal reference to number_of_shards

post_allocation

Instance variable. Internal reference to post_allocation

shrink_node

Instance variable. Internal reference to shrink_node

shrink_prefix

Instance variable. Internal reference to shrink_prefix

shrink_suffix

Instance variable. Internal reference to shrink_suffix

wait_for_rebalance

Instance variable. Internal reference to wait_for_rebalance

wait_interval

Instance variable. How many seconds to wait between checks for completion.

wfc

Instance variable. Internal reference to wait_for_completion

Snapshot

class curator.actions.Snapshot(ilo, repository=None, name=None, ignore_unavailable=False, include_global_state=True, partial=False, wait_for_completion=True, wait_interval=9, max_wait=-1, skip_repo_fs_check=False)
Parameters:
  • ilo – A curator.indexlist.IndexList object

  • repository – The Elasticsearch snapshot repository to use

  • name – What to name the snapshot.

  • wait_for_completion (bool) – Wait (or not) for the operation to complete before returning. (default: True)

  • wait_interval – How long in seconds to wait between checks for completion.

  • max_wait – Maximum number of seconds to wait_for_completion

  • ignore_unavailable (bool) – Ignore unavailable shards/indices. (default: False)

  • include_global_state (bool) – Store cluster global state with snapshot. (default: True)

  • partial (bool) – Do not fail if primary shard is unavailable. (default: False)

  • skip_repo_fs_check (bool) – Do not validate write access to repository on all cluster nodes before proceeding. (default: False). Useful for shared filesystems where intermittent timeouts can affect validation, but won’t likely affect snapshot success.

body

Instance variable. Populated at instance creation time by calling curator.utils.utils.create_snapshot_body with ilo.indices and the provided arguments: ignore_unavailable, include_global_state, partial

client

Instance variable. The Elasticsearch Client object derived from ilo

do_action()

Snapshot indices in index_list.indices, with options passed.

do_dry_run()

Log what the output would be, but take no action.

get_state()

Get the state of the snapshot

index_list

Instance variable. Internal reference to ilo

max_wait

Instance variable. How long in seconds to wait_for_completion before returning with an exception. A value of -1 means wait forever.

name

Instance variable. The parsed version of name

report_state()

Log the state of the snapshot and raise an exception if the state is not SUCCESS

repository

Instance variable. Internally accessible copy of repository

skip_repo_fs_check

Instance variable. Internally accessible copy of skip_repo_fs_check

wait_for_completion

Instance variable. Internally accessible copy of wait_for_completion

wait_interval

Instance variable How many seconds to wait between checks for completion.