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(:etherstub).provide(:etherstub) do |
|
27 desc "Provider for creating Solaris etherstubs" |
|
28 confine :operatingsystem => [:solaris] |
|
29 defaultfor :osfamily => :solaris, :kernelrelease => ['5.11', '5.12'] |
|
30 commands :dladm => '/usr/sbin/dladm' |
|
31 |
|
32 def self.instances |
|
33 dladm("show-etherstub", "-p", "-o", "link").split( |
|
34 "\n").collect do |line| |
|
35 link = line.strip() |
|
36 new(:name => link, :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 self.prefetch(resources) |
|
49 # pull the instances on the system |
|
50 etherstubs = instances |
|
51 |
|
52 # set the provider for the resource to set the property_hash |
|
53 resources.keys.each do |name| |
|
54 if provider = etherstubs.find{ |etherstub| etherstub.name == name} |
|
55 resources[name].provider = provider |
|
56 end |
|
57 end |
|
58 end |
|
59 |
|
60 def exists? |
|
61 @property_hash[:ensure] == :present |
|
62 end |
|
63 |
|
64 def create |
|
65 dladm("create-etherstub", add_options, @resource[:name]) |
|
66 end |
|
67 |
|
68 def destroy |
|
69 dladm("delete-etherstub", add_options, @resource[:name]) |
|
70 end |
|
71 end |
|