Skip to content

Commit 6321f97

Browse files
committed
add hostname as a choice for patching::snapshot_vmware::target_name_property
it can be used in cases where target discovery uses fully qualified domain names and VM names don't have domain name component
1 parent 50a350e commit 6321f97

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ All notable changes to this project will be documented in this file.
88

99
Contributed by Michael Surato (@msurato)
1010

11+
* Add `hostname` as a choice for patching::snapshot_vmware::target_name_property
12+
It can be used in cases where target discovery uses fully qualified domain names
13+
and VM names don't have domain name component
14+
15+
Contributed by Vadym Chepkov (@vchepkov)
16+
1117
## Release 1.0.1 (2020-03-04)
1218

1319
* Ensure the `patching.json` file exists on Windows by creating a blank file if it was previously missing.

functions/target_names.pp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
# @param [TargetSpec] targets
44
# List of targets to extract the name from
55
#
6-
# @param [Enum['name', 'uri']] name_property
6+
# @param [Enum['hostname', 'name', 'uri']] name_property
77
# Property in the Target to use as the name
88
#
99
# @return [Array[String]] Array of names, one for each target
1010
function patching::target_names(
1111
TargetSpec $targets,
12-
Enum['name', 'uri'] $name_property,
12+
Enum['hostname', 'name', 'uri'] $name_property,
1313
) >> Array[String] {
1414
$targets.map |$n| {
1515
case $name_property {
16+
'hostname': {
17+
regsubst($n.uri, '^([^.]+).*','\1')
18+
}
1619
'name': {
1720
$n.name
1821
}

plans/snapshot_vmware.pp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# - `create` creates a new snapshot
2020
# - 'delete' deletes snapshots by matching the `snapshot_name` passed in.
2121
#
22-
# @param [Optional[Enum['name', 'uri']]] target_name_property
22+
# @param [Optional[Enum['hostname', 'name', 'uri']]] target_name_property
2323
# Determines what property on the Target object will be used as the VM name when
2424
# mapping the Target to a VM in vSphere.
2525
#
@@ -28,6 +28,8 @@
2828
# list is set as the `uri` and not the `name`, in this case `name` will be `undef`.
2929
# - `name` : use the `name` property on the Target, this is not preferred because
3030
# `name` is usually a short name or nickname.
31+
# - `hostname`: use the `hostname` value to use host component of `uri` property on the Target
32+
# this can be useful if VM name doesn't include domain name
3133
#
3234
# @param [String[1]] vsphere_host
3335
# Hostname of the vSphere server that we're going to use to create snapshots via the API.
@@ -63,7 +65,7 @@
6365
plan patching::snapshot_vmware (
6466
TargetSpec $targets,
6567
Enum['create', 'delete'] $action,
66-
Optional[Enum['name', 'uri']] $target_name_property = undef,
68+
Optional[Enum['hostname', 'name', 'uri']] $target_name_property = undef,
6769
String[1] $vsphere_host = get_targets($targets)[0].vars['vsphere_host'],
6870
String[1] $vsphere_username = get_targets($targets)[0].vars['vsphere_username'],
6971
String[1] $vsphere_password = get_targets($targets)[0].vars['vsphere_password'],

0 commit comments

Comments
 (0)