opennebula-augeas 0.6.6.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,48 @@
1
+ ##
2
+ # extconf.rb: Ruby extension configuration
3
+ #
4
+ # Copyright (C) 200 Red Hat Inc.
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ # Author: Bryan Kearney <bkearney@redhat.com>
21
+ ##
22
+ require 'mkmf'
23
+
24
+ extension_name = '_augeas'
25
+
26
+ # On Darwin compile for x86_64 only and link with augeas library to avoid dyld errors.
27
+ if RbConfig::CONFIG['target_os'] =~ /darwin/
28
+ $CFLAGS = $CFLAGS.gsub(/\-arch\ i386/, '')
29
+ $LDFLAGS = $LDFLAGS.gsub(/\-arch\ i386/, '')
30
+ $LDSHARED = RbConfig::MAKEFILE_CONFIG['LDSHARED']
31
+ RbConfig::MAKEFILE_CONFIG['LDSHARED'] = $LDSHARED.gsub(/\-arch\ i386/, '')
32
+ $LIBS += "-laugeas"
33
+ end
34
+
35
+ # Use have_library rather than pkg_config
36
+ unless have_library("augeas")
37
+ raise "libaugeas is not installed"
38
+ end
39
+
40
+ pkg_config('augeas')
41
+
42
+ unless have_library("xml2")
43
+ raise "libxml2 is not installed"
44
+ end
45
+
46
+ pkg_config('libxml-2.0')
47
+
48
+ create_makefile(extension_name)
data/lib/augeas.rb ADDED
@@ -0,0 +1,393 @@
1
+ ##
2
+ # augeas.rb: Ruby wrapper for augeas
3
+ #
4
+ # Copyright (C) 2008 Red Hat Inc.
5
+ # Copyright (C) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
6
+ #
7
+ # This library is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation; either
10
+ # version 2.1 of the License, or (at your option) any later version.
11
+ #
12
+ # This library is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with this library; if not, write to the Free Software
19
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ #
21
+ # Authors: Ionuț Arțăriși <iartarisi@suse.cz>
22
+ # Bryan Kearney <bkearney@redhat.com>
23
+ # Artem Sheremet <dot.doom@gmail.com>
24
+ ##
25
+
26
+ require "_augeas"
27
+
28
+ # Wrapper class for the augeas[http://augeas.net] library.
29
+ class Augeas
30
+ private_class_method :new
31
+
32
+ class Error < RuntimeError; end
33
+ class NoMemoryError < Error; end
34
+ class InternalError < Error; end
35
+ class InvalidPathError < Error; end
36
+ class NoMatchError < Error; end
37
+ class MultipleMatchesError < Error; end
38
+ class LensSyntaxError < Error; end
39
+ class LensNotFoundError < Error; end
40
+ class MultipleTransformsError < Error; end
41
+ class NoSpanInfoError < Error; end
42
+ class DescendantError < Error; end
43
+ class CommandExecutionError < Error; end
44
+ class InvalidArgumentError < Error; end
45
+ class InvalidLabelError < Error; end
46
+ ERRORS_HASH = Hash[{
47
+ # the cryptic error names come from the C library, we just make
48
+ # them more ruby and more human
49
+ :ENOMEM => NoMemoryError,
50
+ :EINTERNAL => InternalError,
51
+ :EPATHX => InvalidPathError,
52
+ :ENOMATCH => NoMatchError,
53
+ :EMMATCH => MultipleMatchesError,
54
+ :ESYNTAX => LensSyntaxError,
55
+ :ENOLENS => LensNotFoundError,
56
+ :EMXFM => MultipleTransformsError,
57
+ :ENOSPAN => NoSpanInfoError,
58
+ :EMVDESC => DescendantError,
59
+ :ECMDRUN => CommandExecutionError,
60
+ :EBADARG => InvalidArgumentError,
61
+ :ELABEL => InvalidLabelError,
62
+ }.map { |k, v| [(const_get(k) rescue nil), v] }].freeze
63
+
64
+ # Create a new Augeas instance and return it.
65
+ #
66
+ # Use +:root+ as the filesystem root. If +:root+ is +nil+, use the value
67
+ # of the environment variable +AUGEAS_ROOT+. If that doesn't exist
68
+ # either, use "/".
69
+ #
70
+ # +:loadpath+ is a colon-spearated list of directories that modules
71
+ # should be searched in. This is in addition to the standard load path
72
+ # and the directories in +AUGEAS_LENS_LIB+
73
+ #
74
+ # The following flags can be specified in a hash. They all default to
75
+ # false and can be enabled by setting them to true
76
+ #
77
+ # :type_check - typecheck lenses (since it can be very expensive it is
78
+ # not done by default)
79
+ #
80
+ # :no_stdinc - do not use the builtin load path for modules
81
+ #
82
+ # :no_load - do not load the tree during the initialization phase
83
+ #
84
+ # :no_modl_autoload - do not load the tree during the initialization phase
85
+ #
86
+ # :enable_span - track the span in the input nodes
87
+ #
88
+ # :save_mode can be one of :backup, :newfile, :noop as explained below.
89
+ #
90
+ # :noop - make save a no-op process, just record what would have changed
91
+ #
92
+ # :backup - keep the original file with an .augsave extension
93
+ #
94
+ # :newfile - save changes into a file with an .augnew extension and
95
+ # do not overwrite the original file.
96
+ #
97
+ # When a block is given, the Augeas instance is passed as the only
98
+ # argument into the block and closed when the block exits.
99
+ # With no block, the Augeas instance is returned.
100
+ def self.create(opts={}, &block)
101
+ # aug_flags is a bitmask in the underlying library, we add all the
102
+ # values of the flags which were set to true to the default value
103
+ # Augeas::NONE (which is 0)
104
+ aug_flags = defined?(Augeas::NO_ERR_CLOSE) ? Augeas::NO_ERR_CLOSE : Augeas::NONE
105
+
106
+ flags = {
107
+ :type_check => Augeas::TYPE_CHECK,
108
+ :no_stdinc => Augeas::NO_STDINC,
109
+ :no_load => Augeas::NO_LOAD,
110
+ :no_modl_autoload => Augeas::NO_MODL_AUTOLOAD,
111
+ :enable_span => Augeas::ENABLE_SPAN
112
+ }
113
+ save_modes = {
114
+ :backup => Augeas::SAVE_BACKUP,
115
+ :newfile => Augeas::SAVE_NEWFILE,
116
+ :noop => Augeas::SAVE_NOOP
117
+ }
118
+ opts.each_key do |key|
119
+ if flags.key? key
120
+ aug_flags |= flags[key]
121
+ elsif key == :save_mode
122
+ if save_modes[opts[:save_mode]]
123
+ aug_flags |= save_modes[opts[:save_mode]]
124
+ else
125
+ raise ArgumentError, "Invalid save mode #{opts[:save_mode]}."
126
+ end
127
+ elsif key != :root && key != :loadpath
128
+ raise ArgumentError, "Unknown argument #{key}."
129
+ end
130
+ end
131
+
132
+ aug = Augeas::open3(opts[:root], opts[:loadpath], aug_flags)
133
+
134
+ begin
135
+ aug.send(:raise_last_error)
136
+ rescue
137
+ aug.close
138
+ raise
139
+ end
140
+
141
+ if block_given?
142
+ begin
143
+ yield aug
144
+ ensure
145
+ aug.close
146
+ end
147
+ else
148
+ return aug
149
+ end
150
+ end
151
+
152
+ # Get the value associated with +path+.
153
+ def get(path)
154
+ run_command :augeas_get, path
155
+ end
156
+
157
+ # Return true if there is an entry for this path, false otherwise
158
+ def exists(path)
159
+ run_command :augeas_exists, path
160
+ end
161
+
162
+ # Set one or multiple elements to path.
163
+ # Multiple elements are mainly sensible with a path like
164
+ # .../array[last()+1], since this will append all elements.
165
+ def set(path, *values)
166
+ values.flatten.each { |v| run_command :augeas_set, path, v }
167
+ end
168
+
169
+ # Set multiple nodes in one operation. Find or create a node matching SUB
170
+ # by interpreting SUB as a path expression relative to each node matching
171
+ # BASE. If SUB is '.', the nodes matching BASE will be modified.
172
+
173
+ # +base+ the base node
174
+ # +sub+ the subtree relative to the base
175
+ # +value+ the value for the nodes
176
+ def setm(base, sub, value)
177
+ run_command :augeas_setm, base, sub, value
178
+ end
179
+
180
+ # Remove all nodes matching path expression +path+ and all their
181
+ # children.
182
+ # Raises an <tt>Augeas::InvalidPathError</tt> when the +path+ is invalid.
183
+ def rm(path)
184
+ run_command :augeas_rm, path
185
+ end
186
+
187
+ # Return an Array of all the paths that match the path expression +path+
188
+ #
189
+ # Returns an empty Array if no paths were found.
190
+ # Raises an <tt>Augeas::InvalidPathError</tt> when the +path+ is invalid.
191
+ def match(path)
192
+ run_command :augeas_match, path
193
+ end
194
+
195
+ # Create the +path+ with empty value if it doesn't exist
196
+ def touch(path)
197
+ set(path, nil) if match(path).empty?
198
+ end
199
+
200
+ # Evaluate +expr+ and set the variable +name+ to the resulting
201
+ # nodeset. The variable can be used in path expressions as $name.
202
+ # Note that +expr+ is evaluated when the variable is defined, not when
203
+ # it is used.
204
+ def defvar(name, expr)
205
+ run_command :augeas_defvar, name, expr
206
+ end
207
+
208
+ # Define the variable +name+ to the result of evaluating +expr+, which
209
+ # must be a nodeset. If no node matching +expr+ exists yet, one is
210
+ # created and +name+ will refer to it. When a node is created and
211
+ # +value+ is given, the new node's value is set to +value+.
212
+ def defnode(name, expr, value=nil)
213
+ run_command :augeas_defnode, name, expr, value
214
+ end
215
+
216
+ # Clear the +path+, i.e. make its value +nil+
217
+ def clear(path)
218
+ augeas_set(path, nil)
219
+ end
220
+
221
+ # Add a transform under <tt>/augeas/load</tt>
222
+ #
223
+ # The HASH can contain the following entries
224
+ # * <tt>:lens</tt> - the name of the lens to use
225
+ # * <tt>:name</tt> - a unique name; use the module name of the LENS
226
+ # when omitted
227
+ # * <tt>:incl</tt> - a list of glob patterns for the files to transform
228
+ # * <tt>:excl</tt> - a list of the glob patterns to remove from the
229
+ # list that matches <tt>:incl</tt>
230
+ def transform(hash)
231
+ lens = hash[:lens]
232
+ name = hash[:name]
233
+ incl = hash[:incl]
234
+ excl = hash[:excl]
235
+ raise ArgumentError, "No lens specified" unless lens
236
+ raise ArgumentError, "No files to include" unless incl
237
+ name = lens.split(".")[0].sub("@", "") unless name
238
+
239
+ xfm = "/augeas/load/#{name}/"
240
+ set(xfm + "lens", lens)
241
+ set(xfm + "incl[last()+1]", incl)
242
+ set(xfm + "excl[last()+1]", excl) if excl
243
+ end
244
+
245
+ # Clear all transforms under <tt>/augeas/load</tt>. If +load+
246
+ # is called right after this, there will be no files
247
+ # under +/files+
248
+ def clear_transforms
249
+ rm("/augeas/load/*")
250
+ end
251
+
252
+ # Write all pending changes to disk.
253
+ # Raises <tt>Augeas::CommandExecutionError</tt> if saving fails.
254
+ def save
255
+ begin
256
+ run_command :augeas_save
257
+ rescue Augeas::CommandExecutionError => e
258
+ raise e, 'Saving failed. Search the augeas tree in /augeas//error ' <<
259
+ 'for the actual errors.'
260
+ end
261
+
262
+ nil
263
+ end
264
+
265
+ def clearm(path, sub)
266
+ setm(path, sub, nil)
267
+ end
268
+
269
+ # Load files according to the transforms in /augeas/load or those
270
+ # defined via <tt>transform</tt>. A transform Foo is represented
271
+ # with a subtree /augeas/load/Foo. Underneath /augeas/load/Foo, one
272
+ # node labeled 'lens' must exist, whose value is the fully
273
+ # qualified name of a lens, for example 'Foo.lns', and multiple
274
+ # nodes 'incl' and 'excl' whose values are globs that determine
275
+ # which files are transformed by that lens. It is an error if one
276
+ # file can be processed by multiple transforms.
277
+ def load
278
+ begin
279
+ run_command :augeas_load
280
+ rescue Augeas::CommandExecutionError => e
281
+ raise e, "Loading failed. Search the augeas tree in /augeas//error"+
282
+ "for the actual errors."
283
+ end
284
+
285
+ nil
286
+ end
287
+
288
+ # Move node +src+ to +dst+. +src+ must match exactly one node in
289
+ # the tree. +dst+ must either match exactly one node in the tree,
290
+ # or may not exist yet. If +dst+ exists already, it and all its
291
+ # descendants are deleted. If +dst+ does not exist yet, it and all
292
+ # its missing ancestors are created.
293
+ #
294
+ # Raises <tt>Augeas::NoMatchError</tt> if the +src+ node does not exist
295
+ # Raises <tt>Augeas::MultipleMatchesError</tt> if there were
296
+ # multiple matches in +src+
297
+ # Raises <tt>Augeas::DescendantError</tt> if the +dst+ node is a
298
+ # descendant of the +src+ node.
299
+ def mv(src, dst)
300
+ run_command :augeas_mv, src, dst
301
+ end
302
+
303
+ # Get the filename, label and value position in the text of this node
304
+ #
305
+ # Raises <tt>Augeas::NoMatchError</tt> if the node could not be found
306
+ # Raises <tt>Augeas::NoSpanInfo</tt> if the node associated with
307
+ # +path+ doesn't belong to a file or doesn't exist
308
+ def span(path)
309
+ run_command :augeas_span, path
310
+ end
311
+
312
+ # Run one or more newline-separated commands specified by +text+,
313
+ # returns an array of [successful_commands_number, output] or
314
+ # [-2, output] in case 'quit' command has been encountered.
315
+ # Raises <tt>Augeas::CommandExecutionError</tt> if gets an invalid command
316
+ def srun(text)
317
+ run_command(:augeas_srun, text)
318
+ end
319
+
320
+ # Lookup the label associated with +path+
321
+ # Raises <tt>Augeas::NoMatchError</tt> if the +path+ node does not exist
322
+ def label(path)
323
+ run_command :augeas_label, path
324
+ end
325
+
326
+ # Rename the label of all nodes matching +path+ to +label+
327
+ # Raises <tt>Augeas::NoMatchError</tt> if the +path+ node does not exist
328
+ # Raises <tt>Augeas::InvalidLabelError</tt> if +label+ is invalid
329
+ def rename(path, label)
330
+ run_command :augeas_rename, path, label
331
+ end
332
+
333
+ # Use the value of node +node+ as a string and transform it into a tree
334
+ # using the lens +lens+ and store it in the tree at +path+,
335
+ # which will be overwritten. +path+ and +node+ are path expressions.
336
+ def text_store(lens, node, path)
337
+ run_command :augeas_text_store, lens, node, path
338
+ end
339
+
340
+ # Transform the tree at +path+ into a string lens +lens+ and store it
341
+ # in the node +node_out+, assuming the tree was initially generated using
342
+ # the value of node +node_in+. +path+, +node_in+ and +node_out+ are path expressions.
343
+ def text_retrieve(lens, node_in, path, node_out)
344
+ run_command :augeas_text_retrieve, lens, node_in, path, node_out
345
+ end
346
+
347
+ # Make +label+ a sibling of +path+ by inserting it directly before
348
+ # or after +path+.
349
+ # The boolean +before+ determines if +label+ is inserted before or
350
+ # after +path+.
351
+ def insert(path, label, before)
352
+ run_command :augeas_insert, path, label, before
353
+ end
354
+
355
+ # Set path expression context to +path+ (in /augeas/context)
356
+ def context=(path)
357
+ set('/augeas/context', path)
358
+ end
359
+
360
+ # Get path expression context (from /augeas/context)
361
+ def context
362
+ get('/augeas/context')
363
+ end
364
+
365
+ private
366
+
367
+ # Run a command and raise any errors that happen due to execution.
368
+ #
369
+ # +cmd+ name of the Augeas command to run
370
+ # +params+ parameters with which +cmd+ will be called
371
+ #
372
+ # Returns whatever the original +cmd+ returns
373
+ def run_command(cmd, *params)
374
+ result = self.send cmd, *params
375
+
376
+ raise_last_error
377
+
378
+ if result.kind_of? Integer and result < 0
379
+ # we raise CommandExecutionError here, because this is the error that
380
+ # augtool raises in this case as well
381
+ raise CommandExecutionError, "Command failed. Return code was #{result}."
382
+ end
383
+
384
+ return result
385
+ end
386
+
387
+ def raise_last_error
388
+ error_cache = error
389
+ unless error_cache[:code].zero?
390
+ raise ERRORS_HASH[error_cache[:code]], "#{error_cache[:message]} #{error_cache[:details]}"
391
+ end
392
+ end
393
+ end
@@ -0,0 +1,26 @@
1
+ root:x:0:root
2
+ bin:x:1:root,bin,daemon
3
+ daemon:x:2:root,bin,daemon
4
+ sys:x:3:root,bin,adm
5
+ adm:x:4:root,adm,daemon
6
+ tty:x:5:
7
+ disk:x:6:root
8
+ lp:x:7:daemon,lp
9
+ mem:x:8:
10
+ kmem:x:9:
11
+ wheel:x:10:root
12
+ mail:x:12:mail,postfix
13
+ uucp:x:14:uucp
14
+ man:x:15:
15
+ games:x:20:
16
+ gopher:x:30:
17
+ dip:x:40:
18
+ ftp:x:50:
19
+ lock:x:54:
20
+ nobody:x:99:
21
+ users:x:100:
22
+ floppy:x:19:
23
+ vcsa:x:69:
24
+ rpc:x:32:asfd
25
+ rpcuser:x:29:
26
+ nfsnobody:x:499:
@@ -0,0 +1,6 @@
1
+ # Do not remove the following line, or various programs
2
+ # that require network functionality will fail.
3
+ 127.0.0.1 localhost.localdomain localhost galia.watzmann.net galia
4
+ #172.31.122.254 granny.watzmann.net granny puppet
5
+ #172.31.122.1 galia.watzmann.net galia
6
+ 172.31.122.14 orange.watzmann.net orange
@@ -0,0 +1,53 @@
1
+ #
2
+ # inittab This file describes how the INIT process should set up
3
+ # the system in a certain run-level.
4
+ #
5
+ # Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
6
+ # Modified for RHS Linux by Marc Ewing and Donnie Barnes
7
+ #
8
+
9
+ # Default runlevel. The runlevels used by RHS are:
10
+ # 0 - halt (Do NOT set initdefault to this)
11
+ # 1 - Single user mode
12
+ # 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
13
+ # 3 - Full multiuser mode
14
+ # 4 - unused
15
+ # 5 - X11
16
+ # 6 - reboot (Do NOT set initdefault to this)
17
+ #
18
+ id:5:initdefault:
19
+
20
+ # System initialization.
21
+ si::sysinit:/etc/rc.d/rc.sysinit
22
+
23
+ l0:0:wait:/etc/rc.d/rc 0
24
+ l1:1:wait:/etc/rc.d/rc 1
25
+ l2:2:wait:/etc/rc.d/rc 2
26
+ l3:3:wait:/etc/rc.d/rc 3
27
+ l4:4:wait:/etc/rc.d/rc 4
28
+ l5:5:wait:/etc/rc.d/rc 5
29
+ l6:6:wait:/etc/rc.d/rc 6
30
+
31
+ # Trap CTRL-ALT-DELETE
32
+ ca::ctrlaltdel:/sbin/shutdown -t3 -r now
33
+
34
+ # When our UPS tells us power has failed, assume we have a few minutes
35
+ # of power left. Schedule a shutdown for 2 minutes from now.
36
+ # This does, of course, assume you have powerd installed and your
37
+ # UPS connected and working correctly.
38
+ pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"
39
+
40
+ # If power was restored before the shutdown kicked in, cancel it.
41
+ pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
42
+
43
+
44
+ # Run gettys in standard runlevels
45
+ 1:2345:respawn:/sbin/mingetty tty1
46
+ 2:2345:respawn:/sbin/mingetty tty2
47
+ 3:2345:respawn:/sbin/mingetty tty3
48
+ 4:2345:respawn:/sbin/mingetty tty4
49
+ 5:2345:respawn:/sbin/mingetty tty5
50
+ 6:2345:respawn:/sbin/mingetty tty6
51
+
52
+ # Run xdm in runlevel 5
53
+ x:5:respawn:/etc/X11/prefdm -nodaemon
@@ -0,0 +1,2 @@
1
+ # Used by the test_span test
2
+ Protocol 7