components/puppet/files/solaris/lib/puppet/provider/dns/solaris.rb
branchs11-update
changeset 2771 8e4227dc2fc4
child 1417 5158e071d299
child 2928 43b3da52b84a
equal deleted inserted replaced
2767:82fe1f1d5d8d 2771:8e4227dc2fc4
       
     1 #
       
     2 # CDDL HEADER START
       
     3 #
       
     4 # The contents of this file are subject to the terms of the
       
     5 # Common Development and Distribution License (the "License").
       
     6 # You may not use this file except in compliance with the License.
       
     7 #
       
     8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
     9 # or http://www.opensolaris.org/os/licensing.
       
    10 # See the License for the specific language governing permissions
       
    11 # and limitations under the License.
       
    12 #
       
    13 # When distributing Covered Code, include this CDDL HEADER in each
       
    14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    15 # If applicable, add the following below this CDDL HEADER, with the
       
    16 # fields enclosed by brackets "[]" replaced with your own identifying
       
    17 # information: Portions Copyright [yyyy] [name of copyright owner]
       
    18 #
       
    19 # CDDL HEADER END
       
    20 #
       
    21 
       
    22 #
       
    23 # Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
       
    24 #
       
    25 
       
    26 Puppet::Type.type(:dns).provide(:dns) do
       
    27     desc "Provider for management of DNS for Oracle Solaris"
       
    28     confine :operatingsystem => [:solaris]
       
    29     defaultfor :osfamily => :solaris, :kernelrelease => ['5.11', '5.12']
       
    30     commands :svccfg => '/usr/sbin/svccfg', :svcprop => '/usr/bin/svcprop'
       
    31 
       
    32     class << self; attr_accessor :dns_fmri end
       
    33     @@dns_fmri = "svc:/network/dns/client"
       
    34 
       
    35     def self.instances
       
    36         props = {}
       
    37         svcprop("-p", "config", @@dns_fmri).split("\n").each do |line|
       
    38             fullprop, type, value = line.split(" ", 2)
       
    39             pg, prop = fullprop.split("/")
       
    40             props[prop] = value \
       
    41                 if Puppet::Type.type(:dns).validproperties.include? prop
       
    42         end
       
    43 
       
    44         props[:name] = "current"
       
    45         return Array new(props)
       
    46     end
       
    47 
       
    48     Puppet::Type.type(:dns).validproperties.each do |field|
       
    49         define_method(field) do
       
    50             begin
       
    51                 svcprop("-p", "config/" + field.to_s, @@dns_fmri).strip()
       
    52             rescue
       
    53                 # if the property isn't set, don't raise an error
       
    54                 nil
       
    55             end
       
    56         end
       
    57 
       
    58         define_method(field.to_s + "=") do |should|
       
    59             begin
       
    60                 if should.is_a? Array
       
    61                     # the first entry needs the open paren and the last entry
       
    62                     # needs the close paren
       
    63                     should[0] = "(" + should[0]
       
    64                     should[-1] = should[-1] + ")"
       
    65 
       
    66                     svccfg("-s", @@dns_fmri, "setprop",
       
    67                            "config/" + field.to_s, "=", should)
       
    68                 else
       
    69                     svccfg("-s", @@dns_fmri, "setprop",
       
    70                            "config/" + field.to_s, "=", '"' + should + '"')
       
    71                 end
       
    72                 svccfg("-s", @@dns_fmri, "refresh")
       
    73             rescue => detail
       
    74                 raise Puppet::Error,
       
    75                     "Unable to set #{field.to_s} to #{should.inspect}\n"
       
    76                     "#{detail}\n"
       
    77             end
       
    78         end
       
    79     end
       
    80 end