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
data/fog-proxmox.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
1
|
# Copyright 2018 Tristan Robert
|
3
2
|
|
4
3
|
# This file is part of Fog::Proxmox.
|
@@ -40,7 +39,7 @@ Gem::Specification.new do |spec|
|
|
40
39
|
spec.required_ruby_version = '>= 2.3'
|
41
40
|
spec.rubygems_version = '~> 2.6'
|
42
41
|
|
43
|
-
spec.add_development_dependency 'bundler', '~>
|
42
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
44
43
|
spec.add_development_dependency 'debase', '~> 0.2.2'
|
45
44
|
spec.add_development_dependency 'debride', '~> 1.8'
|
46
45
|
spec.add_development_dependency 'fasterer', '~> 0.3'
|
data/lib/fog/compute/proxmox.rb
CHANGED
@@ -47,20 +47,15 @@ module Fog
|
|
47
47
|
collection :tasks
|
48
48
|
model :snapshot
|
49
49
|
collection :snapshots
|
50
|
-
model :container
|
51
|
-
collection :containers
|
52
|
-
model :container_config
|
53
50
|
|
54
51
|
# Requests
|
55
52
|
request_path 'fog/compute/proxmox/requests'
|
56
53
|
|
57
54
|
# Manage nodes cluster
|
58
55
|
request :list_nodes
|
59
|
-
request :get_node
|
60
56
|
request :get_node_statistics
|
61
|
-
# Manage servers
|
62
57
|
request :next_vmid
|
63
|
-
|
58
|
+
# Manage servers
|
64
59
|
request :list_servers
|
65
60
|
request :create_server
|
66
61
|
request :get_server_status
|
@@ -83,7 +78,6 @@ module Fog
|
|
83
78
|
request :create_backup
|
84
79
|
# Manage storages
|
85
80
|
request :list_storages
|
86
|
-
request :get_storage
|
87
81
|
# Tasks
|
88
82
|
request :list_tasks
|
89
83
|
request :get_task
|
@@ -92,7 +86,7 @@ module Fog
|
|
92
86
|
request :log_task
|
93
87
|
# CRUD snapshots
|
94
88
|
request :list_snapshots
|
95
|
-
request :
|
89
|
+
request :get_snapshot_config
|
96
90
|
request :create_snapshot
|
97
91
|
request :update_snapshot
|
98
92
|
request :delete_snapshot
|
@@ -1,12 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# Copyright 2018 Tristan Robert
|
3
|
-
|
4
|
-
# This file is part of Fog::Proxmox.
|
5
|
-
|
6
|
-
# Fog::Proxmox is free software: you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation, either version 3 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
1
|
# Copyright 2018 Tristan Robert
|
11
2
|
|
12
3
|
# This file is part of Fog::Proxmox.
|
@@ -26,14 +17,13 @@
|
|
26
17
|
|
27
18
|
# frozen_string_literal: true
|
28
19
|
|
29
|
-
require 'fog/proxmox/models/model'
|
30
20
|
require 'fog/proxmox/helpers/disk_helper'
|
31
21
|
|
32
22
|
module Fog
|
33
23
|
module Compute
|
34
24
|
class Proxmox
|
35
25
|
# class Disk model
|
36
|
-
class Disk < Fog::
|
26
|
+
class Disk < Fog::Model
|
37
27
|
identity :id
|
38
28
|
attribute :volid
|
39
29
|
attribute :size
|
@@ -64,6 +54,18 @@ module Fog
|
|
64
54
|
def rootfs?
|
65
55
|
id == 'rootfs'
|
66
56
|
end
|
57
|
+
|
58
|
+
def mount_point?
|
59
|
+
id.match(/(mp)(\d+)/)
|
60
|
+
end
|
61
|
+
|
62
|
+
def controller?
|
63
|
+
id.match(/(scsi|ide|sata|virtio)(\d+)/)
|
64
|
+
end
|
65
|
+
|
66
|
+
def flatten
|
67
|
+
Fog::Proxmox::DiskHelper.flatten(attributes)
|
68
|
+
end
|
67
69
|
end
|
68
70
|
end
|
69
71
|
end
|
@@ -17,23 +17,21 @@
|
|
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/models/collection'
|
21
20
|
require 'fog/compute/proxmox/models/disk'
|
22
21
|
|
23
22
|
module Fog
|
24
23
|
module Compute
|
25
24
|
class Proxmox
|
26
25
|
# class Disks Collection of disk
|
27
|
-
class Disks < Fog::
|
26
|
+
class Disks < Fog::Collection
|
28
27
|
model Fog::Compute::Proxmox::Disk
|
29
28
|
|
30
|
-
def all
|
29
|
+
def all
|
31
30
|
self
|
32
31
|
end
|
33
32
|
|
34
33
|
def get(id)
|
35
|
-
|
36
|
-
return cached_disk if cached_disk
|
34
|
+
all.find { |disk| disk.identity === id }
|
37
35
|
end
|
38
36
|
|
39
37
|
def next_device(controller)
|
@@ -1,12 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# Copyright 2018 Tristan Robert
|
3
|
-
|
4
|
-
# This file is part of Fog::Proxmox.
|
5
|
-
|
6
|
-
# Fog::Proxmox is free software: you can redistribute it and/or modify
|
7
|
-
# it under the terms of the GNU General Public License as published by
|
8
|
-
# the Free Software Foundation, either version 3 of the License, or
|
9
|
-
# (at your option) any later version.
|
10
1
|
# Copyright 2018 Tristan Robert
|
11
2
|
|
12
3
|
# This file is part of Fog::Proxmox.
|
@@ -26,13 +17,13 @@
|
|
26
17
|
|
27
18
|
# frozen_string_literal: true
|
28
19
|
|
29
|
-
require
|
20
|
+
require "fog/proxmox/helpers/nic_helper"
|
30
21
|
|
31
22
|
module Fog
|
32
23
|
module Compute
|
33
24
|
class Proxmox
|
34
25
|
# class Interface model
|
35
|
-
class Interface < Fog::
|
26
|
+
class Interface < Fog::Model
|
36
27
|
identity :id
|
37
28
|
attribute :mac
|
38
29
|
attribute :model
|
@@ -45,6 +36,10 @@ module Fog
|
|
45
36
|
attribute :rate
|
46
37
|
attribute :queues
|
47
38
|
attribute :tag
|
39
|
+
|
40
|
+
def flatten
|
41
|
+
Fog::Proxmox::NicHelper.flatten(attributes)
|
42
|
+
end
|
48
43
|
end
|
49
44
|
end
|
50
45
|
end
|
@@ -17,7 +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/models/collection'
|
21
20
|
require 'fog/compute/proxmox/models/interface'
|
22
21
|
require 'fog/proxmox/helpers/controller_helper'
|
23
22
|
|
@@ -25,16 +24,15 @@ module Fog
|
|
25
24
|
module Compute
|
26
25
|
class Proxmox
|
27
26
|
# class Interfaces Collection of nodes of cluster
|
28
|
-
class Interfaces < Fog::
|
27
|
+
class Interfaces < Fog::Collection
|
29
28
|
model Fog::Compute::Proxmox::Interface
|
30
29
|
|
31
|
-
def all
|
30
|
+
def all
|
32
31
|
self
|
33
32
|
end
|
34
33
|
|
35
34
|
def get(id)
|
36
|
-
|
37
|
-
return cached_interface if cached_interface
|
35
|
+
all.find { |interface| interface.identity === id }
|
38
36
|
end
|
39
37
|
|
40
38
|
def next_nicid
|
@@ -26,72 +26,67 @@
|
|
26
26
|
|
27
27
|
# frozen_string_literal: true
|
28
28
|
|
29
|
-
require 'fog/proxmox/
|
29
|
+
require 'fog/proxmox/attributes'
|
30
30
|
|
31
31
|
module Fog
|
32
32
|
module Compute
|
33
33
|
class Proxmox
|
34
34
|
# class Node model of VMs
|
35
|
-
class Node < Fog::
|
35
|
+
class Node < Fog::Model
|
36
36
|
identity :node
|
37
|
+
attribute :cpu
|
38
|
+
attribute :level
|
39
|
+
attribute :maxcpu
|
40
|
+
attribute :maxmem
|
41
|
+
attribute :mem
|
42
|
+
attribute :maxdisk
|
43
|
+
attribute :disk
|
44
|
+
attribute :ssl_fingerprint
|
37
45
|
attribute :status
|
38
|
-
attribute :wait
|
39
46
|
attribute :uptime
|
40
|
-
attribute :pveversion
|
41
|
-
attribute :ksm
|
42
|
-
attribute :kversion
|
43
|
-
attribute :loadavg
|
44
|
-
attribute :rootfs
|
45
|
-
attribute :cpu
|
46
|
-
attribute :cpuinfo
|
47
|
-
attribute :memory
|
48
|
-
attribute :idle
|
49
|
-
attribute :swap
|
50
|
-
attribute :servers
|
51
47
|
attribute :tasks
|
48
|
+
attribute :servers
|
49
|
+
attribute :containers
|
52
50
|
attribute :storages
|
53
51
|
|
54
|
-
def
|
55
|
-
|
52
|
+
def initialize(new_attributes = {})
|
53
|
+
prepare_service_value(new_attributes)
|
54
|
+
Fog::Proxmox::Attributes.set_attr_and_sym('node', attributes, new_attributes)
|
55
|
+
requires :node
|
56
|
+
initialize_tasks
|
57
|
+
initialize_servers
|
58
|
+
initialize_containers
|
59
|
+
initialize_storages
|
60
|
+
super(new_attributes)
|
56
61
|
end
|
57
62
|
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
node: self)
|
62
|
-
end
|
63
|
+
def backup(options = {})
|
64
|
+
task_upid = service.backup({ node: node }, options)
|
65
|
+
task_upid
|
63
66
|
end
|
64
67
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
68
|
+
def statistics(output = 'rrddata', options = { timeframe: 'hour', cf: 'AVERAGE'})
|
69
|
+
path_params = { node: node, output: output }
|
70
|
+
query_params = options
|
71
|
+
service.get_node_statistics(path_params,query_params)
|
70
72
|
end
|
71
73
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
74
|
+
private
|
75
|
+
|
76
|
+
def initialize_tasks
|
77
|
+
attributes[:tasks] = Fog::Compute::Proxmox::Tasks.new(service: service, node_id: node)
|
77
78
|
end
|
78
79
|
|
79
|
-
def
|
80
|
-
|
81
|
-
Fog::Compute::Proxmox::Storages.new(service: service,
|
82
|
-
node: self)
|
83
|
-
end
|
80
|
+
def initialize_servers
|
81
|
+
attributes[:servers] = Fog::Compute::Proxmox::Servers.new(service: service, node_id: node, type: 'qemu')
|
84
82
|
end
|
85
83
|
|
86
|
-
def
|
87
|
-
|
88
|
-
task_upid
|
84
|
+
def initialize_containers
|
85
|
+
attributes[:containers] = Fog::Compute::Proxmox::Servers.new(service: service, node_id: node, type: 'lxc')
|
89
86
|
end
|
90
87
|
|
91
|
-
def
|
92
|
-
|
93
|
-
query_params = options
|
94
|
-
service.get_node_statistics(path_params,query_params)
|
88
|
+
def initialize_storages
|
89
|
+
attributes[:storages] = Fog::Compute::Proxmox::Storages.new(service: service, node_id: node)
|
95
90
|
end
|
96
91
|
|
97
92
|
end
|
@@ -17,27 +17,21 @@
|
|
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/models/collection'
|
21
20
|
require 'fog/compute/proxmox/models/node'
|
22
21
|
|
23
22
|
module Fog
|
24
23
|
module Compute
|
25
24
|
class Proxmox
|
26
25
|
# class Nodes Collection of nodes of cluster
|
27
|
-
class Nodes < Fog::
|
26
|
+
class Nodes < Fog::Collection
|
28
27
|
model Fog::Compute::Proxmox::Node
|
29
28
|
|
30
|
-
def all
|
31
|
-
|
29
|
+
def all
|
30
|
+
load service.list_nodes
|
32
31
|
end
|
33
32
|
|
34
|
-
def
|
35
|
-
|
36
|
-
return cached_node if cached_node
|
37
|
-
node_hash = service.get_node(id)
|
38
|
-
Fog::Compute::Proxmox::Node.new(
|
39
|
-
node_hash.merge(service: service, node: id)
|
40
|
-
)
|
33
|
+
def get(id)
|
34
|
+
all.find { |node| node.identity === id }
|
41
35
|
end
|
42
36
|
end
|
43
37
|
end
|
@@ -20,6 +20,7 @@
|
|
20
20
|
require 'fog/compute/models/server'
|
21
21
|
require 'fog/proxmox/helpers/disk_helper'
|
22
22
|
require 'fog/proxmox/hash'
|
23
|
+
require 'fog/proxmox/errors'
|
23
24
|
|
24
25
|
module Fog
|
25
26
|
module Compute
|
@@ -27,11 +28,11 @@ module Fog
|
|
27
28
|
# Server model
|
28
29
|
class Server < Fog::Compute::Server
|
29
30
|
identity :vmid
|
30
|
-
attribute :
|
31
|
-
attribute :
|
31
|
+
attribute :type
|
32
|
+
attribute :node_id
|
32
33
|
attribute :config
|
34
|
+
attribute :digest
|
33
35
|
attribute :name
|
34
|
-
attribute :type
|
35
36
|
attribute :maxdisk
|
36
37
|
attribute :disk
|
37
38
|
attribute :diskwrite
|
@@ -53,116 +54,164 @@ module Fog
|
|
53
54
|
attribute :balloon
|
54
55
|
attribute :ballooninfo
|
55
56
|
attribute :snapshots
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
attributes
|
65
|
-
|
66
|
-
|
57
|
+
attribute :tasks
|
58
|
+
attribute :vmgenid
|
59
|
+
attribute :lock
|
60
|
+
attribute :maxswap
|
61
|
+
attribute :swap
|
62
|
+
|
63
|
+
def initialize(new_attributes = {})
|
64
|
+
prepare_service_value(new_attributes)
|
65
|
+
Fog::Proxmox::Attributes.set_attr_and_sym('node_id', attributes, new_attributes)
|
66
|
+
Fog::Proxmox::Attributes.set_attr_and_sym('type', attributes, new_attributes)
|
67
|
+
Fog::Proxmox::Attributes.set_attr_and_sym('vmid', attributes, new_attributes)
|
68
|
+
requires :node_id, :type, :vmid
|
69
|
+
initialize_config(new_attributes)
|
70
|
+
initialize_snapshots
|
71
|
+
initialize_tasks
|
72
|
+
super(new_attributes)
|
73
|
+
end
|
74
|
+
|
75
|
+
def container?
|
76
|
+
type == 'lxc'
|
77
|
+
end
|
78
|
+
|
79
|
+
def persisted?
|
80
|
+
service.next_vmid(vmid: vmid)
|
81
|
+
persisted = false
|
82
|
+
persisted
|
83
|
+
rescue Excon::Error::InternalServerError
|
84
|
+
persisted = false
|
85
|
+
persisted
|
86
|
+
rescue Excon::Error::BadRequest
|
87
|
+
persisted = true
|
88
|
+
persisted
|
89
|
+
end
|
90
|
+
|
91
|
+
# request with async task
|
67
92
|
def request(name, body_params = {}, path_params = {})
|
68
|
-
requires :
|
69
|
-
path = path_params.merge(node:
|
93
|
+
requires :node_id, :type
|
94
|
+
path = path_params.merge(node: node_id, type: type)
|
70
95
|
task_upid = service.send(name, path, body_params)
|
71
96
|
tasks.wait_for(task_upid)
|
72
97
|
end
|
73
98
|
|
74
|
-
def
|
75
|
-
|
99
|
+
def save(new_attributes = {})
|
100
|
+
body_params = new_attributes.merge(vmid: vmid)
|
101
|
+
body_params = body_params.merge(config.flatten) unless persisted?
|
102
|
+
request(:create_server, body_params)
|
103
|
+
reload
|
76
104
|
end
|
77
105
|
|
78
|
-
def update(
|
79
|
-
|
80
|
-
|
106
|
+
def update(new_attributes = {})
|
107
|
+
if container?
|
108
|
+
path_params = { node: node_id, type: type, vmid: vmid }
|
109
|
+
body_params = new_attributes
|
110
|
+
service.update_server(path_params, body_params)
|
111
|
+
else
|
112
|
+
request(:update_server, new_attributes, vmid: vmid)
|
113
|
+
end
|
114
|
+
reload
|
81
115
|
end
|
82
116
|
|
83
117
|
def destroy(options = {})
|
84
|
-
requires :vmid
|
85
118
|
request(:delete_server, options, vmid: vmid)
|
86
119
|
end
|
87
120
|
|
88
121
|
def action(action, options = {})
|
89
|
-
requires :vmid
|
90
122
|
action_known = %w[start stop resume suspend shutdown reset].include? action
|
91
123
|
message = "Action #{action} not implemented"
|
92
124
|
raise Fog::Errors::Error, message unless action_known
|
93
125
|
request(:action_server, options, action: action, vmid: vmid)
|
126
|
+
reload
|
94
127
|
end
|
95
128
|
|
96
129
|
def ready?
|
97
130
|
status == 'running'
|
98
131
|
end
|
99
132
|
|
100
|
-
def reload
|
101
|
-
requires :vmid
|
102
|
-
object = collection.get(vmid)
|
103
|
-
merge_attributes(object.attributes)
|
104
|
-
end
|
105
|
-
|
106
133
|
def backup(options = {})
|
107
|
-
requires :vmid
|
108
134
|
request(:create_backup, options.merge(vmid: vmid))
|
135
|
+
reload
|
109
136
|
end
|
110
137
|
|
111
138
|
def restore(backup, options = {})
|
112
|
-
|
113
|
-
|
114
|
-
|
139
|
+
if container?
|
140
|
+
attr_hash = options.merge(ostemplate: backup.volid, force: 1, restore: 1)
|
141
|
+
else
|
142
|
+
attr_hash = options.merge(archive: backup.volid, force: 1)
|
143
|
+
end
|
144
|
+
save(attr_hash)
|
115
145
|
end
|
116
146
|
|
117
147
|
def clone(newid, options = {})
|
118
|
-
requires :vmid
|
119
148
|
request(:clone_server, options.merge(newid: newid), vmid: vmid)
|
149
|
+
reload
|
120
150
|
end
|
121
151
|
|
122
|
-
def
|
123
|
-
|
124
|
-
|
152
|
+
def create_template(options = {})
|
153
|
+
service.template_server({ node: node_id, type: type, vmid: vmid }, options)
|
154
|
+
reload
|
125
155
|
end
|
126
156
|
|
127
157
|
def migrate(target, options = {})
|
128
|
-
requires :vmid
|
129
158
|
request(:migrate_server, options.merge(target: target), vmid: vmid)
|
159
|
+
reload
|
130
160
|
end
|
131
161
|
|
132
162
|
def extend(disk, size, options = {})
|
133
|
-
|
134
|
-
|
163
|
+
if container?
|
164
|
+
request(:resize_container, options.merge(disk: disk, size: size), vmid: vmid)
|
165
|
+
else
|
166
|
+
service.resize_server({ vmid: vmid, node: node_id }, options.merge(disk: disk, size: size))
|
167
|
+
end
|
168
|
+
reload
|
135
169
|
end
|
136
170
|
|
137
|
-
def move(
|
138
|
-
|
139
|
-
|
171
|
+
def move(volume, storage, options = {})
|
172
|
+
if container?
|
173
|
+
request(:move_volume, options.merge(volume: volume, storage: storage), vmid: vmid)
|
174
|
+
else
|
175
|
+
request(:move_disk, options.merge(disk: volume, storage: storage), vmid: vmid)
|
176
|
+
end
|
177
|
+
reload
|
140
178
|
end
|
141
179
|
|
142
180
|
def attach(disk, options = {})
|
143
|
-
|
144
|
-
update(
|
181
|
+
disk_hash = Fog::Proxmox::DiskHelper.flatten(disk.merge(options: options))
|
182
|
+
update(disk_hash)
|
145
183
|
end
|
146
184
|
|
147
185
|
def detach(diskid)
|
148
186
|
update(delete: diskid)
|
149
187
|
end
|
150
188
|
|
151
|
-
def
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
189
|
+
def start_console(options = {})
|
190
|
+
raise ::Fog::Proxmox::Errors::ServiceError, "Unable to start console because server not running." unless ready?
|
191
|
+
if container?
|
192
|
+
type_console = options[:console]
|
193
|
+
options.delete_if { |option| [:console].include? option }
|
194
|
+
raise ::Fog::Proxmox::Errors::ServiceError, "Unable to start console because console container config is not set or unknown." unless type_console
|
195
|
+
else
|
196
|
+
type_console = config.type_console
|
197
|
+
raise ::Fog::Proxmox::Errors::ServiceError, "Unable to start console because VGA display server config is not set or unknown." unless type_console
|
198
|
+
end
|
199
|
+
requires :vmid, :node_id, :type
|
200
|
+
path_params = { node: node_id, type: type, vmid: vmid }
|
201
|
+
body_params = options
|
202
|
+
data = service.send(('create_' + type_console).to_sym, path_params, body_params)
|
203
|
+
task_upid = data['upid']
|
204
|
+
if task_upid
|
205
|
+
task = tasks.get(task_upid)
|
206
|
+
task.wait_for { running? }
|
207
|
+
end
|
208
|
+
data
|
159
209
|
end
|
160
210
|
|
161
|
-
def
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
end
|
211
|
+
def connect_vnc(options = {})
|
212
|
+
path_params = { node: node_id, type: type, vmid: vmid }
|
213
|
+
query_params = { port: options['port'], vncticket: options['ticket'] }
|
214
|
+
service.get_vnc(path_params, query_params)
|
166
215
|
end
|
167
216
|
|
168
217
|
def backups
|
@@ -176,36 +225,30 @@ module Fog
|
|
176
225
|
def list(content)
|
177
226
|
storages = node.storages.list_by_content_type content
|
178
227
|
volumes = []
|
179
|
-
storages.each { |storage| volumes += storage.volumes.list_by_content_type_and_by_server(content,
|
228
|
+
storages.each { |storage| volumes += storage.volumes.list_by_content_type_and_by_server(content, identity) }
|
180
229
|
volumes
|
181
230
|
end
|
182
231
|
|
183
|
-
|
184
|
-
|
232
|
+
protected
|
233
|
+
|
234
|
+
def initialize_config(new_attributes = {})
|
235
|
+
options = { service: service, vmid: vmid }
|
236
|
+
attributes[:config] = Fog::Compute::Proxmox::ServerConfig.new(options.merge(new_attributes))
|
185
237
|
end
|
186
238
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
requires :vmid, :node, :type
|
192
|
-
path_params = { node: node, type: type, vmid: vmid }
|
193
|
-
body_params = options
|
194
|
-
data = service.send(('create_' + type_console).to_sym, path_params, body_params)
|
195
|
-
task_upid = data['upid']
|
196
|
-
if task_upid
|
197
|
-
task = tasks.get(task_upid)
|
198
|
-
task.wait_for { running? }
|
199
|
-
end
|
200
|
-
data
|
239
|
+
private
|
240
|
+
|
241
|
+
def initialize_snapshots
|
242
|
+
attributes[:snapshots] = Fog::Compute::Proxmox::Snapshots.new(service: service, server_id: vmid, server_type: type, node_id: node_id)
|
201
243
|
end
|
202
244
|
|
203
|
-
def
|
204
|
-
|
205
|
-
path_params = { node: node, type: type, vmid: vmid }
|
206
|
-
query_params = { port: options['port'], vncticket: options['ticket'] }
|
207
|
-
service.get_vnc(path_params, query_params)
|
245
|
+
def initialize_tasks
|
246
|
+
attributes[:tasks] = Fog::Compute::Proxmox::Tasks.new(service: service, node_id: node_id).select { |task| task.id == vmid }
|
208
247
|
end
|
248
|
+
|
249
|
+
def node
|
250
|
+
Fog::Compute::Proxmox::Node.new(service: service, node: node_id)
|
251
|
+
end
|
209
252
|
end
|
210
253
|
end
|
211
254
|
end
|