3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
|
# File 'lib/vtysh/diff.rb', line 3
def self.commands(source, target)
source_cmds = parse_config(source)
target_cmds = parse_config(target)
commands = []
if needs_bgp_recreation?(source_cmds, target_cmds)
commands.concat(handle_bgp_recreation(source_cmds, target_cmds))
else
(source_cmds - target_cmds).each do |cmd|
if is_block_command(cmd[:command])
commands << format_removal_command(cmd)
if cmd[:command].start_with?("router bgp")
asn = cmd[:command].split[2]
end
elsif cmd[:depth] > 0
block_being_removed = false
cmd[:context].each do |ctx|
if source_cmds.any? { |s| s[:command] == ctx && (source_cmds - target_cmds).include?(s) }
block_being_removed = true
break
end
end
unless block_being_removed
commands << format_context_command("no #{cmd[:command]}", cmd[:context])
end
else
commands << "vtysh -c \"configure\" -c \"no #{cmd[:command]}\""
end
end
(target_cmds - source_cmds).each do |cmd|
if is_block_command(cmd[:command])
commands << "vtysh -c \"configure\" -c \"#{cmd[:command]}\""
elsif cmd[:depth] > 0
commands << format_context_command(cmd[:command], cmd[:context])
else
commands << "vtysh -c \"configure\" -c \"#{cmd[:command]}\""
end
end
end
reorder_commands(commands.uniq)
end
|