shopify-junos-ez-stdlib 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +91 -0
  3. data/LICENSE +26 -0
  4. data/README.md +199 -0
  5. data/docs/Facts.md +192 -0
  6. data/docs/Providers/Group.md +61 -0
  7. data/docs/Providers/IPports.md +61 -0
  8. data/docs/Providers/L1ports.md +29 -0
  9. data/docs/Providers/L2ports.md +43 -0
  10. data/docs/Providers/LAGports.md +57 -0
  11. data/docs/Providers/StaticHosts.md +26 -0
  12. data/docs/Providers/StaticRoutes.md +37 -0
  13. data/docs/Providers/UserAuths.md +32 -0
  14. data/docs/Providers/Users.md +122 -0
  15. data/docs/Providers/Vlans.md +43 -0
  16. data/docs/Providers_Resources.md +353 -0
  17. data/docs/README_FIRST.md +27 -0
  18. data/docs/Utils/Config.md +160 -0
  19. data/docs/Utils/Filesystem.md +360 -0
  20. data/docs/Utils/Routing-Engine.md +379 -0
  21. data/docs/Utils/SCP.md +24 -0
  22. data/examples/config/config_file.rb +72 -0
  23. data/examples/config/config_template_object.rb +81 -0
  24. data/examples/config/config_template_simple.rb +76 -0
  25. data/examples/config/multi_config.rb +60 -0
  26. data/examples/fs_utils.rb +31 -0
  27. data/examples/lag_port.rb +27 -0
  28. data/examples/re_upgrade.rb +99 -0
  29. data/examples/re_utils.rb +33 -0
  30. data/examples/simple.rb +46 -0
  31. data/examples/st_hosts.rb +33 -0
  32. data/examples/user.rb +32 -0
  33. data/examples/vlans.rb +31 -0
  34. data/junos-ez-stdlib.gemspec +15 -0
  35. data/lib/junos-ez/exceptions.rb +3 -0
  36. data/lib/junos-ez/facts.rb +83 -0
  37. data/lib/junos-ez/facts/chassis.rb +51 -0
  38. data/lib/junos-ez/facts/ifd_style.rb +17 -0
  39. data/lib/junos-ez/facts/personality.rb +25 -0
  40. data/lib/junos-ez/facts/switch_style.rb +31 -0
  41. data/lib/junos-ez/facts/version.rb +58 -0
  42. data/lib/junos-ez/group.rb +206 -0
  43. data/lib/junos-ez/ip_ports.rb +30 -0
  44. data/lib/junos-ez/ip_ports/classic.rb +188 -0
  45. data/lib/junos-ez/l1_ports.rb +121 -0
  46. data/lib/junos-ez/l1_ports/classic.rb +87 -0
  47. data/lib/junos-ez/l1_ports/switch.rb +134 -0
  48. data/lib/junos-ez/l2_ports.rb +66 -0
  49. data/lib/junos-ez/l2_ports/bridge_domain.rb +499 -0
  50. data/lib/junos-ez/l2_ports/vlan.rb +433 -0
  51. data/lib/junos-ez/l2_ports/vlan_l2ng.rb +502 -0
  52. data/lib/junos-ez/lag_ports.rb +268 -0
  53. data/lib/junos-ez/provider.rb +619 -0
  54. data/lib/junos-ez/stdlib.rb +18 -0
  55. data/lib/junos-ez/system.rb +48 -0
  56. data/lib/junos-ez/system/st_hosts.rb +92 -0
  57. data/lib/junos-ez/system/st_routes.rb +159 -0
  58. data/lib/junos-ez/system/syscfg.rb +103 -0
  59. data/lib/junos-ez/system/userauths.rb +84 -0
  60. data/lib/junos-ez/system/users.rb +217 -0
  61. data/lib/junos-ez/utils/config.rb +236 -0
  62. data/lib/junos-ez/utils/fs.rb +385 -0
  63. data/lib/junos-ez/utils/re.rb +558 -0
  64. data/lib/junos-ez/version.rb +6 -0
  65. data/lib/junos-ez/vlans.rb +38 -0
  66. data/lib/junos-ez/vlans/bridge_domain.rb +89 -0
  67. data/lib/junos-ez/vlans/vlan.rb +119 -0
  68. data/lib/junos-ez/vlans/vlan_l2ng.rb +126 -0
  69. data/shipit.yml +4 -0
  70. data/tmp +7 -0
  71. metadata +129 -0
