xen-ruby 0.7.1.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/system/command.rb +7 -3
- data/lib/system/exception.rb +38 -0
- data/lib/xen/instance.rb +16 -10
- data/xen-ruby.gemspec +3 -2
- metadata +5 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.2
|
data/lib/system/command.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'log/logger'
|
2
|
-
|
2
|
+
require 'system/exception'
|
3
3
|
# This class is for executing any system command. All ruby implemented system commands like ` ` or system() are
|
4
4
|
# not strong and effectivly enough.
|
5
5
|
# You have the opportunity to set a command_level, you own failure message and an expected_exit_status.
|
@@ -44,8 +44,12 @@ module System
|
|
44
44
|
|
45
45
|
def log
|
46
46
|
case @command_level
|
47
|
-
when LEVEL_WARN:
|
48
|
-
|
47
|
+
when LEVEL_WARN:
|
48
|
+
logger.warn(error_message)
|
49
|
+
raise System::Exception::WarningException.new(error_message, command, exit_status)
|
50
|
+
when LEVEL_FATAL:
|
51
|
+
logger.fatal(error_message)
|
52
|
+
raise System::Exception::CriticalException.new(error_message, command, exit_status)
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module System
|
2
|
+
module Exception
|
3
|
+
class CriticalException < ::Exception
|
4
|
+
def initialize(message, command, exit)
|
5
|
+
@message = message
|
6
|
+
@command = command
|
7
|
+
@exit = exit
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
<<EOF
|
12
|
+
#{@message}
|
13
|
+
|
14
|
+
Command (#{@command}) exiting with code #{@exit}
|
15
|
+
|
16
|
+
EOF
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class WarningException < ::Exception
|
21
|
+
def initialize(message, command, exit)
|
22
|
+
@message = message
|
23
|
+
@command = command
|
24
|
+
@exit = exit
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
<<EOF
|
29
|
+
#{@message}
|
30
|
+
|
31
|
+
Command (#{@command}) exiting with code #{@exit}
|
32
|
+
|
33
|
+
EOF
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/lib/xen/instance.rb
CHANGED
@@ -19,7 +19,7 @@ module Xen
|
|
19
19
|
|
20
20
|
# Gets all running instances on dom0
|
21
21
|
def all
|
22
|
-
get_all = System::Command.new("sudo xm list" , :command_level =>
|
22
|
+
get_all = System::Command.new("sudo xm list" , :command_level => 2)
|
23
23
|
get_all.execute
|
24
24
|
return [] unless get_all.exit_status == 0
|
25
25
|
|
@@ -30,7 +30,8 @@ module Xen
|
|
30
30
|
# ==Params:
|
31
31
|
# => +name+: Name of instance
|
32
32
|
def find_by_name(name)
|
33
|
-
find = System::Command.new("sudo xm list #{name}", :command_level => 1
|
33
|
+
find = System::Command.new("sudo xm list #{name}", :command_level => 1,
|
34
|
+
:message => "Can't find running domU with name: #{name}")
|
34
35
|
find.execute
|
35
36
|
instance_from_output(find.output.split("\n").last) if find.exit_status == 0
|
36
37
|
end
|
@@ -63,7 +64,7 @@ module Xen
|
|
63
64
|
--arch=#{attributes[:arch]} --dist=#{attributes[:dist]} --force &
|
64
65
|
cmd
|
65
66
|
|
66
|
-
create_image = System::Command.new(command, :command_level => 2)
|
67
|
+
create_image = System::Command.new(command, :command_level => 2, :message => "Can't create #{attributes[:name]} domU.")
|
67
68
|
attributes.merge(:password => password.output.strip)
|
68
69
|
create_image.execute
|
69
70
|
end
|
@@ -111,41 +112,46 @@ module Xen
|
|
111
112
|
end
|
112
113
|
|
113
114
|
def start
|
114
|
-
start = System::Command.new("sudo xm create #{name}.cfg", :command_level => 2)
|
115
|
+
start = System::Command.new("sudo xm create #{name}.cfg", :command_level => 2, :message => "Can't start #{name} domU")
|
115
116
|
start.execute
|
116
117
|
end
|
117
118
|
|
118
119
|
|
119
120
|
def reboot
|
120
|
-
reboot = System::Command.new("sudo xm reboot #{dom_id}", :command_level => 2)
|
121
|
+
reboot = System::Command.new("sudo xm reboot #{dom_id}", :command_level => 2, :message => "Can't reboot #{name} domU")
|
121
122
|
reboot.execute
|
122
123
|
end
|
123
124
|
|
124
125
|
def shutdown
|
125
|
-
shutdown = System::Command.new("sudo xm shutdown #{dom_id}", :command_level => 2)
|
126
|
+
shutdown = System::Command.new("sudo xm shutdown #{dom_id}", :command_level => 2, :message => "Can't shutdown #{name} domU")
|
126
127
|
shutdown.execute
|
127
128
|
end
|
128
129
|
|
129
130
|
def migrate(destination)
|
130
|
-
migrate = System::Command.new("sudo xm migrate --live #{name} #{destination}",
|
131
|
+
migrate = System::Command.new("sudo xm migrate --live #{name} #{destination}",
|
132
|
+
:command_level => 2,
|
133
|
+
:message => "Can't migrate #{name} domU to #{destination}")
|
131
134
|
migrate.execute
|
132
135
|
end
|
133
136
|
|
134
137
|
def destroy
|
135
|
-
destroy = System::Command.new("sudo xm destroy #{dom_id}", :command_level =>
|
138
|
+
destroy = System::Command.new("sudo xm destroy #{dom_id}", :command_level => 2,
|
139
|
+
:message => "Can't destroy #{name} domU")
|
136
140
|
destroy.execute
|
137
141
|
end
|
138
142
|
|
139
143
|
def pause
|
140
144
|
unless paused?
|
141
|
-
pause = System::Command.new("sudo xm pause #{dom_id}", :command_level => 1
|
145
|
+
pause = System::Command.new("sudo xm pause #{dom_id}", :command_level => 1,
|
146
|
+
:message => "Can't pause #{name} domU")
|
142
147
|
pause.execute
|
143
148
|
end
|
144
149
|
end
|
145
150
|
|
146
151
|
def unpause
|
147
152
|
if paused?
|
148
|
-
unpause = System::Command.new("sudo xm unpause #{dom_id}", :command_level => 1
|
153
|
+
unpause = System::Command.new("sudo xm unpause #{dom_id}", :command_level => 1,
|
154
|
+
:message => "Can't unpause #{name} domU")
|
149
155
|
unpause.execute
|
150
156
|
end
|
151
157
|
end
|
data/xen-ruby.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{xen-ruby}
|
8
|
-
s.version = "0.7.
|
8
|
+
s.version = "0.7.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Heiko Kr\303\244mer", "Clemens Kofler"]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-23}
|
13
13
|
s.description = %q{simple gem to controle xen dom0}
|
14
14
|
s.email = %q{kraemer@avarteq.de}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
"VERSION",
|
26
26
|
"lib/log/logger.rb",
|
27
27
|
"lib/system/command.rb",
|
28
|
+
"lib/system/exception.rb",
|
28
29
|
"lib/xen/instance.rb",
|
29
30
|
"lib/xen/server.rb",
|
30
31
|
"lib/xen/util.rb",
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xen-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
|
11
|
-
version: 0.7.1.1
|
9
|
+
- 2
|
10
|
+
version: 0.7.2
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- "Heiko Kr\xC3\xA4mer"
|
@@ -17,7 +16,7 @@ autorequire:
|
|
17
16
|
bindir: bin
|
18
17
|
cert_chain: []
|
19
18
|
|
20
|
-
date: 2011-05-
|
19
|
+
date: 2011-05-23 00:00:00 Z
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
23
22
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
@@ -111,6 +110,7 @@ files:
|
|
111
110
|
- VERSION
|
112
111
|
- lib/log/logger.rb
|
113
112
|
- lib/system/command.rb
|
113
|
+
- lib/system/exception.rb
|
114
114
|
- lib/xen/instance.rb
|
115
115
|
- lib/xen/server.rb
|
116
116
|
- lib/xen/util.rb
|