|
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(:vnic).provide(:vnic) do |
|
27 desc "Provider for creating VNICs in the Solaris OS" |
|
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-vnic", "-p", "-o", "link,over,macaddress").split( |
|
34 "\n").collect do |line| |
|
35 link, over, mac = line.split(":", 3) |
|
36 new(:name => link, |
|
37 :ensure => :present, |
|
38 :lower_link => over, |
|
39 :mac_address => mac.delete("\\")) # remove the escape character |
|
40 end |
|
41 end |
|
42 |
|
43 def self.prefetch(resources) |
|
44 # pull the instances on the system |
|
45 vnics = instances |
|
46 |
|
47 # set the provider for the resource to set the property_hash |
|
48 resources.keys.each do |name| |
|
49 if provider = vnics.find{ |vnic| vnic.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-vnic", "-l", value, @resource[:name]) |
|
61 end |
|
62 |
|
63 def mac_address |
|
64 @property_hash[:mac_address] |
|
65 end |
|
66 |
|
67 def mac_address=(value) |
|
68 dladm("modify-vnic", "-m", value, @resource[:name]) |
|
69 end |
|
70 |
|
71 def add_options |
|
72 options = [] |
|
73 if @resource[:temporary] == :true |
|
74 options << "-t" |
|
75 end |
|
76 |
|
77 if @resource[:mac_address] |
|
78 options << "-m" << @resource[:mac_address] |
|
79 end |
|
80 options |
|
81 end |
|
82 |
|
83 def exists? |
|
84 @property_hash[:ensure] == :present |
|
85 end |
|
86 |
|
87 def create |
|
88 dladm('create-vnic', '-l', @resource[:lower_link], add_options, |
|
89 @resource[:name]) |
|
90 end |
|
91 |
|
92 def destroy |
|
93 dladm('delete-vnic', @resource[:name]) |
|
94 end |
|
95 end |