This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
physical_volume.go
90 lines (74 loc) · 2.07 KB
/
physical_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
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
package main
import (
"fmt"
"strings"
)
// PhysicalVolume represents the PV inside a VolumeGroup
type PhysicalVolume struct {
// Name is the name of the physical volume - swraid or partition really
Name string `json:"name"`
// Size is the current size of the physical volume
Size string `json:"size"`
// UUID is the physical volume identifier
UUID string `json:"uuid"`
parentPath string
}
// PhysicalVolumes is a list of PhysicalVolume
type PhysicalVolumes []*PhysicalVolume
// toCompList converts a list of PhysicalVolume to a list of Comparator
func (pvs PhysicalVolumes) toCompList() []Comparator {
ns := []Comparator{}
for _, pv := range pvs {
ns = append(ns, pv)
}
return ns
}
// ToPhysicalVolumeList converts a list of Comparator to a list of PhysicalVolume
func ToPhysicalVolumeList(src []Comparator, err error) (PhysicalVolumes, error) {
if err != nil {
return nil, err
}
pvs := PhysicalVolumes{}
for _, s := range src {
pvs = append(pvs, s.(*PhysicalVolume))
}
return pvs, nil
}
// Equal tests identity equivalence between two objects.
func (pv *PhysicalVolume) Equal(c Comparator) bool {
npv := c.(*PhysicalVolume)
return pv.Name == npv.Name
}
// Merge the actual values of the comparator into the PhysicalVolume
func (pv *PhysicalVolume) Merge(c Comparator) error {
npv := c.(*PhysicalVolume)
pv.Size = npv.Size
return nil
}
//
// Validate an PhysicalVolume object.
//
func (pv *PhysicalVolume) Validate() error {
out := []string{}
if len(out) > 0 {
return fmt.Errorf(strings.Join(out, "\n"))
}
return nil
}
// Action applies the configution object to the actual object.
func (pv *PhysicalVolume) Action(npv *PhysicalVolume) (Result, error) {
dmsg(DbgAction|DbgPv, "PV Action: %v %v\n", pv, npv)
// This is a create
if pv.Name == "" {
pv.Name = npv.Name
npv.parentPath = pv.parentPath
out, err := runCommand("pvcreate", pv.parentPath)
dmsg(DbgAction|DbgPv, "pvcreate: %s\n%v\n", string(out), err)
if err != nil {
return ResultFailed, err
}
return ResultRescan, nil
}
// Already in place. Do nothing.
return ResultSuccess, nil
}