grate-handle 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
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Kirill Ishanov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,9 @@
1
+ = grate-handle
2
+
3
+ Grate Handle is a ruby library and a CLI tool which simplify work with [GoGrid](www.gogrid.com). It is built on top of [GoGrid REST API](http://wiki.gogrid.com/wiki/index.php/API).
4
+
5
+ Currently Grate Handle is under lazy development, but I hope that it will become usable in a couple of weeks.
6
+
7
+ == Copyright
8
+
9
+ Copyright (c) 2009 Kirill Ishanov. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "grate-handle"
8
+ gem.summary = %Q{A ruby library and a CLI client to GoGrid API }
9
+ gem.description = %Q{ Grate Handle is a small gem which simplifies the with GoGrid's API from ruby code. Also ships with a CLI tool called 'gh' which allows to perform most of the actions from http://my.gogrid.com but using true Unix CLI way. }
10
+ gem.email = "kirill.ishanov@gmail.com"
11
+ gem.homepage = "http://github.com/kylichuku/grate-handle"
12
+ gem.authors = ["Kirill Ishanov"]
13
+
14
+ %w(rspec jeweler json).each do |dependency|
15
+ gem.add_development_dependency dependency
16
+ end
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ if File.exist?('VERSION')
42
+ version = File.read('VERSION')
43
+ else
44
+ version = ""
45
+ end
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "grate-handle #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/gh ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ require 'grate-handle'
6
+
7
+ GrateHandle::CLIProcessor.new(ARGV).process
8
+
@@ -0,0 +1,74 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
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 = %q{grate-handle}
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 = ["Kirill Ishanov"]
12
+ s.date = %q{2009-08-25}
13
+ s.default_executable = %q{gh}
14
+ s.description = %q{ Grate Handle is a small gem which simplifies the with GoGrid's API from ruby code. Also ships with a CLI tool called 'gh' which allows to perform most of the actions from http://my.gogrid.com but using true Unix CLI way. }
15
+ s.email = %q{kirill.ishanov@gmail.com}
16
+ s.executables = ["gh"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/gh",
29
+ "grate-handle.gemspec",
30
+ "lib/cli_processor.rb",
31
+ "lib/gogrid_client.rb",
32
+ "lib/gogrid_manager.rb",
33
+ "lib/grate-handle.rb",
34
+ "lib/monkey_patches.rb",
35
+ "spec/cli_processor_spec.rb",
36
+ "spec/fixtures/all.rb",
37
+ "spec/fixtures/grid_server_list.json",
38
+ "spec/fixtures/grid_server_list.xml",
39
+ "spec/gogrid_manager_spec.rb",
40
+ "spec/monkey_patches_spec.rb",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+ s.homepage = %q{http://github.com/kylichuku/grate-handle}
44
+ s.rdoc_options = ["--charset=UTF-8"]
45
+ s.require_paths = ["lib"]
46
+ s.rubygems_version = %q{1.3.3}
47
+ s.summary = %q{A ruby library and a CLI client to GoGrid API}
48
+ s.test_files = [
49
+ "spec/gogrid_manager_spec.rb",
50
+ "spec/spec_helper.rb",
51
+ "spec/monkey_patches_spec.rb",
52
+ "spec/fixtures/all.rb",
53
+ "spec/cli_processor_spec.rb"
54
+ ]
55
+
56
+ if s.respond_to? :specification_version then
57
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
58
+ s.specification_version = 3
59
+
60
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
61
+ s.add_development_dependency(%q<rspec>, [">= 0"])
62
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
63
+ s.add_development_dependency(%q<json>, [">= 0"])
64
+ else
65
+ s.add_dependency(%q<rspec>, [">= 0"])
66
+ s.add_dependency(%q<jeweler>, [">= 0"])
67
+ s.add_dependency(%q<json>, [">= 0"])
68
+ end
69
+ else
70
+ s.add_dependency(%q<rspec>, [">= 0"])
71
+ s.add_dependency(%q<jeweler>, [">= 0"])
72
+ s.add_dependency(%q<json>, [">= 0"])
73
+ end
74
+ end
@@ -0,0 +1,37 @@
1
+ require 'gogrid_manager'
2
+
3
+ module GrateHandle
4
+ class CLIProcessor
5
+ attr_writer :manager
6
+
7
+ def initialize(args, out=STDOUT, manager=GoGridManager.new)
8
+ @args = args
9
+ @out = out
10
+ @manager = manager
11
+ end
12
+
13
+ def process
14
+ case @args.shift(1).first
15
+ when 'list':
16
+ list
17
+ else
18
+ @out.puts "unknown action"
19
+ end
20
+ end
21
+
22
+ def list
23
+ case @args.shift(1).first
24
+ when 'servers':
25
+ @manager.list_servers.each do |server|
26
+ @out.puts(sprintf("%-10s\t%-20s\t%-20s\t%s", server.id, server.name, server.ip.ip, server.state.name))
27
+ end
28
+ when 'images':
29
+ @manager.list_images.each do |image|
30
+ @out.puts(sprintf("%-5s\t%s", image.id, image.friendlyName))
31
+ end
32
+ else
33
+ @out.puts "Unknown command"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,44 @@
1
+ require 'digest/md5'
2
+ require 'cgi'
3
+ require 'open-uri'
4
+
5
+ module GrateHandle
6
+ class GoGridClient
7
+
8
+ def initialize(apikey = 'YOUR API KEY',
9
+ secret = 'YOUR SHARED SECRET',
10
+ format = 'json',
11
+ version = '1.2')
12
+ @server = 'https://api.gogrid.com/api'
13
+ @secret = secret
14
+ @default_params = { 'format' => format,
15
+ 'v' => version,
16
+ 'api_key' => apikey }
17
+ end
18
+
19
+ def credentials(apikey, secret)
20
+ @default_params['api_key'] = apikey
21
+ @secret = secret
22
+ end
23
+
24
+ def send_api_request(method, params={})
25
+ open(request_url(method, params)).read
26
+ end
27
+
28
+ private
29
+
30
+ def request_url(method, params)
31
+ call_params = @default_params.merge(params).merge(signature)
32
+ url = "#{@server}/#{method}?#{encoded(call_params)}"
33
+ end
34
+
35
+ def signature
36
+ { 'sig' => Digest::MD5.hexdigest(@default_params['api_key'] + @secret + "%.0f"%Time.new.to_f) }
37
+ end
38
+
39
+ def encoded(params)
40
+ params.map {|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join("&")
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,45 @@
1
+ module GrateHandle
2
+ class GoGridManager
3
+ # {{{1 Attributes
4
+
5
+ attr_accessor :client
6
+
7
+ #}}}
8
+ # {{{1 Initialization
9
+
10
+ def initialize(arg1=nil, arg2=nil)
11
+ if (arg1 && arg2)
12
+ from_params(arg1, arg2)
13
+ else
14
+ from_config(arg1)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def from_config(account=nil)
21
+ configs = YAML::load(File.read(File.expand_path('~/.ghrc')))
22
+ config = (account ? configs.select { |conf| conf['account'] == account }.first : configs.first)
23
+ from_params(config['apikey'], config['secret'])
24
+ end
25
+
26
+ def from_params(apikey, secret)
27
+ @client = GoGridClient.new(apikey, secret)
28
+ end
29
+
30
+ # }}}
31
+ # {{{1 GoGrid Request Wrappers
32
+
33
+ public
34
+
35
+ %w(server ip image).each do |entity|
36
+ define_method("list_#{entity}s".to_sym) do
37
+ response = @client.send_api_request("grid/#{entity}/list")
38
+ JSON.parse(response).list
39
+ end
40
+ end
41
+
42
+ # }}}
43
+ end
44
+ end
45
+
@@ -0,0 +1,11 @@
1
+ require 'gogrid_client'
2
+ require 'monkey_patches'
3
+ require 'gogrid_manager'
4
+ require 'cli_processor'
5
+
6
+ # gems
7
+ require 'rubygems'
8
+ require 'yaml'
9
+ require 'json'
10
+
11
+ include GrateHandle
@@ -0,0 +1,17 @@
1
+ class Hash
2
+ undef_method :id
3
+
4
+ def method_missing(methodname, *args)
5
+ humps = methodname.to_s.split('_')
6
+ key = humps.shift(1).first
7
+ key = key + humps.map { |hump| hump.capitalize }.join if humps.length
8
+
9
+ if self.include?(key)
10
+ self[key]
11
+ elsif key == 'id'
12
+ "N/A"
13
+ else
14
+ super
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe CLIProcessor do
4
+ describe "list servers" do
5
+ #before do
6
+ #@cli = CLIProcessor.new(%w(list servers), mock!, mock!.list_servers.subject { SERVERS } )
7
+ #end
8
+
9
+ #it "should call list_servers on GoGridManager" do
10
+ #@cli.process
11
+ #end
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ SERVERS = File.read('spec/fixtures/grid_server_list.json')
2
+
@@ -0,0 +1,60 @@
1
+ {
2
+ "list": [{
3
+ "description": "Test Sandbox Server",
4
+ "image": {
5
+ "description": "Windows 2008 (32-bit) w/ IIS 7.0 + PHP 5.2 + MySQL 5.0",
6
+ "id": 57,
7
+ "name": "w2k8_32_iis_php_mysql",
8
+ "object": "option"
9
+ },
10
+ "ip": {
11
+ "id": 499,
12
+ "ip": "111.111.11.111",
13
+ "object": "ip",
14
+ "public": true,
15
+ "state": {
16
+ "description": "IP is reserved or in use",
17
+ "id": 2,
18
+ "name": "Assigned",
19
+ "object": "option"
20
+ },
21
+ "subnet": "111.111.11.110/255.255.255.240"
22
+ },
23
+ "isSandbox": true,
24
+ "name": "Sandbox Server",
25
+ "object": "server",
26
+ "os": {
27
+ "description": "Windows 2008 Server (32-bit)",
28
+ "id": 11,
29
+ "name": "Windows 2008 Server (32-bit)",
30
+ "object": "option"
31
+ },
32
+ "ram": {
33
+ "description": "SandBox Server with 2GB RAM",
34
+ "id": 7,
35
+ "name": "2GB",
36
+ "object": "option"
37
+ },
38
+ "state": {
39
+ "description": null,
40
+ "id": 3,
41
+ "name": "Off",
42
+ "object": "option"
43
+ },
44
+ "type": {
45
+ "description": "This server has a public connection to the Internet.",
46
+ "id": 1,
47
+ "name": "Web Server",
48
+ "object": "option"
49
+ }
50
+ }],
51
+ "method": "/grid/server/list",
52
+ "status": "success",
53
+ "summary": {
54
+ "numpages": 0,
55
+ "returned": 1,
56
+ "start": 0,
57
+ "total": 1
58
+ }
59
+ }
60
+
@@ -0,0 +1,571 @@
1
+ <gogrid>
2
+ <response method="/grid/server/list" status="success">
3
+ <summary total="5" start="0" numpages="0" returned="5" />
4
+ <list>
5
+ <object name="server">
6
+ <attribute name="id">28940</attribute>
7
+ <attribute name="name">bebebe_grid</attribute>
8
+ <attribute name="description"></attribute>
9
+ <attribute name="ip">
10
+ <object name="ip">
11
+ <attribute name="id">619894</attribute>
12
+ <attribute name="ip">173.1.54.221</attribute>
13
+ <attribute name="state">
14
+ <object name="option">
15
+ <attribute name="id">2</attribute>
16
+ <attribute name="name">Assigned</attribute>
17
+ <attribute name="description">IP is reserved or in use</attribute>
18
+ </object>
19
+ </attribute>
20
+ <attribute name="subnet">173.1.54.208/255.255.255.240</attribute>
21
+ <attribute name="public">true</attribute>
22
+ </object>
23
+ </attribute>
24
+ <attribute name="ram">
25
+ <object name="option">
26
+ <attribute name="id">3</attribute>
27
+ <attribute name="name">2GB</attribute>
28
+ <attribute name="description">Server with 2GB RAM</attribute>
29
+ </object>
30
+ </attribute>
31
+ <attribute name="image">
32
+ <object name="serverimage">
33
+ <attribute name="id">64</attribute>
34
+ <attribute name="friendlyName">RHEL 5.1 (32-bit) w/
35
+ Appistry</attribute>
36
+ <attribute name="name">rhel51_32_appistry</attribute>
37
+ <attribute name="os">
38
+ <object name="option">
39
+ <attribute name="id">15</attribute>
40
+ <attribute name="name">RHEL 5.1 (32-bit)</attribute>
41
+ <attribute name="description">RHEL 5.1 (32-bit)</attribute>
42
+ </object>
43
+ </attribute>
44
+ <attribute name="architecture">
45
+ <object name="option">
46
+ <attribute name="id">1</attribute>
47
+ <attribute name="name">32-bit</attribute>
48
+ <attribute name="description">32 bit OS</attribute>
49
+ </object>
50
+ </attribute>
51
+ <attribute name="owner">
52
+ <object name="customer">
53
+ <attribute name="id">-1</attribute>
54
+ <attribute name="name">GoGrid</attribute>
55
+ </object>
56
+ </attribute>
57
+ <attribute name="type">
58
+ <object name="option">
59
+ <attribute name="id">1</attribute>
60
+ <attribute name="name">Web Server</attribute>
61
+ <attribute name="description">Web or Application Server</attribute>
62
+ </object>
63
+ </attribute>
64
+ <attribute name="state">
65
+ <object name="option">
66
+ <attribute name="id">2</attribute>
67
+ <attribute name="name">Available</attribute>
68
+ <attribute name="description">Image is available for
69
+ adds</attribute>
70
+ </object>
71
+ </attribute>
72
+ <attribute name="description">RHEL 5.1 (32-bit) w/
73
+ Appistry</attribute>
74
+ <attribute name="location">
75
+ gogrid/rhel51_32_appistry.img</attribute>
76
+ <attribute name="price">0.0</attribute>
77
+ <attribute name="isActive">true</attribute>
78
+ <attribute name="isPublic">true</attribute>
79
+ <attribute name="createdTime">1235548800000</attribute>
80
+ <attribute name="updatedTime">1246000000000</attribute>
81
+ <attribute name="billingtokens">
82
+ <list>
83
+ <object name="billingtoken">
84
+ <attribute name="id">40</attribute>
85
+ <attribute name="name">RHEL 5.1 32bit</attribute>
86
+ <attribute name="price">0.0</attribute>
87
+ </object>
88
+ <object name="billingtoken">
89
+ <attribute name="id">27</attribute>
90
+ <attribute name="name">Appistry 32-bit</attribute>
91
+ <attribute name="price">0.0</attribute>
92
+ </object>
93
+ </list>
94
+ </attribute>
95
+ </object>
96
+ </attribute>
97
+ <attribute name="state">
98
+ <object name="option">
99
+ <attribute name="id">1</attribute>
100
+ <attribute name="name">Started</attribute>
101
+ <attribute name="description">Server is in active
102
+ state.</attribute>
103
+ </object>
104
+ </attribute>
105
+ <attribute name="type">
106
+ <object name="option">
107
+ <attribute name="id">1</attribute>
108
+ <attribute name="name">Web Server</attribute>
109
+ <attribute name="description">Web or Application Server</attribute>
110
+ </object>
111
+ </attribute>
112
+ <attribute name="os">
113
+ <object name="option">
114
+ <attribute name="id">15</attribute>
115
+ <attribute name="name">RHEL 5.1 (32-bit)</attribute>
116
+ <attribute name="description">RHEL 5.1 (32-bit)</attribute>
117
+ </object>
118
+ </attribute>
119
+ <attribute name="isSandbox">false</attribute>
120
+ </object>
121
+ <object name="server">
122
+ <attribute name="id">28941</attribute>
123
+ <attribute name="name">bebebe_mcom</attribute>
124
+ <attribute name="description"></attribute>
125
+ <attribute name="ip">
126
+ <object name="ip">
127
+ <attribute name="id">619884</attribute>
128
+ <attribute name="ip">173.1.54.211</attribute>
129
+ <attribute name="state">
130
+ <object name="option">
131
+ <attribute name="id">2</attribute>
132
+ <attribute name="name">Assigned</attribute>
133
+ <attribute name="description">IP is reserved or in use</attribute>
134
+ </object>
135
+ </attribute>
136
+ <attribute name="subnet">173.1.54.208/255.255.255.240</attribute>
137
+ <attribute name="public">true</attribute>
138
+ </object>
139
+ </attribute>
140
+ <attribute name="ram">
141
+ <object name="option">
142
+ <attribute name="id">3</attribute>
143
+ <attribute name="name">2GB</attribute>
144
+ <attribute name="description">Server with 2GB RAM</attribute>
145
+ </object>
146
+ </attribute>
147
+ <attribute name="image">
148
+ <object name="serverimage">
149
+ <attribute name="id">64</attribute>
150
+ <attribute name="friendlyName">RHEL 5.1 (32-bit) w/
151
+ Appistry</attribute>
152
+ <attribute name="name">rhel51_32_appistry</attribute>
153
+ <attribute name="os">
154
+ <object name="option">
155
+ <attribute name="id">15</attribute>
156
+ <attribute name="name">RHEL 5.1 (32-bit)</attribute>
157
+ <attribute name="description">RHEL 5.1 (32-bit)</attribute>
158
+ </object>
159
+ </attribute>
160
+ <attribute name="architecture">
161
+ <object name="option">
162
+ <attribute name="id">1</attribute>
163
+ <attribute name="name">32-bit</attribute>
164
+ <attribute name="description">32 bit OS</attribute>
165
+ </object>
166
+ </attribute>
167
+ <attribute name="owner">
168
+ <object name="customer">
169
+ <attribute name="id">-1</attribute>
170
+ <attribute name="name">GoGrid</attribute>
171
+ </object>
172
+ </attribute>
173
+ <attribute name="type">
174
+ <object name="option">
175
+ <attribute name="id">1</attribute>
176
+ <attribute name="name">Web Server</attribute>
177
+ <attribute name="description">Web or Application Server</attribute>
178
+ </object>
179
+ </attribute>
180
+ <attribute name="state">
181
+ <object name="option">
182
+ <attribute name="id">2</attribute>
183
+ <attribute name="name">Available</attribute>
184
+ <attribute name="description">Image is available for
185
+ adds</attribute>
186
+ </object>
187
+ </attribute>
188
+ <attribute name="description">RHEL 5.1 (32-bit) w/
189
+ Appistry</attribute>
190
+ <attribute name="location">
191
+ gogrid/rhel51_32_appistry.img</attribute>
192
+ <attribute name="price">0.0</attribute>
193
+ <attribute name="isActive">true</attribute>
194
+ <attribute name="isPublic">true</attribute>
195
+ <attribute name="createdTime">1235548800000</attribute>
196
+ <attribute name="updatedTime">1246000000000</attribute>
197
+ <attribute name="billingtokens">
198
+ <list>
199
+ <object name="billingtoken">
200
+ <attribute name="id">40</attribute>
201
+ <attribute name="name">RHEL 5.1 32bit</attribute>
202
+ <attribute name="price">0.0</attribute>
203
+ </object>
204
+ <object name="billingtoken">
205
+ <attribute name="id">27</attribute>
206
+ <attribute name="name">Appistry 32-bit</attribute>
207
+ <attribute name="price">0.0</attribute>
208
+ </object>
209
+ </list>
210
+ </attribute>
211
+ </object>
212
+ </attribute>
213
+ <attribute name="state">
214
+ <object name="option">
215
+ <attribute name="id">1</attribute>
216
+ <attribute name="name">Started</attribute>
217
+ <attribute name="description">Server is in active
218
+ state.</attribute>
219
+ </object>
220
+ </attribute>
221
+ <attribute name="type">
222
+ <object name="option">
223
+ <attribute name="id">1</attribute>
224
+ <attribute name="name">Web Server</attribute>
225
+ <attribute name="description">Web or Application Server</attribute>
226
+ </object>
227
+ </attribute>
228
+ <attribute name="os">
229
+ <object name="option">
230
+ <attribute name="id">15</attribute>
231
+ <attribute name="name">RHEL 5.1 (32-bit)</attribute>
232
+ <attribute name="description">RHEL 5.1 (32-bit)</attribute>
233
+ </object>
234
+ </attribute>
235
+ <attribute name="isSandbox">false</attribute>
236
+ </object>
237
+ <object name="server">
238
+ <attribute name="id">31701</attribute>
239
+ <attribute name="name">gd-photon-pg</attribute>
240
+ <attribute name="description"></attribute>
241
+ <attribute name="ip">
242
+ <object name="ip">
243
+ <attribute name="id">619892</attribute>
244
+ <attribute name="ip">173.1.54.219</attribute>
245
+ <attribute name="state">
246
+ <object name="option">
247
+ <attribute name="id">2</attribute>
248
+ <attribute name="name">Assigned</attribute>
249
+ <attribute name="description">IP is reserved or in use</attribute>
250
+ </object>
251
+ </attribute>
252
+ <attribute name="subnet">173.1.54.208/255.255.255.240</attribute>
253
+ <attribute name="public">true</attribute>
254
+ </object>
255
+ </attribute>
256
+ <attribute name="ram">
257
+ <object name="option">
258
+ <attribute name="id">4</attribute>
259
+ <attribute name="name">4GB</attribute>
260
+ <attribute name="description">Server with 4GB RAM</attribute>
261
+ </object>
262
+ </attribute>
263
+ <attribute name="image">
264
+ <object name="serverimage">
265
+ <attribute name="id">25</attribute>
266
+ <attribute name="friendlyName">CentOS 5.1 (64-bit) w/ Apache 2.2 +
267
+ PHP 5.1</attribute>
268
+ <attribute name="name">centos51_64_php</attribute>
269
+ <attribute name="os">
270
+ <object name="option">
271
+ <attribute name="id">10</attribute>
272
+ <attribute name="name">CentOS 5.1 (64-bit)</attribute>
273
+ <attribute name="description">CentOS Linux 5.1 (64-bit)</attribute>
274
+ </object>
275
+ </attribute>
276
+ <attribute name="architecture">
277
+ <object name="option">
278
+ <attribute name="id">2</attribute>
279
+ <attribute name="name">64-bit</attribute>
280
+ <attribute name="description">64 bit OS</attribute>
281
+ </object>
282
+ </attribute>
283
+ <attribute name="owner">
284
+ <object name="customer">
285
+ <attribute name="id">-1</attribute>
286
+ <attribute name="name">GoGrid</attribute>
287
+ </object>
288
+ </attribute>
289
+ <attribute name="type">
290
+ <object name="option">
291
+ <attribute name="id">1</attribute>
292
+ <attribute name="name">Web Server</attribute>
293
+ <attribute name="description">Web or Application Server</attribute>
294
+ </object>
295
+ </attribute>
296
+ <attribute name="state">
297
+ <object name="option">
298
+ <attribute name="id">2</attribute>
299
+ <attribute name="name">Available</attribute>
300
+ <attribute name="description">Image is available for
301
+ adds</attribute>
302
+ </object>
303
+ </attribute>
304
+ <attribute name="description">CentOS 5.1 (64-bit) w/ Apache 2.2 +
305
+ PHP 5.1</attribute>
306
+ <attribute name="location">gogrid/centos51_64_php.img</attribute>
307
+ <attribute name="price">0.0</attribute>
308
+ <attribute name="isActive">true</attribute>
309
+ <attribute name="isPublic">true</attribute>
310
+ <attribute name="createdTime">1212044400000</attribute>
311
+ <attribute name="updatedTime">1246000000000</attribute>
312
+ <attribute name="billingtokens">
313
+ <list>
314
+ <object name="billingtoken">
315
+ <attribute name="id">21</attribute>
316
+ <attribute name="name">CentOS 5.1 64bit</attribute>
317
+ <attribute name="price">0.0</attribute>
318
+ </object>
319
+ </list>
320
+ </attribute>
321
+ </object>
322
+ </attribute>
323
+ <attribute name="state">
324
+ <object name="option">
325
+ <attribute name="id">1</attribute>
326
+ <attribute name="name">Started</attribute>
327
+ <attribute name="description">Server is in active
328
+ state.</attribute>
329
+ </object>
330
+ </attribute>
331
+ <attribute name="type">
332
+ <object name="option">
333
+ <attribute name="id">1</attribute>
334
+ <attribute name="name">Web Server</attribute>
335
+ <attribute name="description">Web or Application Server</attribute>
336
+ </object>
337
+ </attribute>
338
+ <attribute name="os">
339
+ <object name="option">
340
+ <attribute name="id">10</attribute>
341
+ <attribute name="name">CentOS 5.1 (64-bit)</attribute>
342
+ <attribute name="description">CentOS Linux 5.1 (64-bit)</attribute>
343
+ </object>
344
+ </attribute>
345
+ <attribute name="isSandbox">false</attribute>
346
+ </object>
347
+ <object name="server">
348
+ <attribute name="id">35181</attribute>
349
+ <attribute name="name">db2</attribute>
350
+ <attribute name="description"></attribute>
351
+ <attribute name="ip">
352
+ <object name="ip">
353
+ <attribute name="id">619891</attribute>
354
+ <attribute name="ip">173.1.54.218</attribute>
355
+ <attribute name="state">
356
+ <object name="option">
357
+ <attribute name="id">2</attribute>
358
+ <attribute name="name">Assigned</attribute>
359
+ <attribute name="description">IP is reserved or in use</attribute>
360
+ </object>
361
+ </attribute>
362
+ <attribute name="subnet">173.1.54.208/255.255.255.240</attribute>
363
+ <attribute name="public">true</attribute>
364
+ </object>
365
+ </attribute>
366
+ <attribute name="ram">
367
+ <object name="option">
368
+ <attribute name="id">4</attribute>
369
+ <attribute name="name">4GB</attribute>
370
+ <attribute name="description">Server with 4GB RAM</attribute>
371
+ </object>
372
+ </attribute>
373
+ <attribute name="image">
374
+ <object name="serverimage">
375
+ <attribute name="id">24</attribute>
376
+ <attribute name="friendlyName">CentOS 5.1 (64-bit) w/ Apache
377
+ 2.2</attribute>
378
+ <attribute name="name">centos51_64_apache</attribute>
379
+ <attribute name="os">
380
+ <object name="option">
381
+ <attribute name="id">10</attribute>
382
+ <attribute name="name">CentOS 5.1 (64-bit)</attribute>
383
+ <attribute name="description">CentOS Linux 5.1 (64-bit)</attribute>
384
+ </object>
385
+ </attribute>
386
+ <attribute name="architecture">
387
+ <object name="option">
388
+ <attribute name="id">2</attribute>
389
+ <attribute name="name">64-bit</attribute>
390
+ <attribute name="description">64 bit OS</attribute>
391
+ </object>
392
+ </attribute>
393
+ <attribute name="owner">
394
+ <object name="customer">
395
+ <attribute name="id">-1</attribute>
396
+ <attribute name="name">GoGrid</attribute>
397
+ </object>
398
+ </attribute>
399
+ <attribute name="type">
400
+ <object name="option">
401
+ <attribute name="id">1</attribute>
402
+ <attribute name="name">Web Server</attribute>
403
+ <attribute name="description">Web or Application Server</attribute>
404
+ </object>
405
+ </attribute>
406
+ <attribute name="state">
407
+ <object name="option">
408
+ <attribute name="id">2</attribute>
409
+ <attribute name="name">Available</attribute>
410
+ <attribute name="description">Image is available for
411
+ adds</attribute>
412
+ </object>
413
+ </attribute>
414
+ <attribute name="description">CentOS 5.1 (64-bit) w/ Apache
415
+ 2.2</attribute>
416
+ <attribute name="location">
417
+ gogrid/centos51_64_apache.img</attribute>
418
+ <attribute name="price">0.0</attribute>
419
+ <attribute name="isActive">true</attribute>
420
+ <attribute name="isPublic">true</attribute>
421
+ <attribute name="createdTime">1212044400000</attribute>
422
+ <attribute name="updatedTime">1246000000000</attribute>
423
+ <attribute name="billingtokens">
424
+ <list>
425
+ <object name="billingtoken">
426
+ <attribute name="id">21</attribute>
427
+ <attribute name="name">CentOS 5.1 64bit</attribute>
428
+ <attribute name="price">0.0</attribute>
429
+ </object>
430
+ </list>
431
+ </attribute>
432
+ </object>
433
+ </attribute>
434
+ <attribute name="state">
435
+ <object name="option">
436
+ <attribute name="id">1</attribute>
437
+ <attribute name="name">Started</attribute>
438
+ <attribute name="description">Server is in active
439
+ state.</attribute>
440
+ </object>
441
+ </attribute>
442
+ <attribute name="type">
443
+ <object name="option">
444
+ <attribute name="id">1</attribute>
445
+ <attribute name="name">Web Server</attribute>
446
+ <attribute name="description">Web or Application Server</attribute>
447
+ </object>
448
+ </attribute>
449
+ <attribute name="os">
450
+ <object name="option">
451
+ <attribute name="id">10</attribute>
452
+ <attribute name="name">CentOS 5.1 (64-bit)</attribute>
453
+ <attribute name="description">CentOS Linux 5.1 (64-bit)</attribute>
454
+ </object>
455
+ </attribute>
456
+ <attribute name="isSandbox">false</attribute>
457
+ </object>
458
+ <object name="server">
459
+ <attribute name="id">38105</attribute>
460
+ <attribute name="name">brz-tomcat-sprdm-1</attribute>
461
+ <attribute name="description"></attribute>
462
+ <attribute name="ip">
463
+ <object name="ip">
464
+ <attribute name="id">1312606</attribute>
465
+ <attribute name="ip">64.151.85.190</attribute>
466
+ <attribute name="state">
467
+ <object name="option">
468
+ <attribute name="id">2</attribute>
469
+ <attribute name="name">Assigned</attribute>
470
+ <attribute name="description">IP is reserved or in use</attribute>
471
+ </object>
472
+ </attribute>
473
+ <attribute name="subnet">64.151.85.176/255.255.255.240</attribute>
474
+ <attribute name="public">true</attribute>
475
+ </object>
476
+ </attribute>
477
+ <attribute name="ram">
478
+ <object name="option">
479
+ <attribute name="id">4</attribute>
480
+ <attribute name="name">4GB</attribute>
481
+ <attribute name="description">Server with 4GB RAM</attribute>
482
+ </object>
483
+ </attribute>
484
+ <attribute name="image">
485
+ <object name="serverimage">
486
+ <attribute name="id">24</attribute>
487
+ <attribute name="friendlyName">CentOS 5.1 (64-bit) w/ Apache
488
+ 2.2</attribute>
489
+ <attribute name="name">centos51_64_apache</attribute>
490
+ <attribute name="os">
491
+ <object name="option">
492
+ <attribute name="id">10</attribute>
493
+ <attribute name="name">CentOS 5.1 (64-bit)</attribute>
494
+ <attribute name="description">CentOS Linux 5.1 (64-bit)</attribute>
495
+ </object>
496
+ </attribute>
497
+ <attribute name="architecture">
498
+ <object name="option">
499
+ <attribute name="id">2</attribute>
500
+ <attribute name="name">64-bit</attribute>
501
+ <attribute name="description">64 bit OS</attribute>
502
+ </object>
503
+ </attribute>
504
+ <attribute name="owner">
505
+ <object name="customer">
506
+ <attribute name="id">-1</attribute>
507
+ <attribute name="name">GoGrid</attribute>
508
+ </object>
509
+ </attribute>
510
+ <attribute name="type">
511
+ <object name="option">
512
+ <attribute name="id">1</attribute>
513
+ <attribute name="name">Web Server</attribute>
514
+ <attribute name="description">Web or Application Server</attribute>
515
+ </object>
516
+ </attribute>
517
+ <attribute name="state">
518
+ <object name="option">
519
+ <attribute name="id">2</attribute>
520
+ <attribute name="name">Available</attribute>
521
+ <attribute name="description">Image is available for
522
+ adds</attribute>
523
+ </object>
524
+ </attribute>
525
+ <attribute name="description">CentOS 5.1 (64-bit) w/ Apache
526
+ 2.2</attribute>
527
+ <attribute name="location">
528
+ gogrid/centos51_64_apache.img</attribute>
529
+ <attribute name="price">0.0</attribute>
530
+ <attribute name="isActive">true</attribute>
531
+ <attribute name="isPublic">true</attribute>
532
+ <attribute name="createdTime">1212044400000</attribute>
533
+ <attribute name="updatedTime">1246000000000</attribute>
534
+ <attribute name="billingtokens">
535
+ <list>
536
+ <object name="billingtoken">
537
+ <attribute name="id">21</attribute>
538
+ <attribute name="name">CentOS 5.1 64bit</attribute>
539
+ <attribute name="price">0.0</attribute>
540
+ </object>
541
+ </list>
542
+ </attribute>
543
+ </object>
544
+ </attribute>
545
+ <attribute name="state">
546
+ <object name="option">
547
+ <attribute name="id">1</attribute>
548
+ <attribute name="name">Started</attribute>
549
+ <attribute name="description">Server is in active
550
+ state.</attribute>
551
+ </object>
552
+ </attribute>
553
+ <attribute name="type">
554
+ <object name="option">
555
+ <attribute name="id">1</attribute>
556
+ <attribute name="name">Web Server</attribute>
557
+ <attribute name="description">Web or Application Server</attribute>
558
+ </object>
559
+ </attribute>
560
+ <attribute name="os">
561
+ <object name="option">
562
+ <attribute name="id">10</attribute>
563
+ <attribute name="name">CentOS 5.1 (64-bit)</attribute>
564
+ <attribute name="description">CentOS Linux 5.1 (64-bit)</attribute>
565
+ </object>
566
+ </attribute>
567
+ <attribute name="isSandbox">false</attribute>
568
+ </object>
569
+ </list>
570
+ </response>
571
+ </gogrid>
@@ -0,0 +1,72 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe GoGridManager do
4
+ # {{{1 GoGridManager initialization
5
+
6
+ describe "when creating a manager" do
7
+ before do
8
+ stub(File).read(File.expand_path("~/.ghrc")) { "config dump" }
9
+ stub(YAML).load("config dump") { config_data }
10
+ end
11
+
12
+ it "should create a GoGridClient with given to manager credentials" do
13
+ mock(GoGridClient).new("key", "secret")
14
+ manager = GoGridManager.new("key", "secret")
15
+ end
16
+
17
+ it "should load config for 1st account from ~/.ghrc if no params given" do
18
+ mock(File).read(File.expand_path("~/.ghrc")) { "config dump" }
19
+ mock(YAML).load("config dump") { config_data }
20
+ mock(GoGridClient).new("key", "secret")
21
+ manager = GoGridManager.new(nil, nil)
22
+ end
23
+
24
+ it "should load config for given account if this data presents in config" do
25
+ mock(GoGridClient).new("key2", "secret2")
26
+ manager = GoGridManager.new("acc2", nil)
27
+ end
28
+
29
+ end
30
+
31
+ def config_data
32
+ [
33
+ {:account => "acc", :apikey => "key", :secret => "secret"},
34
+ {:account => "acc2", :apikey => "key2", :secret => "secret2"},
35
+ {:account => "acc3", :apikey => "key3", :secret => "secret3"}
36
+ ]
37
+ end
38
+
39
+ # }}}
40
+ # {{{1 list_servers methods
41
+ describe "when calling list_servers" do
42
+ before do
43
+ @manager = GoGridManager.new("key", "secret")
44
+ stub(@manager.client).send_api_request("grid/server/list") { SERVERS }
45
+ end
46
+
47
+ it "should send grid/server/list request" do
48
+ mock(@manager.client).send_api_request("grid/server/list") { SERVERS }
49
+ @manager.list_servers
50
+ end
51
+
52
+ it "should parse JSON from response" do
53
+ hash = {}
54
+ mock(JSON).parse(SERVERS) { hash }
55
+ stub(hash).list
56
+ @manager.list_servers
57
+ end
58
+
59
+ it "should return an array of servers of servers" do
60
+ @manager.list_servers.should be_instance_of(Array)
61
+ end
62
+
63
+ it "should return non-empty array for given fixture" do
64
+ @manager.list_servers.should_not be_empty
65
+ end
66
+
67
+ it "should have a Sandbox Server as a first server in response" do
68
+ @manager.list_servers.first.name.should == "Sandbox Server"
69
+ end
70
+ end
71
+ # }}}
72
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Hash do
4
+ it "should allow to access hash value via dot notation" do
5
+ h = { 'key' => 'value' }
6
+ h.key.should == 'value'
7
+ end
8
+
9
+ it "should not patch symbol keys" do
10
+ h = { :key => 'value' }
11
+
12
+ lambda { h.key.should == 'value' }.should raise_error(NoMethodError)
13
+ end
14
+
15
+ it "should access to caleCase named keys using gnu_style accessor" do
16
+ h = { 'camelCasedKey' => 42 }
17
+ h.camel_cased_key.should == 42
18
+ end
19
+ end
20
+
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'grate-handle'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+ require 'fixtures/all'
7
+
8
+ Spec::Runner.configure do |config|
9
+ config.mock_with :rr
10
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grate-handle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kirill Ishanov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-25 00:00:00 +04:00
13
+ default_executable: gh
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: jeweler
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: json
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description: " Grate Handle is a small gem which simplifies the with GoGrid's API from ruby code. Also ships with a CLI tool called 'gh' which allows to perform most of the actions from http://my.gogrid.com but using true Unix CLI way. "
46
+ email: kirill.ishanov@gmail.com
47
+ executables:
48
+ - gh
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ files:
55
+ - .document
56
+ - .gitignore
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - VERSION
61
+ - bin/gh
62
+ - grate-handle.gemspec
63
+ - lib/cli_processor.rb
64
+ - lib/gogrid_client.rb
65
+ - lib/gogrid_manager.rb
66
+ - lib/grate-handle.rb
67
+ - lib/monkey_patches.rb
68
+ - spec/cli_processor_spec.rb
69
+ - spec/fixtures/all.rb
70
+ - spec/fixtures/grid_server_list.json
71
+ - spec/fixtures/grid_server_list.xml
72
+ - spec/gogrid_manager_spec.rb
73
+ - spec/monkey_patches_spec.rb
74
+ - spec/spec_helper.rb
75
+ has_rdoc: true
76
+ homepage: http://github.com/kylichuku/grate-handle
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options:
81
+ - --charset=UTF-8
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.3.3
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: A ruby library and a CLI client to GoGrid API
103
+ test_files:
104
+ - spec/gogrid_manager_spec.rb
105
+ - spec/spec_helper.rb
106
+ - spec/monkey_patches_spec.rb
107
+ - spec/fixtures/all.rb
108
+ - spec/cli_processor_spec.rb