Class: DOCL::CLI
- Inherits:
-
Thor
- Object
- Thor
- DOCL::CLI
- Defined in:
- lib/docl/cli.rb
Instance Method Summary collapse
- #authorize ⇒ Object
- #create(name, image, size, region) ⇒ Object
- #images ⇒ Object
- #keys ⇒ Object
- #regions ⇒ Object
- #upload_key(name, public_key_path) ⇒ Object
Instance Method Details
#authorize ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/docl/cli.rb', line 3 def puts "You'll need to enter your DigitalOcean Private Access Token." puts "To be able to create / modify droplets, it needs to be read / write." puts "You can create a token on the DO website vite the Apps & API menu." print "Enter your DO Token: " token = $stdin.gets.chomp f = File.open(config_path, 'w') f.write(token) f.close File.chmod(0600, config_path) end |
#create(name, image, size, region) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/docl/cli.rb', line 90 def create(name, image, size, region) = { name: name, image: image, region: region, size: size, private_networking: .private_networking, enable_backups: .enable_backups, ipv6: .ipv6, } if [:key] [:ssh_keys] = [[:key]] end if .user_data [:user_data] = File.read(.user_data) end response = .droplet.create() if response.id == 'unprocessable_entity' puts response. exit(1) end if .wait print "Waiting for droplet to become available" action_link = response.links.actions.first begin print '.' sleep 1 action = .action.show(action_link.id).action end until action.status != 'in-progress' puts "Completed" droplet = .droplet.show(response.droplet.id).droplet network_types = [droplet.networks.v4] network_types << droplet.networks.v6 if droplet.networks.v6 puts "You can connect to your Droplet via" network_types.flatten.select { |nw| nw.type == 'public' }.each do |network| puts network.ip_address end end end |
#images ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/docl/cli.rb', line 19 def images() images = .image.all.images images = images.select { |image| image.public == .public } images = images.sort { |a, b| a.name <=> b.name } images.each do |image| if !image.slug.nil? puts "#{image.name} (#{image.slug}, id: #{image.id})" else puts "#{image.name} (id: #{image.id})" end end end |
#keys ⇒ Object
46 47 48 49 50 |
# File 'lib/docl/cli.rb', line 46 def keys() .key.all.ssh_keys.each do |key| puts "#{key.name} (id: #{key.id})" end end |
#regions ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/docl/cli.rb', line 57 def regions() regions = .region.all.regions regions = regions.select do |region| if .ipv6 && !region.features.include?('ipv6') next false end if . && !region.features.include?('metadata') next false end if .private_networking && !region.features.include?('private_networking') next false end if .backups && !region.features.include?('backups') next false end next true end regions.sort { |a, b| a.name <=> b.name }.each do |region| puts "#{region.name} (#{region.slug})" end end |
#upload_key(name, public_key_path) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/docl/cli.rb', line 33 def upload_key(name, public_key_path) response = .key.create(name: name, public_key: File.read(public_key_path)) if response. puts response. exit(1) else puts "Public Key uploaded with ID: #{response.ssh_key.id}" end end |