oc 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8c675dab6b5a469592212d2cae2bf838c2479c8
4
- data.tar.gz: 69ac67a33df1cb23a73c062071a0f6c71b6095a3
3
+ metadata.gz: b98d817e68a5690c2cd2d1511b8badea6b72759f
4
+ data.tar.gz: 3eb56af2f8165d2a5b5ea7763311fc81a0d9e62d
5
5
  SHA512:
6
- metadata.gz: bdd475186317b967f0291b0ad00a290f669319cd68174ecb363b77324a2935412aa73fb3b94d29d1fc1cde83ee2e759999f46ff5fd1acff3ee60ffecc3413fa9
7
- data.tar.gz: 06509921c99148cfa94ddfa46f029779dac2da30950e3d3dc83ca9a100d9bbe8b2f113f18d18fac6a4dd34e5644e3f469297e675e23f1c192d95dd34ccecc03f
6
+ metadata.gz: 0e9cfdf198467e7a7e2f5c6f126d4f096c12615d64e9f2761c402af81117ed7f2a6aee30fcdcc3ae53759d04edebd1a2edba970a881a8a57309c5f3083fd8a44
7
+ data.tar.gz: 73d81d96dff19405f4769bea55000136e259a4b114dc2f60ca084b927df73d946358398af7291a2a1b631354099215b3257726c9c02f970d23a8a74f2a2ff038
data/lib/oc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Oc
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -6,11 +6,9 @@ class Oc::Run::Base
6
6
  return if self == Oc::Run::Base
7
7
  return if private_method_defined? method
8
8
  return if protected_method_defined? method
9
-
10
9
  prefix = self.get_object_name
11
10
  method_name = method.to_s == 'run' ? nil : method.to_s.gsub('_','-')
12
11
  name = [prefix, method_name].compact
