bolt 0.21.7 → 0.21.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bolt might be problematic. Click here for more details.

Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bolt/transport/ssh/connection.rb +4 -5
  3. data/lib/bolt/transport/ssh.rb +4 -1
  4. data/lib/bolt/transport/winrm/connection.rb +3 -4
  5. data/lib/bolt/transport/winrm.rb +4 -1
  6. data/lib/bolt/version.rb +1 -1
  7. data/libexec/apply_catalog.rb +10 -2
  8. data/vendored/puppet/lib/puppet/application/apply.rb +20 -9
  9. data/vendored/puppet/lib/puppet/application/cert.rb +3 -1
  10. data/vendored/puppet/lib/puppet/application/device.rb +22 -5
  11. data/vendored/puppet/lib/puppet/configurer/fact_handler.rb +5 -1
  12. data/vendored/puppet/lib/puppet/configurer.rb +15 -2
  13. data/vendored/puppet/lib/puppet/defaults.rb +36 -25
  14. data/vendored/puppet/lib/puppet/face/certificate.rb +2 -0
  15. data/vendored/puppet/lib/puppet/feature/base.rb +0 -3
  16. data/vendored/puppet/lib/puppet/functions/call.rb +37 -0
  17. data/vendored/puppet/lib/puppet/functions.rb +5 -0
  18. data/vendored/puppet/lib/puppet/indirector/ldap.rb +6 -0
  19. data/vendored/puppet/lib/puppet/node/environment.rb +4 -2
  20. data/vendored/puppet/lib/puppet/parser/scope.rb +2 -2
  21. data/vendored/puppet/lib/puppet/pops/adapters.rb +14 -0
  22. data/vendored/puppet/lib/puppet/pops/evaluator/deferred_resolver.rb +128 -0
  23. data/vendored/puppet/lib/puppet/pops/evaluator/evaluator_impl.rb +4 -1
  24. data/vendored/puppet/lib/puppet/pops/functions/dispatch.rb +2 -0
  25. data/vendored/puppet/lib/puppet/pops/issues.rb +9 -1
  26. data/vendored/puppet/lib/puppet/pops/loader/static_loader.rb +0 -16
  27. data/vendored/puppet/lib/puppet/pops/loaders.rb +1 -3
  28. data/vendored/puppet/lib/puppet/pops/parser/eparser.rb +6 -6
  29. data/vendored/puppet/lib/puppet/pops/pcore.rb +11 -0
  30. data/vendored/puppet/lib/puppet/pops/types/type_factory.rb +17 -0
  31. data/vendored/puppet/lib/puppet/pops/validation/tasks_checker.rb +13 -5
  32. data/vendored/puppet/lib/puppet/pops.rb +1 -0
  33. data/vendored/puppet/lib/puppet/provider/service/debian.rb +1 -0
  34. data/vendored/puppet/lib/puppet/provider/service/smf.rb +2 -3
  35. data/vendored/puppet/lib/puppet/provider/service/upstart.rb +10 -2
  36. data/vendored/puppet/lib/puppet/ssl/certificate_authority.rb +6 -84
  37. data/vendored/puppet/lib/puppet/ssl/certificate_request.rb +11 -3
  38. data/vendored/puppet/lib/puppet/type/file.rb +3 -0
  39. data/vendored/puppet/lib/puppet/type/user.rb +17 -3
  40. data/vendored/puppet/lib/puppet/util/autoload.rb +36 -31
  41. data/vendored/puppet/lib/puppet/util.rb +2 -0
  42. metadata +3 -43
  43. data/vendored/puppet/lib/puppet/indirector/node/write_only_yaml.rb +0 -39
  44. data/vendored/puppet/lib/puppet/provider/augeas/augeas.rb +0 -573
  45. data/vendored/puppet/lib/puppet/provider/cisco.rb +0 -9
  46. data/vendored/puppet/lib/puppet/provider/computer/computer.rb +0 -20
  47. data/vendored/puppet/lib/puppet/provider/host/parsed.rb +0 -46
  48. data/vendored/puppet/lib/puppet/provider/interface/cisco.rb +0 -27
  49. data/vendored/puppet/lib/puppet/provider/macauthorization/macauthorization.rb +0 -298
  50. data/vendored/puppet/lib/puppet/provider/mcx/mcxcontent.rb +0 -173
  51. data/vendored/puppet/lib/puppet/provider/mount/parsed.rb +0 -282
  52. data/vendored/puppet/lib/puppet/provider/mount.rb +0 -76
  53. data/vendored/puppet/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +0 -590
  54. data/vendored/puppet/lib/puppet/provider/selboolean/getsetsebool.rb +0 -47
  55. data/vendored/puppet/lib/puppet/provider/selmodule/semodule.rb +0 -140
  56. data/vendored/puppet/lib/puppet/provider/ssh_authorized_key/parsed.rb +0 -105
  57. data/vendored/puppet/lib/puppet/provider/sshkey/parsed.rb +0 -50
  58. data/vendored/puppet/lib/puppet/provider/vlan/cisco.rb +0 -28
  59. data/vendored/puppet/lib/puppet/provider/yumrepo/inifile.rb +0 -315
  60. data/vendored/puppet/lib/puppet/type/augeas.rb +0 -211
  61. data/vendored/puppet/lib/puppet/type/computer.rb +0 -66
  62. data/vendored/puppet/lib/puppet/type/host.rb +0 -95
  63. data/vendored/puppet/lib/puppet/type/interface.rb +0 -121
  64. data/vendored/puppet/lib/puppet/type/k5login.rb +0 -165
  65. data/vendored/puppet/lib/puppet/type/macauthorization.rb +0 -167
  66. data/vendored/puppet/lib/puppet/type/mcx.rb +0 -98
  67. data/vendored/puppet/lib/puppet/type/mount.rb +0 -314
  68. data/vendored/puppet/lib/puppet/type/router.rb +0 -17
  69. data/vendored/puppet/lib/puppet/type/scheduled_task.rb +0 -183
  70. data/vendored/puppet/lib/puppet/type/selboolean.rb +0 -26
  71. data/vendored/puppet/lib/puppet/type/selmodule.rb +0 -59
  72. data/vendored/puppet/lib/puppet/type/ssh_authorized_key.rb +0 -143
  73. data/vendored/puppet/lib/puppet/type/sshkey.rb +0 -83
  74. data/vendored/puppet/lib/puppet/type/vlan.rb +0 -26
  75. data/vendored/puppet/lib/puppet/type/yumrepo.rb +0 -430
  76. data/vendored/puppet/lib/puppet/util/network_device/cisco/device.rb +0 -285
  77. data/vendored/puppet/lib/puppet/util/network_device/cisco/facts.rb +0 -72
  78. data/vendored/puppet/lib/puppet/util/network_device/cisco/interface.rb +0 -94
  79. data/vendored/puppet/lib/puppet/util/network_device/cisco.rb +0 -4
  80. data/vendored/puppet/lib/puppet/util/network_device/ipcalc.rb +0 -68
  81. data/vendored/puppet/lib/puppet/util/network_device/transport/ssh.rb +0 -126
  82. data/vendored/puppet/lib/puppet/util/network_device/transport/telnet.rb +0 -47
  83. data/vendored/puppet/lib/puppet/util/windows/taskscheduler.rb +0 -1267
