components/puppet/files/solaris/lib/puppet/provider/ipmp_interface/solaris.rb
branchs11-update
changeset 2771 8e4227dc2fc4
child 1661 c59d67c9d1d7
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(:ipmp_interface).provide(:ipmp_interface) do
       
    27     desc "Provider for management of IPMP interfaces for Oracle Solaris"
       
    28     confine :operatingsystem => [:solaris]
       
    29     defaultfor :osfamily => :solaris, :kernelrelease => ['5.11', '5.12']
       
    30     commands :ipadm => '/usr/sbin/ipadm'
       
    31 
       
    32     def self.instances
       
    33         ifaces = []
       
    34         ipadm("show-if", "-p", "-o", "IFNAME,CLASS,OVER").split(
       
    35               "\n").each do |line|
       
    36             name, linkclass, over = line.strip().split(":", 3)
       
    37             next if linkclass != "ipmp"
       
    38             ifaces << new(:name => name.strip(),
       
    39                           :ensure => :present,
       
    40                           :interfaces => over)
       
    41         end
       
    42         ifaces
       
    43     end
       
    44         
       
    45     def self.prefetch(resources)
       
    46         # pull the instances on the system
       
    47         ifaces = instances
       
    48 
       
    49         # set the provider for the resource to set the property_hash
       
    50         resources.keys.each do |name|
       
    51             if provider = ifaces.find{ |iface| iface.name == name}
       
    52                 resources[name].provider = provider
       
    53             end
       
    54         end
       
    55     end
       
    56 
       
    57     def interfaces
       
    58         @property_hash[:interfaces]
       
    59     end
       
    60 
       
    61     def interfaces=(value)
       
    62         current = self.interfaces.split()
       
    63 
       
    64         remove_list = []
       
    65         for entry in current - value
       
    66             remove_list << "-i" << entry
       
    67         end
       
    68 
       
    69         add_list = []
       
    70         for entry in value - current
       
    71             add_list << "-i" << entry
       
    72         end
       
    73 
       
    74         if not add_list.empty?
       
    75             ipadm("add-ipmp", add_list, @resource[:name])
       
    76         end
       
    77 
       
    78         if not remove_list.empty?
       
    79             ipadm("remove-ipmp", remove_list, @resource[:name])
       
    80         end
       
    81     end
       
    82 
       
    83     def add_options
       
    84         options = []
       
    85         if @resource[:temporary] == :true
       
    86             options << "-t"
       
    87         end
       
    88         for iface in @resource[:interfaces] do
       
    89             options << "-i" << iface
       
    90         end
       
    91         options
       
    92     end
       
    93 
       
    94     def exists?
       
    95         @property_hash[:ensure] == :present
       
    96     end
       
    97 
       
    98     def create
       
    99         ipadm('create-ipmp', add_options, @resource[:name])
       
   100     end
       
   101 
       
   102     def destroy
       
   103         for iface in self.interfaces do
       
   104             ipadm("remove-ipmp", "-i", iface, @resource[:name])
       
   105         end
       
   106         ipadm('delete-ipmp', @resource[:name])
       
   107     end
       
   108 end