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.
Files changed (199) hide show
  1. checksums.yaml +7 -0
  2. data/.bundle/config +4 -0
  3. data/.codeclimate.yml +14 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +35 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
  6. data/.gitignore +5 -0
  7. data/.gitlab-ci.yml +42 -0
  8. data/.rubocop.yml +13 -0
  9. data/.ruby-gemset +1 -0
  10. data/.solargraph.yml +10 -0
  11. data/.travis.yml +26 -0
  12. data/.vscode/launch.json +114 -0
  13. data/.vscode/settings.json +45 -0
  14. data/.vscode/tasks.json +27 -0
  15. data/CODE_OF_CONDUCT.md +74 -0
  16. data/CONTRIBUTING.md +20 -0
  17. data/CONTRIBUTORS.md +9 -0
  18. data/Gemfile +23 -0
  19. data/Gemfile.lock +146 -0
  20. data/ISSUE_TEMPLATE.md +43 -0
  21. data/LICENSE +674 -0
  22. data/README.md +58 -0
  23. data/Rakefile +53 -0
  24. data/SUPPORT.md +9 -0
  25. data/bin/console +29 -0
  26. data/bin/setup +29 -0
  27. data/docs/compute.md +846 -0
  28. data/docs/connection_parameters.md +45 -0
  29. data/docs/getting_started.md +53 -0
  30. data/docs/identity.md +357 -0
  31. data/examples/compute.rb +279 -0
  32. data/examples/identity.rb +195 -0
  33. data/fog-proxmox.gemspec +63 -0
  34. data/fogproxmox.png +0 -0
  35. data/lib/fog/compute/proxmox.rb +131 -0
  36. data/lib/fog/compute/proxmox/models/container.rb +97 -0
  37. data/lib/fog/compute/proxmox/models/container_config.rb +90 -0
  38. data/lib/fog/compute/proxmox/models/containers.rb +40 -0
  39. data/lib/fog/compute/proxmox/models/disk.rb +67 -0
  40. data/lib/fog/compute/proxmox/models/disks.rb +49 -0
  41. data/lib/fog/compute/proxmox/models/interface.rb +50 -0
  42. data/lib/fog/compute/proxmox/models/interfaces.rb +46 -0
  43. data/lib/fog/compute/proxmox/models/node.rb +93 -0
  44. data/lib/fog/compute/proxmox/models/nodes.rb +45 -0
  45. data/lib/fog/compute/proxmox/models/server.rb +212 -0
  46. data/lib/fog/compute/proxmox/models/server_config.rb +116 -0
  47. data/lib/fog/compute/proxmox/models/servers.rb +70 -0
  48. data/lib/fog/compute/proxmox/models/snapshot.rb +70 -0
  49. data/lib/fog/compute/proxmox/models/snapshots.rb +55 -0
  50. data/lib/fog/compute/proxmox/models/storage.rb +61 -0
  51. data/lib/fog/compute/proxmox/models/storages.rb +60 -0
  52. data/lib/fog/compute/proxmox/models/task.rb +84 -0
  53. data/lib/fog/compute/proxmox/models/tasks.rb +71 -0
  54. data/lib/fog/compute/proxmox/models/volume.rb +61 -0
  55. data/lib/fog/compute/proxmox/models/volumes.rb +67 -0
  56. data/lib/fog/compute/proxmox/requests/action_server.rb +47 -0
  57. data/lib/fog/compute/proxmox/requests/check_vmid.rb +41 -0
  58. data/lib/fog/compute/proxmox/requests/clone_server.rb +46 -0
  59. data/lib/fog/compute/proxmox/requests/create_backup.rb +44 -0
  60. data/lib/fog/compute/proxmox/requests/create_server.rb +45 -0
  61. data/lib/fog/compute/proxmox/requests/create_snapshot.rb +47 -0
  62. data/lib/fog/compute/proxmox/requests/create_spice.rb +46 -0
  63. data/lib/fog/compute/proxmox/requests/create_term.rb +46 -0
  64. data/lib/fog/compute/proxmox/requests/create_vnc.rb +46 -0
  65. data/lib/fog/compute/proxmox/requests/delete_server.rb +47 -0
  66. data/lib/fog/compute/proxmox/requests/delete_snapshot.rb +48 -0
  67. data/lib/fog/compute/proxmox/requests/delete_volume.rb +40 -0
  68. data/lib/fog/compute/proxmox/requests/get_node.rb +44 -0
  69. data/lib/fog/compute/proxmox/requests/get_server_config.rb +45 -0
  70. data/lib/fog/compute/proxmox/requests/get_server_status.rb +45 -0
  71. data/lib/fog/compute/proxmox/requests/get_snapshot.rb +47 -0
  72. data/lib/fog/compute/proxmox/requests/get_storage.rb +44 -0
  73. data/lib/fog/compute/proxmox/requests/get_task.rb +44 -0
  74. data/lib/fog/compute/proxmox/requests/get_vnc.rb +46 -0
  75. data/lib/fog/compute/proxmox/requests/get_volume.rb +42 -0
  76. data/lib/fog/compute/proxmox/requests/list_nodes.rb +42 -0
  77. data/lib/fog/compute/proxmox/requests/list_servers.rb +42 -0
  78. data/lib/fog/compute/proxmox/requests/list_snapshots.rb +43 -0
  79. data/lib/fog/compute/proxmox/requests/list_storages.rb +42 -0
  80. data/lib/fog/compute/proxmox/requests/list_tasks.rb +42 -0
  81. data/lib/fog/compute/proxmox/requests/list_volumes.rb +42 -0
  82. data/lib/fog/compute/proxmox/requests/log_task.rb +45 -0
  83. data/lib/fog/compute/proxmox/requests/migrate_server.rb +44 -0
  84. data/lib/fog/compute/proxmox/requests/move_disk.rb +46 -0
  85. data/lib/fog/compute/proxmox/requests/move_volume.rb +46 -0
  86. data/lib/fog/compute/proxmox/requests/next_vmid.rb +39 -0
  87. data/lib/fog/compute/proxmox/requests/resize_container.rb +46 -0
  88. data/lib/fog/compute/proxmox/requests/resize_server.rb +43 -0
  89. data/lib/fog/compute/proxmox/requests/rollback_snapshot.rb +46 -0
  90. data/lib/fog/compute/proxmox/requests/status_task.rb +44 -0
  91. data/lib/fog/compute/proxmox/requests/stop_task.rb +41 -0
  92. data/lib/fog/compute/proxmox/requests/template_server.rb +43 -0
  93. data/lib/fog/compute/proxmox/requests/update_server.rb +46 -0
  94. data/lib/fog/compute/proxmox/requests/update_snapshot.rb +45 -0
  95. data/lib/fog/identity/proxmox.rb +132 -0
  96. data/lib/fog/identity/proxmox/models/activedirectory.rb +57 -0
  97. data/lib/fog/identity/proxmox/models/domain.rb +61 -0
  98. data/lib/fog/identity/proxmox/models/domains.rb +115 -0
  99. data/lib/fog/identity/proxmox/models/group.rb +60 -0
  100. data/lib/fog/identity/proxmox/models/groups.rb +50 -0
  101. data/lib/fog/identity/proxmox/models/ldap.rb +57 -0
  102. data/lib/fog/identity/proxmox/models/oath.rb +50 -0
  103. data/lib/fog/identity/proxmox/models/pam.rb +46 -0
  104. data/lib/fog/identity/proxmox/models/permission.rb +69 -0
  105. data/lib/fog/identity/proxmox/models/permissions.rb +61 -0
  106. data/lib/fog/identity/proxmox/models/pool.rb +84 -0
  107. data/lib/fog/identity/proxmox/models/pools.rb +50 -0
  108. data/lib/fog/identity/proxmox/models/principal.rb +47 -0
  109. data/lib/fog/identity/proxmox/models/pve.rb +46 -0
  110. data/lib/fog/identity/proxmox/models/role.rb +61 -0
  111. data/lib/fog/identity/proxmox/models/roles.rb +51 -0
  112. data/lib/fog/identity/proxmox/models/user.rb +74 -0
  113. data/lib/fog/identity/proxmox/models/users.rb +50 -0
  114. data/lib/fog/identity/proxmox/models/yubico.rb +51 -0
  115. data/lib/fog/identity/proxmox/requests/add_permission.rb +41 -0
  116. data/lib/fog/identity/proxmox/requests/change_password.rb +41 -0
  117. data/lib/fog/identity/proxmox/requests/check_permissions.rb +44 -0
  118. data/lib/fog/identity/proxmox/requests/create_domain.rb +40 -0
  119. data/lib/fog/identity/proxmox/requests/create_group.rb +40 -0
  120. data/lib/fog/identity/proxmox/requests/create_pool.rb +40 -0
  121. data/lib/fog/identity/proxmox/requests/create_role.rb +40 -0
  122. data/lib/fog/identity/proxmox/requests/create_user.rb +40 -0
  123. data/lib/fog/identity/proxmox/requests/delete_domain.rb +40 -0
  124. data/lib/fog/identity/proxmox/requests/delete_group.rb +40 -0
  125. data/lib/fog/identity/proxmox/requests/delete_pool.rb +39 -0
  126. data/lib/fog/identity/proxmox/requests/delete_role.rb +40 -0
  127. data/lib/fog/identity/proxmox/requests/delete_user.rb +39 -0
  128. data/lib/fog/identity/proxmox/requests/get_domain.rb +41 -0
  129. data/lib/fog/identity/proxmox/requests/get_group.rb +41 -0
  130. data/lib/fog/identity/proxmox/requests/get_pool.rb +41 -0
  131. data/lib/fog/identity/proxmox/requests/get_role.rb +41 -0
  132. data/lib/fog/identity/proxmox/requests/get_user.rb +40 -0
  133. data/lib/fog/identity/proxmox/requests/list_domains.rb +41 -0
  134. data/lib/fog/identity/proxmox/requests/list_groups.rb +41 -0
  135. data/lib/fog/identity/proxmox/requests/list_permissions.rb +41 -0
  136. data/lib/fog/identity/proxmox/requests/list_pools.rb +41 -0
  137. data/lib/fog/identity/proxmox/requests/list_roles.rb +41 -0
  138. data/lib/fog/identity/proxmox/requests/list_users.rb +42 -0
  139. data/lib/fog/identity/proxmox/requests/read_version.rb +43 -0
  140. data/lib/fog/identity/proxmox/requests/remove_permission.rb +42 -0
  141. data/lib/fog/identity/proxmox/requests/update_domain.rb +41 -0
  142. data/lib/fog/identity/proxmox/requests/update_group.rb +41 -0
  143. data/lib/fog/identity/proxmox/requests/update_pool.rb +41 -0
  144. data/lib/fog/identity/proxmox/requests/update_role.rb +41 -0
  145. data/lib/fog/identity/proxmox/requests/update_user.rb +41 -0
  146. data/lib/fog/network/proxmox.rb +83 -0
  147. data/lib/fog/network/proxmox/models/network.rb +82 -0
  148. data/lib/fog/network/proxmox/models/networks.rb +54 -0
  149. data/lib/fog/network/proxmox/models/node.rb +70 -0
  150. data/lib/fog/network/proxmox/models/nodes.rb +45 -0
  151. data/lib/fog/network/proxmox/requests/create_network.rb +44 -0
  152. data/lib/fog/network/proxmox/requests/delete_network.rb +45 -0
  153. data/lib/fog/network/proxmox/requests/get_network.rb +46 -0
  154. data/lib/fog/network/proxmox/requests/get_node.rb +44 -0
  155. data/lib/fog/network/proxmox/requests/list_networks.rb +43 -0
  156. data/lib/fog/network/proxmox/requests/list_nodes.rb +42 -0
  157. data/lib/fog/network/proxmox/requests/power_node.rb +46 -0
  158. data/lib/fog/network/proxmox/requests/update_network.rb +46 -0
  159. data/lib/fog/proxmox.rb +128 -0
  160. data/lib/fog/proxmox/core.rb +139 -0
  161. data/lib/fog/proxmox/errors.rb +64 -0
  162. data/lib/fog/proxmox/hash.rb +33 -0
  163. data/lib/fog/proxmox/helpers/controller_helper.rb +55 -0
  164. data/lib/fog/proxmox/helpers/cpu_helper.rb +45 -0
  165. data/lib/fog/proxmox/helpers/disk_helper.rb +84 -0
  166. data/lib/fog/proxmox/helpers/nic_helper.rb +62 -0
  167. data/lib/fog/proxmox/json.rb +32 -0
  168. data/lib/fog/proxmox/models/collection.rb +85 -0
  169. data/lib/fog/proxmox/models/model.rb +58 -0
  170. data/lib/fog/proxmox/variables.rb +40 -0
  171. data/lib/fog/proxmox/version.rb +24 -0
  172. data/lib/fog/storage/proxmox.rb +29 -0
  173. data/spec/compute_spec.rb +408 -0
  174. data/spec/fixtures/proxmox/compute/containers.yml +5398 -0
  175. data/spec/fixtures/proxmox/compute/identity_ticket.yml +40 -0
  176. data/spec/fixtures/proxmox/compute/servers.yml +10571 -0
  177. data/spec/fixtures/proxmox/compute/snapshots.yml +1228 -0
  178. data/spec/fixtures/proxmox/compute/storages.yml +120 -0
  179. data/spec/fixtures/proxmox/compute/tasks.yml +200 -0
  180. data/spec/fixtures/proxmox/identity/auth.yml +44 -0
  181. data/spec/fixtures/proxmox/identity/domains.yml +531 -0
  182. data/spec/fixtures/proxmox/identity/groups.yml +324 -0
  183. data/spec/fixtures/proxmox/identity/identity_ticket.yml +40 -0
  184. data/spec/fixtures/proxmox/identity/permissions.yml +565 -0
  185. data/spec/fixtures/proxmox/identity/pools.yml +488 -0
  186. data/spec/fixtures/proxmox/identity/read_version.yml +42 -0
  187. data/spec/fixtures/proxmox/identity/roles.yml +324 -0
  188. data/spec/fixtures/proxmox/identity/users.yml +646 -0
  189. data/spec/fixtures/proxmox/network/identity_ticket.yml +40 -0
  190. data/spec/fixtures/proxmox/network/networks.yml +413 -0
  191. data/spec/helpers/controller_helper_spec.rb +77 -0
  192. data/spec/helpers/cpu_helper_spec.rb +91 -0
  193. data/spec/helpers/disk_helper_spec.rb +104 -0
  194. data/spec/helpers/nic_helper_spec.rb +73 -0
  195. data/spec/identity_spec.rb +316 -0
  196. data/spec/network_spec.rb +67 -0
  197. data/spec/proxmox_vcr.rb +102 -0
  198. data/spec/spec_helper.rb +39 -0
  199. metadata +535 -0
