Sha256: 201e70136134748d9f15f2a5de87414eed9619198c12366b52524fa0cd3e2b94

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 KB

Contents

require_relative 'ionoscloud_base'

class Chef
  class Knife
    class IonoscloudNicList < Knife
      include Knife::IonoscloudBase

      banner 'knife ionoscloud nic list (options)'

      option :datacenter_id,
              short: '-D DATACENTER_ID',
              long: '--datacenter-id DATACENTER_ID',
              description: 'The ID of the datacenter containing the NIC'

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

      def initialize(args = [])
        super(args)
        @description =
        'List all available NICs connected to a server.'
        @directory = 'compute-engine'
        @required_options = [:datacenter_id, :server_id, :ionoscloud_username, :ionoscloud_password]
      end

      def run
        $stdout.sync = true
        handle_extra_config
        validate_required_params(@required_options, config)

        nic_list = [
          ui.color('ID', :bold),
          ui.color('Name', :bold),
          ui.color('IPs', :bold),
          ui.color('DHCP', :bold),
          ui.color('LAN', :bold),
          ui.color('Firewall Type', :bold),
          ui.color('Device Number', :bold),
          ui.color('PCI Slot', :bold),
        ]

        nic_api = Ionoscloud::NetworkInterfacesApi.new(api_client)

        nic_api.datacenters_servers_nics_get(config[:datacenter_id], config[:server_id], { depth: 1 }).items.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
          nic_list << nic.properties.firewall_type.to_s
          nic_list << nic.properties.device_number.to_s
          nic_list << nic.properties.pci_slot.to_s
        end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
knife-ionoscloud-6.1.1 lib/chef/knife/ionoscloud_nic_list.rb
knife-ionoscloud-6.1.0 lib/chef/knife/ionoscloud_nic_list.rb