Exposed the mutli-overlay functionality in the ruby bindings.
[strongswan.git] / src / dumm / ext / lib / dumm / guest.rb
1 =begin
2 Copyright (C) 2008-2009 Tobias Brunner
3 Hochschule fuer Technik Rapperswil
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 for more details.
14 =end
15
16 module Dumm
17 class Guest
18 # accessor for guests
19 # e.g. Guest.sun instead of Guest["sun"]
20 def self.method_missing(id, *args)
21 unless guest? id
22 super(id, *args)
23 end
24 Guest[id]
25 end
26
27 # accessor for interfaces
28 # e.g. guest.eth0 instead of guest["eth0"]
29 def method_missing(id, *args)
30 unless iface? id
31 super(id, *args)
32 end
33 self[id]
34 end
35
36 # remove all overlays, delete all interfaces
37 def reset
38 while pop_overlay; end
39 each {|i|
40 i.delete
41 }
42 end
43
44 # has the guest booted up?
45 def booted?
46 begin
47 exec("pgrep getty")
48 rescue
49 return false
50 end
51 return true
52 end
53
54 # wait until the guest has booted
55 def boot
56 while not booted?
57 sleep(1)
58 end
59 end
60 end
61 end
62
63 # vim:sw=2 ts=2 et