Class: Chef::Knife::CiscoAsaHostRemove

Inherits:
Chef::Knife show all
Includes:
CiscoAsaBase
Defined in:
lib/chef/knife/cisco_asa_host_remove.rb

Instance Method Summary collapse

Methods included from CiscoAsaBase

#get_cisco_asa_config, #get_config, included, #run_config_commands, #tcp_test_port

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/chef/knife/cisco_asa_host_remove.rb', line 25

def run
  $stdout.sync = true
  
  hostname = name_args.first.upcase

  if hostname.nil?
    ui.fatal "You need a host name!"
    show_usage
    exit 1
  end

  args = name_args[1]
  if args.nil?
    args = ""
  end

  get_cisco_asa_config
  commands = []

  ui.info "Removing host from Cisco ASA:"
  ui.info "#{ui.color "ASA:", :cyan} #{get_config(:cisco_asa_hostname)}"
  ui.info "#{ui.color "Host:", :cyan} #{hostname}"

  if get_config(:nat)
    ui.info "#{ui.color "NAT IP:", :cyan} #{get_config(:nat)}"
    commands << "object network #{hostname}"
    commands << "  no nat (inside,outside) static #{get_config(:nat)} dns"
  end

  if get_config(:groups)
    get_config(:groups).split(",").each do |group|
      ui.info "#{ui.color "Group:", :cyan} #{group}"
      commands << "object-group network #{group}"
      commands << "  no network-object object #{hostname}"
    end
  end

  commands << "no object network #{hostname}"

  if get_config(:noop)
    ui.info "#{ui.color "Skipping host removal process because --noop specified.", :red}"
  else
    run_config_commands(commands)
  end
  
end