grate-handle 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,59 @@
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
+ == Getting Started
8
+
9
+ First install grate-handle.
10
+
11
+ <pre>
12
+ <code>
13
+ sudo gem install grate-handle
14
+ </code>
15
+ </pre>
16
+
17
+ Then create a .ghrc file in your home directory. This file will store the GoGrid's API credentials. It's a YAML file, so the structure will look like this:
18
+
19
+ <pre>
20
+ <code>
21
+ % cat ~/.ghrc
22
+ ---
23
+ - account: default
24
+ apikey: YOUR_APIKEY
25
+ secret: YOUR_SECRET
26
+ </code>
27
+ </pre>
28
+
29
+ After putting correct credentials into config file it's good to synchronize the time with internet, cause GoGrid uses timestamps in API
30
+
31
+ <pre>
32
+ <code>
33
+ % cat ~/.ghrc
34
+ ---
35
+ - account: kishanov
36
+ apikey: 12d957fd52ac93e7
37
+ secret: bebebe
38
+ </code>
39
+ </pre>
40
+
41
+ Finally, you can run gh command to see the usage. Now you are ready to work with GoGrid using CLI!
42
+
43
+ <pre>
44
+ <code>
45
+ % gh
46
+ usage: gh ACTION ENTITY [ARGS]
47
+
48
+ Note that not all ACTIONs applicable to every ENTITY.
49
+ Available combinations are:
50
+ list servers Shows all servers in all states
51
+ list images Shows all available server images (both legacy and MyGSI)
52
+ list passwords Shows root login credentials for all servers
53
+ list ips Shows all all ips in all states of all types.
54
+ </code>
55
+ </pre>
56
+
57
+ == Copyright
58
+
59
+ Copyright (c) 2009 Kirill Ishanov. See LICENSE for details.
@@ -4,6 +4,56 @@ Grate Handle is a ruby library and a CLI tool which simplify work with [GoGrid](
4
4
 
5
5
  Currently Grate Handle is under lazy development, but I hope that it will become usable in a couple of weeks.
6
6
 
7
+ == Getting Started
8
+
9
+ First install grate-handle.
10
+
11
+ <pre>
12
+ <code>
13
+ sudo gem install grate-handle
14
+ </code>
15
+ </pre>
16
+
17
+ Then create a .ghrc file in your home directory. This file will store the GoGrid's API credentials. It's a YAML file, so the structure will look like this:
18
+
19
+ <pre>
20
+ <code>
21
+ % cat ~/.ghrc
22
+ ---
23
+ - account: default
24
+ apikey: YOUR_APIKEY
25
+ secret: YOUR_SECRET
26
+ </code>
27
+ </pre>
28
+
29
+ After putting correct credentials into config file it's good to synchronize the time with internet, cause GoGrid uses timestamps in API
30
+
31
+ <pre>
32
+ <code>
33
+ % cat ~/.ghrc
34
+ ---
35
+ - account: kishanov
36
+ apikey: 12d957fd52ac93e7
37
+ secret: bebebe
38
+ </code>
39
+ </pre>
40
+
41
+ Finally, you can run gh command to see the usage. Now you are ready to work with GoGrid using CLI!
42
+
43
+ <pre>
44
+ <code>
45
+ % gh
46
+ usage: gh ACTION ENTITY [ARGS]
47
+
48
+ Note that not all ACTIONs applicable to every ENTITY.
49
+ Available combinations are:
50
+ list servers Shows all servers in all states
51
+ list images Shows all available server images (both legacy and MyGSI)
52
+ list passwords Shows root login credentials for all servers
53
+ list ips Shows all all ips in all states of all types.
54
+ </code>
55
+ </pre>
56
+
7
57
  == Copyright
8
58
 
9
59
  Copyright (c) 2009 Kirill Ishanov. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,23 +5,25 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{grate-handle}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kirill Ishanov"]
12
- s.date = %q{2009-08-25}
12
+ s.date = %q{2009-08-26}
13
13
  s.default_executable = %q{gh}
14
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
15
  s.email = %q{kirill.ishanov@gmail.com}
16
16
  s.executables = ["gh"]
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE",
19
+ "README.md",
19
20
  "README.rdoc"
20
21
  ]
