bolt 0.21.1 → 0.21.2

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 (105) hide show
  1. checksums.yaml +5 -5
  2. data/lib/bolt/applicator.rb +56 -0
  3. data/lib/bolt/error.rb +6 -0
  4. data/lib/bolt/pal.rb +8 -1
  5. data/lib/bolt/transport/winrm.rb +4 -1
  6. data/lib/bolt/version.rb +1 -1
  7. data/libexec/apply_catalog.rb +61 -0
  8. data/{exe → libexec}/bolt_catalog +0 -0
  9. data/vendored/puppet/lib/puppet/application.rb +8 -1
  10. data/vendored/puppet/lib/puppet/application/device.rb +24 -28
  11. data/vendored/puppet/lib/puppet/application/doc.rb +4 -2
  12. data/vendored/puppet/lib/puppet/configurer/plugin_handler.rb +1 -2
  13. data/vendored/puppet/lib/puppet/datatypes.rb +1 -1
  14. data/vendored/puppet/lib/puppet/defaults.rb +2 -6
  15. data/vendored/puppet/lib/puppet/environments.rb +4 -10
  16. data/vendored/puppet/lib/puppet/error.rb +1 -1
  17. data/vendored/puppet/lib/puppet/etc.rb +4 -5
  18. data/vendored/puppet/lib/puppet/face/config.rb +1 -1
  19. data/vendored/puppet/lib/puppet/face/module/build.rb +5 -55
  20. data/vendored/puppet/lib/puppet/face/module/generate.rb +5 -247
  21. data/vendored/puppet/lib/puppet/gettext/config.rb +28 -5
  22. data/vendored/puppet/lib/puppet/indirector/catalog/compiler.rb +5 -7
  23. data/vendored/puppet/lib/puppet/indirector/rest.rb +7 -56
  24. data/vendored/puppet/lib/puppet/indirector/terminus.rb +1 -1
  25. data/vendored/puppet/lib/puppet/interface.rb +1 -1
  26. data/vendored/puppet/lib/puppet/interface/face_collection.rb +3 -1
  27. data/vendored/puppet/lib/puppet/metatype/manager.rb +2 -2
  28. data/vendored/puppet/lib/puppet/module_tool/applications.rb +0 -1
  29. data/vendored/puppet/lib/puppet/module_tool/applications/application.rb +1 -1
  30. data/vendored/puppet/lib/puppet/network/http/connection.rb +2 -23
  31. data/vendored/puppet/lib/puppet/network/http/factory.rb +2 -6
  32. data/vendored/puppet/lib/puppet/node.rb +1 -2
  33. data/vendored/puppet/lib/puppet/node/environment.rb +5 -1
  34. data/vendored/puppet/lib/puppet/parser/functions.rb +35 -3
  35. data/vendored/puppet/lib/puppet/pops/evaluator/evaluator_impl.rb +12 -0
  36. data/vendored/puppet/lib/puppet/pops/loader/static_loader.rb +0 -5
  37. data/vendored/puppet/lib/puppet/pops/model/ast.rb +107 -0
  38. data/vendored/puppet/lib/puppet/pops/model/factory.rb +11 -0
  39. data/vendored/puppet/lib/puppet/pops/model/model_label_provider.rb +2 -0
  40. data/vendored/puppet/lib/puppet/pops/parser/eparser.rb +1519 -1485
  41. data/vendored/puppet/lib/puppet/pops/parser/lexer2.rb +1 -1
  42. data/vendored/puppet/lib/puppet/pops/puppet_stack.rb +1 -1
  43. data/vendored/puppet/lib/puppet/pops/serialization/to_data_converter.rb +1 -1
  44. data/vendored/puppet/lib/puppet/pops/types/p_binary_type.rb +1 -2
  45. data/vendored/puppet/lib/puppet/pops/types/types.rb +1 -24
  46. data/vendored/puppet/lib/puppet/pops/validation/checker4_0.rb +5 -0
  47. data/vendored/puppet/lib/puppet/pops/validation/tasks_checker.rb +31 -4
  48. data/vendored/puppet/lib/puppet/provider.rb +12 -1
  49. data/vendored/puppet/lib/puppet/provider/package/dnf.rb +2 -1
  50. data/vendored/puppet/lib/puppet/provider/selmodule/semodule.rb +1 -1
  51. data/vendored/puppet/lib/puppet/provider/service/base.rb +1 -1
  52. data/vendored/puppet/lib/puppet/provider/service/systemd.rb +3 -1
  53. data/vendored/puppet/lib/puppet/provider/service/upstart.rb +2 -0
  54. data/vendored/puppet/lib/puppet/reference/configuration.rb +6 -0
  55. data/vendored/puppet/lib/puppet/reports.rb +2 -2
  56. data/vendored/puppet/lib/puppet/resource/status.rb +2 -0
  57. data/vendored/puppet/lib/puppet/resource/type_collection.rb +1 -1
  58. data/vendored/puppet/lib/puppet/rest/client.rb +28 -24
  59. data/vendored/puppet/lib/puppet/rest/response.rb +5 -0
  60. data/vendored/puppet/lib/puppet/rest/route.rb +13 -31
  61. data/vendored/puppet/lib/puppet/rest/routes.rb +65 -5
  62. data/vendored/puppet/lib/puppet/rest/ssl_context.rb +13 -0
  63. data/vendored/puppet/lib/puppet/settings.rb +6 -0
  64. data/vendored/puppet/lib/puppet/settings/config_file.rb +1 -2
  65. data/vendored/puppet/lib/puppet/ssl/certificate_request.rb +5 -1
  66. data/vendored/puppet/lib/puppet/ssl/host.rb +148 -43
  67. data/vendored/puppet/lib/puppet/ssl/oids.rb +1 -1
  68. data/vendored/puppet/lib/puppet/test/test_helper.rb +3 -0
  69. data/vendored/puppet/lib/puppet/transaction/event_manager.rb +3 -1
  70. data/vendored/puppet/lib/puppet/transaction/report.rb +1 -1
  71. data/vendored/puppet/lib/puppet/type.rb +2 -2
  72. data/vendored/puppet/lib/puppet/type/file/content.rb +2 -3
  73. data/vendored/puppet/lib/puppet/type/schedule.rb +33 -84
  74. data/vendored/puppet/lib/puppet/type/user.rb +1 -1
  75. data/vendored/puppet/lib/puppet/util.rb +5 -0
  76. data/vendored/puppet/lib/puppet/util/autoload.rb +39 -31
  77. data/vendored/puppet/lib/puppet/util/character_encoding.rb +0 -22
  78. data/vendored/puppet/lib/puppet/util/command_line.rb +0 -1
  79. data/vendored/puppet/lib/puppet/util/connection.rb +74 -0
  80. data/vendored/puppet/lib/puppet/util/feature.rb +2 -2
  81. data/vendored/puppet/lib/puppet/util/instance_loader.rb +1 -19
  82. data/vendored/puppet/lib/puppet/util/json.rb +0 -8
  83. data/vendored/puppet/lib/puppet/util/log/destinations.rb +1 -1
  84. data/vendored/puppet/lib/puppet/util/network_device/base.rb +1 -1
  85. data/vendored/puppet/lib/puppet/util/platform.rb +3 -0
  86. data/vendored/puppet/lib/puppet/util/rdoc/parser/puppet_parser_core.rb +1 -1
  87. data/vendored/puppet/lib/puppet/util/reference.rb +2 -2
  88. data/vendored/puppet/lib/puppet/util/rubygems.rb +1 -13
  89. data/vendored/puppet/lib/puppet/util/ssl.rb +40 -1
  90. data/vendored/puppet/lib/puppet/util/windows.rb +1 -0
  91. data/vendored/puppet/lib/puppet/util/windows/file.rb +18 -0
  92. data/vendored/puppet/lib/puppet/util/windows/security.rb +26 -14
  93. metadata +8 -73
  94. data/vendored/puppet/lib/puppet/module_tool/applications/builder.rb +0 -152
  95. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/spec/spec_helper.rb +0 -1
  96. data/vendored/puppet/lib/puppet/provider/mailalias/aliases.rb +0 -50
  97. data/vendored/puppet/lib/puppet/provider/maillist/mailman.rb +0 -108
  98. data/vendored/puppet/lib/puppet/provider/zfs/zfs.rb +0 -108
  99. data/vendored/puppet/lib/puppet/provider/zone/solaris.rb +0 -364
  100. data/vendored/puppet/lib/puppet/provider/zpool/zpool.rb +0 -125
  101. data/vendored/puppet/lib/puppet/type/mailalias.rb +0 -46
  102. data/vendored/puppet/lib/puppet/type/maillist.rb +0 -62
  103. data/vendored/puppet/lib/puppet/type/zfs.rb +0 -154
  104. data/vendored/puppet/lib/puppet/type/zone.rb +0 -382
  105. data/vendored/puppet/lib/puppet/type/zpool.rb +0 -91
