Sha256: 7fc84b854f552e69ba2fb36db9b405579cb52bed0549ac75d0d58ec08c421657
Contents?: true
Size: 1.7 KB
Versions: 7
Compression:
Stored size: 1.7 KB
Contents
module Kontena::Plugin::DigitalOcean::Prompts def ask_do_token if self.token.nil? prompt.ask('DigitalOcean API token: ', echo: false) else self.token end end def ask_droplet_region(do_token) if self.region.nil? prompt.select("Choose a datacenter region: ") do |menu| do_client = DropletKit::Client.new(access_token: do_token) do_client.regions.all.sort_by{|r| r.slug }.each{ |region| menu.choice region.name, region.slug } end else self.region end end def ask_droplet_size(do_token, do_region) if self.size.nil? prompt.select("Choose droplet size: ") do |menu| do_client = DropletKit::Client.new(access_token: do_token) do_client.sizes.all.to_a.select{ |s| s.memory > 1000 }.sort_by{|s| s.memory }.each{ |size| if size.regions.include?(do_region) memory = size.memory.to_i / 1024 menu.choice "#{memory}GB/#{size.vcpus}CPU/#{size.disk}GB ($#{size.price_monthly.to_i}/mo)", size.slug end } end else self.size end end def ask_node(token) if self.name.nil? nodes = client(token).get("grids/#{current_grid}/nodes") nodes = nodes['nodes'].select{ |n| n['labels'] && n['labels'].include?('provider=digitalocean'.freeze) } raise "Did not find any nodes with label provider=digitalocean" if nodes.size == 0 prompt.select("Select node: ") do |menu| nodes.sort_by{|n| n['node_number'] }.reverse.each do |node| initial = node['initial_member'] ? '(initial) ' : '' menu.choice "#{node['name']} #{initial}", node['name'] end end else self.name end end end
Version data entries
7 entries across 7 versions & 1 rubygems