Sha256: 6f901f71e51e6bb153a121ec190015a1bf99d68652f19674e28ccbc49b7059c1

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

require 'chef/knife/profitbricks_base'

class Chef
  class Knife
    class ProfitbricksNicList < Knife
      include Knife::ProfitbricksBase

      banner 'knife profitbricks nic list (options)'

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

      option :server_id,
             short: '-S SERVER_ID',
             long: '--server-id SERVER_ID',
             description: 'The ID of the server assigned the NIC',
             required: true

      def run
        $stdout.sync = true
        nic_list = [
          ui.color('ID', :bold),
          ui.color('Name', :bold),
          ui.color('IPs', :bold),
          ui.color('DHCP', :bold),
          ui.color('LAN', :bold)
        ]
        connection

        ProfitBricks::NIC.list(config[:datacenter_id], config[:server_id]).each do |nic|
          nic_list << nic.id
          nic_list << nic.properties['name']
          nic_list << nic.properties['ips'].to_s
          nic_list << nic.properties['dhcp'].to_s
          nic_list << nic.properties['lan'].to_s
        end

        puts ui.list(nic_list, :uneven_columns_across, 5)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
knife-profitbricks-1.1.2 lib/chef/knife/profitbricks_nic_list.rb