fog-proxmox-configlmm 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +8 -0
- data/LICENSE +674 -0
- data/README.md +110 -0
- data/docs/compute.md +874 -0
- data/docs/connection_parameters.md +45 -0
- data/docs/getting_started.md +53 -0
- data/docs/identity.md +382 -0
- data/examples/compute.rb +276 -0
- data/examples/identity.rb +203 -0
- data/lib/fog/proxmox/attributes.rb +34 -0
- data/lib/fog/proxmox/auth/token/access_ticket.rb +96 -0
- data/lib/fog/proxmox/auth/token/user_token.rb +107 -0
- data/lib/fog/proxmox/auth/token.rb +94 -0
- data/lib/fog/proxmox/compute/models/disk.rb +94 -0
- data/lib/fog/proxmox/compute/models/disks.rb +55 -0
- data/lib/fog/proxmox/compute/models/interface.rb +56 -0
- data/lib/fog/proxmox/compute/models/interfaces.rb +44 -0
- data/lib/fog/proxmox/compute/models/node.rb +93 -0
- data/lib/fog/proxmox/compute/models/nodes.rb +39 -0
- data/lib/fog/proxmox/compute/models/server.rb +271 -0
- data/lib/fog/proxmox/compute/models/server_config.rb +161 -0
- data/lib/fog/proxmox/compute/models/servers.rb +80 -0
- data/lib/fog/proxmox/compute/models/snapshot.rb +83 -0
- data/lib/fog/proxmox/compute/models/snapshots.rb +47 -0
- data/lib/fog/proxmox/compute/models/storage.rb +65 -0
- data/lib/fog/proxmox/compute/models/storages.rb +51 -0
- data/lib/fog/proxmox/compute/models/task.rb +79 -0
- data/lib/fog/proxmox/compute/models/tasks.rb +65 -0
- data/lib/fog/proxmox/compute/models/volume.rb +68 -0
- data/lib/fog/proxmox/compute/models/volumes.rb +58 -0
- data/lib/fog/proxmox/compute/requests/action_server.rb +45 -0
- data/lib/fog/proxmox/compute/requests/clone_server.rb +44 -0
- data/lib/fog/proxmox/compute/requests/create_backup.rb +42 -0
- data/lib/fog/proxmox/compute/requests/create_server.rb +43 -0
- data/lib/fog/proxmox/compute/requests/create_snapshot.rb +46 -0
- data/lib/fog/proxmox/compute/requests/create_spice.rb +44 -0
- data/lib/fog/proxmox/compute/requests/create_term.rb +45 -0
- data/lib/fog/proxmox/compute/requests/create_vnc.rb +44 -0
- data/lib/fog/proxmox/compute/requests/delete_server.rb +45 -0
- data/lib/fog/proxmox/compute/requests/delete_snapshot.rb +47 -0
- data/lib/fog/proxmox/compute/requests/delete_volume.rb +40 -0
- data/lib/fog/proxmox/compute/requests/get_node_statistics.rb +44 -0
- data/lib/fog/proxmox/compute/requests/get_server_config.rb +60 -0
- data/lib/fog/proxmox/compute/requests/get_server_status.rb +63 -0
- data/lib/fog/proxmox/compute/requests/get_snapshot_config.rb +44 -0
- data/lib/fog/proxmox/compute/requests/get_task.rb +41 -0
- data/lib/fog/proxmox/compute/requests/get_vnc.rb +45 -0
- data/lib/fog/proxmox/compute/requests/get_volume.rb +42 -0
- data/lib/fog/proxmox/compute/requests/list_nodes.rb +48 -0
- data/lib/fog/proxmox/compute/requests/list_servers.rb +113 -0
- data/lib/fog/proxmox/compute/requests/list_snapshots.rb +66 -0
- data/lib/fog/proxmox/compute/requests/list_storages.rb +46 -0
- data/lib/fog/proxmox/compute/requests/list_tasks.rb +44 -0
- data/lib/fog/proxmox/compute/requests/list_volumes.rb +44 -0
- data/lib/fog/proxmox/compute/requests/log_task.rb +44 -0
- data/lib/fog/proxmox/compute/requests/migrate_server.rb +44 -0
- data/lib/fog/proxmox/compute/requests/move_disk.rb +43 -0
- data/lib/fog/proxmox/compute/requests/move_volume.rb +43 -0
- data/lib/fog/proxmox/compute/requests/next_vmid.rb +42 -0
- data/lib/fog/proxmox/compute/requests/resize_container.rb +43 -0
- data/lib/fog/proxmox/compute/requests/resize_server.rb +43 -0
- data/lib/fog/proxmox/compute/requests/rollback_snapshot.rb +48 -0
- data/lib/fog/proxmox/compute/requests/status_task.rb +41 -0
- data/lib/fog/proxmox/compute/requests/stop_task.rb +41 -0
- data/lib/fog/proxmox/compute/requests/template_server.rb +44 -0
- data/lib/fog/proxmox/compute/requests/update_server.rb +44 -0
- data/lib/fog/proxmox/compute/requests/update_snapshot.rb +45 -0
- data/lib/fog/proxmox/compute.rb +141 -0
- data/lib/fog/proxmox/core.rb +147 -0
- data/lib/fog/proxmox/errors.rb +65 -0
- data/lib/fog/proxmox/hash.rb +37 -0
- data/lib/fog/proxmox/helpers/controller_helper.rb +63 -0
- data/lib/fog/proxmox/helpers/cpu_helper.rb +88 -0
- data/lib/fog/proxmox/helpers/disk_helper.rb +185 -0
- data/lib/fog/proxmox/helpers/ip_helper.rb +101 -0
- data/lib/fog/proxmox/helpers/nic_helper.rb +132 -0
- data/lib/fog/proxmox/identity/models/domain.rb +69 -0
- data/lib/fog/proxmox/identity/models/domain_type.rb +47 -0
- data/lib/fog/proxmox/identity/models/domains.rb +44 -0
- data/lib/fog/proxmox/identity/models/group.rb +51 -0
- data/lib/fog/proxmox/identity/models/groups.rb +44 -0
- data/lib/fog/proxmox/identity/models/permission.rb +66 -0
- data/lib/fog/proxmox/identity/models/permissions.rb +46 -0
- data/lib/fog/proxmox/identity/models/pool.rb +89 -0
- data/lib/fog/proxmox/identity/models/pools.rb +46 -0
- data/lib/fog/proxmox/identity/models/principal.rb +42 -0
- data/lib/fog/proxmox/identity/models/role.rb +48 -0
- data/lib/fog/proxmox/identity/models/roles.rb +44 -0
- data/lib/fog/proxmox/identity/models/token.rb +72 -0
- data/lib/fog/proxmox/identity/models/token_info.rb +41 -0
- data/lib/fog/proxmox/identity/models/tokens.rb +54 -0
- data/lib/fog/proxmox/identity/models/user.rb +82 -0
- data/lib/fog/proxmox/identity/models/users.rb +44 -0
- data/lib/fog/proxmox/identity/requests/change_password.rb +41 -0
- data/lib/fog/proxmox/identity/requests/check_permissions.rb +41 -0
- data/lib/fog/proxmox/identity/requests/create_domain.rb +40 -0
- data/lib/fog/proxmox/identity/requests/create_group.rb +40 -0
- data/lib/fog/proxmox/identity/requests/create_pool.rb +40 -0
- data/lib/fog/proxmox/identity/requests/create_role.rb +40 -0
- data/lib/fog/proxmox/identity/requests/create_token.rb +40 -0
- data/lib/fog/proxmox/identity/requests/create_user.rb +40 -0
- data/lib/fog/proxmox/identity/requests/delete_domain.rb +40 -0
- data/lib/fog/proxmox/identity/requests/delete_group.rb +40 -0
- data/lib/fog/proxmox/identity/requests/delete_pool.rb +39 -0
- data/lib/fog/proxmox/identity/requests/delete_role.rb +40 -0
- data/lib/fog/proxmox/identity/requests/delete_token.rb +40 -0
- data/lib/fog/proxmox/identity/requests/delete_user.rb +39 -0
- data/lib/fog/proxmox/identity/requests/get_domain.rb +41 -0
- data/lib/fog/proxmox/identity/requests/get_group.rb +41 -0
- data/lib/fog/proxmox/identity/requests/get_pool.rb +41 -0
- data/lib/fog/proxmox/identity/requests/get_role.rb +41 -0
- data/lib/fog/proxmox/identity/requests/get_token_info.rb +41 -0
- data/lib/fog/proxmox/identity/requests/get_user.rb +41 -0
- data/lib/fog/proxmox/identity/requests/list_domains.rb +41 -0
- data/lib/fog/proxmox/identity/requests/list_groups.rb +41 -0
- data/lib/fog/proxmox/identity/requests/list_permissions.rb +41 -0
- data/lib/fog/proxmox/identity/requests/list_pools.rb +41 -0
- data/lib/fog/proxmox/identity/requests/list_roles.rb +40 -0
- data/lib/fog/proxmox/identity/requests/list_tokens.rb +41 -0
- data/lib/fog/proxmox/identity/requests/list_user_permissions.rb +44 -0
- data/lib/fog/proxmox/identity/requests/list_users.rb +42 -0
- data/lib/fog/proxmox/identity/requests/read_version.rb +39 -0
- data/lib/fog/proxmox/identity/requests/update_domain.rb +41 -0
- data/lib/fog/proxmox/identity/requests/update_group.rb +40 -0
- data/lib/fog/proxmox/identity/requests/update_permissions.rb +41 -0
- data/lib/fog/proxmox/identity/requests/update_pool.rb +41 -0
- data/lib/fog/proxmox/identity/requests/update_role.rb +41 -0
- data/lib/fog/proxmox/identity/requests/update_token.rb +41 -0
- data/lib/fog/proxmox/identity/requests/update_user.rb +41 -0
- data/lib/fog/proxmox/identity.rb +144 -0
- data/lib/fog/proxmox/json.rb +32 -0
- data/lib/fog/proxmox/network/models/network.rb +76 -0
- data/lib/fog/proxmox/network/models/networks.rb +48 -0
- data/lib/fog/proxmox/network/models/node.rb +75 -0
- data/lib/fog/proxmox/network/models/nodes.rb +39 -0
- data/lib/fog/proxmox/network/requests/create_network.rb +41 -0
- data/lib/fog/proxmox/network/requests/delete_network.rb +42 -0
- data/lib/fog/proxmox/network/requests/get_network.rb +43 -0
- data/lib/fog/proxmox/network/requests/get_node.rb +41 -0
- data/lib/fog/proxmox/network/requests/list_networks.rb +43 -0
- data/lib/fog/proxmox/network/requests/list_nodes.rb +42 -0
- data/lib/fog/proxmox/network/requests/power_node.rb +43 -0
- data/lib/fog/proxmox/network/requests/update_network.rb +42 -0
- data/lib/fog/proxmox/network.rb +90 -0
- data/lib/fog/proxmox/storage/requests/create.rb +23 -0
- data/lib/fog/proxmox/storage/requests/download_appliance.rb +24 -0
- data/lib/fog/proxmox/storage/requests/list.rb +22 -0
- data/lib/fog/proxmox/storage/requests/list_appliances.rb +23 -0
- data/lib/fog/proxmox/storage/requests/upload.rb +44 -0
- data/lib/fog/proxmox/storage.rb +82 -0
- data/lib/fog/proxmox/string.rb +32 -0
- data/lib/fog/proxmox/variables.rb +40 -0
- data/lib/fog/proxmox/version.rb +24 -0
- data/lib/fog/proxmox.rb +53 -0
- data/spec/compute_spec.rb +447 -0
- data/spec/fixtures/proxmox/compute/common_auth.yml +40 -0
- data/spec/fixtures/proxmox/compute/containers.yml +6921 -0
- data/spec/fixtures/proxmox/compute/nodes.yml +115 -0
- data/spec/fixtures/proxmox/compute/servers.yml +19011 -0
- data/spec/fixtures/proxmox/compute/snapshots.yml +1376 -0
- data/spec/fixtures/proxmox/compute/storages.yml +151 -0
- data/spec/fixtures/proxmox/compute/tasks.yml +465 -0
- data/spec/fixtures/proxmox/identity/auth.yml +42 -0
- data/spec/fixtures/proxmox/identity/auth_access_ticket.yml +77 -0
- data/spec/fixtures/proxmox/identity/auth_user_token.yml +77 -0
- data/spec/fixtures/proxmox/identity/common_auth.yml +40 -0
- data/spec/fixtures/proxmox/identity/domains.yml +665 -0
- data/spec/fixtures/proxmox/identity/groups.yml +345 -0
- data/spec/fixtures/proxmox/identity/permissions.yml +911 -0
- data/spec/fixtures/proxmox/identity/pools.yml +946 -0
- data/spec/fixtures/proxmox/identity/read_version.yml +40 -0
- data/spec/fixtures/proxmox/identity/roles.yml +345 -0
- data/spec/fixtures/proxmox/identity/tokens.yml +494 -0
- data/spec/fixtures/proxmox/identity/users.yml +725 -0
- data/spec/fixtures/proxmox/network/common_auth.yml +40 -0
- data/spec/fixtures/proxmox/network/networks.yml +375 -0
- data/spec/fixtures/proxmox/pve.home +34 -0
- data/spec/hash_spec.rb +43 -0
- data/spec/helpers/controller_helper_spec.rb +157 -0
- data/spec/helpers/cpu_helper_spec.rb +82 -0
- data/spec/helpers/disk_helper_spec.rb +304 -0
- data/spec/helpers/ip_helper_spec.rb +177 -0
- data/spec/helpers/nic_helper_spec.rb +144 -0
- data/spec/identity_spec.rb +416 -0
- data/spec/network_spec.rb +67 -0
- data/spec/proxmox_vcr.rb +97 -0
- data/spec/spec_helper.rb +41 -0
- metadata +566 -0
@@ -0,0 +1,41 @@
|
|
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
|
+
|
11
|
+
# Fog::Proxmox is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
# frozen_string_literal: true
|
20
|
+
|
21
|
+
module Fog
|
22
|
+
module Proxmox
|
23
|
+
class Compute
|
24
|
+
# class Real status_task
|
25
|
+
class Real
|
26
|
+
def status_task(node, upid)
|
27
|
+
request(
|
28
|
+
expects: [200],
|
29
|
+
method: 'GET',
|
30
|
+
path: "nodes/#{node}/tasks/#{upid}/status"
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# class Mock status_task
|
36
|
+
class Mock
|
37
|
+
def status_task(_node, _upid); end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,41 @@
|
|
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
|
+
|
11
|
+
# Fog::Proxmox is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
# frozen_string_literal: true
|
20
|
+
|
21
|
+
module Fog
|
22
|
+
module Proxmox
|
23
|
+
class Compute
|
24
|
+
# class Real stop_task collection
|
25
|
+
class Real
|
26
|
+
def stop_task(node, upid)
|
27
|
+
request(
|
28
|
+
expects: [200],
|
29
|
+
method: 'DELETE',
|
30
|
+
path: "nodes/#{node}/tasks/#{upid}"
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# class Mock get_task collection
|
36
|
+
class Mock
|
37
|
+
def stop_task(_node, _taskid); end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,44 @@
|
|
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
|
+
module Fog
|
21
|
+
module Proxmox
|
22
|
+
class Compute
|
23
|
+
# class Real template_server request
|
24
|
+
class Real
|
25
|
+
def template_server(path_params, body_params)
|
26
|
+
node = path_params[:node]
|
27
|
+
type = path_params[:type]
|
28
|
+
vmid = path_params[:vmid]
|
29
|
+
request(
|
30
|
+
expects: [200],
|
31
|
+
method: 'POST',
|
32
|
+
path: "nodes/#{node}/#{type}/#{vmid}/template",
|
33
|
+
body: URI.encode_www_form(body_params)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# class Mock template_server request
|
39
|
+
class Mock
|
40
|
+
def template_server(_path_params, _body_params); end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
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
|
+
module Fog
|
21
|
+
module Proxmox
|
22
|
+
class Compute
|
23
|
+
# class Real update_server request
|
24
|
+
class Real
|
25
|
+
def update_server(path_params, body_params)
|
26
|
+
node = path_params[:node]
|
27
|
+
type = path_params[:type]
|
28
|
+
vmid = path_params[:vmid]
|
29
|
+
request(
|
30
|
+
expects: [200],
|
31
|
+
method: type == 'qemu' ? 'POST' : 'PUT',
|
32
|
+
path: "nodes/#{node}/#{type}/#{vmid}/config",
|
33
|
+
body: URI.encode_www_form(body_params)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# class Mock update_server request
|
39
|
+
class Mock
|
40
|
+
def update_server(_path_params, _body_params); end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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
|
+
module Fog
|
21
|
+
module Proxmox
|
22
|
+
class Compute
|
23
|
+
# class Real update_snapshot request
|
24
|
+
class Real
|
25
|
+
def update_snapshot(path_params, body_params)
|
26
|
+
node = path_params[:node]
|
27
|
+
type = path_params[:type]
|
28
|
+
vmid = path_params[:vmid]
|
29
|
+
snapname = path_params[:snapname]
|
30
|
+
request(
|
31
|
+
expects: [200],
|
32
|
+
method: 'PUT',
|
33
|
+
path: "nodes/#{node}/#{type}/#{vmid}/snapshot/#{snapname}/config",
|
34
|
+
body: URI.encode_www_form(body_params)
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# class Mock update_snapshot request
|
40
|
+
class Mock
|
41
|
+
def update_snapshot(_path_params, _body_params); end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,141 @@
|
|
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/core'
|
21
|
+
|
22
|
+
module Fog
|
23
|
+
module Proxmox
|
24
|
+
# Proxmox compute service
|
25
|
+
class Compute < Fog::Service
|
26
|
+
requires :proxmox_url, :proxmox_auth_method
|
27
|
+
recognizes :proxmox_token, :proxmox_tokenid, :proxmox_userid, :persistent, :proxmox_username, :proxmox_password
|
28
|
+
|
29
|
+
# Models
|
30
|
+
model_path 'fog/proxmox/compute/models'
|
31
|
+
model :node
|
32
|
+
collection :nodes
|
33
|
+
model :server
|
34
|
+
collection :servers
|
35
|
+
model :interface
|
36
|
+
collection :interfaces
|
37
|
+
model :disk
|
38
|
+
collection :disks
|
39
|
+
model :server_config
|
40
|
+
model :volume
|
41
|
+
collection :volumes
|
42
|
+
model :storage
|
43
|
+
collection :storages
|
44
|
+
model :task
|
45
|
+
collection :tasks
|
46
|
+
model :snapshot
|
47
|
+
collection :snapshots
|
48
|
+
|
49
|
+
# Requests
|
50
|
+
request_path 'fog/proxmox/compute/requests'
|
51
|
+
|
52
|
+
# Manage nodes cluster
|
53
|
+
request :list_nodes
|
54
|
+
request :get_node_statistics
|
55
|
+
request :next_vmid
|
56
|
+
# Manage servers
|
57
|
+
request :list_servers
|
58
|
+
request :create_server
|
59
|
+
request :get_server_status
|
60
|
+
request :get_server_config
|
61
|
+
request :update_server
|
62
|
+
request :delete_server
|
63
|
+
request :action_server
|
64
|
+
request :template_server
|
65
|
+
request :clone_server
|
66
|
+
request :migrate_server
|
67
|
+
request :move_disk
|
68
|
+
request :move_volume
|
69
|
+
request :resize_server
|
70
|
+
request :resize_container
|
71
|
+
# Manage volumes
|
72
|
+
request :list_volumes
|
73
|
+
request :get_volume
|
74
|
+
request :delete_volume
|
75
|
+
# Manage backups
|
76
|
+
request :create_backup
|
77
|
+
# Manage storages
|
78
|
+
request :list_storages
|
79
|
+
# Tasks
|
80
|
+
request :list_tasks
|
81
|
+
request :get_task
|
82
|
+
request :stop_task
|
83
|
+
request :status_task
|
84
|
+
request :log_task
|
85
|
+
# CRUD snapshots
|
86
|
+
request :list_snapshots
|
87
|
+
request :get_snapshot_config
|
88
|
+
request :create_snapshot
|
89
|
+
request :update_snapshot
|
90
|
+
request :delete_snapshot
|
91
|
+
request :rollback_snapshot
|
92
|
+
# Consoles
|
93
|
+
request :create_term
|
94
|
+
request :create_spice
|
95
|
+
request :create_vnc
|
96
|
+
request :get_vnc
|
97
|
+
|
98
|
+
# Mock class
|
99
|
+
class Mock
|
100
|
+
attr_reader :config
|
101
|
+
|
102
|
+
def initialize(options = {})
|
103
|
+
@proxmox_uri = URI.parse(options[:proxmox_url])
|
104
|
+
@proxmox_auth_method = options[:proxmox_auth_method]
|
105
|
+
@proxmox_tokenid = options[:proxmox_tokenid]
|
106
|
+
@proxmox_userid = options[:proxmox_userid]
|
107
|
+
@proxmox_username = options[:proxmox_username]
|
108
|
+
@proxmox_password = options[:proxmox_password]
|
109
|
+
@proxmox_token = options[:proxmox_token]
|
110
|
+
@proxmox_path = @proxmox_uri.path
|
111
|
+
@config = options
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Real class
|
116
|
+
class Real
|
117
|
+
include Fog::Proxmox::Core
|
118
|
+
|
119
|
+
def self.not_found_class
|
120
|
+
Fog::Proxmox::Compute::NotFound
|
121
|
+
end
|
122
|
+
|
123
|
+
def config
|
124
|
+
self
|
125
|
+
end
|
126
|
+
|
127
|
+
def config_service?
|
128
|
+
true
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def configure(source)
|
134
|
+
source.instance_variables.each do |v|
|
135
|
+
instance_variable_set(v, source.instance_variable_get(v))
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,147 @@
|
|
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/json'
|
21
|
+
require 'fog/proxmox/variables'
|
22
|
+
require 'fog/proxmox/json'
|
23
|
+
|
24
|
+
module Fog
|
25
|
+
module Proxmox
|
26
|
+
# Core module
|
27
|
+
module Core
|
28
|
+
attr_accessor :token
|
29
|
+
attr_reader :auth_method, :expires, :current_user
|
30
|
+
|
31
|
+
def user_token?
|
32
|
+
@auth_token == 'user_token'
|
33
|
+
end
|
34
|
+
|
35
|
+
# fallback
|
36
|
+
def self.not_found_class
|
37
|
+
Fog::Proxmox::Core::NotFound
|
38
|
+
end
|
39
|
+
|
40
|
+
def initialize(options = {})
|
41
|
+
setup(options)
|
42
|
+
authenticate
|
43
|
+
@auth_token.missing_credentials(options)
|
44
|
+
@connection = Fog::Core::Connection.new(@proxmox_url, @persistent, @connection_options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup(options)
|
48
|
+
if options.respond_to?(:config_service?) && options.config_service?
|
49
|
+
configure(options)
|
50
|
+
return
|
51
|
+
end
|
52
|
+
Fog::Proxmox::Variables.to_variables(self, options, 'proxmox')
|
53
|
+
@connection_options = options[:connection_options] || {}
|
54
|
+
@connection_options[:disable_proxy] = true if ENV['DISABLE_PROXY'] == 'true'
|
55
|
+
@connection_options[:ssl_verify_peer] = false if ENV['SSL_VERIFY_PEER'] == 'false'
|
56
|
+
@proxmox_must_reauthenticate = true
|
57
|
+
@persistent = options[:persistent] || false
|
58
|
+
@token ||= options[:proxmox_token]
|
59
|
+
@auth_method ||= options[:proxmox_auth_method]
|
60
|
+
@proxmox_can_reauthenticate = if @token
|
61
|
+
false
|
62
|
+
else
|
63
|
+
true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def credentials
|
68
|
+
options = {
|
69
|
+
provider: 'proxmox',
|
70
|
+
proxmox_auth_method: @auth_method,
|
71
|
+
proxmox_url: @proxmox_uri.to_s,
|
72
|
+
current_user: @current_user
|
73
|
+
}
|
74
|
+
proxmox_options.merge options
|
75
|
+
end
|
76
|
+
|
77
|
+
def reload
|
78
|
+
@connection.reset
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def expired?
|
84
|
+
return false if @expires.nil?
|
85
|
+
return false if @expires == 0
|
86
|
+
|
87
|
+
@expires - Time.now.utc.to_i < 60
|
88
|
+
end
|
89
|
+
|
90
|
+
def request(params)
|
91
|
+
retried = false
|
92
|
+
begin
|
93
|
+
authenticate! if expired?
|
94
|
+
request_options = params.merge(path: "#{@path}/#{params[:path]}",
|
95
|
+
headers: @auth_token.headers(
|
96
|
+
params[:method], {}, params.key?(:headers) ? params[:headers] : {}
|
97
|
+
))
|
98
|
+
response = @connection.request(request_options)
|
99
|
+
rescue Excon::Errors::Unauthorized => e
|
100
|
+
# token expiration and token renewal possible
|
101
|
+
if !%w[Bad username or password, invalid token
|
102
|
+
value!].include?(e.response.body) && @proxmox_can_reauthenticate && !retried
|
103
|
+
authenticate!
|
104
|
+
retried = true
|
105
|
+
retry
|
106
|
+
# bad credentials or token renewal not possible
|
107
|
+
else
|
108
|
+
raise e
|
109
|
+
end
|
110
|
+
rescue Excon::Errors::HTTPStatusError => e
|
111
|
+
raise case e
|
112
|
+
when Excon::Errors::NotFound
|
113
|
+
self.class.not_found_class.slurp(e)
|
114
|
+
else
|
115
|
+
e
|
116
|
+
end
|
117
|
+
end
|
118
|
+
Fog::Proxmox::Json.get_data(response)
|
119
|
+
end
|
120
|
+
|
121
|
+
def proxmox_options
|
122
|
+
Fog::Proxmox::Variables.to_hash(self, 'proxmox')
|
123
|
+
end
|
124
|
+
|
125
|
+
def authenticate
|
126
|
+
if @proxmox_must_reauthenticate
|
127
|
+
@token = nil if @proxmox_must_reauthenticate
|
128
|
+
@auth_token = Fog::Proxmox::Auth::Token.build(proxmox_options, @connection_options)
|
129
|
+
@current_user = proxmox_options[:proxmox_userid] || proxmox_options[:proxmox_username]
|
130
|
+
@token = @auth_token.token
|
131
|
+
@expires = @auth_token.expires
|
132
|
+
@proxmox_must_reauthenticate = false
|
133
|
+
else
|
134
|
+
@token = @proxmox_token
|
135
|
+
end
|
136
|
+
uri = URI.parse(@proxmox_url)
|
137
|
+
@path = uri.path
|
138
|
+
true
|
139
|
+
end
|
140
|
+
|
141
|
+
def authenticate!
|
142
|
+
@proxmox_must_reauthenticate = true
|
143
|
+
authenticate
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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
|
+
module Fog
|
21
|
+
module Proxmox
|
22
|
+
module Errors
|
23
|
+
# class ServiceError
|
24
|
+
class ServiceError < Fog::Errors::Error
|
25
|
+
attr_reader :response_data
|
26
|
+
|
27
|
+
def self.slurp(error)
|
28
|
+
if error.response.body.empty?
|
29
|
+
data = nil
|
30
|
+
message = nil
|
31
|
+
else
|
32
|
+
data = Fog::JSON.decode(error.response.body)
|
33
|
+
message = data['message']
|
34
|
+
data1 = data.values.first
|
35
|
+
message = data1['message'] if message.nil? && !data1.nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
new_error = super(error, message)
|
39
|
+
new_error.instance_variable_set(:@response_data, data)
|
40
|
+
new_error
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# class ServiceUnavailable error
|
45
|
+
class ServiceUnavailable < ServiceError; end
|
46
|
+
|
47
|
+
# class BadRequest error
|
48
|
+
class BadRequest < ServiceError
|
49
|
+
attr_reader :validation_errors
|
50
|
+
|
51
|
+
def self.slurp(error)
|
52
|
+
new_error = super(error)
|
53
|
+
unless new_error.response_data.nil? || new_error.response_data['badRequest'].nil?
|
54
|
+
new_error.instance_variable_set(:@validation_errors,
|
55
|
+
new_error.response_data['badRequest']['validationErrors'])
|
56
|
+
end
|
57
|
+
new_error
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# class InterfaceNotImplemented error
|
62
|
+
class InterfaceNotImplemented < Fog::Errors::Error; end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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
|
+
module Fog
|
21
|
+
module Proxmox
|
22
|
+
# module Hash mixins
|
23
|
+
module Hash
|
24
|
+
def self.stringify(hash)
|
25
|
+
filtered = hash.reject { |_key, value| value.nil? }
|
26
|
+
a = filtered.to_a.collect { |item| item.join('=') }
|
27
|
+
a.join(',')
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.flatten(hash)
|
31
|
+
filtered = hash.reject { |_key, value| value.nil? }
|
32
|
+
a = filtered.to_a.collect { |item| item.join(': ') }
|
33
|
+
a.join(',')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,63 @@
|
|
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
|
+
module Fog
|
21
|
+
module Proxmox
|
22
|
+
# module ControllerHelper mixins
|
23
|
+
module ControllerHelper
|
24
|
+
CONTROLLERS = %w[ide sata scsi virtio mp rootfs].freeze
|
25
|
+
def self.extract(name, controller_value)
|
26
|
+
matches = controller_value.match(%r{,{0,1}#{name}={1}(?<name_value>[\w/.:]+)})
|
27
|
+
matches ? matches[:name_value] : matches
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.extract_index(name, key)
|
31
|
+
matches = key.to_s.match(/#{name}(?<index>\d+)/)
|
32
|
+
index = matches ? matches[:index] : matches
|
33
|
+
index ? index.to_i : -1
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.valid?(name, key)
|
37
|
+
key.to_s.match(/^#{name}(\d*)$/)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.last_index(name, values)
|
41
|
+
return -1 if values.empty?
|
42
|
+
|
43
|
+
indexes = []
|
44
|
+
values.each do |value|
|
45
|
+
index = extract_index(name, value)
|
46
|
+
indexes.push(index) if index
|
47
|
+
end
|
48
|
+
indexes.sort
|
49
|
+
indexes.empty? ? -1 : indexes.last
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.select(hash, name)
|
53
|
+
hash.select { |key| valid?(name, key.to_s) }
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.collect_controllers(attributes)
|
57
|
+
controllers = {}
|
58
|
+
CONTROLLERS.each { |controller| controllers.merge!(select(attributes, controller)) }
|
59
|
+
controllers
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|