rightscale-cli 0.3.0 → 0.4.0
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 +4 -4
 - data/README.md +16 -1
 - data/lib/rightscale_cli.rb +1 -1
 - data/lib/rightscale_cli/base.rb +5 -0
 - data/lib/rightscale_cli/client.rb +36 -1
 - data/lib/rightscale_cli/dashboard.rb +17 -1
 - data/lib/rightscale_cli/logger.rb +36 -13
 - data/lib/rightscale_cli/multi_cloud_images.rb +56 -0
 - data/lib/rightscale_cli/repositories.rb +63 -0
 - data/lib/rightscale_cli/rightscale_cli.rb +8 -1
 - data/lib/rightscale_cli/version.rb +1 -1
 - data/lib/rightscale_cli/volumes.rb +69 -0
 - data/lib/yesno.rb +31 -0
 - metadata +7 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: a4bb058deb48db44d302717cb5975b254c4d4914
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 5e826a2b5d6a6b68823a61dde906f36f47cace1b
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2f16f06941398b9ad84b3f06121879c549e67dc532195c411cb34af7ca469b097077089438382edead30d7cddf728325c48b9ce07975a15c4ce2f674eef103e0
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 2747385386f8dedd7863e41512e164f8c7684da80fad870a9170c5aa24b3ebf2a7cea9a2344d045381741dd76dafd9e5970f356af709c09d2bfd20f1764b0957
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -21,7 +21,22 @@ The executable, `rs` will conflict with RS(1) on Mac OS X (http://www.freebsd.or 
     | 
|
| 
       21 
21 
     | 
    
         
             
            As a result, to avoid overwriting the `/usr/bin/rs` binary, use a different location in your `~/.gemrc` or `/etc/gemrc`, for example:
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
                gem: --bindir /usr/local/bin
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            ## Configuration
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            Setup `~/.rightscale/right_api_client.yml` with your RightScale credentials.
         
     | 
| 
      
 28 
     | 
    
         
            +
            Ensure the correct shard is for your account is set with `:api_url`.
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            An example file is available, https://github.com/rightscale/right_api_client/blob/master/config/login.yml.example.
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
            ## Usage
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            There is one command, `rs`.
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
             * For a list of commands, type `rs help`
         
     | 
| 
      
 37 
     | 
    
         
            +
             * For a list of subcommands, type `rs <namespace> help`, e.g. `rs arrays help`
         
     | 
| 
      
 38 
     | 
    
         
            +
             * For usage options of a subcommand, type `rs <namespace> help <subcommand>`, e.g. `rs arrays help instances`
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
       25 
40 
     | 
    
         
             
            ## License and Authors
         
     | 
| 
       26 
41 
     | 
    
         | 
| 
       27 
42 
     | 
    
         
             
            * Author:: Chris Fordham <chris [at] fordham [hyphon] nagy [dot] id [dot] au>
         
     | 
    
        data/lib/rightscale_cli.rb
    CHANGED
    
    
| 
         @@ -14,5 +14,40 @@ 
     | 
|
| 
       14 
14 
     | 
    
         
             
            # See the License for the specific language governing permissions and
         
     | 
| 
       15 
15 
     | 
    
         
             
            # limitations under the License.
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
            require 'rightscale_cli/config'
         
     | 
| 
       18 
17 
     | 
    
         
             
            require 'right_api_client'
         
     | 
| 
      
 18 
     | 
    
         
            +
            require 'rightscale_cli/config'
         
     | 
| 
      
 19 
     | 
    
         
            +
            require 'rightscale_cli/logger'
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            class RightScaleCLI
         
     | 
| 
      
 22 
     | 
    
         
            +
              class Client
         
     | 
| 
      
 23 
     | 
    
         
            +
                attr_accessor :render
         
     | 
| 
      
 24 
     | 
    
         
            +
                
         
     | 
| 
      
 25 
     | 
    
         
            +
                def initialize(*args)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  @client = RightApi::Client.new(RightScaleCLI::Config::API)
         
     | 
| 
      
 27 
     | 
    
         
            +
                  @logger = RightScaleCLI::Logger.new()
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                def get(resource)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  result = []
         
     | 
| 
      
 32 
     | 
    
         
            +
                  @client.send(resource).index.each { |record|
         
     | 
| 
      
 33 
     | 
    
         
            +
                    result.push(record.raw)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  }
         
     | 
| 
      
 35 
     | 
    
         
            +
                  return result
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                def create(resource, params)
         
     | 
| 
      
 39 
     | 
    
         
            +
                  resource = @client.send("#{resource}s").create(resource => params)
         
     | 
| 
      
 40 
     | 
    
         
            +
                  @logger.info("Created #{resource.href}.")
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                def destroy(resource, resource_id)
         
     | 
| 
      
 44 
     | 
    
         
            +
                  resource = @client.send("#{resource}s").index({ :id => resource_id })
         
     | 
| 
      
 45 
     | 
    
         
            +
                  resource.destroy
         
     | 
| 
      
 46 
     | 
    
         
            +
                  @logger.info("Deleted #{resource.href}.")
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                def render(data, root_element, options)
         
     | 
| 
      
 50 
     | 
    
         
            +
                  RightScaleCLI::Output.render(data, root_element, options)
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
              end
         
     | 
| 
      
 53 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -40,7 +40,7 @@ class RightScaleCLI 
     | 
|
| 
       40 
40 
     | 
    
         
             
                  puts response.body
         
     | 
| 
       41 
41 
     | 
    
         
             
                end
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
                desc "scrape", "Scrape a dashboard URL by href"
         
     | 
| 
      
 43 
     | 
    
         
            +
                desc "scrape", "Scrape a dashboard URL by href."
         
     | 
| 
       44 
44 
     | 
    
         
             
                def scrape(href)
         
     | 
| 
       45 
45 
     | 
    
         
             
                  rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
         @@ -54,6 +54,22 @@ class RightScaleCLI 
     | 
|
| 
       54 
54 
     | 
    
         
             
                  response = http.request(request)
         
     | 
| 
       55 
55 
     | 
    
         
             
                  puts response.body
         
     | 
| 
       56 
56 
     | 
    
         
             
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                desc "ajax", "Scrape a dashboard URL via AJAX."
         
     | 
| 
      
 59 
     | 
    
         
            +
                def ajax(href)
         
     | 
| 
      
 60 
     | 
    
         
            +
                  rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                  uri = URI.parse("#{rightscale.api_url}#{href}")
         
     | 
| 
      
 63 
     | 
    
         
            +
                  http = Net::HTTP.new(uri.host, uri.port)
         
     | 
| 
      
 64 
     | 
    
         
            +
                  http.use_ssl = true
         
     | 
| 
      
 65 
     | 
    
         
            +
                  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
         
     | 
| 
      
 66 
     | 
    
         
            +
                  request = Net::HTTP::Get.new(uri.request_uri)
         
     | 
| 
      
 67 
     | 
    
         
            +
                  request.add_field("Cookie", rightscale.last_request[:request].headers[:cookie])
         
     | 
| 
      
 68 
     | 
    
         
            +
                  request.add_field("X-Requested-With", "XMLHttpRequest")
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                  response = http.request(request)
         
     | 
| 
      
 71 
     | 
    
         
            +
                  puts response.body
         
     | 
| 
      
 72 
     | 
    
         
            +
                end
         
     | 
| 
       57 
73 
     | 
    
         | 
| 
       58 
74 
     | 
    
         
             
                def self.banner(task, namespace = true, subcommand = false)
         
     | 
| 
       59 
75 
     | 
    
         
             
                  "#{basename} #{task.formatted_usage(self, true, subcommand)}"
         
     | 
| 
         @@ -15,20 +15,43 @@ 
     | 
|
| 
       15 
15 
     | 
    
         
             
            # limitations under the License.
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
            require 'logger'
         
     | 
| 
      
 18 
     | 
    
         
            +
            require 'rightscale_cli/config'
         
     | 
| 
       18 
19 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
               
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                 
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
            class RightScaleCLI
         
     | 
| 
      
 21 
     | 
    
         
            +
              class Logger
         
     | 
| 
      
 22 
     | 
    
         
            +
                attr_accessor :log
         
     | 
| 
      
 23 
     | 
    
         
            +
                
         
     | 
| 
      
 24 
     | 
    
         
            +
                def initialize(*args)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  @log_init_msg = 'Initializing Logging using '
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                  if ENV['RIGHT_API_CLIENT_LOG']
         
     | 
| 
      
 28 
     | 
    
         
            +
                    if File.exists?(ENV['RIGHT_API_CLIENT_LOG'])
         
     | 
| 
      
 29 
     | 
    
         
            +
                      file = File.open(ENV['RIGHT_API_CLIENT_LOG'], File::WRONLY | File::APPEND)
         
     | 
| 
      
 30 
     | 
    
         
            +
                    else
         
     | 
| 
      
 31 
     | 
    
         
            +
                      file = ENV['RIGHT_API_CLIENT_LOG']
         
     | 
| 
      
 32 
     | 
    
         
            +
                    end
         
     | 
| 
      
 33 
     | 
    
         
            +
                    @log = ::Logger.new(file)
         
     | 
| 
      
 34 
     | 
    
         
            +
                    @log_init_msg += ENV['RIGHT_API_CLIENT_LOG']
         
     | 
| 
      
 35 
     | 
    
         
            +
                  else
         
     | 
| 
      
 36 
     | 
    
         
            +
                    @log = ::Logger.new(STDOUT)
         
     | 
| 
      
 37 
     | 
    
         
            +
                    @log_init_msg += 'STDOUT'
         
     | 
| 
      
 38 
     | 
    
         
            +
                  end
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                def init_message()
         
     | 
| 
      
 42 
     | 
    
         
            +
                  @log.info @log_init_msg
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                def info(msg)
         
     | 
| 
      
 46 
     | 
    
         
            +
                  @log.info msg
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
                
         
     | 
| 
      
 49 
     | 
    
         
            +
                def debug(msg)
         
     | 
| 
      
 50 
     | 
    
         
            +
                  @log.debug msg
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                def error(msg)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  @log.error msg
         
     | 
| 
       26 
55 
     | 
    
         
             
                end
         
     | 
| 
       27 
     | 
    
         
            -
                $log = Logger.new(file)
         
     | 
| 
       28 
     | 
    
         
            -
                log_init_msg += ENV['RIGHT_API_CLIENT_LOG']
         
     | 
| 
       29 
     | 
    
         
            -
              else
         
     | 
| 
       30 
     | 
    
         
            -
                $log = Logger.new(STDOUT)
         
     | 
| 
       31 
     | 
    
         
            -
                log_init_msg += 'STDOUT'
         
     | 
| 
       32 
56 
     | 
    
         
             
              end
         
     | 
| 
       33 
     | 
    
         
            -
              $log.info log_init_msg
         
     | 
| 
       34 
57 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,56 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Author:: Chris Fordham (<chris@fordham-nagy.id.au>)
         
     | 
| 
      
 2 
     | 
    
         
            +
            # Copyright:: Copyright (c) 2013 Chris Fordham
         
     | 
| 
      
 3 
     | 
    
         
            +
            # License:: Apache License, Version 2.0
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
      
 6 
     | 
    
         
            +
            # you may not use this file except in compliance with the License.
         
     | 
| 
      
 7 
     | 
    
         
            +
            # You may obtain a copy of the License at
         
     | 
| 
      
 8 
     | 
    
         
            +
            #
         
     | 
| 
      
 9 
     | 
    
         
            +
            #     http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
      
 10 
     | 
    
         
            +
            #
         
     | 
| 
      
 11 
     | 
    
         
            +
            # Unless required by applicable law or agreed to in writing, software
         
     | 
| 
      
 12 
     | 
    
         
            +
            # distributed under the License is distributed on an "AS IS" BASIS,
         
     | 
| 
      
 13 
     | 
    
         
            +
            # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         
     | 
| 
      
 14 
     | 
    
         
            +
            # See the License for the specific language governing permissions and
         
     | 
| 
      
 15 
     | 
    
         
            +
            # limitations under the License.
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            require 'thor'
         
     | 
| 
      
 18 
     | 
    
         
            +
            require 'yaml'
         
     | 
| 
      
 19 
     | 
    
         
            +
            require 'right_api_client'
         
     | 
| 
      
 20 
     | 
    
         
            +
            require 'rightscale_cli/client'
         
     | 
| 
      
 21 
     | 
    
         
            +
            require 'rightscale_cli/logger'
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            class RightScaleCLI
         
     | 
| 
      
 24 
     | 
    
         
            +
              class MultiCloudImages < Thor
         
     | 
| 
      
 25 
     | 
    
         
            +
                namespace :mcis
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                def initialize(*args)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  super
         
     | 
| 
      
 29 
     | 
    
         
            +
                  @client = RightScaleCLI::Client.new()
         
     | 
| 
      
 30 
     | 
    
         
            +
                  @logger = RightScaleCLI::Logger.new()
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                # include render options
         
     | 
| 
      
 34 
     | 
    
         
            +
                eval(IO.read("#{File.dirname(File.expand_path(__FILE__))}/render_options.rb"), binding)
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                desc "list", "Lists all MultiCloud Images."
         
     | 
| 
      
 37 
     | 
    
         
            +
                def list()
         
     | 
| 
      
 38 
     | 
    
         
            +
                  @logger.info('Retrieving all MultiCloud Images...')
         
     | 
| 
      
 39 
     | 
    
         
            +
                  @client.render(@client.get('multi_cloud_images'), 'multi_cloud_images', options)
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                desc "create", "Creates a MultiCloud Image."
         
     | 
| 
      
 43 
     | 
    
         
            +
                def create(name, description)
         
     | 
| 
      
 44 
     | 
    
         
            +
                  @client.create('multi_cloud_image', { :name => name, :description => description })
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                desc "destroy", "Deletes a MultiCloud Image."
         
     | 
| 
      
 48 
     | 
    
         
            +
                def destroy(multi_cloud_image_id)
         
     | 
| 
      
 49 
     | 
    
         
            +
                  @client.destroy('multi_cloud_image', multi_cloud_image_id)
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                def self.banner(task, namespace = true, subcommand = false)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  "#{basename} #{task.formatted_usage(self, true, subcommand)}"
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
      
 56 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,63 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Author:: Chris Fordham (<chris@fordham-nagy.id.au>)
         
     | 
| 
      
 2 
     | 
    
         
            +
            # Copyright:: Copyright (c) 2013 Chris Fordham
         
     | 
| 
      
 3 
     | 
    
         
            +
            # License:: Apache License, Version 2.0
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
      
 6 
     | 
    
         
            +
            # you may not use this file except in compliance with the License.
         
     | 
| 
      
 7 
     | 
    
         
            +
            # You may obtain a copy of the License at
         
     | 
| 
      
 8 
     | 
    
         
            +
            #
         
     | 
| 
      
 9 
     | 
    
         
            +
            #     http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
      
 10 
     | 
    
         
            +
            #
         
     | 
| 
      
 11 
     | 
    
         
            +
            # Unless required by applicable law or agreed to in writing, software
         
     | 
| 
      
 12 
     | 
    
         
            +
            # distributed under the License is distributed on an "AS IS" BASIS,
         
     | 
| 
      
 13 
     | 
    
         
            +
            # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         
     | 
| 
      
 14 
     | 
    
         
            +
            # See the License for the specific language governing permissions and
         
     | 
| 
      
 15 
     | 
    
         
            +
            # limitations under the License.
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            require 'thor'
         
     | 
| 
      
 18 
     | 
    
         
            +
            require 'right_api_client'
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
            class RightScaleCLI
         
     | 
| 
      
 21 
     | 
    
         
            +
              class Repositories < Thor
         
     | 
| 
      
 22 
     | 
    
         
            +
                namespace :repositories
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                desc "list", "Lists all (Chef) Repositories."
         
     | 
| 
      
 25 
     | 
    
         
            +
                def list()
         
     | 
| 
      
 26 
     | 
    
         
            +
                  repositories = []
         
     | 
| 
      
 27 
     | 
    
         
            +
                  RightApi::Client.new(RightScaleCLI::Config::API).repositories.index.each { |repos| repositories.push(repos.raw) }  
         
     | 
| 
      
 28 
     | 
    
         
            +
                  RightScaleCLI::Output.render(repositories, 'repositories', options)
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                desc "create", "Creates a (Chef) Repository."
         
     | 
| 
      
 32 
     | 
    
         
            +
                def create(name, source, source_ref)
         
     | 
| 
      
 33 
     | 
    
         
            +
                  # create profile of the repository to add
         
     | 
| 
      
 34 
     | 
    
         
            +
                  # http://reference.rightscale.com/api1.5/resources/ResourceRepositories.html#create
         
     | 
| 
      
 35 
     | 
    
         
            +
                  repository = {}
         
     | 
| 
      
 36 
     | 
    
         
            +
                  repository['source_type'] = 'git'     # only git supported so far
         
     | 
| 
      
 37 
     | 
    
         
            +
                  repository['auto_import'] = true
         
     | 
| 
      
 38 
     | 
    
         
            +
                  repository['source'] = source
         
     | 
| 
      
 39 
     | 
    
         
            +
                
         
     | 
| 
      
 40 
     | 
    
         
            +
                  # not yet supported by CLI
         
     | 
| 
      
 41 
     | 
    
         
            +
                  repository['credentials'] = {}
         
     | 
| 
      
 42 
     | 
    
         
            +
                  repository['credentials']['ssh_key'] = 'text:'    # needed due to bad validation
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                  repository['name'] = "#{name}"
         
     | 
| 
      
 45 
     | 
    
         
            +
                  repository['commit_reference'] = source_ref
         
     | 
| 
      
 46 
     | 
    
         
            +
                  repository['description'] = ""      # todo
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                  puts repository if options[:verbose]
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                  $log.info "Creating RightScale repository, '#{repository['name']}'."
         
     | 
| 
      
 51 
     | 
    
         
            +
                  repo = RightApi::Client.new(RightScaleCLI::Config::API).repositories.create({ :repository => repository })
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                desc "destroy", "Deletes a (Chef) Repository."
         
     | 
| 
      
 55 
     | 
    
         
            +
                def destroy(id)
         
     | 
| 
      
 56 
     | 
    
         
            +
                  RightApi::Client.new(RightScaleCLI::Config::API).repositories.index(:id => id).destroy
         
     | 
| 
      
 57 
     | 
    
         
            +
                end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                def self.banner(task, namespace = true, subcommand = false)
         
     | 
| 
      
 60 
     | 
    
         
            +
                  "#{basename} #{task.formatted_usage(self, true, subcommand)}"
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
              end
         
     | 
| 
      
 63 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -15,14 +15,18 @@ 
     | 
|
| 
       15 
15 
     | 
    
         
             
            # limitations under the License.
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
            require 'thor'
         
     | 
| 
       18 
     | 
    
         
            -
            require 'rightscale_cli/ 
     | 
| 
      
 18 
     | 
    
         
            +
            require 'rightscale_cli/config'
         
     | 
| 
      
 19 
     | 
    
         
            +
            require 'rightscale_cli/logger'
         
     | 
| 
       19 
20 
     | 
    
         
             
            require 'rightscale_cli/clouds'
         
     | 
| 
       20 
21 
     | 
    
         
             
            require 'rightscale_cli/dashboard'
         
     | 
| 
       21 
22 
     | 
    
         
             
            require 'rightscale_cli/deployments'
         
     | 
| 
       22 
23 
     | 
    
         
             
            require 'rightscale_cli/instances'
         
     | 
| 
      
 24 
     | 
    
         
            +
            require 'rightscale_cli/multi_cloud_images'
         
     | 
| 
      
 25 
     | 
    
         
            +
            require 'rightscale_cli/repositories'
         
     | 
| 
       23 
26 
     | 
    
         
             
            require 'rightscale_cli/servers'
         
     | 
| 
       24 
27 
     | 
    
         
             
            require 'rightscale_cli/server_arrays'
         
     | 
| 
       25 
28 
     | 
    
         
             
            require 'rightscale_cli/server_templates'
         
     | 
| 
      
 29 
     | 
    
         
            +
            require 'rightscale_cli/volumes'
         
     | 
| 
       26 
30 
     | 
    
         | 
| 
       27 
31 
     | 
    
         
             
            # http://stackoverflow.com/questions/5663519/namespacing-thor-commands-in-a-standalone-ruby-executable
         
     | 
| 
       28 
32 
     | 
    
         | 
| 
         @@ -39,7 +43,10 @@ class RightScaleCLI 
     | 
|
| 
       39 
43 
     | 
    
         
             
                register(ServerArrays, 'arrays', 'arrays <command>', 'Manage server arrays.')
         
     | 
| 
       40 
44 
     | 
    
         
             
                register(Deployments, 'deployments', 'deployments <command>', 'Manage deployments.')
         
     | 
| 
       41 
45 
     | 
    
         
             
                register(Instances, 'instances', 'instances <command>', 'Manage instances.')
         
     | 
| 
      
 46 
     | 
    
         
            +
                register(MultiCloudImages, 'mcis', 'mcis <command>', 'Manage MultiCloud Images.')
         
     | 
| 
      
 47 
     | 
    
         
            +
                register(Repositories, 'repositories', 'repositories <command>', 'Manage (Chef) Repositories.')
         
     | 
| 
       42 
48 
     | 
    
         
             
                register(Servers, 'servers', 'servers <command>', 'Manage servers.')
         
     | 
| 
       43 
49 
     | 
    
         
             
                register(ServerTemplates, 'server_templates', 'server-templates <command>', 'Manage ServerTemplates.')
         
     | 
| 
      
 50 
     | 
    
         
            +
                register(Volumes, 'volumes', 'volumes <command>', 'Manage volumes.')
         
     | 
| 
       44 
51 
     | 
    
         
             
              end
         
     | 
| 
       45 
52 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,69 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Author:: Chris Fordham (<chris@fordham-nagy.id.au>)
         
     | 
| 
      
 2 
     | 
    
         
            +
            # Copyright:: Copyright (c) 2013 Chris Fordham
         
     | 
| 
      
 3 
     | 
    
         
            +
            # License:: Apache License, Version 2.0
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
      
 6 
     | 
    
         
            +
            # you may not use this file except in compliance with the License.
         
     | 
| 
      
 7 
     | 
    
         
            +
            # You may obtain a copy of the License at
         
     | 
| 
      
 8 
     | 
    
         
            +
            #
         
     | 
| 
      
 9 
     | 
    
         
            +
            #     http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
      
 10 
     | 
    
         
            +
            #
         
     | 
| 
      
 11 
     | 
    
         
            +
            # Unless required by applicable law or agreed to in writing, software
         
     | 
| 
      
 12 
     | 
    
         
            +
            # distributed under the License is distributed on an "AS IS" BASIS,
         
     | 
| 
      
 13 
     | 
    
         
            +
            # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         
     | 
| 
      
 14 
     | 
    
         
            +
            # See the License for the specific language governing permissions and
         
     | 
| 
      
 15 
     | 
    
         
            +
            # limitations under the License.
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            require 'thor'
         
     | 
| 
      
 18 
     | 
    
         
            +
            require 'yaml'
         
     | 
| 
      
 19 
     | 
    
         
            +
            require 'json'
         
     | 
| 
      
 20 
     | 
    
         
            +
            require "active_support/core_ext"
         
     | 
| 
      
 21 
     | 
    
         
            +
            require 'rightscale_cli/logger'
         
     | 
| 
      
 22 
     | 
    
         
            +
            require 'rightscale_cli/client'
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            class RightScaleCLI
         
     | 
| 
      
 25 
     | 
    
         
            +
              class Volumes < Thor
         
     | 
| 
      
 26 
     | 
    
         
            +
                namespace :volumes
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                # include render options
         
     | 
| 
      
 29 
     | 
    
         
            +
                eval(IO.read("#{File.dirname(File.expand_path(__FILE__))}/render_options.rb"), binding)
         
     | 
| 
      
 30 
     | 
    
         
            +
                
         
     | 
| 
      
 31 
     | 
    
         
            +
                desc "list", "Lists volumes, optionally with filter by datacenter, description, name, parent volume snapshot or resource UID."
         
     | 
| 
      
 32 
     | 
    
         
            +
                option :cloud, :desc => "The cloud to query for volumes in.", :type => :string, :required => true
         
     | 
| 
      
 33 
     | 
    
         
            +
                option :datacenter, :desc => "The href of the Datacenter / Zone the Volume is in.", :type => :string, :required => false
         
     | 
| 
      
 34 
     | 
    
         
            +
                option :description, :desc => "The description of the Volume to filter on.", :type => :string, :required => false
         
     | 
| 
      
 35 
     | 
    
         
            +
                option :name, :desc => "The name of the Volume to filter on.", :type => :string, :required => false
         
     | 
| 
      
 36 
     | 
    
         
            +
                option :parent, :desc => "The href of the snapshot from which the volume was created.", :type => :string, :required => false
         
     | 
| 
      
 37 
     | 
    
         
            +
                option :resource_uid, :desc => "Resource Unique IDentifier for the Volume to filter on.", :type => :string, :required => false
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                def list()
         
     | 
| 
      
 40 
     | 
    
         
            +
                  volumes = []      
         
     | 
| 
      
 41 
     | 
    
         
            +
                  filter = []
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                  filter.push("datacenter_href==/api/clouds/#{options[:cloud]}/datacenters/#{options[:datacenter]}") if options[:datacenter]
         
     | 
| 
      
 44 
     | 
    
         
            +
                  filter.push("description==#{options[:description]}") if options[:description]
         
     | 
| 
      
 45 
     | 
    
         
            +
                  filter.push("name==#{options[:name]}") if options[:name]
         
     | 
| 
      
 46 
     | 
    
         
            +
                  filter.push("parent_volume_snapshot_href==#{options[:parent]}") if options[:parent]
         
     | 
| 
      
 47 
     | 
    
         
            +
                  filter.push("resource_uid==#{options[:resource_uid]}") if options[:resource_uid]
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                  $log.debug "filter: #{filter}" if options[:debug]
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                  RightApi::Client.new(RightScaleCLI::Config::API).clouds(:id => options[:cloud]).show.volumes(:filter => filter).index.each { |volume|
         
     | 
| 
      
 52 
     | 
    
         
            +
                    volumes.push(volume.raw)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  }
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                  RightScaleCLI::Output.render(volumes, 'volumes', options)
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                desc "show", "Shows a volume."
         
     | 
| 
      
 59 
     | 
    
         
            +
                option :cloud, :desc => "The cloud to query for volumes in.", :type => :string, :required => true
         
     | 
| 
      
 60 
     | 
    
         
            +
                def show(volume_id)
         
     | 
| 
      
 61 
     | 
    
         
            +
                  volume = RightApi::Client.new(RightScaleCLI::Config::API).clouds(:id => options[:cloud]).show.volumes(:id => volume_id).show.raw
         
     | 
| 
      
 62 
     | 
    
         
            +
                  RightScaleCLI::Output.render(volume, 'volume', options)
         
     | 
| 
      
 63 
     | 
    
         
            +
                end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                def self.banner(task, namespace = true, subcommand = false)
         
     | 
| 
      
 66 
     | 
    
         
            +
                  "#{basename} #{task.formatted_usage(self, true, subcommand)}"
         
     | 
| 
      
 67 
     | 
    
         
            +
                end
         
     | 
| 
      
 68 
     | 
    
         
            +
              end
         
     | 
| 
      
 69 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/yesno.rb
    ADDED
    
    | 
         @@ -0,0 +1,31 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Author:: Chris Fordham (<chris@fordham-nagy.id.au>)
         
     | 
| 
      
 2 
     | 
    
         
            +
            # Copyright:: Copyright (c) 2013 Chris Fordham
         
     | 
| 
      
 3 
     | 
    
         
            +
            # License:: Apache License, Version 2.0
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
      
 6 
     | 
    
         
            +
            # you may not use this file except in compliance with the License.
         
     | 
| 
      
 7 
     | 
    
         
            +
            # You may obtain a copy of the License at
         
     | 
| 
      
 8 
     | 
    
         
            +
            #
         
     | 
| 
      
 9 
     | 
    
         
            +
            #     http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
      
 10 
     | 
    
         
            +
            #
         
     | 
| 
      
 11 
     | 
    
         
            +
            # Unless required by applicable law or agreed to in writing, software
         
     | 
| 
      
 12 
     | 
    
         
            +
            # distributed under the License is distributed on an "AS IS" BASIS,
         
     | 
| 
      
 13 
     | 
    
         
            +
            # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         
     | 
| 
      
 14 
     | 
    
         
            +
            # See the License for the specific language governing permissions and
         
     | 
| 
      
 15 
     | 
    
         
            +
            # limitations under the License.
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            def yesno
         
     | 
| 
      
 18 
     | 
    
         
            +
              begin
         
     | 
| 
      
 19 
     | 
    
         
            +
                system("stty raw -echo")
         
     | 
| 
      
 20 
     | 
    
         
            +
                str = STDIN.getc
         
     | 
| 
      
 21 
     | 
    
         
            +
              ensure
         
     | 
| 
      
 22 
     | 
    
         
            +
                system("stty -raw echo")
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
              if str.downcase == "y"
         
     | 
| 
      
 25 
     | 
    
         
            +
                return true
         
     | 
| 
      
 26 
     | 
    
         
            +
              elsif str.downcase == "n"
         
     | 
| 
      
 27 
     | 
    
         
            +
                return false
         
     | 
| 
      
 28 
     | 
    
         
            +
              else
         
     | 
| 
      
 29 
     | 
    
         
            +
                raise "Invalid response. Please enter y/n."
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: rightscale-cli
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.4.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Chris Fordham
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-01-22 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: activesupport
         
     | 
| 
         @@ -105,6 +105,8 @@ files: 
     | 
|
| 
       105 
105 
     | 
    
         
             
            - lib/rightscale_cli.rb
         
     | 
| 
       106 
106 
     | 
    
         
             
            - lib/rightscale_cli/servers.rb
         
     | 
| 
       107 
107 
     | 
    
         
             
            - lib/rightscale_cli/rightscale_cli.rb
         
     | 
| 
      
 108 
     | 
    
         
            +
            - lib/rightscale_cli/repositories.rb
         
     | 
| 
      
 109 
     | 
    
         
            +
            - lib/rightscale_cli/base.rb
         
     | 
| 
       108 
110 
     | 
    
         
             
            - lib/rightscale_cli/monkey_patches/client_attributes.rb
         
     | 
| 
       109 
111 
     | 
    
         
             
            - lib/rightscale_cli/output.rb
         
     | 
| 
       110 
112 
     | 
    
         
             
            - lib/rightscale_cli/instances.rb
         
     | 
| 
         @@ -116,7 +118,9 @@ files: 
     | 
|
| 
       116 
118 
     | 
    
         
             
            - lib/rightscale_cli/config.rb
         
     | 
| 
       117 
119 
     | 
    
         
             
            - lib/rightscale_cli/dashboard.rb
         
     | 
| 
       118 
120 
     | 
    
         
             
            - lib/rightscale_cli/server_arrays.rb
         
     | 
| 
      
 121 
     | 
    
         
            +
            - lib/rightscale_cli/multi_cloud_images.rb
         
     | 
| 
       119 
122 
     | 
    
         
             
            - lib/rightscale_cli/render_options.rb
         
     | 
| 
      
 123 
     | 
    
         
            +
            - lib/rightscale_cli/volumes.rb
         
     | 
| 
       120 
124 
     | 
    
         
             
            - lib/rightscale_cli/server_arrays/current_instances.rb
         
     | 
| 
       121 
125 
     | 
    
         
             
            - lib/rightscale_cli/server_arrays/links.rb
         
     | 
| 
       122 
126 
     | 
    
         
             
            - lib/rightscale_cli/server_arrays/elasticity_params.rb
         
     | 
| 
         @@ -124,6 +128,7 @@ files: 
     | 
|
| 
       124 
128 
     | 
    
         
             
            - lib/rightscale_cli/server_arrays/alerts.rb
         
     | 
| 
       125 
129 
     | 
    
         
             
            - lib/rightscale_cli/server_arrays/multi_run_executable.rb
         
     | 
| 
       126 
130 
     | 
    
         
             
            - lib/rightscale_cli/logger.rb
         
     | 
| 
      
 131 
     | 
    
         
            +
            - lib/yesno.rb
         
     | 
| 
       127 
132 
     | 
    
         
             
            - README.md
         
     | 
| 
       128 
133 
     | 
    
         
             
            - LICENSE
         
     | 
| 
       129 
134 
     | 
    
         
             
            homepage: https://github.com/flaccid/rightscale-cli
         
     |