Puppet Plan: patching::snapshot_vmware
- Defined in:
- plans/snapshot_vmware.pp
Summary
Creates or deletes VM snapshots on targets in VMware.Overview
Communicates to the vSphere API from the local Bolt control node using the [rbvmomi](github.com/vmware/rbvmomi) Ruby gem.
To install the rbvmomi gem on the bolt control node: “‘shell
/opt/puppetlabs/bolt/bin/gem install --user-install rbvmomi
“‘
TODO config variables
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'plans/snapshot_vmware.pp', line 65
plan patching::snapshot_vmware (
TargetSpec $targets,
Enum['create', 'delete'] $action,
Optional[Enum['hostname', 'name', 'uri']] $target_name_property = undef,
String[1] $vsphere_host = get_targets($targets)[0].vars['vsphere_host'],
String[1] $vsphere_username = get_targets($targets)[0].vars['vsphere_username'],
String[1] $vsphere_password = get_targets($targets)[0].vars['vsphere_password'],
String[1] $vsphere_datacenter = get_targets($targets)[0].vars['vsphere_datacenter'],
Boolean $vsphere_insecure = get_targets($targets)[0].vars['vsphere_insecure'],
Optional[String[1]] $snapshot_name = undef,
Optional[String] $snapshot_description = undef,
Optional[Boolean] $snapshot_memory = undef,
Optional[Boolean] $snapshot_quiesce = 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'],
'')
$_snapshot_memory = pick($snapshot_memory,
$group_vars['patching_snapshot_memory'],
false)
$_snapshot_quiesce = pick($snapshot_quiesce,
$group_vars['patching_snapshot_quiesce'],
true)
# 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 patching::snapshot_vmware($vm_names,
$_snapshot_name,
$vsphere_host,
$vsphere_username,
$vsphere_password,
$vsphere_datacenter,
$vsphere_insecure,
$_snapshot_description,
$_snapshot_memory,
$_snapshot_quiesce,
$action)
}
}
|