added booted?/boot methods
[strongswan.git] / src / dumm / ext / lib / dumm / guest.rb
1 =begin
2 Copyright (C) 2008 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
15 $Id$
16 =end
17
18 module Dumm
19 class Guest
20 # accessor for guests
21 # e.g. Guest.sun instead of Guest["sun"]
22 def self.method_missing(id, *args)
23 unless guest? id
24 super(id, *args)
25 end
26 Guest[id]
27 end
28
29 # accessor for interfaces
30 # e.g. guest.eth0 instead of guest["eth0"]
31 def method_missing(id, *args)
32 unless iface? id
33 super(id, *args)
34 end
35 self[id]
36 end
37
38 # delete all interfaces
39 def reset
40 each {|i|
41 i.delete
42 }
43 end
44
45 # has the guest booted up?
46 def booted?
47 begin
48 exec("pgrep getty")
49 rescue
50 return false
51 end
52 return true
53 end
54
55 # wait until the guest has booted
56 def boot
57 while not booted?
58 sleep(1)
59 end
60 end
61 end
62 end
63
64 # vim:sw=2 ts=2 et