pearl 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/pearl/cli.rb +10 -10
- data/lib/pearl/client/droplets.rb +33 -16
- data/lib/pearl/client/images.rb +11 -7
- data/lib/pearl/client/regions.rb +2 -1
- data/lib/pearl/client/sizes.rb +2 -1
- data/lib/pearl/client.rb +5 -0
- data/lib/pearl/pretty_table.rb +58 -0
- data/lib/pearl/version.rb +1 -1
- data/pearl.gemspec +2 -0
- data/test/pearl/client_test.rb +2 -2
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dca946b28b42b66b4d14e151a63e531eed171186
|
4
|
+
data.tar.gz: df773866825fe4c6cc331f65debd8365207b86d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd0f02927c45e95d4fafd8703113e5743d3fe681c559361fe3d3bb2d8c6ed24353caff0626fa025414bd9990af8c3f6685a4c6099a2db59eb73f742bfa03cab5
|
7
|
+
data.tar.gz: 964a75eaef276a34de3f1913722abb3a36a7d563589c84db3e32033d1b8ea8ff2b1d4e08c82a7d8d43cf70e543dec43933604928af7c6c6cb75338b690080777
|
data/README.md
CHANGED
@@ -27,11 +27,11 @@ To view a droplet
|
|
27
27
|
|
28
28
|
To create a droplet
|
29
29
|
|
30
|
-
$ pearl droplet add
|
30
|
+
$ pearl droplet add <name> --size <size id> --image <image id> --region <region id>
|
31
31
|
|
32
32
|
or
|
33
33
|
|
34
|
-
$ pearl droplet add
|
34
|
+
$ pearl droplet add <name> -s <size id> -i <image id> -r <region id>
|
35
35
|
|
36
36
|
Reboot a droplet
|
37
37
|
|
@@ -63,7 +63,7 @@ Resize droplet
|
|
63
63
|
|
64
64
|
Take a snapshot
|
65
65
|
|
66
|
-
$ pearl droplet snapshot
|
66
|
+
$ pearl droplet snapshot <snapshot name> -d <droplet id>
|
67
67
|
|
68
68
|
Restore droplet
|
69
69
|
|
@@ -105,11 +105,11 @@ Display all images
|
|
105
105
|
|
106
106
|
To display your images
|
107
107
|
|
108
|
-
$ pearl images
|
108
|
+
$ pearl images my
|
109
109
|
|
110
110
|
To display global images (default)
|
111
111
|
|
112
|
-
$ pearl images
|
112
|
+
$ pearl images global
|
113
113
|
|
114
114
|
View a single image
|
115
115
|
|
@@ -121,7 +121,7 @@ To destroy an image
|
|
121
121
|
|
122
122
|
## TODO
|
123
123
|
|
124
|
-
* Format output instead of just printing the json response
|
124
|
+
* ~~Format output instead of just printing the json response.~~
|
125
125
|
* Add SSH resource.
|
126
126
|
|
127
127
|
## Contributing
|
data/lib/pearl/cli.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'optparse'
|
2
2
|
|
3
3
|
require 'pearl'
|
4
4
|
|
@@ -11,8 +11,6 @@ module Pearl
|
|
11
11
|
region = nil
|
12
12
|
size = nil
|
13
13
|
|
14
|
-
images_filter = nil
|
15
|
-
|
16
14
|
opts = OptionParser.new do |opts|
|
17
15
|
opts.banner = "Usage: pearl [resource] [options]"
|
18
16
|
|
@@ -20,10 +18,6 @@ module Pearl
|
|
20
18
|
droplet = d
|
21
19
|
end
|
22
20
|
|
23
|
-
opts.on('-f', '--filter', 'Display either your images or global images') do |filter|
|
24
|
-
images_filter = filter
|
25
|
-
end
|
26
|
-
|
27
21
|
opts.on('-h', '--help', 'Display this message') do
|
28
22
|
puts opts
|
29
23
|
exit
|
@@ -132,11 +126,11 @@ module Pearl
|
|
132
126
|
|
133
127
|
Pearl.resize(droplet_id, size_id)
|
134
128
|
exit
|
135
|
-
when /\Adroplet snapshot \w{3,}\z/i
|
129
|
+
when /\Adroplet snapshot [\w\s]{3,}\z/i
|
136
130
|
droplet_id = droplet.to_i
|
137
131
|
raise 'Error: Invalid droplet id.' if droplet_id == 0 || !droplet_id.is_a?(Fixnum)
|
138
132
|
|
139
|
-
name = command.split(' ', 2
|
133
|
+
name = command.split(' ', 3)[2]
|
140
134
|
raise 'Error: Invalid snapshot name.' if name.nil? || name.length <= 0
|
141
135
|
|
142
136
|
Pearl.snapshot(droplet_id, name)
|
@@ -178,7 +172,13 @@ module Pearl
|
|
178
172
|
Pearl.destroy_droplet(droplet_id)
|
179
173
|
exit
|
180
174
|
when /\Aimages\z/i
|
181
|
-
Pearl.images
|
175
|
+
Pearl.images
|
176
|
+
exit
|
177
|
+
when /\Aimages my\z/i
|
178
|
+
Pearl.images('my_images')
|
179
|
+
exit
|
180
|
+
when /\Aimages global\z/i
|
181
|
+
Pearl.images('global')
|
182
182
|
exit
|
183
183
|
when /\Aimage\z/i
|
184
184
|
image_id = image.to_i
|
@@ -3,11 +3,13 @@ module Pearl
|
|
3
3
|
|
4
4
|
module Droplets
|
5
5
|
def droplets
|
6
|
-
|
6
|
+
response = request("droplets").body
|
7
|
+
pretty_table("Droplets", response)
|
7
8
|
end
|
8
9
|
|
9
10
|
def droplet(id)
|
10
|
-
|
11
|
+
response = request("droplets/#{id}").body
|
12
|
+
pretty_table('Droplet', response)
|
11
13
|
end
|
12
14
|
|
13
15
|
def create_droplet(options = {})
|
@@ -16,63 +18,78 @@ module Pearl
|
|
16
18
|
image_id: options[:image_id],
|
17
19
|
region_id: options[:region_id]
|
18
20
|
}
|
19
|
-
|
21
|
+
response = request("droplets/new", params).body
|
22
|
+
pretty_table("Droplet", response)
|
20
23
|
end
|
21
24
|
|
22
25
|
def reboot(id)
|
23
|
-
|
26
|
+
response = request("droplets/#{id}/reboot").body
|
27
|
+
pretty_event("Rebooting droplet #{id}", response)
|
24
28
|
end
|
25
29
|
|
26
30
|
def power_cycle(id)
|
27
|
-
|
31
|
+
response = request("droplets/#{id}/power_cycle").body
|
32
|
+
pretty_event("Power cycling droplet #{id}", response)
|
28
33
|
end
|
29
34
|
|
30
35
|
def shutdown(id)
|
31
|
-
|
36
|
+
response = request("droplets/#{id}/shutdown").body
|
37
|
+
pretty_event("Shuting down droplet #{id}", response)
|
32
38
|
end
|
33
39
|
|
34
40
|
def power_off(id)
|
35
|
-
|
41
|
+
response = request("droplets/#{id}/power_off").body
|
42
|
+
pretty_event("Powering off droplet #{id}", response)
|
36
43
|
end
|
37
44
|
|
38
45
|
def power_on(id)
|
39
|
-
|
46
|
+
response = request("droplets/#{id}/power_on").body
|
47
|
+
pretty_event("Powering on droplet #{id}", response)
|
40
48
|
end
|
41
49
|
|
42
50
|
def password_reset(id)
|
43
|
-
|
51
|
+
response = request("droplets/#{id}/password_reset").body
|
52
|
+
pretty_event("Resetting password for droplet #{id}", response)
|
44
53
|
end
|
45
54
|
|
46
55
|
def resize(id, size_id)
|
47
56
|
params = { size_id: size_id }
|
48
|
-
|
57
|
+
response = request("droplets/#{id}/resize", params).body
|
58
|
+
pretty_event("Resizing droplet #{id}", response)
|
49
59
|
end
|
50
60
|
|
51
61
|
def snapshot(id, name)
|
62
|
+
puts name
|
52
63
|
params = { name: name }
|
53
|
-
|
64
|
+
response = request("droplets/#{id}/snapshot", params).body
|
65
|
+
pretty_event("Creating snapshot '#{name}' of droplet #{id}", response)
|
54
66
|
end
|
55
67
|
|
56
68
|
def restore(id, image_id)
|
57
69
|
params = { image_id: image_id }
|
58
|
-
|
70
|
+
response = request("droplets/#{id}/restore", params).body
|
71
|
+
pretty_event("Restoring droplet #{id}", response)
|
59
72
|
end
|
60
73
|
|
61
74
|
def rebuild(id, image_id)
|
62
75
|
params = { image_id: image_id }
|
63
|
-
|
76
|
+
response = request("droplets/#{id}/rebuild", params).body
|
77
|
+
pretty_event("Rebuilding droplet #{id}", response)
|
64
78
|
end
|
65
79
|
|
66
80
|
def enable_backups(id)
|
67
|
-
|
81
|
+
response = request("droplets/#{id}/enable_backups").body
|
82
|
+
pretty_event("Enabling auto backups for droplet #{id}", response)
|
68
83
|
end
|
69
84
|
|
70
85
|
def disable_backups(id)
|
71
|
-
|
86
|
+
response = request("droplets/#{id}/disable_backups").body
|
87
|
+
pretty_event("Disabling auto backups for droplet #{id}", response)
|
72
88
|
end
|
73
89
|
|
74
90
|
def destroy_droplet(id)
|
75
|
-
|
91
|
+
response = request("droplets/#{id}/destroy").body
|
92
|
+
pretty_event("Destroying droplet #{id}", response)
|
76
93
|
end
|
77
94
|
end
|
78
95
|
end
|
data/lib/pearl/client/images.rb
CHANGED
@@ -3,21 +3,25 @@ module Pearl
|
|
3
3
|
|
4
4
|
module Images
|
5
5
|
# TODO: image filters
|
6
|
-
def images(filter)
|
7
|
-
if
|
8
|
-
params = { filter:
|
9
|
-
|
6
|
+
def images(filter='')
|
7
|
+
if /\A(my_images|global)\z/ === filter
|
8
|
+
params = { filter: filter }
|
9
|
+
response = request("images", params).body
|
10
10
|
else
|
11
|
-
|
11
|
+
response = request("images").body
|
12
12
|
end
|
13
|
+
|
14
|
+
pretty_table("Images", response)
|
13
15
|
end
|
14
16
|
|
15
17
|
def image(id)
|
16
|
-
|
18
|
+
response = request("images/#{id}").body
|
19
|
+
pretty_table("Image", response)
|
17
20
|
end
|
18
21
|
|
19
22
|
def destroy_image(id)
|
20
|
-
|
23
|
+
response = request("images/#{id}").body
|
24
|
+
pretty_table("Image", response)
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
data/lib/pearl/client/regions.rb
CHANGED
data/lib/pearl/client/sizes.rb
CHANGED
data/lib/pearl/client.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
1
3
|
require 'pearl/http'
|
4
|
+
require 'pearl/pretty_table'
|
2
5
|
|
3
6
|
module Pearl
|
4
7
|
class Client
|
@@ -9,6 +12,8 @@ module Pearl
|
|
9
12
|
include Regions
|
10
13
|
include Sizes
|
11
14
|
|
15
|
+
include PrettyTable
|
16
|
+
|
12
17
|
attr_reader :client_id
|
13
18
|
attr_reader :api_key
|
14
19
|
attr_reader :api_host
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'terminal-table'
|
2
|
+
|
3
|
+
module Pearl
|
4
|
+
module PrettyTable
|
5
|
+
def pretty_table(heading, data)
|
6
|
+
# Convert JSON response into a hash for easier parsing
|
7
|
+
tmp = MultiJson.load(data, symbolize_keys: true)
|
8
|
+
|
9
|
+
# Convert the heading to a symbol and pull the required data
|
10
|
+
symbolized_heading = heading.downcase.gsub(/\s+/, "_").to_sym
|
11
|
+
|
12
|
+
if tmp[symbolized_heading].empty?
|
13
|
+
puts "No #{heading.downcase} found."
|
14
|
+
return
|
15
|
+
end
|
16
|
+
|
17
|
+
# Single objects such as a droplet and an image are not enclosed in
|
18
|
+
# an array.
|
19
|
+
if tmp[symbolized_heading].is_a?(Hash)
|
20
|
+
tmp[symbolized_heading] = [tmp[symbolized_heading]]
|
21
|
+
end
|
22
|
+
|
23
|
+
# Build row headings from the hash keys
|
24
|
+
row_headings = tmp[symbolized_heading].first.keys
|
25
|
+
|
26
|
+
# Sort images in alphabetical order
|
27
|
+
if symbolized_heading == :images
|
28
|
+
tmp[symbolized_heading].sort_by! { |h| h[:name] }
|
29
|
+
end
|
30
|
+
|
31
|
+
# Loop through each array element and get the values
|
32
|
+
rows = []
|
33
|
+
tmp[symbolized_heading].each do |row|
|
34
|
+
rows << row.values
|
35
|
+
end
|
36
|
+
|
37
|
+
table = Terminal::Table.new title: heading, headings: row_headings, rows: rows
|
38
|
+
puts table
|
39
|
+
end
|
40
|
+
|
41
|
+
# Just for events. Eg. When restarting a droplet
|
42
|
+
def pretty_event(heading = '', data)
|
43
|
+
# Convert JSON response into a hash for easier parsing
|
44
|
+
tmp = MultiJson.load(data, symbolize_keys: true)
|
45
|
+
|
46
|
+
if tmp[:event_id].nil?
|
47
|
+
puts "No #{heading.downcase} found."
|
48
|
+
return
|
49
|
+
end
|
50
|
+
|
51
|
+
rows = []
|
52
|
+
rows << [tmp[:status], tmp[:event_id]]
|
53
|
+
|
54
|
+
table = Terminal::Table.new title: heading, headings: ['Status', 'Event ID'], rows: rows
|
55
|
+
puts table
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/pearl/version.rb
CHANGED
data/pearl.gemspec
CHANGED
data/test/pearl/client_test.rb
CHANGED
@@ -11,8 +11,8 @@ class ClientTest < Pearl::TestCase
|
|
11
11
|
client = Pearl::Client.new(client_id: 'qwerty', api_key: 'ytrewq')
|
12
12
|
assert_equal true, client.authenticated?
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
# TODO
|
15
|
+
# assert_raises(Pearl::Error) { Pearl::Client.new }
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_base_url
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pearl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manish Valechha
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: multi_json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.6.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.6.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: terminal-table
|
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'
|
41
69
|
description: Command line interface for DigitalOcean's API
|
42
70
|
email:
|
43
71
|
- manishval@hotmail.com
|
@@ -61,6 +89,7 @@ files:
|
|
61
89
|
- lib/pearl/client/sizes.rb
|
62
90
|
- lib/pearl/error.rb
|
63
91
|
- lib/pearl/http.rb
|
92
|
+
- lib/pearl/pretty_table.rb
|
64
93
|
- lib/pearl/version.rb
|
65
94
|
- pearl.gemspec
|
66
95
|
- test/pearl/client/droplets_test.rb
|