forked from bakins/zfs-flex-volume
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolume.go
48 lines (39 loc) · 905 Bytes
/
volume.go
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
package main
import (
"encoding/json"
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
)
var getVolumeNameCmd = &cobra.Command{
Use: "getvolumename <json options>",
Short: "Get a cluster wide unique volume name for the volume. ",
Run: runGetVolumeNameCmd,
}
func runGetVolumeNameCmd(cmd *cobra.Command, args []string) {
r := result{}
if len(args) < 1 {
r.emit(-2, cmd.Use)
return
}
var p params
if err := json.Unmarshal([]byte(args[0]), &p); err != nil {
r.emit(-1, fmt.Sprintf("unable to unmarshal json: %v", err))
return
}
if p.Dataset == "" {
r.emit(-2, "dataset is required")
return
}
hostname, err := os.Hostname()
if err != nil {
r.emit(-3, fmt.Sprintf("unable to determine node name: %v", err))
return
}
r.VolumeName = strings.Join([]string{hostname, getParent(), p.Dataset}, ":")
r.emit(0, "")
}
func init() {
rootCmd.AddCommand(getVolumeNameCmd)
}