droppper 0.2.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ffc7cf76b3d021c1c299b62e31feb439372e306
4
- data.tar.gz: 8b11d5ae7b9b96a343e807538165b0b52dd3e675
3
+ metadata.gz: 2b17353fdfb8ce96831eaded3ca2ff4b6753327d
4
+ data.tar.gz: 7a1ddc43740c30ddfc1df5a0e260f8b98d3242b5
5
5
  SHA512:
6
- metadata.gz: f6a9be8e7b899b326ab0455fefeebce164ec07d38c41f1d04fad0e7ec49a99866254c662039d2d8249d334c4bc5f41df27890f9b5e2182e8919c435697da18d8
7
- data.tar.gz: 6f78dc91488a3ec83b83c5b48efe4cf01a32c6464087e7d4e2415672b248c88ba3d99a7bb7323996a90609615c0c7009725177bdeced896dde90417899692a8f
6
+ metadata.gz: 253702af284691aa0141e5ac02b4ec903bfcd85082b13175d32135d91dadc99c06b8c42798e1e7daca11b1683833cb5617f0524a4c8deb1728e4d835d8bfb2c6
7
+ data.tar.gz: 3cbd38d340f5df08e9c7e48b572b3a949e907987b533e3e7ee86afc1628c731c6bd0599ec227e42c59be0e3252cef806471baf2f67cce683035ba53635c66f41
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in droppper.gemspec
4
4
  gemspec
5
+ gem 'pry'
@@ -5,6 +5,14 @@ require 'droplet_kit'
5
5
  require 'hashie/mash'
6
6
  require 'droppper/commands/droplets'
7
7
  require 'droppper/droplets'
8
+ require 'droppper/commands/regions'
9
+ require 'droppper/regions'
10
+ require 'droppper/commands/sizes'
11
+ require 'droppper/sizes'
12
+ require 'droppper/commands/images'
13
+ require 'droppper/images'
14
+ require 'droppper/commands/actions'
15
+ require 'droppper/actions'
8
16
  require 'droppper/cli'
9
17
  require 'highline/import'
10
18
  require 'table_print'
@@ -17,6 +25,14 @@ module Droppper
17
25
  self.config = Droppper::Config.new
18
26
  self.config.token = options["token"] if options["token"]
19
27
  self.client = DropletKit::Client.new(access_token: config.token)
28
+ # def client.connection
29
+ # @connection ||= Faraday.new(connection_options) do |req|
30
+ # req.adapter :net_http
31
+ # req.response :logger
32
+ # end
33
+ # end
20
34
  end
21
35
  end
22
36
  end
37
+
38
+ TablePrint::Config.max_width = 100
@@ -0,0 +1,30 @@
1
+ require 'time'
2
+
3
+ module Droppper
4
+ module Actions extend self
5
+ def list(*args)
6
+ data = actions(args)
7
+ tp data, :id, :status, :type, :started_at, :completed_at, :resource_id, :resource_type, :region_slug
8
+ end
9
+
10
+ def status(action_id)
11
+ act = action(action_id)
12
+ puts act.inspect
13
+ end
14
+
15
+ def actions(args)
16
+ pr = Droppper.client.actions.all(page:1, per_page: 25)
17
+ pr.each
18
+ data = pr.collection
19
+ if args.size > 0
20
+ re = Regexp.new(Array(args).join(".*"))
21
+ data = data.select{|i| i.id.to_s=~re or i.status=~re or i.type=~re or i.resource_type=~re}
22
+ end
23
+ data
24
+ end
25
+
26
+ def action(action_id)
27
+ Droppper.client.actions.find id: action_id
28
+ end
29
+ end
30
+ end
@@ -35,5 +35,17 @@ module Droppper
35
35
  def ssh(*args)
36
36
  Droppper::Droplets.ssh(*args, options)
37
37
  end
38
+
39
+ desc "regions", "List regions"
40
+ subcommand "regions", Droppper::Commands::Regions
41
+
42
+ desc "sizes", "List sizes"
43
+ subcommand "sizes", Droppper::Commands::Sizes
44
+
45
+ desc "images", "Images manipulation"
46
+ subcommand "images", Droppper::Commands::Images
47
+
48
+ desc "actions", "Actions querying"
49
+ subcommand "actions", Droppper::Commands::Actions
38
50
  end
39
51
  end
