|
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(:solaris_vlan).provide(:solaris_vlan) do |
|
27 desc "Provider for creating Solaris VLANs" |
|
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-vlan", "-p", "-o", "link,over,vid").split( |
|
34 "\n").collect do |line| |
|
35 link, over, vlanid = line.split(":") |
|
36 new(:name => link, |
|
37 :ensure => :present, |
|
38 :lower_link => over, |
|
39 :vlanid => vlanid) |
|
40 end |
|
41 end |
|
42 |
|
43 def self.prefetch(resources) |
|
44 # pull the instances on the system |
|
45 vlans = instances |
|
46 |
|
47 # set the provider for the resource to set the property_hash |
|
48 resources.keys.each do |name| |
|
49 if provider = vlans.find{ |vlan| vlan.name == name} |
|
50 resources[name].provider = provider |
|
51 end |
|
52 end |
|
53 end |
|
54 |
|
55 def lower_link |
|
56 @property_hash[:lower_link] |
|
57 end |
|
58 |
|
59 def lower_link=(value) |
|
60 dladm("modify-vlan", "-l", value, @resource[:name]) |
|
61 end |
|
62 |
|
63 def vlanid |
|
64 @property_hash[:vlanid] |
|
65 end |
|
66 |
|
67 def vlanid=(value) |
|
68 dladm("modify-vlan", "-v", value, @resource[:name]) |
|
69 end |
|
70 |
|
71 def add_options |
|
72 options = [] |
|
73 if @resource[:temporary] == :true |
|
74 options << "-t" |
|
75 end |
|
76 if @resource[:ensure] == :present and @resource[:force] == :true |
|
77 options << "-f" |
|
78 end |
|
79 options |
|
80 end |
|
81 |
|
82 def exists? |
|
83 @property_hash[:ensure] == :present |
|
84 end |
|
85 |
|
86 def create |
|
87 dladm("create-vlan", add_options, "-l", @resource[:lower_link], |
|
88 "-v", @resource[:vlanid], @resource[:name]) |
|
89 end |
|
90 |
|
91 def destroy |
|
92 dladm("delete-vlan", add_options, @resource[:name]) |
|
93 end |
|
94 end |