Class: Elastomer::Client::Snapshot
- Inherits:
-
Object
- Object
- Elastomer::Client::Snapshot
- Defined in:
- lib/elastomer/client/snapshot.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
-
#create(body = {}, params = {}) ⇒ Object
Create the snapshot.
-
#defaults ⇒ Object
Internal: Returns a Hash containing default parameters.
-
#delete(params = {}) ⇒ Object
Delete the snapshot.
-
#exists?(params = {}) ⇒ Boolean
(also: #exist?)
Check for the existence of the snapshot.
-
#get(params = {}) ⇒ Object
Get snapshot progress information.
-
#initialize(client, repository = nil, name = nil) ⇒ Snapshot
constructor
Create a new snapshot object for making API requests that pertain to creating, restoring, deleting, and retrieving snapshots.
-
#restore(body = {}, params = {}) ⇒ Object
Restore the snapshot.
-
#status(params = {}) ⇒ Object
Get detailed snapshot status.
-
#update_params(params, overrides = nil) ⇒ Object
Internal: Add default parameters to the ‘params` Hash and then apply `overrides` to the params if any are given.
Constructor Details
#initialize(client, repository = nil, name = nil) ⇒ Snapshot
Create a new snapshot object for making API requests that pertain to creating, restoring, deleting, and retrieving snapshots.
client - Elastomer::Client used for HTTP requests to the server repository - The name of the repository as a String. Cannot be nil if
snapshot name is not nil.
name - The name of the snapshot as a String
22 23 24 25 26 27 |
# File 'lib/elastomer/client/snapshot.rb', line 22 def initialize(client, repository = nil, name = nil) @client = client # don't allow nil repository if snapshot name is not nil @repository = @client.assert_param_presence(repository, "repository name") unless repository.nil? && name.nil? @name = @client.assert_param_presence(name, "snapshot name") unless name.nil? end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
29 30 31 |
# File 'lib/elastomer/client/snapshot.rb', line 29 def client @client end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'lib/elastomer/client/snapshot.rb', line 29 def name @name end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
29 30 31 |
# File 'lib/elastomer/client/snapshot.rb', line 29 def repository @repository end |
Instance Method Details
#create(body = {}, params = {}) ⇒ Object
Create the snapshot. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
body - The snapshot options as a Hash or a JSON encoded String params - Parameters Hash
Returns the response body as a Hash
56 57 58 59 |
# File 'lib/elastomer/client/snapshot.rb', line 56 def create(body = {}, params = {}) response = client.put "/_snapshot/{repository}/{snapshot}", update_params(params, body: body, action: "snapshot.create", rest_api: "snapshot.create") response.body end |
#defaults ⇒ Object
Internal: Returns a Hash containing default parameters.
122 123 124 |
# File 'lib/elastomer/client/snapshot.rb', line 122 def defaults { repository: repository, snapshot: name } end |
#delete(params = {}) ⇒ Object
Delete the snapshot. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
params - Parameters Hash
Returns the response body as a Hash
103 104 105 106 |
# File 'lib/elastomer/client/snapshot.rb', line 103 def delete(params = {}) response = client.delete "/_snapshot/{repository}/{snapshot}", update_params(params, action: "snapshot.delete", rest_api: "snapshot.delete") response.body end |
#exists?(params = {}) ⇒ Boolean Also known as: exist?
Check for the existence of the snapshot. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
params - Parameters Hash
Returns true if the snapshot exists
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/elastomer/client/snapshot.rb', line 37 def exists?(params = {}) response = client.get "/_snapshot/{repository}/{snapshot}", update_params(params, action: "snapshot.exists", rest_api: "snapshot.get") response.success? rescue Elastomer::Client::Error => err if err.error && err.error.dig("root_cause", 0, "type") == "snapshot_missing_exception" false else raise err end end |
#get(params = {}) ⇒ Object
Get snapshot progress information. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
params - Parameters Hash
Returns the response body as a Hash
67 68 69 70 71 72 |
# File 'lib/elastomer/client/snapshot.rb', line 67 def get(params = {}) # Set snapshot name or we'll get the repository instead snapshot = name || "_all" response = client.get "/_snapshot/{repository}/{snapshot}", update_params(params, snapshot: snapshot, action: "snapshot.get", rest_api: "snapshot.get") response.body end |
#restore(body = {}, params = {}) ⇒ Object
Restore the snapshot. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
body - The restore options as a Hash or a JSON encoded String params - Parameters Hash
Returns the response body as a Hash
92 93 94 95 |
# File 'lib/elastomer/client/snapshot.rb', line 92 def restore(body = {}, params = {}) response = client.post "/_snapshot/{repository}/{snapshot}/_restore", update_params(params, body: body, action: "snapshot.restore", rest_api: "snapshot.restore") response.body end |
#status(params = {}) ⇒ Object
Get detailed snapshot status. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_snapshot
params - Parameters Hash
Returns the response body as a Hash
80 81 82 83 |
# File 'lib/elastomer/client/snapshot.rb', line 80 def status(params = {}) response = client.get "/_snapshot{/repository}{/snapshot}/_status", update_params(params, action: "snapshot.status", rest_api: "snapshot.status") response.body end |
#update_params(params, overrides = nil) ⇒ Object
Internal: Add default parameters to the ‘params` Hash and then apply `overrides` to the params if any are given.
params - Parameters Hash overrides - Optional parameter overrides as a Hash
Returns a new params Hash.
115 116 117 118 119 |
# File 'lib/elastomer/client/snapshot.rb', line 115 def update_params( params, overrides = nil ) h = defaults.update params h.update overrides unless overrides.nil? h end |