@@ -0,0 +1,25 @@
1
+
2
+ require 'thor'
3
+
4
+ module Droppper
5
+ module Commands
6
+ class Actions < Thor
7
+ default_command :list
8
+
9
+ desc "list [SEARCH_STRING]", "Retrieve the list of actions"
10
+ def list(*args)
11
+ Droppper::Actions.list(*args)
12
+ end
13
+
14
+ desc "status [ACTION_ID]", "Shows the status of an action"
15
+ def status(action_id)
16
+ Droppper::Actions.status(action_id)
17
+ end
18
+
19
+ desc "monitor [ACTION_ID]", "Shows the status of an action and waits until the action finishes"
20
+ def monitor(action_id)
21
+ Droppper::Actions.monitor(action_id)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,56 @@
1
+
2
+ require 'thor'
3
+
4
+ module Droppper
5
+ module Commands
6
+ class Images < Thor
7
+ default_command :list
8
+
9
+ desc "list [SEARCH_STRING]", "Retrieve the list of images"
10
+ method_option "type",
11
+ type: :string,
12
+ aliases: "-t",
13
+ default: 'all',
14
+ enum: %w(all distribution dist application app user),
15
+ desc: "Specifies which images to retrieve (all, distribution / dist, application / app or user images)"
16
+ def list(*args)
17
+ Droppper::Images.list(*args, options)
18
+ end
19
+
20
+ desc "rename NEW_NAME [IMAGE_ID_OR_SEARCH]", "Rename an image"
21
+ def rename(new_name, *args)
22
+ Droppper::Images.rename(new_name, *args)
23
+ end
24
+
25
+ desc "destroy [IMAGE_ID_OR_SEARCH]", "Rename an image"
26
+ def destroy(*args)
27
+ Droppper::Images.destroy(*args)
28
+ end
29
+
30
+ desc "transfer NEW_REGION [IMAGE_ID_OR_SEARCH]", "Transfers an image to another region"
31
+ def transfer(new_region, *args)
32
+ Droppper::Images.transfer(new_region, *args)
33
+ end
34
+
35
+ desc "convert [IMAGE_ID_OR_SEARCH]", "Convert a backup to a snapshot"
36
+ def convert(*args)
37
+ Droppper::Images.convert(*args)
38
+ end
39
+
40
+ desc "actions IMAGE_ID", "Show actions in progress for an image"
41
+ def actions(image_id)
42
+ Droppper::Images.actions(image_id)
43
+ end
44
+
45
+ desc "show_action IMAGE_ID ACTION_ID", "Show an action status for an image and repeats until done"
46
+ def show_action(image_id, action_id)
47
+ Droppper::Images.show_action(image_id, action_id)
48
+ end
49
+
50
+ desc "monitor_action IMAGE_ID ACTION_ID", "Show an action status for an image and repeats until done"
51
+ def monitor_action(image_id, action_id)
52
+ Droppper::Images.monitor_action(image_id, action_id)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,15 @@
1
+
2
+ require 'thor'
3
+
4
+ module Droppper
5
+ module Commands
6
+ class Regions < Thor
7
+ default_command :list
8
+
9
+ desc "list", "Retrieve the list regions"
10
+ def list(*args)
11
+ Droppper::Regions.list(*args)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+
2
+ require 'thor'
3
+
4
+ module Droppper
5
+ module Commands
6
+ class Sizes < Thor
7
+ default_command :list
8
+
9
+ desc "list", "Retrieve the list of available sizes"
10
+ def list(*args)
11
+ Droppper::Sizes.list(*args)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,122 @@
1
+ require 'time'
2
+
3
+ module Droppper
4
+ module Images extend self
5
+ def list(*args, options)
6
+ data = images(args, options)
7
+ tp data, :id, :slug, :distribution, :name, :public, :type,
8
+ {regions: lambda{|r| r.regions.join(", ")}}
9
+ end
10
+
11
+ def rename(new_name, *args)
12
+ img = image(args)
13
+ return unless img
14
+ img.name = new_name
15
+ r = Droppper.client.images.update img, id: img.id
16
+ if r.respond_to?(:name) and r.name == new_name
17
+ puts "Image has been successfully renamed."
18
+ else
19
+ puts "Failed to rename image: Response: #{r}"
20
+ end
21
+ end
22
+
23
+ def destroy(*args)
24
+ img = image(args)
25
+ return unless img
26
+ r = Droppper.client.images.delete id: img.id
27
+ if r.to_s == 'true'
28
+ puts "Image has been successfully destroyed"
29
+ else
30
+ puts "Failed to destroy image: Response: #{r}"
31
+ end
32
+ end
33
+
34
+ def transfer(new_region, *args)
35
+ img = image(args)
36
+ return unless img
37
+ r = Droppper.client.image_actions.transfer(image_id: img.id, region: new_region)
38
+ if r and r.is_a?(DropletKit::ImageAction)
39
+ puts "Image transfer has begin. You can see the progress by running: droppper images monitor_action #{img.id} #{r.id}"
40
+ else
41
+ puts "Failed to transfer image: Response: #{r}"
42
+ end
43
+ end
44
+
45
+ def convert(*args)
46
+ img = image(args)
47
+ return unless img
48
+ r = Droppper.client.image_actions.convert(image_id: img.id)
49
+ if r and r.is_a?(DropletKit::ImageAction)
50
+ puts "Image conversion has begin. You can see the progress by running: droppper images monitor_action #{img.id} #{r.id}"
51
+ else
52
+ puts "Failed to convert image: Response: #{r}"
53
+ end
54
+ end
55
+
56
+ def actions(image_id)
57
+ require 'pry'
58
+ binding.pry
59
+ r = Droppper.client.image_actions.all(image_id: image_id)
60
+ r.each
61
+ data = r.collection
62
+ if data.size==0
63
+ puts "No actions found"
64
+ return
65
+ end
66
+ tp data, :id, :status, :type, :started_at, :completed_at, :resource_id, :resource_type, :region_slug
67
+ end
68
+
69
+ def show_action(image_id, action_id)
70
+ act = Droppper.client.image_actions.find(image_id: image_id, id: action_id)
71
+ puts act
72
+ end
73
+
74
+ def monitor_action(image_id, action_id)
75
+
76
+ end
77
+
78
+ def filters_for_type(type)
79
+ case type
80
+ when 'all'
81
+ {}
82
+ when 'distribution', 'dist'
83
+ {type: :distribution}
84
+ when 'application', 'app'
85
+ {type: :application}
86
+ when 'user'
87
+ {private: :true}
88
+ else
89
+ {}
90
+ end
91
+ end
92
+
93
+ def images(args, options={})
94
+ data = Droppper.client.images.all(filters_for_type(options["type"])).to_a
95
+ if args.size > 0
96
+ re = Regexp.new(Array(args).join(".*"))
97
+ data = data.select{|i| i.id.to_s=~re or i.name=~re or i.distribution=~re or i.slug=~re or i.type=~re or i.regions.join( )=~re}
98
+ end
99
+ data
100
+ end
101
+
102
+ def image(*args)
103
+ list = images(args)
104
+ if list.size == 0
105
+ puts "Cannot find image"
106
+ elsif list.size == 1
107
+ list.first
108
+ else
109
+ select_image(list)
110
+ end
111
+ end
112
+
113
+ def select_image(list)
114
+ choose do |menu|
115
+ menu.prompt = "Multiple droplets found. Select one:"
116
+ list.each do |image|
117
+ menu.choice "#{image.name} (dist: #{image.distribution}, type: #{image.type}, public: #{image.public})" do image end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,10 @@
1
+ require 'time'
2
+
3
+ module Droppper
4
+ module Regions extend self
5
+ def list(*args)
6
+ data = Droppper.client.regions.all.to_a
7
+ tp data, :slug, :name, {sizes: lambda{|r| r.sizes.join(", ")}}, :available, {features: lambda{|r| r.features.join(", ")}}
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ require 'time'
2
+
3
+ module Droppper
4
+ module Sizes extend self
5
+ def list(*args)
6
+ data = Droppper.client.sizes.all.to_a
7
+ tp data, :slug, :memory, :vcpus, :disk, :transfer, :price_monthly, :price_hourly,
8
+ {regions: lambda{|r| r.regions.join(", ")}},
9
+ :available
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Droppper
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: droppper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cristian Bica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-07 00:00:00.000000000 Z
11
+ date: 2015-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -123,10 +123,18 @@ files:
123
123
  - bin/droppper
124
124
  - droppper.gemspec
125
125
  - lib/droppper.rb
126
+ - lib/droppper/actions.rb
126
127
  - lib/droppper/cli.rb
128
+ - lib/droppper/commands/actions.rb
127
129
  - lib/droppper/commands/droplets.rb
130
+ - lib/droppper/commands/images.rb
131
+ - lib/droppper/commands/regions.rb
132
+ - lib/droppper/commands/sizes.rb
128
133
  - lib/droppper/config.rb
129
134
  - lib/droppper/droplets.rb
135
+ - lib/droppper/images.rb
136
+ - lib/droppper/regions.rb
137
+ - lib/droppper/sizes.rb
130
138
  - lib/droppper/utils.rb
131
139
  - lib/droppper/version.rb
132
140
  homepage: https://github.com/cristianbica/droppper