diff options
| author | Rein Henrichs <rein@puppetlabs.com> | 2010-04-13 16:47:16 -0700 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | a166d50c3c555a38ae13c1658b9afaefd583cfc9 (patch) | |
| tree | eccfda10f430377f539feb6b3bdbc46f9f9bed92 /lib | |
| parent | af521fade9bf64704bab00ddf5d81aa1f987fb7e (diff) | |
| download | puppet-a166d50c3c555a38ae13c1658b9afaefd583cfc9.tar.gz puppet-a166d50c3c555a38ae13c1658b9afaefd583cfc9.tar.xz puppet-a166d50c3c555a38ae13c1658b9afaefd583cfc9.zip | |
Fix for #3399 zone type should handle exclusive IP stacks
* corrected missing status
* added cloning and support for default router
* RH: Fix spec to return accurate value for @resource[:clone]
* RH: Add spec for untested install case when @resource[:clone] returns
a (non-falsy) value
Signed-off-by: Rein Henrichs <rein@puppetlabs.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/provider/zone/solaris.rb | 15 | ||||
| -rw-r--r-- | lib/puppet/type/zone.rb | 95 |
2 files changed, 80 insertions, 30 deletions
diff --git a/lib/puppet/provider/zone/solaris.rb b/lib/puppet/provider/zone/solaris.rb index b047f6984..1aaa70d47 100644 --- a/lib/puppet/provider/zone/solaris.rb +++ b/lib/puppet/provider/zone/solaris.rb @@ -65,7 +65,9 @@ Puppet::Type.type(:zone).provide(:solaris) do end def install(dummy_argument=:work_arround_for_ruby_GC_bug) - if @resource[:install_args] + if @resource[:clone] # TODO: add support for "-s snapshot" + zoneadm :clone, @resource[:clone] + elsif @resource[:install_args] zoneadm :install, @resource[:install_args].split(" ") else zoneadm :install @@ -227,8 +229,17 @@ Puppet::Type.type(:zone).provide(:solaris) do if dir = config["inherit-pkg-dir"] result[:inherit] = dir.collect { |dirs| dirs[:dir] } end + result[:iptype] = config[:"ip-type"] if net = config["net"] - result[:ip] = net.collect { |params| "%s:%s" % [params[:physical], params[:address]] } + result[:ip] = net.collect do |params| + if params[:defrouter] + "%s:%s:%s" % [params[:physical], params[:address], params[:defrouter]] + elsif params[:address] + "%s:%s" % [params[:physical], params[:address]] + else + params[:physical] + end + end end result diff --git a/lib/puppet/type/zone.rb b/lib/puppet/type/zone.rb index b8a7e9aa9..70dd3e093 100644 --- a/lib/puppet/type/zone.rb +++ b/lib/puppet/type/zone.rb @@ -173,7 +173,7 @@ Puppet::Type.newtype(:zone) do provider.send(method) else raise Puppet::DevError, "Cannot move %s from %s" % - [direction, st[:name]] + [direction, st[:name]] end end @@ -198,6 +198,13 @@ Puppet::Type.newtype(:zone) do and cannot be changed." end + newparam(:clone) do + desc "Instead of installing the zone, clone it from another zone. + If the zone root resides on a zfs file system, a snapshot will be + used to create the clone, is it redisides on ufs, a copy of the zone + will be used. The zone you clone from must not be running." + end + newproperty(:ip, :parent => ZoneMultiConfigProperty) do require 'ipaddr' @@ -205,44 +212,49 @@ Puppet::Type.newtype(:zone) do with the interface, separated by a colon, e.g.: bge0:192.168.0.1. For multiple interfaces, specify them in an array." - validate do |value| - unless value =~ /:/ - raise ArgumentError, - "IP addresses must specify the interface and the address, separated by a colon." - end - - interface, address = value.split(':') - - begin - IPAddr.new(address) - rescue ArgumentError - raise ArgumentError, "'%s' is an invalid IP address" % address - end - end - # Add an interface. def add(str) - interface, ip = ipsplit(str) - "add net -set address=#{ip} -set physical=#{interface} -end -" + interface, ip, defrouter = ipsplit(str) + cmd = "add net\n" + cmd += "set physical=#{interface}\n" if interface + cmd += "set address=#{ip}\n" if ip + cmd += "set defrouter=#{defrouter}\n" if defrouter + #if @resource[:iptype] == :shared + cmd += "end\n" end - # Convert a string into the component interface and address + # Convert a string into the component interface, address and defrouter def ipsplit(str) - interface, address = str.split(':') - return interface, address + interface, address, defrouter = str.split(':') + return interface, address, defrouter end # Remove an interface. def rm(str) - interface, ip = ipsplit(str) + interface, ip, defrouter = ipsplit(str) # Reality seems to disagree with the documentation here; the docs # specify that braces are required, but they're apparently only # required if you're specifying multiple values. - "remove net address=#{ip}" + if ip + "remove net address=#{ip}" + elsif interface + "remove net interface=#{interface}" + else + raise ArgumentError, "can not remove network based on default router" + end + end + end + + newproperty(:iptype, :parent => ZoneConfigProperty) do + desc "The IP stack type of the zone. Can either be 'shared' or 'exclusive'." + + defaultto :shared + + newvalue :shared + newvalue :exclusive + + def configtext + "set ip-type=#{self.should}" end end @@ -380,6 +392,34 @@ end end end + def validate_ip(ip, name) + begin + IPAddr.new(ip) if ip + rescue ArgumentError + self.fail "'%s' is an invalid %s" % [ip, name] + end + end + + validate do + value = self[:ip] + interface, address, defrouter = value.split(':') + if self[:iptype] == :shared + if (interface && address && defrouter.nil?) || + (interface && address && defrouter) + validate_ip(address, "IP address") + validate_ip(defrouter, "default router") + else + self.fail "ip must contain interface name and ip address separated by a \":\"" + end + else + unless interface && address.nil? && defrouter.nil? + self.fail "only interface may be specified when using exclusive IP stack: %s" % value + end + end + + self.fail "zone path is required" unless self[:path] + end + def retrieve provider.flush if hash = provider.properties() and hash[:ensure] != :absent @@ -412,4 +452,3 @@ end return prophash end end - |
