components/puppet/files/solaris/lib/puppet/provider/vni_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(:vni_interface).provide(:vni_interface) do
       
    27     desc "Provider for management of VNI 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         vnis = []
       
    34         ipadm("show-if", "-p", "-o", "IFNAME,CLASS").split(
       
    35               "\n").each do |line|
       
    36             ifname, ifclass = line.split(":", 2)
       
    37             next if ifclass != "vni"
       
    38             vnis << new(:name => ifname, :ensure => :present)
       
    39         end
       
    40         vnis
       
    41     end
       
    42 
       
    43     def add_options
       
    44        options = []
       
    45        if @resource[:temporary] == :true
       
    46          options << "-t"
       
    47        end
       
    48        options
       
    49     end
       
    50 
       
    51     def exists?
       
    52         p = exec_cmd(command(:ipadm), "show-if", "-p", "-o", "IFNAME,CLASS",
       
    53                      @resource[:name])
       
    54         if p[:exit] == 1:
       
    55             return false
       
    56         end
       
    57 
       
    58         ifname, ifclass = p[:out].strip().split(":", 2)
       
    59         if ifclass == "vni"
       
    60             return true
       
    61         end
       
    62 
       
    63         # for all other cases, return false
       
    64         return false
       
    65     end
       
    66 
       
    67     def create
       
    68         ipadm('create-vni', add_options, @resource[:name])
       
    69     end
       
    70 
       
    71     def destroy
       
    72         ipadm('delete-vni', @resource[:name])
       
    73     end
       
    74 
       
    75     def exec_cmd(*cmd)
       
    76         output = Puppet::Util::Execution.execute(cmd, :failonfail => false)
       
    77         {:out => output, :exit => $CHILD_STATUS.exitstatus}
       
    78     end
       
    79 end