virtconsole 1.0
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/bin/virtconsole +24 -0
- data/lib/version.rb +3 -0
- data/lib/virt_console.rb +23 -0
- metadata +102 -0
data/bin/virtconsole
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'nokogiri'
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$:.unshift lib unless $:.include?(lib)
|
6
|
+
require 'virt_console' unless defined?(VirtConsole)
|
7
|
+
variable_hash = {}
|
8
|
+
# quit unless our script gets two command line arguments
|
9
|
+
unless ARGV.length == 2
|
10
|
+
puts 'Incorrect usage.'
|
11
|
+
puts 'Usage: virtconsole instance-name "command line to be executed(must be in quotes)"'
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
# instance name should be the first command line arg
|
15
|
+
variable_hash[:instancename] = ARGV[0]
|
16
|
+
# the command(in quotes) should be the second command line arg
|
17
|
+
variable_hash[:command] = ARGV[1]
|
18
|
+
# use Nokogiri to gather the proper serial path
|
19
|
+
output = IO.popen("virsh dumpxml #{variable_hash[:instancename]}")
|
20
|
+
xml = Nokogiri::XML(output)
|
21
|
+
variable_hash[:path] = xml.xpath("/domain/devices/serial/source/@path")
|
22
|
+
# call the class and pass our variable data for execution
|
23
|
+
virt = VirtConsole.new(variable_hash)
|
24
|
+
virt.execute
|
data/lib/version.rb
ADDED
data/lib/virt_console.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
class VirtConsole
|
2
|
+
require 'serialport'
|
3
|
+
attr_accessor :port, :command
|
4
|
+
def initialize(hash)
|
5
|
+
@path = hash[:path]
|
6
|
+
@command = hash[:command]
|
7
|
+
end
|
8
|
+
def execute
|
9
|
+
sp = SerialPort.open("#{@path}", baud = 9600, data_bits = 8, stop_bits = 1) { |tty|
|
10
|
+
tty.sync = true
|
11
|
+
line = ""
|
12
|
+
Thread.new {
|
13
|
+
tty.write @command + "\015"
|
14
|
+
}
|
15
|
+
until line == "Execution Completed." do
|
16
|
+
line = (tty.readline.chomp!)
|
17
|
+
print "#{line}\n"
|
18
|
+
end
|
19
|
+
print "\n"
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: virtconsole
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: "1.0"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Branden Coates
|
13
|
+
- Eugene Howe
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-01-18 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: nokogiri
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: serialport
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: Provides a means to pass commands via script into the LibVirt console of an instance.
|
50
|
+
email:
|
51
|
+
- branden.c.coates@gmail.com
|
52
|
+
- eugene@xtreme-computers.net
|
53
|
+
executables:
|
54
|
+
- virtconsole
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files: []
|
58
|
+
|
59
|
+
files:
|
60
|
+
- bin/virtconsole
|
61
|
+
- lib/virt_console.rb
|
62
|
+
- lib/version.rb
|
63
|
+
has_rdoc: true
|
64
|
+
homepage: https://github.com/GearheadRed/VirtConsole
|
65
|
+
licenses: []
|
66
|
+
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 57
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 8
|
81
|
+
- 7
|
82
|
+
version: 1.8.7
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 21
|
89
|
+
segments:
|
90
|
+
- 1
|
91
|
+
- 3
|
92
|
+
- 7
|
93
|
+
version: 1.3.7
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.3.7
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: LibVirt console scriptable command executor in Ruby
|
101
|
+
test_files: []
|
102
|
+
|