@@ -1,430 +0,0 @@
1
- require 'uri'
2
-
3
- Puppet::Type.newtype(:yumrepo) do
4
- @doc = "The client-side description of a yum repository. Repository
5
- configurations are found by parsing `/etc/yum.conf` and
6
- the files indicated by the `reposdir` option in that file
7
- (see `yum.conf(5)` for details).
8
-
9
- Most parameters are identical to the ones documented
10
- in the `yum.conf(5)` man page.
11
-
12
- Continuation lines that yum supports (for the `baseurl`, for example)
13
- are not supported. This type does not attempt to read or verify the
14
- existence of files listed in the `include` attribute."
15
-
16
- # Ensure yumrepos can be removed too.
17
- ensurable
18
- # Doc string for properties that can be made 'absent'
19
- ABSENT_DOC="Set this to `absent` to remove it from the file completely."
20
- # False can be false/0/no and True can be true/1/yes in yum.
21
- YUM_BOOLEAN=/^(true|false|0|1|no|yes)$/
22
- YUM_BOOLEAN_DOC="Valid values are: false/0/no or true/1/yes."
23
-
24
- # Common munge logic for YUM_BOOLEAN values. Munges for two requirements:
25
- # 1) Because of how regex validation works in Puppet::Parameter::Value,
26
- # Boolean false and lowercase false will not be considered invalid. However,
27
- # if the user specified false (or true), they meant False (or True).
28
- # 2) In order for parameter removal to work correctly, when absent is passed
29
- # as a string it needs to be munged back to a symbol.
30
- munge_yum_bool = Proc.new do |val|
31
- val.to_s == 'absent' ? :absent : val.to_s.capitalize
32
- end
33
-
34
- VALID_SCHEMES = %w[file http https ftp]
35
-
36
- newparam(:name, :namevar => true) do
37
- desc "The name of the repository. This corresponds to the
38
- `repositoryid` parameter in `yum.conf(5)`."
39
- end
40
-
41
- newparam(:target) do
42
- desc "The target parameter will be enabled in a future release and should not be used."
43
-
44
- defaultto :absent
45
- end
46
-
47
- newproperty(:descr) do
48
- desc "A human-readable description of the repository.
49
- This corresponds to the name parameter in `yum.conf(5)`.
50
- #{ABSENT_DOC}"
51
-
52
- newvalues(/.*/, :absent)
53
- end
54
-
55
- newproperty(:mirrorlist) do
56
- desc "The URL that holds the list of mirrors for this repository.
57
- #{ABSENT_DOC}"
58
-
59
- newvalues(/.*/, :absent)
60
- validate do |value|
61
- next if value.to_s == 'absent'
62
- parsed = URI.parse(value)
63
-
64
- unless VALID_SCHEMES.include?(parsed.scheme)
65
- raise _("Must be a valid URL")
66
- end
67
- end
68
- end
69
-
70
- newproperty(:baseurl) do
71
- desc "The URL for this repository. #{ABSENT_DOC}"
72
-
73
- newvalues(/.*/, :absent)
74
- validate do |value|
75
- next if value.to_s == 'absent'
76
-
77
- value.split(/\s+/).each do |uri|
78
-
79
- parsed = URI.parse(uri)
80
-
81
- unless VALID_SCHEMES.include?(parsed.scheme)
82
- raise _("Must be a valid URL")
83
- end
84
- end
85
- end
86
- end
87
-
88
- newproperty(:enabled) do
89
- desc "Whether this repository is enabled.
90
- #{YUM_BOOLEAN_DOC}
91
- #{ABSENT_DOC}"
92
-
93
- newvalues(YUM_BOOLEAN, :absent)
94
- munge(&munge_yum_bool)
95
- end
96
-
97
- newproperty(:gpgcheck) do
98
- desc "Whether to check the GPG signature on packages installed
99
- from this repository.
100
- #{YUM_BOOLEAN_DOC}
101
- #{ABSENT_DOC}"
102
-
103
- newvalues(YUM_BOOLEAN, :absent)
104
- munge(&munge_yum_bool)
105
- end
106
-
107
- newproperty(:payload_gpgcheck) do
108
- desc "Whether to check the GPG signature of the packages payload.
109
- #{YUM_BOOLEAN_DOC}
110
- #{ABSENT_DOC}"
111
-
112
- newvalues(YUM_BOOLEAN, :absent)
113
- munge(&munge_yum_bool)
114
- end
115
-
116
- newproperty(:repo_gpgcheck) do
117
- desc "Whether to check the GPG signature on repodata.
118
- #{YUM_BOOLEAN_DOC}
119
- #{ABSENT_DOC}"
120
-
121
- newvalues(YUM_BOOLEAN, :absent)
122
- munge(&munge_yum_bool)
123
- end
124
-
125
- newproperty(:gpgkey) do
126
- desc "The URL for the GPG key with which packages from this
127
- repository are signed. #{ABSENT_DOC}"
128
-
129
- newvalues(/.*/, :absent)
130
- validate do |value|
131
- next if value.to_s == 'absent'
132
-
133
- value.split(/\s+/).each do |uri|
134
-
135
- parsed = URI.parse(uri)
136
-
137
- unless VALID_SCHEMES.include?(parsed.scheme)
138
- raise _("Must be a valid URL")
139
- end
140
- end
141
- end
142
- end
143
-
144
- newproperty(:mirrorlist_expire) do
145
- desc "Time (in seconds) after which the mirrorlist locally cached
146
- will expire.\n#{ABSENT_DOC}"
147
-
148
- newvalues(/^[0-9]+$/, :absent)
149
- end
150
-
151
- newproperty(:include) do
152
- desc "The URL of a remote file containing additional yum configuration
153
- settings. Puppet does not check for this file's existence or validity.
154
- #{ABSENT_DOC}"
155
-
156
- newvalues(/.*/, :absent)
157
- validate do |value|
158
- next if value.to_s == 'absent'
159
- parsed = URI.parse(value)
160
-
161
- unless VALID_SCHEMES.include?(parsed.scheme)
162
- raise _("Must be a valid URL")
163
- end
164
- end
165
- end
166
-
167
- newproperty(:exclude) do
168
- desc "The string of package names or shell globs separated by spaces to exclude.
169
- Packages that match the package name given or shell globs will never be
170
- considered in updates or installs for this repo.
171
- #{ABSENT_DOC}"
172
-
173
- newvalues(/.*/, :absent)
174
- end
175
-
176
- newproperty(:gpgcakey) do
177
- desc "The URL for the GPG CA key for this repository. #{ABSENT_DOC}"
178
-
179
- newvalues(/.*/, :absent)
180
- validate do |value|
181
- next if value.to_s == 'absent'
182
- parsed = URI.parse(value)
183
-
184
- unless VALID_SCHEMES.include?(parsed.scheme)
185
- raise _("Must be a valid URL")
186
- end
187
- end
188
- end
189
-
190
- newproperty(:includepkgs) do
191
- desc "The string of package names or shell globs separated by spaces to
192
- include. If this is set, only packages matching one of the package
193
- names or shell globs will be considered for update or install
194
- from this repository. #{ABSENT_DOC}"
195
-
196
- newvalues(/.*/, :absent)
197
- end
198
-
199
- newproperty(:enablegroups) do
200
- desc "Whether yum will allow the use of package groups for this
201
- repository.
202
- #{YUM_BOOLEAN_DOC}
203
- #{ABSENT_DOC}"
204
-
205
- newvalues(YUM_BOOLEAN, :absent)
206
- munge(&munge_yum_bool)
207
- end
208
-
209
- newproperty(:failovermethod) do
210
- desc "The failover method for this repository; should be either
211
- `roundrobin` or `priority`. #{ABSENT_DOC}"
212
-
213
- newvalues(/^roundrobin|priority$/, :absent)
214
- end
215
-
216
- newproperty(:keepalive) do
217
- desc "Whether HTTP/1.1 keepalive should be used with this repository.
218
- #{YUM_BOOLEAN_DOC}
219
- #{ABSENT_DOC}"
220
-
221
- newvalues(YUM_BOOLEAN, :absent)
222
- munge(&munge_yum_bool)
223
- end
224
-
225
- newproperty(:retries) do
226
- desc "Set the number of times any attempt to retrieve a file should
227
- retry before returning an error. Setting this to `0` makes yum
228
- try forever.\n#{ABSENT_DOC}"
229
-
230
- newvalues(/^[0-9]+$/, :absent)
231
- end
232
-
233
- newproperty(:http_caching) do
234
- desc "What to cache from this repository. #{ABSENT_DOC}"
235
-
236
- newvalues(/^(packages|all|none)$/, :absent)
237
- end
238
-
239
- newproperty(:timeout) do
240
- desc "Number of seconds to wait for a connection before timing
241
- out. #{ABSENT_DOC}"
242
-
243
- newvalues(/^\d+$/, :absent)
244
- end
245
-
246
- newproperty(:metadata_expire) do
247
- desc "Number of seconds after which the metadata will expire.
248
- #{ABSENT_DOC}"
249
-
250
- newvalues(/^([0-9]+[dhm]?|never)$/, :absent)
251
- end
252
-
253
- newproperty(:protect) do
254
- desc "Enable or disable protection for this repository. Requires
255
- that the `protectbase` plugin is installed and enabled.
256
- #{YUM_BOOLEAN_DOC}
257
- #{ABSENT_DOC}"
258
-
259
- newvalues(YUM_BOOLEAN, :absent)
260
- munge(&munge_yum_bool)
261
- end
262
-
263
- newproperty(:priority) do
264
- desc "Priority of this repository. Can be any integer value
265
- (including negative). Requires that the `priorities` plugin
266
- is installed and enabled.
267
- #{ABSENT_DOC}"
268
-
269
- newvalues(/^-?\d+$/, :absent)
270
- end
271
-
272
- newproperty(:throttle) do
273
- desc "Enable bandwidth throttling for downloads. This option
274
- can be expressed as a absolute data rate in bytes/sec or a
275
- percentage `60%`. An SI prefix (k, M or G) may be appended
276
- to the data rate values.\n#{ABSENT_DOC}"
277
-
278
- newvalues(/^\d+[kMG%]?$/, :absent)
279
- end
280
-
281
- newproperty(:bandwidth) do
282
- desc "Use to specify the maximum available network bandwidth
283
- in bytes/second. Used with the `throttle` option. If `throttle`
284
- is a percentage and `bandwidth` is `0` then bandwidth throttling
285
- will be disabled. If `throttle` is expressed as a data rate then
286
- this option is ignored.\n#{ABSENT_DOC}"
287
-
288
- newvalues(/^\d+[kMG]?$/, :absent)
289
- end
290
-
291
- newproperty(:cost) do
292
- desc "Cost of this repository. #{ABSENT_DOC}"
293
-
294
- newvalues(/^\d+$/, :absent)
295
- end
296
-
297
- newproperty(:proxy) do
298
- desc "URL of a proxy server that Yum should use when accessing this repository.
299
- This attribute can also be set to `'_none_'`, which will make Yum bypass any
300
- global proxy settings when accessing this repository.
301
- #{ABSENT_DOC}"
302
-
303
- newvalues(/.*/, :absent)
304
- validate do |value|
305
- next if value.to_s =~ /^(absent|_none_)$/
306
- parsed = URI.parse(value)
307
-
308
- unless VALID_SCHEMES.include?(parsed.scheme)
309
- raise _("Must be a valid URL")
310
- end
311
- end
312
- end
313
-
314
- newproperty(:proxy_username) do
315
- desc "Username for this proxy. #{ABSENT_DOC}"
316
-
317
- newvalues(/.*/, :absent)
318
- end
319
-
320
- newproperty(:proxy_password) do
321
- desc "Password for this proxy. #{ABSENT_DOC}"
322
-
323
- newvalues(/.*/, :absent)
324
-
325
- sensitive true
326
- end
327
-
328
- newproperty(:s3_enabled) do
329
- desc "Access the repository via S3.
330
- #{YUM_BOOLEAN_DOC}
331
- #{ABSENT_DOC}"
332
-
333
- newvalues(YUM_BOOLEAN, :absent)
334
- munge(&munge_yum_bool)
335
- end
336
-
337
- newproperty(:sslcacert) do
338
- desc "Path to the directory containing the databases of the
339
- certificate authorities yum should use to verify SSL certificates.
340
- #{ABSENT_DOC}"
341
-
342
- newvalues(/.*/, :absent)
343
- end
344
-
345
- newproperty(:sslverify) do
346
- desc "Should yum verify SSL certificates/hosts at all.
347
- #{YUM_BOOLEAN_DOC}
348
- #{ABSENT_DOC}"
349
-
350
- newvalues(YUM_BOOLEAN, :absent)
351
- munge(&munge_yum_bool)
352
- end
353
-
354
- newproperty(:sslclientcert) do
355
- desc "Path to the SSL client certificate yum should use to connect
356
- to repositories/remote sites. #{ABSENT_DOC}"
357
-
358
- newvalues(/.*/, :absent)
359
- end
360
-
361
- newproperty(:sslclientkey) do
362
- desc "Path to the SSL client key yum should use to connect
363
- to repositories/remote sites. #{ABSENT_DOC}"
364
-
365
- newvalues(/.*/, :absent)
366
- end
367
-
368
- newproperty(:metalink) do
369
- desc "Metalink for mirrors. #{ABSENT_DOC}"
370
-
371
- newvalues(/.*/, :absent)
372
- validate do |value|
373
- next if value.to_s == 'absent'
374
- parsed = URI.parse(value)
375
-
376
- unless VALID_SCHEMES.include?(parsed.scheme)
377
- raise _("Must be a valid URL")
378
- end
379
- end
380
- end
381
-
382
- newproperty(:skip_if_unavailable) do
383
- desc "Should yum skip this repository if unable to reach it.
384
- #{YUM_BOOLEAN_DOC}
385
- #{ABSENT_DOC}"
386
-
387
- newvalues(YUM_BOOLEAN, :absent)
388
- munge(&munge_yum_bool)
389
- end
390
-
391
- newproperty(:assumeyes) do
392
- desc "Determines if yum prompts for confirmation of critical actions.
393
- #{YUM_BOOLEAN_DOC}
394
- #{ABSENT_DOC}"
395
-
396
- newvalues(YUM_BOOLEAN, :absent)
397
- munge(&munge_yum_bool)
398
- end
399
-
400
- newproperty(:deltarpm_percentage) do
401
- desc "Percentage value that determines when to use deltas for this repository.
402
- When the delta is larger than this percentage value of the package, the
403
- delta is not used.
404
- #{ABSENT_DOC}"
405
-
406
- newvalues(/^\d+$/, :absent)
407
- end
408
-
409
- newproperty(:deltarpm_metadata_percentage) do
410
- desc "Percentage value that determines when to download deltarpm metadata.
411
- When the deltarpm metadata is larger than this percentage value of the
412
- package, deltarpm metadata is not downloaded.
413
- #{ABSENT_DOC}"
414
-
415
- newvalues(/^\d+$/, :absent)
416
- end
417
-
418
- newproperty(:username) do
419
- desc "Username to use for basic authentication to a repo or really any url.
420
- #{ABSENT_DOC}"
421
- newvalues(/.*/, :absent)
422
- end
423
-
424
- newproperty(:password) do
425
- desc "Password to use with the username for basic authentication.
426
- #{ABSENT_DOC}"
427
- newvalues(/.*/, :absent)
428
- sensitive true
429
- end
430
- end
@@ -1,285 +0,0 @@
1
- require 'puppet'
2
- require 'puppet/util'
3
- require 'puppet/util/network_device/base'
4
- require 'puppet/util/network_device/ipcalc'
5
- require 'puppet/util/network_device/cisco/interface'
6
- require 'puppet/util/network_device/cisco/facts'
7
- require 'ipaddr'
8
-
9
- class Puppet::Util::NetworkDevice::Cisco::Device < Puppet::Util::NetworkDevice::Base
10
-
11
- include Puppet::Util::NetworkDevice::IPCalc
12
-
13
- attr_accessor :enable_password
14
-
15
- def initialize(url, options = {})
16
- super(url, options)
17
- @enable_password = options[:enable_password] || parse_enable(@url.query)
18
- transport.default_prompt = /[#>]\s?\z/n
19
- end
20
-
21
- def parse_enable(query)
22
- if query
23
- params = CGI.parse(query)
24
- params['enable'].first unless params['enable'].empty?
25
- end
26
- end
27
-
28
- def connect
29
- transport.connect
30
- login
31
- transport.command("terminal length 0") do |out|
32
- enable if out =~ />\s?\z/n
33
- end
34
- find_capabilities
35
- end
36
-
37
- def disconnect
38
- transport.close
39
- end
40
-
41
- def command(cmd = nil)
42
- connect
43
- out = execute(cmd) if cmd
44
- yield self if block_given?
45
- disconnect
46
- out
47
- end
48
-
49
- def execute(cmd)
50
- transport.command(cmd) do |out|
51
- if out =~ /^%/mo or out =~ /^Command rejected:/mo
52
- # strip off the command just sent
53
- error = out.sub(cmd,'')
54
- Puppet.err _("Error while executing '%{cmd}', device returned: %{error}") % { cmd: cmd, error: error }
55
- end
56
- end
57
- end
58
-
59
- def login
60
- return if transport.handles_login?
61
- if @url.user != ''
62
- transport.command(@url.user, :prompt => /^Password:/)
63
- else
64
- transport.expect(/^Password:/)
65
- end
66
- transport.command(@url.password)
67
- end
68
-
69
- def enable
70
- raise _("Can't issue \"enable\" to enter privileged, no enable password set") unless enable_password
71
- transport.command("enable", :prompt => /^Password:/)
72
- transport.command(enable_password)
73
- end
74
-
75
- def support_vlan_brief?
76
- !! @support_vlan_brief
77
- end
78
-
79
- def find_capabilities
80
- out = execute("sh vlan brief")
81
- lines = out.split("\n")
82
- lines.shift; lines.pop
83
-
84
- @support_vlan_brief = ! (lines.first =~ /^%/)
85
- end
86
-
87
- IF = {
88
- :FastEthernet => %w{FastEthernet FastEth Fast FE Fa F},
89
- :GigabitEthernet => %w{GigabitEthernet GigEthernet GigEth GE Gi G},
90
- :TenGigabitEthernet => %w{TenGigabitEthernet TE Te},
91
- :Ethernet => %w{Ethernet Eth E},
92
- :Serial => %w{Serial Se S},
93
- :PortChannel => %w{PortChannel Port-Channel Po},
94
- :POS => %w{POS P},
95
- :VLAN => %w{VLAN VL V},
96
- :Loopback => %w{Loopback Loop Lo},
97
- :ATM => %w{ATM AT A},
98
- :Dialer => %w{Dialer Dial Di D},
99
- :VirtualAccess => %w{Virtual-Access Virtual-A Virtual Virt}
100
- }
101
-
102
- def canonicalize_ifname(interface)
103
- IF.each do |k,ifnames|
104
- if found = ifnames.find { |ifname| interface =~ /^#{ifname}\s*\d/i }
105
- found = /^#{found}(.+)\Z/i.match(interface)
106
- return "#{k.to_s}#{found[1]}".gsub(/\s+/,'')
107
- end
108
- end
109
- interface
110
- end
111
-
112
- def facts
113
- @facts ||= Puppet::Util::NetworkDevice::Cisco::Facts.new(transport)
114
- facts = {}
115
- command do |ng|
116
- facts = @facts.retrieve
117
- end
118
- facts
119
- end
120
-
121
- def interface(name)
122
- ifname = canonicalize_ifname(name)
123
- interface = parse_interface(ifname)
124
- return { :ensure => :absent } if interface.empty?
125
- interface.merge!(parse_trunking(ifname))
126
- interface.merge!(parse_interface_config(ifname))
127
- end
128
-
129
- def new_interface(name)
130
- Puppet::Util::NetworkDevice::Cisco::Interface.new(canonicalize_ifname(name), transport)
131
- end
132
-
133
- def parse_interface(name)
134
- resource = {}
135
- out = execute("sh interface #{name}")
136
- lines = out.split("\n")
137
- lines.shift; lines.pop
138
- lines.each do |l|
139
- if l =~ /#{name} is (.+), line protocol is /
140
- resource[:ensure] = ($1 == 'up' ? :present : :absent);
141
- end
142
- if l =~ /Auto Speed \(.+\),/ or l =~ /Auto Speed ,/ or l =~ /Auto-speed/
143
- resource[:speed] = :auto
144
- end
145
- if l =~ /, (.+)Mb\/s/
146
- resource[:speed] = $1
147
- end
148
- if l =~ /\s+Auto-duplex \((.{4})\),/
149
- resource[:duplex] = :auto
150
- end
151
- if l =~ /\s+(.+)-duplex/
152
- resource[:duplex] = $1 == "Auto" ? :auto : $1.downcase.to_sym
153
- end
154
- if l =~ /Description: (.+)/
155
- resource[:description] = $1
156
- end
157
- end
158
- resource
159
- end
160
-
161
- def parse_interface_config(name)
162
- resource = Hash.new { |hash, key| hash[key] = Array.new ; }
163
- out = execute("sh running-config interface #{name} | begin interface")
164
- lines = out.split("\n")
165
- lines.shift; lines.pop
166
- lines.each do |l|
167
- if l =~ /ip address (#{IP}) (#{IP})\s+secondary\s*$/
168
- resource[:ipaddress] << [prefix_length(IPAddr.new($2)), IPAddr.new($1), 'secondary']
169
- end
170
- if l =~ /ip address (#{IP}) (#{IP})\s*$/
171
- resource[:ipaddress] << [prefix_length(IPAddr.new($2)), IPAddr.new($1), nil]
172
- end
173
- if l =~ /ipv6 address (#{IP})\/(\d+) (eui-64|link-local)/
174
- resource[:ipaddress] << [$2.to_i, IPAddr.new($1), $3]
175
- end
176
- if l =~ /channel-group\s+(\d+)/
177
- resource[:etherchannel] = $1
178
- end
179
- end
180
- resource
181
- end
182
-
183
- def parse_vlans
184
- vlans = {}
185
- out = execute(support_vlan_brief? ? "sh vlan brief" : "sh vlan-switch brief")
186
- lines = out.split("\n")
187
- lines.shift; lines.shift; lines.shift; lines.pop
188
- vlan = nil
189
- lines.each do |l|
190
- case l
191
- # vlan name status
192
- when /^(\d+)\s+(\w+)\s+(\w+)\s+([a-zA-Z0-9,\/. ]+)\s*$/
193
- vlan = { :name => $1, :description => $2, :status => $3, :interfaces => [] }
194
- if $4.strip.length > 0
195
- vlan[:interfaces] = $4.strip.split(/\s*,\s*/).map{ |ifn| canonicalize_ifname(ifn) }
196
- end
197
- vlans[vlan[:name]] = vlan
198
- when /^\s+([a-zA-Z0-9,\/. ]+)\s*$/
199
- raise _("invalid sh vlan summary output") unless vlan
200
- if $1.strip.length > 0
201
- vlan[:interfaces] += $1.strip.split(/\s*,\s*/).map{ |ifn| canonicalize_ifname(ifn) }
202
- end
203
- else
204
- end
205
- end
206
- vlans
207
- end
208
-
209
- def update_vlan(id, is = {}, should = {})
210
- if should[:ensure] == :absent
211
- Puppet.info _("Removing %{id} from device vlan") % { id: id }
212
- execute("conf t")
213
- execute("no vlan #{id}")
214
- execute("exit")
215
- return
216
- end
217
-
218
- # Cisco VLANs are supposed to be alphanumeric only
219
- if should[:description] =~ /[^\w]/
220
- Puppet.err _("Invalid VLAN name '%{name}' for Cisco device.\nVLAN name must be alphanumeric, no spaces or special characters.") % { name: should[:description] }
221
- return
222
- end
223
-
224
- # We're creating or updating an entry
225
- execute("conf t")
226
- execute("vlan #{id}")
227
- [is.keys, should.keys].flatten.uniq.each do |property|
228
- Puppet.debug("trying property: #{property}: #{should[property]}")
229
- next if property != :description
230
- execute("name #{should[property]}")
231
- end
232
- execute("exit")
233
- execute("exit")
234
- end
235
-
236
- def parse_trunking(interface)
237
- trunking = {}
238
- out = execute("sh interface #{interface} switchport")
239
- lines = out.split("\n")
240
- lines.shift; lines.pop
241
- lines.each do |l|
242
- case l
243
- when /^Administrative mode:\s+(.*)$/i
244
- case $1
245
- when "trunk"
246
- trunking[:mode] = :trunk
247
- when "static access"
248
- trunking[:mode] = :access
249
- when "dynamic auto"
250
- trunking[:mode] = 'dynamic auto'
251
- when "dynamic desirable"
252
- trunking[:mode] = 'dynamic desirable'
253
- else
254
- raise _("Unknown switchport mode: %{mode} for %{interface}") % { mode: $1, interface: interface }
255
- end
256
- when /^Administrative Trunking Encapsulation:\s+(.*)$/
257
- case $1
258
- when "dot1q","isl"
259
- trunking[:encapsulation] = $1.to_sym if trunking[:mode] != :access
260
- when "negotiate"
261
- trunking[:encapsulation] = :negotiate
262
- else
263
- raise _("Unknown switchport encapsulation: %{value} for %{interface}") % { value: $1, interface: interface }
264
- end
265
- when /^Access Mode VLAN:\s+(.*) \((.*)\)$/
266
- trunking[:access_vlan] = $1 if $2 != '(Inactive)'
267
- when /^Trunking Native Mode VLAN:\s+(.*) \(.*\)$/
268
- trunking[:native_vlan] = $1
269
- when /^Trunking VLANs Enabled:\s+(.*)$/
270
- next if trunking[:mode] == :access
271
- vlans = $1
272
- trunking[:allowed_trunk_vlans] = case vlans
273
- when /all/i
274
- :all
275
- when /none/i
276
- :none
277
- else
278
- vlans
279
- end
280
- end
281
- end
282
- trunking
283
- end
284
-
285
- end