fog-proxmox 0.7.0 → 0.8.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.
- checksums.yaml +4 -4
- data/{CODE_OF_CONDUCT.md → .github/CODE_OF_CONDUCT.md} +0 -0
- data/{CONTRIBUTING.md → .github/CONTRIBUTING.md} +0 -0
- data/{CONTRIBUTORS.md → .github/CONTRIBUTORS.md} +0 -0
- data/{ISSUE_TEMPLATE.md → .github/ISSUE_TEMPLATE.md} +0 -0
- data/{SUPPORT.md → .github/SUPPORT.md} +0 -0
- data/{fogproxmox.png → .github/fogproxmox.png} +0 -0
- data/Gemfile.lock +4 -6
- data/README.md +3 -3
- data/fog-proxmox.gemspec +1 -1
- data/lib/fog/compute/proxmox/models/disk.rb +4 -0
- data/lib/fog/compute/proxmox/models/interface.rb +5 -1
- data/lib/fog/compute/proxmox/models/server_config.rb +2 -2
- data/lib/fog/proxmox.rb +16 -12
- data/lib/fog/proxmox/core.rb +9 -14
- data/lib/fog/proxmox/hash.rb +11 -6
- data/lib/fog/proxmox/helpers/disk_helper.rb +52 -11
- data/lib/fog/proxmox/helpers/nic_helper.rb +21 -13
- data/lib/fog/proxmox/version.rb +1 -1
- data/spec/hash_spec.rb +43 -0
- data/spec/helpers/disk_helper_spec.rb +78 -5
- data/spec/helpers/nic_helper_spec.rb +30 -3
- data/spec/proxmox_vcr.rb +1 -1
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0320a22c2debb1a4e6dcc2f7d90e4bee91aa9015391a56bfc727620d3d72c55d
|
4
|
+
data.tar.gz: '075000983c20f5ba9170766ecf1839c0e6c407a57711a0e7efbdcc0cd1b98ef9'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57e88aae5403f9b7b3487963787b7898b18ce4277c44f4bdb264c10997890c5d9d890dd1af005a3808b6e20035a0941baafe5973caaba35615579e97216c7869
|
7
|
+
data.tar.gz: 7bd9493e5601e647f24a5ff1c56231e4543162cd9fbfa57bf66fe9333d06f3cb639633ea1460d27149cd05aa61e6b4a6539827093d04ffb99523697ae45f41c4
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fog-proxmox (0.
|
4
|
+
fog-proxmox (0.8.0)
|
5
5
|
fog-core (~> 2.1)
|
6
6
|
fog-json (~> 1.2)
|
7
7
|
ipaddress (~> 0.8)
|
@@ -51,7 +51,7 @@ GEM
|
|
51
51
|
fog-core
|
52
52
|
multi_json (~> 1.10)
|
53
53
|
formatador (0.2.5)
|
54
|
-
hashdiff (0.3.
|
54
|
+
hashdiff (0.3.9)
|
55
55
|
ice_nine (0.11.2)
|
56
56
|
ipaddress (0.8.3)
|
57
57
|
jaro_winkler (1.5.2)
|
@@ -69,7 +69,6 @@ GEM
|
|
69
69
|
pry (0.12.2)
|
70
70
|
coderay (~> 1.1.0)
|
71
71
|
method_source (~> 0.9.0)
|
72
|
-
psych (3.1.0)
|
73
72
|
public_suffix (3.0.3)
|
74
73
|
rainbow (3.0.0)
|
75
74
|
rake (12.3.2)
|
@@ -84,18 +83,17 @@ GEM
|
|
84
83
|
rspec-mocks (~> 3.8.0)
|
85
84
|
rspec-core (3.8.0)
|
86
85
|
rspec-support (~> 3.8.0)
|
87
|
-
rspec-expectations (3.8.
|
86
|
+
rspec-expectations (3.8.3)
|
88
87
|
diff-lcs (>= 1.2.0, < 2.0)
|
89
88
|
rspec-support (~> 3.8.0)
|
90
89
|
rspec-mocks (3.8.0)
|
91
90
|
diff-lcs (>= 1.2.0, < 2.0)
|
92
91
|
rspec-support (~> 3.8.0)
|
93
92
|
rspec-support (3.8.0)
|
94
|
-
rubocop (0.
|
93
|
+
rubocop (0.68.0)
|
95
94
|
jaro_winkler (~> 1.5.1)
|
96
95
|
parallel (~> 1.10)
|
97
96
|
parser (>= 2.5, != 2.5.1.1)
|
98
|
-
psych (>= 3.1.0)
|
99
97
|
rainbow (>= 2.2.2, < 4.0)
|
100
98
|
ruby-progressbar (~> 1.7)
|
101
99
|
unicode-display_width (>= 1.4.0, < 1.6)
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-

|
1
|
+

|
2
2
|
|
3
3
|
# Fog::Proxmox
|
4
4
|
|
@@ -65,10 +65,10 @@ USE_VCR=true bundle exec rake spec
|
|
65
65
|
|
66
66
|
## Contributing
|
67
67
|
|
68
|
-
You can reach the [contributors](CONTRIBUTORS.md).
|
68
|
+
You can reach the [contributors](.github/CONTRIBUTORS.md).
|
69
69
|
Bug reports and pull requests are welcome on GitHub at [Fog-Proxmox](https://github.com/fog/fog-proxmox/issues). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
70
70
|
|
71
|
-
Please read [how to contribute](CONTRIBUTING.md).
|
71
|
+
Please read [how to contribute](.github/CONTRIBUTING.md).
|
72
72
|
|
73
73
|
## License
|
74
74
|
|
data/fog-proxmox.gemspec
CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
|
30
30
|
spec.summary = "Module for the 'Fog' gem to support Proxmox VE"
|
31
31
|
spec.description = 'This library can be used as a module for `fog`.'
|
32
|
-
spec.homepage = '
|
32
|
+
spec.homepage = 'https://github.com/fog/fog-proxmox'
|
33
33
|
spec.license = 'GPL-3.0'
|
34
34
|
|
35
35
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -25,7 +25,7 @@ module Fog
|
|
25
25
|
# class Interface model
|
26
26
|
class Interface < Fog::Model
|
27
27
|
identity :id
|
28
|
-
attribute :
|
28
|
+
attribute :macaddr
|
29
29
|
attribute :model
|
30
30
|
attribute :name
|
31
31
|
attribute :ip
|
@@ -40,6 +40,10 @@ module Fog
|
|
40
40
|
def flatten
|
41
41
|
Fog::Proxmox::NicHelper.flatten(attributes)
|
42
42
|
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
Fog::Proxmox::Hash.flatten(flatten)
|
46
|
+
end
|
43
47
|
end
|
44
48
|
end
|
45
49
|
end
|
@@ -118,9 +118,9 @@ module Fog
|
|
118
118
|
nic_hash = {
|
119
119
|
id: key.to_s,
|
120
120
|
model: Fog::Proxmox::NicHelper.extract_nic_id(value),
|
121
|
-
|
121
|
+
macaddr: Fog::Proxmox::NicHelper.extract_mac_address(value)
|
122
122
|
}
|
123
|
-
names = Fog::Proxmox::Compute::Interface.attributes.reject { |attribute| [:id, :
|
123
|
+
names = Fog::Proxmox::Compute::Interface.attributes.reject { |attribute| [:id, :macaddr, :model].include? attribute }
|
124
124
|
names.each { |name| nic_hash.store(name.to_sym, Fog::Proxmox::ControllerHelper.extract(name, value)) }
|
125
125
|
attributes[:interfaces] << Fog::Proxmox::Compute::Interface.new(nic_hash)
|
126
126
|
end
|
data/lib/fog/proxmox.rb
CHANGED
@@ -37,27 +37,33 @@ module Fog
|
|
37
37
|
service(:storage, 'Storage')
|
38
38
|
service(:network, 'Network')
|
39
39
|
|
40
|
-
@
|
40
|
+
@credentials = {}
|
41
|
+
@now = Time.now
|
41
42
|
|
42
43
|
# Default lifetime ticket is 2 hours
|
43
44
|
@ticket_lifetime = 2 * 60 * 60
|
44
45
|
|
45
46
|
class << self
|
46
|
-
|
47
|
+
attr_reader :credentials
|
47
48
|
attr_reader :version
|
49
|
+
attr_accessor :now # tests only
|
48
50
|
end
|
49
51
|
|
50
|
-
def self.
|
51
|
-
|
52
|
+
def self.clear_credentials
|
53
|
+
@credentials = {}
|
52
54
|
end
|
53
55
|
|
54
56
|
def self.authenticate(options, connection_options = {})
|
55
57
|
get_tokens(options, connection_options)
|
56
|
-
|
58
|
+
self
|
57
59
|
end
|
58
60
|
|
59
61
|
def self.authenticated?
|
60
|
-
!@
|
62
|
+
!@credentials.empty?
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.credentials_has_expired?
|
66
|
+
authenticated? && @credentials[:deadline] > @now
|
61
67
|
end
|
62
68
|
|
63
69
|
def self.extract_password(options)
|
@@ -73,7 +79,8 @@ module Fog
|
|
73
79
|
uri = URI.parse(url)
|
74
80
|
@api_path = uri.path
|
75
81
|
connection_options = connection_options.merge(path_prefix: @api_path)
|
76
|
-
|
82
|
+
password = @credentials[:csrftoken] if credentials_has_expired?
|
83
|
+
retrieve_tokens(uri, connection_options, username, password) unless authenticated? && !credentials_has_expired?
|
77
84
|
end
|
78
85
|
|
79
86
|
def self.retrieve_tokens(uri, connection_options, username, password)
|
@@ -96,20 +103,17 @@ module Fog
|
|
96
103
|
ticket = data['ticket']
|
97
104
|
username = data['username']
|
98
105
|
csrftoken = data['CSRFPreventionToken']
|
99
|
-
|
100
|
-
now = Time.now
|
101
|
-
deadline = Time.at(now.to_i + @ticket_lifetime)
|
106
|
+
deadline = Time.at(@now.to_i + @ticket_lifetime)
|
102
107
|
save_token(username, ticket, csrftoken, deadline)
|
103
108
|
end
|
104
109
|
|
105
110
|
def self.save_token(username, ticket, csrftoken, deadline)
|
106
|
-
@
|
111
|
+
@credentials = {
|
107
112
|
username: username,
|
108
113
|
ticket: ticket,
|
109
114
|
csrftoken: csrftoken,
|
110
115
|
deadline: deadline
|
111
116
|
}
|
112
|
-
Fog::Proxmox.cache = @cache
|
113
117
|
end
|
114
118
|
end
|
115
119
|
end
|
data/lib/fog/proxmox/core.rb
CHANGED
@@ -38,11 +38,9 @@ module Fog
|
|
38
38
|
|
39
39
|
def initialize_identity(options)
|
40
40
|
@principal = nil
|
41
|
-
@pve_must_reauthenticate = true
|
42
41
|
@pve_ticket = nil
|
43
42
|
Fog::Proxmox::Variables.to_variables(self, options, 'pve')
|
44
43
|
@pve_uri = URI.parse(@pve_url)
|
45
|
-
@pve_must_reauthenticate = true unless @pve_ticket
|
46
44
|
missing_credentials = []
|
47
45
|
missing_credentials << :pve_username unless @pve_username
|
48
46
|
|
@@ -78,7 +76,7 @@ module Fog
|
|
78
76
|
))
|
79
77
|
rescue Excon::Errors::Unauthorized => error
|
80
78
|
# token expiration and token renewal possible
|
81
|
-
if error.response.body != 'Bad username or password' &&
|
79
|
+
if error.response.body != 'Bad username or password' && !retried
|
82
80
|
authenticate
|
83
81
|
retried = true
|
84
82
|
retry
|
@@ -115,17 +113,14 @@ module Fog
|
|
115
113
|
end
|
116
114
|
|
117
115
|
def authenticate
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
@pve_csrftoken = credentials[:csrftoken]
|
127
|
-
@pve_must_reauthenticate = false
|
128
|
-
end
|
116
|
+
options = pve_options
|
117
|
+
@pve_ticket = options[:pve_ticket]
|
118
|
+
Fog::Proxmox.authenticate(options, @connection_options)
|
119
|
+
@principal = Fog::Proxmox.credentials
|
120
|
+
@pve_username = Fog::Proxmox.credentials[:username]
|
121
|
+
@pve_ticket = Fog::Proxmox.credentials[:ticket]
|
122
|
+
@pve_deadline = Fog::Proxmox.credentials[:deadline]
|
123
|
+
@pve_csrftoken = Fog::Proxmox.credentials[:csrftoken]
|
129
124
|
|
130
125
|
@host = @pve_uri.host
|
131
126
|
@api_path = @pve_uri.path
|
data/lib/fog/proxmox/hash.rb
CHANGED
@@ -21,14 +21,19 @@ module Fog
|
|
21
21
|
module Proxmox
|
22
22
|
# module Hash mixins
|
23
23
|
module Hash
|
24
|
+
|
24
25
|
def self.stringify(hash)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
filtered = hash.reject { |_key,value| value.to_s.empty? }
|
27
|
+
a = filtered.to_a.collect { |item| item.join('=') }
|
28
|
+
a.join(',')
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.flatten(hash)
|
32
|
+
filtered = hash.reject { |_key,value| value.to_s.empty? }
|
33
|
+
a = filtered.to_a.collect { |item| item.join(': ') }
|
34
|
+
a.join(',')
|
31
35
|
end
|
36
|
+
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
@@ -23,19 +23,36 @@ module Fog
|
|
23
23
|
module Proxmox
|
24
24
|
# module Disk mixins
|
25
25
|
module DiskHelper
|
26
|
+
|
27
|
+
DISKS_REGEXP = /^(scsi|sata|mp|rootfs|virtio|ide)(\d+){0,1}$/
|
28
|
+
SERVER_DISK_REGEXP = /^(scsi|sata|virtio|ide)(\d+)$/
|
29
|
+
MOUNT_POINT_REGEXP = /^(mp)(\d+)$/
|
30
|
+
ROOTFS_REGEXP = /^(rootfs)$/
|
31
|
+
CDROM_REGEXP = /^(.*)[,]{0,1}(media=cdrom)[,]{0,1}(.*)$/
|
32
|
+
|
26
33
|
def self.flatten(disk)
|
27
|
-
|
28
|
-
value =
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
id = disk[:id]
|
35
|
+
value = ''
|
36
|
+
if disk[:volid]
|
37
|
+
value += disk[:volid]
|
38
|
+
value += ',size=' + disk[:size].to_s if disk[:size]
|
39
|
+
elsif disk[:storage] && disk[:size]
|
40
|
+
value += disk[:storage] + ':' + disk[:size].to_s
|
41
|
+
elsif id == 'ide2'
|
42
|
+
value += 'none'
|
43
|
+
end
|
44
|
+
opts = disk[:options] if disk[:options]
|
34
45
|
main_a = [:id,:volid,:storage,:size]
|
35
46
|
opts = disk.reject { |key,_value| main_a.include? key } unless opts
|
36
|
-
options =
|
37
|
-
|
38
|
-
|
47
|
+
options = ''
|
48
|
+
options += Fog::Proxmox::Hash.stringify(opts) if opts
|
49
|
+
if id == 'ide2' && !self.cdrom?(options)
|
50
|
+
options += ',' if !options.empty?
|
51
|
+
options += 'media=cdrom'
|
52
|
+
end
|
53
|
+
value += ',' if !options.empty? && !value.empty?
|
54
|
+
value += options
|
55
|
+
{ "#{id}": value }
|
39
56
|
end
|
40
57
|
|
41
58
|
def self.extract_controller(id)
|
@@ -59,7 +76,7 @@ module Fog
|
|
59
76
|
def self.extract_storage_volid_size(disk_value)
|
60
77
|
#volid definition: <VOULME_ID>:=<STORAGE_ID>:<storage type dependent volume name>
|
61
78
|
values_a = disk_value.scan(/^(([\w-]+)[:]{0,1}([\w\/\.-]+))/)
|
62
|
-
no_cdrom = !disk_value.match(
|
79
|
+
no_cdrom = !disk_value.match(CDROM_REGEXP)
|
63
80
|
creation = disk_value.split(',')[0].match(/^(([\w-]+)[:]{1}([\d]+))$/)
|
64
81
|
values = values_a.first if values_a
|
65
82
|
if no_cdrom
|
@@ -97,6 +114,30 @@ module Fog
|
|
97
114
|
size=extract_option('size', disk_value)
|
98
115
|
size ? self.to_bytes(size) : "1G"
|
99
116
|
end
|
117
|
+
|
118
|
+
def self.disk?(id)
|
119
|
+
DISKS_REGEXP.match?(id)
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.cdrom?(value)
|
123
|
+
CDROM_REGEXP.match?(value)
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.server_disk?(id)
|
127
|
+
SERVER_DISK_REGEXP.match?(id)
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.rootfs?(id)
|
131
|
+
ROOTFS_REGEXP.match?(id)
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.mount_point?(id)
|
135
|
+
MOUNT_POINT_REGEXP.match?(id)
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.container_disk?(id)
|
139
|
+
rootfs?(id) || mount_point?(id)
|
140
|
+
end
|
100
141
|
end
|
101
142
|
end
|
102
143
|
end
|
@@ -24,6 +24,8 @@ module Fog
|
|
24
24
|
# module NicHelper mixins
|
25
25
|
module NicHelper
|
26
26
|
|
27
|
+
NICS_REGEXP = /^(net)(\d+)/
|
28
|
+
|
27
29
|
def self.extract_mac_address(nic_value)
|
28
30
|
nic_value[/([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})/]
|
29
31
|
end
|
@@ -36,7 +38,7 @@ module Fog
|
|
36
38
|
/^name=(\w+)[,].+/
|
37
39
|
end
|
38
40
|
|
39
|
-
def self.
|
41
|
+
def self.nic_update_regexp
|
40
42
|
/^(\w+)[=]{1}([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2}).+/
|
41
43
|
end
|
42
44
|
|
@@ -54,13 +56,13 @@ module Fog
|
|
54
56
|
elsif self.has_name?(nic_value)
|
55
57
|
nic_value.scan(self.name_regexp).first.first
|
56
58
|
else
|
57
|
-
nic_value.scan(self.
|
59
|
+
nic_value.scan(self.nic_update_regexp).first.first
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
61
63
|
def self.to_mac_adresses_array(nics)
|
62
64
|
addresses = []
|
63
|
-
nics.each { |nic| addresses.push(nic.
|
65
|
+
nics.each { |nic| addresses.push(nic.macaddr) }
|
64
66
|
addresses
|
65
67
|
end
|
66
68
|
|
@@ -74,19 +76,25 @@ module Fog
|
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
77
|
-
def self.flatten(
|
78
|
-
nic_id =
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
79
|
+
def self.flatten(nic_hash)
|
80
|
+
nic_id = nic_hash[self.nic_name(nic_hash).to_sym]
|
81
|
+
if nic_hash.has_key?(:macaddr)
|
82
|
+
nic_value = nic_id + "=" + nic_hash[:macaddr]
|
83
|
+
else
|
84
|
+
nic_value = self.nic_name(nic_hash) + "=" + nic_id
|
85
|
+
end
|
86
|
+
options = nic_hash.reject { |key, _value| [self.nic_name(nic_hash).to_sym,:id,:macaddr].include? key.to_sym }
|
87
|
+
nic_value += ',' unless options.empty?
|
88
|
+
nic_value += Fog::Proxmox::Hash.stringify(options) unless options.empty?
|
89
|
+
{ "#{nic_hash[:id]}": nic_value }
|
86
90
|
end
|
87
91
|
|
88
92
|
def self.collect_nics(attributes)
|
89
|
-
attributes.select { |key|
|
93
|
+
attributes.select { |key| nic?(key.to_s) }
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.nic?(id)
|
97
|
+
NICS_REGEXP.match?(id)
|
90
98
|
end
|
91
99
|
end
|
92
100
|
end
|
data/lib/fog/proxmox/version.rb
CHANGED
data/spec/hash_spec.rb
ADDED
@@ -0,0 +1,43 @@
|
|
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 'spec_helper'
|
21
|
+
require 'fog/proxmox/hash'
|
22
|
+
|
23
|
+
describe Fog::Proxmox::Hash do
|
24
|
+
|
25
|
+
let(:net_vm) do
|
26
|
+
{ net0: 'virtio=66:89:C5:59:AA:96,bridge=vmbr0,firewall=1,link_down=1,queues=1,rate=1,tag=1' }
|
27
|
+
end
|
28
|
+
let(:net) do
|
29
|
+
{ id: 'net0', model: 'virtio', macaddr: '66:89:C5:59:AA:96', z: nil }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#flatten' do
|
33
|
+
it "returns string net_vm" do
|
34
|
+
assert_equal 'net0: virtio=66:89:C5:59:AA:96,bridge=vmbr0,firewall=1,link_down=1,queues=1,rate=1,tag=1', Fog::Proxmox::Hash.flatten(net_vm)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#stringify' do
|
39
|
+
it "returns stringify hash" do
|
40
|
+
assert_equal 'id=net0,model=virtio,macaddr=66:89:C5:59:AA:96', Fog::Proxmox::Hash.stringify(net)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -35,12 +35,20 @@ require 'fog/proxmox/helpers/disk_helper'
|
|
35
35
|
end
|
36
36
|
|
37
37
|
let(:virtio1) do
|
38
|
-
|
39
|
-
|
38
|
+
{ id: 'virtio1', volid: 'local:108/vm-108-disk-1.qcow2,size=15G' }
|
39
|
+
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
let(:virtio) do
|
42
|
+
{ virtio1: 'local:108/vm-108-disk-1.qcow2,size=245'}
|
43
|
+
end
|
44
|
+
|
45
|
+
let(:ide2) do
|
46
|
+
{ id: 'ide2' }
|
47
|
+
end
|
48
|
+
|
49
|
+
let(:ide2_image) do
|
50
|
+
{ id: 'ide2', volid: 'local:iso/alpine-virt-3.7.0-x86_64.iso' }
|
51
|
+
end
|
44
52
|
|
45
53
|
let(:cdrom_none) do
|
46
54
|
{ ide2: 'none,media=cdrom'}
|
@@ -59,6 +67,14 @@ require 'fog/proxmox/helpers/disk_helper'
|
|
59
67
|
disk = Fog::Proxmox::DiskHelper.flatten(scsi0_image)
|
60
68
|
assert_equal({ scsi0: 'local-lvm:vm-100-disk-1,size=1,cache=none' }, disk)
|
61
69
|
end
|
70
|
+
it "returns cdrom none string" do
|
71
|
+
disk = Fog::Proxmox::DiskHelper.flatten(ide2)
|
72
|
+
assert_equal(cdrom_none, disk)
|
73
|
+
end
|
74
|
+
it "returns cdrom image string" do
|
75
|
+
disk = Fog::Proxmox::DiskHelper.flatten(ide2_image)
|
76
|
+
assert_equal(cdrom_iso, disk)
|
77
|
+
end
|
62
78
|
end
|
63
79
|
|
64
80
|
describe '#extract_controller' do
|
@@ -122,4 +138,61 @@ require 'fog/proxmox/helpers/disk_helper'
|
|
122
138
|
assert_equal(245, size)
|
123
139
|
end
|
124
140
|
end
|
141
|
+
|
142
|
+
describe '#disk?' do
|
143
|
+
it "rootfs returns true" do
|
144
|
+
assert Fog::Proxmox::DiskHelper.disk?('rootfs')
|
145
|
+
end
|
146
|
+
it "mp0 returns true" do
|
147
|
+
assert Fog::Proxmox::DiskHelper.disk?('mp0')
|
148
|
+
end
|
149
|
+
it "scsi0 returns true" do
|
150
|
+
assert Fog::Proxmox::DiskHelper.disk?('scsi0')
|
151
|
+
end
|
152
|
+
it "virtio12 returns true" do
|
153
|
+
assert Fog::Proxmox::DiskHelper.disk?('virtio12')
|
154
|
+
end
|
155
|
+
it "sata2 returns true" do
|
156
|
+
assert Fog::Proxmox::DiskHelper.disk?('sata2')
|
157
|
+
end
|
158
|
+
it "ide0 returns true" do
|
159
|
+
assert Fog::Proxmox::DiskHelper.disk?('ide0')
|
160
|
+
end
|
161
|
+
it "dsfdsfdsfds returns false" do
|
162
|
+
assert !Fog::Proxmox::DiskHelper.disk?('dsfdsfdsfds')
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe '#server_disk?' do
|
167
|
+
it "ide0 returns true" do
|
168
|
+
assert Fog::Proxmox::DiskHelper.server_disk?('ide0')
|
169
|
+
end
|
170
|
+
it "scsi1 returns true" do
|
171
|
+
assert Fog::Proxmox::DiskHelper.server_disk?('scsi1')
|
172
|
+
end
|
173
|
+
it "virtio returns false" do
|
174
|
+
assert !Fog::Proxmox::DiskHelper.server_disk?('virtio')
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe '#container_disk?' do
|
179
|
+
it "rootfs returns true" do
|
180
|
+
assert Fog::Proxmox::DiskHelper.container_disk?('rootfs')
|
181
|
+
end
|
182
|
+
it "mp0 returns true" do
|
183
|
+
assert Fog::Proxmox::DiskHelper.container_disk?('mp0')
|
184
|
+
end
|
185
|
+
it "mp returns false" do
|
186
|
+
assert !Fog::Proxmox::DiskHelper.container_disk?('mp')
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe '#cdrom?' do
|
191
|
+
it "local:iso/alpine-virt-3.7.0-x86_64.iso,media=cdrom returns true" do
|
192
|
+
assert Fog::Proxmox::DiskHelper.cdrom?('local:iso/alpine-virt-3.7.0-x86_64.iso,media=cdrom')
|
193
|
+
end
|
194
|
+
it "local:iso/alpine-virt-3.7.0-x86_64.iso returns false" do
|
195
|
+
assert !Fog::Proxmox::DiskHelper.cdrom?('local:iso/alpine-virt-3.7.0-x86_64.iso')
|
196
|
+
end
|
197
|
+
end
|
125
198
|
end
|
@@ -38,6 +38,18 @@ require 'fog/proxmox/helpers/nic_helper'
|
|
38
38
|
{ net0: 'name=eth0,bridge=vmbr0,firewall=1,link_down=1,queues=1,rate=1,tag=1' }
|
39
39
|
end
|
40
40
|
|
41
|
+
let(:lxc_nic) do
|
42
|
+
{ id: 'net0', name: 'eth0', macaddr: '66:89:C5:59:AA:96', bridge: 'vmbr0', firewall: 1, link_down: 1, queues: 1, rate: 1, tag: 1 }
|
43
|
+
end
|
44
|
+
|
45
|
+
let(:qemu_nic) do
|
46
|
+
{ id: 'net1', model: 'virtio', macaddr: '66:89:C5:59:AA:96', bridge: 'vmbr0', firewall: 1, link_down: 1, queues: 1, rate: 1, tag: 1 }
|
47
|
+
end
|
48
|
+
|
49
|
+
let(:qemu_nic_create) do
|
50
|
+
{ id: 'net1', model: 'virtio', bridge: 'vmbr0', firewall: 1, link_down: 1, queues: 1, rate: 1, tag: 1 }
|
51
|
+
end
|
52
|
+
|
41
53
|
describe '#extract_model' do
|
42
54
|
it "returns model card" do
|
43
55
|
model = Fog::Proxmox::NicHelper.extract_nic_id(net_vm[:net0])
|
@@ -71,12 +83,12 @@ require 'fog/proxmox/helpers/nic_helper'
|
|
71
83
|
end
|
72
84
|
end
|
73
85
|
|
74
|
-
describe '#
|
86
|
+
describe '#nic?' do
|
75
87
|
it "returns true" do
|
76
|
-
assert Fog::Proxmox::NicHelper.
|
88
|
+
assert Fog::Proxmox::NicHelper.nic?('net0')
|
77
89
|
end
|
78
90
|
it "returns false" do
|
79
|
-
assert !Fog::Proxmox::NicHelper.
|
91
|
+
assert !Fog::Proxmox::NicHelper.nic?('net')
|
80
92
|
end
|
81
93
|
end
|
82
94
|
|
@@ -92,4 +104,19 @@ require 'fog/proxmox/helpers/nic_helper'
|
|
92
104
|
assert nets.empty?
|
93
105
|
end
|
94
106
|
end
|
107
|
+
|
108
|
+
describe '#flatten' do
|
109
|
+
it "returns qemu nic string" do
|
110
|
+
flat_qemu = { net1: 'virtio=66:89:C5:59:AA:96,bridge=vmbr0,firewall=1,link_down=1,queues=1,rate=1,tag=1' }
|
111
|
+
assert_equal flat_qemu ,Fog::Proxmox::NicHelper.flatten(qemu_nic)
|
112
|
+
end
|
113
|
+
it "returns qemu nic create string" do
|
114
|
+
flat_qemu = { net1: 'model=virtio,bridge=vmbr0,firewall=1,link_down=1,queues=1,rate=1,tag=1' }
|
115
|
+
assert_equal flat_qemu ,Fog::Proxmox::NicHelper.flatten(qemu_nic_create)
|
116
|
+
end
|
117
|
+
it "returns lxc nic string" do
|
118
|
+
flat_lxc = { net0: 'eth0=66:89:C5:59:AA:96,bridge=vmbr0,firewall=1,link_down=1,queues=1,rate=1,tag=1' }
|
119
|
+
assert_equal flat_lxc ,Fog::Proxmox::NicHelper.flatten(lxc_nic)
|
120
|
+
end
|
121
|
+
end
|
95
122
|
end
|
data/spec/proxmox_vcr.rb
CHANGED
@@ -72,7 +72,7 @@ class ProxmoxVCR
|
|
72
72
|
@connection_options[:ssl_verify_peer] = false if ENV['SSL_VERIFY_PEER'] == 'false'
|
73
73
|
|
74
74
|
VCR.use_cassette('identity_ticket') do
|
75
|
-
Fog::Proxmox.
|
75
|
+
Fog::Proxmox.clear_credentials
|
76
76
|
|
77
77
|
@username = 'root@pam'
|
78
78
|
@password = 'proxmox01'
|
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.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tristan Robert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -287,8 +287,14 @@ extra_rdoc_files: []
|
|
287
287
|
files:
|
288
288
|
- ".bundle/config"
|
289
289
|
- ".codeclimate.yml"
|
290
|
+
- ".github/CODE_OF_CONDUCT.md"
|
291
|
+
- ".github/CONTRIBUTING.md"
|
292
|
+
- ".github/CONTRIBUTORS.md"
|
293
|
+
- ".github/ISSUE_TEMPLATE.md"
|
290
294
|
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
291
295
|
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
296
|
+
- ".github/SUPPORT.md"
|
297
|
+
- ".github/fogproxmox.png"
|
292
298
|
- ".gitignore"
|
293
299
|
- ".gitlab-ci.yml"
|
294
300
|
- ".rubocop.yml"
|
@@ -298,16 +304,11 @@ files:
|
|
298
304
|
- ".vscode/launch.json"
|
299
305
|
- ".vscode/settings.json"
|
300
306
|
- ".vscode/tasks.json"
|
301
|
-
- CODE_OF_CONDUCT.md
|
302
|
-
- CONTRIBUTING.md
|
303
|
-
- CONTRIBUTORS.md
|
304
307
|
- Gemfile
|
305
308
|
- Gemfile.lock
|
306
|
-
- ISSUE_TEMPLATE.md
|
307
309
|
- LICENSE
|
308
310
|
- README.md
|
309
311
|
- Rakefile
|
310
|
-
- SUPPORT.md
|
311
312
|
- bin/console
|
312
313
|
- bin/setup
|
313
314
|
- docs/compute.md
|
@@ -317,7 +318,6 @@ files:
|
|
317
318
|
- examples/compute.rb
|
318
319
|
- examples/identity.rb
|
319
320
|
- fog-proxmox.gemspec
|
320
|
-
- fogproxmox.png
|
321
321
|
- lib/fog/compute/proxmox.rb
|
322
322
|
- lib/fog/compute/proxmox/models/disk.rb
|
323
323
|
- lib/fog/compute/proxmox/models/disks.rb
|
@@ -463,6 +463,7 @@ files:
|
|
463
463
|
- spec/fixtures/proxmox/identity/users.yml
|
464
464
|
- spec/fixtures/proxmox/network/identity_ticket.yml
|
465
465
|
- spec/fixtures/proxmox/network/networks.yml
|
466
|
+
- spec/hash_spec.rb
|
466
467
|
- spec/helpers/controller_helper_spec.rb
|
467
468
|
- spec/helpers/cpu_helper_spec.rb
|
468
469
|
- spec/helpers/disk_helper_spec.rb
|
@@ -471,7 +472,7 @@ files:
|
|
471
472
|
- spec/network_spec.rb
|
472
473
|
- spec/proxmox_vcr.rb
|
473
474
|
- spec/spec_helper.rb
|
474
|
-
homepage:
|
475
|
+
homepage: https://github.com/fog/fog-proxmox
|
475
476
|
licenses:
|
476
477
|
- GPL-3.0
|
477
478
|
metadata: {}
|
@@ -514,6 +515,7 @@ test_files:
|
|
514
515
|
- spec/fixtures/proxmox/identity/users.yml
|
515
516
|
- spec/fixtures/proxmox/network/identity_ticket.yml
|
516
517
|
- spec/fixtures/proxmox/network/networks.yml
|
518
|
+
- spec/hash_spec.rb
|
517
519
|
- spec/helpers/controller_helper_spec.rb
|
518
520
|
- spec/helpers/cpu_helper_spec.rb
|
519
521
|
- spec/helpers/disk_helper_spec.rb
|