Sha256: dffc2d6ef4120371b1f8182e5f1b58e3d0366a297cd964660efde16c4fd72acd

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

require 'chef/knife/profitbricks_base'

class Chef
  class Knife
    class ProfitbricksNicDelete < Knife
      include Knife::ProfitbricksBase

      banner 'knife profitbricks nic delete NIC_ID [NIC_ID] (options)'

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

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

      def run
        connection
        validate_required_params(%i(datacenter_id server_id), Chef::Config[:knife])

        @name_args.each do |nic_id|
          begin
            nic = ProfitBricks::NIC.get(Chef::Config[:knife][:datacenter_id], Chef::Config[:knife][:server_id], nic_id)
          rescue Excon::Errors::NotFound
            ui.error("NIC ID #{nic_id} not found. Skipping.")
            next
          end

          msg_pair('ID', nic.id)
          msg_pair('Name', nic.properties['name'])
          msg_pair('IPs', nic.properties['cores'])
          msg_pair('DHCP', nic.properties['ram'])
          msg_pair('LAN', nic.properties['availabilityZone'])

          confirm('Do you really want to delete this NIC')

          nic.delete
          ui.warn("Deleted nic #{nic.id}")
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
knife-profitbricks-2.0.1 lib/chef/knife/profitbricks_nic_delete.rb