forked from buaazp/diskutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirtualDrive.go
81 lines (76 loc) · 2.12 KB
/
virtualDrive.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
package diskutil
import (
"encoding/json"
"errors"
"strings"
)
// VirtualDriveStat is a struct to get the Virtual Drive Stat of a RAID card.
type VirtualDriveStat struct {
VirtualDrive int `json:"virtual_drive"`
Name string `json:"name"`
Size string `json:"size"`
State string `json:"state"`
NumberOfDrives int `json:"number_of_drives"`
Encryptiontype string `json:"encryption_type"`
OsPath string `json:"os_path"`
}
// String() is used to get the print string.
func (v *VirtualDriveStat) String() string {
data, err := json.Marshal(v)
if err != nil {
return err.Error()
}
return string(data)
}
// ToJson() is used to get the json encoded string.
func (v *VirtualDriveStat) ToJson() (string, error) {
data, err := json.Marshal(v)
if err != nil {
return "", err
}
return string(data), nil
}
func (v *VirtualDriveStat) parseLine(line string) error {
if strings.HasPrefix(line, keyVdVirtualDrive) {
parts := strings.SplitN(line, "(", 2)
if len(parts) != 2 {
return errors.New("format illegal: " + line)
}
virtualDrive, err := parseFiled(parts[0], keyVdVirtualDrive, typeInt)
if err != nil {
return err
}
v.VirtualDrive = virtualDrive.(int)
} else if strings.HasPrefix(line, keyVdName) {
name, err := parseFiled(line, keyVdName, typeString)
if err != nil {
return err
}
v.Name = name.(string)
} else if strings.HasPrefix(line, keyVdSize) {
size, err := parseFiled(line, keyVdSize, typeString)
if err != nil {
return err
}
v.Size = size.(string)
} else if strings.HasPrefix(line, keyVdState) {
state, err := parseFiled(line, keyVdState, typeString)
if err != nil {
return err
}
v.State = state.(string)
} else if strings.HasPrefix(line, keyVdNumberOfDrives) {
numberOfDrives, err := parseFiled(line, keyVdNumberOfDrives, typeInt)
if err != nil {
return err
}
v.NumberOfDrives = numberOfDrives.(int)
} else if strings.HasPrefix(line, keyVdEncryptiontype) {
encryptiontype, err := parseFiled(line, keyVdEncryptiontype, typeString)
if err != nil {
return err
}
v.Encryptiontype = encryptiontype.(string)
}
return nil
}