@@ -0,0 +1,63 @@
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
+ lib = File.expand_path('lib', __dir__)
22
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
23
+ require 'fog/proxmox/version'
24
+
25
+ Gem::Specification.new do |spec|
26
+ spec.name = 'fog-proxmox'
27
+ spec.version = Fog::Proxmox::VERSION
28
+ spec.authors = ['Tristan Robert']
29
+ spec.email = ['tristan.robert.44@gmail.com']
30
+
31
+ spec.summary = "Module for the 'Fog' gem to support Proxmox VE"
32
+ spec.description = 'This library can be used as a module for `fog`.'
33
+ spec.homepage = 'http://github.com/fog/fog-proxmox'
34
+ spec.license = 'GPL-3.0'
35
+
36
+ spec.files = `git ls-files -z`.split("\x0")
37
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
38
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
39
+ spec.require_paths = ['lib']
40
+ spec.required_ruby_version = '>= 2.3'
41
+ spec.rubygems_version = '~> 2.6'
42
+
43
+ spec.add_development_dependency 'bundler', '~> 1.16'
44
+ spec.add_development_dependency 'debase', '~> 0.2.2'
45
+ spec.add_development_dependency 'debride', '~> 1.8'
46
+ spec.add_development_dependency 'fasterer', '~> 0.3'
47
+ spec.add_development_dependency 'fastri', '~> 0.3'
48
+ spec.add_development_dependency 'minitest', '~> 5.11'
49
+ spec.add_development_dependency 'pry', '~> 0.11'
50
+ spec.add_development_dependency 'rake', '~> 12.3'
51
+ spec.add_development_dependency 'rcodetools', '~> 0.3'
52
+ spec.add_development_dependency 'reek', '~> 4.7'
53
+ spec.add_development_dependency 'rspec', '~> 3.7'
54
+ spec.add_development_dependency 'rubocop', '~> 0.55'
55
+ spec.add_development_dependency 'ruby-debug-ide', '~> 0.6'
56
+ spec.add_development_dependency 'simplecov'
57
+ spec.add_development_dependency 'vcr', '~> 3.0'
58
+ spec.add_development_dependency 'webmock', '~> 3.4'
59
+
60
+ spec.add_dependency 'fog-core', '~> 1.45'
61
+ spec.add_dependency 'fog-json', '~> 1.0'
62
+ spec.add_dependency 'ipaddress', '~> 0.8'
63
+ end
data/fogproxmox.png ADDED
Binary file
@@ -0,0 +1,131 @@
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 Compute
24
+ # Proxmox compute service
25
+ class Proxmox < Fog::Service
26
+ requires :pve_url
27
+ recognizes :pve_ticket, :pve_path, :pve_ticket_expires,
28
+ :pve_csrftoken, :persistent, :current_user, :pve_username,
29
+ :pve_password, :pve_deadline
30
+
31
+ # Models
32
+ model_path 'fog/compute/proxmox/models'
33
+ model :node
34
+ collection :nodes
35
+ model :server
36
+ collection :servers
37
+ model :interface
38
+ collection :interfaces
39
+ model :disk
40
+ collection :disks
41
+ model :server_config
42
+ model :volume
43
+ collection :volumes
44
+ model :storage
45
+ collection :storages
46
+ model :task
47
+ collection :tasks
48
+ model :snapshot
49
+ collection :snapshots
50
+ model :container
51
+ collection :containers
52
+ model :container_config
53
+
54
+ # Requests
55
+ request_path 'fog/compute/proxmox/requests'
56
+
57
+ # Manage nodes cluster
58
+ request :list_nodes
59
+ request :get_node
60
+ # Manage servers
61
+ request :next_vmid
62
+ request :check_vmid
63
+ request :list_servers
64
+ request :create_server
65
+ request :get_server_status
66
+ request :get_server_config
67
+ request :update_server
68
+ request :delete_server
69
+ request :action_server
70
+ request :template_server
71
+ request :clone_server
72
+ request :migrate_server
73
+ request :move_disk
74
+ request :move_volume
75
+ request :resize_server
76
+ request :resize_container
77
+ # Manage volumes
78
+ request :list_volumes
79
+ request :get_volume
80
+ request :delete_volume
81
+ # Manage backups
82
+ request :create_backup
83
+ # Manage storages
84
+ request :list_storages
85
+ request :get_storage
86
+ # Tasks
87
+ request :list_tasks
88
+ request :get_task
89
+ request :stop_task
90
+ request :status_task
91
+ request :log_task
92
+ # CRUD snapshots
93
+ request :list_snapshots
94
+ request :get_snapshot
95
+ request :create_snapshot
96
+ request :update_snapshot
97
+ request :delete_snapshot
98
+ request :rollback_snapshot
99
+ # Consoles
100
+ request :create_term
101
+ request :create_spice
102
+ request :create_vnc
103
+ request :get_vnc
104
+
105
+ # Mock class
106
+ class Mock
107
+ attr_reader :config
108
+
109
+ def initialize(options = {})
110
+ @pve_uri = URI.parse(options[:pve_url])
111
+ @pve_path = @pve_uri.path
112
+ @config = options
113
+ end
114
+ end
115
+
116
+ # Real class
117
+ class Real
118
+ include Fog::Proxmox::Core
119
+ def initialize(options = {})
120
+ initialize_identity(options)
121
+ @connection_options = options[:connection_options] || {}
122
+ @path_prefix = URI.parse(options[:pve_url]).path
123
+ authenticate
124
+ @persistent = options[:persistent] || false
125
+ url = "#{@scheme}://#{@host}:#{@port}"
126
+ @connection = Fog::Core::Connection.new(url, @persistent, @connection_options.merge(path_prefix: @path_prefix))
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,97 @@
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
+ require 'fog/compute/proxmox/models/container_config'
22
+
23
+ module Fog
24
+ module Compute
25
+ class Proxmox
26
+ # Container model
27
+ class Container < Fog::Compute::Proxmox::Server
28
+ identity :vmid
29
+ attribute :lock
30
+ attribute :maxswap
31
+ attribute :swap
32
+ attribute :config
33
+
34
+ def initialize(attributes = {})
35
+ prepare_service_value(attributes)
36
+ set_config(attributes)
37
+ super
38
+ end
39
+
40
+ def type(attributes = {})
41
+ @type ||= 'lxc' unless attributes[:type] || attributes['type']
42
+ @type
43
+ end
44
+
45
+ def restore(backup, options = {})
46
+ requires :node, :vmid
47
+ path_params = { node: node, type: type }
48
+ body_params = options.merge(vmid: vmid, ostemplate: backup.volid, force: 1, restore: 1)
49
+ task_upid = service.create_server(path_params, body_params)
50
+ tasks.wait_for(task_upid)
51
+ end
52
+
53
+ def move(volume, storage, options = {})
54
+ requires :vmid, :node
55
+ path_params = { node: node, vmid: vmid }
56
+ body_params = options.merge(volume: volume, storage: storage)
57
+ task_upid = service.move_volume(path_params, body_params)
58
+ tasks.wait_for(task_upid)
59
+ end
60
+
61
+ def update(config = {})
62
+ requires :node, :vmid
63
+ path_params = { node: node, type: type, vmid: vmid }
64
+ body_params = config
65
+ service.update_server(path_params, body_params)
66
+ end
67
+
68
+ def set_config(attributes = {})
69
+ @config = Fog::Compute::Proxmox::ContainerConfig.new({ service: service }.merge(attributes))
70
+ end
71
+
72
+ def config
73
+ path_params = { node: node, type: type, vmid: vmid }
74
+ set_config(service.get_server_config(path_params)) if uptime
75
+ @config
76
+ end
77
+
78
+ def detach(mpid)
79
+ update(delete: mpid)
80
+ end
81
+
82
+ def extend(disk, size, options = {})
83
+ requires :vmid, :node
84
+ path_params = { node: node, vmid: vmid }
85
+ body_params = options.merge(disk: disk, size: size)
86
+ task_upid = service.resize_container(path_params, body_params)
87
+ tasks.wait_for(task_upid)
88
+ end
89
+
90
+ def action(action, options = {})
91
+ raise Fog::Errors::Error, "Action #{action} not implemented" unless %w[start stop shutdown].include? action
92
+ super
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,90 @@
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
+
23
+ module Fog
24
+ module Compute
25
+ class Proxmox
26
+ # ContainerConfig model
27
+ class ContainerConfig < Fog::Proxmox::Model
28
+ identity :digest
29
+ attribute :ostype
30
+ attribute :arch
31
+ attribute :memory
32
+ attribute :swap
33
+ attribute :hostname
34
+ attribute :onboot
35
+ attribute :rootfs
36
+ attribute :interfaces
37
+ attribute :mount_points
38
+
39
+ def initialize(attributes = {})
40
+ prepare_service_value(attributes)
41
+ compute_nets(attributes)
42
+ compute_mps(attributes)
43
+ super(attributes)
44
+ end
45
+
46
+ attr_reader :interfaces
47
+
48
+ attr_reader :mount_points
49
+
50
+ def mac_addresses
51
+ Fog::Proxmox::NicHelper.to_mac_adresses_array(interfaces)
52
+ end
53
+
54
+ private
55
+
56
+ def compute_nets(attributes)
57
+ nets = Fog::Proxmox::ControllerHelper.to_hash(attributes, Fog::Compute::Proxmox::Interface::NAME)
58
+ @interfaces ||= Fog::Compute::Proxmox::Interfaces.new
59
+ nets.each do |key, value|
60
+ nic_hash = {
61
+ id: key.to_s,
62
+ name: Fog::Proxmox::NicHelper.extract_name(value),
63
+ mac: Fog::Proxmox::NicHelper.extract_mac_address(value)
64
+ }
65
+ names = Fog::Compute::Proxmox::Interface.attributes.reject { |key, _value| %i[id mac name].include? key }
66
+ names.each { |name| nic_hash.store(name.to_sym, Fog::Proxmox::ControllerHelper.extract(name, value)) }
67
+ @interfaces << Fog::Compute::Proxmox::Interface.new(nic_hash)
68
+ end
69
+ end
70
+
71
+ def compute_mps(attributes)
72
+ mps = Fog::Proxmox::ControllerHelper.to_hash(attributes, 'mp')
73
+ @mount_points ||= Fog::Compute::Proxmox::Disks.new
74
+ mps.each do |key, value|
75
+ storage, volid, size = Fog::Proxmox::DiskHelper.extract_storage_volid_size(value)
76
+ disk_hash = {
77
+ id: key.to_s,
78
+ storage: storage,
79
+ volid: volid,
80
+ size: size
81
+ }
82
+ names = Fog::Compute::Proxmox::Disk.attributes.reject { |key, _value| %i[id size storage].include? key }
83
+ names.each { |name| disk_hash.store(name.to_sym, Fog::Proxmox::ControllerHelper.extract(name, value)) }
84
+ @mount_points << Fog::Compute::Proxmox::Disk.new(disk_hash)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,40 @@
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
+ # Containers Collection
26
+ class Containers < Fog::Compute::Proxmox::Servers
27
+ model Fog::Compute::Proxmox::Container
28
+
29
+ def new(attributes = {})
30
+ super({ node: node, type: type }.merge(attributes))
31
+ end
32
+
33
+ def type(attributes = {})
34
+ @type ||= 'lxc' unless attributes[:type] || attributes['type']
35
+ @type
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,67 @@
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
+ require 'fog/proxmox/helpers/disk_helper'
31
+
32
+ module Fog
33
+ module Compute
34
+ class Proxmox
35
+ # class Disk model
36
+ class Disk < Fog::Proxmox::Model
37
+ identity :id
38
+ attribute :volid
39
+ attribute :size
40
+ attribute :storage
41
+ attribute :cache
42
+ attribute :replicate
43
+ attribute :media
44
+ attribute :format
45
+ attribute :model
46
+ attribute :shared
47
+ attribute :snapshot
48
+ attribute :backup
49
+ attribute :aio
50
+
51
+ CONTROLLERS = %w[ide sata scsi virtio].freeze
52
+
53
+ def controller
54
+ Fog::Proxmox::DiskHelper.extract_controller(id)
55
+ end
56
+
57
+ def device
58
+ Fog::Proxmox::DiskHelper.extract_device(id)
59
+ end
60
+
61
+ def cdrom?
62
+ id == 'ide2' && media == 'cdrom'
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end