vmserver 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +6 -1
- data/VERSION +1 -1
- data/lib/vmserver.rb +141 -14
- data/vmserver.gemspec +2 -2
- metadata +4 -4
data/README.textile
CHANGED
@@ -24,8 +24,13 @@ bc. vmserver.start
|
|
24
24
|
|
25
25
|
bc. vmserver.mkdir('dir')
|
26
26
|
|
27
|
+
*To create a directory in the guest OS*
|
28
|
+
|
29
|
+
bc. vmserver.mkdir('c:\test folder\vm server')
|
30
|
+
|
27
31
|
*To copy a file from Host OS to Guest OS*
|
28
32
|
|
29
33
|
bc. vmserver.copy_file_from_host_to_guest('src','dest')
|
30
34
|
|
31
|
-
*_Note_* The src and dest need to be absolute paths.
|
35
|
+
*_Note_* The src and dest need to be absolute paths.
|
36
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/vmserver.rb
CHANGED
@@ -9,7 +9,7 @@ class VMServer
|
|
9
9
|
@base_command = "vmrun -T server -h #{@host} -u #{@vm_user} -p #{@vm_password}"
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
|
13
13
|
##
|
14
14
|
# Logs if logging is enabled
|
15
15
|
|
@@ -18,33 +18,94 @@ class VMServer
|
|
18
18
|
end
|
19
19
|
|
20
20
|
|
21
|
+
# -------------------------------- Controlling Virtual Machine Power States with vmrun -------------------------
|
22
|
+
#
|
21
23
|
##
|
22
|
-
#
|
24
|
+
# Start up the Virtual Machine
|
23
25
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
26
|
+
def start
|
27
|
+
command = 'start'
|
28
|
+
vm_command = "#{@base_command} #{command} \'#{@datastore}\'"
|
29
|
+
log vm_command
|
30
|
+
result = system(vm_command)
|
31
|
+
result ? log("VM started successfully has been executed.") : log("Error! VM could not be started.")
|
32
|
+
result
|
32
33
|
end
|
33
34
|
|
34
35
|
|
35
36
|
##
|
36
|
-
#
|
37
|
+
# Stops the Virtual Machine
|
38
|
+
# Mode is soft by default.
|
39
|
+
# If it is overridden to be 'hard' it acts in a similar fashion to that pf physically switching off a machine.
|
37
40
|
|
38
|
-
def
|
39
|
-
command = '
|
41
|
+
def stop(mode='soft')
|
42
|
+
command = 'stop'
|
43
|
+
vm_command = "#{@base_command} #{command} \'#{@datastore}\' #{mode}"
|
44
|
+
log vm_command
|
45
|
+
result = system(vm_command)
|
46
|
+
result ? log("VM stopped successfully.") : log("Error! VM could not be stopped.")
|
47
|
+
result
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
##
|
52
|
+
# Reset the Virtual Machine
|
53
|
+
# Mode is soft by default.
|
54
|
+
# If it is overridden to be 'hard' it acts in a similar fashion to that pf physically switching off a machine.
|
55
|
+
|
56
|
+
def reset(mode='soft')
|
57
|
+
command = 'reset'
|
58
|
+
vm_command = "#{@base_command} #{command} \'#{@datastore}\' #{mode}"
|
59
|
+
log vm_command
|
60
|
+
result = system(vm_command)
|
61
|
+
result ? log("VM has been resetted.") : log("Error! VM could not be reset.")
|
62
|
+
result
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
##
|
67
|
+
# Suspend the Virtual Machine
|
68
|
+
# Mode is soft by default.
|
69
|
+
# If it is overridden to be 'hard' it acts in a similar fashion to that pf physically switching off a machine.
|
70
|
+
|
71
|
+
def suspend(mode='soft')
|
72
|
+
command = 'reset'
|
73
|
+
vm_command = "#{@base_command} #{command} \'#{@datastore}\' #{mode}"
|
74
|
+
log vm_command
|
75
|
+
result = system(vm_command)
|
76
|
+
result ? log("VM has been suspended.") : log("Error! VM could not be suspended.")
|
77
|
+
result
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
##
|
82
|
+
# Pause the Virtual Machine
|
83
|
+
|
84
|
+
def pause
|
85
|
+
command = 'pause'
|
40
86
|
vm_command = "#{@base_command} #{command} \'#{@datastore}\'"
|
41
87
|
log vm_command
|
42
88
|
result = system(vm_command)
|
43
|
-
result ? log("VM
|
89
|
+
result ? log("VM has been paused") : log("Error! VM could not be paused.")
|
44
90
|
result
|
45
91
|
end
|
46
92
|
|
47
93
|
|
94
|
+
##
|
95
|
+
# Pause the Virtual Machine
|
96
|
+
|
97
|
+
def unpause
|
98
|
+
command = 'unpause'
|
99
|
+
vm_command = "#{@base_command} #{command} \'#{@datastore}\'"
|
100
|
+
log vm_command
|
101
|
+
result = system(vm_command)
|
102
|
+
result ? log("VM has been unpaused") : log("Error! VM could not be unpaused.")
|
103
|
+
result
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
# -------------------------------------- Working with Files and Directory in Guest OS -------------------------
|
108
|
+
#
|
48
109
|
##
|
49
110
|
# Create a directory in the Virtual Machine
|
50
111
|
|
@@ -58,6 +119,59 @@ class VMServer
|
|
58
119
|
end
|
59
120
|
|
60
121
|
|
122
|
+
##
|
123
|
+
# Remove Directory form the Guest OS
|
124
|
+
|
125
|
+
def rmdir(dir)
|
126
|
+
command = 'deleteDirectoryInGuest'
|
127
|
+
vm_command = "#{@base_command} -gu #{@guest_user} -gp #{@guest_password} #{command} \'#{@datastore}\' \'#{dir}\'"
|
128
|
+
log vm_command
|
129
|
+
result = system(vm_command)
|
130
|
+
result ? log("Directory deleted successfully.") : log("Error! Failed to delete directory.")
|
131
|
+
result
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
##
|
136
|
+
# Remove Directory form the Guest OS
|
137
|
+
|
138
|
+
def rmfile(file)
|
139
|
+
command = 'deleteFileInGuest'
|
140
|
+
vm_command = "#{@base_command} -gu #{@guest_user} -gp #{@guest_password} #{command} \'#{@datastore}\' \'#{file}\'"
|
141
|
+
log vm_command
|
142
|
+
result = system(vm_command)
|
143
|
+
result ? log("File deleted successfully.") : log("Error! Failed to delete file.")
|
144
|
+
result
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
##
|
149
|
+
# List a directory in Guest OS
|
150
|
+
|
151
|
+
def ls(dir)
|
152
|
+
command = 'listDirectoryInGuest'
|
153
|
+
vm_command = "#{@base_command} -gu #{@guest_user} -gp #{@guest_password} #{command} \'#{@datastore}\' \'#{dir}\'"
|
154
|
+
log vm_command
|
155
|
+
result = system(vm_command)
|
156
|
+
result ? log("Listing Successful.") : log("Error! Listing directory failed.")
|
157
|
+
result
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
##
|
162
|
+
# Checks if a file exists in the guest OS
|
163
|
+
|
164
|
+
def file_exists_in_guest?(file)
|
165
|
+
vm_command = "#{@base_command} -gu #{@guest_user} -gp #{@guest_password} fileExistsInGuest \'#{datastore}\' #{file}"
|
166
|
+
output = system(vm_command)
|
167
|
+
if output =~ /The file exists/
|
168
|
+
return true
|
169
|
+
else
|
170
|
+
return false
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
|
61
175
|
##
|
62
176
|
# Copy a file from host OS to Guest OS
|
63
177
|
|
@@ -119,4 +233,17 @@ class VMServer
|
|
119
233
|
result ? log("Program executed successfully in guest.") : log("Error! Failed to execute program in guest.")
|
120
234
|
result
|
121
235
|
end
|
236
|
+
|
237
|
+
|
238
|
+
##
|
239
|
+
# Remove Directory form the Guest OS
|
240
|
+
|
241
|
+
def capture_screen(output_file)
|
242
|
+
command = 'captureScreen'
|
243
|
+
vm_command = "#{@base_command} -gu #{@guest_user} -gp #{@guest_password} #{command} \'#{@datastore}\' \'#{output_file}\'"
|
244
|
+
log vm_command
|
245
|
+
result = system(vm_command)
|
246
|
+
result ? log("File deleted successfully.") : log("Error! Failed to delete file.")
|
247
|
+
result
|
248
|
+
end
|
122
249
|
end
|
data/vmserver.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{vmserver}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Sriram Varahan"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-26}
|
13
13
|
s.description = %q{This gem simplifies the interaction of ruby code with VMServer. You need to have VMServer installed and running to use this gem.}
|
14
14
|
s.email = %q{sriram.varahan@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmserver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sriram Varahan
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-26 00:00:00 +05:30
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|