Skip to content

Commit 17ba2d4

Browse files
committed
Add cloud-init support
Fixes #68
1 parent 9886649 commit 17ba2d4

File tree

5 files changed

+269
-204
lines changed

5 files changed

+269
-204
lines changed

lib/fog/proxmox/compute/models/disk.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# frozen_string_literal: true
1919

2020
require 'fog/proxmox/helpers/disk_helper'
21+
require 'fog/proxmox/helpers/controller_helper'
2122

2223
module Fog
2324
module Proxmox
@@ -56,11 +57,19 @@ def rootfs?
5657
end
5758

5859
def mount_point?
59-
id.match(/(mp)(\d+)/)
60+
Fog::Proxmox::DiskHelper.mount_point?(id)
6061
end
6162

6263
def controller?
63-
id.match(/(scsi|ide|sata|virtio)(\d+)/)
64+
Fog::Proxmox::DiskHelper.server_disk?(id)
65+
end
66+
67+
def cloud_init?
68+
id != 'ide2' && media == 'cdrom'
69+
end
70+
71+
def hard_disk?
72+
controller? && !cdrom? && !cloud_init?
6473
end
6574

6675
def template?

lib/fog/proxmox/compute/models/disks.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ def cdrom
4545
def rootfs
4646
find(&:rootfs?)
4747
end
48+
49+
def cloudinit
50+
find(&:cloud_init?)
51+
end
4852
end
4953
end
5054
end

lib/fog/proxmox/compute/models/server_config.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ class ServerConfig < Fog::Model
6969
attribute :unprivileged
7070
attribute :interfaces
7171
attribute :disks
72+
attribute :ciuser
73+
attribute :cipassword
74+
attribute :cicustom
75+
attribute :citype
76+
attribute :ipconfigs
77+
attribute :sshkeys
78+
attribute :searchdomain
79+
attribute :nameserver
7280

7381
def initialize(new_attributes = {})
7482
prepare_service_value(new_attributes)

lib/fog/proxmox/helpers/disk_helper.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ module Fog
2323
module Proxmox
2424
# module Disk mixins
2525
module DiskHelper
26-
2726
DISKS_REGEXP = /^(scsi|sata|mp|rootfs|virtio|ide)(\d+){0,1}$/
2827
SERVER_DISK_REGEXP = /^(scsi|sata|virtio|ide)(\d+)$/
2928
MOUNT_POINT_REGEXP = /^(mp)(\d+)$/
3029
ROOTFS_REGEXP = /^(rootfs)$/
3130
CDROM_REGEXP = /^(.*)[,]{0,1}(media=cdrom)[,]{0,1}(.*)$/
3231
TEMPLATE_REGEXP = /^(.*)(base-)(.*)$/
32+
CLOUD_INIT_REGEXP = /^(.*)(cloudinit)(.*)$/
3333

34-
# Convert disk attributes hash into API Proxmox parameters string
34+
# Convert disk attributes hash into API Proxmox parameters string
3535
def self.flatten(disk)
3636
id = disk[:id]
3737
value = ''
@@ -161,6 +161,19 @@ def self.container_disk?(id)
161161
def self.template?(volid)
162162
TEMPLATE_REGEXP.match(volid) ? true : false
163163
end
164+
165+
def self.cloud_init?(volid)
166+
CLOUD_INIT_REGEXP.match(volid) ? true : false
167+
end
168+
169+
def self.of_type?(disk_h, vm_type)
170+
id = disk_h['id'] if disk_h.key?('id')
171+
id = disk_h[:id] if disk_h.key?(:id)
172+
result = false
173+
result = server_disk?(id) if vm_type == 'qemu'
174+
result = container_disk?(id) if vm_type == 'lxc'
175+
result
176+
end
164177
end
165178
end
166179
end

0 commit comments

Comments
 (0)