Skip to content

Commit e058d6a

Browse files
author
Ganesh Nalawade
committed
Added defined types apply_group
1 parent 224eeb2 commit e058d6a

26 files changed

+344
-46
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@
2626
### 2015-05-05
2727
* Add support for new JUNOS resource type "netdev_group", upgrade to version 2.0.0
2828

29-
29+
### 2015-06-30
30+
* Add support for defined type 'apply_group' and minor bug fixes

Modulefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name 'juniper-netdev_stdlib_junos'
2-
version '2.0.0'
2+
version '2.0.1'
33
source 'https://github.com/Juniper/puppet-netdev-stdlib-junos'
44
author 'Jeremy Schulman, Ganesh Nalawade, Juniper Networks'
55
license 'See LICENSE file'

NETDEV-STDLIB.md

+77
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,80 @@ node "switch1234.mycorp.com" {
142142
}
143143
144144
````
145+
146+
## netdev_stdlib_junos::apply_group
147+
148+
This defined type apply_group used for Generic configuration using
149+
puppet template resource:
150+
151+
* template_path => _Template file path used to generate JUNOS configuration on device_
152+
* active => [ true | false ]
153+
* ensure => [ present | absent ]
154+
155+
````puppet
156+
node "switch1234.mycorp.com" {
157+
158+
netdev_device { $hostname: }
159+
160+
# service variables passed in template file
161+
$services = [ [ 'ftp' ], [ 'ssh' ], [ 'telnet' ], [ 'netconf', 'ssh' ] ]
162+
163+
netdev_stdlib_junos::apply_group{ "services_group":
164+
template_path => "netdev_stdlib_junos/services.set.erb",
165+
active => true,
166+
ensure => present,
167+
}
168+
169+
# Interface variable passed in 'interface.set.erb' template file
170+
$interfaces = { 'ge-1/2/0' => {'unit' => 0, 'description' => 'to-A', 'family' => 'inet', 'address' => '10.10.10.1/30' },
171+
'ge-1/1/1' => {'unit' => 0, 'description' => 'to-B', 'family' => 'inet', 'address' => '10.10.10.5/30' },
172+
'ge-1/1/0' => {'unit' => 0, 'description' => 'to-C', 'family' => 'inet', 'address' => '10.10.10.9/30' },
173+
'ge-1/2/1' => {'unit' => 0, 'description' => 'to-D', 'family' => 'inet', 'address' => '10.21.7.1/30' }
174+
}
175+
176+
netdev_stdlib_junos::apply_group{ "interface_group":
177+
template_path => "netdev_stdlib_junos/interface.set.erb",
178+
active => true,
179+
ensure => present,
180+
}
181+
182+
# Syslog variable passed in 'syslog.text.erb' template file
183+
$syslog_names = {
184+
'messages' => [ { 'facility' => 'any', 'level' => 'critical' }, { 'facility' => 'authorization', 'level' => 'info' } ] ,
185+
'interactive-commands' => [ { 'facility' => 'interactive-commands', 'level' => 'error'} ]
186+
}
187+
188+
netdev_stdlib_junos::apply_group{ "syslog_group":
189+
template_path => "netdev_stdlib_junos/syslog.text.erb",
190+
active => true,
191+
ensure => present,
192+
}
193+
194+
195+
# Event-policy variable passed in 'event-options.xml.erb' template file
196+
$policy = {
197+
'p1' => {
198+
'events' => [ 'TEST' ],
199+
'action' => 'then',
200+
'event-script' => 'hello.slax'
201+
}
202+
}
203+
$event_script = [ 'hello.slax' ]
204+
205+
# file resource copies the file hello.slax from master to agent
206+
file { '/var/db/scripts/event/hello.slax':
207+
mode => 0644,
208+
source => "puppet:///modules/netdev_stdlib_junos/junoscripts/event/hello.slax",
209+
}
210+
211+
# Configure event policy and event script
212+
netdev_stdlib_junos::apply_group{ "event_options_group":
213+
template_path => "netdev_stdlib_junos/event-options.xml.erb",
214+
active => true,
215+
ensure => present,
216+
}
217+
218+
}
219+
220+
````
221+

README.md

