Class: ZoneAdd

Inherits:
Command show all
Defined in:
lib/zone_add.rb

Instance Attribute Summary

Attributes inherited from Command

#desc, #name

Instance Method Summary collapse

Methods inherited from Command

#add_arg, #add_cmd, #add_flow, #add_flow_from_usage, #add_input, #add_option, #add_options, #command_name?, #get_args_used, #init, #initialize, #run, #show_help, #show_help_option

Constructor Details

This class inherits a constructor from Command

Instance Method Details

#create_args ⇒ Object



2
3
4
5
6
7
# File 'lib/zone_add.rb', line 2

def create_args
  # for level zone.Records.?
  add_arg('name', 'Name of the node to which this record pertains', /[[:alnum:]]+/)
  add_arg('rdata', 'Additional resource record data, such as IP Address', /.*/)
  add_arg('ttl', 'Time to live, in seconds', /\d+/)
end

#create_flows ⇒ Object



9
10
11
# File 'lib/zone_add.rb', line 9

def create_flows
  add_flow_from_usage("<name> <rdata> <ttl>")
end

#execute(arghash, rest) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/zone_add.rb', line 25

def execute(arghash, rest)
  struct = @input["struct"]
  level = @input["level"]
  @zone_struct = @input["toplevel"]
  zone = @input["zone"]

  @record = { "Name" => arghash["name"], "Rdata" => arghash["rdata"], "TTL" => arghash["ttl"].to_i }
  handle_level(level)
  zone.write_zone_file(@zone_struct)
  
end

#handle_level(level) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/zone_add.rb', line 13

def handle_level(level)
  levels = level.split('.')
  if levels.length == 3 && levels[1] == 'Records'
    rtype = levels[2]
    struct = @input["struct"] 
    struct << @record
    StructurePrint.new("-").structure_print(struct, level)
  else
    raise "Illegal or unimplemented add location"
  end
end