author | Virginia Wray <virginia.wray@oracle.com> |
Mon, 23 Sep 2013 10:03:20 -0700 | |
branch | s11-update |
changeset 2771 | 8e4227dc2fc4 |
child 2004 | 2a230bc62c46 |
permissions | -rw-r--r-- |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
1 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
2 |
# CDDL HEADER START |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
3 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
4 |
# The contents of this file are subject to the terms of the |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
5 |
# Common Development and Distribution License (the "License"). |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
6 |
# You may not use this file except in compliance with the License. |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
7 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
8 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
9 |
# or http://www.opensolaris.org/os/licensing. |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
10 |
# See the License for the specific language governing permissions |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
11 |
# and limitations under the License. |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
12 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
13 |
# When distributing Covered Code, include this CDDL HEADER in each |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
14 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
15 |
# If applicable, add the following below this CDDL HEADER, with the |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
16 |
# fields enclosed by brackets "[]" replaced with your own identifying |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
17 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
18 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
19 |
# CDDL HEADER END |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
20 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
21 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
22 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
23 |
# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
24 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
25 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
26 |
Puppet::Type.type(:vnic).provide(:vnic) do |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
27 |
desc "Provider for creating VNICs in the Solaris OS" |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
28 |
confine :operatingsystem => [:solaris] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
29 |
defaultfor :osfamily => :solaris, :kernelrelease => ['5.11', '5.12'] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
30 |
commands :dladm => '/usr/sbin/dladm' |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
31 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
32 |
def self.instances |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
33 |
dladm("show-vnic", "-p", "-o", "link,over,macaddress").split( |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
34 |
"\n").collect do |line| |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
35 |
link, over, mac = line.split(":", 3) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
36 |
new(:name => link, |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
37 |
:ensure => :present, |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
38 |
:lower_link => over, |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
39 |
:mac_address => mac.delete("\\")) # remove the escape character |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
40 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
41 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
42 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
43 |
def self.prefetch(resources) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
44 |
# pull the instances on the system |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
45 |
vnics = instances |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
46 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
47 |
# set the provider for the resource to set the property_hash |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
48 |
resources.keys.each do |name| |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
49 |
if provider = vnics.find{ |vnic| vnic.name == name} |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
50 |
resources[name].provider = provider |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
51 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
52 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
53 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
54 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
55 |
def lower_link |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
56 |
@property_hash[:lower_link] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
57 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
58 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
59 |
def lower_link=(value) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
60 |
dladm("modify-vnic", "-l", value, @resource[:name]) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
61 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
62 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
63 |
def mac_address |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
64 |
@property_hash[:mac_address] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
65 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
66 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
67 |
def mac_address=(value) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
68 |
dladm("modify-vnic", "-m", value, @resource[:name]) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
69 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
70 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
71 |
def add_options |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
72 |
options = [] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
73 |
if @resource[:temporary] == :true |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
74 |
options << "-t" |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
75 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
76 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
77 |
if @resource[:mac_address] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
78 |
options << "-m" << @resource[:mac_address] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
79 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
80 |
options |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
81 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
82 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
83 |
def exists? |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
84 |
@property_hash[:ensure] == :present |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
85 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
86 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
87 |
def create |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
88 |
dladm('create-vnic', '-l', @resource[:lower_link], add_options, |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
89 |
@resource[:name]) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
90 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
91 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
92 |
def destroy |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
93 |
dladm('delete-vnic', @resource[:name]) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
94 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
95 |
end |