Module: Droppper::Droplets
Instance Method Summary collapse
- #droplet(*args) ⇒ Object
- #droplets(*args) ⇒ Object
- #list(*args) ⇒ Object
- #select_droplet(list) ⇒ Object
- #show(*args) ⇒ Object
- #ssh(*args, options) ⇒ Object
Instance Method Details
#droplet(*args) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/droppper/droplets.rb', line 68 def droplet(*args) list = droplets(*args) if list.size == 0 puts "Cannot find droplet" elsif list.size == 1 list.first else select_droplet(list) end end |
#droplets(*args) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/droppper/droplets.rb', line 57 def droplets(*args) args = Array(args).flatten data = Droppper.client.droplets.all.to_a if args.size > 0 data = data.select do |d| (args.size==1 and (d.id.to_s == args[0] or d.name == args[0])) or (d.name =~ Regexp.new(args.join(".*"))) end end data end |
#list(*args) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/droppper/droplets.rb', line 6 def list(*args) data = droplets(*args) tp data, {id: {display_name: "ID"}}, {name: {display_name: "NAME"}}, {"region.slug" => {display_name: "REGION"}}, {"size_slug" => {display_name: "SIZE"}}, :status, :locked end |
#select_droplet(list) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/droppper/droplets.rb', line 79 def select_droplet(list) choose do || .prompt = "Multiple droplets found. Select one:" list.each do |droplet| .choice droplet.name do droplet end end end end |
#show(*args) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/droppper/droplets.rb', line 16 def show(*args) d = droplet(*args) puts "ID: \#{d.id}\nName: \#{d.name}\nMemory: \#{d.memory}MB\nvCPUs: \#{d.vcpus}\nDisk: \#{d.disk}G\nCreated on: \#{Time.parse(d.created_at).rfc2822}\nStatus: \#{d.status}\nBackups: \#{d.backup_ids.size}\nFeatures: \#{d.features.join(\", \")}\nRegion: \#{d.region.name}\nImage: \#{d.image.name}\nKernel: \#{d.kernel.name}\n eos\n puts \"Networking:\"\n [['v4', 'public'], ['v4', 'private'], ['v6', 'public'], ['v6', 'private']].each do |pair|\n version, publicity = pair\n if net = d.networks.send(version).find{|net| net.type == publicity}\n puts \" IP\#{version} (\#{publicity}):\".ljust(18) +\"\#{net.ip_address}\"\n end\n end\nend\n" |
#ssh(*args, options) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/droppper/droplets.rb', line 41 def ssh(*args, ) d = droplet(*args) = [ "-o", "IdentitiesOnly=yes", "-o", "LogLevel=ERROR", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-i", File.(Droppper.config.ssh.keyfile) ] .push "-l", "#{options['user']||Droppper.config.ssh.user}" .push "-p", "#{options['port']||Droppper.config.ssh.port}" << d.public_ip puts "Executing: ssh #{cmd_options.join(" ")}" Kernel.exec("ssh", *) end |