Class: CiscoAsaKnifePlugin::CiscoAsaHostAdd

Inherits:
BaseCiscoAsaCommand show all
Defined in:
lib/chef/knife/cisco_asa_host_add.rb

Instance Method Summary collapse

Methods inherited from BaseCiscoAsaCommand

#get_cisco_asa_config, get_common_options, #get_config, #run_config_commands, #tcp_test_port

Instance Method Details

#runObject



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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/chef/knife/cisco_asa_host_add.rb', line 34

def run
  
  hostname = name_args.first

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

  ip = name_args[1]

  if ip.nil?
    ui.fatal "You need an IP!"
    show_usage
    exit 1
  end

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

  get_cisco_asa_config
  commands = []

  ui.info "Adding host to Cisco ASA:"
  ui.info "#{ui.color "ASA:", :cyan} #{get_config(:cisco_asa_host)}"
  ui.info "#{ui.color "Host:", :cyan} #{hostname}"
  ui.info "#{ui.color "IP:", :cyan} #{ip}"

  commands << "object network #{hostname}"
  commands << "  host #{ip}"

  if get_config(:description)
    ui.info "#{ui.color "Description:", :cyan} #{get_config(:description)}"
    commands << "  description #{get_config(:description)}"
  end

  if get_config(:nat)
    ui.info "#{ui.color "NAT IP:", :cyan} #{get_config(:nat)}"
    command = "  nat static #{get_config(:nat)}"
    if get_config(:nat_dns)
      ui.info "#{ui.color "NAT DNS:", :cyan} Enabled"
      command = command + " dns"
    end
    commands << command
  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 << "  network-object object #{hostname}"
    end
  end

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