gaptool-client 0.1.0

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", ">= 0"
11
+ gem "bundler", ">= 0"
12
+ gem "jeweler", "~> 1.8.4"
13
+ gem "simplecov", ">= 0"
14
+ end
15
+
16
+ gem 'json'
17
+ gem 'peach'
18
+ gem 'rainbow'
19
+ gem 'clamp'
20
+ gem 'gaptool-api'
data/Gemfile.lock ADDED
@@ -0,0 +1,52 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.2.9)
5
+ i18n (~> 0.6)
6
+ multi_json (~> 1.0)
7
+ clamp (0.5.0)
8
+ gaptool-api (0.1.5)
9
+ httparty
10
+ git (1.2.5)
11
+ httparty (0.9.0)
12
+ multi_json (~> 1.0)
13
+ multi_xml
14
+ i18n (0.6.1)
15
+ jeweler (1.8.4)
16
+ bundler (~> 1.0)
17
+ git (>= 1.2.5)
18
+ rake
19
+ rdoc
20
+ json (1.7.5)
21
+ multi_json (1.3.7)
22
+ multi_xml (0.5.1)
23
+ peach (0.5.1)
24
+ rainbow (1.1.4)
25
+ rake (10.0.2)
26
+ rdoc (3.12)
27
+ json (~> 1.4)
28
+ shoulda (3.3.2)
29
+ shoulda-context (~> 1.0.1)
30
+ shoulda-matchers (~> 1.4.1)
31
+ shoulda-context (1.0.1)
32
+ shoulda-matchers (1.4.1)
33
+ activesupport (>= 3.0.0)
34
+ simplecov (0.7.1)
35
+ multi_json (~> 1.0)
36
+ simplecov-html (~> 0.7.1)
37
+ simplecov-html (0.7.1)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ bundler
44
+ clamp
45
+ gaptool-api
46
+ jeweler (~> 1.8.4)
47
+ json
48
+ peach
49
+ rainbow
50
+ rdoc
51
+ shoulda
52
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ See LICENSE for license (Apache-2.0)
2
+
3
+ About
4
+ =====
5
+
6
+ gaptool will create environments in AWS EC2, RDS, and Route 53 based on your chef recipes and make them manageable much in the same way that EngineYard and Heroku are.
7
+
8
+ Essentially, turning your IaaS into a PaaS.
9
+
10
+ Setup
11
+ =====
12
+
13
+ Lots of documentation will be fourthcoming, stay tuned.
14
+
15
+ Examples of configuration for the tool are in common/
16
+
17
+ Example of chef repo to use this properly will be available soon
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "gaptool-client"
18
+ gem.homepage = "http://github.com/mattbailey/gaptool-client"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{gaptool client}
21
+ gem.description = %Q{client for gaptool-server}
22
+ gem.email = "m@mdb.io"
23
+ gem.authors = ["Matt Bailey"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "gaptool-client #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/gt ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'gaptool-api'
5
+
6
+ # Make sure lang isn't fucked
7
+ ENV['LANG'] = "en_US.UTF-8"
8
+
9
+ # Nuke your ssh-agent
10
+ ENV['SSH_AUTH_SOCK'] = ''
11
+
12
+ # Make API accessable to client
13
+ $api = GTAPI::GaptoolServer.new(ENV['GT_USER'], ENV['GT_KEY'], ENV['GT_URL'])
14
+
15
+ # Run client
16
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/gaptool-client.rb")
17
+
18
+
@@ -0,0 +1,79 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "gaptool-client"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Matt Bailey"]
12
+ s.date = "2012-12-13"
13
+ s.description = "client for gaptool-server"
14
+ s.email = "m@mdb.io"
15
+ s.executables = ["gt"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.md"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/gt",
29
+ "gaptool-client.gemspec",
30
+ "lib/gaptool-client.rb",
31
+ "test/helper.rb",
32
+ "test/test_gaptool-client.rb"
33
+ ]
34
+ s.homepage = "http://github.com/mattbailey/gaptool-client"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.23"
38
+ s.summary = "gaptool client"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<json>, [">= 0"])
45
+ s.add_runtime_dependency(%q<peach>, [">= 0"])
46
+ s.add_runtime_dependency(%q<rainbow>, [">= 0"])
47
+ s.add_runtime_dependency(%q<clamp>, [">= 0"])
48
+ s.add_runtime_dependency(%q<gaptool-api>, [">= 0"])
49
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
50
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
51
+ s.add_development_dependency(%q<bundler>, [">= 0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
53
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<json>, [">= 0"])
56
+ s.add_dependency(%q<peach>, [">= 0"])
57
+ s.add_dependency(%q<rainbow>, [">= 0"])
58
+ s.add_dependency(%q<clamp>, [">= 0"])
59
+ s.add_dependency(%q<gaptool-api>, [">= 0"])
60
+ s.add_dependency(%q<shoulda>, [">= 0"])
61
+ s.add_dependency(%q<rdoc>, [">= 0"])
62
+ s.add_dependency(%q<bundler>, [">= 0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
64
+ s.add_dependency(%q<simplecov>, [">= 0"])
65
+ end
66
+ else
67
+ s.add_dependency(%q<json>, [">= 0"])
68
+ s.add_dependency(%q<peach>, [">= 0"])
69
+ s.add_dependency(%q<rainbow>, [">= 0"])
70
+ s.add_dependency(%q<clamp>, [">= 0"])
71
+ s.add_dependency(%q<gaptool-api>, [">= 0"])
72
+ s.add_dependency(%q<shoulda>, [">= 0"])
73
+ s.add_dependency(%q<rdoc>, [">= 0"])
74
+ s.add_dependency(%q<bundler>, [">= 0"])
75
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
76
+ s.add_dependency(%q<simplecov>, [">= 0"])
77
+ end
78
+ end
79
+
@@ -0,0 +1,211 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rainbow'
3
+ require 'peach'
4
+ require 'json'
5
+ require 'clamp'
6
+ require 'net/ssh'
7
+ require 'net/scp'
8
+
9
+ class InitCommand < Clamp::Command
10
+ option ["-r", "--role"], "ROLE", "Resource name to initilize", :required => true
11
+ option ["-e", "--environment"], "ENVIRONMENT", "Which environment, e.g. production", :required => true
12
+ option ["-z", "--zone"], "ZONE", "AWS availability zone to put node in", :required => true
13
+ option ["-t", "--type"], "TYPE", "Type of instance, e.g. m1.large", :required => true
14
+ option ["-m", "--mirror"], "GIGABYTES", "Gigs for raid mirror, must be set up on each node", :required => false
15
+ def execute
16
+ $api.addnode(zone, type, role, environment, mirror)
17
+ end
18
+ end
19
+
20
+ class TerminateCommand < Clamp::Command
21
+ option ["-z", "--zone"], "ZONE", "AWS availability zone to put node in", :required => true
22
+ option ["-i", "--instance"], "INSTANCE", "Instance ID, e.g. i-12345678", :required => true
23
+ def execute
24
+ $api.terminatenode(instance, zone)
25
+ end
26
+ end
27
+
28
+ class SshCommand < Clamp::Command
29
+ option ["-r", "--role"], "ROLE", "Role name to ssh to", :required => true
30
+ option ["-e", "--environment"], "ENVIRONMENT", "Which environment, e.g. production", :required => true
31
+ option ["-i", "--instance"], "INSTANCE", "Node instance, leave blank to query avilable nodes", :require => false
32
+ option ["-f", "--first"], :flag, "Just connect to first available instance"
33
+
34
+ def execute
35
+ if instance
36
+ @ssh = $api.ssh(role, environment, instance)
37
+ else
38
+ nodes = $api.getenvroles(role, environment)
39
+ if first? || nodes.size == 1
40
+ puts "No instnace specified, but only one instance in cluster or first forced"
41
+ @ssh = $api.ssh(role, environment, nodes.first['instance'])
42
+ else
43
+ puts "No instance specified, querying list."
44
+ nodes.each_index do |i|
45
+ puts "#{i}: #{nodes[i]['instance']}"
46
+ end
47
+ print "Select a node: ".color(:cyan)
48
+ @ssh = $api.ssh(role, environment, nodes[$stdin.gets.chomp.to_i]['instance'])
49
+ end
50
+ end
51
+ File.open('/tmp/gtkey', 'w') {|f| f.write(@ssh['key'])}
52
+ File.chmod(0600, '/tmp/gtkey')
53
+ system "SSH_AUTH_SOCK='' ssh -i /tmp/gtkey admin@#{@ssh['hostname']}"
54
+ end
55
+
56
+ end
57
+
58
+ def sshcmd(node, commands)
59
+ Net::SSH.start(
60
+ node['hostname'],
61
+ 'admin',
62
+ :key_data => [$api.ssh(node['role'], node['environment'], node['instance'])['key']],
63
+ :config => false,
64
+ :keys_only => true,
65
+ :paranoid => false
66
+ ) do |ssh|
67
+ commands.each do |command|
68
+ command.color(:cyan)
69
+ ssh.exec! command do
70
+ |ch, stream, line|
71
+ puts "#{node['role'].color(:yellow)}:#{node['environment'].color(:yellow)}:#{node['instance'].color(:yellow)}> #{line}"
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+
78
+ class ChefrunCommand < Clamp::Command
79
+ option ["-r", "--role"], "ROLE", "Role name to ssh to", :required => true
80
+ option ["-e", "--environment"], "ENVIRONMENT", "Which environment, e.g. production", :required => true
81
+ option ["-i", "--instance"], "INSTANCE", "Instance ID, e.g. i-12345678", :required => false
82
+
83
+ def execute
84
+ if !instance.nil?
85
+ nodes = [$api.getonenode(role, environment, instance)]
86
+ else
87
+ nodes = $api.getenvroles(role, environment)
88
+ end
89
+ nodes.peach do |node|
90
+ json = {
91
+ 'this_server' => "#{role}-#{environment}-#{node['instance']}",
92
+ 'role' => role,
93
+ 'environment' => environment,
94
+ 'app_user' => node['appuser'],
95
+ 'run_list' => [ "recipe[main]" ],
96
+ 'hostname' => node['hostname'],
97
+ 'instance' => node['instance'],
98
+ 'zone' => node['zone'],
99
+ 'itype' => node['itype'],
100
+ 'apps' => eval(node['apps'])
101
+ }.to_json
102
+ commands = [
103
+ "cd ~admin/ops; git pull",
104
+ "echo '#{json}' > ~admin/solo.json",
105
+ "sudo chef-solo -c ~admin/ops/cookbooks/solo.rb -j ~admin/solo.json"
106
+ ]
107
+ sshcmd(node, commands)
108
+ end
109
+ end
110
+ end
111
+
112
+ class DeployCommand < Clamp::Command
113
+ option ["-a", "--app"], "APP", "Application to deploy", :required => true
114
+ option ["-m", "--migrate"], :flag, "Toggle running migrations"
115
+ option ["-e", "--environment"], "ENVIRONMENT", "Which environment, e.g. production", :required => true
116
+ option ["-b", "--branch"], "BRANCH", "Git branch to deploy, default is master", :required => false
117
+ option ["-r", "--rollback"], :flag, "Toggle this to rollback last deploy"
118
+
119
+ def execute
120
+ nodes = $api.getappnodes(app, environment)
121
+ nodes.peach do |node|
122
+ json = {
123
+ 'this_server' => "#{node['role']}-#{environment}-#{node['instance']}",
124
+ 'role' => node['role'],
125
+ 'environment' => environment,
126
+ 'app_user' => node['appuser'],
127
+ 'run_list' => [ "recipe[deploy]" ],
128
+ 'hostname' => node['hostname'],
129
+ 'instance' => node['instance'],
130
+ 'zone' => node['zone'],
131
+ 'itype' => node['itype'],
132
+ 'apps' => eval(node['apps']),
133
+ 'app_name' => app,
134
+ 'app' => app,
135
+ 'rollback' => rollback?,
136
+ 'branch' => branch || 'master',
137
+ 'migrate' => migrate?
138
+ }.to_json
139
+ commands = [
140
+ "cd ~admin/ops; git pull",
141
+ "echo '#{json}' > ~admin/solo.json",
142
+ "sudo chef-solo -c ~admin/ops/cookbooks/solo.rb -j ~admin/solo.json"
143
+ ]
144
+ sshcmd(node, commands)
145
+ end
146
+ end
147
+ end
148
+
149
+ class RegenCommand < Clamp::Command
150
+ option ["-z", "--zone"], "ZONE", "AWS availability zone to put node in", :required => true
151
+ def execute
152
+ nodes = $api.regenhosts(zone)
153
+ end
154
+ end
155
+
156
+ class BalanceCommand < Clamp::Command
157
+ option ["-r", "--role"], "ROLE", "Role name to ssh to", :required => true
158
+ option ["-e", "--environment"], "ENVIRONMENT", "Which environment, e.g. production", :required => true
159
+ def execute
160
+ puts $api.balanceservices(role, environment)
161
+ end
162
+ end
163
+
164
+ class AddserviceCommand < Clamp::Command
165
+ option ["-r", "--role"], "ROLE", "Role name to ssh to", :required => true
166
+ option ["-e", "--environment"], "ENVIRONMENT", "Which environment, e.g. production", :required => true
167
+ option ["-n", "--name"], "NAME", "Name of the service, e.g. 'twitter'. MUST MATCH UPSTARTD SERVICE NAME.", :required => true
168
+ option ["-w", "--weight"], "WEIGHT", "Relative service weight, for the balancer to chose run location", :required => true
169
+ option ["-y", "--enabled"], :flag, "Enable this service in balance run"
170
+ option ["-k", "--keys"], "KEYS", "Hash of keys that will be written to YAML /tmp/apikeys-<service name>.yml. This will be eval()'d, write it like a ruby hash.", :required => true
171
+ def execute
172
+ if enabled?
173
+ en = 1
174
+ else
175
+ en = 0
176
+ end
177
+ puts $api.addservice(role, environment, name, eval(keys), weight, en)
178
+ end
179
+ end
180
+
181
+ class DelserviceCommand < Clamp::Command
182
+ option ["-r", "--role"], "ROLE", "Role name to ssh to", :required => true
183
+ option ["-e", "--environment"], "ENVIRONMENT", "Which environment, e.g. production", :required => true
184
+ option ["-n", "--name"], "NAME", "Name of the service, e.g. 'twitter'. MUST MATCH UPSTARTD SERVICE NAME.", :required => true
185
+ def execute
186
+ puts $api.deleteservice(role, environment, name)
187
+ end
188
+ end
189
+
190
+ class ServicesCommand < Clamp::Command
191
+ def execute
192
+ puts $api.getservices()
193
+ end
194
+ end
195
+
196
+ class MainCommand < Clamp::Command
197
+
198
+ subcommand "init", "Create new application cluster", InitCommand
199
+ subcommand "terminate", "Terminate instance", TerminateCommand
200
+ subcommand "ssh", "ssh to cluster host", SshCommand
201
+ subcommand "chefrun", "chefrun on a resource pool", ChefrunCommand
202
+ subcommand "deploy", "deploy on an application", DeployCommand
203
+ subcommand "regen", "regen metadata from aws", RegenCommand
204
+ subcommand "balance", "balance services across nodes based on weight", BalanceCommand
205
+ subcommand "addservice", "add new service to service framework", AddserviceCommand
206
+ subcommand "delservice", "delete last service", DelserviceCommand
207
+ subcommand "services", "show all services", ServicesCommand
208
+
209
+ end
210
+
211
+ MainCommand.run
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'gaptool-client'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestGaptoolClient < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,223 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gaptool-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Bailey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: peach
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rainbow
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: clamp
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: gaptool-api
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: shoulda
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rdoc
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: bundler
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: jeweler
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 1.8.4
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 1.8.4
158
+ - !ruby/object:Gem::Dependency
159
+ name: simplecov
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ description: client for gaptool-server
175
+ email: m@mdb.io
176
+ executables:
177
+ - gt
178
+ extensions: []
179
+ extra_rdoc_files:
180
+ - LICENSE.txt
181
+ - README.md
182
+ files:
183
+ - .document
184
+ - Gemfile
185
+ - Gemfile.lock
186
+ - LICENSE.txt
187
+ - README.md
188
+ - Rakefile
189
+ - VERSION
190
+ - bin/gt
191
+ - gaptool-client.gemspec
192
+ - lib/gaptool-client.rb
193
+ - test/helper.rb
194
+ - test/test_gaptool-client.rb
195
+ homepage: http://github.com/mattbailey/gaptool-client
196
+ licenses:
197
+ - MIT
198
+ post_install_message:
199
+ rdoc_options: []
200
+ require_paths:
201
+ - lib
202
+ required_ruby_version: !ruby/object:Gem::Requirement
203
+ none: false
204
+ requirements:
205
+ - - ! '>='
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ segments:
209
+ - 0
210
+ hash: 596003341975408369
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
+ none: false
213
+ requirements:
214
+ - - ! '>='
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ requirements: []
218
+ rubyforge_project:
219
+ rubygems_version: 1.8.23
220
+ signing_key:
221
+ specification_version: 3
222
+ summary: gaptool client
223
+ test_files: []