race 0.1.6
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 +7 -0
 - data/.gitignore +17 -0
 - data/Gemfile +4 -0
 - data/LICENSE.txt +22 -0
 - data/README.md +159 -0
 - data/Rakefile +1 -0
 - data/bin/race +21 -0
 - data/lib/race/version.rb +3 -0
 - data/lib/race.rb +4 -0
 - data/lib/system/config.rb +18 -0
 - data/lib/system/run/base.rb +64 -0
 - data/lib/system/run/client.rb +13 -0
 - data/lib/system/run/commands/account.rb +28 -0
 - data/lib/system/run/commands/domain.rb +88 -0
 - data/lib/system/run/commands/droplets.rb +445 -0
 - data/lib/system/run/commands/images.rb +121 -0
 - data/lib/system/run/commands/info.rb +22 -0
 - data/lib/system/run/commands/regions.rb +24 -0
 - data/lib/system/run/commands/sizes.rb +37 -0
 - data/lib/system/run/commands/ssh.rb +120 -0
 - data/lib/system/run/run.rb +58 -0
 - data/race.gemspec +29 -0
 - metadata +164 -0
 
| 
         @@ -0,0 +1,445 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Race::Run
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Droplets < Base
         
     | 
| 
      
 3 
     | 
    
         
            +
                description 'Show Droplets'
         
     | 
| 
      
 4 
     | 
    
         
            +
                syntax 'race droplets'
         
     | 
| 
      
 5 
     | 
    
         
            +
                def run
         
     | 
| 
      
 6 
     | 
    
         
            +
                  result = barge.droplet.all
         
     | 
| 
      
 7 
     | 
    
         
            +
                  if !result.success?
         
     | 
| 
      
 8 
     | 
    
         
            +
                    puts 'Error: Please check your information'.red
         
     | 
| 
      
 9 
     | 
    
         
            +
                  else
         
     | 
| 
      
 10 
     | 
    
         
            +
                    puts 'Your Droplets'.yellow
         
     | 
| 
      
 11 
     | 
    
         
            +
                    droplets = []
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                    droplets << [
         
     | 
| 
      
 14 
     | 
    
         
            +
                      'ID',
         
     | 
| 
      
 15 
     | 
    
         
            +
                      'Name',
         
     | 
| 
      
 16 
     | 
    
         
            +
                      'IP Address',
         
     | 
| 
      
 17 
     | 
    
         
            +
                      'Status',
         
     | 
| 
      
 18 
     | 
    
         
            +
                      'Created At'
         
     | 
| 
      
 19 
     | 
    
         
            +
                    ]
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                    result.droplets.each do |droplet|
         
     | 
