components/ruby/puppet/files/solaris/lib/puppet/provider/ip_interface/solaris.rb
branchs11u2-sru
changeset 3460 5c5af6e58474
parent 3151 0dbc999aeec2
equal deleted inserted replaced
3457:6358358b4186 3460:5c5af6e58474
       
     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, 2014, Oracle and/or its affiliates. All rights reserved.
       
    24 #
       
    25 
       
    26 Puppet::Type.type(:ip_interface).provide(:ip_interface) do
       
    27     desc "Provider for management of IP interfaces for Oracle Solaris"
       
    28     confine :operatingsystem => [:solaris]
       
    29     defaultfor :osfamily => :solaris, :kernelrelease => ['5.11', '5.12']
       
    30     commands :ipadm => '/usr/sbin/ipadm', :dladm => '/usr/sbin/dladm'
       
    31 
       
    32     def self.instances
       
    33         (dladm("show-link", "-p", "-o", "link").split("\n") &
       
    34          ipadm("show-if", "-p", "-o", "ifname").split("\n")).collect do |ifname|
       
    35             new(:name => ifname,
       
    36                 :ensure => :present)
       
    37         end
       
    38     end
       
    39 
       
    40     def add_options
       
    41        options = []
       
    42        if @resource[:temporary] == :true
       
    43          options << "-t"
       
    44        end
       
    45        options
       
    46     end
       
    47 
       
    48     def exists?
       
    49         ipadm("show-if", "-p", "-o", "IFNAME").split(
       
    50               "\n").include? @resource[:name]
       
    51     end
       
    52 
       
    53     def create
       
    54         ipadm('create-ip', add_options, @resource[:name])
       
    55     end
       
    56 
       
    57     def destroy
       
    58         ipadm('delete-ip', @resource[:name])
       
    59     end
       
    60 end