fog-proxmox 0.9.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +12 -0
  3. data/.github/workflows/ci.yml +79 -0
  4. data/.gitignore +2 -0
  5. data/.rubocop.yml +1 -1
  6. data/README.md +10 -8
  7. data/fog-proxmox.gemspec +3 -3
  8. data/lib/fog/compute/proxmox/models/interface.rb +2 -0
  9. data/lib/fog/compute/proxmox/models/server.rb +0 -1
  10. data/lib/fog/compute/proxmox/models/server_config.rb +1 -1
  11. data/lib/fog/compute/proxmox/models/snapshot.rb +4 -5
  12. data/lib/fog/compute/proxmox/models/storage.rb +2 -3
  13. data/lib/fog/compute/proxmox/models/task.rb +2 -3
  14. data/lib/fog/compute/proxmox/models/volume.rb +3 -3
  15. data/lib/fog/compute/proxmox/requests/action_server.rb +1 -0
  16. data/lib/fog/compute/proxmox/requests/clone_server.rb +1 -0
  17. data/lib/fog/compute/proxmox/requests/create_backup.rb +1 -0
  18. data/lib/fog/compute/proxmox/requests/create_server.rb +1 -0
  19. data/lib/fog/compute/proxmox/requests/create_snapshot.rb +3 -1
  20. data/lib/fog/compute/proxmox/requests/create_spice.rb +1 -0
  21. data/lib/fog/compute/proxmox/requests/create_term.rb +1 -0
  22. data/lib/fog/compute/proxmox/requests/create_vnc.rb +1 -0
  23. data/lib/fog/compute/proxmox/requests/delete_server.rb +1 -0
  24. data/lib/fog/compute/proxmox/requests/delete_snapshot.rb +3 -1
  25. data/lib/fog/compute/proxmox/requests/delete_volume.rb +1 -1
  26. data/lib/fog/compute/proxmox/requests/get_node_statistics.rb +2 -2
  27. data/lib/fog/compute/proxmox/requests/get_server_config.rb +18 -0
  28. data/lib/fog/compute/proxmox/requests/get_server_status.rb +21 -0
  29. data/lib/fog/compute/proxmox/requests/get_snapshot_config.rb +1 -1
  30. data/lib/fog/compute/proxmox/requests/get_task.rb +1 -1
  31. data/lib/fog/compute/proxmox/requests/get_vnc.rb +1 -0
  32. data/lib/fog/compute/proxmox/requests/get_volume.rb +1 -1
  33. data/lib/fog/compute/proxmox/requests/list_nodes.rb +8 -1
  34. data/lib/fog/compute/proxmox/requests/list_servers.rb +72 -1
  35. data/lib/fog/compute/proxmox/requests/list_snapshots.rb +24 -1
  36. data/lib/fog/compute/proxmox/requests/list_storages.rb +3 -1
  37. data/lib/fog/compute/proxmox/requests/list_tasks.rb +3 -1
  38. data/lib/fog/compute/proxmox/requests/list_volumes.rb +3 -1
  39. data/lib/fog/compute/proxmox/requests/log_task.rb +3 -1
  40. data/lib/fog/compute/proxmox/requests/migrate_server.rb +1 -1
  41. data/lib/fog/compute/proxmox/requests/move_disk.rb +1 -1
  42. data/lib/fog/compute/proxmox/requests/move_volume.rb +1 -1
  43. data/lib/fog/compute/proxmox/requests/next_vmid.rb +1 -0
  44. data/lib/fog/compute/proxmox/requests/resize_container.rb +1 -1
  45. data/lib/fog/compute/proxmox/requests/resize_server.rb +1 -1
  46. data/lib/fog/compute/proxmox/requests/rollback_snapshot.rb +3 -1
  47. data/lib/fog/compute/proxmox/requests/status_task.rb +1 -1
  48. data/lib/fog/compute/proxmox/requests/stop_task.rb +1 -1
  49. data/lib/fog/compute/proxmox/requests/template_server.rb +1 -0
  50. data/lib/fog/compute/proxmox/requests/update_server.rb +1 -0
  51. data/lib/fog/compute/proxmox/requests/update_snapshot.rb +1 -1
  52. data/lib/fog/identity/proxmox/models/pool.rb +18 -0
  53. data/lib/fog/identity/proxmox/models/pools.rb +3 -1
  54. data/lib/fog/proxmox/core.rb +1 -1
  55. data/lib/fog/proxmox/helpers/controller_helper.rb +1 -1
  56. data/lib/fog/proxmox/helpers/cpu_helper.rb +1 -1
  57. data/lib/fog/proxmox/helpers/disk_helper.rb +16 -0
  58. data/lib/fog/proxmox/helpers/ip_helper.rb +100 -0
  59. data/lib/fog/proxmox/helpers/nic_helper.rb +16 -2
  60. data/lib/fog/proxmox/version.rb +1 -1
  61. data/spec/fixtures/proxmox/identity/auth.yml +8 -8
  62. data/spec/fixtures/proxmox/identity/domains.yml +119 -115
  63. data/spec/fixtures/proxmox/identity/groups.yml +51 -51
  64. data/spec/fixtures/proxmox/identity/identity_ticket.yml +6 -6
  65. data/spec/fixtures/proxmox/identity/permissions.yml +122 -122
  66. data/spec/fixtures/proxmox/identity/pools.yml +603 -95
  67. data/spec/fixtures/proxmox/identity/read_version.yml +6 -6
  68. data/spec/fixtures/proxmox/identity/renew.yml +6 -6
  69. data/spec/fixtures/proxmox/identity/roles.yml +59 -59
  70. data/spec/fixtures/proxmox/identity/users.yml +111 -111
  71. data/spec/helpers/controller_helper_spec.rb +13 -2
  72. data/spec/helpers/cpu_helper_spec.rb +2 -2
  73. data/spec/helpers/disk_helper_spec.rb +12 -0
  74. data/spec/helpers/ip_helper_spec.rb +160 -0
  75. data/spec/helpers/nic_helper_spec.rb +18 -4
  76. data/spec/identity_spec.rb +6 -0
  77. metadata +14 -12
  78. data/.gitlab-ci.yml +0 -50
  79. data/.travis.yml +0 -25
  80. data/Gemfile.lock +0 -153