21
22
  s.files = [
22
23
  ".document",
23
24
  ".gitignore",
24
25
  "LICENSE",
26
+ "README.md",
25
27
  "README.rdoc",
26
28
  "Rakefile",
27
29
  "VERSION",
@@ -2,36 +2,84 @@ require 'gogrid_manager'
2
2
 
3
3
  module GrateHandle
4
4
  class CLIProcessor
5
+ #{{{1 Initialization and accessors
5
6
  attr_writer :manager
6
7
 
7
- def initialize(args, out=STDOUT, manager=GoGridManager.new)
8
+ def initialize(args, manager=GoGridManager.new, out=STDOUT)
8
9
  @args = args
10
+ @extra_params = {}
9
11
  @out = out
10
12
  @manager = manager
11
13
  end
12
-
14
+ #}}}
15
+ #{{{1 Ugly Options processing
13
16
  def process
14
17
  case @args.shift(1).first
15
- when 'list':
16
- list
17
- else
18
- @out.puts "unknown action"
18
+ when 'list' then list_action
19
+ when 'help', nil then print_usage
20
+ else @out.puts "unknown action"
19
21
  end
20
22
  end
21
23
 
22
- def list
24
+ def list_action
23
25
  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"
26
+ when 'servers' then print_servers
27
+ when 'images' then print_images
28
+ when 'ips' then print_ips
29
+ when 'passwords' then print_passwords
30
+ when 'help', nil then print_usage
31
+ else print_list_error
32
+ end
33
+ end
34
+ #}}}
35
+ #{{{1 Help Messages
36
+ def print_list_error
37
+ @out.puts "Unknown command. Please check gh help for the list of available commands"
38
+ end
39
+
40
+ def print_usage
41
+ # don't like multilines strings, sorry
42
+ usage = []
43
+ usage << 'usage: gh ACTION ENTITY [ARGS]'
44
+ usage << ''
45
+ usage << 'Note that not all ACTIONs applicable to every ENTITY.'
46
+ usage << 'Available combinations are:'
47
+
48
+ actions = []
49
+ actions << ['list servers', 'Shows all servers in all states']
50
+ actions << ['list images', 'Shows all available server images (both legacy and MyGSI)']
51
+ actions << ['list passwords', 'Shows root login credentials for all servers']
52
+ actions << ['list ips', 'Shows all all ips in all states of all types.']
53
+
54
+ actions.map! { |action| sprintf("\t%-20s%s", action[0], action[1]) }
55
+
56
+ (usage + actions).each { |line| @out.puts line }
57
+ end
58
+ #}}}
59
+ #{{{1 listings print
60
+ def print_images
61
+ @manager.list_images.each do |image|
62
+ @out.puts(sprintf("%-5s\t%s", image.id, image.name))
63
+ end
64
+ end
65
+
66
+ def print_servers
67
+ @manager.list_servers.each do |server|
68
+ @out.puts(sprintf("%-6s\t%-20s\t%-15s\t%s", server.id, server.name, server.ip.ip, server.state.name))
69
+ end
70
+ end
71
+
72
+ def print_ips
73
+ @manager.list_ips.each do |ip|
74
+ @out.puts(sprintf("%-15s\t%-7s\t%s", ip.ip, (ip.public ? "Public" : "Private"), ip.state.name))
75
+ end
76
+ end
77
+
78
+ def print_passwords
79
+ @manager.list_passwords.each do |passwd|
80
+ @out.puts(sprintf("%-20s\t%s@%-15s\t%s", passwd.server.name, passwd.username, passwd.server.ip.ip, passwd.password)) if passwd.has_key?('server') # hack against CloudStorage
34
81
  end
35
82
  end
83
+ #}}}
36
84
  end
37
85
  end
@@ -32,11 +32,27 @@ module GrateHandle
32
32
 
33
33
  public
34
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
35
+ def list_servers
36
+ list_request_for 'grid/server/list'
37
+ end
38
+
39
+ def list_images
40
+ list_request_for 'grid/image/list'
41
+ end
42
+
43
+ def list_ips
44
+ list_request_for 'grid/ip/list'
45
+ end
46
+
47
+ def list_passwords
48
+ list_request_for 'support/password/list'
49
+ end
50
+
51
+ private
52
+
53
+ def list_request_for(url, extra_params={})
54
+ response = @client.send_api_request(url, extra_params)
55
+ JSON.parse(response).list
40
56
  end
41
57
 
42
58
  # }}}
@@ -1,13 +1,61 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe CLIProcessor do
4
+ #{{{1 list servers
4
5
  describe "list servers" do
5
- #before do
6
- #@cli = CLIProcessor.new(%w(list servers), mock!, mock!.list_servers.subject { SERVERS } )
7
- #end
6
+ before do
7
+ stub(STDOUT).puts
8
+ @servers = [{
9
+ 'id' => '123',
10
+ 'name' => 'myserver',
11
+ 'ip' => { 'ip' => '1.1.1.1' },
12
+ 'state' => { 'name' => 'started' }
13
+ }]
14
+ end
8
15
 
9
- #it "should call list_servers on GoGridManager" do
10
- #@cli.process
11
- #end
16
+ it "should call list_servers on GoGridManager" do
17
+ manager = mock!.list_servers { @servers }.subject
18
+ command = %w(list servers)
19
+ cli = CLIProcessor.new(command, manager)
20
+ cli.process
21
+ end
12
22
  end
23
+ #}}}
24
+ #{{{1 list ips
25
+ describe "list ips" do
26
+ before do
27
+ stub(STDOUT).puts
28
+ @ips = [{
29
+ 'ip' => '1.1.1.1',
30
+ 'public' => true,
31
+ 'state' => { 'name' => 'assigned' }
32
+ }]
33
+ end
34
+
35
+ it "should call list_ips on GoGridManager" do
36
+ manager = mock!.list_ips { @ips }.subject
37
+ command = %w(list ips)
38
+ cli = CLIProcessor.new(command, manager)
39
+ cli.process
40
+ end
41
+ end
42
+ #}}}
43
+ #{{{1 list images
44
+ describe "list ips" do
45
+ before do
46
+ stub(STDOUT).puts
47
+ @images = [{
48
+ 'id' => '123',
49
+ 'name' => 'my super image'
50
+ }]
51
+ end
52
+
53
+ it "should call list_images on GoGridManager" do
54
+ manager = mock!.list_images { @images }.subject
55
+ command = %w(list images)
56
+ cli = CLIProcessor.new(command, manager)
57
+ cli.process
58
+ end
59
+ end
60
+ #}}}
13
61
  end
@@ -17,8 +17,8 @@ describe GoGridManager do
17
17
  it "should load config for 1st account from ~/.ghrc if no params given" do
18
18
  mock(File).read(File.expand_path("~/.ghrc")) { "config dump" }
19
19
  mock(YAML).load("config dump") { config_data }
20
- mock(GoGridClient).new("key", "secret")
21
- manager = GoGridManager.new(nil, nil)
20
+ mock(GoGridClient).new('key', 'secret')
21
+ manager = GoGridManager.new()
22
22
  end
23
23
 
24
24
  it "should load config for given account if this data presents in config" do
@@ -30,9 +30,9 @@ describe GoGridManager do
30
30
 
31
31
  def config_data
32
32
  [
33
- {:account => "acc", :apikey => "key", :secret => "secret"},
34
- {:account => "acc2", :apikey => "key2", :secret => "secret2"},
35
- {:account => "acc3", :apikey => "key3", :secret => "secret3"}
33
+ {'account' => "acc", 'apikey' => "key", 'secret' => "secret"},
34
+ {'account' => "acc2", 'apikey' => "key2", 'secret' => "secret2"},
35
+ {'account' => "acc3", 'apikey' => "key3", 'secret' => "secret3"}
36
36
  ]
37
37
  end
38
38
 
@@ -41,11 +41,11 @@ describe GoGridManager do
41
41
  describe "when calling list_servers" do
42
42
  before do
43
43
  @manager = GoGridManager.new("key", "secret")
44
- stub(@manager.client).send_api_request("grid/server/list") { SERVERS }
44
+ stub(@manager.client).send_api_request("grid/server/list", {}) { SERVERS }
45
45
  end
46
46
 
47
47
  it "should send grid/server/list request" do
48
- mock(@manager.client).send_api_request("grid/server/list") { SERVERS }
48
+ mock(@manager.client).send_api_request("grid/server/list", {}) { SERVERS }
49
49
  @manager.list_servers
50
50
  end
51
51
 
@@ -56,7 +56,7 @@ describe GoGridManager do
56
56
  @manager.list_servers
57
57
  end
58
58
 
59
- it "should return an array of servers of servers" do
59
+ it "should return an array of servers" do
60
60
  @manager.list_servers.should be_instance_of(Array)
61
61
  end
62
62
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grate-handle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Ishanov
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-25 00:00:00 +04:00
12
+ date: 2009-08-26 00:00:00 +04:00
13
13
  default_executable: gh
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -50,11 +50,13 @@ extensions: []
50
50
 
51
51
  extra_rdoc_files:
52
52
  - LICENSE
53
+ - README.md
53
54
  - README.rdoc
54
55
  files:
55
56
  - .document
56
57
  - .gitignore
57
58
  - LICENSE
59
+ - README.md
58
60
  - README.rdoc
59
61
  - Rakefile
60
62
  - VERSION