fog-proxmox 0.4.0
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 +7 -0
- data/.bundle/config +4 -0
- data/.codeclimate.yml +14 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +35 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
- data/.gitignore +5 -0
- data/.gitlab-ci.yml +42 -0
- data/.rubocop.yml +13 -0
- data/.ruby-gemset +1 -0
- data/.solargraph.yml +10 -0
- data/.travis.yml +26 -0
- data/.vscode/launch.json +114 -0
- data/.vscode/settings.json +45 -0
- data/.vscode/tasks.json +27 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +20 -0
- data/CONTRIBUTORS.md +9 -0
- data/Gemfile +23 -0
- data/Gemfile.lock +146 -0
- data/ISSUE_TEMPLATE.md +43 -0
- data/LICENSE +674 -0
- data/README.md +58 -0
- data/Rakefile +53 -0
- data/SUPPORT.md +9 -0
- data/bin/console +29 -0
- data/bin/setup +29 -0
- data/docs/compute.md +846 -0
- data/docs/connection_parameters.md +45 -0
- data/docs/getting_started.md +53 -0
- data/docs/identity.md +357 -0
- data/examples/compute.rb +279 -0
- data/examples/identity.rb +195 -0
- data/fog-proxmox.gemspec +63 -0
- data/fogproxmox.png +0 -0
- data/lib/fog/compute/proxmox.rb +131 -0
- data/lib/fog/compute/proxmox/models/container.rb +97 -0
- data/lib/fog/compute/proxmox/models/container_config.rb +90 -0
- data/lib/fog/compute/proxmox/models/containers.rb +40 -0
- data/lib/fog/compute/proxmox/models/disk.rb +67 -0
- data/lib/fog/compute/proxmox/models/disks.rb +49 -0
- data/lib/fog/compute/proxmox/models/interface.rb +50 -0
- data/lib/fog/compute/proxmox/models/interfaces.rb +46 -0
- data/lib/fog/compute/proxmox/models/node.rb +93 -0
- data/lib/fog/compute/proxmox/models/nodes.rb +45 -0
- data/lib/fog/compute/proxmox/models/server.rb +212 -0
- data/lib/fog/compute/proxmox/models/server_config.rb +116 -0
- data/lib/fog/compute/proxmox/models/servers.rb +70 -0
- data/lib/fog/compute/proxmox/models/snapshot.rb +70 -0
- data/lib/fog/compute/proxmox/models/snapshots.rb +55 -0
- data/lib/fog/compute/proxmox/models/storage.rb +61 -0
- data/lib/fog/compute/proxmox/models/storages.rb +60 -0
- data/lib/fog/compute/proxmox/models/task.rb +84 -0
- data/lib/fog/compute/proxmox/models/tasks.rb +71 -0
- data/lib/fog/compute/proxmox/models/volume.rb +61 -0
- data/lib/fog/compute/proxmox/models/volumes.rb +67 -0
- data/lib/fog/compute/proxmox/requests/action_server.rb +47 -0
- data/lib/fog/compute/proxmox/requests/check_vmid.rb +41 -0
- data/lib/fog/compute/proxmox/requests/clone_server.rb +46 -0
- data/lib/fog/compute/proxmox/requests/create_backup.rb +44 -0
- data/lib/fog/compute/proxmox/requests/create_server.rb +45 -0
- data/lib/fog/compute/proxmox/requests/create_snapshot.rb +47 -0
- data/lib/fog/compute/proxmox/requests/create_spice.rb +46 -0
- data/lib/fog/compute/proxmox/requests/create_term.rb +46 -0
- data/lib/fog/compute/proxmox/requests/create_vnc.rb +46 -0
- data/lib/fog/compute/proxmox/requests/delete_server.rb +47 -0
- data/lib/fog/compute/proxmox/requests/delete_snapshot.rb +48 -0
- data/lib/fog/compute/proxmox/requests/delete_volume.rb +40 -0
- data/lib/fog/compute/proxmox/requests/get_node.rb +44 -0
- data/lib/fog/compute/proxmox/requests/get_server_config.rb +45 -0
- data/lib/fog/compute/proxmox/requests/get_server_status.rb +45 -0
- data/lib/fog/compute/proxmox/requests/get_snapshot.rb +47 -0
- data/lib/fog/compute/proxmox/requests/get_storage.rb +44 -0
- data/lib/fog/compute/proxmox/requests/get_task.rb +44 -0
- data/lib/fog/compute/proxmox/requests/get_vnc.rb +46 -0
- data/lib/fog/compute/proxmox/requests/get_volume.rb +42 -0
- data/lib/fog/compute/proxmox/requests/list_nodes.rb +42 -0
- data/lib/fog/compute/proxmox/requests/list_servers.rb +42 -0
- data/lib/fog/compute/proxmox/requests/list_snapshots.rb +43 -0
- data/lib/fog/compute/proxmox/requests/list_storages.rb +42 -0
- data/lib/fog/compute/proxmox/requests/list_tasks.rb +42 -0
- data/lib/fog/compute/proxmox/requests/list_volumes.rb +42 -0
- data/lib/fog/compute/proxmox/requests/log_task.rb +45 -0
- data/lib/fog/compute/proxmox/requests/migrate_server.rb +44 -0
- data/lib/fog/compute/proxmox/requests/move_disk.rb +46 -0
- data/lib/fog/compute/proxmox/requests/move_volume.rb +46 -0
- data/lib/fog/compute/proxmox/requests/next_vmid.rb +39 -0
- data/lib/fog/compute/proxmox/requests/resize_container.rb +46 -0
- data/lib/fog/compute/proxmox/requests/resize_server.rb +43 -0
- data/lib/fog/compute/proxmox/requests/rollback_snapshot.rb +46 -0
- data/lib/fog/compute/proxmox/requests/status_task.rb +44 -0
- data/lib/fog/compute/proxmox/requests/stop_task.rb +41 -0
- data/lib/fog/compute/proxmox/requests/template_server.rb +43 -0
- data/lib/fog/compute/proxmox/requests/update_server.rb +46 -0
- data/lib/fog/compute/proxmox/requests/update_snapshot.rb +45 -0
- data/lib/fog/identity/proxmox.rb +132 -0
- data/lib/fog/identity/proxmox/models/activedirectory.rb +57 -0
- data/lib/fog/identity/proxmox/models/domain.rb +61 -0
- data/lib/fog/identity/proxmox/models/domains.rb +115 -0
- data/lib/fog/identity/proxmox/models/group.rb +60 -0
- data/lib/fog/identity/proxmox/models/groups.rb +50 -0
- data/lib/fog/identity/proxmox/models/ldap.rb +57 -0
- data/lib/fog/identity/proxmox/models/oath.rb +50 -0
- data/lib/fog/identity/proxmox/models/pam.rb +46 -0
- data/lib/fog/identity/proxmox/models/permission.rb +69 -0
- data/lib/fog/identity/proxmox/models/permissions.rb +61 -0
- data/lib/fog/identity/proxmox/models/pool.rb +84 -0
- data/lib/fog/identity/proxmox/models/pools.rb +50 -0
- data/lib/fog/identity/proxmox/models/principal.rb +47 -0
- data/lib/fog/identity/proxmox/models/pve.rb +46 -0
- data/lib/fog/identity/proxmox/models/role.rb +61 -0
- data/lib/fog/identity/proxmox/models/roles.rb +51 -0
- data/lib/fog/identity/proxmox/models/user.rb +74 -0
- data/lib/fog/identity/proxmox/models/users.rb +50 -0
- data/lib/fog/identity/proxmox/models/yubico.rb +51 -0
- data/lib/fog/identity/proxmox/requests/add_permission.rb +41 -0
- data/lib/fog/identity/proxmox/requests/change_password.rb +41 -0
- data/lib/fog/identity/proxmox/requests/check_permissions.rb +44 -0
- data/lib/fog/identity/proxmox/requests/create_domain.rb +40 -0
- data/lib/fog/identity/proxmox/requests/create_group.rb +40 -0
- data/lib/fog/identity/proxmox/requests/create_pool.rb +40 -0
- data/lib/fog/identity/proxmox/requests/create_role.rb +40 -0
- data/lib/fog/identity/proxmox/requests/create_user.rb +40 -0
- data/lib/fog/identity/proxmox/requests/delete_domain.rb +40 -0
- data/lib/fog/identity/proxmox/requests/delete_group.rb +40 -0
- data/lib/fog/identity/proxmox/requests/delete_pool.rb +39 -0
- data/lib/fog/identity/proxmox/requests/delete_role.rb +40 -0
- data/lib/fog/identity/proxmox/requests/delete_user.rb +39 -0
- data/lib/fog/identity/proxmox/requests/get_domain.rb +41 -0
- data/lib/fog/identity/proxmox/requests/get_group.rb +41 -0
- data/lib/fog/identity/proxmox/requests/get_pool.rb +41 -0
- data/lib/fog/identity/proxmox/requests/get_role.rb +41 -0
- data/lib/fog/identity/proxmox/requests/get_user.rb +40 -0
- data/lib/fog/identity/proxmox/requests/list_domains.rb +41 -0
- data/lib/fog/identity/proxmox/requests/list_groups.rb +41 -0
- data/lib/fog/identity/proxmox/requests/list_permissions.rb +41 -0
- data/lib/fog/identity/proxmox/requests/list_pools.rb +41 -0
- data/lib/fog/identity/proxmox/requests/list_roles.rb +41 -0
- data/lib/fog/identity/proxmox/requests/list_users.rb +42 -0
- data/lib/fog/identity/proxmox/requests/read_version.rb +43 -0
- data/lib/fog/identity/proxmox/requests/remove_permission.rb +42 -0
- data/lib/fog/identity/proxmox/requests/update_domain.rb +41 -0
- data/lib/fog/identity/proxmox/requests/update_group.rb +41 -0
- data/lib/fog/identity/proxmox/requests/update_pool.rb +41 -0
- data/lib/fog/identity/proxmox/requests/update_role.rb +41 -0
- data/lib/fog/identity/proxmox/requests/update_user.rb +41 -0
- data/lib/fog/network/proxmox.rb +83 -0
- data/lib/fog/network/proxmox/models/network.rb +82 -0
- data/lib/fog/network/proxmox/models/networks.rb +54 -0
- data/lib/fog/network/proxmox/models/node.rb +70 -0
- data/lib/fog/network/proxmox/models/nodes.rb +45 -0
- data/lib/fog/network/proxmox/requests/create_network.rb +44 -0
- data/lib/fog/network/proxmox/requests/delete_network.rb +45 -0
- data/lib/fog/network/proxmox/requests/get_network.rb +46 -0
- data/lib/fog/network/proxmox/requests/get_node.rb +44 -0
- data/lib/fog/network/proxmox/requests/list_networks.rb +43 -0
- data/lib/fog/network/proxmox/requests/list_nodes.rb +42 -0
- data/lib/fog/network/proxmox/requests/power_node.rb +46 -0
- data/lib/fog/network/proxmox/requests/update_network.rb +46 -0
- data/lib/fog/proxmox.rb +128 -0
- data/lib/fog/proxmox/core.rb +139 -0
- data/lib/fog/proxmox/errors.rb +64 -0
- data/lib/fog/proxmox/hash.rb +33 -0
- data/lib/fog/proxmox/helpers/controller_helper.rb +55 -0
- data/lib/fog/proxmox/helpers/cpu_helper.rb +45 -0
- data/lib/fog/proxmox/helpers/disk_helper.rb +84 -0
- data/lib/fog/proxmox/helpers/nic_helper.rb +62 -0
- data/lib/fog/proxmox/json.rb +32 -0
- data/lib/fog/proxmox/models/collection.rb +85 -0
- data/lib/fog/proxmox/models/model.rb +58 -0
- data/lib/fog/proxmox/variables.rb +40 -0
- data/lib/fog/proxmox/version.rb +24 -0
- data/lib/fog/storage/proxmox.rb +29 -0
- data/spec/compute_spec.rb +408 -0
- data/spec/fixtures/proxmox/compute/containers.yml +5398 -0
- data/spec/fixtures/proxmox/compute/identity_ticket.yml +40 -0
- data/spec/fixtures/proxmox/compute/servers.yml +10571 -0
- data/spec/fixtures/proxmox/compute/snapshots.yml +1228 -0
- data/spec/fixtures/proxmox/compute/storages.yml +120 -0
- data/spec/fixtures/proxmox/compute/tasks.yml +200 -0
- data/spec/fixtures/proxmox/identity/auth.yml +44 -0
- data/spec/fixtures/proxmox/identity/domains.yml +531 -0
- data/spec/fixtures/proxmox/identity/groups.yml +324 -0
- data/spec/fixtures/proxmox/identity/identity_ticket.yml +40 -0
- data/spec/fixtures/proxmox/identity/permissions.yml +565 -0
- data/spec/fixtures/proxmox/identity/pools.yml +488 -0
- data/spec/fixtures/proxmox/identity/read_version.yml +42 -0
- data/spec/fixtures/proxmox/identity/roles.yml +324 -0
- data/spec/fixtures/proxmox/identity/users.yml +646 -0
- data/spec/fixtures/proxmox/network/identity_ticket.yml +40 -0
- data/spec/fixtures/proxmox/network/networks.yml +413 -0
- data/spec/helpers/controller_helper_spec.rb +77 -0
- data/spec/helpers/cpu_helper_spec.rb +91 -0
- data/spec/helpers/disk_helper_spec.rb +104 -0
- data/spec/helpers/nic_helper_spec.rb +73 -0
- data/spec/identity_spec.rb +316 -0
- data/spec/network_spec.rb +67 -0
- data/spec/proxmox_vcr.rb +102 -0
- data/spec/spec_helper.rb +39 -0
- metadata +535 -0
@@ -0,0 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Tristan Robert
|
4
|
+
|
5
|
+
# This file is part of Fog::Proxmox.
|
6
|
+
|
7
|
+
# Fog::Proxmox is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
|
12
|
+
# Fog::Proxmox is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require 'fog/proxmox/variables'
|
21
|
+
require 'fog/proxmox/helpers/nic_helper'
|
22
|
+
require 'fog/proxmox/models/model'
|
23
|
+
|
24
|
+
module Fog
|
25
|
+
module Compute
|
26
|
+
class Proxmox
|
27
|
+
# ServerConfig model
|
28
|
+
class ServerConfig < Fog::Proxmox::Model
|
29
|
+
identity :id
|
30
|
+
attribute :digest
|
31
|
+
attribute :description
|
32
|
+
attribute :ostype
|
33
|
+
attribute :smbios1
|
34
|
+
attribute :numa
|
35
|
+
attribute :kvm
|
36
|
+
attribute :vcpus
|
37
|
+
attribute :cores
|
38
|
+
attribute :bootdisk
|
39
|
+
attribute :onboot
|
40
|
+
attribute :boot
|
41
|
+
attribute :agent
|
42
|
+
attribute :scsihw
|
43
|
+
attribute :sockets
|
44
|
+
attribute :memory
|
45
|
+
attribute :min_memory
|
46
|
+
attribute :shares
|
47
|
+
attribute :balloon
|
48
|
+
attribute :name
|
49
|
+
attribute :cpu
|
50
|
+
attribute :cpulimit
|
51
|
+
attribute :cpuunits
|
52
|
+
attribute :keyboard
|
53
|
+
attribute :vga
|
54
|
+
attribute :interfaces
|
55
|
+
attribute :disks
|
56
|
+
|
57
|
+
def initialize(attributes = {})
|
58
|
+
prepare_service_value(attributes)
|
59
|
+
compute_nets(attributes)
|
60
|
+
compute_disks(attributes)
|
61
|
+
super(attributes)
|
62
|
+
end
|
63
|
+
|
64
|
+
def mac_addresses
|
65
|
+
Fog::Proxmox::NicHelper.to_mac_adresses_array(interfaces)
|
66
|
+
end
|
67
|
+
|
68
|
+
attr_reader :disks
|
69
|
+
|
70
|
+
attr_reader :interfaces
|
71
|
+
|
72
|
+
def type_console
|
73
|
+
console = 'vnc' if %w[std cirrus vmware].include?(vga)
|
74
|
+
console = 'spice' if %w[qxl qxl2 qxl3 qxl4].include?(vga)
|
75
|
+
console = 'term' if %w[serial0 serial1 serial2 serial3].include?(vga)
|
76
|
+
console
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def compute_nets(attributes)
|
82
|
+
nets = Fog::Proxmox::ControllerHelper.to_hash(attributes, Fog::Compute::Proxmox::Interface::NAME)
|
83
|
+
@interfaces ||= Fog::Compute::Proxmox::Interfaces.new
|
84
|
+
nets.each do |key, value|
|
85
|
+
nic_hash = {
|
86
|
+
id: key.to_s,
|
87
|
+
model: Fog::Proxmox::NicHelper.extract_model(value),
|
88
|
+
mac: Fog::Proxmox::NicHelper.extract_mac_address(value)
|
89
|
+
}
|
90
|
+
names = Fog::Compute::Proxmox::Interface.attributes.reject { |key, _value| %i[id mac model].include? key }
|
91
|
+
names.each { |name| nic_hash.store(name.to_sym, Fog::Proxmox::ControllerHelper.extract(name, value)) }
|
92
|
+
@interfaces << Fog::Compute::Proxmox::Interface.new(nic_hash)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def compute_disks(attributes)
|
97
|
+
controllers = {}
|
98
|
+
Fog::Compute::Proxmox::Disk::CONTROLLERS.each { |controller| controllers.merge!(Fog::Proxmox::ControllerHelper.to_hash(attributes, controller)) }
|
99
|
+
@disks ||= Fog::Compute::Proxmox::Disks.new
|
100
|
+
controllers.each do |key, value|
|
101
|
+
storage, volid, size = Fog::Proxmox::DiskHelper.extract_storage_volid_size(value)
|
102
|
+
disk_hash = {
|
103
|
+
id: key.to_s,
|
104
|
+
size: size,
|
105
|
+
volid: volid,
|
106
|
+
storage: storage
|
107
|
+
}
|
108
|
+
names = Fog::Compute::Proxmox::Disk.attributes.reject { |key, _value| %i[id size storage volid].include? key }
|
109
|
+
names.each { |name| disk_hash.store(name.to_sym, Fog::Proxmox::ControllerHelper.extract(name, value)) }
|
110
|
+
@disks << Fog::Compute::Proxmox::Disk.new(disk_hash)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Tristan Robert
|
4
|
+
|
5
|
+
# This file is part of Fog::Proxmox.
|
6
|
+
|
7
|
+
# Fog::Proxmox is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
|
12
|
+
# Fog::Proxmox is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require 'fog/compute/proxmox/models/server'
|
21
|
+
|
22
|
+
module Fog
|
23
|
+
module Compute
|
24
|
+
class Proxmox
|
25
|
+
# Servers Collection
|
26
|
+
class Servers < Fog::Proxmox::Collection
|
27
|
+
model Fog::Compute::Proxmox::Server
|
28
|
+
attribute :node
|
29
|
+
attribute :type
|
30
|
+
|
31
|
+
def new(attributes = {})
|
32
|
+
super({ node: node, type: type }.merge(attributes))
|
33
|
+
end
|
34
|
+
|
35
|
+
def type(attributes = {})
|
36
|
+
@type ||= 'qemu' unless attributes[:type] || attributes['type']
|
37
|
+
@type
|
38
|
+
end
|
39
|
+
|
40
|
+
def next_id
|
41
|
+
response = service.next_vmid
|
42
|
+
body = JSON.decode(response.body)
|
43
|
+
data = body['data']
|
44
|
+
Integer(data)
|
45
|
+
end
|
46
|
+
|
47
|
+
def id_valid?(vmid)
|
48
|
+
service.check_vmid(vmid)
|
49
|
+
true
|
50
|
+
rescue Excon::Errors::BadRequest
|
51
|
+
false
|
52
|
+
end
|
53
|
+
|
54
|
+
def get(vmid)
|
55
|
+
requires :node
|
56
|
+
path_params = { node: node, type: type, vmid: vmid }
|
57
|
+
server_data = service.get_server_status path_params
|
58
|
+
config_data = service.get_server_config path_params
|
59
|
+
data = server_data.merge(config_data).merge(node: node, vmid: vmid)
|
60
|
+
new(data)
|
61
|
+
end
|
62
|
+
|
63
|
+
def all(options = {})
|
64
|
+
body_params = options.merge(type: 'vm')
|
65
|
+
load_response(service.list_servers(body_params), 'servers')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Tristan Robert
|
4
|
+
|
5
|
+
# This file is part of Fog::Proxmox.
|
6
|
+
|
7
|
+
# Fog::Proxmox is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
# Copyright 2018 Tristan Robert
|
12
|
+
|
13
|
+
# This file is part of Fog::Proxmox.
|
14
|
+
|
15
|
+
# Fog::Proxmox is free software: you can redistribute it and/or modify
|
16
|
+
# it under the terms of the GNU General Public License as published by
|
17
|
+
# the Free Software Foundation, either version 3 of the License, or
|
18
|
+
# (at your option) any later version.
|
19
|
+
|
20
|
+
# Fog::Proxmox is distributed in the hope that it will be useful,
|
21
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23
|
+
# GNU General Public License for more details.
|
24
|
+
|
25
|
+
# You should have received a copy of the GNU General Public License
|
26
|
+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
27
|
+
|
28
|
+
require 'fog/proxmox/models/model'
|
29
|
+
|
30
|
+
module Fog
|
31
|
+
module Compute
|
32
|
+
class Proxmox
|
33
|
+
# class Snapshot model
|
34
|
+
class Snapshot < Fog::Proxmox::Model
|
35
|
+
identity :name
|
36
|
+
attribute :description
|
37
|
+
attribute :snaptime
|
38
|
+
attribute :vmstate
|
39
|
+
attribute :server
|
40
|
+
|
41
|
+
def create(options = {})
|
42
|
+
requires :server
|
43
|
+
path_params = { node: server.node, type: server.type, vmid: server.vmid }
|
44
|
+
body_params = options
|
45
|
+
server.tasks.wait_for(service.create_snapshot(path_params, body_params))
|
46
|
+
end
|
47
|
+
|
48
|
+
def update
|
49
|
+
requires :name, :server
|
50
|
+
path_params = { node: server.node, type: server.type, vmid: server.vmid, snapname: name }
|
51
|
+
body_params = { description: description }
|
52
|
+
service.update_snapshot(path_params, body_params)
|
53
|
+
end
|
54
|
+
|
55
|
+
def rollback
|
56
|
+
requires :name, :server
|
57
|
+
path_params = { node: server.node, type: server.type, vmid: server.vmid, snapname: name }
|
58
|
+
server.tasks.wait_for(service.rollback_snapshot(path_params))
|
59
|
+
end
|
60
|
+
|
61
|
+
def destroy(force = 0)
|
62
|
+
requires :name, :server
|
63
|
+
path_params = { node: server.node, type: server.type, vmid: server.vmid, snapname: name }
|
64
|
+
query_params = { force: force }
|
65
|
+
server.tasks.wait_for(service.delete_snapshot(path_params, query_params))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Tristan Robert
|
4
|
+
|
5
|
+
# This file is part of Fog::Proxmox.
|
6
|
+
|
7
|
+
# Fog::Proxmox is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
|
12
|
+
# Fog::Proxmox is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require 'fog/proxmox/models/collection'
|
21
|
+
require 'fog/compute/proxmox/models/snapshot'
|
22
|
+
|
23
|
+
module Fog
|
24
|
+
module Compute
|
25
|
+
class Proxmox
|
26
|
+
# class Snapshots Collection of snapshots
|
27
|
+
class Snapshots < Fog::Proxmox::Collection
|
28
|
+
model Fog::Compute::Proxmox::Snapshot
|
29
|
+
attribute :server
|
30
|
+
|
31
|
+
def new(attributes = {})
|
32
|
+
requires :server
|
33
|
+
super({ server: server }.merge!(attributes))
|
34
|
+
end
|
35
|
+
|
36
|
+
def all
|
37
|
+
requires :server
|
38
|
+
path_params = { node: server.node, type: server.type, vmid: server.vmid }
|
39
|
+
load_response(service.list_snapshots(path_params), 'snapshots')
|
40
|
+
end
|
41
|
+
|
42
|
+
def get(name)
|
43
|
+
requires :server
|
44
|
+
cached_snapshot = find { |snapshot| snapshot.name == name }
|
45
|
+
return cached_snapshot if cached_snapshot
|
46
|
+
path_params = { node: server.node, type: server.type, vmid: server.vmid, snapname: name }
|
47
|
+
snapshot_hash = service.get_snapshot(path_params)
|
48
|
+
Fog::Compute::Proxmox::Snapshot.new(
|
49
|
+
snapshot_hash.merge(service: service, server: server, name: name)
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,61 @@
|
|
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
|
+
# Copyright 2018 Tristan Robert
|
11
|
+
|
12
|
+
# This file is part of Fog::Proxmox.
|
13
|
+
|
14
|
+
# Fog::Proxmox is free software: you can redistribute it and/or modify
|
15
|
+
# it under the terms of the GNU General Public License as published by
|
16
|
+
# the Free Software Foundation, either version 3 of the License, or
|
17
|
+
# (at your option) any later version.
|
18
|
+
|
19
|
+
# Fog::Proxmox is distributed in the hope that it will be useful,
|
20
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22
|
+
# GNU General Public License for more details.
|
23
|
+
|
24
|
+
# You should have received a copy of the GNU General Public License
|
25
|
+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
26
|
+
|
27
|
+
# frozen_string_literal: true
|
28
|
+
|
29
|
+
require 'fog/proxmox/models/model'
|
30
|
+
|
31
|
+
module Fog
|
32
|
+
module Compute
|
33
|
+
class Proxmox
|
34
|
+
# class Storage model
|
35
|
+
class Storage < Fog::Proxmox::Model
|
36
|
+
identity :storage
|
37
|
+
attribute :node
|
38
|
+
attribute :content
|
39
|
+
attribute :type
|
40
|
+
attribute :avail
|
41
|
+
attribute :total
|
42
|
+
attribute :used
|
43
|
+
attribute :shared
|
44
|
+
attribute :active
|
45
|
+
attribute :enabled
|
46
|
+
attribute :volumes
|
47
|
+
|
48
|
+
def to_s
|
49
|
+
storage
|
50
|
+
end
|
51
|
+
|
52
|
+
def volumes
|
53
|
+
@volumes ||= begin
|
54
|
+
Fog::Compute::Proxmox::Volumes.new(service: service,
|
55
|
+
node: node, storage: self)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Tristan Robert
|
4
|
+
|
5
|
+
# This file is part of Fog::Proxmox.
|
6
|
+
|
7
|
+
# Fog::Proxmox is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
|
12
|
+
# Fog::Proxmox is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require 'fog/proxmox/models/collection'
|
21
|
+
require 'fog/compute/proxmox/models/storage'
|
22
|
+
|
23
|
+
module Fog
|
24
|
+
module Compute
|
25
|
+
class Proxmox
|
26
|
+
# class Storages Collection of storages
|
27
|
+
class Storages < Fog::Proxmox::Collection
|
28
|
+
model Fog::Compute::Proxmox::Storage
|
29
|
+
attribute :node
|
30
|
+
|
31
|
+
def new(attributes = {})
|
32
|
+
requires :node
|
33
|
+
super({ node: node }.merge(attributes))
|
34
|
+
end
|
35
|
+
|
36
|
+
def all
|
37
|
+
search
|
38
|
+
end
|
39
|
+
|
40
|
+
def search(options = {})
|
41
|
+
requires :node
|
42
|
+
load_response(service.list_storages(node, options), 'storages')
|
43
|
+
end
|
44
|
+
|
45
|
+
def list_by_content_type(content)
|
46
|
+
search(content: content)
|
47
|
+
end
|
48
|
+
|
49
|
+
def find_by_id(id)
|
50
|
+
cached_storage = find { |storage| storage.storage == id }
|
51
|
+
return cached_storage if cached_storage
|
52
|
+
storage_hash = service.get_storage(node, id, {})
|
53
|
+
Fog::Compute::Proxmox::Storage.new(
|
54
|
+
storage_hash.merge(service: service)
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,84 @@
|
|
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
|
+
# Copyright 2018 Tristan Robert
|
11
|
+
|
12
|
+
# This file is part of Fog::Proxmox.
|
13
|
+
|
14
|
+
# Fog::Proxmox is free software: you can redistribute it and/or modify
|
15
|
+
# it under the terms of the GNU General Public License as published by
|
16
|
+
# the Free Software Foundation, either version 3 of the License, or
|
17
|
+
# (at your option) any later version.
|
18
|
+
|
19
|
+
# Fog::Proxmox is distributed in the hope that it will be useful,
|
20
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22
|
+
# GNU General Public License for more details.
|
23
|
+
|
24
|
+
# You should have received a copy of the GNU General Public License
|
25
|
+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
26
|
+
|
27
|
+
# frozen_string_literal: true
|
28
|
+
|
29
|
+
require 'fog/proxmox/models/model'
|
30
|
+
|
31
|
+
module Fog
|
32
|
+
module Compute
|
33
|
+
class Proxmox
|
34
|
+
# class Task model of a node
|
35
|
+
class Task < Fog::Proxmox::Model
|
36
|
+
identity :upid
|
37
|
+
attribute :node
|
38
|
+
attribute :status
|
39
|
+
attribute :exitstatus
|
40
|
+
attribute :pid
|
41
|
+
attribute :user
|
42
|
+
attribute :id, aliases: :vmid
|
43
|
+
attribute :type
|
44
|
+
attribute :pstart
|
45
|
+
attribute :starttime
|
46
|
+
attribute :endtime
|
47
|
+
attribute :status_details
|
48
|
+
attribute :log
|
49
|
+
|
50
|
+
def new(attributes = {})
|
51
|
+
requires :node
|
52
|
+
super({ node: node }.merge(attributes))
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_s
|
56
|
+
upid
|
57
|
+
end
|
58
|
+
|
59
|
+
def succeeded?
|
60
|
+
finished? && exitstatus == 'OK'
|
61
|
+
end
|
62
|
+
|
63
|
+
def finished?
|
64
|
+
status == 'stopped'
|
65
|
+
end
|
66
|
+
|
67
|
+
def running?
|
68
|
+
status == 'running'
|
69
|
+
end
|
70
|
+
|
71
|
+
def stop
|
72
|
+
requires :node, :upid
|
73
|
+
service.stop_task(node, upid)
|
74
|
+
end
|
75
|
+
|
76
|
+
def reload
|
77
|
+
requires :upid
|
78
|
+
object = collection.get(upid)
|
79
|
+
merge_attributes(object.attributes)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|