Class: ZoneAdd
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?, #flow_passes_parse, #flow_passes_preconditions, #get_args_used, #init, #initialize, #option_help_string, #run, #show_help, #show_help_option
Constructor Details
This class inherits a constructor from Command
Instance Method Details
#add_at_level(struct, level, arghash) ⇒ Object
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
|
# File 'lib/zone_add.rb', line 48
def add_at_level(struct, level, arghash)
if add_record_cond.nil?
element = { "Name" => arghash["name"], "Rdata" => arghash["rdata"], "TTL" => arghash["ttl"].to_i }
elsif add_group_cond.nil?
element = { "Group" => { "A" => [ ], "AAAA" => [ ], "CNAME" => [ ] }, "GroupTypeId" => 3, "Name" => arghash["gname"], "TTL" => arghash["ttl"] }
elsif add_group_record_cond.nil?
puts "level = #{level}"
key =
if arghash["weight"]
"LoadBalancingGroups"
elsif arghash["is-primary"]
"FailoverGroups"
end
groups = @zone_struct[key]
re = /(LoadBalancingGroups|FailoverGroups)\[([^\]]+)\]/
index = re.match(level)[2].to_i
index -= 1
element = {
"HealthCheck" => nil,
}
if arghash["weight"]
element["Weight"] = arghash["weight"].to_i
elsif arghash["is-primary"]
element["IsPrimary"] = (arghash["is-primary"] == "true")
end
element["Rdata"] = arghash["rdata"]
else
raise "should not happen"
end
struct << element
end
|
#add_group_cond ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/zone_add.rb', line 39
def add_group_cond
level = @input["level"]
if (level == 'zone.LoadBalancingGroups' || level == 'zone.FailoverGroups')
nil
else
"invalid drill down level (#{level}) for adding load balancing group or failover group"
end
end
|
#add_group_record_cond(group_type = '') ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/zone_add.rb', line 19
def add_group_record_cond(group_type='')
level = @input["level"]
levels = level.split('.')
if (levels.length == 4 && levels[1].start_with?(group_type) && levels[2] == 'Group')
nil
else
"invalid drill down level (#{level}) for adding record to a group"
end
end
|
#add_record_cond ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/zone_add.rb', line 29
def add_record_cond
level = @input["level"]
levels = level.split('.')
if (levels[1] == 'Records' && levels.length == 3)
nil
else
"invalid drill down level (#{level}) for adding record"
end
end
|
#create_args ⇒ Object
2
3
4
5
6
7
8
9
10
|
# File 'lib/zone_add.rb', line 2
def create_args
add_arg('name', 'Name of the node to which this record pertains', /[[:alnum:]@]+/)
add_arg('gname', 'Name of load balancing or failover group', /[[:alnum:]]+/)
add_arg('rdata', 'Additional resource record data, such as IP Address', /.*/)
add_arg('ttl', 'Time to live, in seconds', /\d+/)
add_arg('weight', 'Load balancing weight assigned to the record', /\d+/)
add_arg('is-primary', 'Indicates whether record is the primary server/domain to which traffic will be directed.', ["true", "false"])
end
|
#create_flows ⇒ Object
12
13
14
15
16
17
|
# File 'lib/zone_add.rb', line 12
def create_flows
add_flow_from_usage("<gname> [<ttl>='300']", :add_group_cond)
add_flow_from_usage("<name> <rdata> <ttl>", :add_record_cond)
add_flow_from_usage("<weight> <rdata>", :add_group_record_cond, 'LoadBalancing')
add_flow_from_usage("<is-primary> <rdata>", :add_group_record_cond, 'Failover')
end
|
#execute(arghash, rest) ⇒ Object
80
81
82
83
84
85
86
87
88
|
# File 'lib/zone_add.rb', line 80
def execute(arghash, rest)
struct = @input["struct"]
level = @input["level"]
zone = @input["zone"]
@zone_struct = @input["toplevel"]
add_at_level(struct, level, arghash)
zone.write_zone_file(@zone_struct, false)
StructurePrint.new("-").structure_print(struct, level)
end
|