quickmox 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +10 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/misc.xml +14 -0
- data/.idea/modules.xml +8 -0
- data/.idea/quickmox.iml +58 -0
- data/.idea/vcs.xml +6 -0
- data/.idea/workspace.xml +41 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/README.md +59 -0
- data/Rakefile +1 -0
- data/bin/console +10 -0
- data/bin/setup +7 -0
- data/lib/quickmox/host.rb +152 -0
- data/lib/quickmox/version.rb +3 -0
- data/lib/quickmox.rb +5 -0
- data/quickmox.gemspec +44 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fdfd2bee043eaf537570299389f15324d8b7c81c
|
4
|
+
data.tar.gz: a4b7af1c231472f4832faf0044d431e0e8beef27
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 300bc078c4e23686d8dab7e6734356059a65f9d41d9316d9ee36dec326a0c7ba1d999fb3e440d9a084ae1191825f27d772efdec4ca88e67e4a47b59d54647a5c
|
7
|
+
data.tar.gz: 6d99c1ae8311cb24f28013e1482ad87eef8cdac8c8815cfae95a21f3ee5bf8093d57640cb3ad806bdc7e33988457ffb27e843f3a419f2bfacc7ce3b586e6d62e
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.idea/.rakeTasks
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Settings><!--This file was automatically generated by Ruby plugin.
|
3
|
+
You are allowed to:
|
4
|
+
1. Remove rake task
|
5
|
+
2. Add existing rake tasks
|
6
|
+
To add existing rake tasks automatically delete this file and reload the project.
|
7
|
+
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build quickmox-0.1.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Build and install quickmox-0.1.0.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install quickmox-0.1.0.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.0 and build and push quickmox-0.1.0.gem to Rubygems" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
|
data/.idea/misc.xml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
4
|
+
<OptionsSetting value="true" id="Add" />
|
5
|
+
<OptionsSetting value="true" id="Remove" />
|
6
|
+
<OptionsSetting value="true" id="Checkout" />
|
7
|
+
<OptionsSetting value="true" id="Update" />
|
8
|
+
<OptionsSetting value="true" id="Status" />
|
9
|
+
<OptionsSetting value="true" id="Edit" />
|
10
|
+
<ConfirmationsSetting value="0" id="Add" />
|
11
|
+
<ConfirmationsSetting value="0" id="Remove" />
|
12
|
+
</component>
|
13
|
+
<component name="ProjectRootManager" version="2" project-jdk-name="ruby-2.1.2-p95" project-jdk-type="RUBY_SDK" />
|
14
|
+
</project>
|
data/.idea/modules.xml
ADDED
data/.idea/quickmox.iml
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="FacetManager">
|
4
|
+
<facet type="gem" name="Ruby Gem">
|
5
|
+
<configuration>
|
6
|
+
<option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
|
7
|
+
<option name="GEM_APP_TEST_PATH" value="" />
|
8
|
+
<option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
|
9
|
+
</configuration>
|
10
|
+
</facet>
|
11
|
+
</component>
|
12
|
+
<component name="NewModuleRootManager">
|
13
|
+
<content url="file://$MODULE_DIR$" />
|
14
|
+
<orderEntry type="inheritedJdk" />
|
15
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="awesome_print (v1.6.1, ruby-2.1.2-p95) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="celluloid (v0.16.0, ruby-2.1.2-p95) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="coderay (v1.1.0, ruby-2.1.2-p95) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="coveralls (v0.8.1, ruby-2.1.2-p95) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, ruby-2.1.2-p95) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="docile (v1.1.5, ruby-2.1.2-p95) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="domain_name (v0.5.24, ruby-2.1.2-p95) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="ffi (v1.9.8, ruby-2.1.2-p95) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="formatador (v0.2.5, ruby-2.1.2-p95) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="guard (v2.12.6, ruby-2.1.2-p95) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="guard-compat (v1.2.1, ruby-2.1.2-p95) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="guard-rspec (v4.5.2, ruby-2.1.2-p95) [gem]" level="application" />
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="hitimes (v1.2.2, ruby-2.1.2-p95) [gem]" level="application" />
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="http-cookie (v1.0.2, ruby-2.1.2-p95) [gem]" level="application" />
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="json (v1.8.3, ruby-2.1.2-p95) [gem]" level="application" />
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="listen (v2.10.0, ruby-2.1.2-p95) [gem]" level="application" />
|
32
|
+
<orderEntry type="library" scope="PROVIDED" name="lumberjack (v1.0.9, ruby-2.1.2-p95) [gem]" level="application" />
|
33
|
+
<orderEntry type="library" scope="PROVIDED" name="mime-types (v2.6.1, ruby-2.1.2-p95) [gem]" level="application" />
|
34
|
+
<orderEntry type="library" scope="PROVIDED" name="nenv (v0.2.0, ruby-2.1.2-p95) [gem]" level="application" />
|
35
|
+
<orderEntry type="library" scope="PROVIDED" name="net-ssh (v2.9.2, ruby-2.1.2-p95) [gem]" level="application" />
|
36
|
+
<orderEntry type="library" scope="PROVIDED" name="netrc (v0.10.3, ruby-2.1.2-p95) [gem]" level="application" />
|
37
|
+
<orderEntry type="library" scope="PROVIDED" name="notiffany (v0.0.6, ruby-2.1.2-p95) [gem]" level="application" />
|
38
|
+
<orderEntry type="library" scope="PROVIDED" name="pry (v0.10.1, ruby-2.1.2-p95) [gem]" level="application" />
|
39
|
+
<orderEntry type="library" scope="PROVIDED" name="rb-fsevent (v0.9.5, ruby-2.1.2-p95) [gem]" level="application" />
|
40
|
+
<orderEntry type="library" scope="PROVIDED" name="rb-inotify (v0.9.5, ruby-2.1.2-p95) [gem]" level="application" />
|
41
|
+
<orderEntry type="library" scope="PROVIDED" name="rest-client (v1.8.0, ruby-2.1.2-p95) [gem]" level="application" />
|
42
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.3.0, ruby-2.1.2-p95) [gem]" level="application" />
|
43
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.3.0, ruby-2.1.2-p95) [gem]" level="application" />
|
44
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.3.0, ruby-2.1.2-p95) [gem]" level="application" />
|
45
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.3.0, ruby-2.1.2-p95) [gem]" level="application" />
|
46
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.3.0, ruby-2.1.2-p95) [gem]" level="application" />
|
47
|
+
<orderEntry type="library" scope="PROVIDED" name="shellany (v0.0.1, ruby-2.1.2-p95) [gem]" level="application" />
|
48
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov (v0.10.0, ruby-2.1.2-p95) [gem]" level="application" />
|
49
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.10.0, ruby-2.1.2-p95) [gem]" level="application" />
|
50
|
+
<orderEntry type="library" scope="PROVIDED" name="slop (v3.6.0, ruby-2.1.2-p95) [gem]" level="application" />
|
51
|
+
<orderEntry type="library" scope="PROVIDED" name="term-ansicolor (v1.3.0, ruby-2.1.2-p95) [gem]" level="application" />
|
52
|
+
<orderEntry type="library" scope="PROVIDED" name="thor (v0.19.1, ruby-2.1.2-p95) [gem]" level="application" />
|
53
|
+
<orderEntry type="library" scope="PROVIDED" name="timers (v4.0.1, ruby-2.1.2-p95) [gem]" level="application" />
|
54
|
+
<orderEntry type="library" scope="PROVIDED" name="tins (v1.5.2, ruby-2.1.2-p95) [gem]" level="application" />
|
55
|
+
<orderEntry type="library" scope="PROVIDED" name="unf (v0.1.4, ruby-2.1.2-p95) [gem]" level="application" />
|
56
|
+
<orderEntry type="library" scope="PROVIDED" name="unf_ext (v0.0.7.1, ruby-2.1.2-p95) [gem]" level="application" />
|
57
|
+
</component>
|
58
|
+
</module>
|
data/.idea/vcs.xml
ADDED
data/.idea/workspace.xml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ChangeListManager">
|
4
|
+
<option name="TRACKING_ENABLED" value="true" />
|
5
|
+
<option name="SHOW_DIALOG" value="false" />
|
6
|
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
7
|
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
8
|
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
9
|
+
</component>
|
10
|
+
<component name="ChangesViewManager" flattened_view="true" show_ignored="false" />
|
11
|
+
<component name="CreatePatchCommitExecutor">
|
12
|
+
<option name="PATCH_PATH" value="" />
|
13
|
+
</component>
|
14
|
+
<component name="NamedScopeManager">
|
15
|
+
<order />
|
16
|
+
</component>
|
17
|
+
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
18
|
+
<OptionsSetting value="true" id="Add" />
|
19
|
+
<OptionsSetting value="true" id="Remove" />
|
20
|
+
<OptionsSetting value="true" id="Checkout" />
|
21
|
+
<OptionsSetting value="true" id="Update" />
|
22
|
+
<OptionsSetting value="true" id="Status" />
|
23
|
+
<OptionsSetting value="true" id="Edit" />
|
24
|
+
<ConfirmationsSetting value="0" id="Add" />
|
25
|
+
<ConfirmationsSetting value="0" id="Remove" />
|
26
|
+
</component>
|
27
|
+
<component name="ShelveChangesManager" show_recycled="false" />
|
28
|
+
<component name="TaskManager">
|
29
|
+
<task active="true" id="Default" summary="Default task">
|
30
|
+
<option name="number" value="Default" />
|
31
|
+
</task>
|
32
|
+
<servers />
|
33
|
+
</component>
|
34
|
+
<component name="VcsContentAnnotationSettings">
|
35
|
+
<option name="myLimit" value="2678400000" />
|
36
|
+
</component>
|
37
|
+
<component name="XDebuggerManager">
|
38
|
+
<breakpoint-manager />
|
39
|
+
<watches-manager />
|
40
|
+
</component>
|
41
|
+
</project>
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/jkvalk/quickmox.svg?branch=master)](https://travis-ci.org/jkvalk/quickmox)
|
2
|
+
[![Coverage Status](https://coveralls.io/repos/jkvalk/quickmox/badge.svg?branch=master)](https://coveralls.io/r/jkvalk/quickmox?branch=master)
|
3
|
+
|
4
|
+
# Quickmox
|
5
|
+
|
6
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/quickmox`. To experiment with that code, run `bin/console` for an interactive prompt.
|
7
|
+
|
8
|
+
TODO: Delete this and the text above, and describe your gem
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'quickmox'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install quickmox
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'quickmox'
|
30
|
+
include Quickmox
|
31
|
+
|
32
|
+
hostname = 'host1.example.com'
|
33
|
+
user = 'root'
|
34
|
+
pass = 's3cr3t'
|
35
|
+
|
36
|
+
host = Host.new(hostname: hostname, username: user, password: pass).connect
|
37
|
+
|
38
|
+
p host.localname
|
39
|
+
p host.uptime
|
40
|
+
|
41
|
+
host.guests.each do |guest_id|
|
42
|
+
p host.guest_params(guest_id)
|
43
|
+
p host.guest_status(guest_id)
|
44
|
+
end if host.is_proxmox?
|
45
|
+
|
46
|
+
host.disconnect
|
47
|
+
|
48
|
+
```
|
49
|
+
|
50
|
+
## Development
|
51
|
+
|
52
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
53
|
+
|
54
|
+
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).
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jkvalk/quickmox. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
59
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
require 'ap'
|
3
|
+
require 'resolv'
|
4
|
+
|
5
|
+
module Quickmox
|
6
|
+
|
7
|
+
|
8
|
+
# This class represents a SSH server host. It may or may not be
|
9
|
+
# connected to a Proxmox server. If it's not, proxmox specific
|
10
|
+
# methods like guests(), guest_params() etc. will return empty
|
11
|
+
# data structures.
|
12
|
+
class Host
|
13
|
+
|
14
|
+
class HostError < StandardError
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_accessor :hostname, :username, :password, :ip, :session
|
18
|
+
|
19
|
+
# Initialize Host object
|
20
|
+
# * +hostname:+
|
21
|
+
# * +username:+
|
22
|
+
# * +password:+
|
23
|
+
# h = Host.new(hostname:"10.0.0.1", username:"root", password:"qwerty123")
|
24
|
+
def initialize(opts = {})
|
25
|
+
@hostname = opts[:hostname]
|
26
|
+
@username = opts[:username]
|
27
|
+
@password = opts[:password]
|
28
|
+
begin
|
29
|
+
@ip = Resolv.getaddress(@hostname)
|
30
|
+
rescue => e
|
31
|
+
@ip = ''
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Make SSH connection and log in.
|
36
|
+
def connect
|
37
|
+
begin
|
38
|
+
@session = Net::SSH.start(hostname,
|
39
|
+
username,
|
40
|
+
password: password,
|
41
|
+
auth_methods: %w(password),
|
42
|
+
number_of_password_prompts: 0,
|
43
|
+
timeout: 3)
|
44
|
+
|
45
|
+
rescue => e
|
46
|
+
raise HostError, "Warning: exception while connecting to host #{hostname}: #{e.to_s}"
|
47
|
+
end
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns local hostname obtained by the Unix 'hostname' command
|
52
|
+
def localname
|
53
|
+
handle_exceptions do
|
54
|
+
session.exec!('hostname').chomp
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns host uptime
|
59
|
+
def uptime
|
60
|
+
handle_exceptions do
|
61
|
+
session.exec!('uptime').chomp
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Disconnects the SSH session
|
66
|
+
def disconnect
|
67
|
+
begin
|
68
|
+
session.close
|
69
|
+
rescue => e
|
70
|
+
raise HostError, "Warning: exception while disconnecting from host #{hostname}: #{e.to_s}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Checks if host responds to 'qm' commands
|
75
|
+
def is_proxmox?
|
76
|
+
handle_exceptions do
|
77
|
+
output = session.exec!('qm list')
|
78
|
+
(output =~ /VMID NAME/) ? true : false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns guest status (running/stopped/NA)
|
83
|
+
# * +guest_id+ numeric ID of the guest
|
84
|
+
def guest_status(guest_id)
|
85
|
+
status = ''
|
86
|
+
handle_exceptions do
|
87
|
+
status = session.exec!("qm status #{guest_id}")
|
88
|
+
end
|
89
|
+
if status =~ /running/
|
90
|
+
'running'
|
91
|
+
elsif status =~ /stopped/
|
92
|
+
'stopped'
|
93
|
+
else
|
94
|
+
'N/A'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Returns a hash of guest parameters
|
99
|
+
# * +guest_id+ numeric ID of the guest
|
100
|
+
# h = guest_params(100)
|
101
|
+
# h = guest_params("101")
|
102
|
+
def guest_params(guest_id)
|
103
|
+
params = {}
|
104
|
+
handle_exceptions do
|
105
|
+
session.exec!("qm config #{guest_id}").split("\n").each do |line|
|
106
|
+
if line =~ /net0:.*=([0-9A-Fa-f:]{17}),/
|
107
|
+
params['mac'] = $1
|
108
|
+
params['mac'].gsub!(':', '').downcase!
|
109
|
+
elsif line =~ /cores: ([0-9]{1,3})/
|
110
|
+
params['cores'] = $1
|
111
|
+
elsif line =~ /bootdisk: (.*)/
|
112
|
+
params['bootdisk'] = $1
|
113
|
+
elsif line =~ /description: (.*)/
|
114
|
+
params['description'] = $1
|
115
|
+
elsif line =~ /memory: ([0-9]{1,6})/
|
116
|
+
params['memory'] = $1
|
117
|
+
elsif line =~ /name: (.*)/
|
118
|
+
params['name'] = $1
|
119
|
+
elsif line =~ /onboot: ([0-9])/
|
120
|
+
params['onboot'] = $1
|
121
|
+
elsif line =~ /(scsi|virtio|ide)[0-9]{1,3}: .*size=([0-9]{1,3}[MGTK])/
|
122
|
+
params['disk'] = $2
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
params
|
127
|
+
end
|
128
|
+
|
129
|
+
# Returns an array of guest IDs on this host
|
130
|
+
def guests
|
131
|
+
guests = []
|
132
|
+
table = handle_exceptions { session.exec!('qm list') }
|
133
|
+
lines = table.split("\n")
|
134
|
+
lines.each do |line|
|
135
|
+
if line =~ /^ *([0-9]{1,4}) */
|
136
|
+
guests << $1
|
137
|
+
end
|
138
|
+
end
|
139
|
+
guests
|
140
|
+
end
|
141
|
+
|
142
|
+
# Wrapper method to rescue SSH/connection exceptions
|
143
|
+
private
|
144
|
+
def handle_exceptions
|
145
|
+
begin
|
146
|
+
yield
|
147
|
+
rescue => e
|
148
|
+
raise HostError, "Exception while talking to host #{hostname}: #{e.to_s}"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
data/lib/quickmox.rb
ADDED
data/quickmox.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'quickmox/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "quickmox"
|
8
|
+
spec.version = Quickmox::VERSION
|
9
|
+
spec.authors = ["J.K.Valk"]
|
10
|
+
spec.email = ["jkvalk@mail.ru"]
|
11
|
+
|
12
|
+
spec.summary = %q{Quickmox is a Ruby gem for managing Proxmox hosts by SSH screen-scraping techniques.}
|
13
|
+
spec.description = %q{This is VERY raw, version 1.0.0 is expected to be first usable implementation.}
|
14
|
+
spec.homepage = "https://github.com/jkvalk/quickmox"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
#if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = ""
|
20
|
+
#else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
#end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.license = "MIT"
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
|
34
|
+
spec.add_development_dependency "rspec"
|
35
|
+
spec.add_development_dependency "guard"
|
36
|
+
spec.add_development_dependency "guard-rspec"
|
37
|
+
spec.add_development_dependency "coveralls"
|
38
|
+
spec.add_development_dependency "pry"
|
39
|
+
|
40
|
+
spec.add_dependency "net-ssh", "~> 2.9"
|
41
|
+
spec.add_dependency "awesome_print", '~> 1.6'
|
42
|
+
|
43
|
+
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quickmox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- J.K.Valk
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: net-ssh
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.9'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.9'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: awesome_print
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.6'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.6'
|
139
|
+
description: This is VERY raw, version 1.0.0 is expected to be first usable implementation.
|
140
|
+
email:
|
141
|
+
- jkvalk@mail.ru
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".coveralls.yml"
|
147
|
+
- ".gitignore"
|
148
|
+
- ".idea/.rakeTasks"
|
149
|
+
- ".idea/misc.xml"
|
150
|
+
- ".idea/modules.xml"
|
151
|
+
- ".idea/quickmox.iml"
|
152
|
+
- ".idea/vcs.xml"
|
153
|
+
- ".idea/workspace.xml"
|
154
|
+
- ".rspec"
|
155
|
+
- ".travis.yml"
|
156
|
+
- CODE_OF_CONDUCT.md
|
157
|
+
- Gemfile
|
158
|
+
- README.md
|
159
|
+
- Rakefile
|
160
|
+
- bin/console
|
161
|
+
- bin/setup
|
162
|
+
- lib/quickmox.rb
|
163
|
+
- lib/quickmox/host.rb
|
164
|
+
- lib/quickmox/version.rb
|
165
|
+
- quickmox.gemspec
|
166
|
+
homepage: https://github.com/jkvalk/quickmox
|
167
|
+
licenses:
|
168
|
+
- MIT
|
169
|
+
metadata: {}
|
170
|
+
post_install_message:
|
171
|
+
rdoc_options: []
|
172
|
+
require_paths:
|
173
|
+
- lib
|
174
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
requirements: []
|
185
|
+
rubyforge_project:
|
186
|
+
rubygems_version: 2.2.2
|
187
|
+
signing_key:
|
188
|
+
specification_version: 4
|
189
|
+
summary: Quickmox is a Ruby gem for managing Proxmox hosts by SSH screen-scraping
|
190
|
+
techniques.
|
191
|
+
test_files: []
|