@@ -37,7 +37,7 @@ module Fog
37
37
 
38
38
  # class Mock get_snapshot_config request
39
39
  class Mock
40
- def get_snapshot_config; end
40
+ def get_snapshot_config(_path_params); end
41
41
  end
42
42
  end
43
43
  end
@@ -34,7 +34,7 @@ module Fog
34
34
 
35
35
  # class Mock get_task collection
36
36
  class Mock
37
- def get_task(node, upid); end
37
+ def get_task(_node, _upid); end
38
38
  end
39
39
  end
40
40
  end
@@ -37,6 +37,7 @@ module Fog
37
37
 
38
38
  # class Mock get_vnc request
39
39
  class Mock
40
+ def get_vnc(_path_params, _query_params); end
40
41
  end
41
42
  end
42
43
  end
@@ -35,7 +35,7 @@ module Fog
35
35
 
36
36
  # class Mock get_volume request
37
37
  class Mock
38
- def get_volume; end
38
+ def get_volume(_node, _storage, _volume); end
39
39
  end
40
40
  end
41
41
  end
@@ -34,7 +34,14 @@ module Fog
34
34
 
35
35
  # class Mock list_nodes request
36
36
  class Mock
37
- def list_nodes; end
37
+ def list_nodes
38
+ [
39
+ {
40
+ 'node' => 'proxmox',
41
+ 'type' => 'node'
42
+ }
43
+ ]
44
+ end
38
45
  end
39
46
  end
40
47
  end
