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.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +7 -0
  3. data/.travis.yml +1 -0
  4. data/.vscode/launch.json +3 -21
  5. data/.vscode/settings.json +7 -7
  6. data/Gemfile.lock +39 -39
  7. data/README.md +9 -2
  8. data/examples/compute.rb +20 -23
  9. data/examples/identity.rb +16 -21
  10. data/fog-proxmox.gemspec +1 -2
  11. data/lib/fog/compute/proxmox.rb +2 -8
  12. data/lib/fog/compute/proxmox/models/disk.rb +13 -11
  13. data/lib/fog/compute/proxmox/models/disks.rb +3 -5
  14. data/lib/fog/compute/proxmox/models/interface.rb +6 -11
  15. data/lib/fog/compute/proxmox/models/interfaces.rb +3 -5
  16. data/lib/fog/compute/proxmox/models/node.rb +38 -43
  17. data/lib/fog/compute/proxmox/models/nodes.rb +5 -11
  18. data/lib/fog/compute/proxmox/models/server.rb +123 -80
  19. data/lib/fog/compute/proxmox/models/server_config.rb +56 -24
  20. data/lib/fog/compute/proxmox/models/servers.rb +34 -26
  21. data/lib/fog/compute/proxmox/models/snapshot.rb +28 -14
  22. data/lib/fog/compute/proxmox/models/snapshots.rb +9 -17
  23. data/lib/fog/compute/proxmox/models/storage.rb +15 -11
  24. data/lib/fog/compute/proxmox/models/storages.rb +13 -22
  25. data/lib/fog/compute/proxmox/models/task.rb +10 -14
  26. data/lib/fog/compute/proxmox/models/tasks.rb +9 -18
  27. data/lib/fog/compute/proxmox/models/volume.rb +12 -12
  28. data/lib/fog/compute/proxmox/models/volumes.rb +10 -19
  29. data/lib/fog/compute/proxmox/requests/action_server.rb +1 -4
  30. data/lib/fog/compute/proxmox/requests/clone_server.rb +1 -4
  31. data/lib/fog/compute/proxmox/requests/create_backup.rb +1 -4
  32. data/lib/fog/compute/proxmox/requests/create_server.rb +1 -4
  33. data/lib/fog/compute/proxmox/requests/create_snapshot.rb +1 -4
  34. data/lib/fog/compute/proxmox/requests/create_spice.rb +1 -4
  35. data/lib/fog/compute/proxmox/requests/create_term.rb +1 -4
  36. data/lib/fog/compute/proxmox/requests/create_vnc.rb +1 -4
  37. data/lib/fog/compute/proxmox/requests/delete_server.rb +1 -4
  38. data/lib/fog/compute/proxmox/requests/delete_snapshot.rb +1 -4
  39. data/lib/fog/compute/proxmox/requests/get_node_statistics.rb +1 -4
  40. data/lib/fog/compute/proxmox/requests/get_server_config.rb +1 -4
  41. data/lib/fog/compute/proxmox/requests/get_server_status.rb +1 -4
  42. data/lib/fog/compute/proxmox/requests/{get_snapshot.rb → get_snapshot_config.rb} +5 -8
  43. data/lib/fog/compute/proxmox/requests/get_task.rb +1 -4
  44. data/lib/fog/compute/proxmox/requests/get_vnc.rb +1 -4
  45. data/lib/fog/compute/proxmox/requests/list_nodes.rb +1 -2
  46. data/lib/fog/compute/proxmox/requests/list_storages.rb +3 -1
  47. data/lib/fog/compute/proxmox/requests/log_task.rb +1 -4
  48. data/lib/fog/compute/proxmox/requests/move_disk.rb +1 -4
  49. data/lib/fog/compute/proxmox/requests/move_volume.rb +1 -4
  50. data/lib/fog/compute/proxmox/requests/next_vmid.rb +5 -3
  51. data/lib/fog/compute/proxmox/requests/resize_container.rb +1 -4
  52. data/lib/fog/compute/proxmox/requests/status_task.rb +1 -4
  53. data/lib/fog/compute/proxmox/requests/update_server.rb +1 -4
  54. data/lib/fog/identity/proxmox.rb +2 -8
  55. data/lib/fog/identity/proxmox/models/domain.rb +25 -21
  56. data/lib/fog/identity/proxmox/models/{ldap.rb → domain_type.rb} +9 -18
  57. data/lib/fog/identity/proxmox/models/domains.rb +6 -76
  58. data/lib/fog/identity/proxmox/models/group.rb +6 -19
  59. data/lib/fog/identity/proxmox/models/groups.rb +6 -12
  60. data/lib/fog/identity/proxmox/models/permission.rb +27 -31
  61. data/lib/fog/identity/proxmox/models/permissions.rb +8 -25
  62. data/lib/fog/identity/proxmox/models/pool.rb +9 -22
  63. data/lib/fog/identity/proxmox/models/pools.rb +7 -13
  64. data/lib/fog/identity/proxmox/models/principal.rb +1 -6
  65. data/lib/fog/identity/proxmox/models/role.rb +7 -20
  66. data/lib/fog/identity/proxmox/models/roles.rb +6 -13
  67. data/lib/fog/identity/proxmox/models/user.rb +7 -21
  68. data/lib/fog/identity/proxmox/models/users.rb +6 -12
  69. data/lib/fog/identity/proxmox/requests/check_permissions.rb +1 -4
  70. data/lib/fog/identity/proxmox/requests/list_roles.rb +0 -1
  71. data/lib/fog/identity/proxmox/requests/read_version.rb +1 -5
  72. data/lib/fog/identity/proxmox/requests/update_group.rb +2 -3
  73. data/lib/fog/identity/proxmox/requests/{add_permission.rb → update_permissions.rb} +4 -4
  74. data/lib/fog/network/proxmox/models/network.rb +12 -18
  75. data/lib/fog/network/proxmox/models/networks.rb +11 -17
  76. data/lib/fog/network/proxmox/models/node.rb +14 -10
  77. data/lib/fog/network/proxmox/models/nodes.rb +5 -11
  78. data/lib/fog/network/proxmox/requests/create_network.rb +1 -4
  79. data/lib/fog/network/proxmox/requests/delete_network.rb +1 -4
  80. data/lib/fog/network/proxmox/requests/get_network.rb +1 -4
  81. data/lib/fog/network/proxmox/requests/get_node.rb +1 -4
  82. data/lib/fog/network/proxmox/requests/power_node.rb +1 -4
  83. data/lib/fog/network/proxmox/requests/update_network.rb +1 -4
  84. data/lib/fog/{compute/proxmox/requests/check_vmid.rb → proxmox/attributes.rb} +9 -17
  85. data/lib/fog/proxmox/core.rb +2 -1
  86. data/lib/fog/proxmox/helpers/cpu_helper.rb +6 -3
  87. data/lib/fog/proxmox/helpers/disk_helper.rb +1 -1
  88. data/lib/fog/proxmox/helpers/nic_helper.rb +37 -22
  89. data/lib/fog/proxmox/version.rb +1 -1
  90. data/lib/fog/storage/proxmox.rb +1 -1
  91. data/spec/compute_spec.rb +64 -45
  92. data/spec/fixtures/proxmox/compute/containers.yml +1684 -4137
  93. data/spec/fixtures/proxmox/compute/identity_ticket.yml +4 -4
  94. data/spec/fixtures/proxmox/compute/nodes.yml +21 -21
  95. data/spec/fixtures/proxmox/compute/servers.yml +3065 -7741
  96. data/spec/fixtures/proxmox/compute/snapshots.yml +279 -827
  97. data/spec/fixtures/proxmox/compute/storages.yml +60 -21
  98. data/spec/fixtures/proxmox/compute/tasks.yml +56 -98
  99. data/spec/fixtures/proxmox/identity/auth.yml +6 -6
  100. data/spec/fixtures/proxmox/identity/domains.yml +252 -84
  101. data/spec/fixtures/proxmox/identity/groups.yml +93 -54
  102. data/spec/fixtures/proxmox/identity/identity_ticket.yml +4 -4
  103. data/spec/fixtures/proxmox/identity/permissions.yml +317 -79
  104. data/spec/fixtures/proxmox/identity/pools.yml +266 -71
  105. data/spec/fixtures/proxmox/identity/read_version.yml +6 -6
  106. data/spec/fixtures/proxmox/identity/roles.yml +96 -57
  107. data/spec/fixtures/proxmox/identity/users.yml +224 -107
  108. data/spec/fixtures/proxmox/network/identity_ticket.yml +4 -4
  109. data/spec/fixtures/proxmox/network/networks.yml +54 -95
  110. data/spec/helpers/nic_helper_spec.rb +4 -4
  111. data/spec/identity_spec.rb +38 -46
  112. data/spec/network_spec.rb +1 -1
  113. metadata +9 -23
  114. data/lib/fog/compute/proxmox/models/container.rb +0 -86
  115. data/lib/fog/compute/proxmox/models/container_config.rb +0 -114
  116. data/lib/fog/compute/proxmox/models/containers.rb +0 -43
  117. data/lib/fog/compute/proxmox/requests/get_node.rb +0 -44
  118. data/lib/fog/compute/proxmox/requests/get_storage.rb +0 -44
  119. data/lib/fog/identity/proxmox/models/activedirectory.rb +0 -57
  120. data/lib/fog/identity/proxmox/models/oath.rb +0 -50
  121. data/lib/fog/identity/proxmox/models/pam.rb +0 -46
  122. data/lib/fog/identity/proxmox/models/pve.rb +0 -46
  123. data/lib/fog/identity/proxmox/models/yubico.rb +0 -51
  124. data/lib/fog/identity/proxmox/requests/remove_permission.rb +0 -42
  125. data/lib/fog/proxmox/models/collection.rb +0 -85
  126. data/lib/fog/proxmox/models/model.rb +0 -58
