-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional helper functions have proven useful to consumers when rendering templates with hardware data. The concrete use-case is formatting of partitions where nvme uses a different format to the historical block device.
- Loading branch information
1 parent
a0e9350
commit f8f1f8d
Showing
4 changed files
with
387 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package workflow | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// templateFuncs defines the custom functions available to workflow templates. | ||
var templateFuncs = map[string]interface{}{ | ||
"contains": strings.Contains, | ||
"hasPrefix": strings.HasPrefix, | ||
"hasSuffix": strings.HasSuffix, | ||
"formatPartition": formatPartition, | ||
} | ||
|
||
// formatPartition formats a device path with partition for the device type. If it receives an | ||
// unidentifiable device path it returns the dev. | ||
// | ||
// Examples | ||
// formatPartition("/dev/nvme0n1", 0) -> /dev/nvme0n1p1 | ||
// formatPartition("/dev/sda", 1) -> /dev/sda1 | ||
func formatPartition(dev string, partition int) string { | ||
switch { | ||
case strings.HasPrefix(dev, "/dev/nvme"): | ||
return fmt.Sprintf("%vp%v", dev, partition) | ||
case strings.HasPrefix(dev, "/dev/sd"): | ||
return fmt.Sprintf("%v%v", dev, partition) | ||
} | ||
return dev | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.