proxmox 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +41 -0
- data/Gemfile +14 -14
- data/Guardfile +1 -1
- data/Rakefile +3 -3
- data/lib/proxmox.rb +26 -10
- data/lib/proxmox/version.rb +1 -1
- data/proxmox.gemspec +14 -14
- data/spec/lib/proxmox_spec.rb +230 -175
- data/spec/spec_helper.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 41abce9de10f96aff6099d9f18f30e8352495a36
|
|
4
|
+
data.tar.gz: 6a5d9657b7197404ca13a7af6ef62a3362e0fc5a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fea450ccbebce6fea5403da75b166beed9fb62f104d63876b73577441dae0fb8b2f9c3312db30d21fb0ff3e97cfedf52a1118ccc85d8e7eb0829d58407511efc
|
|
7
|
+
data.tar.gz: 71a920f1a3f8ccc488434b723e5d4ba60341c555cc073ba9bda3d82cb99ada571e6a1b94110c0a6d52c9783ef8450ec6c1eb1cacab2b696e3ff209e184c32c63
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# This configuration was generated by
|
|
2
|
+
# `rubocop --auto-gen-config`
|
|
3
|
+
# on 2015-11-14 20:39:56 -0600 using RuboCop version 0.35.1.
|
|
4
|
+
# The point is for the user to remove these configuration records
|
|
5
|
+
# one by one as the offenses are removed from the code base.
|
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
|
8
|
+
|
|
9
|
+
# Offense count: 1
|
|
10
|
+
Lint/Void:
|
|
11
|
+
Exclude:
|
|
12
|
+
- 'spec/lib/proxmox_spec.rb'
|
|
13
|
+
|
|
14
|
+
# Offense count: 1
|
|
15
|
+
# Configuration parameters: CountComments.
|
|
16
|
+
Metrics/ClassLength:
|
|
17
|
+
Max: 130
|
|
18
|
+
|
|
19
|
+
# Offense count: 45
|
|
20
|
+
# Configuration parameters: AllowURI, URISchemes.
|
|
21
|
+
Metrics/LineLength:
|
|
22
|
+
Max: 1094
|
|
23
|
+
|
|
24
|
+
# Offense count: 1
|
|
25
|
+
# Configuration parameters: CountComments.
|
|
26
|
+
Metrics/MethodLength:
|
|
27
|
+
Max: 11
|
|
28
|
+
|
|
29
|
+
# Offense count: 1
|
|
30
|
+
# Configuration parameters: CountKeywordArgs.
|
|
31
|
+
Metrics/ParameterLists:
|
|
32
|
+
Max: 6
|
|
33
|
+
|
|
34
|
+
# Offense count: 1
|
|
35
|
+
# Configuration parameters: Exclude.
|
|
36
|
+
Style/Documentation:
|
|
37
|
+
Exclude:
|
|
38
|
+
- 'spec/**/*'
|
|
39
|
+
- 'test/**/*'
|
|
40
|
+
- 'lib/proxmox/version.rb'
|
|
41
|
+
|
data/Gemfile
CHANGED
|
@@ -4,24 +4,24 @@ source 'https://rubygems.org'
|
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
6
|
group :developpement do
|
|
7
|
-
gem
|
|
8
|
-
gem
|
|
9
|
-
gem
|
|
7
|
+
gem 'guard'
|
|
8
|
+
gem 'guard-rspec'
|
|
9
|
+
gem 'guard-bundler'
|
|
10
10
|
|
|
11
|
-
gem
|
|
12
|
-
gem
|
|
13
|
-
gem
|
|
11
|
+
gem 'growl' if RUBY_PLATFORM =~ /darwin/
|
|
12
|
+
gem 'wdm' if RUBY_PLATFORM =~ /mingw/
|
|
13
|
+
gem 'ruby_gntp' if RUBY_PLATFORM =~ /mingw/
|
|
14
14
|
|
|
15
|
-
gem
|
|
15
|
+
gem 'guard-spork'
|
|
16
16
|
|
|
17
|
-
gem
|
|
18
|
-
gem
|
|
19
|
-
gem
|
|
17
|
+
gem 'yard'
|
|
18
|
+
gem 'redcarpet'
|
|
19
|
+
gem 'guard-yard'
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
group :test do
|
|
23
|
-
gem
|
|
24
|
-
gem
|
|
25
|
-
gem
|
|
26
|
-
gem
|
|
23
|
+
gem 'spork'
|
|
24
|
+
gem 'simplecov'
|
|
25
|
+
gem 'json', '~> 1.8.3'
|
|
26
|
+
gem 'coveralls'
|
|
27
27
|
end
|
data/Guardfile
CHANGED
data/Rakefile
CHANGED
data/lib/proxmox.rb
CHANGED
|
@@ -34,6 +34,22 @@ module Proxmox
|
|
|
34
34
|
@auth_params = create_ticket
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
def get(path, args = {})
|
|
38
|
+
http_action_get(path, args)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def post(path, args = {})
|
|
42
|
+
http_action_post(path, args)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def put(path, args = {})
|
|
46
|
+
http_action_put(path, args)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def delete(path)
|
|
50
|
+
http_action_delete(path)
|
|
51
|
+
end
|
|
52
|
+
|
|
37
53
|
# Get task status
|
|
38
54
|
#
|
|
39
55
|
# :call-seq:
|
|
@@ -51,7 +67,7 @@ module Proxmox
|
|
|
51
67
|
# - stopped:OK
|
|
52
68
|
#
|
|
53
69
|
def task_status(upid)
|
|
54
|
-
data = http_action_get "nodes/#{@node}/tasks/#{URI
|
|
70
|
+
data = http_action_get "nodes/#{@node}/tasks/#{URI.encode upid}/status"
|
|
55
71
|
status = data['status']
|
|
56
72
|
exitstatus = data['exitstatus']
|
|
57
73
|
if exitstatus
|
|
@@ -93,7 +109,7 @@ module Proxmox
|
|
|
93
109
|
data = http_action_get "nodes/#{@node}/storage/local/content"
|
|
94
110
|
template_list = {}
|
|
95
111
|
data.each do |ve|
|
|
96
|
-
name = ve['volid'].gsub(
|
|
112
|
+
name = ve['volid'].gsub(%r{local:vztmpl\/(.*).tar.gz}, '\1')
|
|
97
113
|
template_list[name] = ve
|
|
98
114
|
end
|
|
99
115
|
template_list
|
|
@@ -323,7 +339,7 @@ module Proxmox
|
|
|
323
339
|
# Methods manages auth
|
|
324
340
|
def create_ticket
|
|
325
341
|
post_param = { username: @username, realm: @realm, password: @password }
|
|
326
|
-
@site['access/ticket'].post post_param do |response,
|
|
342
|
+
@site['access/ticket'].post post_param do |response, _request, _result, &_block|
|
|
327
343
|
if response.code == 200
|
|
328
344
|
extract_ticket response
|
|
329
345
|
else
|
|
@@ -357,26 +373,26 @@ module Proxmox
|
|
|
357
373
|
end
|
|
358
374
|
|
|
359
375
|
# Methods manage http dialogs
|
|
360
|
-
def http_action_post(url, data =
|
|
361
|
-
@site[url].post data, @auth_params do |response,
|
|
376
|
+
def http_action_post(url, data = {})
|
|
377
|
+
@site[url].post data, @auth_params do |response, _request, _result, &_block|
|
|
362
378
|
check_response response
|
|
363
379
|
end
|
|
364
380
|
end
|
|
365
381
|
|
|
366
|
-
def http_action_put(url, data =
|
|
367
|
-
@site[url].put data, @auth_params do |response,
|
|
382
|
+
def http_action_put(url, data = {})
|
|
383
|
+
@site[url].put data, @auth_params do |response, _request, _result, &_block|
|
|
368
384
|
check_response response
|
|
369
385
|
end
|
|
370
386
|
end
|
|
371
387
|
|
|
372
|
-
def http_action_get(url)
|
|
373
|
-
@site[url].get @auth_params do |response,
|
|
388
|
+
def http_action_get(url, data = {})
|
|
389
|
+
@site[url].get @auth_params.merge(data) do |response, _request, _result, &_block|
|
|
374
390
|
check_response response
|
|
375
391
|
end
|
|
376
392
|
end
|
|
377
393
|
|
|
378
394
|
def http_action_delete(url)
|
|
379
|
-
@site[url].delete @auth_params do |response,
|
|
395
|
+
@site[url].delete @auth_params do |response, _request, _result, &_block|
|
|
380
396
|
check_response response
|
|
381
397
|
end
|
|
382
398
|
end
|
data/lib/proxmox/version.rb
CHANGED
data/proxmox.gemspec
CHANGED
|
@@ -4,23 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
|
4
4
|
require 'proxmox/version'
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name =
|
|
7
|
+
spec.name = 'proxmox'
|
|
8
8
|
spec.version = Proxmox::VERSION
|
|
9
|
-
spec.authors = [
|
|
10
|
-
spec.email = [
|
|
11
|
-
spec.description =
|
|
12
|
-
spec.summary =
|
|
13
|
-
spec.homepage =
|
|
14
|
-
spec.license =
|
|
9
|
+
spec.authors = ['Nicolas Ledez']
|
|
10
|
+
spec.email = ['github@ledez.net']
|
|
11
|
+
spec.description = 'A library to drive a Proxmox host'
|
|
12
|
+
spec.summary = 'You need to manage a proxmox host with Ruby? This library is for you.'
|
|
13
|
+
spec.homepage = 'https://github.com/nledez/proxmox'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
15
|
|
|
16
|
-
spec.files = `git ls-files`.split(
|
|
16
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
-
spec.add_dependency
|
|
20
|
-
spec.require_paths = [
|
|
19
|
+
spec.add_dependency 'rest-client', '>=1.6.7'
|
|
20
|
+
spec.require_paths = ['lib']
|
|
21
21
|
|
|
22
|
-
spec.add_development_dependency
|
|
23
|
-
spec.add_development_dependency
|
|
24
|
-
spec.add_development_dependency
|
|
25
|
-
spec.add_development_dependency
|
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
|
23
|
+
spec.add_development_dependency 'rake'
|
|
24
|
+
spec.add_development_dependency 'rspec'
|
|
25
|
+
spec.add_development_dependency 'webmock'
|
|
26
26
|
end
|
data/spec/lib/proxmox_spec.rb
CHANGED
|
@@ -5,235 +5,290 @@ require 'proxmox'
|
|
|
5
5
|
describe Proxmox do
|
|
6
6
|
before(:each) do
|
|
7
7
|
@common_headers_in = { 'User-Agent' => 'Ruby',
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@common_headers_out = { :
|
|
11
|
-
:
|
|
12
|
-
:
|
|
8
|
+
'Cookie' => /.*/,
|
|
9
|
+
'Csrfpreventiontoken' => /.*/ }
|
|
10
|
+
@common_headers_out = { connection: 'close',
|
|
11
|
+
server: 'pve-api-daemon/3.0',
|
|
12
|
+
content_type: 'application/json;charset=UTF-8' }
|
|
13
13
|
|
|
14
14
|
# Common auth
|
|
15
|
-
stub_request(:post,
|
|
16
|
-
:
|
|
15
|
+
stub_request(:post, 'http://localhost:8006/api2/json/access/ticket').with(
|
|
16
|
+
headers: {
|
|
17
17
|
'Content-Type' => 'application/x-www-form-urlencoded',
|
|
18
18
|
'User-Agent' => 'Ruby'
|
|
19
19
|
},
|
|
20
|
-
:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
body: {
|
|
21
|
+
'username' => 'root',
|
|
22
|
+
'password' => 'secret',
|
|
23
|
+
'realm' => 'pam'
|
|
24
24
|
}
|
|
25
25
|
).to_return(
|
|
26
|
-
:
|
|
27
|
-
:
|
|
28
|
-
:
|
|
26
|
+
status: 200,
|
|
27
|
+
headers: @common_headers_out,
|
|
28
|
+
body: '{"data":{"cap":{"dc":{"Sys.Audit":1},"access":{"Group.Allocate":1,"User.Modify":1},"nodes":{"Sys.Audit":1,"Sys.Syslog":1,"Sys.Console":1,"Sys.Modify":1,"Sys.PowerMgmt":1},"vms":{"VM.Backup":1,"VM.Allocate":1,"VM.Config.CPU":1,"VM.Config.Network":1,"VM.Migrate":1,"VM.Config.Memory":1,"VM.Config.Options":1,"Permissions.Modify":1,"VM.Monitor":1,"VM.Console":1,"VM.Config.Disk":1,"VM.Config.HWType":1,"VM.Clone":1,"VM.Snapshot":1,"VM.Audit":1,"VM.PowerMgmt":1,"VM.Config.CDROM":1},"storage":{"Datastore.AllocateTemplate":1,"Datastore.Allocate":1,"Datastore.Audit":1,"Permissions.Modify":1,"Datastore.AllocateSpace":1}},"CSRFPreventionToken":"51F00E60:Pnd0AHehuTE++j87nUz0nLuyW+0","ticket":"PVE:root@pam:51F00E60::OS5lBKlaabgnmekdbVY2JYAbd5Z/MPWCeZ9b33UwjsE1yVB1esIwUQoXJ4Xgb/+UVE9mtS2K3dJ65wyPDsGYTDc0TCl0VmdOGz7djXMlMy5ShRjXcX/GLs77LHXlLQOO+ED/jCoz0tHV55igNSBNMG2UrSLlTGvgm8zf1fNqAsVszrAWgeFu+e/1CLIfs//cWyimBuDx+r3m/NOjaoyeb2u63eBCPrWyEiCJZniMZDVnqqQcOm32tE2XQj4D2LS+xaHn2fdZDlcAo0uY4qVspKiMjf9g2AudRblkobCTf7KdhanIm0kCSqkvHJy2EMcAbxcqnGnjPiYSH0WYZMTnlA==","username":"root@pam"}}'
|
|
29
29
|
)
|
|
30
30
|
|
|
31
|
-
@server1 = Proxmox::Proxmox.new(
|
|
31
|
+
@server1 = Proxmox::Proxmox.new('http://localhost:8006/api2/json/', 'localhost', 'root', 'secret', 'pam')
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
describe 'get' do
|
|
35
|
+
it 'calls http_action_get' do
|
|
36
|
+
expect(@server1).to receive(:http_action_get).with("version", {})
|
|
37
|
+
@server1.get("version")
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe 'post' do
|
|
42
|
+
it 'calls http_action_post' do
|
|
43
|
+
expect(@server1).to receive(:http_action_post).with("version", {})
|
|
44
|
+
@server1.post("version")
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe 'put' do
|
|
49
|
+
it 'calls http_action_put' do
|
|
50
|
+
expect(@server1).to receive(:http_action_put).with("version", {})
|
|
51
|
+
@server1.put("version")
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe 'delete' do
|
|
56
|
+
it 'calls http_action_delete' do
|
|
57
|
+
expect(@server1).to receive(:http_action_delete).with("version")
|
|
58
|
+
@server1.delete("version")
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
34
62
|
it 'should connect to Proxmox server' do
|
|
35
63
|
# Bad auth
|
|
36
|
-
stub_request(:post,
|
|
37
|
-
:
|
|
64
|
+
stub_request(:post, 'http://localhost:8006/api2/json/access/ticket').with(
|
|
65
|
+
headers: {
|
|
38
66
|
'Content-Type' => 'application/x-www-form-urlencoded',
|
|
39
67
|
'User-Agent' => 'Ruby'
|
|
40
68
|
},
|
|
41
|
-
:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
69
|
+
body: {
|
|
70
|
+
'username' => 'root',
|
|
71
|
+
'password' => 'bad',
|
|
72
|
+
'realm' => 'pam'
|
|
45
73
|
}
|
|
46
74
|
).to_return(
|
|
47
|
-
:
|
|
48
|
-
:
|
|
49
|
-
:
|
|
75
|
+
status: 500,
|
|
76
|
+
headers: @common_headers_out,
|
|
77
|
+
body: '{"data":null}'
|
|
50
78
|
)
|
|
51
|
-
expect(@server1.connection_status).to eq
|
|
79
|
+
expect(@server1.connection_status).to eq 'connected'
|
|
52
80
|
|
|
53
|
-
server2 = Proxmox::Proxmox.new(
|
|
54
|
-
expect(server2.connection_status).to eq
|
|
81
|
+
server2 = Proxmox::Proxmox.new('http://localhost:8006/api2/json/', 'localhost', 'root', 'bad', 'pam')
|
|
82
|
+
expect(server2.connection_status).to eq 'error'
|
|
55
83
|
end
|
|
56
84
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
85
|
+
describe 'task_status' do
|
|
86
|
+
it 'should get task status' do
|
|
87
|
+
# Status done
|
|
88
|
+
stub_request(:get, 'http://localhost:8006/api2/json/nodes/localhost/tasks/UPID:localhost:00051DA0:119EAABB:521CCB19:vzcreate:200:root@pam:/status').with(
|
|
89
|
+
headers: @common_headers_in).to_return(
|
|
90
|
+
status: 200,
|
|
91
|
+
headers: {
|
|
92
|
+
connection: 'close', server: 'pve-api-daemon/3.0', content_type: 'application/json;charset=UTF-8' },
|
|
93
|
+
body: '{"data":{"exitstatus":"OK","status":"stopped","upid":"UPID:localhost:00051DA0:119EAABB:521CCB19:vzcreate:200:root@pam:","node":"localhost","pid":335264,"starttime":1377618713,"user":"root@pam","type":"vzcreate","id":"200","pstart":295611067}}'
|
|
94
|
+
)
|
|
66
95
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
96
|
+
# Status running
|
|
97
|
+
stub_request(:get, 'http://localhost:8006/api2/json/nodes/localhost/tasks/UPID:localhost:00055DDA:11A99D07:521CE71F:vzcreate:200:root@pam:/status').with(
|
|
98
|
+
headers: @common_headers_in).to_return(
|
|
99
|
+
status: 200,
|
|
100
|
+
headers: @common_headers_out,
|
|
101
|
+
body: '{"data":{"status":"running","upid":"UPID:localhost:00055DDA:11A99D07:521CE71F:vzcreate:200:root@pam:","node":"localhost","pid":351706,"starttime":1377625887,"user":"root@pam","type":"vzcreate","id":"200","pstart":296328455}}'
|
|
102
|
+
)
|
|
74
103
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
104
|
+
# Get status
|
|
105
|
+
expect(@server1.task_status('UPID:localhost:00051DA0:119EAABB:521CCB19:vzcreate:200:root@pam:')).to be_eql 'stopped:OK'
|
|
106
|
+
expect(@server1.task_status('UPID:localhost:00055DDA:11A99D07:521CE71F:vzcreate:200:root@pam:')).to be_eql 'running'
|
|
107
|
+
end
|
|
78
108
|
end
|
|
79
109
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
:
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
110
|
+
describe 'templates' do
|
|
111
|
+
it 'should get template list' do
|
|
112
|
+
# First template list
|
|
113
|
+
stub_request(:get, 'http://localhost:8006/api2/json/nodes/localhost/storage/local/content').with(
|
|
114
|
+
headers: @common_headers_in).to_return(
|
|
115
|
+
status: 200,
|
|
116
|
+
headers: @common_headers_out,
|
|
117
|
+
body: '{"data":[{"format":"tgz","content":"vztmpl","volid":"local:vztmpl/ubuntu-10.04-standard_10.04-4_i386.tar.gz","size":142126884},{"format":"tgz","content":"vztmpl","volid":"local:vztmpl/ubuntu-12.04-standard_12.04-1_i386.tar.gz","size":130040792}]}'
|
|
118
|
+
)
|
|
88
119
|
|
|
89
|
-
|
|
90
|
-
|
|
120
|
+
expect(@server1.templates).to be_an_instance_of Hash
|
|
121
|
+
expect(@server1.templates.keys.sort).to be_eql ['ubuntu-10.04-standard_10.04-4_i386', 'ubuntu-12.04-standard_12.04-1_i386']
|
|
122
|
+
end
|
|
91
123
|
end
|
|
92
124
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
125
|
+
describe 'openvz_get' do
|
|
126
|
+
it 'should get openvz vm list' do
|
|
127
|
+
# First VM list
|
|
128
|
+
stub_request(:get, 'http://localhost:8006/api2/json/nodes/localhost/openvz').with(
|
|
129
|
+
headers: @common_headers_in).to_return(
|
|
130
|
+
status: 200,
|
|
131
|
+
headers: @common_headers_out,
|
|
132
|
+
body: '{"data":[{"maxswap":536870912,"disk":404037632,"ip":"192.168.1.5","status":"running","netout":272,"maxdisk":4294967296,"maxmem":536870912,"uptime":3847,"swap":0,"vmid":"101","nproc":"10","diskread":0,"cpu":0.00183354942808597,"netin":0,"name":"test2.dummy.tld","failcnt":0,"diskwrite":0,"mem":21303296,"type":"openvz","cpus":1},{"maxswap":536870912,"disk":387186688,"ip":"192.168.1.1","status":"running","netout":272,"maxdisk":4294967296,"maxmem":536870912,"uptime":17120,"swap":0,"vmid":"100","nproc":"17","diskread":0,"cpu":0.000504170031344927,"netin":0,"name":"test.dummy.tld","failcnt":0,"diskwrite":0,"mem":27987968,"type":"openvz","cpus":1}]}'
|
|
133
|
+
)
|
|
101
134
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
135
|
+
# Second VM list
|
|
136
|
+
stub_request(:get, 'http://localhost:8006/api2/json/nodes/otherone/openvz').with(
|
|
137
|
+
headers: @common_headers_in).to_return(
|
|
138
|
+
status: 200,
|
|
139
|
+
headers: @common_headers_out,
|
|
140
|
+
body: '{"data":[{"maxswap":536870912,"disk":404041728,"ip":"192.168.1.5","status":"running","netout":272,"maxdisk":4294967296,"maxmem":536870912,"uptime":6176,"swap":0,"vmid":"101","nproc":"10","diskread":0,"cpu":0.00161487378340585,"netin":0,"name":"test2.dummy.tld","failcnt":0,"diskwrite":0,"mem":21299200,"type":"openvz","cpus":1},{"maxswap":2147483648,"disk":0,"ip":"10.0.0.1","status":"stopped","netout":0,"maxdisk":10737418240,"maxmem":1073741824,"uptime":0,"swap":0,"vmid":"102","nproc":0,"diskread":0,"cpu":0,"netin":0,"name":"test3.other.domain","failcnt":0,"diskwrite":0,"mem":0,"type":"openvz","cpus":2},{"maxswap":536870912,"disk":387194880,"ip":"192.168.1.1","status":"running","netout":272,"maxdisk":4294967296,"maxmem":536870912,"uptime":19449,"swap":0,"vmid":"100","nproc":"17","diskread":0,"cpu":0.000589570582552814,"netin":0,"name":"test.dummy.tld","failcnt":0,"diskwrite":0,"mem":28282880,"type":"openvz","cpus":1}]}'
|
|
141
|
+
)
|
|
109
142
|
|
|
110
|
-
|
|
111
|
-
|
|
143
|
+
expect(@server1.openvz_get).to be_an_instance_of Hash
|
|
144
|
+
expect(@server1.openvz_get.keys.sort).to be_eql %w(100 101)
|
|
112
145
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
146
|
+
server2 = Proxmox::Proxmox.new('http://localhost:8006/api2/json/', 'otherone', 'root', 'secret', 'pam')
|
|
147
|
+
expect(server2.openvz_get).to be_an_instance_of Hash
|
|
148
|
+
expect(server2.openvz_get.keys.sort).to be_eql %w(100 101 102)
|
|
149
|
+
end
|
|
116
150
|
end
|
|
117
151
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
152
|
+
describe 'openvz_post' do
|
|
153
|
+
it 'should create a container' do
|
|
154
|
+
# Create VM
|
|
155
|
+
stub_request(:post, 'http://localhost:8006/api2/json/nodes/localhost/openvz').with(
|
|
156
|
+
body: 'vmid=200&ostemplate=local%3Avztmpl%2Fubuntu-10.04-standard_10.04-4_i386.tar.gz',
|
|
157
|
+
headers: @common_headers_in).to_return(
|
|
158
|
+
status: 200,
|
|
159
|
+
headers: @common_headers_out,
|
|
160
|
+
body: '{"data":"UPID:localhost:00051DA0:119EAABB:521CCB19:vzcreate:200:root@pam:"}'
|
|
161
|
+
)
|
|
127
162
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
163
|
+
stub_request(:post, 'http://localhost:8006/api2/json/nodes/localhost/openvz').with(
|
|
164
|
+
body: 'hostname=vm1.domain.com&password=secret&memory=512&swap=512&disk=4&vmid=203&ostemplate=local%3Avztmpl%2Fubuntu-10.04-standard_10.04-4_i386.tar.gz',
|
|
165
|
+
headers: @common_headers_in).to_return(
|
|
166
|
+
status: 200,
|
|
167
|
+
headers: @common_headers_out,
|
|
168
|
+
body: '{"data":"UPID:localhost:00051DA0:119EAABC:521CCB19:vzcreate:203:root@pam:"}'
|
|
169
|
+
)
|
|
135
170
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
171
|
+
stub_request(:post, 'http://localhost:8006/api2/json/nodes/localhost/openvz').with(
|
|
172
|
+
body: 'vmid=204&ostemplate=local%3Avztmpl%2Fubuntu-10.04-standard_10.04-4_i386.tar.gz',
|
|
173
|
+
headers: @common_headers_in).to_return(
|
|
174
|
+
status: 500,
|
|
175
|
+
headers: { connection: 'close', server: 'pve-api-daemon/3.0', content_type: 'application/json;charset=UTF-8'
|
|
176
|
+
},
|
|
177
|
+
body: 'NOK: error code = 500'
|
|
178
|
+
)
|
|
144
179
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
180
|
+
# Create the vm
|
|
181
|
+
expect(@server1.openvz_post('ubuntu-10.04-standard_10.04-4_i386', 200)).to be_eql 'UPID:localhost:00051DA0:119EAABB:521CCB19:vzcreate:200:root@pam:'
|
|
182
|
+
expect(@server1.openvz_post('ubuntu-10.04-standard_10.04-4_i386', 203, 'hostname' => 'vm1.domain.com', 'password' => 'secret', 'memory' => 512, 'swap' => 512, 'disk' => 4)).to be_eql 'UPID:localhost:00051DA0:119EAABC:521CCB19:vzcreate:203:root@pam:'
|
|
183
|
+
expect(@server1.openvz_post('ubuntu-10.04-standard_10.04-4_i386', 204)).to be_eql 'NOK: error code = 500'
|
|
184
|
+
end
|
|
149
185
|
end
|
|
150
186
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
:
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
187
|
+
describe 'openvz_delete' do
|
|
188
|
+
it 'should delete openvz container' do
|
|
189
|
+
# Delete VM
|
|
190
|
+
stub_request(:delete, 'http://localhost:8006/api2/json/nodes/localhost/openvz/200').with(
|
|
191
|
+
headers: @common_headers_in).to_return(
|
|
192
|
+
status: 200,
|
|
193
|
+
headers: @common_headers_out,
|
|
194
|
+
body: '{"data":"UPID:localhost:0005C1EB:11BAA4EB:521D12B8:vzdestroy:200:root@pam:"}'
|
|
195
|
+
)
|
|
159
196
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
197
|
+
stub_request(:delete, 'http://localhost:8006/api2/json/nodes/localhost/openvz/201').with(
|
|
198
|
+
headers: @common_headers_in).to_return(
|
|
199
|
+
status: 500,
|
|
200
|
+
headers: @common_headers_out,
|
|
201
|
+
body: 'NOK: error code = 500'
|
|
202
|
+
)
|
|
166
203
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
204
|
+
# Delete the vm
|
|
205
|
+
expect(@server1.openvz_delete(200)).to be_eql 'UPID:localhost:0005C1EB:11BAA4EB:521D12B8:vzdestroy:200:root@pam:'
|
|
206
|
+
expect(@server1.openvz_delete(201)).to be_eql 'NOK: error code = 500'
|
|
207
|
+
end
|
|
170
208
|
end
|
|
171
209
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
:
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
210
|
+
describe 'openvz_status' do
|
|
211
|
+
it 'should get container status' do
|
|
212
|
+
# VM Status
|
|
213
|
+
stub_request(:get, 'http://localhost:8006/api2/json/nodes/localhost/openvz/200/status/current').with(
|
|
214
|
+
headers: @common_headers_in).to_return(
|
|
215
|
+
status: 200,
|
|
216
|
+
headers: @common_headers_out,
|
|
217
|
+
body: '{"data":{"maxswap":268435456,"disk":0,"ip":"-","status":"stopped","ha":0,"netout":0,"maxdisk":9.44473296573929e+21,"maxmem":268435456,"uptime":0,"swap":0,"nproc":0,"diskread":0,"cpu":0,"netin":0,"name":"CT200","failcnt":0,"diskwrite":0,"mem":0,"type":"openvz","cpus":1}}'
|
|
218
|
+
)
|
|
180
219
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
220
|
+
expect(@server1.openvz_status(200)).to be_an_instance_of Hash
|
|
221
|
+
expect(@server1.openvz_status(200)['status']).to be_eql 'stopped'
|
|
222
|
+
expect(@server1.openvz_status(200)['cpus']).to be_eql 1
|
|
223
|
+
end
|
|
184
224
|
end
|
|
185
225
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
226
|
+
describe 'openvz_start' do
|
|
227
|
+
it 'should start vm' do
|
|
228
|
+
stub_request(:post, 'http://localhost:8006/api2/json/nodes/localhost/openvz/200/status/start').with(
|
|
229
|
+
headers: @common_headers_in).to_return(
|
|
230
|
+
status: 200,
|
|
231
|
+
headers: @common_headers_out,
|
|
232
|
+
body: '{"data":"UPID:ks311324:0005D91C:11BE5277:521D1C23:vzstart:200:root@pam:"}'
|
|
233
|
+
)
|
|
194
234
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
235
|
+
expect(@server1.openvz_start(200)).to be_eql 'UPID:ks311324:0005D91C:11BE5277:521D1C23:vzstart:200:root@pam:'
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
describe 'openvz_stop' do
|
|
240
|
+
it 'should stop vm' do
|
|
241
|
+
stub_request(:post, 'http://localhost:8006/api2/json/nodes/localhost/openvz/200/status/stop').with(
|
|
242
|
+
headers: @common_headers_in).to_return(
|
|
243
|
+
status: 200,
|
|
244
|
+
headers: @common_headers_out,
|
|
245
|
+
body: '{"data":"UPID:ks311324:0005D91C:11BE5277:521D1C23:vzstop:200:root@pam:"}'
|
|
246
|
+
)
|
|
201
247
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
248
|
+
expect(@server1.openvz_stop(200)).to be_eql 'UPID:ks311324:0005D91C:11BE5277:521D1C23:vzstop:200:root@pam:'
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
describe 'openvz_shutdown' do
|
|
253
|
+
it 'should shutdown vm' do
|
|
254
|
+
stub_request(:post, 'http://localhost:8006/api2/json/nodes/localhost/openvz/200/status/shutdown').with(
|
|
255
|
+
headers: @common_headers_in).to_return(
|
|
256
|
+
status: 200,
|
|
257
|
+
headers: @common_headers_out,
|
|
258
|
+
body: '{"data":"UPID:ks311324:0005D91C:11BE5277:521D1C23:vzshutdown:200:root@pam:"}'
|
|
259
|
+
)
|
|
208
260
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
expect(@server1.openvz_shutdown(200)).to be_eql "UPID:ks311324:0005D91C:11BE5277:521D1C23:vzshutdown:200:root@pam:"
|
|
261
|
+
expect(@server1.openvz_shutdown(200)).to be_eql 'UPID:ks311324:0005D91C:11BE5277:521D1C23:vzshutdown:200:root@pam:'
|
|
262
|
+
end
|
|
212
263
|
end
|
|
213
264
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
:
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
265
|
+
describe 'openvz_config' do
|
|
266
|
+
it 'should get container config' do
|
|
267
|
+
# VM config
|
|
268
|
+
stub_request(:get, 'http://localhost:8006/api2/json/nodes/localhost/openvz/200/config').with(
|
|
269
|
+
headers: @common_headers_in).to_return(
|
|
270
|
+
status: 200,
|
|
271
|
+
headers: @common_headers_out,
|
|
272
|
+
body: '{"data":{"quotaugidlimit":0,"disk":0,"ostemplate":"ubuntu-10.04-standard_10.04-4_i386.tar.gz","nameserver":"127.0.0.1 192.168.1.1","memory":256,"searchdomain":"domain.com","onboot":0,"cpuunits":1000,"swap":256,"quotatime":0,"digest":"5a6f4052d559d3ecc89c849214f482217018a07e","cpus":1,"storage":"local"}}'
|
|
273
|
+
)
|
|
222
274
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
275
|
+
expect(@server1.openvz_config(200)).to be_an_instance_of Hash
|
|
276
|
+
expect(@server1.openvz_config(200)['searchdomain']).to be_eql 'domain.com'
|
|
277
|
+
expect(@server1.openvz_config(200)['ostemplate']).to be_eql 'ubuntu-10.04-standard_10.04-4_i386.tar.gz'
|
|
278
|
+
end
|
|
226
279
|
end
|
|
227
280
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
281
|
+
describe 'openvz_config_set' do
|
|
282
|
+
it 'should modify container config' do
|
|
283
|
+
# VM config
|
|
284
|
+
stub_request(:put, 'http://localhost:8006/api2/json/nodes/localhost/openvz/200/config').with(
|
|
285
|
+
headers: @common_headers_in).to_return(
|
|
286
|
+
status: 200,
|
|
287
|
+
headers: @common_headers_out,
|
|
288
|
+
body: '{"data":null}'
|
|
289
|
+
)
|
|
236
290
|
|
|
237
|
-
|
|
291
|
+
@server1.openvz_config_set(200, 'searchdomain' => 'other.com')
|
|
292
|
+
end
|
|
238
293
|
end
|
|
239
294
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: proxmox
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nicolas Ledez
|
|
@@ -89,6 +89,7 @@ extra_rdoc_files: []
|
|
|
89
89
|
files:
|
|
90
90
|
- ".gitignore"
|
|
91
91
|
- ".rspec"
|
|
92
|
+
- ".rubocop.yml"
|
|
92
93
|
- ".travis.yml"
|
|
93
94
|
- Gemfile
|
|
94
95
|
- Guardfile
|
|
@@ -127,3 +128,4 @@ summary: You need to manage a proxmox host with Ruby? This library is for you.
|
|
|
127
128
|
test_files:
|
|
128
129
|
- spec/lib/proxmox_spec.rb
|
|
129
130
|
- spec/spec_helper.rb
|
|
131
|
+
has_rdoc:
|