| 
      
 22 
     | 
    
         
            +
                      droplets << [
         
     | 
| 
      
 23 
     | 
    
         
            +
                        droplet.id,
         
     | 
| 
      
 24 
     | 
    
         
            +
                        droplet.name.to_s.red,
         
     | 
| 
      
 25 
     | 
    
         
            +
                        droplet.networks.v4[0].ip_address.to_s.red,
         
     | 
| 
      
 26 
     | 
    
         
            +
                        droplet.status == 'active' ? 'Active'.green : 'Deactive'.red,
         
     | 
| 
      
 27 
     | 
    
         
            +
                        droplet.created_at
         
     | 
| 
      
 28 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 29 
     | 
    
         
            +
                    end
         
     | 
| 
      
 30 
     | 
    
         
            +
                    table = Terminal::Table.new rows: droplets
         
     | 
| 
      
 31 
     | 
    
         
            +
                    puts table
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                description 'Create new droplet'
         
     | 
| 
      
 36 
     | 
    
         
            +
                syntax 'race droplets new [DROPLET_NAME] [SIZE_ID] [IMAGE_ID] [REGION_ID]'
         
     | 
| 
      
 37 
     | 
    
         
            +
                def new(*args)
         
     | 
| 
      
 38 
     | 
    
         
            +
                  name = args[0]
         
     | 
| 
      
 39 
     | 
    
         
            +
                  size = args[1]
         
     | 
| 
      
 40 
     | 
    
         
            +
                  image_id = args[2]
         
     | 
| 
      
 41 
     | 
    
         
            +
                  region_id = args[3]
         
     | 
| 
      
 42 
     | 
    
         
            +
                  if name.nil? || size.nil? || image_id.nil? || region_id.nil?
         
     | 
| 
      
 43 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 44 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 45 
     | 
    
         
            +
                    puts '$ race droplets new [DROPLET_NAME] [SIZE_ID] [IMAGE_ID] [REGION_ID]'.yellow
         
     | 
| 
      
 46 
     | 
    
         
            +
                  else
         
     | 
| 
      
 47 
     | 
    
         
            +
                    result = barge.droplet.create(name: name, region: region_id, size: size, image: image_id)
         
     | 
| 
      
 48 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 49 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 50 
     | 
    
         
            +
                    else
         
     | 
| 
      
 51 
     | 
    
         
            +
                      puts 'Droplet created'.green
         
     | 
| 
      
 52 
     | 
    
         
            +
                    end
         
     | 
| 
      
 53 
     | 
    
         
            +
                  end
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                description 'Destroy droplet'
         
     | 
| 
      
 57 
     | 
    
         
            +
                syntax 'race droplets destroy [DROPLET_ID]'
         
     | 
| 
      
 58 
     | 
    
         
            +
                def destroy(*args)
         
     | 
| 
      
 59 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 60 
     | 
    
         
            +
                  if id.nil?
         
     | 
| 
      
 61 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 62 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 63 
     | 
    
         
            +
                    puts '$ race droplets destroy [DROPLET_ID]'.yellow
         
     | 
| 
      
 64 
     | 
    
         
            +
                  else
         
     | 
| 
      
 65 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 66 
     | 
    
         
            +
                    result = barge.droplet.destroy(id)
         
     | 
| 
      
 67 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 68 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 69 
     | 
    
         
            +
                    else
         
     | 
| 
      
 70 
     | 
    
         
            +
                      puts 'Droplet destroyed'.green
         
     | 
| 
      
 71 
     | 
    
         
            +
                    end
         
     | 
| 
      
 72 
     | 
    
         
            +
                  end
         
     | 
| 
      
 73 
     | 
    
         
            +
                end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                description 'Reboot droplet'
         
     | 
| 
      
 76 
     | 
    
         
            +
                syntax 'race droplets reboot [DROPLET_ID]'
         
     | 
| 
      
 77 
     | 
    
         
            +
                def reboot(*args)
         
     | 
| 
      
 78 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 79 
     | 
    
         
            +
                  if id.nil?
         
     | 
| 
      
 80 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 81 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 82 
     | 
    
         
            +
                    puts '$ race droplets reboot [DROPLET_ID]'.yellow
         
     | 
| 
      
 83 
     | 
    
         
            +
                  else
         
     | 
| 
      
 84 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 85 
     | 
    
         
            +
                    result = barge.droplet.reboot(id)
         
     | 
| 
      
 86 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 87 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 88 
     | 
    
         
            +
                    else
         
     | 
| 
      
 89 
     | 
    
         
            +
                      puts 'Droplet rebooted'.green
         
     | 
| 
      
 90 
     | 
    
         
            +
                    end
         
     | 
| 
      
 91 
     | 
    
         
            +
                  end
         
     | 
| 
      
 92 
     | 
    
         
            +
                end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
                description 'This method allows you to power cycle a droplet. This will turn off the droplet and then turn it back on.'
         
     | 
| 
      
 95 
     | 
    
         
            +
                syntax 'race droplets cycle [DROPLET_ID]'
         
     | 
| 
      
 96 
     | 
    
         
            +
                def cycle(*args)
         
     | 
| 
      
 97 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 98 
     | 
    
         
            +
                  if id.nil?
         
     | 
| 
      
 99 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 100 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 101 
     | 
    
         
            +
                    puts '$ race droplets cycle [DROPLET_ID]'.yellow
         
     | 
| 
      
 102 
     | 
    
         
            +
                  else
         
     | 
| 
      
 103 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 104 
     | 
    
         
            +
                    result = barge.droplet.power_cycle(id)
         
     | 
| 
      
 105 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 106 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 107 
     | 
    
         
            +
                    else
         
     | 
| 
      
 108 
     | 
    
         
            +
                      puts 'Power cycle has been successful'.green
         
     | 
| 
      
 109 
     | 
    
         
            +
                    end
         
     | 
| 
      
 110 
     | 
    
         
            +
                  end
         
     | 
| 
      
 111 
     | 
    
         
            +
                end
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                description 'This method allows you to shutdown a running droplet. The droplet will remain in your account.'
         
     | 
| 
      
 114 
     | 
    
         
            +
                syntax 'race droplets down [DROPLET_ID]'
         
     | 
| 
      
 115 
     | 
    
         
            +
                def down(*args)
         
     | 
| 
      
 116 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 117 
     | 
    
         
            +
                  if id.nil?
         
     | 
| 
      
 118 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 119 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 120 
     | 
    
         
            +
                    puts '$ race droplets down [DROPLET_ID]'.yellow
         
     | 
| 
      
 121 
     | 
    
         
            +
                  else
         
     | 
| 
      
 122 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 123 
     | 
    
         
            +
                    result = barge.droplet.shutdown(id)
         
     | 
| 
      
 124 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 125 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 126 
     | 
    
         
            +
                    else
         
     | 
| 
      
 127 
     | 
    
         
            +
                      puts 'Shut down has been successful'.green
         
     | 
| 
      
 128 
     | 
    
         
            +
                    end
         
     | 
| 
      
 129 
     | 
    
         
            +
                  end
         
     | 
| 
      
 130 
     | 
    
         
            +
                end
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
                description 'This method allows you to poweroff a running droplet. The droplet will remain in your account.'
         
     | 
| 
      
 133 
     | 
    
         
            +
                syntax 'race droplets off [DROPLET_ID]'
         
     | 
| 
      
 134 
     | 
    
         
            +
                def off(*args)
         
     | 
| 
      
 135 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 136 
     | 
    
         
            +
                  if id.nil?
         
     | 
| 
      
 137 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 138 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 139 
     | 
    
         
            +
                    puts '$ race droplets off [DROPLET_ID]'.yellow
         
     | 
| 
      
 140 
     | 
    
         
            +
                  else
         
     | 
| 
      
 141 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 142 
     | 
    
         
            +
                    result = barge.droplet.power_off(id)
         
     | 
| 
      
 143 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 144 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 145 
     | 
    
         
            +
                    else
         
     | 
| 
      
 146 
     | 
    
         
            +
                      puts 'Power off has been successful'.green
         
     | 
| 
      
 147 
     | 
    
         
            +
                    end
         
     | 
| 
      
 148 
     | 
    
         
            +
                  end
         
     | 
| 
      
 149 
     | 
    
         
            +
                end
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
                description 'This method allows you to poweron a powered off droplet.'
         
     | 
| 
      
 152 
     | 
    
         
            +
                syntax 'race droplets on [DROPLET_ID]'
         
     | 
| 
      
 153 
     | 
    
         
            +
                def on(*args)
         
     | 
| 
      
 154 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 155 
     | 
    
         
            +
                  if id.nil?
         
     | 
| 
      
 156 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 157 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 158 
     | 
    
         
            +
                    puts '$ race droplets on [DROPLET_ID]'.yellow
         
     | 
| 
      
 159 
     | 
    
         
            +
                  else
         
     | 
| 
      
 160 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 161 
     | 
    
         
            +
                    result = barge.droplet.power_on(id)
         
     | 
| 
      
 162 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 163 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 164 
     | 
    
         
            +
                    else
         
     | 
| 
      
 165 
     | 
    
         
            +
                      puts 'Power on has been successful'.green
         
     | 
| 
      
 166 
     | 
    
         
            +
                    end
         
     | 
| 
      
 167 
     | 
    
         
            +
                  end
         
     | 
| 
      
 168 
     | 
    
         
            +
                end
         
     | 
| 
      
 169 
     | 
    
         
            +
             
     | 
| 
      
 170 
     | 
    
         
            +
                description 'This method will reset the root password for a droplet. Please be aware that this will reboot the droplet to allow resetting the password.'
         
     | 
| 
      
 171 
     | 
    
         
            +
                syntax 'race droplets reset_password [DROPLET_ID]'
         
     | 
| 
      
 172 
     | 
    
         
            +
                def reset_password(*args)
         
     | 
| 
      
 173 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 174 
     | 
    
         
            +
                  if id.nil?
         
     | 
| 
      
 175 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 176 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 177 
     | 
    
         
            +
                    puts '$ race droplets reset_password [DROPLET_ID]'.yellow
         
     | 
| 
      
 178 
     | 
    
         
            +
                  else
         
     | 
| 
      
 179 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 180 
     | 
    
         
            +
                    result = barge.droplet.password_reset(id)
         
     | 
| 
      
 181 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 182 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 183 
     | 
    
         
            +
                    else
         
     | 
| 
      
 184 
     | 
    
         
            +
                      puts 'Password restored. Please check your email'.green
         
     | 
| 
      
 185 
     | 
    
         
            +
                    end
         
     | 
| 
      
 186 
     | 
    
         
            +
                  end
         
     | 
| 
      
 187 
     | 
    
         
            +
                end
         
     | 
| 
      
 188 
     | 
    
         
            +
             
     | 
| 
      
 189 
     | 
    
         
            +
                description 'This method allows you to resize a specific droplet to a different size. This will affect the number of processors and memory allocated to the droplet.'
         
     | 
| 
      
 190 
     | 
    
         
            +
                syntax 'race droplets resize [DROPLET_ID] [SIZE_ID]'
         
     | 
| 
      
 191 
     | 
    
         
            +
                def resize(*args)
         
     | 
| 
      
 192 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 193 
     | 
    
         
            +
                  size_id = args[1]
         
     | 
| 
      
 194 
     | 
    
         
            +
                  if id.nil? || size_id.nil?
         
     | 
| 
      
 195 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 196 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 197 
     | 
    
         
            +
                    puts '$ race droplets resize [DROPLET_ID] [SIZE_ID]'.yellow
         
     | 
| 
      
 198 
     | 
    
         
            +
                  else
         
     | 
| 
      
 199 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 200 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless size_id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 201 
     | 
    
         
            +
                    result = barge.droplet.resize(id, size: size_id)
         
     | 
| 
      
 202 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 203 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 204 
     | 
    
         
            +
                    else
         
     | 
| 
      
 205 
     | 
    
         
            +
                      puts 'Droplet resized'.green
         
     | 
| 
      
 206 
     | 
    
         
            +
                    end
         
     | 
| 
      
 207 
     | 
    
         
            +
                  end
         
     | 
| 
      
 208 
     | 
    
         
            +
                end
         
     | 
| 
      
 209 
     | 
    
         
            +
             
     | 
| 
      
 210 
     | 
    
         
            +
                description 'This method allows you to take a snapshot of the droplet once it has been powered off, which can later be restored or used to create a new droplet from the same image. Please be aware this may cause a reboot.'
         
     | 
| 
      
 211 
     | 
    
         
            +
                syntax 'race droplets create-snaphot [DROPLET_ID] [SNAPSHOT_NAME]'
         
     | 
| 
      
 212 
     | 
    
         
            +
                def create_snapshot(*args)
         
     | 
| 
      
 213 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 214 
     | 
    
         
            +
                  name = args[1]
         
     | 
| 
      
 215 
     | 
    
         
            +
                  if id.nil? || name.nil?
         
     | 
| 
      
 216 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 217 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 218 
     | 
    
         
            +
                    puts '$ race droplets snaphot [DROPLET_ID] [SNAPSHOT_NAME]'.yellow
         
     | 
| 
      
 219 
     | 
    
         
            +
                  else
         
     | 
| 
      
 220 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 221 
     | 
    
         
            +
                    result = barge.droplet.snapshot(id, name: name)
         
     | 
| 
      
 222 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 223 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 224 
     | 
    
         
            +
                    else
         
     | 
| 
      
 225 
     | 
    
         
            +
                      puts 'Snapshot generated.'.green
         
     | 
| 
      
 226 
     | 
    
         
            +
                    end
         
     | 
| 
      
 227 
     | 
    
         
            +
                  end
         
     | 
| 
      
 228 
     | 
    
         
            +
                end
         
     | 
| 
      
 229 
     | 
    
         
            +
             
     | 
| 
      
 230 
     | 
    
         
            +
                description 'Show droplet snapshots'
         
     | 
| 
      
 231 
     | 
    
         
            +
                syntax 'race droplets snaphots [DROPLET_ID]'
         
     | 
| 
      
 232 
     | 
    
         
            +
                def snapshots(*args)
         
     | 
| 
      
 233 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 234 
     | 
    
         
            +
                  if id.nil?
         
     | 
| 
      
 235 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 236 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 237 
     | 
    
         
            +
                    puts '$ race droplets snaphots [DROPLET_ID] '.yellow
         
     | 
| 
      
 238 
     | 
    
         
            +
                  else
         
     | 
| 
      
 239 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 240 
     | 
    
         
            +
                    result = barge.droplet.snapshots(id)
         
     | 
| 
      
 241 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 242 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 243 
     | 
    
         
            +
                    else
         
     | 
| 
      
 244 
     | 
    
         
            +
                      puts 'Your Droplets'.yellow
         
     | 
| 
      
 245 
     | 
    
         
            +
                      snapshots = []
         
     | 
| 
      
 246 
     | 
    
         
            +
                      snapshots << [
         
     | 
| 
      
 247 
     | 
    
         
            +
                        'Name',
         
     | 
| 
      
 248 
     | 
    
         
            +
                        'Distribution',
         
     | 
| 
      
 249 
     | 
    
         
            +
                        'Public',
         
     | 
| 
      
 250 
     | 
    
         
            +
                        'Created At'
         
     | 
| 
      
 251 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 252 
     | 
    
         
            +
                      result.snapshots.each do |snapshot|
         
     | 
| 
      
 253 
     | 
    
         
            +
                        snapshots << [
         
     | 
| 
      
 254 
     | 
    
         
            +
                          snapshot.name.to_s.red,
         
     | 
| 
      
 255 
     | 
    
         
            +
                          snapshot.distribution.to_s.red,
         
     | 
| 
      
 256 
     | 
    
         
            +
                          snapshot.status.to_s == 'active' ? 'Active'.green : 'Deactive'.red,
         
     | 
| 
      
 257 
     | 
    
         
            +
                          snapshot.created_at
         
     | 
| 
      
 258 
     | 
    
         
            +
                        ]
         
     | 
| 
      
 259 
     | 
    
         
            +
                      end
         
     | 
| 
      
 260 
     | 
    
         
            +
                      table = Terminal::Table.new rows: snapshots
         
     | 
| 
      
 261 
     | 
    
         
            +
                      puts table
         
     | 
| 
      
 262 
     | 
    
         
            +
                    end
         
     | 
| 
      
 263 
     | 
    
         
            +
             
     | 
| 
      
 264 
     | 
    
         
            +
                  end
         
     | 
| 
      
 265 
     | 
    
         
            +
                end
         
     | 
| 
      
 266 
     | 
    
         
            +
             
     | 
| 
      
 267 
     | 
    
         
            +
                description 'This method allows you to restore a droplet with a previous image or snapshot. This will be a mirror copy of the image or snapshot to your droplet. Be sure you have backed up any necessary information prior to restore.'
         
     | 
| 
      
 268 
     | 
    
         
            +
                syntax 'race droplets restore [DROPLET_ID] [IMAGE_ID]'
         
     | 
| 
      
 269 
     | 
    
         
            +
                def restore(*args)
         
     | 
| 
      
 270 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 271 
     | 
    
         
            +
                  image_id = args[1]
         
     | 
| 
      
 272 
     | 
    
         
            +
                  if id.nil? || image_id.nil?
         
     | 
| 
      
 273 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 274 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 275 
     | 
    
         
            +
                    puts '$ race droplets restore [DROPLET_ID] [IMAGE_ID]'.yellow
         
     | 
| 
      
 276 
     | 
    
         
            +
                  else
         
     | 
| 
      
 277 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 278 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{image_id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 279 
     | 
    
         
            +
                    result = barge.droplet.restore(id, image: image_id)
         
     | 
| 
      
 280 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 281 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 282 
     | 
    
         
            +
                    else
         
     | 
| 
      
 283 
     | 
    
         
            +
                      puts 'Droplets restored.'.green
         
     | 
| 
      
 284 
     | 
    
         
            +
                    end
         
     | 
| 
      
 285 
     | 
    
         
            +
                  end
         
     | 
| 
      
 286 
     | 
    
         
            +
                end
         
     | 
| 
      
 287 
     | 
    
         
            +
             
     | 
| 
      
 288 
     | 
    
         
            +
                description 'This method allows you to reinstall a droplet with a default image. This is useful if you want to start again but retain the same IP address for your droplet.'
         
     | 
| 
      
 289 
     | 
    
         
            +
                syntax 'race droplets rebuild [DROPLET_ID] [IMAGE_ID]'
         
     | 
| 
      
 290 
     | 
    
         
            +
                def rebuild(*args)
         
     | 
| 
      
 291 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 292 
     | 
    
         
            +
                  image_id = args[1]
         
     | 
| 
      
 293 
     | 
    
         
            +
                  if id.nil? || image_id.nil?
         
     | 
| 
      
 294 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 295 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 296 
     | 
    
         
            +
                    puts '$ race droplets rebuild [DROPLET_ID] [IMAGE_ID]'.yellow
         
     | 
| 
      
 297 
     | 
    
         
            +
                  else
         
     | 
| 
      
 298 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 299 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{image_id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 300 
     | 
    
         
            +
                    result = barge.droplet.rebuild(id, image: image_id)
         
     | 
| 
      
 301 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 302 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 303 
     | 
    
         
            +
                    else
         
     | 
| 
      
 304 
     | 
    
         
            +
                      puts 'Droplets rebuilded.'.green
         
     | 
| 
      
 305 
     | 
    
         
            +
                    end
         
     | 
| 
      
 306 
     | 
    
         
            +
                  end
         
     | 
| 
      
 307 
     | 
    
         
            +
                end
         
     | 
| 
      
 308 
     | 
    
         
            +
             
     | 
| 
      
 309 
     | 
    
         
            +
                description 'This method renames the droplet to the specified name.'
         
     | 
| 
      
 310 
     | 
    
         
            +
                syntax 'race droplets rename [DROPLET_ID] [NEW_NAME]'
         
     | 
| 
      
 311 
     | 
    
         
            +
                def rename(*args)
         
     | 
| 
      
 312 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 313 
     | 
    
         
            +
                  name = args[1]
         
     | 
| 
      
 314 
     | 
    
         
            +
                  if id.nil? || name.nil?
         
     | 
| 
      
 315 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 316 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 317 
     | 
    
         
            +
                    puts '$ race droplets rename [DROPLET_ID] [NEW_NAME]'.yellow
         
     | 
| 
      
 318 
     | 
    
         
            +
                  else
         
     | 
| 
      
 319 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 320 
     | 
    
         
            +
                    result = barge.droplet.rename(id, name: name)
         
     | 
| 
      
 321 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 322 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 323 
     | 
    
         
            +
                    else
         
     | 
| 
      
 324 
     | 
    
         
            +
                      puts 'Droplets renamed.'.green
         
     | 
| 
      
 325 
     | 
    
         
            +
                    end
         
     | 
| 
      
 326 
     | 
    
         
            +
                  end
         
     | 
| 
      
 327 
     | 
    
         
            +
                end
         
     | 
| 
      
 328 
     | 
    
         
            +
             
     | 
| 
      
 329 
     | 
    
         
            +
                description 'Enable IPv6 for a droplet'
         
     | 
| 
      
 330 
     | 
    
         
            +
                syntax 'race droplets enable-ipv6 [DROPLET_ID]'
         
     | 
| 
      
 331 
     | 
    
         
            +
                def enable_ipv6(*args)
         
     | 
| 
      
 332 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 333 
     | 
    
         
            +
                  if id.nil?
         
     | 
| 
      
 334 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 335 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 336 
     | 
    
         
            +
                    puts '$ race droplets enable-ipv6 [DROPLET_ID]'
         
     | 
| 
      
 337 
     | 
    
         
            +
                  else
         
     | 
| 
      
 338 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 339 
     | 
    
         
            +
                    result = barge.droplet.enable_ipv6(id)
         
     | 
| 
      
 340 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 341 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 342 
     | 
    
         
            +
                    else
         
     | 
| 
      
 343 
     | 
    
         
            +
                      puts 'IPv6 Enabled'.green
         
     | 
| 
      
 344 
     | 
    
         
            +
                    end
         
     | 
| 
      
 345 
     | 
    
         
            +
                  end
         
     | 
| 
      
 346 
     | 
    
         
            +
                end
         
     | 
| 
      
 347 
     | 
    
         
            +
             
     | 
| 
      
 348 
     | 
    
         
            +
                description 'Show droplet kernels'
         
     | 
| 
      
 349 
     | 
    
         
            +
                syntax 'race droplets kernels [DROPLET_ID]'
         
     | 
| 
      
 350 
     | 
    
         
            +
                def kernels(*args)
         
     | 
| 
      
 351 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 352 
     | 
    
         
            +
                  if id.nil?
         
     | 
| 
      
 353 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 354 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 355 
     | 
    
         
            +
                    puts '$ race droplets kernels [DROPLET_ID]'
         
     | 
| 
      
 356 
     | 
    
         
            +
                  else
         
     | 
| 
      
 357 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 358 
     | 
    
         
            +
                    result = barge.droplet.kernels(id)
         
     | 
| 
      
 359 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 360 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 361 
     | 
    
         
            +
                    else
         
     | 
| 
      
 362 
     | 
    
         
            +
                      puts 'Kernels'.yellow
         
     | 
| 
      
 363 
     | 
    
         
            +
                      kernels = []
         
     | 
| 
      
 364 
     | 
    
         
            +
             
     | 
| 
      
 365 
     | 
    
         
            +
                      kernels << %w(ID Name Version)
         
     | 
| 
      
 366 
     | 
    
         
            +
             
     | 
| 
      
 367 
     | 
    
         
            +
                      result.kernels.each do |kernel|
         
     | 
| 
      
 368 
     | 
    
         
            +
                        kernels << [
         
     | 
| 
      
 369 
     | 
    
         
            +
                          kernel.id,
         
     | 
| 
      
 370 
     | 
    
         
            +
                          kernel.name.to_s.red,
         
     | 
| 
      
 371 
     | 
    
         
            +
                          kernel.version.to_s
         
     | 
| 
      
 372 
     | 
    
         
            +
                        ]
         
     | 
| 
      
 373 
     | 
    
         
            +
                      end
         
     | 
| 
      
 374 
     | 
    
         
            +
                      table = Terminal::Table.new rows: kernels
         
     | 
| 
      
 375 
     | 
    
         
            +
                      puts table
         
     | 
| 
      
 376 
     | 
    
         
            +
                    end
         
     | 
| 
      
 377 
     | 
    
         
            +
                  end
         
     | 
| 
      
 378 
     | 
    
         
            +
                end
         
     | 
| 
      
 379 
     | 
    
         
            +
             
     | 
| 
      
 380 
     | 
    
         
            +
                description "Change a droplet's kernel"
         
     | 
| 
      
 381 
     | 
    
         
            +
                syntax 'race droplets change-kernel [DROPLET_ID] [KERNEL_ID]'
         
     | 
| 
      
 382 
     | 
    
         
            +
                def change_kernel(*args)
         
     | 
| 
      
 383 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 384 
     | 
    
         
            +
                  kernel_id = args[1]
         
     | 
| 
      
 385 
     | 
    
         
            +
                  if id.nil? || kernel_id.nil?
         
     | 
| 
      
 386 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 387 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 388 
     | 
    
         
            +
                    puts '$ race droplets change-kernel [DROPLET_ID] [KERNEL_ID]'
         
     | 
| 
      
 389 
     | 
    
         
            +
                  else
         
     | 
| 
      
 390 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 391 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{kernel_id}" unless kernel_id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 392 
     | 
    
         
            +
                    result = barge.droplet.change_kernel(id, kernel: kernel_id)
         
     | 
| 
      
 393 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 394 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 395 
     | 
    
         
            +
                    else
         
     | 
| 
      
 396 
     | 
    
         
            +
                      puts 'Droplet kernel changed'.green
         
     | 
| 
      
 397 
     | 
    
         
            +
                    end
         
     | 
| 
      
 398 
     | 
    
         
            +
                  end
         
     | 
| 
      
 399 
     | 
    
         
            +
                end
         
     | 
| 
      
 400 
     | 
    
         
            +
             
     | 
| 
      
 401 
     | 
    
         
            +
                description 'Disable backups for a droplet'
         
     | 
| 
      
 402 
     | 
    
         
            +
                syntax 'race droplets disable-backup [DROPLET_ID]'
         
     | 
| 
      
 403 
     | 
    
         
            +
                def disable_backup(*args)
         
     | 
| 
      
 404 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 405 
     | 
    
         
            +
                  if id.nil?
         
     | 
| 
      
 406 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 407 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 408 
     | 
    
         
            +
                    puts '$ race droplets disable-backup [DROPLET_ID]'
         
     | 
| 
      
 409 
     | 
    
         
            +
                  else
         
     | 
| 
      
 410 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 411 
     | 
    
         
            +
                    result = barge.droplet.disable_backups(id)
         
     | 
| 
      
 412 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 413 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 414 
     | 
    
         
            +
                    else
         
     | 
| 
      
 415 
     | 
    
         
            +
                      puts 'Backup disabled'.green
         
     | 
| 
      
 416 
     | 
    
         
            +
                    end
         
     | 
| 
      
 417 
     | 
    
         
            +
                  end
         
     | 
| 
      
 418 
     | 
    
         
            +
                end
         
     | 
| 
      
 419 
     | 
    
         
            +
             
     | 
| 
      
 420 
     | 
    
         
            +
                description 'Enable private networking for a droplet'
         
     | 
| 
      
 421 
     | 
    
         
            +
                syntax 'race droplets enable-private-network [DROPLET_ID]'
         
     | 
| 
      
 422 
     | 
    
         
            +
                def enable_private_network(*args)
         
     | 
| 
      
 423 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 424 
     | 
    
         
            +
                  if id.nil?
         
     | 
| 
      
 425 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 426 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 427 
     | 
    
         
            +
                    puts '$ race droplets enable-private-network [DROPLET_ID]'
         
     | 
| 
      
 428 
     | 
    
         
            +
                  else
         
     | 
| 
      
 429 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 430 
     | 
    
         
            +
                    result = barge.droplet.enable_private_networking(id)
         
     | 
| 
      
 431 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 432 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 433 
     | 
    
         
            +
                    else
         
     | 
| 
      
 434 
     | 
    
         
            +
                      puts 'Backup disabled'.green
         
     | 
| 
      
 435 
     | 
    
         
            +
                    end
         
     | 
| 
      
 436 
     | 
    
         
            +
                  end
         
     | 
| 
      
 437 
     | 
    
         
            +
                end
         
     | 
| 
      
 438 
     | 
    
         
            +
             
     | 
| 
      
 439 
     | 
    
         
            +
                private
         
     | 
| 
      
 440 
     | 
    
         
            +
             
     | 
| 
      
 441 
     | 
    
         
            +
                def config(value)
         
     | 
| 
      
 442 
     | 
    
         
            +
                  @config ||= value
         
     | 
| 
      
 443 
     | 
    
         
            +
                end
         
     | 
| 
      
 444 
     | 
    
         
            +
              end
         
     | 
| 
      
 445 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,121 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Race::Run
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Images < Base
         
     | 
| 
      
 3 
     | 
    
         
            +
                description 'This method returns all the available images that can be accessed by your client ID. You will have access to all public images by default, and any snapshots or backups that you have created in your own account.'
         
     | 
| 
      
 4 
     | 
    
         
            +
                syntax 'race images'
         
     | 
| 
      
 5 
     | 
    
         
            +
                def run(*_args)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  result = barge.image.all
         
     | 
| 
      
 7 
     | 
    
         
            +
                  if !result.success?
         
     | 
| 
      
 8 
     | 
    
         
            +
                    puts 'Error: Please check your information'.red
         
     | 
| 
      
 9 
     | 
    
         
            +
                  else
         
     | 
| 
      
 10 
     | 
    
         
            +
                    puts 'Images'.yellow
         
     | 
| 
      
 11 
     | 
    
         
            +
                    rows = []
         
     | 
| 
      
 12 
     | 
    
         
            +
                    rows << %w(ID Name Distribution Public Regions)
         
     | 
| 
      
 13 
     | 
    
         
            +
                    result.images.each do |image|
         
     | 
| 
      
 14 
     | 
    
         
            +
                      rows << [
         
     | 
| 
      
 15 
     | 
    
         
            +
                        image.id,
         
     | 
| 
      
 16 
     | 
    
         
            +
                        image.name.to_s.red,
         
     | 
| 
      
 17 
     | 
    
         
            +
                        image.distribution.to_s.red,
         
     | 
| 
      
 18 
     | 
    
         
            +
                        image.public.to_s == 'true' ? 'True'.green : 'False'.red,
         
     | 
| 
      
 19 
     | 
    
         
            +
                        image.regions.join(',').yellow
         
     | 
| 
      
 20 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end
         
     | 
| 
      
 22 
     | 
    
         
            +
                    table = Terminal::Table.new rows: rows
         
     | 
| 
      
 23 
     | 
    
         
            +
                    puts table
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                description 'This method displays the attributes of an image.'
         
     | 
| 
      
 28 
     | 
    
         
            +
                syntax 'race images show [IMAGE_ID]'
         
     | 
| 
      
 29 
     | 
    
         
            +
                def show(*args)
         
     | 
| 
      
 30 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 31 
     | 
    
         
            +
                  if id.nil?
         
     | 
| 
      
 32 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 33 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 34 
     | 
    
         
            +
                    puts '$ race images show [IMAGE_ID]'.yellow
         
     | 
| 
      
 35 
     | 
    
         
            +
                  else
         
     | 
| 
      
 36 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 37 
     | 
    
         
            +
                    result = barge.image.show(id)
         
     | 
| 
      
 38 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 39 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 40 
     | 
    
         
            +
                    else
         
     | 
| 
      
 41 
     | 
    
         
            +
                      puts 'Images'.yellow
         
     | 
| 
      
 42 
     | 
    
         
            +
                      rows = []
         
     | 
| 
      
 43 
     | 
    
         
            +
                      rows << %w(ID Name Distribution Public Regions)
         
     | 
| 
      
 44 
     | 
    
         
            +
                      image = result.image
         
     | 
| 
      
 45 
     | 
    
         
            +
                      rows << [
         
     | 
| 
      
 46 
     | 
    
         
            +
                        image.id,
         
     | 
| 
      
 47 
     | 
    
         
            +
                        image.name.to_s.red,
         
     | 
| 
      
 48 
     | 
    
         
            +
                        image.distribution.to_s.red,
         
     | 
| 
      
 49 
     | 
    
         
            +
                        image.public.to_s == 'true' ? 'True'.green : 'False'.red,
         
     | 
| 
      
 50 
     | 
    
         
            +
                        image.regions.join(',').yellow
         
     | 
| 
      
 51 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                      table = Terminal::Table.new rows: rows
         
     | 
| 
      
 54 
     | 
    
         
            +
                      puts table
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                    end
         
     | 
| 
      
 57 
     | 
    
         
            +
                  end
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                description 'This method allows you to destroy an image. There is no way to restore a deleted image so be careful and ensure your data is properly backed up.'
         
     | 
| 
      
 61 
     | 
    
         
            +
                syntax 'race images destroy [IMAGE_ID]'
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                def destroy(*args)
         
     | 
| 
      
 64 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 65 
     | 
    
         
            +
                  if id.nil?
         
     | 
| 
      
 66 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 67 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 68 
     | 
    
         
            +
                    puts '$ race images destroy [IMAGE_ID]'.yellow
         
     | 
| 
      
 69 
     | 
    
         
            +
                  else
         
     | 
| 
      
 70 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 71 
     | 
    
         
            +
                    result = barge.image.destroy(id)
         
     | 
| 
      
 72 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 73 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 74 
     | 
    
         
            +
                    else
         
     | 
| 
      
 75 
     | 
    
         
            +
                      puts 'Image destroyed'.green
         
     | 
| 
      
 76 
     | 
    
         
            +
                    end
         
     | 
| 
      
 77 
     | 
    
         
            +
                  end
         
     | 
| 
      
 78 
     | 
    
         
            +
                end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                description 'This method allows you to transfer an image to a specified region.'
         
     | 
| 
      
 81 
     | 
    
         
            +
                syntax 'race images transfer [IMAGE_ID] [REGION_ID]'
         
     | 
| 
      
 82 
     | 
    
         
            +
                def transfer(*args)
         
     | 
| 
      
 83 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 84 
     | 
    
         
            +
                  region_id = args[1]
         
     | 
| 
      
 85 
     | 
    
         
            +
                  if id.nil? || region_id.nil?
         
     | 
| 
      
 86 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 87 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 88 
     | 
    
         
            +
                    puts '$ race images transfer [IMAGE_ID] [REGION_ID]'.yellow
         
     | 
| 
      
 89 
     | 
    
         
            +
                  else
         
     | 
| 
      
 90 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 91 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{region_id}" unless region_id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 92 
     | 
    
         
            +
                    result = barge.image.transfer(id, region: region_id)
         
     | 
| 
      
 93 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 94 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 95 
     | 
    
         
            +
                    else
         
     | 
| 
      
 96 
     | 
    
         
            +
                      puts 'Image transfered'.green
         
     | 
| 
      
 97 
     | 
    
         
            +
                    end
         
     | 
| 
      
 98 
     | 
    
         
            +
                  end
         
     | 
| 
      
 99 
     | 
    
         
            +
                end
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
                description 'Update image'
         
     | 
| 
      
 102 
     | 
    
         
            +
                syntax 'race images update [IMAGE_ID] [NEW_IMAGE_NAME]'
         
     | 
| 
      
 103 
     | 
    
         
            +
                def update(*args)
         
     | 
| 
      
 104 
     | 
    
         
            +
                  id = args[0]
         
     | 
| 
      
 105 
     | 
    
         
            +
                  name = args[1]
         
     | 
| 
      
 106 
     | 
    
         
            +
                  if id.nil? || name.nil?
         
     | 
| 
      
 107 
     | 
    
         
            +
                    puts 'Argument Error'.red
         
     | 
| 
      
 108 
     | 
    
         
            +
                    puts 'Usage'.yellow
         
     | 
| 
      
 109 
     | 
    
         
            +
                    puts '$ race images transfer [IMAGE_ID] [NAME]'.yellow
         
     | 
| 
      
 110 
     | 
    
         
            +
                  else
         
     | 
| 
      
 111 
     | 
    
         
            +
                    fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
         
     | 
| 
      
 112 
     | 
    
         
            +
                    result = barge.image.update(id, name: name)
         
     | 
| 
      
 113 
     | 
    
         
            +
                    if !result.success?
         
     | 
| 
      
 114 
     | 
    
         
            +
                      puts "#{result.message}".red
         
     | 
| 
      
 115 
     | 
    
         
            +
                    else
         
     | 
| 
      
 116 
     | 
    
         
            +
                      puts 'Image updated'.green
         
     | 
| 
      
 117 
     | 
    
         
            +
                    end
         
     | 
| 
      
 118 
     | 
    
         
            +
                  end
         
     | 
| 
      
 119 
     | 
    
         
            +
                end
         
     | 
| 
      
 120 
     | 
    
         
            +
              end
         
     | 
| 
      
 121 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,22 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Race::Run
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Info < Base
         
     | 
| 
      
 3 
     | 
    
         
            +
                description 'Show your API information'
         
     | 
| 
      
 4 
     | 
    
         
            +
                def show
         
     | 
| 
      
 5 
     | 
    
         
            +
                  puts "Access Tokens: #{Race::Config.get('api_key')}".yellow
         
     | 
| 
      
 6 
     | 
    
         
            +
                end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                description 'Change your API information'
         
     | 
| 
      
 9 
     | 
    
         
            +
                def change(*_args)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  config = Netrc.read("#{(ENV['HOME'] || './')}/race.netrc")
         
     | 
| 
      
 11 
     | 
    
         
            +
                  api_key = [(print 'Access Tokens: '), STDIN.gets.rstrip][1]
         
     | 
| 
      
 12 
     | 
    
         
            +
                  client_id = 'empty'
         
     | 
| 
      
 13 
     | 
    
         
            +
                  if api_key.empty?
         
     | 
| 
      
 14 
     | 
    
         
            +
                    puts 'Please fill all fields'.red
         
     | 
| 
      
 15 
     | 
    
         
            +
                  else
         
     | 
| 
      
 16 
     | 
    
         
            +
                    config['api.digitalocean.com'] = api_key, client_id
         
     | 
| 
      
 17 
     | 
    
         
            +
                    config.save
         
     | 
| 
      
 18 
     | 
    
         
            +
                    puts 'Informations is changed'.red
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Race::Run
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Regions < Base
         
     | 
| 
      
 3 
     | 
    
         
            +
                description 'This method will return all the available regions within the DigitalRaceean cloud.'
         
     | 
| 
      
 4 
     | 
    
         
            +
                syntax 'race regions'
         
     | 
| 
      
 5 
     | 
    
         
            +
                def run
         
     | 
| 
      
 6 
     | 
    
         
            +
                  result = barge.region.all
         
     | 
| 
      
 7 
     | 
    
         
            +
                  if !result.success?
         
     | 
| 
      
 8 
     | 
    
         
            +
                    puts 'Error: Please check your information'.red
         
     | 
| 
      
 9 
     | 
    
         
            +
                  else
         
     | 
| 
      
 10 
     | 
    
         
            +
                    puts 'Regions'.yellow
         
     | 
| 
      
 11 
     | 
    
         
            +
                    droplets = []
         
     | 
| 
      
 12 
     | 
    
         
            +
                    droplets << %w(ID Name)
         
     | 
| 
      
 13 
     | 
    
         
            +
                    result.regions.each do |region|
         
     | 
| 
      
 14 
     | 
    
         
            +
                      droplets << [
         
     | 
| 
      
 15 
     | 
    
         
            +
                        region.slug,
         
     | 
| 
      
 16 
     | 
    
         
            +
                        region.name.to_s.red
         
     | 
| 
      
 17 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 18 
     | 
    
         
            +
                    end
         
     | 
| 
      
 19 
     | 
    
         
            +
                    table = Terminal::Table.new rows: droplets
         
     | 
| 
      
 20 
     | 
    
         
            +
                    puts table
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,37 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Race::Run
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Sizes < Base
         
     | 
| 
      
 3 
     | 
    
         
            +
                description 'This method returns all the available sizes that can be used to create a droplet.'
         
     | 
| 
      
 4 
     | 
    
         
            +
                syntax 'race sizes'
         
     | 
| 
      
 5 
     | 
    
         
            +
                def run
         
     | 
| 
      
 6 
     | 
    
         
            +
                  result = barge.size.all
         
     | 
| 
      
 7 
     | 
    
         
            +
                  if !result.success?
         
     | 
| 
      
 8 
     | 
    
         
            +
                    puts "Error: #{result['error_message']}".red
         
     | 
| 
      
 9 
     | 
    
         
            +
                  else
         
     | 
| 
      
 10 
     | 
    
         
            +
                    puts 'Sizes'.yellow
         
     | 
| 
      
 11 
     | 
    
         
            +
                    rows = []
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                    rows << [
         
     | 
| 
      
 14 
     | 
    
         
            +
                      'ID',
         
     | 
| 
      
 15 
     | 
    
         
            +
                      'Memory',
         
     | 
| 
      
 16 
     | 
    
         
            +
                      'Disk',
         
     | 
| 
      
 17 
     | 
    
         
            +
                      'Cpu',
         
     | 
| 
      
 18 
     | 
    
         
            +
                      'Price (Monthly)',
         
     | 
| 
      
 19 
     | 
    
         
            +
                      'Price (Hourly)'
         
     | 
| 
      
 20 
     | 
    
         
            +
                    ]
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                    result.sizes.each do |size|
         
     | 
| 
      
 23 
     | 
    
         
            +
                      rows << [
         
     | 
| 
      
 24 
     | 
    
         
            +
                        size.slug,
         
     | 
| 
      
 25 
     | 
    
         
            +
                        size.memory.to_s + ' MB',
         
     | 
| 
      
 26 
     | 
    
         
            +
                        size.disk.to_s + ' GB',
         
     | 
| 
      
 27 
     | 
    
         
            +
                        size.vcpus,
         
     | 
| 
      
 28 
     | 
    
         
            +
                        '$ ' + size.price_monthly.to_s,
         
     | 
| 
      
 29 
     | 
    
         
            +
                        '$ ' + size.price_hourly.to_s
         
     | 
| 
      
 30 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 31 
     | 
    
         
            +
                    end
         
     | 
| 
      
 32 
     | 
    
         
            +
                    table = Terminal::Table.new rows: rows
         
     | 
| 
      
 33 
     | 
    
         
            +
                    puts table
         
     | 
| 
      
 34 
     | 
    
         
            +
                  end
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
              end
         
     | 
| 
      
 37 
     | 
    
         
            +
            end
         
     |