+44
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,50 @@ node "myswitch1234.mycorp.com" {
4343
netdev_l2_interface { $uplink_ports:
4444
tagged_vlans => keys( $vlans )
4545
}
46+
47+
# service variables passed in template file
48+
$services = [ [ 'ftp' ], [ 'ssh' ], [ 'telnet' ], [ 'netconf', 'ssh' ] ]
49+
50+
netdev_stdlib_junos::apply_group{ "services_group":
51+
template_path => "netdev_stdlib_junos/services.set.erb",
52+
active => true,
53+
ensure => present,
54+
}
55+
56+
# Syslog variable passed in 'syslog.text.erb' template file
57+
$syslog_names = {
58+
'messages' => [ { 'facility' => 'any', 'level' => 'critical' }, { 'facility' => 'authorization', 'level' => 'info' } ] ,
59+
'interactive-commands' => [ { 'facility' => 'interactive-commands', 'level' => 'error'} ]
60+
}
61+
62+
netdev_stdlib_junos::apply_group{ "syslog_group":
63+
template_path => "netdev_stdlib_junos/syslog.text.erb",
64+
active => true,
65+
ensure => present,
66+
}
67+
68+
# Event-policy variable passed in 'event-options.xml.erb' template file
69+
$policy = {
70+
'p1' => {
71+
'events' => [ 'TEST' ],
72+
'action' => 'then',
73+
'event-script' => 'hello.slax'
74+
}
75+
}
76+
$event_script = [ 'hello.slax' ]
77+
78+
# file resource copies the file hello.slax from master to agent
79+
file { '/var/db/scripts/event/hello.slax':
80+
mode => 0644,
81+
source => "puppet:///modules/netdev_stdlib_junos/junoscripts/event/hello.slax",
82+
}
83+
84+
# Configure event policy and event script
85+
netdev_stdlib_junos::apply_group{ "event_options_group":
86+
template_path => "netdev_stdlib_junos/event-options.xml.erb",
87+
active => true,
88+
ensure => present,
89+
}
4690
}
4791
~~~~
4892

checksums.json

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
{
2-
"CHANGELOG.md": "c992f6ca85a0082a3d44735a66b1450d",
2+
"CHANGELOG.md": "6cf01e7080b101c94e307556f63ca1b4",
33
"LICENSE-JUNIPER": "1ac394e2e858b6ce915ac8fe8f4b881b",
4-
"Modulefile": "2c19318427c173725f43d8ef465466d5",
4+
"Modulefile": "9a62b3208938dbd9320d13ed2d107238",
55
"NETDEV-STDLIB.md": "0f85e3d11dffb387d8bc4168bc58e5e7",
6-
"README.md": "dff2798b9bb0a139ad5f32df45071d6d",
7-
"lib/puppet/provider/junos/junos_interface.rb": "2a277339ceabc0c2b83b46b0d39cd6b6",
6+
"README.md": "569409849a9d1df48fb496db13d8f944",
7+
"lib/puppet/provider/junos/junos_group.rb": "4caf1d1626c10e3d489c24cf4f98b66a",
8+
"lib/puppet/provider/junos/junos_interface.rb": "8506cf47a55ffe77b6f8e9582c35e14c",
89
"lib/puppet/provider/junos/junos_interface_classic.rb": "f03fbafe01e763ea75b58191e8225e77",
910
"lib/puppet/provider/junos/junos_l2_interface.rb": "5c788c613677546e3058fd27c357de42",
1011
"lib/puppet/provider/junos/junos_l2_interface_bd.rb": "39777f336925a04eb9e1407a82264c31",
11-
"lib/puppet/provider/junos/junos_l2_interface_l2ng.rb": "49a0cb7d9090a1ed1a35ef8461683048",
12+
"lib/puppet/provider/junos/junos_l2_interface_l2ng.rb": "086d5129611d2fd66b93b9a5f48233fd",
1213
"lib/puppet/provider/junos/junos_lag.rb": "6d7635b27b857c05794464335f367f1c",
1314
"lib/puppet/provider/junos/junos_netdev.rb": "fb9eb7ddf5c280befa992718d4e28a23",
14-
"lib/puppet/provider/junos/junos_netdev_device.rb": "89a367870456997a8676d6e21dd7d8d3",
15+
"lib/puppet/provider/junos/junos_netdev_device.rb": "92324ac7889d9365f46faf45d8d2aa18",
1516
"lib/puppet/provider/junos/junos_netdev_log.rb": "955d700a78b8a1af6a5c64d258cd613f",
16-
"lib/puppet/provider/junos/junos_netdev_res.rb": "5a4c1b362d8ad60cc0e83a9e85af5f69",
17-
"lib/puppet/provider/junos/junos_parent.rb": "2ecfefed6255fbe725477b3456aa3cd9",
17+
"lib/puppet/provider/junos/junos_netdev_res.rb": "1878df86d32182d8f9175a6ed59a3ac7",
18+
"lib/puppet/provider/junos/junos_parent.rb": "a1f180cac16d9d86b52b6bab02bb6a42",
1819
"lib/puppet/provider/junos/junos_vlan.rb": "10fb9d3bda7227089f81c51bce8f675a",
1920
"lib/puppet/provider/junos/junos_vlan_bd.rb": "b018caa792f87b5a12b198e4c8500b29",
2021
"lib/puppet/provider/netdev_device/junos.rb": "b3c23054b61d4b23734338c4b3e85029",
21-
"lib/puppet/provider/netdev_interface/junos.rb": "907cfe92ecdf7668a45673496b4a64f4",
22+
"lib/puppet/provider/netdev_group/junos.rb": "19f9920929daadc26b089a1aae8aa420",
23+
"lib/puppet/provider/netdev_interface/junos.rb": "747718da1c862c223fdcfeda3f9faaf5",
2224
"lib/puppet/provider/netdev_l2_interface/junos.rb": "89384f7a79c2ced11a636a48383322fb",
2325
"lib/puppet/provider/netdev_lag/junos.rb": "1866cf36ae505c66b5f8d04b2a7ced2c",
2426
"lib/puppet/provider/netdev_vlan/junos.rb": "daf2f5d5735f37102b5915aeb81d6a42",
25-
"metadata.json": "fbdf83b794017fea26e8827e52a20433"
27+
"lib/puppet/type/netdev_group.rb": "31b571ca4c0ecb7aa244924685ca1369",
28+
"metadata.json": "ba3062fa21bde77faa139c0d13f052ce",
29+
"templates/interface_set.erb": "595e1c0ac9119d24796df1406b5d52e9",
30+
"templates/interface_text.erb": "1f83b6a4e3ecc31dae451ffe10ae35e6",
31+
"templates/interface_xml.erb": "e15123e3988c0ae9cd1e2d2f97c8a351"
2632
}