@@ -17,18 +17,16 @@
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/variables'
20
+ require 'fog/proxmox/attributes'
21
21
  require 'fog/proxmox/helpers/nic_helper'
22
22
  require 'fog/proxmox/helpers/controller_helper'
23
- require 'fog/proxmox/models/model'
24
23
 
25
24
  module Fog
26
25
  module Compute
27
26
  class Proxmox
28
27
  # ServerConfig model
29
- class ServerConfig < Fog::Proxmox::Model
28
+ class ServerConfig < Fog::Model
30
29
  identity :vmid
31
- attribute :digest
32
30
  attribute :description
33
31
  attribute :ostype
34
32
  attribute :smbios1
@@ -52,24 +50,39 @@ module Fog
52
50
  attribute :cpuunits
53
51
  attribute :keyboard
54
52
  attribute :vga
53
+ attribute :storage
54
+ attribute :template
55
+ attribute :arch
56
+ attribute :swap
57
+ attribute :hostname
58
+ attribute :nameserver
59
+ attribute :searchdomain
60
+ attribute :password
61
+ attribute :startup
62
+ attribute :console
63
+ attribute :cmode
64
+ attribute :tty
65
+ attribute :force
66
+ attribute :lock
67
+ attribute :pool
68
+ attribute :bwlimit
69
+ attribute :unprivileged
55
70
  attribute :interfaces
