quickmox 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +5 -8
- data/lib/quickmox/guest.rb +21 -18
- data/lib/quickmox/guestlist.rb +5 -5
- data/lib/quickmox/host.rb +9 -39
- data/lib/quickmox/ssh_transport.rb +52 -0
- data/lib/quickmox/version.rb +1 -1
- data/lib/quickmox.rb +5 -4
- metadata +28 -45
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 51ff987bfc392ddaed3e9244f1a665ee22548ac4
|
4
|
+
data.tar.gz: 1c4307e709e15702d0ac997892bc1df33d3f4e67
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1287f3d4557a7b5526611dc3e4bf166c78af3be8f1864c43775e400dceb87e280dfc30152d192994ae9b88ef13bff86cb6b07c5f00ed394f6408f03cedee29d1
|
7
|
+
data.tar.gz: 859c576eeebdc1b538d71a2de7c6ff65058b1f324afbcfe92b6c64065d49414530708911450b8fb44860c3f22ea5b6ae0dc2c3c4ee764b7ae3c66912d62035b7
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/jkvalk/quickmox.svg?branch=master)](https://travis-ci.org/jkvalk/quickmox)
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/quickmox.svg)](http://badge.fury.io/rb/quickmox)
|
3
3
|
[![Coverage Status](https://coveralls.io/repos/jkvalk/quickmox/badge.svg?branch=master)](https://coveralls.io/r/jkvalk/quickmox?branch=master)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/jkvalk/quickmox/badges/gpa.svg)](https://codeclimate.com/github/jkvalk/quickmox)
|
4
5
|
|
5
6
|
# Quickmox
|
6
7
|
|
@@ -28,11 +29,9 @@ Or install it yourself as:
|
|
28
29
|
require 'quickmox'
|
29
30
|
include Quickmox
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
host = Host.new(hostname: hostname, username: user, password: pass).connect
|
32
|
+
host = Host.new( SSHTransport.new('hostname','username','password') )
|
33
|
+
.connect
|
34
|
+
.scan
|
36
35
|
|
37
36
|
p host.localname
|
38
37
|
p host.uptime
|
@@ -51,9 +50,7 @@ host.disconnect
|
|
51
50
|
|
52
51
|
## Development
|
53
52
|
|
54
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `
|
55
|
-
|
56
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
53
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
57
54
|
|
58
55
|
## Contributing
|
59
56
|
|
data/lib/quickmox/guest.rb
CHANGED
@@ -36,27 +36,30 @@ module Quickmox
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def scan
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
params[:onboot] = $1
|
55
|
-
elsif line =~ /(scsi|virtio|ide)[0-9]{1,3}: .*size=([0-9]{1,3}[MGTK])/
|
56
|
-
params[:disk] = $2
|
39
|
+
config_lines.each do |line|
|
40
|
+
case line
|
41
|
+
when /net0:.*=([0-9A-Fa-f:]{17}),/
|
42
|
+
params[:mac] = $1
|
43
|
+
params[:mac] = params[:mac].gsub(':', '').downcase
|
44
|
+
when /cores: ([0-9]{1,3})/
|
45
|
+
params[:cores] = $1
|
46
|
+
when /(description|name|bootdisk): (.*)/
|
47
|
+
params[$1.to_sym] = $2
|
48
|
+
when /memory: ([0-9]{1,6})/
|
49
|
+
params[:memory] = $1
|
50
|
+
when /onboot: ([0-9])/
|
51
|
+
params[:onboot] = $1
|
52
|
+
when /(scsi|virtio|ide)[0-9]{1,3}: .*size=([0-9]{1,3}[MGTK])/
|
53
|
+
params[:disk] = $2
|
57
54
|
end
|
58
55
|
end
|
59
56
|
self
|
60
57
|
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def config_lines
|
62
|
+
host.exec("qm config #{id}").split("\n")
|
63
|
+
end
|
61
64
|
end
|
62
65
|
end
|
data/lib/quickmox/guestlist.rb
CHANGED
data/lib/quickmox/host.rb
CHANGED
@@ -19,30 +19,19 @@ module Quickmox
|
|
19
19
|
:session,
|
20
20
|
:guests
|
21
21
|
|
22
|
-
def initialize(
|
23
|
-
@
|
24
|
-
@
|
25
|
-
|
22
|
+
def initialize(transport)
|
23
|
+
@session = transport
|
24
|
+
@guests = Guestlist.new
|
25
|
+
|
26
26
|
begin
|
27
|
-
@ip = Resolv.getaddress(@
|
27
|
+
@ip = Resolv.getaddress(@session.host)
|
28
28
|
rescue => e
|
29
29
|
@ip = String.new
|
30
30
|
end
|
31
|
-
@guests = Guestlist.new
|
32
31
|
end
|
33
32
|
|
34
33
|
def connect
|
35
|
-
|
36
|
-
@session = Net::SSH.start(hostname,
|
37
|
-
username,
|
38
|
-
password: password,
|
39
|
-
auth_methods: %w(password),
|
40
|
-
number_of_password_prompts: 0,
|
41
|
-
timeout: 3)
|
42
|
-
|
43
|
-
rescue => e
|
44
|
-
raise HostError, "Warning: exception while connecting to host #{hostname}: #{e}"
|
45
|
-
end
|
34
|
+
@session.connect
|
46
35
|
self
|
47
36
|
end
|
48
37
|
|
@@ -59,7 +48,7 @@ module Quickmox
|
|
59
48
|
|
60
49
|
def guestlist
|
61
50
|
list = Array.new
|
62
|
-
table =
|
51
|
+
table = session.exec!('qm list')
|
63
52
|
lines = table.split("\n")
|
64
53
|
lines.each do |line|
|
65
54
|
if line =~ /^ *([0-9]{1,4}) */
|
@@ -70,15 +59,11 @@ module Quickmox
|
|
70
59
|
end
|
71
60
|
|
72
61
|
def localname
|
73
|
-
handle_exceptions do
|
74
62
|
session.exec!('hostname').chomp
|
75
|
-
end
|
76
63
|
end
|
77
64
|
|
78
65
|
def uptime
|
79
|
-
handle_exceptions do
|
80
66
|
session.exec!('uptime').chomp
|
81
|
-
end
|
82
67
|
end
|
83
68
|
|
84
69
|
def close
|
@@ -86,33 +71,18 @@ module Quickmox
|
|
86
71
|
end
|
87
72
|
|
88
73
|
def disconnect
|
89
|
-
begin
|
90
74
|
session.close
|
91
|
-
rescue => e
|
92
|
-
raise HostError, "Warning: exception while disconnecting from host #{hostname}: #{e.to_s}"
|
93
|
-
end
|
94
75
|
end
|
95
76
|
|
96
77
|
def is_proxmox?
|
97
|
-
handle_exceptions do
|
98
78
|
output = session.exec!('qm list')
|
99
79
|
(output =~ /VMID NAME/) ? true : false
|
100
|
-
end
|
101
80
|
end
|
102
81
|
|
103
82
|
def exec(cmd)
|
104
|
-
|
105
|
-
return session.exec!(cmd).chomp
|
106
|
-
end
|
83
|
+
session.exec!(cmd).chomp
|
107
84
|
end
|
108
85
|
|
109
|
-
|
110
|
-
def handle_exceptions
|
111
|
-
begin
|
112
|
-
yield
|
113
|
-
rescue => e
|
114
|
-
raise HostError, "Exception while talking to host #{hostname}: #{e.to_s}"
|
115
|
-
end
|
116
|
-
end
|
86
|
+
|
117
87
|
end
|
118
88
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Quickmox
|
2
|
+
|
3
|
+
class SSHTransport
|
4
|
+
|
5
|
+
class SSHTransportError < StandardError
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_accessor :session, :host, :user, :pass
|
9
|
+
|
10
|
+
def initialize(host, user, pass)
|
11
|
+
@host = host
|
12
|
+
@user = user
|
13
|
+
@pass = pass
|
14
|
+
end
|
15
|
+
|
16
|
+
def connect
|
17
|
+
handle_exceptions do
|
18
|
+
@session = Net::SSH.start(host,
|
19
|
+
user,
|
20
|
+
password: pass,
|
21
|
+
auth_methods: %w(password),
|
22
|
+
number_of_password_prompts: 0,
|
23
|
+
timeout: 3)
|
24
|
+
end
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def close
|
29
|
+
handle_exceptions do
|
30
|
+
session.close
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def exec!(cmd)
|
35
|
+
handle_exceptions do
|
36
|
+
session.exec!(cmd).chomp
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def handle_exceptions
|
44
|
+
begin
|
45
|
+
yield
|
46
|
+
rescue => e
|
47
|
+
raise SSHTransportError, "Exception while talking to host #{host}: #{e}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
data/lib/quickmox/version.rb
CHANGED
data/lib/quickmox.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'quickmox/version'
|
2
|
+
require 'quickmox/host'
|
3
|
+
require 'quickmox/guest'
|
4
|
+
require 'quickmox/guestlist'
|
5
|
+
require 'quickmox/ssh_transport'
|
5
6
|
|
6
7
|
module Quickmox
|
7
8
|
end
|
metadata
CHANGED
@@ -1,142 +1,125 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quickmox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- J.K.Valk
|
9
8
|
autorequire:
|
10
9
|
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-20 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.10'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.10'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '10.0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '10.0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: guard
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: guard-rspec
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - ">="
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - ">="
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: coveralls
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - ">="
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '0'
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - ">="
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
98
|
name: pry
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
100
|
requirements:
|
115
|
-
- -
|
101
|
+
- - ">="
|
116
102
|
- !ruby/object:Gem::Version
|
117
103
|
version: '0'
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
107
|
requirements:
|
123
|
-
- -
|
108
|
+
- - ">="
|
124
109
|
- !ruby/object:Gem::Version
|
125
110
|
version: '0'
|
126
111
|
- !ruby/object:Gem::Dependency
|
127
112
|
name: net-ssh
|
128
113
|
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
114
|
requirements:
|
131
|
-
- - ~>
|
115
|
+
- - "~>"
|
132
116
|
- !ruby/object:Gem::Version
|
133
117
|
version: '2.9'
|
134
118
|
type: :runtime
|
135
119
|
prerelease: false
|
136
120
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
121
|
requirements:
|
139
|
-
- - ~>
|
122
|
+
- - "~>"
|
140
123
|
- !ruby/object:Gem::Version
|
141
124
|
version: '2.9'
|
142
125
|
description: This is VERY raw, version 1.0.0 is expected to be first usable implementation.
|
@@ -146,10 +129,10 @@ executables: []
|
|
146
129
|
extensions: []
|
147
130
|
extra_rdoc_files: []
|
148
131
|
files:
|
149
|
-
- .coveralls.yml
|
150
|
-
- .gitignore
|
151
|
-
- .rspec
|
152
|
-
- .travis.yml
|
132
|
+
- ".coveralls.yml"
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".travis.yml"
|
153
136
|
- CODE_OF_CONDUCT.md
|
154
137
|
- Gemfile
|
155
138
|
- README.md
|
@@ -160,32 +143,32 @@ files:
|
|
160
143
|
- lib/quickmox/guest.rb
|
161
144
|
- lib/quickmox/guestlist.rb
|
162
145
|
- lib/quickmox/host.rb
|
146
|
+
- lib/quickmox/ssh_transport.rb
|
163
147
|
- lib/quickmox/version.rb
|
164
148
|
- quickmox.gemspec
|
165
149
|
homepage: https://github.com/jkvalk/quickmox
|
166
150
|
licenses:
|
167
151
|
- MIT
|
152
|
+
metadata: {}
|
168
153
|
post_install_message:
|
169
154
|
rdoc_options: []
|
170
155
|
require_paths:
|
171
156
|
- lib
|
172
157
|
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
-
none: false
|
174
158
|
requirements:
|
175
|
-
- -
|
159
|
+
- - ">="
|
176
160
|
- !ruby/object:Gem::Version
|
177
161
|
version: '0'
|
178
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
-
none: false
|
180
163
|
requirements:
|
181
|
-
- -
|
164
|
+
- - ">="
|
182
165
|
- !ruby/object:Gem::Version
|
183
166
|
version: '0'
|
184
167
|
requirements: []
|
185
168
|
rubyforge_project:
|
186
|
-
rubygems_version:
|
169
|
+
rubygems_version: 2.2.2
|
187
170
|
signing_key:
|
188
|
-
specification_version:
|
171
|
+
specification_version: 4
|
189
172
|
summary: Quickmox is a Ruby gem for managing Proxmox hosts by SSH screen-scraping
|
190
173
|
techniques.
|
191
174
|
test_files: []
|