Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Snapshot Repository #1087

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions lib/puppet/provider/elasticsearch_snapshot_repository/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These new fields will need to be added as optional fields on the generate_body method below.

: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'],
Expand All @@ -36,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?
Expand Down
29 changes: 28 additions & 1 deletion lib/puppet/type/elasticsearch_snapshot_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@
desc 'Repository location'
end

newproperty(:client) do
defaultto 'default'
desc 'Azure client'
end

newproperty(:container) do
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'
end
Expand All @@ -46,6 +69,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
27 changes: 24 additions & 3 deletions manifests/snapshot_repository.pp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,23 @@
# @param repository_type
# Snapshot repository type.
#
# @param location
# Location of snapshots. Mandatory
# @param location. Mandatory for type => "fs"
# Location of snapshots.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field is still mandatory when type => "fs", so we should state that.

#
# @param container. Mandatory for type => "azure"
# 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?
Expand All @@ -60,8 +75,13 @@
# @author Tyler Langlois <tyler.langlois@elastic.co>
#
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,
Expand All @@ -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,
Expand Down