fog-proxmox 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '056981428a2dd09b1d8e93d7a4578cc797310bbe'
4
- data.tar.gz: eea20ceac33c67ea37bb2942717a582564a22543
3
+ metadata.gz: bbbdd3aadac2823e21f3a920021fe70067b1f711
4
+ data.tar.gz: 83d7e18c74cd2eecc897a0732437020a16bfd7d1
5
5
  SHA512:
6
- metadata.gz: 0e880f0b5554949ede95015bbca2f7b11eb38ee9d2166933bec0c703bb68d8d60e949c922327c04dd89d65c6fa7068090a8738d47d2e497e5bef6ab718b2a799
7
- data.tar.gz: ae2813964763f177f71716a9d71e025ea575d4d9159e4f1c27848715d53670dc2c37985e9acfac4bc4ecbd4dd46b8818d1a08e38d34d17a2e51f4c8dfde878b1
6
+ metadata.gz: 6a0708b3f3b2c6afe53e852e00b15f59b1b7410ba06a10b2339c4aa162168de7fa25b2984d32d24c90a883f4954cbc99bb34d5ad3630ee30517098cda22d6aa6
7
+ data.tar.gz: e56a28ea1faff24e7023034c3ed8fc082f5b83e15841e23eef4e78cdc4f29f304d40171555019ee361a52edc5144cb3ef317c037e85def22fd130fc788708883
data/.gitignore CHANGED
@@ -2,4 +2,5 @@ vendor/
2
2
  bin/
3
3
  pkg/
4
4
  spec/debug/
5
- coverage/
5
+ coverage/
6
+ TAGS
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fog-proxmox (0.5.0)
4
+ fog-proxmox (0.5.1)
5
5
  fog-core (~> 1.45)
6
6
  fog-json (~> 1.0)
7
7
  ipaddress (~> 0.8)
@@ -31,17 +31,6 @@ module Fog
31
31
  attribute :swap
32
32
  attribute :config
33
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
34
  def restore(backup, options = {})
46
35
  requires :node, :vmid
47
36
  path_params = { node: node, type: type }
@@ -66,7 +55,7 @@ module Fog
66
55
  end
67
56
 
68
57
  def set_config(attributes = {})
69
- @config = Fog::Compute::Proxmox::ContainerConfig.new({ service: service }.merge(attributes))
58
+ @config = Fog::Compute::Proxmox::ContainerConfig.new({ service: service, vmid: vmid }.merge(attributes))
70
59
  end
71
60
 
72
61
  def config
@@ -19,20 +19,40 @@
19
19
 
20
20
  require 'fog/proxmox/variables'
21
21
  require 'fog/proxmox/helpers/nic_helper'
22
+ require 'fog/proxmox/helpers/controller_helper'
22
23
 
23
24
  module Fog
24
25
  module Compute
25
26
  class Proxmox
26
27
  # ContainerConfig model
27
28
  class ContainerConfig < Fog::Proxmox::Model
28
- identity :digest
29
+ identity :vmid
30
+ attribute :digest
29
31
  attribute :ostype
32
+ attribute :storage
33
+ attribute :template
30
34
  attribute :arch
31
35
  attribute :memory
32
36
  attribute :swap
33
37
  attribute :hostname
38
+ attribute :nameserver
39
+ attribute :searchdomain
40
+ attribute :password
34
41
  attribute :onboot
42
+ attribute :startup
35
43
  attribute :rootfs
44
+ attribute :cores
45
+ attribute :cpuunits
46
+ attribute :cpulimit
47
+ attribute :description
48
+ attribute :console
49
+ attribute :cmode
50
+ attribute :tty
51
+ attribute :force
52
+ attribute :lock
53
+ attribute :pool
54
+ attribute :bwlimit
55
+ attribute :unprivileged
36
56
  attribute :interfaces
37
57
  attribute :mount_points
38
58
 
@@ -51,10 +71,14 @@ module Fog
51
71
  Fog::Proxmox::NicHelper.to_mac_adresses_array(interfaces)
52
72
  end
53
73
 
74
+ def type_console
75
+ 'vnc' # by default. term is available too
76
+ end
77
+
54
78
  private
55
79
 
56
80
  def compute_nets(attributes)