@@ -35,7 +35,78 @@ module Fog
35
35
 
36
36
  # class Mock list_servers request
37
37
  class Mock
38
- def list_servers; end
38
+ def list_servers(_options = {})
39
+ if options[:type] == 'qemu'
40
+ [
41
+ {
42
+ 'vmid' => '100',
43
+ 'type' => 'qemu',
44
+ 'node_id' => 'proxmox',
45
+ 'config' => {
46
+ 'vmid' => '100',
47
+ 'description' => nil,
48
+ 'smbios1' => nil,
49
+ 'numa' => 0,
50
+ 'kvm' => 0,
51
+ 'vcpus' => nil,
52
+ 'cores' => 1,
53
+ 'bootdisk' => 'scsi0',
54
+ 'onboot' => 0,
55
+ 'boot' => nil,
56
+ 'agent' => '0',
57
+ 'scsihw' => nil,
58
+ 'sockets' => 1,
59
+ 'memory' => 512,
60
+ 'min_memory' => nil,
61
+ 'shares' => nil,
62
+ 'balloon' => 0,
63
+ 'cpu' => 'cputype=kvm64',
64
+ 'cpulimit' => nil,
65
+ 'cpuunits' => nil,
66
+ 'keyboard' => 'en-us',
67
+ 'vga' => 'std',
68
+ 'storage' => nil,
69
+ 'template' => '',
70
+ 'arch' => nil,
71
+ 'swap' => nil,
72
+ 'hostname' => nil,
73
+ 'nameserver' => nil,
74
+ 'searchdomain' => nil,
75
+ 'password' => nil,
76
+ 'startup' => nil,
77
+ 'console' => nil
78
+ },
79
+ 'digest' => nil,
80
+ 'maxdisk' => 8_589_934_592,
81
+ 'disk' => 0,
82
+ 'diskwrite' => 0,
83
+ 'diskread' => 0,
84
+ 'uptime' => 0,
85
+ 'netout' => 0,
86
+ 'netin' => 0,
87
+ 'cpu' => 'cputype=kvm64',
88
+ 'cpus' => 1,
89
+ 'template' => '',
90
+ 'status' => 'stopped',
91
+ 'maxcpu' => nil,
92
+ 'mem' => 0,
93
+ 'maxmem' => 536_870_912,
94
+ 'qmpstatus' => 'stopped',
95
+ 'ha' => { 'managed' => 0 },
96
+ 'pid' => nil,
97
+ 'blockstat' => nil,
98
+ 'balloon' => 0,
99
+ 'ballooninfo' => nil,
100
+ 'vmgenid' => nil,
101
+ 'lock' => nil,
102
+ 'maxswap' => nil,
103
+ 'swap' => nil
104
+ }
105
+ ]
106
+ else
107
+ []
108
+ end
109
+ end
39
110
  end
40
111
  end
41
112
  end
@@ -36,7 +36,30 @@ module Fog
36
36
 
37
37
  # class Mock list_snapshots request
38
38
  class Mock
39
- def list_snapshots; end
39
+ def list_snapshots(_path_params)
40
+ [
41
+ {
42
+ 'name' => 'snapshot1',
43
+ 'description' => 'latest snapshot',
44
+ 'snaptime' => 1_578_057_452,
45
+ 'vmstate' => 0,
46
+ 'node_id' => 'proxmox',
47
+ 'server_id' => '100',
48
+ 'server_type' => 'qemu',
49
+ 'vmgenid' => nil
50
+ },
51
+ {
52
+ 'name' => 'snapshot2',
53
+ 'description' => 'latest snapshot2',
54
+ 'snaptime' => 1_578_058_452,
55
+ 'vmstate' => 0,
56
+ 'node_id' => 'proxmox',
57
+ 'server_id' => '100',
58
+ 'server_type' => 'qemu',
59
+ 'vmgenid' => nil
60
+ }
61
+ ]
62
+ end
40
63
  end
41
64
  end
42
65
  end
@@ -37,7 +37,9 @@ module Fog
37
37
 
38
38
  # class Mock list_storages request
39
39
  class Mock
40
- def list_storages; end
40
+ def list_storages(_node, _options = {})
41
+ []
42
+ end
41
43
  end
42
44
  end
43
45
  end
@@ -35,7 +35,9 @@ module Fog
35
35
 
36
36
  # class Mock list_tasks request
37
37
  class Mock
38
- def list_tasks; end
38
+ def list_tasks(_node, _options = {})
39
+ []
40
+ end
39
41
  end
40
42
  end
41
43
  end
@@ -35,7 +35,9 @@ module Fog
35
35
 
36
36
  # class Mock list_volumes request
37
37
  class Mock
38
- def list_volumes; end
38
+ def list_volumes(_node, _storage, _options = {})
39
+ []
40
+ end
39
41
  end
40
42
  end
41
43
  end
@@ -35,7 +35,9 @@ module Fog
35
35
 
36
36
  # class Mock status_task
37
37
  class Mock
38
- def log_task(node, upid); end
38
+ def log_task(_node, _upid, options = {})
39
+ [{ 't' => 'TASK OK', 'n' => 1 }]
40
+ end
39
41
  end
40
42
  end
41
43
  end
@@ -37,7 +37,7 @@ module Fog
37
37
 
38
38
  # class Mock migrate_server request
39
39
  class Mock
40
- def migrate_server; end
40
+ def migrate_server(_path_params, _body_params); end
41
41
  end
42
42
  end
43
43
  end
@@ -36,7 +36,7 @@ module Fog
36
36
 
37
37
  # class Mock move_disk request
38
38
  class Mock
39
- def move_disk; end
39
+ def move_disk(_path_params, _body_params); end
40
40
  end
41
41
  end
42
42
  end
@@ -36,7 +36,7 @@ module Fog
36
36
 
37
37
  # class Mock move_volume request
38
38
  class Mock
39
- def move_volume; end
39
+ def move_volume(_path_params, _body_params); end
40
40
  end
41
41
  end
42
42
  end
@@ -35,6 +35,7 @@ module Fog
35
35
 
36
36
  # class Mock next_vmid collection
37
37
  class Mock
38
+ def next_vmid; end
38
39
  end
39
40
  end
40
41
  end
@@ -36,7 +36,7 @@ module Fog
36
36
 
37
37
  # class Mock resize_container request
38
38
  class Mock
39
- def resize_container; end
39
+ def resize_container(_path_params, _body_params); end
40
40
  end
41
41
  end
42
42
  end
@@ -36,7 +36,7 @@ module Fog
36
36
 
37
37
  # class Mock resize_server request
38
38
  class Mock
39
- def resize_server; end
39
+ def resize_server(_path_params, _body_params); end
40
40
  end
41
41
  end
42
42
  end
@@ -39,7 +39,9 @@ module Fog
39
39
 
40
40
  # class Mock rollback_snapshot request
41
41
  class Mock
42
- def rollback_snapshot; end
42
+ def rollback_snapshot(_path_params)
43
+ 'UPID:proxmox:00002EBF:646E2BF3:5E1C7E39:qmrollback:100:root@pam:'
44
+ end
43
45
  end
44
46
  end
45
47
  end
@@ -34,7 +34,7 @@ module Fog
34
34
 
35
35
  # class Mock status_task
36
36
  class Mock
37
- def status_task(node, upid); end
37
+ def status_task(_node, _upid); end
38
38
  end
39
39
  end
40
40
  end
@@ -34,7 +34,7 @@ module Fog
34
34
 
35
35
  # class Mock get_task collection
36
36
  class Mock
37
- def stop_task(taskid); end
37
+ def stop_task(_node, _taskid); end
38
38
  end
39
39
  end
40
40
  end
@@ -37,6 +37,7 @@ module Fog
37
37
 
38
38
  # class Mock template_server request
39
39
  class Mock
40
+ def template_server(_path_params, _body_params); end
40
41
  end
41
42
  end
42
43
  end
@@ -37,6 +37,7 @@ module Fog
37
37
 
38
38
  # class Mock update_server request
39
39
  class Mock
40
+ def update_server(_path_params, _body_params); end
40
41
  end
41
42
  end
42
43
  end
@@ -38,7 +38,7 @@ module Fog
38
38
 
39
39
  # class Mock update_snapshot request
40
40
  class Mock
41
- def update_snapshot; end
41
+ def update_snapshot(_path_params, _body_params); end
42
42
  end
43
43
  end
44
44
  end
@@ -65,6 +65,24 @@ module Fog
65
65
  def update
66
66
  update_with_member(nil, nil, false)
67
67
  end
68
+
69
+ def has_server?(vmid)
70
+ has?("vmid", vmid)
71
+ end
72
+
73
+ def has_storage?(storage)
74
+ has?("storage", storage)
75
+ end
76
+
77
+ private
78
+
79
+ def has?(key, vmid)
80
+ result = false
81
+ attributes[:members].each do |member|
82
+ result = member[key].to_s.eql?(vmid.to_s) if member.has_key?(key) && member[key] && vmid
83
+ end
84
+ result
85
+ end
68
86
  end
69
87
  end
70
88
  end
@@ -27,7 +27,9 @@ module Fog
27
27
  model Fog::Proxmox::Identity::Pool
28
28
 
29
29
  def all
30
- load service.list_pools
30
+ pools_with_members = Array.new
31
+ service.list_pools.each { |pool| pools_with_members.push(pool.merge(service.get_pool(pool["poolid"]))) }
32
+ load pools_with_members
31
33
  end
32
34
 
33
35
  def get(id)
@@ -69,7 +69,7 @@ module Fog
69
69
  private
70
70
 
71
71
  def request(params)
72
- retried = false
72
+ retried = false
73
73
  begin
