Module: Droppper::Images
Instance Method Summary collapse
- #actions(image_id) ⇒ Object
- #convert(*args) ⇒ Object
- #destroy(*args) ⇒ Object
- #filters_for_type(type) ⇒ Object
- #image(*args) ⇒ Object
- #images(args, options = {}) ⇒ Object
- #list(*args, options) ⇒ Object
- #monitor_action(image_id, action_id) ⇒ Object
- #rename(new_name, *args) ⇒ Object
- #select_image(list) ⇒ Object
- #show_action(image_id, action_id) ⇒ Object
- #transfer(new_region, *args) ⇒ Object
Instance Method Details
#actions(image_id) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/droppper/images.rb', line 56 def actions(image_id) require 'pry' binding.pry r = Droppper.client.image_actions.all(image_id: image_id) r.each data = r.collection if data.size==0 puts "No actions found" return end tp data, :id, :status, :type, :started_at, :completed_at, :resource_id, :resource_type, :region_slug end |
#convert(*args) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/droppper/images.rb', line 45 def convert(*args) img = image(args) return unless img r = Droppper.client.image_actions.convert(image_id: img.id) if r and r.is_a?(DropletKit::ImageAction) puts "Image conversion has begin. You can see the progress by running: droppper images monitor_action #{img.id} #{r.id}" else puts "Failed to convert image: Response: #{r}" end end |
#destroy(*args) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/droppper/images.rb', line 23 def destroy(*args) img = image(args) return unless img r = Droppper.client.images.delete id: img.id if r.to_s == 'true' puts "Image has been successfully destroyed" else puts "Failed to destroy image: Response: #{r}" end end |
#filters_for_type(type) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/droppper/images.rb', line 78 def filters_for_type(type) case type when 'all' {} when 'distribution', 'dist' {type: :distribution} when 'application', 'app' {type: :application} when 'user' {private: :true} else {} end end |
#image(*args) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/droppper/images.rb', line 102 def image(*args) list = images(args) if list.size == 0 puts "Cannot find image" elsif list.size == 1 list.first else select_image(list) end end |
#images(args, options = {}) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/droppper/images.rb', line 93 def images(args, ={}) data = Droppper.client.images.all(filters_for_type(["type"])).to_a if args.size > 0 re = Regexp.new(Array(args).join(".*")) 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} end data end |
#list(*args, options) ⇒ Object
5 6 7 8 9 |
# File 'lib/droppper/images.rb', line 5 def list(*args, ) data = images(args, ) tp data, :id, :slug, :distribution, :name, :public, :type, {regions: lambda{|r| r.regions.join(", ")}} end |
#monitor_action(image_id, action_id) ⇒ Object
74 75 76 |
# File 'lib/droppper/images.rb', line 74 def monitor_action(image_id, action_id) end |
#rename(new_name, *args) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/droppper/images.rb', line 11 def rename(new_name, *args) img = image(args) return unless img img.name = new_name r = Droppper.client.images.update img, id: img.id if r.respond_to?(:name) and r.name == new_name puts "Image has been successfully renamed." else puts "Failed to rename image: Response: #{r}" end end |
#select_image(list) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/droppper/images.rb', line 113 def select_image(list) choose do || .prompt = "Multiple droplets found. Select one:" list.each do |image| .choice "#{image.name} (dist: #{image.distribution}, type: #{image.type}, public: #{image.public})" do image end end end end |
#show_action(image_id, action_id) ⇒ Object
69 70 71 72 |
# File 'lib/droppper/images.rb', line 69 def show_action(image_id, action_id) act = Droppper.client.image_actions.find(image_id: image_id, id: action_id) puts act end |
#transfer(new_region, *args) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/droppper/images.rb', line 34 def transfer(new_region, *args) img = image(args) return unless img r = Droppper.client.image_actions.transfer(image_id: img.id, region: new_region) if r and r.is_a?(DropletKit::ImageAction) puts "Image transfer has begin. You can see the progress by running: droppper images monitor_action #{img.id} #{r.id}" else puts "Failed to transfer image: Response: #{r}" end end |