Puppet Plan: patching::snapshot_kvm

Defined in:
plans/snapshot_kvm.pp

Summary

Creates or deletes VM snapshots on targets in KVM/Libvirt.

Overview

Runs commands on the CLI of the KVM/Libvirt hypervisor host.

Parameters:

  • targets (TargetSpec)

    Set of targets to run against.

  • action (Enum['create', 'delete'])

    What action to perform on the snapshots:

    - `create` creates a new snapshot
    - 'delete' deletes snapshots by matching the `snapshot_name` passed in.
    
  • target_name_property (Optional[Enum['hostname', 'name', 'uri']]) (defaults to: undef)

    Determines what property on the Target object will be used as the VM name when mapping the Target to a VM in vSphere.

    - `uri` : use the `uri` property on the Target. This is preferred because
       If you specify a list of Targets in the inventory file, the value shown in that
       list is set as the `uri` and not the `name`, in this case `name` will be `undef`.
    - `name` : use the `name` property on the Target, this is not preferred because
       `name` is usually a short name or nickname.
    - `hostname`: use the `hostname` value to use host component of `uri` property on the Target
      this can be useful if VM name doesn't include domain name
    
  • snapshot_name (Optional[String[1]]) (defaults to: undef)

    Name of the snapshot

  • snapshot_description (Optional[String]) (defaults to: undef)

    Description of the snapshot

  • snapshot_memory (Optional[Boolean]) (defaults to: undef)

    Capture the VMs memory in the snapshot

  • snapshot_quiesce (Optional[Boolean]) (defaults to: undef)

    Quiesce/flush the filesystem when snapshotting the VM. This requires VMware tools be installed in the guest OS to work properly.

  • hypervisor_targets (Optional[TargetSpec]) (defaults to: undef)

    Name or reference to the targets of the KVM hypervisors. We will login to this host an run the snapshot tasks so that the local CLI can be used. Default target name is “kvm_hypervisors”, this can be a group of targets too!

  • noop (Boolean) (defaults to: false)

    Flag to enable noop mode. When noop mode is enabled no snapshots will be created or deleted.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'plans/snapshot_kvm.pp', line 47

plan patching::snapshot_kvm (
  TargetSpec $targets,
  Enum['create', 'delete'] $action,
  Optional[Enum['hostname', 'name', 'uri']] $target_name_property = undef,
  Optional[String[1]] $snapshot_name      = undef,
  Optional[String] $snapshot_description  = undef,
  Optional[Boolean] $snapshot_memory      = undef,
  Optional[Boolean] $snapshot_quiesce     = undef,
  Optional[TargetSpec] $hypervisor_targets = undef,
  Boolean $noop                 = false,
) {
  $_targets = run_plan('patching::get_targets', $targets)
  $group_vars = $_targets[0].vars
  # Order: CLI > Config > Default
  $_target_name_property = pick($target_name_property,
                                $group_vars['patching_snapshot_target_name_property'],
                                'uri')
  $_snapshot_name = pick($snapshot_name,
                          $group_vars['patching_snapshot_name'],
                          'Bolt Patching Snapshot')
  $_snapshot_description = pick_default($snapshot_description,
                                        $group_vars['patching_snapshot_description'],
                                        'Bolt Patching Snapshot')
  $_snapshot_memory = pick($snapshot_memory,
                            $group_vars['patching_snapshot_memory'],
                            false)
  $_snapshot_quiesce = pick($snapshot_quiesce,
                            $group_vars['patching_snapshot_quiesce'],
                            false)
  $_hypervisor_targets = pick($hypervisor_targets,
                              $group_vars['patching_snapshot_kvm_hypervisor_targets'],
                              'kvm_hypervisors')

  # Create array of node names
  $vm_names = patching::target_names($_targets, $_target_name_property)

  # Display status message
  if $action == 'create' {
    out::message("Creating VM snapshot '${_snapshot_name}' for:")
    $vm_names.each |$n| {
      out::message(" + ${n}")
    }
  } else {
    out::message("Deleting VM snapshot '${_snapshot_name}' for:")
    $vm_names.each |$n| {
      out::message(" - ${n}")
    }
  }

  if !$noop {
    return(run_task('patching::snapshot_kvm', $_hypervisor_targets,
                    vm_names => $vm_names,
                    snapshot_name => $_snapshot_name,
                    snapshot_description => $_snapshot_description,
                    snapshot_memory => $_snapshot_memory,
                    snapshot_quiesce => $_snapshot_quiesce,
                    action => $action))
  }
}