fog-proxmox 0.5.5 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +7 -0
- data/.travis.yml +1 -0
- data/.vscode/launch.json +3 -21
- data/.vscode/settings.json +7 -7
- data/Gemfile.lock +39 -39
- data/README.md +9 -2
- data/examples/compute.rb +20 -23
- data/examples/identity.rb +16 -21
- data/fog-proxmox.gemspec +1 -2
- data/lib/fog/compute/proxmox.rb +2 -8
- data/lib/fog/compute/proxmox/models/disk.rb +13 -11
- data/lib/fog/compute/proxmox/models/disks.rb +3 -5
- data/lib/fog/compute/proxmox/models/interface.rb +6 -11
- data/lib/fog/compute/proxmox/models/interfaces.rb +3 -5
- data/lib/fog/compute/proxmox/models/node.rb +38 -43
- data/lib/fog/compute/proxmox/models/nodes.rb +5 -11
- data/lib/fog/compute/proxmox/models/server.rb +123 -80
- data/lib/fog/compute/proxmox/models/server_config.rb +56 -24
- data/lib/fog/compute/proxmox/models/servers.rb +34 -26
- data/lib/fog/compute/proxmox/models/snapshot.rb +28 -14
- data/lib/fog/compute/proxmox/models/snapshots.rb +9 -17
- data/lib/fog/compute/proxmox/models/storage.rb +15 -11
- data/lib/fog/compute/proxmox/models/storages.rb +13 -22
- data/lib/fog/compute/proxmox/models/task.rb +10 -14
- data/lib/fog/compute/proxmox/models/tasks.rb +9 -18
- data/lib/fog/compute/proxmox/models/volume.rb +12 -12
- data/lib/fog/compute/proxmox/models/volumes.rb +10 -19
- data/lib/fog/compute/proxmox/requests/action_server.rb +1 -4
- data/lib/fog/compute/proxmox/requests/clone_server.rb +1 -4
- data/lib/fog/compute/proxmox/requests/create_backup.rb +1 -4
- data/lib/fog/compute/proxmox/requests/create_server.rb +1 -4
- data/lib/fog/compute/proxmox/requests/create_snapshot.rb +1 -4
- data/lib/fog/compute/proxmox/requests/create_spice.rb +1 -4
- data/lib/fog/compute/proxmox/requests/create_term.rb +1 -4
- data/lib/fog/compute/proxmox/requests/create_vnc.rb +1 -4
- data/lib/fog/compute/proxmox/requests/delete_server.rb +1 -4
- data/lib/fog/compute/proxmox/requests/delete_snapshot.rb +1 -4
- data/lib/fog/compute/proxmox/requests/get_node_statistics.rb +1 -4
- data/lib/fog/compute/proxmox/requests/get_server_config.rb +1 -4
- data/lib/fog/compute/proxmox/requests/get_server_status.rb +1 -4
- data/lib/fog/compute/proxmox/requests/{get_snapshot.rb → get_snapshot_config.rb} +5 -8
- data/lib/fog/compute/proxmox/requests/get_task.rb +1 -4
- data/lib/fog/compute/proxmox/requests/get_vnc.rb +1 -4
- data/lib/fog/compute/proxmox/requests/list_nodes.rb +1 -2
- data/lib/fog/compute/proxmox/requests/list_storages.rb +3 -1
- data/lib/fog/compute/proxmox/requests/log_task.rb +1 -4
- data/lib/fog/compute/proxmox/requests/move_disk.rb +1 -4
- data/lib/fog/compute/proxmox/requests/move_volume.rb +1 -4
- data/lib/fog/compute/proxmox/requests/next_vmid.rb +5 -3
- data/lib/fog/compute/proxmox/requests/resize_container.rb +1 -4
- data/lib/fog/compute/proxmox/requests/status_task.rb +1 -4
- data/lib/fog/compute/proxmox/requests/update_server.rb +1 -4
- data/lib/fog/identity/proxmox.rb +2 -8
- data/lib/fog/identity/proxmox/models/domain.rb +25 -21
- data/lib/fog/identity/proxmox/models/{ldap.rb → domain_type.rb} +9 -18
- data/lib/fog/identity/proxmox/models/domains.rb +6 -76
- data/lib/fog/identity/proxmox/models/group.rb +6 -19
- data/lib/fog/identity/proxmox/models/groups.rb +6 -12
- data/lib/fog/identity/proxmox/models/permission.rb +27 -31
- data/lib/fog/identity/proxmox/models/permissions.rb +8 -25
- data/lib/fog/identity/proxmox/models/pool.rb +9 -22
- data/lib/fog/identity/proxmox/models/pools.rb +7 -13
- data/lib/fog/identity/proxmox/models/principal.rb +1 -6
- data/lib/fog/identity/proxmox/models/role.rb +7 -20
- data/lib/fog/identity/proxmox/models/roles.rb +6 -13
- data/lib/fog/identity/proxmox/models/user.rb +7 -21
- data/lib/fog/identity/proxmox/models/users.rb +6 -12
- data/lib/fog/identity/proxmox/requests/check_permissions.rb +1 -4
- data/lib/fog/identity/proxmox/requests/list_roles.rb +0 -1
- data/lib/fog/identity/proxmox/requests/read_version.rb +1 -5
- data/lib/fog/identity/proxmox/requests/update_group.rb +2 -3
- data/lib/fog/identity/proxmox/requests/{add_permission.rb → update_permissions.rb} +4 -4
- data/lib/fog/network/proxmox/models/network.rb +12 -18
- data/lib/fog/network/proxmox/models/networks.rb +11 -17
- data/lib/fog/network/proxmox/models/node.rb +14 -10
- data/lib/fog/network/proxmox/models/nodes.rb +5 -11
- data/lib/fog/network/proxmox/requests/create_network.rb +1 -4
- data/lib/fog/network/proxmox/requests/delete_network.rb +1 -4
- data/lib/fog/network/proxmox/requests/get_network.rb +1 -4
- data/lib/fog/network/proxmox/requests/get_node.rb +1 -4
- data/lib/fog/network/proxmox/requests/power_node.rb +1 -4
- data/lib/fog/network/proxmox/requests/update_network.rb +1 -4
- data/lib/fog/{compute/proxmox/requests/check_vmid.rb → proxmox/attributes.rb} +9 -17
- data/lib/fog/proxmox/core.rb +2 -1
- data/lib/fog/proxmox/helpers/cpu_helper.rb +6 -3
- data/lib/fog/proxmox/helpers/disk_helper.rb +1 -1
- data/lib/fog/proxmox/helpers/nic_helper.rb +37 -22
- data/lib/fog/proxmox/version.rb +1 -1
- data/lib/fog/storage/proxmox.rb +1 -1
- data/spec/compute_spec.rb +64 -45
- data/spec/fixtures/proxmox/compute/containers.yml +1684 -4137
- data/spec/fixtures/proxmox/compute/identity_ticket.yml +4 -4
- data/spec/fixtures/proxmox/compute/nodes.yml +21 -21
- data/spec/fixtures/proxmox/compute/servers.yml +3065 -7741
- data/spec/fixtures/proxmox/compute/snapshots.yml +279 -827
- data/spec/fixtures/proxmox/compute/storages.yml +60 -21
- data/spec/fixtures/proxmox/compute/tasks.yml +56 -98
- data/spec/fixtures/proxmox/identity/auth.yml +6 -6
- data/spec/fixtures/proxmox/identity/domains.yml +252 -84
- data/spec/fixtures/proxmox/identity/groups.yml +93 -54
- data/spec/fixtures/proxmox/identity/identity_ticket.yml +4 -4
- data/spec/fixtures/proxmox/identity/permissions.yml +317 -79
- data/spec/fixtures/proxmox/identity/pools.yml +266 -71
- data/spec/fixtures/proxmox/identity/read_version.yml +6 -6
- data/spec/fixtures/proxmox/identity/roles.yml +96 -57
- data/spec/fixtures/proxmox/identity/users.yml +224 -107
- data/spec/fixtures/proxmox/network/identity_ticket.yml +4 -4
- data/spec/fixtures/proxmox/network/networks.yml +54 -95
- data/spec/helpers/nic_helper_spec.rb +4 -4
- data/spec/identity_spec.rb +38 -46
- data/spec/network_spec.rb +1 -1
- metadata +9 -23
- data/lib/fog/compute/proxmox/models/container.rb +0 -86
- data/lib/fog/compute/proxmox/models/container_config.rb +0 -114
- data/lib/fog/compute/proxmox/models/containers.rb +0 -43
- data/lib/fog/compute/proxmox/requests/get_node.rb +0 -44
- data/lib/fog/compute/proxmox/requests/get_storage.rb +0 -44
- data/lib/fog/identity/proxmox/models/activedirectory.rb +0 -57
- data/lib/fog/identity/proxmox/models/oath.rb +0 -50
- data/lib/fog/identity/proxmox/models/pam.rb +0 -46
- data/lib/fog/identity/proxmox/models/pve.rb +0 -46
- data/lib/fog/identity/proxmox/models/yubico.rb +0 -51
- data/lib/fog/identity/proxmox/requests/remove_permission.rb +0 -42
- data/lib/fog/proxmox/models/collection.rb +0 -85
- data/lib/fog/proxmox/models/model.rb +0 -58
@@ -17,8 +17,6 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
-
require 'fog/proxmox/json'
|
21
|
-
|
22
20
|
module Fog
|
23
21
|
module Network
|
24
22
|
class Proxmox
|
@@ -26,13 +24,12 @@ module Fog
|
|
26
24
|
class Real
|
27
25
|
def create_network(path_params, body_params)
|
28
26
|
node = path_params[:node]
|
29
|
-
|
27
|
+
request(
|
30
28
|
expects: [200],
|
31
29
|
method: 'POST',
|
32
30
|
path: "nodes/#{node}/network",
|
33
31
|
body: URI.encode_www_form(body_params)
|
34
32
|
)
|
35
|
-
Fog::Proxmox::Json.get_data(response)
|
36
33
|
end
|
37
34
|
end
|
38
35
|
|
@@ -18,8 +18,6 @@
|
|
18
18
|
|
19
19
|
# frozen_string_literal: true
|
20
20
|
|
21
|
-
require 'fog/proxmox/json'
|
22
|
-
|
23
21
|
module Fog
|
24
22
|
module Network
|
25
23
|
class Proxmox
|
@@ -28,12 +26,11 @@ module Fog
|
|
28
26
|
def delete_network(path_params)
|
29
27
|
node = path_params[:node]
|
30
28
|
iface = path_params[:iface]
|
31
|
-
|
29
|
+
request(
|
32
30
|
expects: [200],
|
33
31
|
method: 'DELETE',
|
34
32
|
path: "nodes/#{node}/network/#{iface}"
|
35
33
|
)
|
36
|
-
Fog::Proxmox::Json.get_data(response)
|
37
34
|
end
|
38
35
|
end
|
39
36
|
|
@@ -18,8 +18,6 @@
|
|
18
18
|
|
19
19
|
# frozen_string_literal: true
|
20
20
|
|
21
|
-
require 'fog/proxmox/json'
|
22
|
-
|
23
21
|
module Fog
|
24
22
|
module Network
|
25
23
|
class Proxmox
|
@@ -28,12 +26,11 @@ module Fog
|
|
28
26
|
def get_network(path_params)
|
29
27
|
node = path_params[:node]
|
30
28
|
iface = path_params[:iface]
|
31
|
-
|
29
|
+
request(
|
32
30
|
expects: [200],
|
33
31
|
method: 'GET',
|
34
32
|
path: "nodes/#{node}/network/#{iface}"
|
35
33
|
)
|
36
|
-
Fog::Proxmox::Json.get_data(response)
|
37
34
|
end
|
38
35
|
end
|
39
36
|
|
@@ -18,20 +18,17 @@
|
|
18
18
|
|
19
19
|
# frozen_string_literal: true
|
20
20
|
|
21
|
-
require 'fog/proxmox/json'
|
22
|
-
|
23
21
|
module Fog
|
24
22
|
module Network
|
25
23
|
class Proxmox
|
26
24
|
# class Real get_node request
|
27
25
|
class Real
|
28
26
|
def get_node(node)
|
29
|
-
|
27
|
+
request(
|
30
28
|
expects: [200],
|
31
29
|
method: 'GET',
|
32
30
|
path: "nodes/#{node}/status"
|
33
31
|
)
|
34
|
-
Fog::Proxmox::Json.get_data(response)
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
@@ -18,8 +18,6 @@
|
|
18
18
|
|
19
19
|
# frozen_string_literal: true
|
20
20
|
|
21
|
-
require 'fog/proxmox/json'
|
22
|
-
|
23
21
|
module Fog
|
24
22
|
module Network
|
25
23
|
class Proxmox
|
@@ -27,13 +25,12 @@ module Fog
|
|
27
25
|
class Real
|
28
26
|
def power_node(path_params, body_params)
|
29
27
|
node = path_params[:node]
|
30
|
-
|
28
|
+
request(
|
31
29
|
expects: [200],
|
32
30
|
method: 'POST',
|
33
31
|
path: "nodes/#{node}/status",
|
34
32
|
body: URI.encode_www_form(body_params)
|
35
33
|
)
|
36
|
-
Fog::Proxmox::Json.get_data(response)
|
37
34
|
end
|
38
35
|
end
|
39
36
|
|
@@ -17,8 +17,6 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
-
require 'fog/proxmox/json'
|
21
|
-
|
22
20
|
module Fog
|
23
21
|
module Network
|
24
22
|
class Proxmox
|
@@ -27,13 +25,12 @@ module Fog
|
|
27
25
|
def update_network(path_params, body_params)
|
28
26
|
node = path_params[:node]
|
29
27
|
iface = path_params[:iface]
|
30
|
-
|
28
|
+
request(
|
31
29
|
expects: [200],
|
32
30
|
method: 'PUT',
|
33
31
|
path: "nodes/#{node}/network/#{iface}",
|
34
32
|
body: URI.encode_www_form(body_params)
|
35
33
|
)
|
36
|
-
Fog::Proxmox::Json.get_data(response)
|
37
34
|
end
|
38
35
|
end
|
39
36
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
# Copyright 2018 Tristan Robert
|
3
4
|
|
4
5
|
# This file is part of Fog::Proxmox.
|
@@ -16,25 +17,16 @@
|
|
16
17
|
# You should have received a copy of the GNU General Public License
|
17
18
|
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
18
19
|
|
19
|
-
# frozen_string_literal: true
|
20
|
-
|
21
20
|
module Fog
|
22
|
-
module
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
request(
|
28
|
-
expects: [200],
|
29
|
-
method: 'GET',
|
30
|
-
path: 'cluster/nextid',
|
31
|
-
query: "vmid=#{vmid}"
|
32
|
-
)
|
33
|
-
end
|
21
|
+
module Proxmox
|
22
|
+
# module Attributes mixins
|
23
|
+
module Attributes
|
24
|
+
def self.set_attr(attr_name, attributes, new_attributes)
|
25
|
+
attributes[attr_name.to_sym] = new_attributes[attr_name] unless new_attributes[attr_name].nil?
|
34
26
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
27
|
+
def self.set_attr_and_sym(attr_name, attributes, new_attributes)
|
28
|
+
self.set_attr(attr_name, attributes, new_attributes)
|
29
|
+
self.set_attr(attr_name.to_sym, attributes, new_attributes)
|
38
30
|
end
|
39
31
|
end
|
40
32
|
end
|
data/lib/fog/proxmox/core.rb
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
|
20
20
|
require 'fog/json'
|
21
21
|
require 'fog/proxmox/variables'
|
22
|
+
require 'fog/proxmox/json'
|
22
23
|
|
23
24
|
module Fog
|
24
25
|
module Proxmox
|
@@ -93,7 +94,7 @@ module Fog
|
|
93
94
|
error
|
94
95
|
end
|
95
96
|
end
|
96
|
-
response
|
97
|
+
Fog::Proxmox::Json.get_data(response)
|
97
98
|
end
|
98
99
|
|
99
100
|
def headers(method, additional_headers)
|
@@ -22,11 +22,13 @@ module Fog
|
|
22
22
|
# module Cpu mixins
|
23
23
|
module CpuHelper
|
24
24
|
def self.extract(cpu)
|
25
|
-
|
25
|
+
cpu_regexp = /^(cputype=)?(\w+)(,flags=){0,1}(\+[\w-]+){0,1}[;]{0,1}(\+[\w-]+){0,1}/
|
26
|
+
cpu && cpu.is_a?(String) && cpu&.match(cpu_regexp) ? cpu&.scan(cpu_regexp)&.first : []
|
26
27
|
end
|
27
28
|
|
28
29
|
def self.extract_type(cpu)
|
29
|
-
extract(cpu)
|
30
|
+
cpu_a = extract(cpu)
|
31
|
+
cpu_a[1] unless cpu_a.empty? || cpu_a.size < 2
|
30
32
|
end
|
31
33
|
|
32
34
|
def self.extract_pcid(cpu)
|
@@ -38,7 +40,8 @@ module Fog
|
|
38
40
|
end
|
39
41
|
|
40
42
|
def self.has?(value, cpu)
|
41
|
-
extract(cpu)
|
43
|
+
cpu_a = extract(cpu)
|
44
|
+
cpu_a.include? value
|
42
45
|
end
|
43
46
|
end
|
44
47
|
end
|
@@ -28,21 +28,33 @@ module Fog
|
|
28
28
|
nic_value[/([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})/]
|
29
29
|
end
|
30
30
|
|
31
|
-
def self.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
31
|
+
def self.model_regexp
|
32
|
+
/^model=(\w+)[,].+/
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.name_regexp
|
36
|
+
/^name=(\w+)[,].+/
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.nic_creation_regexp
|
40
|
+
/^(\w+)[=]{1}([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2}).+/
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.has_model?(nic_value)
|
44
|
+
nic_value.match(self.model_regexp)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.has_name?(nic_value)
|
48
|
+
nic_value.match(self.name_regexp)
|
38
49
|
end
|
39
50
|
|
40
|
-
def self.
|
41
|
-
|
42
|
-
|
43
|
-
|
51
|
+
def self.extract_nic_id(nic_value)
|
52
|
+
if self.has_model?(nic_value)
|
53
|
+
nic_value.scan(self.model_regexp).first.first
|
54
|
+
elsif self.has_name?(nic_value)
|
55
|
+
nic_value.scan(self.name_regexp).first.first
|
44
56
|
else
|
45
|
-
nic_value.scan(
|
57
|
+
nic_value.scan(self.nic_creation_regexp).first.first
|
46
58
|
end
|
47
59
|
end
|
48
60
|
|
@@ -52,18 +64,21 @@ module Fog
|
|
52
64
|
addresses
|
53
65
|
end
|
54
66
|
|
55
|
-
def self.
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
67
|
+
def self.nic_name(nic)
|
68
|
+
if nic.has_key?(:model)
|
69
|
+
"model"
|
70
|
+
elsif nic.has_key?(:name)
|
71
|
+
"name"
|
72
|
+
else
|
73
|
+
""
|
74
|
+
end
|
60
75
|
end
|
61
76
|
|
62
|
-
def self.
|
63
|
-
|
64
|
-
options = nic.reject { |key, _value|
|
65
|
-
|
66
|
-
{ "#{nic[:id]}":
|
77
|
+
def self.flatten(nic)
|
78
|
+
nic_id = self.nic_name(nic) + "=" + nic[self.nic_name(nic).to_sym]
|
79
|
+
options = nic.reject { |key, _value| [self.nic_name(nic).to_sym, :id].include? key }
|
80
|
+
nic_id += ',' + Fog::Proxmox::Hash.stringify(options) unless options.empty?
|
81
|
+
{ "#{nic[:id]}": nic_id }
|
67
82
|
end
|
68
83
|
|
69
84
|
def self.valid?(key)
|
data/lib/fog/proxmox/version.rb
CHANGED
data/lib/fog/storage/proxmox.rb
CHANGED
data/spec/compute_spec.rb
CHANGED
@@ -37,27 +37,29 @@ describe Fog::Compute::Proxmox do
|
|
37
37
|
it 'Manage tasks' do
|
38
38
|
VCR.use_cassette('tasks') do
|
39
39
|
# List all tasks
|
40
|
-
|
41
|
-
node_name = '
|
42
|
-
node = @service.nodes.
|
43
|
-
tasks = node.tasks.
|
40
|
+
filters = { limit: 1 }
|
41
|
+
node_name = 'proxmox'
|
42
|
+
node = @service.nodes.get node_name
|
43
|
+
tasks = node.tasks.all(filters)
|
44
44
|
tasks.wont_be_nil
|
45
45
|
tasks.wont_be_empty
|
46
|
+
tasks.size.must_equal 1
|
46
47
|
# Get task
|
47
48
|
upid = tasks[0].upid
|
48
|
-
task = node.tasks.
|
49
|
+
task = node.tasks.get(upid)
|
49
50
|
task.wont_be_nil
|
50
51
|
# Stop task
|
51
52
|
task.stop
|
52
|
-
task.
|
53
|
+
task.wait_for { finished? }
|
54
|
+
task.finished?.must_equal true
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
58
|
it 'Manage nodes' do
|
57
59
|
VCR.use_cassette('nodes') do
|
58
60
|
# Get node
|
59
|
-
node_name = '
|
60
|
-
node = @service.nodes.
|
61
|
+
node_name = 'proxmox'
|
62
|
+
node = @service.nodes.get node_name
|
61
63
|
# Get statistics data
|
62
64
|
data = node.statistics
|
63
65
|
data.wont_be_nil
|
@@ -72,26 +74,29 @@ describe Fog::Compute::Proxmox do
|
|
72
74
|
it 'Manage storages' do
|
73
75
|
VCR.use_cassette('storages') do
|
74
76
|
# Get node
|
75
|
-
node_name = '
|
76
|
-
node = @service.nodes.
|
77
|
+
node_name = 'proxmox'
|
78
|
+
node = @service.nodes.get node_name
|
77
79
|
# List all storages
|
78
80
|
storages = node.storages.all
|
79
81
|
storages.wont_be_nil
|
80
82
|
storages.wont_be_empty
|
83
|
+
storages.size.must_equal 2
|
81
84
|
# List by content type
|
82
85
|
storages = node.storages.list_by_content_type 'iso'
|
83
86
|
storages.wont_be_nil
|
84
87
|
storages.wont_be_empty
|
88
|
+
storages.size.must_equal 1
|
85
89
|
# Get storage
|
86
|
-
storage = node.storages.
|
90
|
+
storage = node.storages.get('local')
|
87
91
|
storage.wont_be_nil
|
92
|
+
storage.identity.must_equal 'local'
|
88
93
|
end
|
89
94
|
end
|
90
95
|
|
91
96
|
it 'CRUD servers' do
|
92
97
|
VCR.use_cassette('servers') do
|
93
|
-
node_name = '
|
94
|
-
node = @service.nodes.
|
98
|
+
node_name = 'proxmox'
|
99
|
+
node = @service.nodes.get node_name
|
95
100
|
# Get next vmid
|
96
101
|
vmid = node.servers.next_id
|
97
102
|
server_hash = { vmid: vmid }
|
@@ -102,7 +107,9 @@ describe Fog::Compute::Proxmox do
|
|
102
107
|
valid = node.servers.id_valid? 99
|
103
108
|
valid.must_equal false
|
104
109
|
# Create 1st time
|
105
|
-
node.servers.create(server_hash)
|
110
|
+
server = node.servers.create(server_hash)
|
111
|
+
ok = server.persisted?
|
112
|
+
ok.must_equal true
|
106
113
|
# Check already used vmid
|
107
114
|
valid = node.servers.id_valid? vmid
|
108
115
|
valid.must_equal false
|
@@ -138,15 +145,15 @@ describe Fog::Compute::Proxmox do
|
|
138
145
|
# Get clone
|
139
146
|
clone = node.servers.get newid
|
140
147
|
# Template this clone (read-only)
|
141
|
-
clone.
|
148
|
+
clone.create_template
|
142
149
|
# Get clone disk image
|
143
150
|
image = clone.images.first
|
144
151
|
image.wont_be_nil
|
145
152
|
# Delete clone
|
146
153
|
clone.destroy
|
147
154
|
proc do
|
148
|
-
node.servers.get newid
|
149
|
-
end.must_raise
|
155
|
+
clone = node.servers.get newid
|
156
|
+
end.must_raise Fog::Errors::NotFound
|
150
157
|
# Create 2nd time must fails
|
151
158
|
proc do
|
152
159
|
node.servers.create server_hash
|
@@ -170,10 +177,11 @@ describe Fog::Compute::Proxmox do
|
|
170
177
|
config = server.config
|
171
178
|
config.identity.must_equal vmid
|
172
179
|
disks = server.config.disks
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
180
|
+
interfaces = server.config.interfaces
|
181
|
+
interfaces.wont_be_nil
|
182
|
+
interfaces.wont_be_empty
|
183
|
+
net0 = interfaces.get('net0')
|
184
|
+
net0.wont_be_nil
|
177
185
|
disks.wont_be_nil
|
178
186
|
disks.wont_be_empty
|
179
187
|
virtio0 = disks.get('virtio0')
|
@@ -185,7 +193,6 @@ describe Fog::Compute::Proxmox do
|
|
185
193
|
mac_address.wont_be_nil
|
186
194
|
# all servers
|
187
195
|
servers_all = node.servers.all
|
188
|
-
servers_all.wont_be_nil
|
189
196
|
servers_all.wont_be_empty
|
190
197
|
servers_all.must_include server
|
191
198
|
# server not running exception
|
@@ -264,21 +271,21 @@ describe Fog::Compute::Proxmox do
|
|
264
271
|
server.destroy
|
265
272
|
proc do
|
266
273
|
node.servers.get vmid
|
267
|
-
end.must_raise
|
274
|
+
end.must_raise Fog::Errors::NotFound
|
268
275
|
end
|
269
276
|
end
|
270
277
|
|
271
278
|
it 'CRUD snapshots' do
|
272
279
|
VCR.use_cassette('snapshots') do
|
273
|
-
node_name = '
|
274
|
-
node = @service.nodes.
|
280
|
+
node_name = 'proxmox'
|
281
|
+
node = @service.nodes.get node_name
|
275
282
|
vmid = node.servers.next_id
|
276
283
|
server_hash = { vmid: vmid }
|
277
284
|
node.servers.create server_hash
|
278
285
|
# Create
|
279
286
|
snapname = 'snapshot1'
|
280
287
|
server = node.servers.get vmid
|
281
|
-
snapshot_hash = {
|
288
|
+
snapshot_hash = { name: snapname }
|
282
289
|
server.snapshots.create(snapshot_hash)
|
283
290
|
# Find by id
|
284
291
|
snapshot = server.snapshots.get snapname
|
@@ -299,14 +306,13 @@ describe Fog::Compute::Proxmox do
|
|
299
306
|
|
300
307
|
it 'CRUD containers' do
|
301
308
|
VCR.use_cassette('containers') do
|
302
|
-
node_name = '
|
303
|
-
node = @service.nodes.
|
309
|
+
node_name = 'proxmox'
|
310
|
+
node = @service.nodes.get node_name
|
311
|
+
node.wont_be_nil
|
304
312
|
# Get next vmid
|
305
313
|
vmid = node.containers.next_id
|
306
314
|
ostemplate = 'local:vztmpl/alpine-3.8-default_20180913_amd64.tar.xz'
|
307
|
-
container_hash = {
|
308
|
-
storage: 'local-lvm',
|
309
|
-
ostemplate: ostemplate, password: 'proxmox01', rootfs: 'local-lvm:1' }
|
315
|
+
container_hash = { ostemplate: ostemplate, storage: 'local-lvm', password: 'proxmox01', rootfs: 'local-lvm:1' }
|
310
316
|
# Check valid vmid
|
311
317
|
valid = node.containers.id_valid? vmid
|
312
318
|
valid.must_equal true
|
@@ -314,7 +320,7 @@ describe Fog::Compute::Proxmox do
|
|
314
320
|
valid = node.containers.id_valid? 99
|
315
321
|
valid.must_equal false
|
316
322
|
# Create 1st time
|
317
|
-
node.containers.create(container_hash)
|
323
|
+
node.containers.create(container_hash.merge(vmid: vmid))
|
318
324
|
# Check already used vmid
|
319
325
|
valid = node.containers.id_valid? vmid
|
320
326
|
valid.must_equal false
|
@@ -323,6 +329,10 @@ describe Fog::Compute::Proxmox do
|
|
323
329
|
# Get container
|
324
330
|
container = node.containers.get vmid
|
325
331
|
container.wont_be_nil
|
332
|
+
rootfs_a = container.config.disks.select { |disk| disk.rootfs? }
|
333
|
+
rootfs_a.wont_be_empty
|
334
|
+
rootfs = rootfs_a.first
|
335
|
+
rootfs.wont_be_nil
|
326
336
|
# Backup it
|
327
337
|
container.backup(compress: 'lzo')
|
328
338
|
# Get this backup image
|
@@ -333,6 +343,7 @@ describe Fog::Compute::Proxmox do
|
|
333
343
|
container.restore(backup, storage: 'local-lvm')
|
334
344
|
# Delete it
|
335
345
|
backup.destroy
|
346
|
+
container.backups.must_be_empty
|
336
347
|
# Add mount points
|
337
348
|
# Find available storages with images
|
338
349
|
storages = node.storages.list_by_content_type 'images'
|
@@ -341,7 +352,7 @@ describe Fog::Compute::Proxmox do
|
|
341
352
|
options = { mp: '/opt/app', backup: 0, replicate: 0, quota: 1 }
|
342
353
|
container.attach(mp0, options)
|
343
354
|
# Fetch mount points
|
344
|
-
mount_points = container.config.
|
355
|
+
mount_points = container.config.disks.select { |disk| disk.mount_point? }
|
345
356
|
mount_points.wont_be_empty
|
346
357
|
mount_points.get('mp0').wont_be_nil
|
347
358
|
# Remove mount points
|
@@ -361,10 +372,10 @@ describe Fog::Compute::Proxmox do
|
|
361
372
|
clone.destroy
|
362
373
|
proc do
|
363
374
|
node.containers.get newid
|
364
|
-
end.must_raise
|
375
|
+
end.must_raise Fog::Errors::NotFound
|
365
376
|
# Create 2nd time must fails
|
366
377
|
proc do
|
367
|
-
node.containers.create
|
378
|
+
node.containers.create(container_hash.merge(vmid: vmid))
|
368
379
|
end.must_raise Excon::Errors::InternalServerError
|
369
380
|
# Update config container
|
370
381
|
# Resize rootfs container
|
@@ -382,13 +393,13 @@ describe Fog::Compute::Proxmox do
|
|
382
393
|
config = container.config
|
383
394
|
config.wont_be_nil
|
384
395
|
config.identity.must_equal vmid
|
385
|
-
# Get a mac address
|
386
|
-
mac_address = container.config.mac_addresses.first
|
387
|
-
mac_address.wont_be_nil
|
388
396
|
# Fetch nics
|
389
397
|
interfaces = container.config.interfaces
|
390
398
|
interfaces.wont_be_empty
|
391
399
|
interfaces.get('net0').wont_be_nil
|
400
|
+
# Get a mac address
|
401
|
+
mac_address = container.config.mac_addresses.first
|
402
|
+
mac_address.wont_be_nil
|
392
403
|
# all containers
|
393
404
|
containers_all = node.containers.all
|
394
405
|
containers_all.wont_be_nil
|
@@ -399,14 +410,22 @@ describe Fog::Compute::Proxmox do
|
|
399
410
|
container.wait_for { ready? }
|
400
411
|
status = container.ready?
|
401
412
|
status.must_equal true
|
402
|
-
#
|
403
|
-
proc do
|
404
|
-
container.action('suspend')
|
405
|
-
end.must_raise Fog::Errors::Error
|
406
|
-
# Resume container not implemented
|
413
|
+
# Start console
|
407
414
|
proc do
|
408
|
-
container.
|
415
|
+
container.start_console
|
409
416
|
end.must_raise Fog::Errors::Error
|
417
|
+
spice = container.start_console(console: 'spice')
|
418
|
+
spice['password'].wont_be_nil
|
419
|
+
# Suspend container (: command 'lxc-checkpoint -n 100 -s -D /var/lib/vz/dump' failed: exit code 1)
|
420
|
+
# container.action('suspend')
|
421
|
+
# container.wait_for { container.qmpstatus == 'paused' }
|
422
|
+
# qmpstatus = container.qmpstatus
|
423
|
+
# qmpstatus.must_equal 'paused'
|
424
|
+
# Resume server
|
425
|
+
# container.action('resume')
|
426
|
+
# container.wait_for { ready? }
|
427
|
+
# status = container.ready?
|
428
|
+
# status.must_equal true
|
410
429
|
# Stop container
|
411
430
|
container.action('stop')
|
412
431
|
container.wait_for { container.status == 'stopped' }
|
@@ -421,7 +440,7 @@ describe Fog::Compute::Proxmox do
|
|
421
440
|
storage.volumes.each(&:destroy)
|
422
441
|
proc do
|
423
442
|
node.containers.get vmid
|
424
|
-
end.must_raise
|
443
|
+
end.must_raise Fog::Errors::NotFound
|
425
444
|
end
|
426
445
|
end
|
427
446
|
end
|