@@ -1,152 +0,0 @@
1
- require 'fileutils'
2
- require 'puppet/util/json'
3
- require 'puppet/file_system'
4
- require 'pathspec'
5
- require 'facter'
6
-
7
- module Puppet::ModuleTool
8
- module Applications
9
- class Builder < Application
10
-
11
- def initialize(path, options = {})
12
- @path = File.expand_path(path)
13
- @pkg_path = File.join(@path, 'pkg')
14
- super(options)
15
- end
16
-
17
- def run
18
- # Disallow anything that invokes md5 to avoid un-friendly termination due to FIPS
19
- raise _("Module building is prohibited in FIPS mode.") if Facter.value(:fips_enabled)
20
-
21
- load_metadata!
22
- create_directory
23
- copy_contents
24
- write_json
25
- Puppet.notice _("Building %{path} for release") % { path: @path }
26
- pack
27
- relative = Pathname.new(archive_file).relative_path_from(Pathname.new(File.expand_path(Dir.pwd)))
28
-
29
- # Return the Pathname object representing the path to the release
30
- # archive just created. This return value is used by the module_tool
31
- # face build action, and displayed to on the console using the to_s
32
- # method.
33
- #
34
- # Example return value:
35
- #
36
- # <Pathname:puppetlabs-apache/pkg/puppetlabs-apache-0.0.1.tar.gz>
37
- #
38
- relative
39
- end
40
-
41
- private
42
-
43
- def archive_file
44
- File.join(@pkg_path, "#{metadata.release_name}.tar.gz")
45
- end
46
-
47
- def pack
48
- FileUtils.rm archive_file rescue nil
49
-
50
- tar = Puppet::ModuleTool::Tar.instance
51
- Dir.chdir(@pkg_path) do
52
- tar.pack(metadata.release_name, archive_file)
53
- end
54
- end
55
-
56
- def create_directory
57
- FileUtils.mkdir(@pkg_path) rescue nil
58
- if File.directory?(build_path)
59
- FileUtils.rm_rf(build_path, :secure => true)
60
- end
61
- FileUtils.mkdir(build_path)
62
- end
63
-
64
- def ignored_files
65
- if @ignored_files
66
- return @ignored_files
67
- else
68
- pmtignore = File.join(@path, '.pmtignore')
69
- gitignore = File.join(@path, '.gitignore')
70
-
71
- if File.file? pmtignore
72
- @ignored_files = PathSpec.new Puppet::FileSystem.read(pmtignore, :encoding => 'utf-8')
73
- elsif File.file? gitignore
74
- @ignored_files = PathSpec.new Puppet::FileSystem.read(gitignore, :encoding => 'utf-8')
75
- else
76
- @ignored_files = PathSpec.new
77
- end
78
- end
79
- end
80
-
81
- def copy_contents
82
- symlinks = []
83
- Find.find(File.join(@path)) do |path|
84
- # because Find.find finds the path itself
85
- if path == @path
86
- next
87
- end
88
-
89
- # Needed because pathspec looks for a trailing slash in the path to
90
- # determine if a path is a directory
91
- path = path.to_s + '/' if File.directory? path
92
-
93
- # if it matches, then prune it with fire
94
- unless ignored_files.match_paths([path], @path).empty?
95
- Find.prune
96
- end
97
-
98
- # don't copy all the Puppet ARTIFACTS
99
- rel = Pathname.new(path).relative_path_from(Pathname.new(@path))
100
- case rel.to_s
101
- when *Puppet::ModuleTool::ARTIFACTS
102
- Find.prune
103
- end
104
-
105
- # make dir tree, copy files, and add symlinks to the symlinks list
106
- dest = "#{build_path}/#{rel.to_s}"
107
- if File.directory? path
108
- FileUtils.mkdir dest, :mode => File.stat(path).mode
109
- elsif Puppet::FileSystem.symlink? path
110
- symlinks << path
111
- else
112
- FileUtils.cp path, dest, :preserve => true
113
- end
114
- end
115
-
116
- # send a message about each symlink and raise an error if they exist
117
- unless symlinks.empty?
118
- symlinks.each do |s|
119
- s = Pathname.new s
120
- mpath = Pathname.new @path
121
- Puppet.warning _("Symlinks in modules are unsupported. Please investigate symlink %{from} -> %{to}.") % { from: s.relative_path_from(mpath), to: s.realpath.relative_path_from(mpath) }
122
- end
123
-
124
- raise Puppet::ModuleTool::Errors::ModuleToolError, _("Found symlinks. Symlinks in modules are not allowed, please remove them.")
125
- end
126
- end
127
-
128
- def write_json
129
- metadata_path = File.join(build_path, 'metadata.json')
130
-
131
- if metadata.to_hash.include? 'checksums'
132
- Puppet.warning _("A 'checksums' field was found in metadata.json. This field will be ignored and can safely be removed.")
133
- end
134
-
135
- # TODO: This may necessarily change the order in which the metadata.json
136
- # file is packaged from what was written by the user. This is a
137
- # regretable, but required for now.
138
- Puppet::FileSystem.open(metadata_path, nil, 'w:UTF-8') do |f|
139
- f.write(metadata.to_json)
140
- end
141
-
142
- Puppet::FileSystem.open(File.join(build_path, 'checksums.json'), nil, 'wb') do |f|
143
- f.write(Puppet::Util::Json.dump(Checksums.new(build_path), :pretty => true))
144
- end
145
- end
146
-
147
- def build_path
148
- @build_path ||= File.join(@pkg_path, metadata.release_name)
149
- end
150
- end
151
- end
152
- end
@@ -1 +0,0 @@
1
- require 'puppetlabs_spec_helper/module_spec_helper'
@@ -1,50 +0,0 @@
1
- require 'puppet/provider/parsedfile'
2
-
3
- Puppet::Type.type(:mailalias).provide(
4
- :aliases,
5
- :parent => Puppet::Provider::ParsedFile,
6
- :default_target => "/etc/aliases",
7
- :filetype => :flat
8
- ) do
9
- text_line :comment, :match => /^#/
10
- text_line :blank, :match => /^\s*$/
11
-
12
- record_line :aliases, :fields => %w{name recipient}, :separator => /\s*:\s*/, :block_eval => :instance do
13
- def post_parse(record)
14
- if record[:recipient]
15
- record[:recipient] = record[:recipient].split(/\s*,\s*/).collect { |d| d.gsub(/^['"]|['"]$/, '') }
16
- end
17
- record
18
- end
19
-
20
- def process(line)
21
- ret = {}
22
- records = line.split(':',4)
23
- ret[:name] = records[0].strip
24
- if records.length == 4 and records[2].strip == 'include'
25
- ret[:file] = records[3].strip
26
- else
27
- records = line.split(':',2)
28
- ret[:recipient] = records[1].strip
29
- end
30
- ret
31
- end
32
-
33
- def to_line(record)
34
- if record[:recipient]
35
- dest = record[:recipient].collect do |d|
36
- # Quote aliases that have non-alpha chars
37
- if d =~ /[^-+\w@.]/
38
- '"%s"' % d
39
- else
40
- d
41
- end
42
- end.join(",")
43
- "#{record[:name]}: #{dest}"
44
- elsif record[:file]
45
- "#{record[:name]}: :include: #{record[:file]}"
46
- end
47
- end
48
- end
49
- end
50
-
@@ -1,108 +0,0 @@
1
- require 'puppet/provider/parsedfile'
2
-
3
- Puppet::Type.type(:maillist).provide(:mailman) do
4
- if [ "CentOS", "RedHat", "Fedora" ].any? { |os| Facter.value(:operatingsystem) == os }
5
- commands :list_lists => "/usr/lib/mailman/bin/list_lists", :rmlist => "/usr/lib/mailman/bin/rmlist", :newlist => "/usr/lib/mailman/bin/newlist"
6
- commands :mailman => "/usr/lib/mailman/mail/mailman"
7
- else
8
- # This probably won't work for non-Debian installs, but this path is sure not to be in the PATH.
9
- commands :list_lists => "list_lists", :rmlist => "rmlist", :newlist => "newlist"
10
- commands :mailman => "/var/lib/mailman/mail/mailman"
11
- end
12
-
13
- mk_resource_methods
14
-
15
- # Return a list of existing mailman instances.
16
- def self.instances
17
- list_lists('--bare').
18
- split("\n").
19
- collect { |line| new(:ensure => :present, :name => line.strip) }
20
- end
21
-
22
- # Prefetch our list list, yo.
23
- def self.prefetch(lists)
24
- instances.each do |prov|
25
- if list = lists[prov.name] || lists[prov.name.downcase]
26
- list.provider = prov
27
- end
28
- end
29
- end
30
-
31
- def aliases
32
- mailman = self.class.command(:mailman)
33
- name = self.name.downcase
34
- aliases = {name => "| #{mailman} post #{name}"}
35
- %w{admin bounces confirm join leave owner request subscribe unsubscribe}.each do |address|
36
- aliases["#{name}-#{address}"] = "| #{mailman} #{address} #{name}"
37
- end
38
- aliases
39
- end
40
-
41
- # Create the list.
42
- def create
43
- args = []
44
- if val = @resource[:mailserver]
45
- args << "--emailhost" << val
46
- end
47
- if val = @resource[:webserver]
48
- args << "--urlhost" << val
49
- end
50
-
51
- args << self.name
52
- if val = @resource[:admin]
53
- args << val
54
- else
55
- raise ArgumentError, _("Mailman lists require an administrator email address")
56
- end
57
- if val = @resource[:password]
58
- args << val
59
- else
60
- raise ArgumentError, _("Mailman lists require an administrator password")
61
- end
62
- newlist(*args)
63
- end
64
-
65
- # Delete the list.
66
- def destroy(purge = false)
67
- args = []
68
- args << "--archives" if purge
69
- args << self.name
70
- rmlist(*args)
71
- end
72
-
73
- # Does our list exist already?
74
- def exists?
75
- properties[:ensure] != :absent
76
- end
77
-
78
- # Clear out the cached values.
79
- def flush
80
- @property_hash.clear
81
- end
82
-
83
- # Look up the current status.
84
- def properties
85
- if @property_hash.empty?
86
- @property_hash = query || {:ensure => :absent}
87
- @property_hash[:ensure] = :absent if @property_hash.empty?
88
- end
89
- @property_hash.dup
90
- end
91
-
92
- # Remove the list and its archives.
93
- def purge
94
- destroy(true)
95
- end
96
-
97
- # Pull the current state of the list from the full list. We're
98
- # getting some double entendre here....
99
- def query
100
- self.class.instances.each do |list|
101
- if list.name == self.name or list.name.downcase == self.name
102
- return list.properties
103
- end
104
- end
105
- nil
106
- end
107
- end
108
-
@@ -1,108 +0,0 @@
1
- Puppet::Type.type(:zfs).provide(:zfs) do
2
- desc "Provider for zfs."
3
-
4
- commands :zfs => 'zfs'
5
-
6
- def self.instances
7
- zfs(:list, '-H').split("\n").collect do |line|
8
- name, _used, _avail, _refer, _mountpoint = line.split(/\s+/)
9
- new({:name => name, :ensure => :present})
10
- end
11
- end
12
-
13
- def add_properties
14
- properties = []
15
- Puppet::Type.type(:zfs).validproperties.each do |property|
16
- next if property == :ensure
17
- if value = @resource[property] and value != ""
18
- if property == :volsize
19
- properties << "-V" << "#{value}"
20
- else
21
- properties << "-o" << "#{property}=#{value}"
22
- end
23
- end
24
- end
25
- properties
26
- end
27
-
28
- def create
29
- zfs(*([:create] + add_properties + [@resource[:name]]))
30
- end
31
-
32
- def destroy
33
- zfs(:destroy, @resource[:name])
34
- end
35
-
36
- def exists?
37
- begin
38
- zfs(:list, @resource[:name])
39
- true
40
- rescue Puppet::ExecutionFailure
41
- false
42
- end
43
- end
44
-
45
- # On FreeBSD zoned is called jailed
46
- def container_property
47
- case Facter.value(:operatingsystem)
48
- when "FreeBSD"
49
- :jailed
50
- else
51
- :zoned
52
- end
53
- end
54
-
55
- PARAMETER_UNSET_OR_NOT_AVAILABLE = '-'
56
-
57
- # https://docs.oracle.com/cd/E19963-01/html/821-1448/gbscy.html
58
- # shareiscsi (added in build 120) was removed from S11 build 136
59
- # aclmode was removed from S11 in build 139 but it may have been added back
60
- # acltype is for ZFS on Linux, and allows disabling or enabling POSIX ACLs
61
- # http://webcache.googleusercontent.com/search?q=cache:-p74K0DVsdwJ:developers.slashdot.org/story/11/11/09/2343258/solaris-11-released+&cd=13
62
- [:aclmode, :acltype, :shareiscsi].each do |field|
63
- # The zfs commands use the property value '-' to indicate that the
64
- # property is not set. We make use of this value to indicate that the
65
- # property is not set since it is not available. Conversely, if these
66
- # properties are attempted to be unset, and resulted in an error, our
67
- # best bet is to catch the exception and continue.
68
- define_method(field) do
69
- begin
70
- zfs(:get, "-H", "-o", "value", field, @resource[:name]).strip
71
- rescue
72
- PARAMETER_UNSET_OR_NOT_AVAILABLE
73
- end
74
- end
75
- define_method(field.to_s + "=") do |should|
76
- begin
77
- zfs(:set, "#{field}=#{should}", @resource[:name])
78
- rescue
79
- end
80
- end
81
- end
82
-
83
- [:aclinherit, :atime, :canmount, :checksum,
84
- :compression, :copies, :dedup, :devices, :exec, :logbias,
85
- :mountpoint, :nbmand, :primarycache, :quota, :readonly,
86
- :recordsize, :refquota, :refreservation, :reservation,
87
- :secondarycache, :setuid, :sharenfs, :sharesmb,
88
- :snapdir, :version, :volsize, :vscan, :xattr].each do |field|
89
- define_method(field) do
90
- zfs(:get, "-H", "-o", "value", field, @resource[:name]).strip
91
- end
92
-
93
- define_method(field.to_s + "=") do |should|
94
- zfs(:set, "#{field}=#{should}", @resource[:name])
95
- end
96
- end
97
-
98
-
99
- define_method(:zoned) do
100
- zfs(:get, "-H", "-o", "value", container_property, @resource[:name]).strip
101
- end
102
-
103
- define_method("zoned=") do |should|
104
- zfs(:set, "#{container_property}=#{should}", @resource[:name])
105
- end
106
-
107
- end
108
-
@@ -1,364 +0,0 @@
1
- Puppet::Type.type(:zone).provide(:solaris) do
2
- desc "Provider for Solaris Zones."
3
-
4
- commands :adm => "/usr/sbin/zoneadm", :cfg => "/usr/sbin/zonecfg"
5
- defaultfor :osfamily => :solaris
6
-
7
- mk_resource_methods
8
-
9
- # Convert the output of a list into a hash
10
- def self.line2hash(line)
11
- fields = [:id, :name, :ensure, :path, :uuid, :brand, :iptype]
12
- properties = Hash[fields.zip(line.split(':'))]
13
-
14
- del_id = [:brand, :uuid]
15
- # Configured but not installed zones do not have IDs
16
- del_id << :id if properties[:id] == "-"
17
- del_id.each { |p| properties.delete(p) }
18
-
19
- properties[:ensure] = properties[:ensure].intern
20
- properties[:iptype] = 'exclusive' if properties[:iptype] == 'excl'
21
-
22
- properties
23
- end
24
-
25
- def self.instances
26
- adm(:list, "-cp").split("\n").collect do |line|
27
- new(line2hash(line))
28
- end
29
- end
30
-
31
- def multi_conf(name, should, &action)
32
- has = properties[name]
33
- has = [] if !has || has == :absent
34
- rms = has - should
35
- adds = should - has
36
- (rms.map{|o| action.call(:rm,o)} + adds.map{|o| action.call(:add,o)}).join("\n")
37
- end
38
-
39
- def self.def_prop(var, str)
40
- define_method('%s_conf' % var.to_s) do |v|
41
- str % v
42
- end
43
- define_method('%s=' % var.to_s) do |v|
44
- setconfig self.send( ('%s_conf'% var).intern, v)
45
- end
46
- end
47
-
48
- def self.def_multiprop(var, &conf)
49
- define_method(var.to_s) do |v|
50
- o = properties[var]
51
- return '' if o.nil? or o == :absent
52
- o.join(' ')
53
- end
54
- define_method('%s=' % var.to_s) do |v|
55
- setconfig self.send( ('%s_conf'% var).intern, v)
56
- end
57
- define_method('%s_conf' % var.to_s) do |v|
58
- multi_conf(var, v, &conf)
59
- end
60
- end
61
-
62
- def_prop :iptype, "set ip-type=%s"
63
- def_prop :autoboot, "set autoboot=%s"
64
- def_prop :path, "set zonepath=%s"
65
- def_prop :pool, "set pool=%s"
66
- def_prop :shares, "add rctl\nset name=zone.cpu-shares\nadd value (priv=privileged,limit=%s,action=none)\nend"
67
-
68
- def_multiprop :ip do |action, str|
69
- interface, ip, defrouter = str.split(':')
70
- case action
71
- when :add
72
- cmd = ["add net"]
73
- cmd << "set physical=#{interface}" if interface
74
- cmd << "set address=#{ip}" if ip
75
- cmd << "set defrouter=#{defrouter}" if defrouter
76
- cmd << "end"
77
- cmd.join("\n")
78
- when :rm
79
- if ip
80
- "remove net address=#{ip}"
81
- elsif interface
82
- "remove net physical=#{interface}"
83
- else
84
- raise ArgumentError, _("can not remove network based on default router")
85
- end
86
- else self.fail action
87
- end
88
- end
89
-
90
- def_multiprop :dataset do |action, str|
91
- case action
92
- when :add; ['add dataset',"set name=#{str}",'end'].join("\n")
93
- when :rm; "remove dataset name=#{str}"
94
- else self.fail action
95
- end
96
- end
97
-
98
- def_multiprop :inherit do |action, str|
99
- case action
100
- when :add; ['add inherit-pkg-dir', "set dir=#{str}",'end'].join("\n")
101
- when :rm; "remove inherit-pkg-dir dir=#{str}"
102
- else self.fail action
103
- end
104
- end
105
-
106
- def my_properties
107
- [:path, :iptype, :autoboot, :pool, :shares, :ip, :dataset, :inherit]
108
- end
109
-
110
- # Perform all of our configuration steps.
111
- def configure
112
- self.fail "Path is required" unless @resource[:path]
113
- arr = ["create -b #{@resource[:create_args]}"]
114
-
115
- # Then perform all of our configuration steps. It's annoying
116
- # that we need this much internal info on the resource.
117
- self.resource.properties.each do |property|
118
- next unless my_properties.include? property.name
119
- method = (property.name.to_s + '_conf').intern
120
- arr << self.send(method ,@resource[property.name]) unless property.safe_insync?(properties[property.name])
121
- end
122
- setconfig(arr.join("\n"))
123
- end
124
-
125
- def destroy
126
- zonecfg :delete, "-F"
127
- end
128
-
129
- def add_cmd(cmd)
130
- @cmds = [] if @cmds.nil?
131
- @cmds << cmd
132
- end
133
-
134
- def exists?
135
- properties[:ensure] != :absent
136
- end
137
-
138
- # We cannot use the execpipe in util because the pipe is not opened in
139
- # read/write mode.
140
- def exec_cmd(var)
141
- # In bash, the exit value of the last command is the exit value of the
142
- # entire pipeline
143
- out = execute("echo \"#{var[:input]}\" | #{var[:cmd]}", :failonfail => false, :combine => true)
144
- st = $?.exitstatus
145
- {:out => out, :exit => st}
146
- end
147
-
148
- # Clear out the cached values.
149
- def flush
150
- return if @cmds.nil? || @cmds.empty?
151
- str = (@cmds << "commit" << "exit").join("\n")
152
- @cmds = []
153
- @property_hash.clear
154
-
155
- command = "#{command(:cfg)} -z #{@resource[:name]} -f -"
156
- r = exec_cmd(:cmd => command, :input => str)
157
- if r[:exit] != 0 or r[:out] =~ /not allowed/
158
- raise ArgumentError, _("Failed to apply configuration")
159
- end
160
- end
161
-
162
- def install
163
- if @resource[:clone] # TODO: add support for "-s snapshot"
164
- zoneadm :clone, @resource[:clone]
165
- elsif @resource[:install_args]
166
- zoneadm :install, @resource[:install_args].split(" ")
167
- else
168
- zoneadm :install
169
- end
170
- end
171
-
172
- # Look up the current status.
173
- def properties
174
- if @property_hash.empty?
175
- @property_hash = status || {}
176
- if @property_hash.empty?
177
- @property_hash[:ensure] = :absent
178
- else
179
- @resource.class.validproperties.each do |name|
180
- @property_hash[name] ||= :absent
181
- end
182
- end
183
- end
184
- @property_hash.dup
185
- end
186
-
187
- # We need a way to test whether a zone is in process. Our 'ensure'
188
- # property models the static states, but we need to handle the temporary ones.
189
- def processing?
190
- hash = status
191
- return false unless hash
192
- ["incomplete", "ready", "shutting_down"].include? hash[:ensure]
193
- end
194
-
195
- # Collect the configuration of the zone. The output looks like:
196
- # zonename: z1
197
- # zonepath: /export/z1
198
- # brand: native
199
- # autoboot: true
200
- # bootargs:
201
- # pool:
202
- # limitpriv:
203
- # scheduling-class:
204
- # ip-type: shared
205
- # hostid:
206
- # net:
207
- # address: 192.168.1.1
208
- # physical: eg0001
209
- # defrouter not specified
210
- # net:
211
- # address: 192.168.1.3
212
- # physical: eg0002
213
- # defrouter not specified
214
- #
215
- def getconfig
216
- output = zonecfg :info
217
-
218
- name = nil
219
- current = nil
220
- hash = {}
221
- output.split("\n").each do |line|
222
- case line
223
- when /^(\S+):\s*$/
224
- name = $1
225
- current = nil # reset it
226
- when /^(\S+):\s*(\S+)$/
227
- hash[$1.intern] = $2
228
- when /^\s+(\S+):\s*(.+)$/
229
- if name
230
- hash[name] ||= []
231
- unless current
232
- current = {}
233
- hash[name] << current
234
- end
235
- current[$1.intern] = $2
236
- else
237
- err "Ignoring '#{line}'"
238
- end
239
- else
240
- debug "Ignoring zone output '#{line}'"
241
- end
242
- end
243
-
244
- hash
245
- end
246
-
247
- # Execute a configuration string. Can't be private because it's called
248
- # by the properties.
249
- def setconfig(str)
250
- add_cmd str
251
- end
252
-
253
- def start
254
- # Check the sysidcfg stuff
255
- if cfg = @resource[:sysidcfg]
256
- self.fail "Path is required" unless @resource[:path]
257
- zoneetc = File.join(@resource[:path], "root", "etc")
258
- sysidcfg = File.join(zoneetc, "sysidcfg")
259
-
260
- # if the zone root isn't present "ready" the zone
261
- # which makes zoneadmd mount the zone root
262
- zoneadm :ready unless File.directory?(zoneetc)
263
-
264
- unless Puppet::FileSystem.exist?(sysidcfg)
265
- begin
266
- # For compatibility reasons use System encoding for this OS file
267
- # the manifest string is UTF-8 so this could result in conversion errors
268
- # which should propagate to users
269
- Puppet::FileSystem.open(sysidcfg, 0600, "w:#{Encoding.default_external.name}") do |f|
270
- f.puts cfg
271
- end
272
- rescue => detail
273
- puts detail.stacktrace if Puppet[:debug]
274
- raise Puppet::Error, "Could not create sysidcfg: #{detail}", detail.backtrace
275
- end
276
- end
277
- end
278
-
279
- zoneadm :boot
280
- end
281
-
282
- # Return a hash of the current status of this zone.
283
- def status
284
- begin
285
- output = adm "-z", @resource[:name], :list, "-p"
286
- rescue Puppet::ExecutionFailure
287
- return nil
288
- end
289
-
290
- main = self.class.line2hash(output.chomp)
291
-
292
- # Now add in the configuration information
293
- config_status.each do |name, value|
294
- main[name] = value
295
- end
296
-
297
- main
298
- end
299
-
300
- def ready
301
- zoneadm :ready
302
- end
303
-
304
- def stop
305
- zoneadm :halt
306
- end
307
-
308
- def unconfigure
309
- zonecfg :delete, "-F"
310
- end
311
-
312
- def uninstall
313
- zoneadm :uninstall, "-F"
314
- end
315
-
316
- private
317
-
318
- # Turn the results of getconfig into status information.
319
- def config_status
320
- config = getconfig
321
- result = {}
322
-
323
- result[:autoboot] = config[:autoboot] ? config[:autoboot].intern : :true
324
- result[:pool] = config[:pool]
325
- result[:shares] = config[:shares]
326
- if dir = config["inherit-pkg-dir"]
327
- result[:inherit] = dir.collect { |dirs| dirs[:dir] }
328
- end
329
- if datasets = config["dataset"]
330
- result[:dataset] = datasets.collect { |dataset| dataset[:name] }
331
- end
332
- result[:iptype] = config[:'ip-type'] if config[:'ip-type']
333
- if net = config["net"]
334
- result[:ip] = net.collect do |params|
335
- if params[:defrouter]
336
- "#{params[:physical]}:#{params[:address]}:#{params[:defrouter]}"
337
- elsif params[:address]
338
- "#{params[:physical]}:#{params[:address]}"
339
- else
340
- params[:physical]
341
- end
342
- end
343
- end
344
-
345
- result
346
- end
347
-
348
- def zoneadm(*cmd)
349
- adm("-z", @resource[:name], *cmd)
350
- rescue Puppet::ExecutionFailure => detail
351
- self.fail Puppet::Error, "Could not #{cmd[0]} zone: #{detail}", detail
352
- end
353
-
354
- def zonecfg(*cmd)
355
- # You apparently can't get the configuration of the global zone (strictly in solaris11)
356
- return "" if self.name == "global"
357
- begin
358
- cfg("-z", self.name, *cmd)
359
- rescue Puppet::ExecutionFailure => detail
360
- self.fail Puppet::Error, "Could not #{cmd[0]} zone: #{detail}", detail
361
- end
362
- end
363
- end
364
-