From 032c5817cc135a85d2fb6949ba2dda0a10a026a9 Mon Sep 17 00:00:00 2001 From: Jacob Brush Date: Tue, 2 Jun 2020 07:55:11 -0400 Subject: [PATCH 1/7] adds code for azure snapshot repository --- .../elasticsearch_snapshot_repository/ruby.rb | 5 ++++ .../type/elasticsearch_snapshot_repository.rb | 30 ++++++++++++++++++- manifests/snapshot_repository.pp | 25 ++++++++++++++-- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/lib/puppet/provider/elasticsearch_snapshot_repository/ruby.rb b/lib/puppet/provider/elasticsearch_snapshot_repository/ruby.rb index 9b5e6e326..032677c3f 100644 --- a/lib/puppet/provider/elasticsearch_snapshot_repository/ruby.rb +++ b/lib/puppet/provider/elasticsearch_snapshot_repository/ruby.rb @@ -21,6 +21,11 @@ def self.process_body(body) :type => api_object['type'], :compress => api_object['settings']['compress'], :location => api_object['settings']['location'], + :container => api_object['settings']['container'], + :base_path => api_object['settings']['base_path'], + :client => api_object['settings']['client'], + :readonly => api_object['settigns']['readonly'], + :location_mode => api_object['settings']['location_mode'], :chunk_size => api_object['settings']['chunk_size'], :max_restore_rate => api_object['settings']['max_restore_rate'], :max_snapshot_rate => api_object['settings']['max_snapshot_rate'], diff --git a/lib/puppet/type/elasticsearch_snapshot_repository.rb b/lib/puppet/type/elasticsearch_snapshot_repository.rb index 17357a912..a290968d4 100644 --- a/lib/puppet/type/elasticsearch_snapshot_repository.rb +++ b/lib/puppet/type/elasticsearch_snapshot_repository.rb @@ -32,6 +32,30 @@ newproperty(:location) do desc 'Repository location' end + + newproperty(:client) do + defaultto 'default' + desc 'Azure client' + end + + newproperty(:container) do + defaultto 'elasticsearch-snapshots' + desc 'Azure storage container' + end + + newproperty(:base_path) do + desc 'Specifies the path within container to repository data.' + end + + newproperty(:readonly) do + defaultto 'false' + desc 'Makes repository read-only.' + end + + newproperty(:location_mode) do + defaultto 'primary_only' + desc 'primary_only or secondary_only. Note that if you set it to secondary_only, it will force readonly to true.' + end newproperty(:chunk_size) do desc 'File chunk size' @@ -46,6 +70,10 @@ end validate do - raise ArgumentError, 'Location is required.' if self[:location].nil? + if self[:type] == 'fs' + raise ArgumentError, 'Location is required.' if self[:location].nil? + elsif self[:type] == 'azure' + raise ArgumentError, 'Container is required.' if self[:container].nil? + end end end # of newtype diff --git a/manifests/snapshot_repository.pp b/manifests/snapshot_repository.pp index 1906194ea..6bc8cbc6e 100644 --- a/manifests/snapshot_repository.pp +++ b/manifests/snapshot_repository.pp @@ -37,7 +37,22 @@ # Snapshot repository type. # # @param location -# Location of snapshots. Mandatory +# Location of snapshots. +# +# @param container +# Azure Container name. +# +# @param client +# Azure named client to use. +# +# @param base_path +# Azure path within container to repository data. +# +# @param readonly +# Makes Azure repository read-only. +# +# @param location_mode +# Azure location_mode. # # @param compress # Compress the snapshot metadata files? @@ -60,8 +75,13 @@ # @author Tyler Langlois # define elasticsearch::snapshot_repository ( - String $location, + Optional[String] $location = undef, Enum['absent', 'present'] $ensure = 'present', + Optional[String] $client = undef, + Optional[String] $container = undef, + Optional[String] $base_path = undef, + Optional[Boolean] $readonly = false, + Optional[String] $location_mode = undef, Optional[String] $api_basic_auth_password = $elasticsearch::api_basic_auth_password, Optional[String] $api_basic_auth_username = $elasticsearch::api_basic_auth_username, Optional[Stdlib::Absolutepath] $api_ca_file = $elasticsearch::api_ca_file, @@ -88,6 +108,7 @@ chunk_size => $chunk_size, compress => $compress, location => $location, + location => $location, max_restore_rate => $max_restore_rate, max_snapshot_rate => $max_snapshot_rate, type => $repository_type, From d17608ea1f28f6a4555f061745cb27b617122b12 Mon Sep 17 00:00:00 2001 From: Jacob Brush Date: Mon, 8 Jun 2020 13:30:36 -0400 Subject: [PATCH 2/7] adds optional fields to body. --- .../provider/elasticsearch_snapshot_repository/ruby.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/elasticsearch_snapshot_repository/ruby.rb b/lib/puppet/provider/elasticsearch_snapshot_repository/ruby.rb index 032677c3f..d7cd8d3ad 100644 --- a/lib/puppet/provider/elasticsearch_snapshot_repository/ruby.rb +++ b/lib/puppet/provider/elasticsearch_snapshot_repository/ruby.rb @@ -41,12 +41,17 @@ def generate_body body = { 'type' => resource[:type], 'settings' => { - 'compress' => resource[:compress], - 'location' => resource[:location] + 'compress' => resource[:compress] } } # Add optional values + body['settings']['location'] = resource[:location] unless resource[:location].nil? + body['settings']['container'] = resource[:container] unless resource[:container].nil? + body['settings']['base_path'] = resource[:base_path] unless resource[:base_path].nil? + body['settings']['client'] = resource[:client] unless resource[:client].nil? + body['settings']['readonly'] = resource[:readonly] unless resource[:readonly].nil? + body['settings']['location_mode'] = resource[:location_mode] unless resource[:location_mode].nil? body['settings']['chunk_size'] = resource[:chunk_size] unless resource[:chunk_size].nil? body['settings']['max_restore_rate'] = resource[:max_restore_rate] unless resource[:max_restore_rate].nil? body['settings']['max_snapshot_rate'] = resource[:max_snapshot_rate] unless resource[:max_snapshot_rate].nil? From 0686a7f4ba2c8ee6f921924a951420e2e4234754 Mon Sep 17 00:00:00 2001 From: Jacob Brush Date: Mon, 8 Jun 2020 14:24:28 -0400 Subject: [PATCH 3/7] removes container default name --- lib/puppet/type/elasticsearch_snapshot_repository.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/puppet/type/elasticsearch_snapshot_repository.rb b/lib/puppet/type/elasticsearch_snapshot_repository.rb index a290968d4..e35f3494d 100644 --- a/lib/puppet/type/elasticsearch_snapshot_repository.rb +++ b/lib/puppet/type/elasticsearch_snapshot_repository.rb @@ -39,7 +39,6 @@ end newproperty(:container) do - defaultto 'elasticsearch-snapshots' desc 'Azure storage container' end From 66b37030b1a64e565aebef35f52dc51449cebec5 Mon Sep 17 00:00:00 2001 From: Jacob Brush Date: Mon, 8 Jun 2020 14:24:45 -0400 Subject: [PATCH 4/7] removes trailing whitespace --- lib/puppet/type/elasticsearch_snapshot_repository.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/type/elasticsearch_snapshot_repository.rb b/lib/puppet/type/elasticsearch_snapshot_repository.rb index e35f3494d..9d83ab6f3 100644 --- a/lib/puppet/type/elasticsearch_snapshot_repository.rb +++ b/lib/puppet/type/elasticsearch_snapshot_repository.rb @@ -32,7 +32,7 @@ newproperty(:location) do desc 'Repository location' end - + newproperty(:client) do defaultto 'default' desc 'Azure client' From d40328dc1f105ee6e1a3bbd2bddfcae1525e6058 Mon Sep 17 00:00:00 2001 From: Jacob Brush Date: Mon, 8 Jun 2020 14:26:14 -0400 Subject: [PATCH 5/7] adds comment for mandatory params --- manifests/snapshot_repository.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/snapshot_repository.pp b/manifests/snapshot_repository.pp index 6bc8cbc6e..1855194f9 100644 --- a/manifests/snapshot_repository.pp +++ b/manifests/snapshot_repository.pp @@ -36,10 +36,10 @@ # @param repository_type # Snapshot repository type. # -# @param location +# @param location. Mandatory for type => "fs" # Location of snapshots. # -# @param container +# @param container. Mandatory for type => "azure" # Azure Container name. # # @param client From ac386572461d2c98bb91ce807c00ce7d3395fc03 Mon Sep 17 00:00:00 2001 From: Jacob Brush Date: Mon, 8 Jun 2020 14:26:48 -0400 Subject: [PATCH 6/7] cleans up alignment --- manifests/snapshot_repository.pp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/manifests/snapshot_repository.pp b/manifests/snapshot_repository.pp index 1855194f9..32dff9040 100644 --- a/manifests/snapshot_repository.pp +++ b/manifests/snapshot_repository.pp @@ -77,11 +77,11 @@ define elasticsearch::snapshot_repository ( Optional[String] $location = undef, Enum['absent', 'present'] $ensure = 'present', - Optional[String] $client = undef, - Optional[String] $container = undef, - Optional[String] $base_path = undef, + Optional[String] $client = undef, + Optional[String] $container = undef, + Optional[String] $base_path = undef, Optional[Boolean] $readonly = false, - Optional[String] $location_mode = undef, + Optional[String] $location_mode = undef, Optional[String] $api_basic_auth_password = $elasticsearch::api_basic_auth_password, Optional[String] $api_basic_auth_username = $elasticsearch::api_basic_auth_username, Optional[Stdlib::Absolutepath] $api_ca_file = $elasticsearch::api_ca_file, From 7a4a933c38893fdc75e5fe2783596ff53f4c7059 Mon Sep 17 00:00:00 2001 From: Jacob Brush Date: Mon, 8 Jun 2020 14:31:04 -0400 Subject: [PATCH 7/7] adds example to readme --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 9f32ab948..ab54d9151 100644 --- a/README.md +++ b/README.md @@ -432,6 +432,22 @@ elasticsearch::snapshot_repository { 'backups': } ``` +```elasticsearch::snapshot_repository { azure_backups: + type => 'azure', + container => 'elasticsearch_backups, + api_protocol => 'https', + api_host => $::ipaddress, + api_port => 9201, + api_timeout => 60, + api_basic_auth_username => 'admin', + api_basic_auth_password => 'adminpassword', + api_ca_file => '/etc/ssl/certs', + api_ca_path => '/etc/pki/certs', + validate_tls => false, + + } +``` + #### Delete a snapshot repository ```puppet