Class: Chef::Knife::ProfitbricksFirewallDelete

Inherits:
Chef::Knife
  • Object
show all
Includes:
ProfitbricksBase
Defined in:
lib/chef/knife/profitbricks_firewall_delete.rb

Instance Method Summary collapse

Methods included from ProfitbricksBase

#connection, #error_and_exit, #get_image, included, #msg_pair, #validate_required_params

Instance Method Details

#runObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/chef/knife/profitbricks_firewall_delete.rb', line 25

def run
  validate_required_params(i(datacenter_id server_id nic_id), Chef::Config[:knife])
  connection
  @name_args.each do |firewall_id|
    begin
      firewall = ProfitBricks::Firewall.get(Chef::Config[:knife][:datacenter_id],
                                            Chef::Config[:knife][:server_id],
                                            Chef::Config[:knife][:nic_id],
                                            firewall_id)
    rescue Excon::Errors::NotFound
      ui.error("Firewall ID #{firewall_id} not found. Skipping.")
      next
    end

    msg_pair('ID', firewall.id)
    msg_pair('Name', firewall.properties['name'])
    msg_pair('Protocol', firewall.properties['protocol'])
    msg_pair('Source MAC', firewall.properties['sourceMac'])
    msg_pair('Source IP', firewall.properties['sourceIp'])
    msg_pair('Target IP', firewall.properties['targetIp'])
    msg_pair('Port Range Start', firewall.properties['portRangeStart'])
    msg_pair('Port Range End', firewall.properties['portRangeEnd'])
    msg_pair('ICMP Type', firewall.properties['icmpType'])
    msg_pair('ICMP Code', firewall.properties['icmpCode'])

    confirm('Do you really want to delete this firewall rule')

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