56
71
  attribute :disks
57
72
 
58
- def initialize(attributes = {})
59
- prepare_service_value(attributes)
60
- compute_nets(attributes)
61
- compute_disks(attributes)
62
- super(attributes)
73
+ def initialize(new_attributes = {})
74
+ prepare_service_value(new_attributes)
75
+ Fog::Proxmox::Attributes.set_attr_and_sym('vmid', attributes, new_attributes)
76
+ requires :vmid
77
+ initialize_interfaces(new_attributes)
78
+ initialize_disks(new_attributes)
79
+ super(new_attributes)
63
80
  end
64
81
 
65
82
  def mac_addresses
66
83
  Fog::Proxmox::NicHelper.to_mac_adresses_array(interfaces)
67
84
  end
68
85
 
69
- attr_reader :disks
70
-
71
- attr_reader :interfaces
72
-
73
86
  def type_console
74
87
  console = 'vnc' if %w[std cirrus vmware].include?(vga)
75
88
  console = 'spice' if %w[qxl qxl2 qxl3 qxl4].include?(vga)
@@ -77,26 +90,45 @@ module Fog
77
90
  console
78
91
  end
79
92
 
93
+ def flatten
94
+ flat_hash = attributes.reject { |attribute| [:node_id, :type, :vmid, :disks, :interfaces].include? attribute }
95
+ flat_hash.merge(interfaces_flatten)
96
+ flat_hash.merge(disks_flatten)
97
+ flat_hash
98
+ end
99
+
80
100
  private