57
- nets = Fog::Proxmox::ControllerHelper.to_hash(attributes, Fog::Compute::Proxmox::Interface::NAME)
81
+ nets = Fog::Proxmox::NicHelper.collect_nics(attributes)
58
82
  @interfaces ||= Fog::Compute::Proxmox::Interfaces.new
59
83
  nets.each do |key, value|
60
84
  nic_hash = {
@@ -69,9 +93,9 @@ module Fog
69
93
  end
70
94
 
71
95
  def compute_mps(attributes)
72
- mps = Fog::Proxmox::ControllerHelper.to_hash(attributes, 'mp')
96
+ controllers = Fog::Proxmox::ControllerHelper.collect_controllers(attributes)
73
97
  @mount_points ||= Fog::Compute::Proxmox::Disks.new
74
- mps.each do |key, value|
98
+ controllers.each do |key, value|
75
99
  storage, volid, size = Fog::Proxmox::DiskHelper.extract_storage_volid_size(value)
76
100
  disk_hash = {
77
101
  id: key.to_s,
@@ -79,7 +103,7 @@ module Fog
79
103
  volid: volid,
80
104
  size: size
81
105
  }
82
- names = Fog::Compute::Proxmox::Disk.attributes.reject { |key, _value| %i[id size storage].include? key }
106
+ names = Fog::Compute::Proxmox::Disk.attributes.reject { |key, _value| %i[id size storage volid].include? key }
83
107
  names.each { |name| disk_hash.store(name.to_sym, Fog::Proxmox::ControllerHelper.extract(name, value)) }
84
108
  @mount_points << Fog::Compute::Proxmox::Disk.new(disk_hash)
85
109
  end
@@ -26,13 +26,16 @@ module Fog
26
26
  class Containers < Fog::Compute::Proxmox::Servers
27
27
  model Fog::Compute::Proxmox::Container
28
28
 
29
- def new(attributes = {})
30
- super({ node: node, type: type }.merge(attributes))
29
+ def initialize(attributes = {})
30
+ super(attributes)
31
+ end
32
+
33
+ def type
34
+ 'lxc'
31
35
  end
32
36
 
33
- def type(attributes = {})
34
- @type ||= 'lxc' unless attributes[:type] || attributes['type']
35
- @type
37
+ def new(attributes = {})
38
+ super({ node: node, type: type }.merge(attributes))
36
39
  end
37
40
  end
38
41
  end
@@ -48,8 +48,6 @@ module Fog
48
48
  attribute :backup
49
49
  attribute :aio
50
50
 
51
- CONTROLLERS = %w[ide sata scsi virtio].freeze
52
-
53
51
  def controller
54
52
  Fog::Proxmox::DiskHelper.extract_controller(id)
55
53
  end
@@ -61,6 +59,10 @@ module Fog
61
59
  def cdrom?
62
60
  id == 'ide2' && media == 'cdrom'
63
61
  end
62
+
63
+ def rootfs?
64
+ id == 'rootfs'
65
+ end
64
66
  end
65
67
  end
66
68
  end
@@ -43,6 +43,10 @@ module Fog
43
43
  def cdrom
44
44
  find(&:cdrom?)
45
45
  end
46
+
47
+ def rootfs
48
+ find(&:rootfs?)
49
+ end
46
50
  end
47
51
  end
48
52
  end
@@ -36,14 +36,15 @@ module Fog
36
36
  identity :id
37
37
  attribute :mac
38
38
  attribute :model
39
+ attribute :name
40
+ attribute :ip
41
+ attribute :ip6
39
42
  attribute :bridge
40
43
  attribute :firewall
41
44
  attribute :link_down
42
45
  attribute :rate
43
46
  attribute :queues
44
47
  attribute :tag
45
-
46
- NAME = 'net'
47
48
  end
48
49
  end
49
50
  end
@@ -27,6 +27,7 @@ module Fog
27
27
  # Server model
28
28
  class Server < Fog::Compute::Server
29
29
  identity :vmid
30
+ attribute :id
30
31
  attribute :node
31
32
  attribute :config
32
33
  attribute :name
@@ -59,10 +60,9 @@ module Fog
59
60
  super
60
61
  end
61
62
 
62
- def type(attributes = {})
63
- @type ||= 'qemu' unless attributes[:type] || attributes['type']
64
- @type
65
- end
63
+ def type
64
+ attributes[:type]
65
+ end
66
66
 
67
67
  def request(name, body_params = {}, path_params = {})
68
68
  requires :node, :type
@@ -149,7 +149,7 @@ module Fog
149
149
  end
150
150
 
151
151
  def set_config(attributes = {})
152
- @config = Fog::Compute::Proxmox::ServerConfig.new({ service: service }.merge(attributes))
152
+ @config = Fog::Compute::Proxmox::ServerConfig.new({ service: service, vmid: vmid }.merge(attributes))
153
153
  end
154
154
 
155
155
  def config
@@ -19,6 +19,7 @@
19
19
 
20
20
  require 'fog/proxmox/variables'
21
21
  require 'fog/proxmox/helpers/nic_helper'
22
+ require 'fog/proxmox/helpers/controller_helper'
22
23
  require 'fog/proxmox/models/model'
23
24
 
24
25
  module Fog
@@ -26,7 +27,7 @@ module Fog
26
27
  class Proxmox
27
28
  # ServerConfig model
28
29
  class ServerConfig < Fog::Proxmox::Model
29
- identity :id
30
+ identity :vmid
30
31
  attribute :digest
31
32
  attribute :description
32
33
  attribute :ostype
@@ -79,7 +80,7 @@ module Fog
79
80
  private
80
81
 
81
82
  def compute_nets(attributes)
82
- nets = Fog::Proxmox::ControllerHelper.to_hash(attributes, Fog::Compute::Proxmox::Interface::NAME)
83
+ nets = Fog::Proxmox::NicHelper.collect_nics(attributes)
83
84
  @interfaces ||= Fog::Compute::Proxmox::Interfaces.new
84
85
  nets.each do |key, value|
85
86
  nic_hash = {
@@ -94,8 +95,7 @@ module Fog
94
95
  end
95
96
 
96
97
  def compute_disks(attributes)
97
- controllers = {}
98
- Fog::Compute::Proxmox::Disk::CONTROLLERS.each { |controller| controllers.merge!(Fog::Proxmox::ControllerHelper.to_hash(attributes, controller)) }
98
+ controllers = Fog::Proxmox::ControllerHelper.collect_controllers(attributes)
99
99
  @disks ||= Fog::Compute::Proxmox::Disks.new
100
100
  controllers.each do |key, value|
101
101
  storage, volid, size = Fog::Proxmox::DiskHelper.extract_storage_volid_size(value)
@@ -26,15 +26,17 @@ module Fog
26
26
  class Servers < Fog::Proxmox::Collection
27
27
  model Fog::Compute::Proxmox::Server
28
28
  attribute :node
29
- attribute :type
30
29
 
31
- def new(attributes = {})
32
- super({ node: node, type: type }.merge(attributes))
30
+ def initialize(attributes = {})
31
+ super(attributes)
32
+ end
33
+
34
+ def type
35
+ 'qemu'
33
36
  end
34
37
 
35
- def type(attributes = {})
36
- @type ||= 'qemu' unless attributes[:type] || attributes['type']
37
- @type
38
+ def new(attributes = {})
39
+ super({ node: node, type: type }.merge(attributes))
38
40
  end
39
41
 
40
42
  def next_id
@@ -26,7 +26,6 @@ module Fog
26
26
  class Real
27
27
  def update_network(path_params, body_params)
28
28
  node = path_params[:node]
29
- type = body_params[:type]
30
29
  iface = path_params[:iface]
31
30
  response = request(
32
31
  expects: [200],
@@ -22,11 +22,12 @@ module Fog
22
22
  # module Hash mixins
23
23
  module Hash
24
24
  def self.stringify(hash)
25
+ return '' unless hash
25
26
  string = ''
26
27
  hash.each do |key, value|
27
- string += "#{key}=#{value},"
28
+ string += "#{key}=#{value}," if value
28
29
  end
29
- string.slice(0, string.length - 1)
30
+ string.slice(0, string.length - 1) if string.length > 0
30
31
  end
31
32
  end
32
33
  end
@@ -21,6 +21,9 @@ module Fog
21
21
  module Proxmox
22
22
  # module ControllerHelper mixins
23
23
  module ControllerHelper
24
+
25
+ CONTROLLERS = %w[ide sata scsi virtio mp rootfs].freeze
26
+
24
27
  def self.extract(name, controller_value)
25
28
  values = controller_value.scan(/#{name}=(\w+)/)
26
29
  name_value = values.first if values
@@ -33,7 +36,7 @@ module Fog
33
36
  end
34
37
 
35
38
  def self.valid?(name, key)
36
- key.to_s.match(/#{name}(\d+)/)
39
+ key.to_s.match(/^#{name}(\d*)$/)
37
40
  end
38
41
 
39
42
  def self.last_index(name, values)
@@ -47,9 +50,16 @@ module Fog
47
50
  indexes.empty? ? -1 : indexes.last
48
51
  end
49
52
 
50
- def self.to_hash(hash, name)
53
+ def self.select(hash,name)
51
54
  hash.select { |key| valid?(name, key.to_s) }
52
55
  end
56
+
57
+ def self.collect_controllers(attributes)
58
+ controllers = {}
59
+ CONTROLLERS.each { |controller| controllers.merge!(select(attributes, controller)) }
60
+ controllers
61
+ end
62
+
53
63
  end
54
64
  end
55
65
  end
@@ -30,8 +30,11 @@ module Fog
30
30
  else
31
31
  "#{disk[:storage]}:#{disk[:size]}"
32
32
  end
33
- options = Fog::Proxmox::Hash.stringify(disk[:options])
34
- value += ",#{options}" unless options.empty?
33
+ opts = disk[:options] if disk.has_key? :options
34
+ main_a = [:id,:volid,:storage,:size]
35
+ opts = disk.reject { |key,_value| main_a.include? key } unless opts
36
+ options = Fog::Proxmox::Hash.stringify(opts) if opts
37
+ value += ",#{options}" if options
35
38
  { "#{disk[:id]}": value }
36
39
  end
37
40
 
@@ -23,6 +23,7 @@ module Fog
23
23
  module Proxmox
24
24
  # module NicHelper mixins
25
25
  module NicHelper
26
+
26
27
  def self.extract_mac_address(nic_value)
27
28
  nic_value[/([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})/]
28
29
  end
@@ -57,6 +58,21 @@ module Fog
57
58
  model += ',' + Fog::Proxmox::Hash.stringify(options) unless options.empty?
58
59
  { "#{nic[:id]}": model }
59
60
  end
61
+
62
+ def self.container_flatten(nic)
63
+ name = "name=#{nic[:name]}"
64
+ options = nic.reject { |key, _value| %i[name id].include? key }
65
+ name += ',' + Fog::Proxmox::Hash.stringify(options) unless options.empty?
66
+ { "#{nic[:id]}": name }
67
+ end
68
+
69
+ def self.valid?(key)
70
+ key.to_s.match(/^net(\d+)$/)
71
+ end
72
+
73
+ def self.collect_nics(attributes)
74
+ attributes.select { |key| valid?(key.to_s) }
75
+ end
60
76
  end
61
77
  end
62
78
  end
@@ -19,6 +19,6 @@
19
19
 
20
20
  module Fog
21
21
  module Proxmox
22
- VERSION = '0.5.0'
22
+ VERSION = '0.5.1'
23
23
  end
24
24
  end
@@ -167,6 +167,8 @@ describe Fog::Compute::Proxmox do
167
167
  config_hash = { onboot: 1, keyboard: 'fr', ostype: 'l26', kvm: 0 }
168
168
  server.update(config_hash)
169
169
  # server config
170
+ #config = server.config
171
+ #config.identity.must_equal vmid
170
172
  disks = server.config.disks
171
173
  nics = server.config.interfaces
172
174
  nics.wont_be_nil
@@ -188,7 +190,7 @@ describe Fog::Compute::Proxmox do
188
190
  servers_all.must_include server
189
191
  # server not running exception
190
192
  proc do
191
- vnc = server.start_console(websocket: 1)
193
+ server.start_console(websocket: 1)
192
194
  end.must_raise Fog::Proxmox::Errors::ServiceError
193
195
  # Start server
194
196
  server.action('start')
@@ -197,7 +199,7 @@ describe Fog::Compute::Proxmox do
197
199
  status.must_equal true
198
200
  # server vga not set exception
199
201
  proc do
200
- vnc = server.start_console(websocket: 1)
202
+ server.start_console(websocket: 1)
201
203
  end.must_raise Fog::Proxmox::Errors::ServiceError
202
204
  # Stop server
203
205
  server.action('stop')
@@ -379,6 +381,7 @@ describe Fog::Compute::Proxmox do
379
381
  # get container config
380
382
  config = container.config
381
383
  config.wont_be_nil
384
+ config.identity.must_equal vmid
382
385
  # Get a mac address
383
386
  mac_address = container.config.mac_addresses.first
384
387
  mac_address.wont_be_nil
@@ -31,6 +31,15 @@ require 'fog/proxmox/helpers/controller_helper'
31
31
  let(:scsi) do
32
32
  { scsi10: 'local-lvm:1,cache=none' }
33
33
  end
34
+ let(:cdrom) do
35
+ { ide2: 'none,media=cdrom' }
36
+ end
37
+ let(:mp) do
38
+ { mp0: 'local-lvm:1' }
39
+ end
40
+ let(:rootfs) do
41
+ { rootfs: 'local-lvm:1' }
42
+ end
34
43
 
35
44
  describe '#extract' do
36
45
  it "returns bridge" do
@@ -74,4 +83,37 @@ require 'fog/proxmox/helpers/controller_helper'
74
83
  assert !Fog::Proxmox::ControllerHelper.valid?('net','sdfdsf')
75
84
  end
76
85
  end
86
+
87
+ describe '#select' do
88
+ it "returns scsi10" do
89
+ controllers = Fog::Proxmox::ControllerHelper.select(scsi,'scsi')
90
+ assert controllers.has_key?(:scsi10)
91
+ assert controllers.has_value?(scsi[:scsi10])
92
+ end
93
+ it "returns empty" do
94
+ controllers = Fog::Proxmox::ControllerHelper.select(net,'scsi')
95
+ assert controllers.empty?
96
+ end
97
+ end
98
+
99
+ describe '#collect_controllers' do
100
+ it "returns scsi0 and ide2" do
101
+ controllers = Fog::Proxmox::ControllerHelper.collect_controllers(scsi.merge(cdrom))
102
+ assert controllers.has_key?(:scsi10)
103
+ assert controllers.has_value?(scsi[:scsi10])
104
+ assert controllers.has_key?(:ide2)
105
+ assert controllers.has_value?(cdrom[:ide2])
106
+ end
107
+ it "returns rootfs and mp0" do
108
+ controllers = Fog::Proxmox::ControllerHelper.collect_controllers(rootfs.merge(mp))
109
+ assert controllers.has_key?(:mp0)
110
+ assert controllers.has_value?(mp[:mp0])
111
+ assert controllers.has_key?(:rootfs)
112
+ assert controllers.has_value?(rootfs[:rootfs])
113
+ end
114
+ it "returns empty" do
115
+ controllers = Fog::Proxmox::ControllerHelper.collect_controllers(net)
116
+ assert controllers.empty?
117
+ end
118
+ end
77
119
  end
@@ -70,4 +70,26 @@ require 'fog/proxmox/helpers/nic_helper'
70
70
  assert_equal '66:89:C5:59:AA:96', mac_address
71
71
  end
72
72
  end
73
+
74
+ describe '#valid?' do
75
+ it "returns true" do
76
+ assert Fog::Proxmox::NicHelper.valid?('net0')
77
+ end
78
+ it "returns false" do
79
+ assert !Fog::Proxmox::NicHelper.valid?('net')
80
+ end
81
+ end
82
+
83
+ describe '#collect_nics' do
84
+ it "returns net0" do
85
+ nets = Fog::Proxmox::NicHelper.collect_nics(net_vm.merge({'netout': 'sdfdsgfdsf'}))
86
+ assert nets.has_key?(:net0)
87
+ assert nets.has_value?(net_vm[:net0])
88
+ assert !nets.has_key?('netout')
89
+ end
90
+ it "returns empty" do
91
+ nets = Fog::Proxmox::NicHelper.collect_nics({'netout': 'sdfdsgfdsf'})
92
+ assert nets.empty?
93
+ end
94
+ end
73
95
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-proxmox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Robert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-13 00:00:00.000000000 Z
11
+ date: 2018-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler