Class: PVE::CTTemplate::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/pve/templates.rb

Direct Known Subclasses

Datacenter, Default

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**opts) ⇒ Base

Returns a new instance of Base.



7
8
9
10
# File 'lib/pve/templates.rb', line 7

def initialize **opts
  @options = OpenStruct.new opts
  @virts = Proxmox::LXC.all + Proxmox::Qemu.all
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/pve/templates.rb', line 5

def options
  @options
end

Instance Method Details

#_ipv4(ip, gw) ⇒ Object



30
31
32
33
34
# File 'lib/pve/templates.rb', line 30

def _ipv4 ip, gw
  return [ip, nil]  if %w[dhcp].include? ip
  ip = IPAddress::IPv4.new ip
  [ip.to_string, gw || ip.hosts.last.to_s]
end

#_ipv6(ip, gw) ⇒ Object



36
37
38
39
40
# File 'lib/pve/templates.rb', line 36

def _ipv6 ip, gw
  return [ip, nil]  if %w[dhcp auto].include? ip
  ip = IPAddress::IPv6.new ip
  [ip.to_string, gw || ip.hosts.last.to_s]
end

#archObject



14
# File 'lib/pve/templates.rb', line 14

def arch() options.arch || 'amd64' end

#cmodeObject



17
# File 'lib/pve/templates.rb', line 17

def cmode() options.cmode || 'shell' end

#coresObject



18
# File 'lib/pve/templates.rb', line 18

def cores() options.cores || 1 end

#descriptionObject



19
# File 'lib/pve/templates.rb', line 19

def description() options.description || '' end

#hostnameObject



20
# File 'lib/pve/templates.rb', line 20

def hostname() options.hostname || name end

#memoryObject



21
# File 'lib/pve/templates.rb', line 21

def memory() options.memory || 1024 end

#nameObject



12
# File 'lib/pve/templates.rb', line 12

def name() options.name end

#net0Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pve/templates.rb', line 42

def net0()
  if options.ipv4 || options.ipv6
    ipv4, gw4 = _ipv4( options.ipv4, options.gateway4)
    ipv6, gw6 = _ipv6( options.ipv6, options.gateway6)
    {
      name: 'eth0',
      bridge: 'vmbr1',
      ip: ipv4, ip6: ipv6,
      gw: gw4, gw6: gw6,
    }
  end
end

#net1Object



54
# File 'lib/pve/templates.rb', line 54

def net1() nil end

#net2Object



55
# File 'lib/pve/templates.rb', line 55

def net2() nil end

#net3Object



56
# File 'lib/pve/templates.rb', line 56

def net3() nil end

#nodeObject



13
# File 'lib/pve/templates.rb', line 13

def node() options.node end

#ostypeObject



16
# File 'lib/pve/templates.rb', line 16

def ostype() options.ostype end

#ssh_public_keysObject



25
26
27
28
# File 'lib/pve/templates.rb', line 25

def ssh_public_keys
  options[:'ssh-public-keys'] ||
    File.read( options[:'ssh-public-keys-file'] || '/root/.ssh/authorized_keys')
end

#swapObject



22
# File 'lib/pve/templates.rb', line 22

def swap() options.swap || 0 end

#unprivilegedObject



23
# File 'lib/pve/templates.rb', line 23

def unprivileged() options.unprivileged() || 1 end

#vmidObject



15
# File 'lib/pve/templates.rb', line 15

def vmid() options.vmid end