elasticache_snapshot 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6162037bf56882a329646bbea26d1b4a6afccfcd
4
+ data.tar.gz: 2d0005af065879e8884b30ccaa0c6c56ae8a9f04
5
+ SHA512:
6
+ metadata.gz: 2cd11498ab69dff2c1b755f844ad40307f4f999c632c010bf7302ac59183d8469d02e21960538388ea40c7150eeb4eb89bd1400e05e53e8a6bf38658105e6bf6
7
+ data.tar.gz: cf37e5202e55382e3eb8eddc495692adc59cfc8d95db158265f7862ae092be16747833b822ea1a640f5c55d2fe9f94a085baeb5f375c5c986f8a54549fdfe64a
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in elasticache_snapshot.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,68 @@
1
+ # おれん ElastiCache Snapshot
2
+
3
+ おれん ElastiCache のスナップショットを管理ツールくさ。
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'elasticache_snapshot'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install elasticache_snapshot
20
+
21
+ ## Usage
22
+
23
+ ### Set AWS Credentials
24
+
25
+ ```bash
26
+ cat << EOT > ~/.aws/credentials
27
+ [default]
28
+ aws_access_key_id = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
29
+ aws_secret_access_key = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
30
+ EOT
31
+ export AWS_REGION=ap-northeast-1 or export AWS_REGION=(your region)
32
+ ```
33
+
34
+ ### Help
35
+
36
+ ```bash
37
+ bundle exec bin/elasticache_snapshot
38
+
39
+ (output)
40
+ Commands:
41
+ elasticache_snapshot create SNAPSHOT_NAME # Create Snapshot SNAPSHOT_NAME
42
+ elasticache_snapshot delete SNAPSHOT_NAME # Dispose Snapshot SNAPSHOT_NAME
43
+ elasticache_snapshot help [COMMAND] # Describe available commands or one specific command
44
+ elasticache_snapshot list # Describe Snapshots
45
+ ```
46
+
47
+ ### list
48
+
49
+ ```bash
50
+ bundle exec bin/elasticache_snapshot list
51
+
52
+ (output)
53
+ +---------------------+-------------------------+
54
+ | SNAPSHOT Name | SNAPSHOT Create time |
55
+ +---------------------+-------------------------+
56
+ | snapshot-1420457086 | 2015-01-05 11:25:01 UTC |
57
+ | snapshot-1420457295 | 2015-01-05 11:28:31 UTC |
58
+ | snapshot-1420461070 | 2015-01-05 12:31:21 UTC |
59
+ +---------------------+-------------------------+
60
+ ```
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it ( https://github.com/[my-github-username]/elasticache_snapshot/fork )
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'elasticache_snapshot'
4
+ Elasticachesnapshot::ORENCLI.start(ARGV)
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'elasticache_snapshot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "elasticache_snapshot"
8
+ spec.version = ElasticacheSnapshot::VERSION
9
+ spec.authors = ["Yohei Kawahara(kappa)"]
10
+ spec.email = [""]
11
+ spec.summary = %q{AWS ElastiCache for Redis Snapshot tool}
12
+ spec.description = %q{AWS ElastiCache for Redis Snapshot tool}
13
+ spec.homepage = "https://github.com/inokappa/elasticache_snapshot"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+
25
+ spec.add_dependency "thor"
26
+ spec.add_dependency "aws-sdk"
27
+ spec.add_dependency "terminal-table"
28
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "elasticache_snapshot/version"
4
+ require "elasticache_snapshot/elasticache_snapshot"
5
+
6
+ module Elasticachesnapshot
7
+
8
+ end
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'aws-sdk'
4
+ require 'json'
5
+ require 'thor'
6
+ require 'terminal-table'
7
+
8
+ module Elasticachesnapshot
9
+ class ORENCLI < Thor
10
+ desc "list", "Describe Snapshots"
11
+ def list(name=nil)
12
+ describe_snapshots
13
+ end
14
+
15
+ desc "create SNAPSHOT_NAME", "Create Snapshot SNAPSHOT_NAME"
16
+ def create(snapshot_name= "snapshot-" + Time.now.to_i.to_s)
17
+ create_snapshot("#{snapshot_name}")
18
+ end
19
+
20
+ desc "delete SNAPSHOT_NAME", "Dispose Snapshot SNAPSHOT_NAME"
21
+ def delete(snapshot_name)
22
+ delete_snapshot("#{snapshot_name}")
23
+ end
24
+
25
+ private
26
+
27
+ def elc
28
+ AWS.config.credentials
29
+ AWS::ElastiCache.new.client
30
+ end
31
+
32
+ def describe_snapshots(name=nil)
33
+ snapshots = []
34
+ elc.describe_snapshots[:snapshots].each do |snapshot|
35
+ snapshot_create_time = ""
36
+ snapshot[:node_snapshots].each do |node_snapshot|
37
+ snapshot_create_time = node_snapshot[:snapshot_create_time]
38
+ end
39
+ snapshots << [ snapshot[:snapshot_name], "#{snapshot_create_time}" ]
40
+ end
41
+ snapshot_table = Terminal::Table.new :headings => ['SNAPSHOT Name', 'SNAPSHOT Create time'], :rows => snapshots
42
+ puts snapshot_table
43
+ end
44
+
45
+ def elaction_snapshot_node
46
+ cluster = []
47
+ elc.describe_cache_clusters.cache_clusters.each do |i|
48
+ cluster << { :cluster_id => i.cache_cluster_id, :create_time => i.cache_cluster_create_time, :cache_cluster_status => i.cache_cluster_status }
49
+ end
50
+
51
+ sorted = cluster.sort {|x, y| y[:create_time] <=> x[:create_time]}
52
+
53
+ unless sorted[0][:cache_cluster_status].include?("snapshotting")
54
+ replica_node = sorted[0][:cluster_id]
55
+ elc.describe_replication_groups.replication_groups[0].node_groups[0].node_group_members.each do |node|
56
+ if node.current_role == "replica" and node[:cache_cluster_id] == replica_node
57
+ return node[:cache_cluster_id]
58
+ end
59
+ end
60
+ else
61
+ return "Error, Snapshotting..."
62
+ end
63
+ end
64
+
65
+ def create_snapshot(snapshot_name)
66
+ unless elaction_snapshot_node.include?("Error")
67
+ snapshot_name = "snapshot-" + Time.now.to_i.to_s
68
+ puts "Create #{snapshot_name} from #{elaction_snapshot_node}..."
69
+ elc.create_snapshot({ :cache_cluster_id => elaction_snapshot_node, :snapshot_name => snapshot_name })
70
+ else
71
+ puts elaction_snapshot_node
72
+ end
73
+ end
74
+
75
+ def delete_snapshot(snapshot_name)
76
+ elc.delete_snapshot({ :snapshot_name => snapshot_name })
77
+ puts "Deleted #{snapshot_name}"
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,3 @@
1
+ module ElasticacheSnapshot
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe ElasticacheSnapshot do
4
+ it 'has a version number' do
5
+ expect(ElasticacheSnapshot::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful' do
9
+ expect(false).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'elasticache_snapshot'
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elasticache_snapshot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Yohei Kawahara(kappa)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aws-sdk
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: terminal-table
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: AWS ElastiCache for Redis Snapshot tool
98
+ email:
99
+ - ''
100
+ executables:
101
+ - elasticache_snapshot
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - .rspec
107
+ - .travis.yml
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/elasticache_snapshot
113
+ - elasticache_snapshot.gemspec
114
+ - lib/elasticache_snapshot.rb
115
+ - lib/elasticache_snapshot/elasticache_snapshot.rb
116
+ - lib/elasticache_snapshot/version.rb
117
+ - spec/elasticache_snapshot_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: https://github.com/inokappa/elasticache_snapshot
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.0.14
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: AWS ElastiCache for Redis Snapshot tool
143
+ test_files:
144
+ - spec/elasticache_snapshot_spec.rb
145
+ - spec/spec_helper.rb