Sha256: 9057e040f8ec64d1ac170e5eae18a1b9331b2bff83a91e38d3cbaaedbd53d454

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

require 'chef/knife/profitbricks_base'

class Chef
  class Knife
    class ProfitbricksServerList < Knife
      include Knife::ProfitbricksBase

      banner 'knife profitbricks server list (options)'

      option :datacenter_id,
             short: '-D DATACENTER_ID',
             long: '--datacenter-id DATACENTER_ID',
             description: 'The ID of the datacenter containing the server',
             proc: proc { |datacenter_id| Chef::Config[:knife][:datacenter_id] = datacenter_id },
             required: true 

      def run
        $stdout.sync = true
        server_list = [
          ui.color('ID', :bold),
          ui.color('Name', :bold),
          ui.color('Cores', :bold),
          ui.color('RAM', :bold),
          ui.color('Availability Zone', :bold),
          ui.color('VM State', :bold),
          ui.color('Boot Volume', :bold),
          ui.color('Boot CDROM', :bold)
        ]
        connection

        ProfitBricks::Server.list(config[:datacenter_id]).each do |server|
          server_list << server.id
          server_list << server.properties['name']
          server_list << server.properties['cores'].to_s
          server_list << server.properties['ram'].to_s
          server_list << server.properties['availabilityZone']
          server_list << server.properties['vmState']
          server_list << (server.properties['bootVolume'] == nil ? '' : server.properties['bootVolume']['id'])
          server_list << (server.properties['bootCdrom'] == nil ? '' : server.properties['bootCdrom']['id'])
        end

        puts ui.list(server_list, :uneven_columns_across, 8)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
knife-profitbricks-1.2.0 lib/chef/knife/profitbricks_server_list.rb
knife-profitbricks-1.1.2 lib/chef/knife/profitbricks_server_list.rb