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,18 @@
1
+
2
+ require 'junos-ez/provider' # framework code
3
+ require 'junos-ez/facts' # fact keeper
4
+ require 'junos-ez/system' # various system resources
5
+ require 'junos-ez/l1_ports' # physical ports
6
+ require 'junos-ez/vlans' # vlans
7
+ require 'junos-ez/l2_ports' # switch ports
8
+ require 'junos-ez/ip_ports' # ip ports (v4)
9
+ require 'junos-ez/lag_ports' # Link Aggregation Groups
10
+ require 'junos-ez/group'
11
+
12
+ # -------------------------------------------------------------------
13
+ # utility libraries, not providers
14
+ # -------------------------------------------------------------------
15
+
16
+ require 'junos-ez/utils/re'
17
+ require 'junos-ez/utils/fs'
18
+ require 'junos-ez/utils/config'
@@ -0,0 +1,48 @@
1
+
2
+ require "junos-ez/provider"
3
+ require 'junos-ez/system/st_hosts'
4
+ require 'junos-ez/system/st_routes'
5
+ require 'junos-ez/system/users'
6
+ require 'junos-ez/system/userauths'
7
+
8
+ ### -----------------------------------------------------------------
9
+ ### the 'syscfg' is a work in progress, do not use ...
10
+ ### -----------------------------------------------------------------
11
+
12
+ module Junos::Ez::SysConfig
13
+
14
+ PROPERTIES = [
15
+ :host_name, # String, host-name
16
+ :domain_name, # domain name, string or array
17
+ :domain_search, # array of dns name suffix values
18
+ :dns_servers, # array of ip-addrs
19
+ :ntp_servers, # array NTP servers HASH of
20
+ # :version
21
+ # :key
22
+ :timezone, # String time-zone
23
+ :date, # String format: YYYYMMDDhhmm.ss
24
+ :location, # location HASH with properties
25
+ # :countrycode
26
+ # :building,
27
+ # :floor,
28
+ # :rack
29
+ ]
30
+
31
+ def self.Provider( ndev, varsym )
32
+ raise ArgumentError "work-in-progress ..."
33
+
34
+ newbie = Junos::Ez::SysConfig::Provider.new( ndev )
35
+ newbie.properties = Junos::Ez::Provider::PROPERTIES + PROPERTIES
36
+ Junos::Ez::Provider.attach_instance_variable( ndev, varsym, newbie )
37
+ end
38
+
39
+ class Provider < Junos::Ez::Provider::Parent
40
+ end
41
+
42
+ end
43
+
44
+ require 'junos-ez/system/syscfg'
45
+
46
+
47
+
48
+
@@ -0,0 +1,92 @@
1
+ module Junos::Ez::StaticHosts
2
+
3
+ PROPERTIES = [
4
+ :ip, # ipv4 address :String
5
+ :ip6, # ipv6 address :String
6
+ ]
7
+
8
+ def self.Provider( ndev, varsym )
9
+ newbie = Junos::Ez::StaticHosts::Provider.new( ndev )
10
+ newbie.properties = Junos::Ez::Provider::PROPERTIES + PROPERTIES
11
+ Junos::Ez::Provider.attach_instance_variable( ndev, varsym, newbie )
12
+ end
13
+
14
+ class Provider < Junos::Ez::Provider::Parent
15
+ end
16
+
17
+ end
18
+
19
+ class Junos::Ez::StaticHosts::Provider
20
+
21
+ ### ---------------------------------------------------------------
22
+ ### XML top placement
23
+ ### ---------------------------------------------------------------
24
+
25
+ def xml_at_top
26
+ xml = Nokogiri::XML::Builder.new {|xml| xml.configuration {
27
+ xml.system { xml.send('static-host-mapping') {
28
+ xml.name @name
29
+ return xml
30
+ }}
31
+ }}
32
+ end
33
+
34
+ ### ---------------------------------------------------------------
35
+ ### XML property readers
36
+ ### ---------------------------------------------------------------
37
+
38
+ def xml_get_has_xml( xml )
39
+ xml.xpath('//static-host-mapping')[0]
40
+ end
41
+
42
+ def xml_read_parser( as_xml, as_hash )
43
+ set_has_status( as_xml, as_hash )
44
+
45
+ ip_v4 = as_xml.xpath('inet').text
46
+ as_hash[:ip] = ip_v4 unless ip_v4.empty?
47
+
48
+ ip_v6 = as_xml.xpath('inet6').text
49
+ as_hash[:ip6] = ip_v6 unless ip_v6.empty?
50
+ end
51
+
52
+ ### ---------------------------------------------------------------
53
+ ### XML property writers
54
+ ### ---------------------------------------------------------------
55
+
56
+ def xml_change_ip( xml )
57
+ xml_set_or_delete( xml, 'inet', @should[:ip] )
58
+ end
59
+
60
+ def xml_change_ip6( xml )
61
+ xml_set_or_delete( xml, 'inet6', @should[:ip6] )
62
+ end
63
+
64
+ end
65
+
66
+ ##### ---------------------------------------------------------------
67
+ ##### Provider collection methods
68
+ ##### ---------------------------------------------------------------
69
+
70
+ class Junos::Ez::StaticHosts::Provider
71
+
72
+ def build_list
73
+ @ndev.rpc.get_configuration{|xml| xml.system {
74
+ xml.send(:'static-host-mapping')
75
+ }}.xpath('system/static-host-mapping/name').collect do |item|
76
+ item.text
77
+ end
78
+ end
79
+
80
+ def build_catalog
81
+ @catalog = {}
82
+ @ndev.rpc.get_configuration{ |xml| xml.system {
83
+ xml.send(:'static-host-mapping')
84
+ }}.xpath('system/static-host-mapping').each do |item|
85
+ name = item.xpath('name').text
86
+ @catalog[name] = {}
87
+ xml_read_parser( item, @catalog[name] )
88
+ end
89
+ @catalog
90
+ end
91
+
92
+ end
@@ -0,0 +1,159 @@
1
+ module Junos::Ez::StaticRoutes
2
+
3
+ PROPERTIES = [
4
+ :gateway, # next-hop gateway, could be single or Array
5
+ :metric, # number or nil
6
+ :action, # one-of [ :reject, :discard, :receive ]
7
+ :active, # flag [ true, nil | false ]
8
+ :retain, # no-flag [ nil, true, false ]
9
+ :install, # no-flag [ nil, true, false ]
10
+ :readvertise, # no-flag [ nil, true, false ]
11
+ :resolve, # no-flag [ nil, true, false ]
12
+ ]
13
+
14
+ def self.Provider( ndev, varsym )
15
+ newbie = Junos::Ez::StaticRoutes::Provider.new( ndev )
16
+ newbie.properties = Junos::Ez::Provider::PROPERTIES + PROPERTIES
17
+ Junos::Ez::Provider.attach_instance_variable( ndev, varsym, newbie )
18
+ end
19
+
20
+ class Provider < Junos::Ez::Provider::Parent
21
+ end
22
+
23
+ end
24
+
25
+ class Junos::Ez::StaticRoutes::Provider
26
+
27
+ ### ---------------------------------------------------------------
28
+ ### XML top placement
29
+ ### ---------------------------------------------------------------
30
+
31
+ def xml_at_top
32
+ @name = "0.0.0.0/0" if @name == :default
33
+
34
+ Nokogiri::XML::Builder.new {|xml| xml.configuration {
35
+ xml.send('routing-options') {
36
+ xml.static { xml.route {
37
+ xml.name @name
38
+ return xml
39
+ }}
40
+ }
41
+ }}
42
+ end
43
+
44
+ ### ---------------------------------------------------------------
45
+ ### XML property readers
46
+ ### ---------------------------------------------------------------
47
+
48
+ def xml_get_has_xml( xml )
49
+ xml.xpath('routing-options/static/route')[0]
50
+ end
51
+
52
+ def xml_read_parser( as_xml, as_hash )
53
+ set_has_status( as_xml, as_hash )
54
+
55
+ ## :gateway
56
+ unless (next_hop = as_xml.xpath('next-hop')).empty?
57
+ if next_hop.count == 1
58
+ as_hash[:gateway] = next_hop.text
59
+ else
60
+ as_hash[:gateway] = next_hop.collect{|i| i.text }
61
+ end
62
+ end
63
+
64
+ unless (active = as_xml.xpath('active')).empty?
65
+ as_hash[:active] = true
66
+ end
67
+
68
+ unless (action = as_xml.xpath( 'reject | discard | receive' )).empty?
69
+ as_hash[:action] = action[0].name.to_sym
70
+ end
71
+
72
+ unless (metric = as_xml.xpath('metric')).empty?
73
+ as_hash[:metric] = metric.text.to_i
74
+ end
75
+
76
+ xml_read_parse_noele( as_xml, 'retain', as_hash, :retain )
77
+ xml_read_parse_noele( as_xml, 'install', as_hash, :install )
78
+ xml_read_parse_noele( as_xml, 'resolve', as_hash, :resolve )
79
+ xml_read_parse_noele( as_xml, 'readvertise', as_hash, :readvertise )
80
+ end
81
+
82
+
83
+ ### ---------------------------------------------------------------
84
+ ### XML property writers
85
+ ### ---------------------------------------------------------------
86
+
87
+ def xml_change_action( xml )
88
+
89
+ if @should[:action].nil?
90
+ xml.send( @has[:action], Netconf::JunosConfig::DELETE )
91
+ return true
92
+ end
93
+
94
+ xml.send( @should[:action] )
95
+ end
96
+
97
+ def xml_change_active( xml )
98
+ xml_set_or_delete_element( xml, 'active', @should[:active] )
99
+ end
100
+
101
+ def xml_change_gateway( xml )
102
+ # delete existing entries
103
+ ele_nh = :'next-hop'
104
+
105
+ # clear any existing values, and return unless there are any new ones ...
106
+ xml.send(ele_nh, Netconf::JunosConfig::DELETE) if @has[:gateway]
107
+ return true unless @should[:gateway]
108
+
109
+ ## adding back the ones we want now ...
110
+ if @should[:gateway].kind_of? String
111
+ xml.send( ele_nh, @should[:gateway] )
112
+ else
113
+ @should[:gateway].each{ |gw| xml.send( ele_nh, gw ) }
114
+ end
115
+ end
116
+
117
+ def xml_change_retain( xml )
118
+ xml_set_or_delete_noele( xml, 'retain' )
119
+ end
120
+
121
+ def xml_change_install( xml )
122
+ xml_set_or_delete_noele( xml, 'install' )
123
+ end
124
+
125
+ def xml_change_resolve( xml )
126
+ xml_set_or_delete_noele( xml, 'resolve' )
127
+ end
128
+
129
+ def xml_change_readvertise( xml )
130
+ xml_set_or_delete_noele( xml, 'readvertise' )
131
+ end
132
+
133
+ def xml_change_metric( xml )
134
+ xml_set_or_delete( xml, 'metric', @should[:metric] )
135
+ end
136
+
137
+
138
+ end
139
+
140
+ ##### ---------------------------------------------------------------
141
+ ##### Provider collection methods
142
+ ##### ---------------------------------------------------------------
143
+
144
+ class Junos::Ez::StaticRoutes::Provider
145
+
146
+ def build_list
147
+ @ndev.rpc.get_configuration{|xml| xml.send(:'routing-options') {
148
+ xml.static { xml.route }
149
+ }}.xpath('//route/name').collect do |item|
150
+ item.text
151
+ end
152
+ end
153
+
154
+ def build_catalog
155
+ @catalog = {}
156
+ @catalog
157
+ end
158
+
159
+ end
@@ -0,0 +1,103 @@
1
+ class Junos::Ez::SysConfig::Provider
2
+
3
+ ### ---------------------------------------------------------------
4
+ ### XML top placement
5
+ ### ---------------------------------------------------------------
6
+
7
+ def xml_at_top
8
+ xml = Nokogiri::XML::Builder.new {|xml| xml.configuration {
9
+ xml.system {
10
+ return xml
11
+ }
12
+ }}
13
+ end
14
+
15
+ def xml_config_read!
16
+ xml = xml_at_top
17
+ xml.send(:'host-name')
18
+ xml.send(:'domain-name')
19
+ xml.send(:'domain-search')
20
+ xml.send(:'time-zone')
21
+ xml.location
22
+ xml.send(:'name-server')
23
+ xml.ntp
24
+ @ndev.rpc.get_configuration( xml )
25
+ end
26
+
27
+ ### ---------------------------------------------------------------
28
+ ### XML property readers
29
+ ### ---------------------------------------------------------------
30
+
31
+ def xml_get_has_xml( xml )
32
+ xml.xpath('system')[0]
33
+ end
34
+
35
+ def xml_read_parser( as_xml, as_hash )
36
+ set_has_status( as_xml, as_hash )
37
+ as_hash[:host_name] = as_xml.xpath('host-name').text
38
+ unless (data = as_xml.xpath('domain-name')).empty?
39
+ as_hash[:domain_name] = data.text
40
+ end
41
+ unless (data = as_xml.xpath('domain-search')).empty?
42
+ as_hash[:domain_search] = data.collect{|i| i.text}
43
+ end
44
+ unless (data = as_xml.xpath('time-zone')).empty?
45
+ as_hash[:timezone] = data.text
46
+ end
47
+ unless (data = as_xml.xpath('name-server/name')).empty?
48
+ as_hash[:dns_servers] = data.collect{|i| i.text}
49
+ end
50
+ unless (data = as_xml.xpath('ntp/server/name')).empty?
51
+ as_hash[:ntp_servers] = data.collect{|i| i.text}
52
+ end
53
+ unless (location = as_xml.xpath('location')).empty?
54
+ as_hash[:location] = {}
55
+ unless (data = location.xpath('building')).empty?
56
+ as_hash[:location][:building] = data.text
57
+ end
58
+ unless (data = location.xpath('country-code')).empty?
59
+ as_hash[:location][:countrycode] = data.text
60
+ end
61
+ unless (data = location.xpath('floor')).empty?
62
+ as_hash[:location][:floor] = data.text
63
+ end
64
+ unless (data = location.xpath('rack')).empty?
65
+ as_hash[:location][:rack] = data.text
66
+ end
67
+ end
68
+ end
69
+
70
+ ### ---------------------------------------------------------------
71
+ ### XML property writers
72
+ ### ---------------------------------------------------------------
73
+
74
+ def xml_change_host_name( xml )
75
+ xml.send(:'host-name', @should[:host_name] )
76
+ end
77
+
78
+ def xml_change_domain_name( xml )
79
+ xml.send(:'domain-name', @should[:domain_name] )
80
+ end
81
+
82
+ def xml_change_domain_search( xml )
83
+ end
84
+
85
+ def xml_change_timezone( xml )
86
+ xml.send(:'time-zone', @should[:timezone])
87
+ end
88
+
89
+ def xml_change_dns_servers( xml )
90
+ end
91
+
92
+ def xml_change_ntp_servers( xml )
93
+ end
94
+
95
+ def xml_change_date( xml )
96
+ end
97
+
98
+ def xml_change_location( xml )
99
+ end
100
+
101
+ end
102
+
103
+
@@ -0,0 +1,84 @@
1
+ =begin
2
+ =end
3
+
4
+ module Junos::Ez::UserAuths
5
+
6
+ VALID_KEY_TYPES = ['ssh-rsa','ssh-dsa']
7
+
8
+ def self.Provider( ndev, varsym )
9
+ newbie = Junos::Ez::UserAuths::Provider.new( ndev )
10
+ newbie.properties = Junos::Ez::Provider::PROPERTIES
11
+ Junos::Ez::Provider.attach_instance_variable( ndev, varsym, newbie )
12
+ end
13
+
14
+ class Provider < Junos::Ez::Provider::Parent
15
+ end
16
+
17
+ end
18
+
19
+ ##### ---------------------------------------------------------------
20
+ ##### Resource Property Methods
21
+ ##### ---------------------------------------------------------------
22
+
23
+ class Junos::Ez::UserAuths::Provider
24
+
25
+ ### ---------------------------------------------------------------
26
+ ### XML top placement
27
+ ### ---------------------------------------------------------------
28
+
29
+ def xml_at_top
30
+ Nokogiri::XML::Builder.new{|x| x.configuration{
31
+ x.system { x.login { x.user {
32
+ x.name @name[:user]
33
+ x.authentication {
34
+ x.send( @name[:keytype].to_sym ) {
35
+ x.name @name[:publickey]
36
+ return x
37
+ }
38
+ }
39
+ }}}
40
+ }}
41
+ end
42
+
43
+ ### ---------------------------------------------------------------
44
+ ### XML readers
45
+ ### ---------------------------------------------------------------
46
+
47
+ def xml_get_has_xml( xml )
48
+ @should[:_active] = true # mark it so it will write!
49
+ xml.xpath('//user/authentication/*')[0]
50
+ end
51
+
52
+ def xml_read_parser( as_xml, as_hash )
53
+ set_has_status( as_xml, as_hash )
54
+ end
55
+
56
+ ### ---------------------------------------------------------------
57
+ ### XML writers
58
+ ### ---------------------------------------------------------------
59
+
60
+ ## !! since we're not actually modifying any properties, we need
61
+ ## !! to overload the xml_build_change method to simply return
62
+ ## !! the config at-top (includes ssh name)
63
+
64
+ def xml_build_change( xml_at_here = nil )
65
+ xml_at_top.doc.root
66
+ end
67
+
68
+ end
69
+
70
+ ##### ---------------------------------------------------------------
71
+ ##### Provider Collection Methods
72
+ ##### ---------------------------------------------------------------
73
+
74
+ class Junos::Ez::UserAuths::Provider
75
+ def build_list
76
+ []
77
+ end
78
+
79
+ def build_catalog
80
+ {}
81
+ end
82
+ end
83
+
84
+