13
-
14
12
  Oc::Run.add({
15
13
  :name => name,
16
14
  :class => self,
@@ -4,13 +4,10 @@ require 'commander/import'
4
4
  module Oc
5
5
  class Runner
6
6
  def self.start
7
-
8
7
  program :name, 'Digital Ocean Client'
9
8
  program :version, Oc::VERSION
10
9
  program :description, 'Digital Ocean Command Line Tools'
11
-
12
10
  Oc::Run.load_commands.parse_command
13
-
14
11
  end
15
12
  end
16
13
  end
@@ -27,7 +27,7 @@ module Oc::Run
27
27
  droplets << [
28
28
  droplet.id,
29
29
  droplet.name.to_s.red,
30
- droplet.ip_address.to_s.red,
30
+ droplet.networks.v4[0].ip_address.to_s.red,
31
31
  droplet.status == "active" ? "Active".green : "Deactive".red,
32
32
  droplet.created_at
33
33
  ]
@@ -37,10 +37,8 @@ module Oc::Run
37
37
  end
38
38
  end
39
39
 
40
-
41
40
  description "Create new droplet"
42
41
  syntax "oc droplets new [DROPLET_NAME] [SIZE_ID] [IMAGE_ID] [REGION_ID]"
43
-
44
42
  def new(*args)
45
43
  name = args[0]
46
44
  size = args[1]
@@ -51,7 +49,6 @@ module Oc::Run
51
49
  puts "Usage".yellow
52
50
  puts "$ oc droplets new [DROPLET_NAME] [SIZE_ID] [IMAGE_ID] [REGION_ID]".yellow
53
51
  else
54
-
55
52
  result = barge.droplet.create({:name => name, :region => region_id, :size => size, :image => image_id})
56
53
  if !result.success?
57
54
  puts "#{result.message}".red
@@ -72,7 +69,6 @@ module Oc::Run
72
69
  puts "$ oc droplets reboot [DROPLET_ID]".yellow
73
70
  else
74
71
  raise ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
75
-
76
72
  result = barge.droplet.reboot(id)
77
73
  if !result.success?
78
74
  puts "#{result.message}".red
@@ -152,7 +148,6 @@ module Oc::Run
152
148
  puts "$ oc droplets on [DROPLET_ID]".yellow
153
149
  else
154
150
  raise ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
155
-
156
151
  result = barge.droplet.power_on(id)
157
152
  if !result.success?
158
153
  puts "#{result.message}".red
@@ -165,7 +160,6 @@ module Oc::Run
165
160
 
166
161
  description "This method will reset the root password for a droplet. Please be aware that this will reboot the droplet to allow resetting the password."
167
162
  syntax "oc droplets reset_password [DROPLET_ID]"
168
-
169
163
  def reset_password(*args)
170
164
  id = args[0]
171
165
  if id.nil?
@@ -188,7 +182,6 @@ module Oc::Run
188
182
  def resize(*args)
189
183
  id = args[0]
190
184
  size_id = args[1]
191
-
192
185
  if id.nil? or size_id.nil?
193
186
  puts "Argument Error".red
194
187
  puts "Usage".yellow
@@ -241,14 +234,12 @@ module Oc::Run
241
234
  else
242
235
  puts "Your Droplets".yellow
243
236
  snapshots = []
244
-
245
237
  snapshots << [
246
238
  'Name',
247
239
  'Distribution',
248
240
  'Public',
249
241
  'Created At'
250
242
  ]
251
-
252
243
  result.snapshots.each do |snapshot|
253
244
  snapshots << [
254
245
  snapshot.name.to_s.red,
@@ -264,10 +255,8 @@ module Oc::Run
264
255
  end
265
256
  end
266
257
 
267
-
268
258
  description "This method allows you to restore a droplet with a previous image or snapshot. This will be a mirror copy of the image or snapshot to your droplet. Be sure you have backed up any necessary information prior to restore."
269
259
  syntax "oc droplets restore [DROPLET_ID] [IMAGE_ID]"
270
-
271
260
  def restore(*args)
272
261
  id = args[0]
273
262
  image_id = args[1]
@@ -290,7 +279,6 @@ module Oc::Run
290
279
 
291
280
  description "This method allows you to reinstall a droplet with a default image. This is useful if you want to start again but retain the same IP address for your droplet."
292
281
  syntax "oc droplets rebuild [DROPLET_ID] [IMAGE_ID]"
293
-
294
282
  def rebuild(*args)
295
283
  id = args[0]
296
284
  image_id = args[1]
@@ -301,7 +289,6 @@ module Oc::Run
301
289
  else
302
290
  raise ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
303
291
  raise ArgumentError, "Argument Error - #{image_id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
304
-
305
292
  result = barge.droplet.rebuild(id, image: image_id)
306
293
  if !result.success?
307
294
  puts "#{result.message}".red
@@ -322,7 +309,6 @@ module Oc::Run
322
309
  puts "$ oc droplets rename [DROPLET_ID] [NEW_NAME]".yellow
323
310
  else
324
311
  raise ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
325
-
326
312
  result = barge.droplet.rename(id, name: name)
327
313
  if !result.success?
328
314
  puts "#{result.message}".red
@@ -342,7 +328,6 @@ module Oc::Run
342
328
  puts "$ oc droplets enable-ipv6 [DROPLET_ID]"
343
329
  else
344
330
  raise ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
345
-
346
331
  result = barge.droplet.enable_ipv6(id)
347
332
  if !result.success?
348
333
  puts "#{result.message}".red
@@ -352,15 +337,15 @@ module Oc::Run
352
337
  end
353
338
  end
354
339
 
355
- def barge
356
- puts "I'm thinking, please wait..".blue
357
- Oc::Get.get_barge
358
- end
359
-
360
340
  private
361
341
  def config(value)
362
342
  @config ||= value
363
343
  end
364
344
 
345
+ def barge
346
+ puts "I'm thinking, please wait..".blue
347
+ Oc::Get.get_barge
348
+ end
349
+
365
350
  end
366
351
  end
@@ -10,7 +10,6 @@ module Oc::Run
10
10
  else
11
11
  puts "Images".yellow
12
12
  rows = []
13
-
14
13
  rows << [
15
14
  'ID',
16
15
  'Name',
@@ -18,7 +17,6 @@ module Oc::Run
18
17
  'Public',
19
18
  'Regions'
20
19
  ]
21
-
22
20
  result.images.each do |image|
23
21
  rows << [
24
22
  image.id,
@@ -49,7 +47,6 @@ module Oc::Run
49
47
  else
50
48
  puts "Images".yellow
51
49
  rows = []
52
-
53
50
  rows << [
54
51
  'ID',
55
52
  'Name',
@@ -57,9 +54,7 @@ module Oc::Run
57
54
  'Public',
58
55
  'Regions'
59
56
  ]
60
-
61
57
  image = result.image
62
-
63
58
  rows << [
64
59
  image.id,
65
60
  image.name.to_s.red,
@@ -75,7 +70,6 @@ module Oc::Run
75
70
  end
76
71
  end
77
72
 
78
-
79
73
  description "This method allows you to destroy an image. There is no way to restore a deleted image so be careful and ensure your data is properly backed up."
80
74
  syntax "oc images destroy [IMAGE_ID]"
81
75
 
@@ -117,10 +111,10 @@ module Oc::Run
117
111
  end
118
112
  end
119
113
 
114
+ private
120
115
  def barge
121
116
  puts "I'm thinking, please wait..".blue
122
117
  Oc::Get.get_barge
123
118
  end
124
-
125
119
  end
126
120
  end
@@ -9,12 +9,10 @@ module Oc::Run
9
9
  else
10
10
  puts "Regions".yellow
11
11
  droplets = []
12
-
13
12
  droplets << [
14
13
  'ID',
15
14
  'Name'
16
15
  ]
17
-
18
16
  result.regions.each do |region|
19
17
  droplets << [
20
18
  region.slug,
@@ -25,6 +23,8 @@ module Oc::Run
25
23
  puts table
26
24
  end
27
25
  end
26
+
27
+ private
28
28
  def barge
29
29
  puts "I'm thinking, please wait..".blue
30
30
  Oc::Get.get_barge
@@ -1,39 +1,39 @@
1
1
  module Oc::Run
2
2
  class Sizes < Base
3
+ description "This method returns all the available sizes that can be used to create a droplet."
4
+ syntax "oc sizes"
5
+ def run
6
+ result = barge.size.all
7
+ if !result.success?
8
+ puts "Error: #{result["error_message"]}".red
9
+ else
10
+ puts "Sizes".yellow
11
+ rows = []
3
12
 
4
- description "This method returns all the available sizes that can be used to create a droplet."
5
- syntax "oc sizes"
6
- def run
7
- result = barge.size.all
8
- if !result.success?
9
- puts "Error: #{result["error_message"]}".red
10
- else
11
- puts "Sizes".yellow
12
- rows = []
13
+ rows << [
14
+ 'ID',
15
+ 'Memory',
16
+ 'Disk',
17
+ 'Cpu',
18
+ 'Price (Monthly)',
19
+ 'Price (Hourly)',
20
+ ]
13
21
 
22
+ result.sizes.each do |size|
14
23
  rows << [
15
- 'ID',
16
- 'Memory',
17
- 'Disk',
18
- 'Cpu',
19
- 'Price (Monthly)',
20
- 'Price (Hourly)',
24
+ size.slug,
25
+ size.memory.to_s + " MB",
26
+ size.disk.to_s + " GB",
27
+ size.vcpus,
28
+ "$ " + size.price_monthly.to_s,
29
+ "$ " + size.price_hourly.to_s
21
30
  ]
22
-
23
- result.sizes.each do |size|
24
- rows << [
25
- size.slug,
26
- size.memory.to_s + " MB",
27
- size.disk.to_s + " GB",
28
- size.vcpus,
29
- "$ " + size.price_monthly.to_s,
30
- "$ " + size.price_hourly.to_s
31
- ]
32
- end
33
- table = Terminal::Table.new :rows => rows
34
- puts table
35
31
  end
32
+ table = Terminal::Table.new :rows => rows
33
+ puts table
36
34
  end
35
+ end
36
+ private
37
37
  def barge
38
38
  puts "I'm thinking, please wait..".blue
39
39
  Oc::Get.get_barge
@@ -4,7 +4,6 @@ module Oc::Run
4
4
  config(Netrc.read)
5
5
  end
6
6
 
7
-
8
7
  description "This method lists all the available public SSH keys in your account that can be added to a droplet."
9
8
  syntax "oc ssh keys"
10
9
  def keys
@@ -14,12 +13,10 @@ module Oc::Run
14
13
  else
15
14
  puts "Your SSH Keys".yellow
16
15
  rows = []
17
-
18
16
  rows << [
19
17
  'ID',
20
18
  'Name'
21
19
  ]
22
-
23
20
  result.ssh_keys.each do |key|
24
21
  rows << [
25
22
  key["id"],
@@ -33,7 +30,6 @@ module Oc::Run
33
30
 
34
31
  description "This method allows you to add a new public SSH key to your account."
35
32
  syntax "oc ssh add [KEY_NAME] [KEY_EMAIL] [KEY_PUB]"
36
-
37
33
  def add(*args)
38
34
  name = args[0]
39
35
  pub_key = args[1]
@@ -70,12 +66,10 @@ module Oc::Run
70
66
  else
71
67
  puts "SSH Keys".yellow
72
68
  rows = []
73
-
74
69
  rows << [
75
70
  'ID',
76
71
  'Name'
77
72
  ]
78
-
79
73
  key = result.ssh_key
80
74
  rows << [
81
75
  key.id,
@@ -84,19 +78,16 @@ module Oc::Run
84
78
 
85
79
  table = Terminal::Table.new :rows => rows
86
80
  puts table
87
-
88
81
  end
89
82
  end
90
83
  end
91
84
 
92
85
  description "This method allows you to modify an existing public SSH key in your account."
93
86
  syntax "oc ssh edit [KEY_ID] [KEY_NAME] [KEY_PUB]"
94
-
95
87
  def update(*args)
96
88
  id = args[0]
97
89
  name = args[1]
98
90
  pub_key = args[2]
99
-
100
91
  if id.nil? or name.nil? or pub_key.nil?
101
92
  puts "Argument Error".red
102
93
  puts "Usage".yellow
@@ -117,7 +108,6 @@ module Oc::Run
117
108
 
118
109
  description "This method will delete the SSH key from your account."
119
110
  syntax "oc ssh destroy [KEY_ID]"
120
-
121
111
  def destroy(*args)
122
112
  id = args[0]
123
113
  if id.nil?
@@ -144,10 +134,5 @@ module Oc::Run
144
134
  puts "I'm thinking, please wait..".blue
145
135
  Oc::Get.get_barge
146
136
  end
147
-
148
- def new_key_request name, pub_key
149
-
150
- end
151
-
152
137
  end
153
138
  end
@@ -1,7 +1,6 @@
1
1
  module Oc
2
2
  module Run
3
3
  autoload :Base, "system/run/base"
4
-
5
4
  attr_accessor :main
6
5
 
7
6
  def self.load_commands
@@ -15,36 +14,27 @@ module Oc
15
14
  commands[opts[:name]] = opts
16
15
  end
17
16
 
18
-
19
17
  def self.parse_command(ins = Commander::Runner::instance)
20
-
21
18
  commands.each_pair do |name, opts|
22
19
  name = Array(name)
23
20
  names = [name.reverse.join('-'), name.join(' ')] if name.length > 1
24
21
  name = name.join(" ")
25
-
26
-
27
22
  ins.command name do |c|
28
23
  c.description = opts[:options][:description]
29
24
  c.summary = opts[:options][:summary]
30
25
  c.syntax = opts[:options][:syntax]
31
-
32
26
  (options_metadata = Array(opts[:options][:meta])).each do |o|
33
27
  option_data = [o[:switches], o[:type], o[:description], o[:optional]].compact.flatten(1)
34
28
  c.option *option_data
35
29
  o[:arg] = Commander::Runner.switch_to_sym(Array(o[:switches]).last)
36
-
37
30
  end
38
-
39
31
  c.when_called do |args, options|
40
32
  object = opts[:class].new
41
33
  object.options = options
42
34
  run(object,opts[:method],args)
43
35
  end
44
36
  end
45
-
46
37
  end
47
-
48
38
  end
49
39
 
50
40
  protected
@@ -52,8 +42,6 @@ module Oc
52
42
  obj.send(method, *args)
53
43
  end
54
44
 
55
-
56
- protected
57
45
  def self.hash_to_array(options)
58
46
  return_data = []
59
47
  options.each do |k,v|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sedat Ciftci