Sha256: 70dedb083a35175b8dec8ce43d71af83c4d88a5a7a7188055f74e23f6eef39ef

Contents?: true

Size: 836 Bytes

Versions: 4

Compression:

Stored size: 836 Bytes

Contents

module CloudstackCli  
  class Base < Thor
    include Thor::Actions
    attr_reader :config

    # catch control-c and exit
    trap("SIGINT") {
      puts " bye"
      exit!
    }

    no_commands do  
      def client
        @config ||= CloudstackClient::ConnectionHelper.load_configuration(options[:config])
        @client ||= CloudstackClient::Connection.new(
          @config[:url],
          @config[:api_key],
          @config[:secret_key]
        )
      end

      def find_project(project_name = options[:project])
        unless project = client.get_project(project_name)
          say "Project '#{options[:project]}' not found", :red
          exit 1
        end
        project
      end

      def filter_by(objects, tag_name, tag)
        objects.select {|r| r[tag_name].downcase == tag }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cloudstack-cli-0.1.4 lib/cloudstack-cli/base.rb
cloudstack-cli-0.1.3 lib/cloudstack-cli/base.rb
cloudstack-cli-0.1.2 lib/cloudstack-cli/base.rb
cloudstack-cli-0.1.1 lib/cloudstack-cli/base.rb