examples/event-options.pp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
$policy = {
2+
'p1' => {
3+
'events' => [ 'TEST' ],
4+
'action' => 'then',
5+
'event-script' => 'hello.slax'
6+
}
7+
}
8+
$event_script = [ 'hello.slax' ]
9+
10+
file { '/var/db/scripts/event/hello.slax':
11+
mode => 0644,
12+
source => "puppet:///modules/netdev_stdlib_junos/junoscripts/event/hello.slax",
13+
}
14+
15+
netdev_stdlib_junos::apply_group{ "event_options_group":
16+
template_path => "netdev_stdlib_junos/event-options.xml.erb",
17+
active => true,
18+
ensure => present,
19+
}
20+

examples/interface.pp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
$interfaces = { 'ge-1/2/0' => {'unit' => 0, 'description' => 'to-A', 'family' => 'inet', 'address' => '10.10.10.1/30' },
2+
'ge-1/1/1' => {'unit' => 0, 'description' => 'to-B', 'family' => 'inet', 'address' => '10.10.10.5/30' },
3+
'ge-1/1/0' => {'unit' => 0, 'description' => 'to-C', 'family' => 'inet', 'address' => '10.10.10.9/30' },
4+
'ge-1/2/1' => {'unit' => 0, 'description' => 'to-D', 'family' => 'inet', 'address' => '10.21.7.1/30' }
5+
}
6+
7+
netdev_stdlib_junos::apply_group{ "interface_group":
8+
template_path => "netdev_stdlib_junos/interface.set.erb",
9+
active => true,
10+
ensure => present,
11+
12+
}

examples/services.pp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
$services = [ [ 'ftp' ], [ 'ssh' ], [ 'telnet' ], [ 'netconf', 'ssh' ] ]
2+
3+
netdev_stdlib_junos::apply_group{ "services_group":
4+
template_path => "netdev_stdlib_junos/services.set.erb",
5+
active => true,
6+
ensure => present,
7+
8+
}
9+

examples/site.pp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node 'myswitch1234.mycorp.com' {
2+
3+
netdev_device { $hostname:}
4+
import 'syslogs.pp'
5+
import 'interface.pp'
6+
import 'services.pp'
7+
import 'event-options.pp'
8+
}
9+
10+

examples/syslogs.pp

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
$syslog_names = {
2+
'messages' => [ { 'facility' => 'any', 'level' => 'critical' }, { 'facility' => 'authorization', 'level' => 'info' } ] ,
3+
'interactive-commands' => [ { 'facility' => 'interactive-commands', 'level' => 'error'} ]
4+
}
5+
6+
netdev_stdlib_junos::apply_group{ "syslog_group":
7+
template_path => "netdev_stdlib_junos/syslog.text.erb",
8+
active => true,
9+
ensure => present,
10+
11+
}

