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.
Files changed (62) hide show
  1. checksums.yaml +6 -14
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +8 -0
  5. data/.travis.yml +18 -0
  6. data/CHANGELOG.md +60 -19
  7. data/Gemfile +7 -0
  8. data/README.md +41 -30
  9. data/Rakefile +6 -0
  10. data/SUGGESTION-BOX/README.md +32 -0
  11. data/docs/Providers/Group.md +61 -0
  12. data/docs/Providers/L2ports.md +1 -1
  13. data/docs/Providers/LAGports.md +57 -0
  14. data/docs/Providers/Vlans.md +1 -1
  15. data/examples/config/config_file.rb +0 -0
  16. data/examples/config/config_template_object.rb +0 -0
  17. data/examples/config/config_template_simple.rb +0 -0
  18. data/examples/config/load_sample.conf +129 -0
  19. data/examples/config/load_sample.set +3 -0
  20. data/examples/config/load_template_main.conf +7 -0
  21. data/examples/config/load_template_object.conf +7 -0
  22. data/examples/config/multi_config.rb +0 -0
  23. data/examples/fs_utils.rb +0 -0
  24. data/examples/lag_port.rb +27 -0
  25. data/examples/re_upgrade.rb +0 -0
  26. data/examples/re_utils.rb +0 -0
  27. data/examples/simple.rb +0 -1
  28. data/examples/st_hosts.rb +0 -0
  29. data/examples/user.rb +0 -0
  30. data/examples/vlans.rb +4 -4
  31. data/junos-ez-stdlib.gemspec +25 -14
  32. data/lib/junos-ez/exceptions.rb +0 -0
  33. data/lib/junos-ez/facts.rb +5 -7
  34. data/lib/junos-ez/facts/chassis.rb +6 -0
  35. data/lib/junos-ez/facts/ifd_style.rb +6 -3
  36. data/lib/junos-ez/facts/personality.rb +6 -6
  37. data/lib/junos-ez/facts/switch_style.rb +11 -2
  38. data/lib/junos-ez/facts/version.rb +24 -9
  39. data/lib/junos-ez/group.rb +206 -0
  40. data/lib/junos-ez/ip_ports.rb +0 -0
  41. data/lib/junos-ez/ip_ports/classic.rb +2 -2
  42. data/lib/junos-ez/l1_ports.rb +0 -0
  43. data/lib/junos-ez/l1_ports/classic.rb +0 -0
  44. data/lib/junos-ez/l1_ports/switch.rb +0 -0
  45. data/lib/junos-ez/l2_ports.rb +18 -9
  46. data/lib/junos-ez/l2_ports/bridge_domain.rb +499 -0
  47. data/lib/junos-ez/l2_ports/vlan.rb +3 -3
  48. data/lib/junos-ez/l2_ports/vlan_l2ng.rb +502 -0
  49. data/lib/junos-ez/lag_ports.rb +268 -0
  50. data/lib/junos-ez/provider.rb +4 -8
  51. data/lib/junos-ez/stdlib.rb +2 -0
  52. data/lib/junos-ez/system.rb +0 -0
  53. data/lib/junos-ez/system/users.rb +5 -7
  54. data/lib/junos-ez/utils/config.rb +0 -0
  55. data/lib/junos-ez/utils/fs.rb +0 -0
  56. data/lib/junos-ez/utils/re.rb +0 -0
  57. data/lib/junos-ez/version.rb +4 -1
  58. data/lib/junos-ez/vlans.rb +4 -1
  59. data/lib/junos-ez/vlans/bridge_domain.rb +7 -3
  60. data/lib/junos-ez/vlans/vlan.rb +4 -3
  61. data/lib/junos-ez/vlans/vlan_l2ng.rb +126 -0
  62. metadata +142 -64
@@ -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` - Array of VLAN-names for packets with VLAN tags
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
+
@@ -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 `true` this VLAN will not learn MAC addresses
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
+ }
@@ -0,0 +1,3 @@
1
+ set system host-name jeremy
2
+ set system domain-name foo.bar
3
+
@@ -0,0 +1,7 @@
1
+ interfaces {
2
+ <% interfaces.each do |ifd| %>
3
+ <%= ifd %> {
4
+ disable;
5
+ }
6
+ <% end %>
7
+ }
@@ -0,0 +1,7 @@
1
+ interfaces {
2
+ <% @interfaces.each do |ifd| %>
3
+ <%= ifd %> {
4
+ disable;
5
+ }
6
+ <% end %>
7
+ }
File without changes
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
File without changes
File without changes
@@ -2,7 +2,6 @@ require 'pry'
2
2
  require 'yaml'
3
3
  require 'net/netconf/jnpr'
4
4
  require 'junos-ez/stdlib'
5
- require 'junos-ez/srx'
6
5
 
7
6
  unless ARGV[0]
8
7
  puts "You must specify a target"
File without changes
File without changes
@@ -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
 
@@ -1,15 +1,26 @@
1
- $LOAD_PATH.unshift 'lib'
2
- require 'rake'
3
- require 'junos-ez/provider'
4
-
5
- Gem::Specification.new do |s|
6
- s.name = 'junos-ez-stdlib'
7
- s.version = Junos::Ez::VERSION
8
- s.summary = "Junos EZ Framework - Standard Libraries"
9
- s.description = "Automation Framework for Junos/NETCONF: Facts, Providers, and Utils"
10
- s.homepage = 'https://github.com/jeremyschulman/ruby-junos-ez-stdlib'
11
- s.authors = ["Jeremy Schulman"]
12
- s.email = 'jschulman@juniper.net'
13
- s.files = FileList[ '*', 'lib/**/*.rb', 'examples/**/*.rb', 'docs/**/*.md' ]
14
- s.add_dependency('netconf', ">= 0.2.5")
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
File without changes
@@ -75,11 +75,9 @@ end
75
75
  ### Load all of the fact files
76
76
  ### -----------------------------------------------------------------
77
77
 
78
- Dir[File.dirname(__FILE__) + "/facts/*.rb"].each do |file|
79
- require file
80
- end
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
- :SWITCH
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[:RE0][:model]
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 facts[:hardwaremodel]
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