aboutsummaryrefslogtreecommitdiff
path: root/manifests/kvm/kvmx/instance.pp
blob: ee1dac3f4dbb95cd9e933d04696bded802797855 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
define virtual::kvm::kvmx::instance(
  $vg,
  $size,
  $ram,
  $shell,
  $udev = false,
) {
  virtual::kvm::instance { $name:
    udev  => $udev,
    shell => $shell ? {
      undef   => '/usr/local/bin/kvmx-restricted-shell',
      default => $shell,
    },
  }

  exec { "kvmx-lvcreate-${name}":
    command => "/sbin/lvcreate --name ${name} --size ${size} ${vg}",
    user    => root,
    creates => "/dev/${vg}/${name}",
    #onlyif  => "test ! -e /dev/${vg}/${name}"
  }

  exec { "kvmx-init-${name}":
    command     => "/usr/local/bin/kvmx init",
    user        => $name,
    environment => [ "HOME=/home/${name}" ],
    cwd         => "/home/${name}/vms/${name}",
    creates     => "/home/${name}/vms/${name}/kvmxfile",
    require     => Virtual::Kvm::Instance["$name"],
  }

  exec { "kvmx-config-${name}-ram":
    #command    => "/usr/local/bin/kvmx $name config memory ${ram}",
    command     => "/usr/local/bin/kvmx config memory ${ram}",
    user        => $name,
    environment => [ "HOME=/home/${name}" ],
    cwd         => "/home/${name}/vms/${name}",
    #onlyif     => "/usr/local/bin/kvmx config ${name} memory | grep -v memory=\"${ram}\"",
    onlyif      => "/usr/local/bin/kvmx config ${name} memory | grep -v ^${ram}",
    require     => Exec["kvmx-init-${name}"],
  }

  exec { "kvmx-config-${name}-size":
    #command    => "/usr/local/bin/kvmx ${name} config size ${size}",
    command     => "/usr/local/bin/kvmx config size ${size}",
    user        => $name,
    environment => [ "HOME=/home/${name}" ],
    cwd         => "/home/${name}/vms/${name}",
    #onlyif     => "/usr/local/bin/kvmx config ${name} size | grep -v memory=\"${size}\"",
    onlyif      => "/usr/local/bin/kvmx config ${name} size | grep -v ^${size}",
    require     => Exec["kvmx-init-${name}"],
  }
}