@@ -0,0 +1,61 @@
1
+ # Junos::Ez::Group::Provider
2
+
3
+ Manages JUNOS group properties
4
+
5
+ # EXAMPLE
6
+
7
+ The provider *name* selector is the JUNOS group name, e.g. "service_group".
8
+
9
+ ```ruby
10
+ Junos::Ez::Group::Provider( ndev, :group )
11
+
12
+ grp = ndev.group["service_group"]
13
+
14
+ grp[:format] = 'set'
15
+ grp[:path] = 'services.set'
16
+
17
+ grp.write!
18
+
19
+ ```
20
+
21
+ # PROPERTIES
22
+
23
+ - `:format` - JUNOS configuration format is file. It can be 'xml', 'text' or 'set'. Default is 'xml'
24
+ - `:path` - Path of configuration file that is applied inside JUNOS group hierarchy.
25
+
26
+ # METHODS
27
+
28
+ No additional methods at this time ...
29
+
30
+ # USAGE NOTES
31
+
32
+ Contents of 'service.set' file
33
+
34
+ ````
35
+ % cat services.set
36
+ set system services ftp
37
+ set system services ssh
38
+ set system services netconf ssh
39
+ ````
40
+
41
+ JUNOS group configuration reflected on executing above example.
42
+
43
+ ````
44
+ {master}[edit]
45
+ junos@switch# show groups service_group
46
+ system {
47
+ services {
48
+ ftp;
49
+ ssh;
50
+ netconf {
51
+ ssh;
52
+ }
53
+ }
54
+ }
55
+
56
+ junos@switch# show apply-groups
57
+ apply-groups [ global re0 re1 service_group ];
58
+
59
+ ````
60
+
61
+
@@ -0,0 +1,61 @@
1
+ # Junos::Ez::IPports::Provider
2
+
3
+ Manages IPv4 ports. For now, ports recognized are:
4
+
5
+ - Fast Ethernet: `fe-*`
6
+ - Gigabit Ethernet: `ge-*`
7
+ - 10 Gigabit Ethernet: `xe-*`
8
+
9
+ IPv6 ports are a different provider (comming soon...)
10
+
11
+ # USAGE
12
+
13
+ The provider *name* selector is the interface. If the *name* does not include the ".0" unit, the framework will default to this.
14
+
15
+ ```ruby
16
+ Junos::Ez::IPports::Provider( ndev, :ip_ports )
17
+
18
+ port = ndev.ip_ports["ge-0/0/8"]
19
+
20
+ puts "IPv4 port #{port.name} does not exist!" unless port.exists?
21
+ ```
22
+
23
+ # PROPERTIES
24
+
25
+ - `:admin` - [:up, :down] - administrative control of the port
26
+ - `:description` - String, description assigned at the interface unit level
27
+ - `:tag_id` - Fixnum, used if the phyiscal port is vlan-tagging (but not L2port)
28
+ - `:mtu` - Fixnum, MTU value assigned for IP packets (but not L1port MTU)
29
+ - `:address` - String in "ip/prefix" format. For example "192.168.10.12/24"
30
+ - `:acl_in` - Name of input ACL (firewall-filter)
31
+ - `:acl_out` - Name of output ACL
32
+
33
+ # METHODS
34
+
35
+ ## status
36
+
37
+ Returns a Hash of status information about the IP unit interface.
38
+ ```ruby
39
+ port = ndev.ip_ports["ge-0/0/8.0"]
40
+
41
+ # display the configuration information
42
+ pp port.to_h
43
+ ->
44
+ {"ge-0/0/8.0"=>
45
+ {:_active=>true,
46
+ :_exist=>true,
47
+ :admin=>:up,
48
+ :description=>"this is port8",
49
+ :address=>"192.168.100.1/24",
50
+ :acl_in=>"foo",
51
+ :acl_out=>"bar"}}
52
+
53
+ # display the status information
54
+ pp port.status
55
+ ->
56
+ {:l1_oper_status=>:up,
57
+ :oper_status=>:up,
58
+ :snmp_index=>522,
59
+ :packets_rx=>0,
60
+ :packets_tx=>18}
61
+ ```
@@ -0,0 +1,29 @@
1
+ # Junos::Ez::L1ports::Provider
2
+
3
+ Manages the physical properties of interfaces.
4
+
5
+ # USAGE
6
+
7
+ The provider *name* selector is the interface name.
8
+
9
+ ```ruby
10
+ Junos::Ez::L1ports::Provider( ndev, :l1_ports )
11
+
12
+ port = ndev.l1_ports["ge-0/0/12"]
13
+
14
+ port[:admin] = :down
15
+ port.write!
16
+ ```
17
+
18
+ # PROPERTIES
19
+
20
+ - `:admin` - [:up, :down] - administratively controls the port
21
+ - `:description` - String, description applied at the physical port
22
+ - `:mtu` - Fixnum, MTU value applied at the physical port
23
+ - `:speed` - Link Speed, [:auto, '10m', '100m', '1g', 10g']
24
+ - `:duplex` - Link Duplex, [:auto, :half, :full]
25
+ - `:unit_count` - **READ-ONLY** indicates the number of logical ports (units) configured
26
+
27
+ # METHODS
28
+
29
+ No additional methods at this time ...
@@ -0,0 +1,43 @@
1
+ # Junos::Ez::L2ports::Provider
2
+
3
+ Manages the ethernet switch ports. The primary function is to associate switching ports to VLANs.
4
+
5
+ Currently the association of VLANS to ports is read/write under the interfaces stanza. Junos OS also supports
6
+ the association under the VLAN resource stanza (vlans/bridge-domains).
7
+
8
+ _NOTE: this provider does not use the VLAN resource stanza at this time. Under review now. If you have an opionin on this, please let us know, thank you!_
9
+
10
+ # USAGE
11
+
12
+ The provider *name* is the interface. The framework will assume unit 0 if the name does not indicate one.
13
+
14
+ ```ruby
15
+ Junos::Ez::L2ports::Provider( ndev, l2_ports )
16
+
17
+ port = ndev.l2_ports["ge-0/0/12"]
18
+
19
+ puts "port #{port.name} is not a switch-port!" unless port.exists?
20
+ ```
21
+
22
+ # PROPERTIES
23
+
24
+ - `:description` - String description at the logical interface level
25
+ - `:untagged_vlan` - String, VLAN-name for packets without VLAN tags
26
+ - `:tagged_vlans` - Set of VLAN-names for packets with VLAN tags
27
+ - `:vlan_tagging` - [true | false] - indicates if this port accepts packets with VLAN tags
28
+
29
+ # METHODS
30
+
31
+ No additional methods at this time ...
32
+
33
+ # SUPPORTED PLATFORMS
34
+
35
+ - EX2200, EX3200, EX3300, EX4200, EX4500, EX4550, EX6100, EX8200
36
+ - SRX branch: **entire product line, but not vSRX**
37
+ - QFX3500, QFX3600
38
+
39
+ Comming soon:
40
+
41
+ - EX platforms released in 2013
42
+ - MX5, MX10, MX40, MX80, MX240, MX480, MX960
43
+
@@ -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
+
@@ -0,0 +1,26 @@
1
+ # Junos::Ez::StaticHosts::Provider
2
+
3
+ Manages locally configured host-name to IPv4 & IPv6 address mapping
4
+
5
+ # USAGE
6
+
7
+ The provider *name* is the host-name as it would have been configured under `[edit system static-host-mapping]`
8
+
9
+ ```ruby
10
+ Junos::Ez::StaticHosts::Provider( ndev, :etc_hosts )
11
+
12
+ host = ndev.etc_hosts["ex4.jeremylab.net"]
13
+ host[:ip] = "192.168.10.24"
14
+ host.write!
15
+ ```
16
+
17
+ # PROPERITES
18
+
19
+ - `:ip` - The IPv4 address
20
+ - `:ip6` - The IPv6 address
21
+
22
+ _NOTE: A host entry **can** have both IPv4 and IPv6 addresses assigned at the same time_
23
+
24
+ # METHODS
25
+
26
+ No additional methods at this time ...
@@ -0,0 +1,37 @@
1
+ # Junos::Ez::StaticRoutes::Provider
2
+
3
+ Manages static route entries.
4
+
5
+ _NOTE: for now, routing-instances are not supported, but under review for upcoming release..._
6
+
7
+ # USAGE
8
+
9
+ The provider *name* is the target-route. If you want to specify the default-route, you can either use "0.0.0.0/0" or the special name `:default`.
10
+
11
+ ```ruby
12
+ Junos::Ez::StaticRoutes::Provider( ndev, :route )
13
+
14
+ default = ndev.route[:default]
15
+
16
+ unless default.exists?
17
+ default[:gateway] = "192.168.1.1"
18
+ default.write!
19
+ end
20
+ ```
21
+
22
+ # PROPERTIES
23
+
24
+ - `:gateway` - The next-hop gateway. Could be single String or Array-of-Strings
25
+ - `:metic` - The metric assigned to this route, Fixnum
26
+ - `:action` - Configures the route action, [:reject, :discard, :receive]
27
+ - `:active` - Configures the route active, [true, false, nil]
28
+ - `:retain` - Configures the ratain/no-retain flag, [ nil, true, false ]
29
+ - `:install` - Configures the install/no-install flag, [nil, true, false ]
30
+ - `:readvertise` - Configures the readvertise/no-readvertise flag, [nil, true, false]
31
+ - `:resovlve` - Configures the resolve/no-resolve falg, [nil, true, false]
32
+
33
+ In the above "flag controls", assigning the values [true | false] configures if the flat is set or "no-" set respectively. To delete the flag from the configuration, set the property to `nil`.
34
+
35
+ # METHODS
36
+
37
+ No additional methods at this time ...
@@ -0,0 +1,32 @@
1
+ # Junos::Ez::UserAuths::Provider
2
+
3
+ Manages user account ssh-keys, RSA or DSA.
4
+
5
+ # USAGE
6
+
7
+ The provider *name* for accessing the provider is a Hash comprised of the following key/value pairs:
8
+
9
+ - `:user` - String, user-name
10
+ - `:keytype` - String, one of ['ssh-rsa', 'ssh-dsa']
11
+ - `:publickey` - String, the public key value
12
+
13
+ ```ruby
14
+
15
+ # bind :auths for managing ssh-keys directly
16
+
17
+ Junos::Ez::UserAuths::Provider( ndev, :auths )
18
+
19
+ # setup a name Hash to access this key
20
+
21
+ key_name = {}
22
+ key_name[:user] = "jeremy"
23
+ key_name[:keytype] = "ssh-rsa"
24
+ key_name[:publickey] = "ssh-rsa gibberishMagicSwingDeadCatoverHeadand_LetMeLoginFoo"
25
+
26
+ ssh_key = ndev.auths[ key_name ]
27
+
28
+ puts "Key does not exist" unless ssh_key.exists?
29
+ ```
30
+
31
+ Generally speaking, you probably won't be using this provider directly, but rather using a
32
+ `Junos::Ez::Users::Provider` resource and the `load_ssh_key!` method. This method makes use of the `Junos::Ez::UserAuths::Provider` internally.
@@ -0,0 +1,122 @@
1
+ # Junos::Ez::Users::Provider
2
+
3
+ Manages the on-target configured users, located under Junos `[edit system login]` stanza.
4
+
5
+ # USAGE
6
+
7
+ The provider *name* selector is the user-name String.
8
+
9
+ ```ruby
10
+
11
+ # bind :users to provide access to the local login configuration
12
+
13
+ Junos::Ez::Users::Provider( ndev, :users )
14
+
15
+ user = ndev.users["jeremy"]
16
+
17
+ puts "#{user.name} does not exist!" unless user.exists?
18
+ ```
19
+
20
+ # PROPERTIES
21
+
22
+ - `:class` - String, The user priviledge class (like "read-only", or "super-user")
23
+ - `:uid` - Number, User ID (unix). If not provided, Junos will auto-create
24
+ - `:fullname` - String, User Full Name
25
+ - `:password` - Junos encrypted password
26
+ - `:ssh_keys` - SSH keys (READ/ONLY)
27
+
28
+ If you need to modify the user's ssh-keys, see the `load_ssh_key!` method in the next section.
29
+
30
+
31
+
32
+ # RESOURCE METHODS
33
+
34
+ ## password=
35
+
36
+ Used to set the user password by providing a plain-text value.
37
+ ```ruby
38
+
39
+ Junos::Ez::User::Provider( ndev, :users )
40
+
41
+ pp ndev.users.list
42
+ ->
43
+ ["goofy", "jeremy"]
44
+
45
+ user = ndev.users["goofy"]
46
+ user.to_h
47
+ ->
48
+ {"goofy"=>
49
+ {:_active=>true,
50
+ :_exist=>true,
51
+ :uid=>"3000",
52
+ :class=>"read-only",
53
+ :password=>"XRykM8Grm0R0A"}}
54
+
55
+ # set the password with plaintext value, then re-read the config from the device
56
+ user.password = "n3wpassw0rd"
57
+ user.read!
58
+
59
+ user.to_h
60
+ ->
61
+ {"goofy"=>
62
+ {:_active=>true,
63
+ :_exist=>true,
64
+ :uid=>"3000",
65
+ :class=>"read-only",
66
+ :password=>"W05ckLnjLcPCk"}}
67
+ ```
68
+ ## load_ssh_key!( :opts = {} )
69
+
70
+ opts[:publickey] - String of public-key
71
+ opts[:filename] - String, filename on server to public-key file
72
+
73
+ This method will create an ssh-key for the user based on the contents of the provided public key. The key will be written to the device, but not committed (just like resource write!). The `Junos::Ez::UserAuths::Provider` resource for this key will be returned.
74
+
75
+ ```ruby
76
+ user = ndev.users["jeremy"]
77
+ pp user.to_h
78
+ ->
79
+ {"jeremy"=>
80
+ {:_active=>true,
81
+ :_exist=>true,
82
+ :uid=>"2008",
83
+ :class=>"super-user",
84
+ :password=>"$1$JhZms6TE$dXF8P1ey1u3G.5j/V9FBk0"}}
85
+
86
+ # write the key and then re-load user object
87
+ user.load_ssh_key! :filename=>'/home/jschulman/.ssh/keys/key1.pub'
88
+ user.read!
89
+ pp user.to_h
90
+ ->
91
+ {"jeremy"=>
92
+ {:_active=>true,
93
+ :_exist=>true,
94
+ :uid=>"2008",
95
+ :class=>"super-user",
96
+ :password=>"$1$JhZms6TE$dXF8P1ey1u3G.5j/V9FBk0",
97
+ :ssh_keys=>
98
+ {"ssh-rsa"=>
99
+ ["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIpOXEUJFfHstdDjVEaTIf5YkTbUliSel6/dsNe"]}}}
100
+ ```
101
+ ## ssh_key( keytype, index = 0 )
102
+ keytype: ['ssh-rsa', 'ssh-dsa']
103
+
104
+ This method will return a formulate name Hash for the specified key. This name can then be used in conjunction
105
+ with the `Junos::Ez::UserAuth::Provider` class.
106
+
107
+ The `index` parameter is used to select a key in the event that there is more than one in use.
108
+
109
+ ```ruby
110
+ key_name = user.ssh_key( 'ssh-rsa' )
111
+ ->
112
+ {:user=>"jeremy",
113
+ :keytype=>"ssh-rsa",
114
+ :publickey=>
115
+ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIpOXEUJFfHstdDjVEaTIf5YkTbUliSel6/dsNe"}
116
+
117
+ # bind :auths as so we can directly access ssh-keys ...
118
+ Junos::Ez::UserAuths::Provider( ndev, :auths )
119
+
120
+ # now delete the key from the user.
121
+ ndev.auths[ key_name ].delete!
122
+ ```