|
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(:ip_tunnel).provide(:ip_tunnel) do |
|
27 desc "Provider for managing Oracle Solaris IP Tunnel links" |
|
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-iptun", "-p", "-o", "link,type,local,remote").split( |
|
34 "\n").collect do |line| |
|
35 link, type, local, remote = line.split(":") |
|
36 new(:name => link, |
|
37 :ensure => :present, |
|
38 :tunnel_type => type, |
|
39 :local_address => local, |
|
40 :remote_address => remote) |
|
41 end |
|
42 end |
|
43 |
|
44 def self.prefetch(resources) |
|
45 # pull the instances on the system |
|
46 ip_tunnels = instances |
|
47 |
|
48 # set the provider for the resource to set the property_hash |
|
49 resources.keys.each do |name| |
|
50 if provider = ip_tunnels.find{ |ip_tunnel| ip_tunnel.name == name} |
|
51 resources[name].provider = provider |
|
52 end |
|
53 end |
|
54 end |
|
55 |
|
56 [:tunnel_type, :local_address, :remote_address].each do |field| |
|
57 define_method(field) do |
|
58 begin |
|
59 @property_hash[field] |
|
60 end |
|
61 end |
|
62 end |
|
63 |
|
64 def local_address=(value) |
|
65 dladm("modify-iptun", "-a", "local=#{value}", @resource[:name]) |
|
66 end |
|
67 |
|
68 def remote_address=(value) |
|
69 dladm("modify-iptun", "-a", "remote=#{value}", @resource[:name]) |
|
70 end |
|
71 |
|
72 def add_options |
|
73 options = [] |
|
74 if @resource[:temporary] == :true |
|
75 options << "-t" |
|
76 end |
|
77 |
|
78 if tunnel_type = @resource[:tunnel_type] and tunnel_type != nil |
|
79 options << "-T" << resource[:tunnel_type] |
|
80 end |
|
81 |
|
82 if local = @resource[:local_address] and local != nil |
|
83 options << "-a" << "local=#{local}" |
|
84 end |
|
85 |
|
86 if remote = @resource[:remote_address] and remote != nil |
|
87 options << "-a" << "remote=#{remote}" |
|
88 end |
|
89 options |
|
90 end |
|
91 |
|
92 def exists? |
|
93 @property_hash[:ensure] == :present |
|
94 end |
|
95 |
|
96 def create |
|
97 dladm('create-iptun', add_options, @resource[:name]) |
|
98 end |
|
99 |
|
100 def destroy |
|
101 dladm('delete-iptun', @resource[:name]) |
|
102 end |
|
103 end |