81
101
 
82
- def compute_nets(attributes)
83
- nets = Fog::Proxmox::NicHelper.collect_nics(attributes)
84
- @interfaces ||= Fog::Compute::Proxmox::Interfaces.new
102
+ def interfaces_flatten
103
+ flat_hash = {}
104
+ interfaces.each { |interface| flat_hash.merge(interface.flatten) }
105
+ flat_hash
106
+ end
107
+
108
+ def disks_flatten
109
+ flat_hash = {}
110
+ disks.each { |disk| flat_hash.merge(disk.flatten) }
111
+ flat_hash
112
+ end
113
+
114
+ def initialize_interfaces(new_attributes)
115
+ nets = Fog::Proxmox::NicHelper.collect_nics(new_attributes)
116
+ attributes[:interfaces] = Fog::Compute::Proxmox::Interfaces.new
85
117
  nets.each do |key, value|
86
118
  nic_hash = {
87
119
  id: key.to_s,
88
- model: Fog::Proxmox::NicHelper.extract_model(value),
120
+ model: Fog::Proxmox::NicHelper.extract_nic_id(value),
89
121
  mac: Fog::Proxmox::NicHelper.extract_mac_address(value)
90
122
  }
91
- names = Fog::Compute::Proxmox::Interface.attributes.reject { |key, _value| %i[id mac model].include? key }
123
+ names = Fog::Compute::Proxmox::Interface.attributes.reject { |attribute| [:id, :mac, :model].include? attribute }
92
124
  names.each { |name| nic_hash.store(name.to_sym, Fog::Proxmox::ControllerHelper.extract(name, value)) }
93
- @interfaces << Fog::Compute::Proxmox::Interface.new(nic_hash)
125
+ attributes[:interfaces] << Fog::Compute::Proxmox::Interface.new(nic_hash)
94
126
  end
95
127
  end
96
128
 
97
- def compute_disks(attributes)
98
- controllers = Fog::Proxmox::ControllerHelper.collect_controllers(attributes)
99
- @disks ||= Fog::Compute::Proxmox::Disks.new
129
+ def initialize_disks(new_attributes)
130
+ controllers = Fog::Proxmox::ControllerHelper.collect_controllers(new_attributes)
131
+ attributes[:disks] = Fog::Compute::Proxmox::Disks.new
100
132
  controllers.each do |key, value|
101
133
  storage, volid, size = Fog::Proxmox::DiskHelper.extract_storage_volid_size(value)
102
134
  disk_hash = {
@@ -105,9 +137,9 @@ module Fog
105
137
  volid: volid,
106
138
  storage: storage
107
139
  }
108
- names = Fog::Compute::Proxmox::Disk.attributes.reject { |key, _value| %i[id size storage volid].include? key }
140
+ names = Fog::Compute::Proxmox::Disk.attributes.reject { |attribute| [:id, :size, :storage, :volid].include? attribute }
109
141
  names.each { |name| disk_hash.store(name.to_sym, Fog::Proxmox::ControllerHelper.extract(name, value)) }
