junos-ez-stdlib 0.1.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +18 -0
- data/CHANGELOG.md +60 -19
- data/Gemfile +7 -0
- data/README.md +41 -30
- data/Rakefile +6 -0
- data/SUGGESTION-BOX/README.md +32 -0
- data/docs/Providers/Group.md +61 -0
- data/docs/Providers/L2ports.md +1 -1
- data/docs/Providers/LAGports.md +57 -0
- data/docs/Providers/Vlans.md +1 -1
- data/examples/config/config_file.rb +0 -0
- data/examples/config/config_template_object.rb +0 -0
- data/examples/config/config_template_simple.rb +0 -0
- data/examples/config/load_sample.conf +129 -0
- data/examples/config/load_sample.set +3 -0
- data/examples/config/load_template_main.conf +7 -0
- data/examples/config/load_template_object.conf +7 -0
- data/examples/config/multi_config.rb +0 -0
- data/examples/fs_utils.rb +0 -0
- data/examples/lag_port.rb +27 -0
- data/examples/re_upgrade.rb +0 -0
- data/examples/re_utils.rb +0 -0
- data/examples/simple.rb +0 -1
- data/examples/st_hosts.rb +0 -0
- data/examples/user.rb +0 -0
- data/examples/vlans.rb +4 -4
- data/junos-ez-stdlib.gemspec +25 -14
- data/lib/junos-ez/exceptions.rb +0 -0
- data/lib/junos-ez/facts.rb +5 -7
- data/lib/junos-ez/facts/chassis.rb +6 -0
- data/lib/junos-ez/facts/ifd_style.rb +6 -3
- data/lib/junos-ez/facts/personality.rb +6 -6
- data/lib/junos-ez/facts/switch_style.rb +11 -2
- data/lib/junos-ez/facts/version.rb +24 -9
- data/lib/junos-ez/group.rb +206 -0
- data/lib/junos-ez/ip_ports.rb +0 -0
- data/lib/junos-ez/ip_ports/classic.rb +2 -2
- data/lib/junos-ez/l1_ports.rb +0 -0
- data/lib/junos-ez/l1_ports/classic.rb +0 -0
- data/lib/junos-ez/l1_ports/switch.rb +0 -0
- data/lib/junos-ez/l2_ports.rb +18 -9
- data/lib/junos-ez/l2_ports/bridge_domain.rb +499 -0
- data/lib/junos-ez/l2_ports/vlan.rb +3 -3
- data/lib/junos-ez/l2_ports/vlan_l2ng.rb +502 -0
- data/lib/junos-ez/lag_ports.rb +268 -0
- data/lib/junos-ez/provider.rb +4 -8
- data/lib/junos-ez/stdlib.rb +2 -0
- data/lib/junos-ez/system.rb +0 -0
- data/lib/junos-ez/system/users.rb +5 -7
- data/lib/junos-ez/utils/config.rb +0 -0
- data/lib/junos-ez/utils/fs.rb +0 -0
- data/lib/junos-ez/utils/re.rb +0 -0
- data/lib/junos-ez/version.rb +4 -1
- data/lib/junos-ez/vlans.rb +4 -1
- data/lib/junos-ez/vlans/bridge_domain.rb +7 -3
- data/lib/junos-ez/vlans/vlan.rb +4 -3
- data/lib/junos-ez/vlans/vlan_l2ng.rb +126 -0
- metadata +142 -64
data/docs/Providers/L2ports.md
CHANGED
@@ -23,7 +23,7 @@ puts "port #{port.name} is not a switch-port!" unless port.exists?
|
|
23
23
|
|
24
24
|
- `:description` - String description at the logical interface level
|
25
25
|
- `:untagged_vlan` - String, VLAN-name for packets without VLAN tags
|
26
|
-
- `:tagged_vlans` -
|
26
|
+
- `:tagged_vlans` - Set of VLAN-names for packets with VLAN tags
|
27
27
|
- `:vlan_tagging` - [true | false] - indicates if this port accepts packets with VLAN tags
|
28
28
|
|
29
29
|
# METHODS
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Junos::Ez::LAGports::Provider
|
2
|
+
|
3
|
+
Manages Link Aggregation Group (LAG) port properties
|
4
|
+
|
5
|
+
# EXAMPLE
|
6
|
+
|
7
|
+
The provider *name* selector is the interface name, e.g. "ae0".
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
Junos::Ez::LAGports::Provider( ndev, :lags )
|
11
|
+
|
12
|
+
port = ndev.lags["ae0"]
|
13
|
+
|
14
|
+
port[:links] = ["ge-0/0/0", "ge-0/0/1", "ge-0/0/2", "ge-0/0/3"]
|
15
|
+
port[:lacp] = :active
|
16
|
+
port[:minimum_links] = 2
|
17
|
+
|
18
|
+
port.write!
|
19
|
+
```
|
20
|
+
|
21
|
+
# PROPERTIES
|
22
|
+
|
23
|
+
- `:links` - Set of interface names
|
24
|
+
- `:lacp` - [:active, :passive, :disabled], :disabled is default
|
25
|
+
- `:minimum_links` - number of interfaces that must be active for LAG to be declared 'up'
|
26
|
+
|
27
|
+
# METHODS
|
28
|
+
|
29
|
+
No additional methods at this time ...
|
30
|
+
|
31
|
+
# USAGE NOTES
|
32
|
+
|
33
|
+
### Allocating Aggregated Ethernet (AE) Ports in Junos
|
34
|
+
|
35
|
+
Before using LAG ports, you must first configured the "aggregated ethernet ports" device count in Junos. This is done under the `[edit chassis]` stanza as shown:
|
36
|
+
|
37
|
+
````
|
38
|
+
{master:0}[edit chassis]
|
39
|
+
jeremy@switch# show
|
40
|
+
aggregated-devices {
|
41
|
+
ethernet {
|
42
|
+
device-count 10;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
````
|
46
|
+
|
47
|
+
### Changing the Links Property
|
48
|
+
|
49
|
+
The `:links` property is internally managed as a Ruby Set. When modifing the `:links` property you must use an Array notation, even if you are simply adding or removing one link. For example:
|
50
|
+
|
51
|
+
````ruby
|
52
|
+
port = ndev.lags["ae0"]
|
53
|
+
|
54
|
+
port[:links] += ["ge-0/0/15"]
|
55
|
+
port.write!
|
56
|
+
````
|
57
|
+
|
data/docs/Providers/Vlans.md
CHANGED
@@ -20,7 +20,7 @@ puts "VLAN: #{vlan.name} does not exists!" unless vlan.exists?
|
|
20
20
|
|
21
21
|
- `:vlan_id` - The VLAN tag-id, Fixnum [ 1 .. 4094]
|
22
22
|
- `:description` - String description for this VLAN
|
23
|
-
- `:no_mac_learning` - If `
|
23
|
+
- `:no_mac_learning` - [`:enable`, `:disable`]. If `:enable` this VLAN will not learn MAC addresses
|
24
24
|
|
25
25
|
# RESOURCE METHODS
|
26
26
|
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# sample contributed by "Maarten at the Amsterdam University of Applied Sciences", @289Sec
|
2
|
+
# slight mods by @nwkautomaniac
|
3
|
+
|
4
|
+
# Prefix-lists:
|
5
|
+
policy-options {
|
6
|
+
prefix-list dns-servers-ipv4 {
|
7
|
+
apply-path "system name-server <*.*>";
|
8
|
+
}
|
9
|
+
prefix-list ntp-servers-ipv4 {
|
10
|
+
apply-path "system ntp server <*.*>";
|
11
|
+
}
|
12
|
+
prefix-list snmp-client-systems-ipv4 {
|
13
|
+
apply-path "snmp client-list <*> <*.*>";
|
14
|
+
}
|
15
|
+
prefix-list tacacs-servers-ipv4 {
|
16
|
+
apply-path "system tacplus-server <*.*>";
|
17
|
+
}
|
18
|
+
prefix-list radius-servers-ipv4 {
|
19
|
+
apply-path "access radius-server <*.*>";
|
20
|
+
}
|
21
|
+
prefix-list management-networks-ipv4 {
|
22
|
+
172.20.0.0/16;
|
23
|
+
192.168.56.0/24;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
|
28
|
+
# Firewall filter:
|
29
|
+
firewall {
|
30
|
+
family inet {
|
31
|
+
filter re-protect-ipv4 {
|
32
|
+
term discard-fragments-icmp {
|
33
|
+
from {
|
34
|
+
is-fragment;
|
35
|
+
protocol icmp;
|
36
|
+
}
|
37
|
+
then discard;
|
38
|
+
}
|
39
|
+
term icmp-allow {
|
40
|
+
from {
|
41
|
+
protocol icmp;
|
42
|
+
icmp-type [ echo-request echo-reply unreachable time-exceeded source-quench ];
|
43
|
+
}
|
44
|
+
then accept;
|
45
|
+
}
|
46
|
+
term dns-allow {
|
47
|
+
from {
|
48
|
+
source-prefix-list {
|
49
|
+
dns-servers-ipv4;
|
50
|
+
}
|
51
|
+
protocol [ udp tcp ]
|
52
|
+
source-port domain;
|
53
|
+
}
|
54
|
+
then accept;
|
55
|
+
}
|
56
|
+
term ntp-allow {
|
57
|
+
from {
|
58
|
+
source-prefix-list {
|
59
|
+
ntp-servers-ipv4;
|
60
|
+
}
|
61
|
+
protocol udp;
|
62
|
+
source-port ntp;
|
63
|
+
}
|
64
|
+
then accept;
|
65
|
+
}
|
66
|
+
term snmp-allow {
|
67
|
+
from {
|
68
|
+
source-prefix-list {
|
69
|
+
snmp-client-systems-ipv4;
|
70
|
+
}
|
71
|
+
protocol udp;
|
72
|
+
destination-port snmp;
|
73
|
+
}
|
74
|
+
then accept;
|
75
|
+
}
|
76
|
+
term tacacs-allow {
|
77
|
+
from {
|
78
|
+
source-prefix-list {
|
79
|
+
tacacs-servers-ipv4;
|
80
|
+
}
|
81
|
+
protocol tcp;
|
82
|
+
source-port tacacs;
|
83
|
+
}
|
84
|
+
then accept;
|
85
|
+
}
|
86
|
+
term radius-allow {
|
87
|
+
from {
|
88
|
+
source-prefix-list {
|
89
|
+
radius-servers-ipv4;
|
90
|
+
}
|
91
|
+
protocol udp;
|
92
|
+
source-port radius;
|
93
|
+
}
|
94
|
+
then accept;
|
95
|
+
}
|
96
|
+
term ssh-allow {
|
97
|
+
from {
|
98
|
+
source-prefix-list {
|
99
|
+
management-networks-ipv4;
|
100
|
+
}
|
101
|
+
protocol tcp;
|
102
|
+
destination-port ssh;
|
103
|
+
}
|
104
|
+
then {
|
105
|
+
accept;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
term everything-else-discard {
|
109
|
+
then {
|
110
|
+
discard;
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
# Interface configuration:
|
119
|
+
interfaces {
|
120
|
+
fe-0/0/0 {
|
121
|
+
unit 0 {
|
122
|
+
family inet {
|
123
|
+
filter {
|
124
|
+
input re-protect-ipv4;
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}
|
File without changes
|
data/examples/fs_utils.rb
CHANGED
File without changes
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'net/netconf/jnpr'
|
2
|
+
require 'junos-ez/stdlib'
|
3
|
+
|
4
|
+
unless ARGV[0]
|
5
|
+
puts "You must specify a target"
|
6
|
+
exit 1
|
7
|
+
end
|
8
|
+
|
9
|
+
# login information for NETCONF session
|
10
|
+
login = { :target => ARGV[0], :username => 'jeremy', :password => 'jeremy1', }
|
11
|
+
|
12
|
+
## create a NETCONF object to manage the device and open the connection ...
|
13
|
+
|
14
|
+
ndev = Netconf::SSH.new( login )
|
15
|
+
$stdout.print "Connecting to device #{login[:target]} ... "
|
16
|
+
ndev.open
|
17
|
+
$stdout.puts "OK!"
|
18
|
+
|
19
|
+
Junos::Ez::Provider( ndev )
|
20
|
+
Junos::Ez::Config::Utils( ndev, :cu )
|
21
|
+
Junos::Ez::LAGports::Provider( ndev, :lags )
|
22
|
+
Junos::Ez::Vlans::Provider( ndev, :vlans )
|
23
|
+
Junos::Ez::L2ports::Provider( ndev, :l2_ports )
|
24
|
+
|
25
|
+
binding.pry
|
26
|
+
|
27
|
+
ndev.close
|
data/examples/re_upgrade.rb
CHANGED
File without changes
|
data/examples/re_utils.rb
CHANGED
File without changes
|
data/examples/simple.rb
CHANGED
data/examples/st_hosts.rb
CHANGED
File without changes
|
data/examples/user.rb
CHANGED
File without changes
|
data/examples/vlans.rb
CHANGED
@@ -19,12 +19,12 @@ $stdout.puts "OK!"
|
|
19
19
|
Junos::Ez::Provider( ndev )
|
20
20
|
Junos::Ez::Config::Utils( ndev, :cu )
|
21
21
|
Junos::Ez::Vlans::Provider( ndev, :vlans )
|
22
|
-
Junos::Ez::L1ports::Provider( ndev, :l1_ports )
|
22
|
+
#Junos::Ez::L1ports::Provider( ndev, :l1_ports )
|
23
23
|
Junos::Ez::L2ports::Provider( ndev, :l2_ports )
|
24
|
-
Junos::Ez::IPports::Provider( ndev, :ip_ports )
|
24
|
+
#Junos::Ez::IPports::Provider( ndev, :ip_ports )
|
25
25
|
|
26
|
-
pp ndev.vlans.list
|
27
|
-
pp ndev.vlans.catalog
|
26
|
+
#pp ndev.vlans.list
|
27
|
+
#pp ndev.vlans.catalog
|
28
28
|
|
29
29
|
binding.pry
|
30
30
|
|
data/junos-ez-stdlib.gemspec
CHANGED
@@ -1,15 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# coding: utf-8
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'junos-ez/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'junos-ez-stdlib'
|
9
|
+
spec.version = Junos::Ez::VERSION
|
10
|
+
spec.authors = ['Jeremy Schulman', 'John Deatherage', 'Nitin Kumar', 'Priyal Jain', 'Ganesh Nalawade']
|
11
|
+
spec.email = 'jnpr-community-netdev@juniper.net'
|
12
|
+
|
13
|
+
spec.summary = 'Junos EZ Framework - Standard Libraries'
|
14
|
+
spec.description = 'Automation Framework for Junos/NETCONF: Facts, Providers, and Utils'
|
15
|
+
spec.homepage = 'https://github.com/Juniper/ruby-junos-ez-stdlib'
|
16
|
+
spec.license = 'BSD-2-Clause'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
|
20
|
+
spec.add_dependency('netconf', '~> 0.3.1')
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
spec.add_development_dependency 'rubocop', '~> 0.42.0'
|
15
26
|
end
|
data/lib/junos-ez/exceptions.rb
CHANGED
File without changes
|
data/lib/junos-ez/facts.rb
CHANGED
@@ -75,11 +75,9 @@ end
|
|
75
75
|
### Load all of the fact files
|
76
76
|
### -----------------------------------------------------------------
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
78
|
+
require 'junos-ez/facts/chassis'
|
79
|
+
require 'junos-ez/facts/personality'
|
80
|
+
require 'junos-ez/facts/version'
|
81
|
+
require 'junos-ez/facts/switch_style'
|
82
|
+
require 'junos-ez/facts/ifd_style'
|
85
83
|
|
@@ -1,6 +1,12 @@
|
|
1
1
|
Junos::Ez::Facts::Keeper.define( :chassis ) do |ndev, facts|
|
2
2
|
|
3
3
|
inv_info = ndev.rpc.get_chassis_inventory
|
4
|
+
errs = inv_info.xpath('//output')[0]
|
5
|
+
|
6
|
+
if errs and errs.text.include? "This command can only be used on the master routing engine"
|
7
|
+
raise Junos::Ez::NoProviderError, "Chef can only be used on master routing engine !!"
|
8
|
+
end
|
9
|
+
|
4
10
|
chassis = inv_info.xpath('chassis')
|
5
11
|
|
6
12
|
facts[:hardwaremodel] = chassis.xpath('description').text
|
@@ -1,10 +1,13 @@
|
|
1
|
-
|
2
1
|
Junos::Ez::Facts::Keeper.define( :ifd_style ) do |ndev, facts|
|
3
|
-
persona = uses :personality
|
2
|
+
persona,sw_style = uses :personality,:switch_style
|
4
3
|
|
5
4
|
facts[:ifd_style] = case persona
|
6
5
|
when :SWITCH
|
7
|
-
:
|
6
|
+
if sw_style == :VLAN_L2NG
|
7
|
+
:CLASSIC
|
8
|
+
else
|
9
|
+
:SWITCH
|
10
|
+
end
|
8
11
|
else
|
9
12
|
:CLASSIC
|
10
13
|
end
|
@@ -3,22 +3,22 @@ Junos::Ez::Facts::Keeper.define( :personality ) do |ndev, facts|
|
|
3
3
|
uses :chassis, :routingengines
|
4
4
|
model = facts[:hardwaremodel]
|
5
5
|
|
6
|
-
examine = ( model != "Virtual Chassis" ) ? model : facts[
|
6
|
+
examine = ( model != "Virtual Chassis" ) ? model : facts.select {|k,v| k.match(/^RE[0..9]+/) }.values[0][:model]
|
7
7
|
|
8
8
|
facts[:personality] = case examine
|
9
|
-
when /^(EX)|(QFX)/
|
9
|
+
when /^(EX)|(QFX)|(OCX)/i
|
10
10
|
:SWITCH
|
11
|
-
when /^MX/
|
11
|
+
when /^MX/i
|
12
12
|
:MX
|
13
|
-
when /^vMX/
|
13
|
+
when /^vMX/i
|
14
14
|
facts[:virtual] = true
|
15
15
|
:MX
|
16
|
-
when /SRX(\d){3}/
|
16
|
+
when /SRX(\d){3}/i
|
17
17
|
:SRX_BRANCH
|
18
18
|
when /junosv-firefly/i
|
19
19
|
facts[:virtual] = true
|
20
20
|
:SRX_BRANCH
|
21
|
-
when /SRX(\d){4}/
|
21
|
+
when /SRX(\d){4}/i
|
22
22
|
:SRX_HIGHEND
|
23
23
|
end
|
24
24
|
|
@@ -1,13 +1,22 @@
|
|
1
1
|
Junos::Ez::Facts::Keeper.define( :switch_style ) do |ndev, facts|
|
2
2
|
f_persona = uses :personality
|
3
|
+
|
4
|
+
model = facts[:hardwaremodel]
|
5
|
+
examine = ( model != "Virtual Chassis" ) ? model : facts.select {|k,v| k.match(/^RE[0-9]+/) }.values[0][:model]
|
3
6
|
|
4
7
|
facts[:switch_style] = case f_persona
|
5
8
|
when :SWITCH, :SRX_BRANCH
|
6
|
-
case
|
9
|
+
case examine
|
7
10
|
when /junosv-firefly/i
|
8
11
|
:NONE
|
9
|
-
when /^(ex9)|(ex43)/i
|
12
|
+
when /^(ex9)|(ex43)|(ocx)/i
|
10
13
|
:VLAN_L2NG
|
14
|
+
when /^(qfx)/i
|
15
|
+
if facts[:version][0..3].to_f >= 13.2
|
16
|
+
:VLAN_L2NG
|
17
|
+
else
|
18
|
+
:VLAN
|
19
|
+
end
|
11
20
|
else
|
12
21
|
:VLAN
|
13
22
|
end
|