74
74
  response = @connection.request(params.merge(
75
75
  headers: headers(params[:method], params[:headers])
@@ -24,7 +24,7 @@ module Fog
24
24
 
25
25
  CONTROLLERS = %w[ide sata scsi virtio mp rootfs].freeze
26
26
  def self.extract(name, controller_value)
27
- matches = controller_value.match(/[,]{0,1}#{name}[=]{1}(?<name_value>[\w\/]+)/)
27
+ matches = controller_value.match(/[,]{0,1}#{name}[=]{1}(?<name_value>[\w\/\.\:]+)/)
28
28
  matches ? matches[:name_value] : matches
29
29
  end
30
30
 
@@ -21,7 +21,7 @@ module Fog
21
21
  module Proxmox
22
22
  # module Cpu mixins
23
23
  module CpuHelper
24
- CPU_REGEXP = /(\bcputype=)?(\w+)[,]?(\bflags=)?(\+[\w-]+)?[;]?(\+[\w-]+)?/
24
+ CPU_REGEXP = /(\bcputype=)?([\w-]+)[,]?(\bflags=)?(\+[\w-]+)?[;]?(\+[\w-]+)?/
25
25
  def self.extract(cpu,i)
26
26
  cpu ? CPU_REGEXP.match(cpu.to_s)[i] : ''
27
27
  end
@@ -110,6 +110,22 @@ module Fog
110
110
  val[0].to_i*1024**m
111
111
  end
112
112
 
113
+ def self.modulo_bytes(size)
114
+ size / 1024
115
+ end
116
+
117
+ def self.to_human_bytes(size)
118
+ units = ['Kb','Mb','Gb','Tb','Pb']
119
+ i = 0
120
+ human_size = size.to_s + 'b'
121
+ while i < 5 && size >= 1024
122
+ size = self.modulo_bytes(size)
123
+ human_size = size.to_s + units[i]
124
+ i+=1
125
+ end
126
+ human_size
127
+ end
128
+
113
129
  def self.extract_size(disk_value)
114
130
  size=extract_option('size', disk_value)
115
131
  size ? self.to_bytes(size) : "1G"
@@ -0,0 +1,100 @@
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 'resolv'
21
+ require 'fog/proxmox/hash'
22
+
23
+ module Fog
24
+ module Proxmox
25
+ # module IpHelper mixins
26
+ module IpHelper
27
+
28
+ CIDRv4_PREFIX = '([0-9]|[1-2][0-9]|3[0-2])'
29
+ CIDRv4_PREFIX_REGEXP = /^#{CIDRv4_PREFIX}$/
30
+ IPv4_SRC = "#{Resolv::IPv4::Regex.source.delete_suffix('\z').delete_prefix('\A')}"
31
+ CIDRv4_REGEXP = Regexp.new("\\A(#{IPv4_SRC})(\/#{CIDRv4_PREFIX})?\\z")
32
+ CIDRv6_PREFIX = '(\d+)'
33
+ CIDRv6_PREFIX_REGEXP = /^#{CIDRv6_PREFIX}$/xi
34
+ IPv6_SRC = "#{Resolv::IPv6::Regex_8Hex.source.delete_suffix('\z').delete_prefix('\A')}"
35
+ CIDRv6_REGEXP = Regexp.new("\\A(#{IPv6_SRC})(\/#{CIDRv6_PREFIX})?\\z", Regexp::EXTENDED | Regexp::IGNORECASE)
36
+
37
+ def self.cidr?(ip)
38
+ CIDRv4_REGEXP.match?(ip)
39
+ end
40
+
41
+ def self.cidr6?(ip)
42
+ CIDRv6_REGEXP.match?(ip)
43
+ end
44
+
45
+ def self.prefix(ip)
46
+ if cidr = CIDRv4_REGEXP.match(ip)
47
+ cidr[7]
48
+ end
49
+ end
50
+
51
+ def self.prefix6(ip)
52
+ if cidr = CIDRv6_REGEXP.match(ip)
53
+ cidr[3]
54
+ end
55
+ end
56
+
57
+ def self.ip?(ip)
58
+ Resolv::IPv4::Regex.match?(ip)
59
+ end
60
+
61
+ def self.ip6?(ip)
62
+ Resolv::IPv6::Regex.match?(ip)
63
+ end
64
+
65
+ def self.cidr_prefix?(prefix)
66
+ CIDRv4_PREFIX_REGEXP.match?(prefix)
67
+ end
68
+
69
+ def self.cidr6_prefix?(prefix)
70
+ CIDRv6_PREFIX_REGEXP.match?(prefix) && prefix.to_i >= 0 && prefix.to_i <= 128
71
+ end
72
+
73
+ def self.ip(ip)
74
+ if cidr = CIDRv4_REGEXP.match(ip)
75
+ cidr[1]
76
+ end
77
+ end
78
+
79
+ def self.ip6(ip)
80
+ if cidr = CIDRv6_REGEXP.match(ip)
81
+ cidr[1]
82
+ end
83
+ end
84
+
85
+ def self.to_cidr(ip,prefix = nil)
86
+ return nil unless self.ip?(ip) && (!prefix || self.cidr_prefix?(prefix))
87
+ cidr = "#{ip}"
88
+ cidr += "/#{prefix}" if self.cidr_prefix?(prefix)
89
+ cidr
90
+ end
91
+
92
+ def self.to_cidr6(ip,prefix = nil)
93
+ return nil unless self.ip6?(ip) && (!prefix || self.cidr6_prefix?(prefix))
94
+ cidr = "#{ip}"
95
+ cidr += "/#{prefix}" if self.cidr6_prefix?(prefix)
96
+ cidr
97
+ end
98
+ end
99
+ end
100
+ end