110
- @disks << Fog::Compute::Proxmox::Disk.new(disk_hash)
142
+ attributes[:disks] << Fog::Compute::Proxmox::Disk.new(disk_hash)
111
143
  end
112
144
  end
113
145
  end
@@ -23,48 +23,56 @@ module Fog
23
23
  module Compute
24
24
  class Proxmox
25
25
  # Servers Collection
26
- class Servers < Fog::Proxmox::Collection
26
+ class Servers < Fog::Collection
27
27
  model Fog::Compute::Proxmox::Server
28
- attribute :node
28
+ attribute :node_id
29
+ attribute :type
29
30
 
30
- def initialize(attributes = {})
31
- super(attributes)
32
- end
33
-
34
- def type
35
- 'qemu'
36
- end
37
-
38
- def new(attributes = {})
39
- super({ node: node, type: type }.merge(attributes))
31
+ def new(new_attributes = {})
32
+ super({ node_id: node_id, type: type }.merge(new_attributes))
40
33
  end
41
34
 
42
35
  def next_id
43
- response = service.next_vmid
44
- body = JSON.decode(response.body)
45
- data = body['data']
46
- Integer(data)
36
+ service.next_vmid
47
37
  end
48
38
 
49
39
  def id_valid?(vmid)
50
- service.check_vmid(vmid)
40
+ service.next_vmid(vmid: vmid)
51
41
  true
52
42
  rescue Excon::Errors::BadRequest
53
43
  false
54
44
  end
55
45
 
56
- def get(vmid)
57
- requires :node
58
- path_params = { node: node, type: type, vmid: vmid }
59
- server_data = service.get_server_status path_params
60
- config_data = service.get_server_config path_params
61
- data = server_data.merge(config_data).merge(node: node, vmid: vmid)
62
- new(data)
46
+ def containers?
47
+ type == 'lxc'
48
+ end
49
+
50
+ def get(id)
51
+ path_params = { node: node_id, type: type, vmid: id }
52
+ begin
53
+ status_data = service.get_server_status path_params
54
+ config_data = service.get_server_config path_params
55
+ rescue => e
56
+ if e.respond_to?('response') && e.response.respond_to?('data') && e.response.data.has_key?(:reason_phrase) && e.response.data[:reason_phrase].end_with?('does not exist')
57
+ raise(Fog::Errors::NotFound)
58
+ else
59
+ raise(e)
60
+ end
61
+ else
62
+ data = status_data.merge(config_data).merge(node: node_id, vmid: id)
63
+ new(data)
64
+ end
63
65
  end
64
66
 
65
67
  def all(options = {})
66
- body_params = options.merge(node: node, type: type)
67
- load_response(service.list_servers(body_params), 'servers')
68
+ body_params = options.merge(node: node_id, type: type)
69
+ load service.list_servers(body_params)
70
+ end
71
+
72
+ def create(new_attributes = {})
73
+ object = new(new_attributes.select { |key, _value| [:node_id, :vmid, :type].include? key.to_sym })
74
+ object.save(new_attributes.reject { |key, _value| [:node_id, :vmid, :type].include? key.to_sym })
75
+ object
68
76
  end
69
77
  end
70
78
  end
@@ -25,45 +25,59 @@
25
25
  # You should have received a copy of the GNU General Public License
26
26
  # along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
27
27
 
28
- require 'fog/proxmox/models/model'
29
-
30
28
  module Fog
31
29
  module Compute
32
30
  class Proxmox
33
31
  # class Snapshot model
34
- class Snapshot < Fog::Proxmox::Model
32
+ class Snapshot < Fog::Model
35
33
  identity :name
36
34
  attribute :description
37
35
  attribute :snaptime
38
36
  attribute :vmstate
39
- attribute :server
37
+ attribute :node_id
38
+ attribute :server_id
39
+ attribute :server_type
40
+ attribute :vmgenid
41
+
42
+ def initialize(new_attributes = {})
43
+ prepare_service_value(new_attributes)
44
+ attributes[:node_id] = new_attributes[:node_id] unless new_attributes[:node_id].nil?
45
+ attributes[:server_id] = new_attributes[:server_id] unless new_attributes[:server_id].nil?
46
+ attributes[:server_type] = new_attributes[:server_type] unless new_attributes[:server_type].nil?
47
+ attributes[:name] = new_attributes[:name] unless new_attributes[:name].nil?
48
+ attributes[:name] = new_attributes['name'] unless new_attributes['name'].nil?
49
+ requires :node_id, :server_id, :server_type, :name
50
+ super(new_attributes)
51
+ end
40
52
 
41
- def create(options = {})
42
- requires :server
43
- path_params = { node: server.node, type: server.type, vmid: server.vmid }
44
- body_params = options
53
+ def save
54
+ path_params = { node: node_id, type: server_type, vmid: server_id }
55
+ body_params = { snapname: name }
45
56
  server.tasks.wait_for(service.create_snapshot(path_params, body_params))
46
57
  end
47
58
 
48
59
  def update
49
- requires :name, :server
50
- path_params = { node: server.node, type: server.type, vmid: server.vmid, snapname: name }
60
+ path_params = { node: node_id, type: server_type, vmid: server_id, snapname: name }
51
61
  body_params = { description: description }
52
62
  service.update_snapshot(path_params, body_params)
53
63
  end
54
64
 
55
65
  def rollback
56
- requires :name, :server
57
- path_params = { node: server.node, type: server.type, vmid: server.vmid, snapname: name }
66
+ path_params = { node: node_id, type: server_type, vmid: server_id, snapname: name }
58
67
  server.tasks.wait_for(service.rollback_snapshot(path_params))
59
68
  end
60
69
 
61
70
  def destroy(force = 0)
62
- requires :name, :server
63
- path_params = { node: server.node, type: server.type, vmid: server.vmid, snapname: name }
71
+ path_params = { node: node_id, type: server_type, vmid: server_id, snapname: name }
64
72
  query_params = { force: force }
65
73
  server.tasks.wait_for(service.delete_snapshot(path_params, query_params))
66
74
  end
75
+
76
+ private
77
+
78
+ def server
79
+ Fog::Compute::Proxmox::Server.new(service: service, node_id: node_id, type: server_type, vmid: server_id)
80
+ end
67
81
  end
68
82
  end
69
83
  end
@@ -17,37 +17,29 @@
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/snapshot'
22
21
 
23
22
  module Fog
24
23
  module Compute
25
24
  class Proxmox
26
25
  # class Snapshots Collection of snapshots
27
- class Snapshots < Fog::Proxmox::Collection
26
+ class Snapshots < Fog::Collection
28
27
  model Fog::Compute::Proxmox::Snapshot
29
- attribute :server
28
+ attribute :server_id
29
+ attribute :server_type
30
+ attribute :node_id
30
31
 
31
- def new(attributes = {})
32
- requires :server
33
- super({ server: server }.merge!(attributes))
32
+ def new(new_attributes = {})
33
+ super({ node_id: node_id, server_id: server_id, server_type: server_type }.merge(new_attributes))
34
34
  end
35
35
 
36
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')
37
+ path_params = { node: node_id, type: server_type, vmid: server_id }
38
+ load service.list_snapshots(path_params)
40
39
  end
41
40
 
42
41
  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
- )
42
+ all.find { |snapshot| snapshot.identity === name }
51
43
  end
52
44
  end
53
45
  end
@@ -26,15 +26,13 @@
26
26
 
27
27
  # frozen_string_literal: true
28
28
 
29
- require 'fog/proxmox/models/model'
30
-
31
29
  module Fog
32
30
  module Compute
33
31
  class Proxmox
34
32
  # class Storage model
35
- class Storage < Fog::Proxmox::Model
33
+ class Storage < Fog::Model
36
34
  identity :storage
37
- attribute :node
35
+ attribute :node_id, aliases: :node
38
36
  attribute :content
39
37
  attribute :type
40
38
  attribute :avail
@@ -43,17 +41,23 @@ module Fog
43
41
  attribute :shared
44
42
  attribute :active
45
43
  attribute :enabled
44
+ attribute :used_fraction
46
45
  attribute :volumes
47
46
 
48
- def to_s
49
- storage
47
+ def initialize(new_attributes = {})
48
+ prepare_service_value(new_attributes)
49
+ attributes[:node_id] = new_attributes[:node_id] unless new_attributes[:node_id].nil?
50
+ attributes[:storage] = new_attributes[:storage] unless new_attributes[:storage].nil?
51
+ attributes[:storage] = new_attributes['storage'] unless new_attributes['storage'].nil?
52
+ requires :node_id, :storage
53
+ initialize_volumes
54
+ super(new_attributes)
50
55
  end
51
56
 
52
- def volumes
53
- @volumes ||= begin
54
- Fog::Compute::Proxmox::Volumes.new(service: service,
55
- node: node, storage: self)
56
- end
57
+ private
58
+
59
+ def initialize_volumes
60
+ attributes[:volumes] = Fog::Compute::Proxmox::Volumes.new(service: service, node_id: node_id, storage_id: identity)
57
61
  end
58
62
  end
59
63
  end
@@ -17,42 +17,33 @@
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/storage'
22
21
 
23
22
  module Fog
24
23
  module Compute
25
24
  class Proxmox
26
25
  # class Storages Collection of storages
27
- class Storages < Fog::Proxmox::Collection
26
+ class Storages < Fog::Collection
28
27
  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
28
+ attribute :node_id
29
+
30
+ def new(new_attributes = {})
31
+ super({ node_id: node_id }.merge(new_attributes))
38
32
  end
39
33
 
40
- def search(options = {})
41
- requires :node
42
- load_response(service.list_storages(node, options), 'storages')
34
+ def all(filters = {})
35
+ requires :node_id
36
+ load service.list_storages(node_id, filters)
43
37
  end
44
38
 
45
39
  def list_by_content_type(content)
46
- search(content: content)
40
+ requires :node_id
41
+ all.select { |storage| storage.content.include? content }
47
42
  end
48
43
 
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
- )
44
+ def get(id)
45
+ requires :node_id
46
+ all.find { |storage| storage.identity === id }
56
47
  end
57
48
  end
58
49
  end
@@ -26,15 +26,13 @@
26
26
 
27
27
  # frozen_string_literal: true
28
28
 
29
- require 'fog/proxmox/models/model'
30
-
31
29
  module Fog
32
30
  module Compute
33
31
  class Proxmox
34
32
  # class Task model of a node
35
- class Task < Fog::Proxmox::Model
33
+ class Task < Fog::Model
36
34
  identity :upid
37
- attribute :node
35
+ attribute :node_id, aliases: :node
38
36
  attribute :status
39
37
  attribute :exitstatus
40
38
  attribute :pid
@@ -47,13 +45,13 @@ module Fog
47
45
  attribute :status_details
48
46
  attribute :log
49
47
 
50
- def new(attributes = {})
51
- requires :node
52
- super({ node: node }.merge(attributes))
53
- end
54
-
55
- def to_s
56
- upid
48
+ def initialize(new_attributes = {})
49
+ prepare_service_value(new_attributes)
50
+ attributes[:node_id] = new_attributes[:node_id] unless new_attributes[:node_id].nil?
51
+ attributes[:upid] = new_attributes[:upid] unless new_attributes[:upid].nil?
52
+ attributes[:upid] = new_attributes['upid'] unless new_attributes['upid'].nil?
53
+ requires :node_id, :upid
54
+ super(new_attributes)
57
55
  end
58
56
 
59
57
  def succeeded?
@@ -69,12 +67,10 @@ module Fog
69
67
  end
70
68
 
71
69
  def stop
72
- requires :node, :upid
73
- service.stop_task(node, upid)
70
+ service.stop_task(node_id, upid)
74
71
  end
75
72
 
76
73
  def reload
77
- requires :upid
78
74
  object = collection.get(upid)
79
75
  merge_attributes(object.attributes)
80
76
  end