files/junoscripts/event/hello.slax

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version 1.0;
2+
ns junos = "http://xml.juniper.net/junos/*/junos";
3+
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
4+
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
5+
import "../import/junos.xsl";
6+
/* Define arguments */
7+
8+
match / {
9+
<event-script-results> {
10+
expr jcs:syslog("external.info", "Hello");
11+
}
12+
}
13+

lib/puppet/provider/junos/junos_group.rb

+30-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
class Puppet::Provider::Junos::Group < Puppet::Provider::Junos
4040

41-
4241
### ---------------------------------------------------------------
4342
### triggered from Provider #exists?
4443
### ---------------------------------------------------------------
@@ -112,12 +111,11 @@ def xml_change_format( xml )
112111
##### XML Resource Building
113112
##### ------------------------------------------------------------
114113

115-
# override default 'top' method to create the unit sub-interface
116-
114+
# override default 'top' method
117115
def netdev_resxml_top( xml )
118116
xml.name resource[:name]
119-
par = xml.instance_variable_get(:@parent)
120-
par['replace'] = 'replace'
117+
par = xml.instance_variable_get(:@parent)
118+
par['replace'] = 'replace' unless resource[:ensure] == :absent
121119
return xml
122120
end
123121

@@ -163,4 +161,31 @@ def config_update( name )
163161

164162
end
165163

164+
##### ------------------------------------------------------------
165+
##### Device provider methods expected by Puppet
166+
##### ------------------------------------------------------------
167+
168+
def flush
169+
## handle netdev_group attribute change
170+
if netdev_res_exists?
171+
if resource[:ensure] == :absent or
172+
resource[:active] != @ndev_res[:active]
173+
Puppet::Provider::Junos.instance_method(:flush).bind(self).call
174+
else
175+
Puppet.debug( "#{self.resource.type}:: Nothing to flush #{resource[:name]}" )
176+
end
177+
elsif resource[:ensure] == :present
178+
Puppet::Provider::Junos.instance_method(:flush).bind(self).call
179+
else
180+
Puppet.debug( "#{self.resource.type}:: Nothing to flush #{resource[:name]}" )
181+
end
182+
183+
end
184+
185+
def refresh
186+
## handle refresh event from file resource types
187+
Puppet.debug( "#{self.resource.type}: REFRESH #{resource[:name]}" )
188+
Puppet::Provider::Junos.instance_method(:flush).bind(self).call
189+
end
190+
166191
end

lib/puppet/provider/junos/junos_netdev_res.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def netdev_resxml_top
135135
xml = cfg.doc
136136
at_ele = cfg.edit_path( xml, @edit_path )
137137
Nokogiri::XML::Builder.with( at_ele ) do |dot|
138-
@pp_obj.netdev_resxml_top( dot ) unless dot
138+
@pp_obj.netdev_resxml_top( dot )
139139
end
140140
return xml
141141
end

lib/puppet/provider/junos/junos_parent.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ def flush
6868
Puppet.debug( "#{self.resource.type}:: Nothing to flush #{resource[:name]}" )
6969
end
7070
end
71-
71+
72+
def refresh
73+
Puppet.debug( "#{self.resource.type}: REFRESH #{resource[:name]}" )
74+
flush
75+
end
76+
7277
def netdev_create
7378
@@netdev ||= NetdevJunos::Device.new( resource.catalog.version )
7479
netdev_get
@@ -166,8 +171,3 @@ def netdev_resxml_new( edit_xml )
166171
end
167172

168173
end
169-
170-
171-
172-
173-

lib/puppet/provider/netdev_group/junos.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@
4242
@doc = "Junos Configuration Group"
4343
has_feature :activable
4444
confine :kernel => :JUNOS
45-
4645
### invoke class method to autogen the default property methods for both Puppet
4746
### and the netdev module. That's it, yo!
48-
47+
4948
mk_resource_methods
5049
mk_netdev_resource_methods
5150

lib/puppet/type/netdev_group.rb

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
Puppet::Type.newtype(:netdev_group) do
1717
@doc = "Network Device Group Configuration"
18+
19+
feature :refreshable, "The provider can restart the service.",
20+
:methods => [:restart]
1821

1922
ensurable
2023
feature :activable, "The ability to activate/deactive configuration"
@@ -70,5 +73,8 @@
7073
netdev.title # returns the name of the netdev_device resource
7174
end
7275

76+
def refresh
77+
provider.refresh
78+
end
7379
end
7480

0 commit comments

Comments
 (0)