-
Notifications
You must be signed in to change notification settings - Fork 36
/
filesystem.go
69 lines (60 loc) · 1.87 KB
/
filesystem.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
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package gomaasapi
import "github.com/juju/schema"
type filesystem struct {
fstype string
mountPoint string
label string
uuid string
// no idea what the mount_options are as a value type, so ignoring for now.
}
// Type implements FileSystem.
func (f *filesystem) Type() string {
return f.fstype
}
// MountPoint implements FileSystem.
func (f *filesystem) MountPoint() string {
return f.mountPoint
}
// Label implements FileSystem.
func (f *filesystem) Label() string {
return f.label
}
// UUID implements FileSystem.
func (f *filesystem) UUID() string {
return f.uuid
}
// There is no need for controller based parsing of filesystems until we need it.
// Currently the filesystem reading is only called by the Partition parsing.
func filesystem2_0(source map[string]interface{}) (*filesystem, error) {
fields := schema.Fields{
"fstype": schema.String(),
"mount_point": schema.OneOf(schema.Nil(""), schema.String()),
"label": schema.OneOf(schema.Nil(""), schema.String()),
"uuid": schema.String(),
// TODO: mount_options when we know the type (note it can be
// nil).
}
defaults := schema.Defaults{
"mount_point": "",
"label": "",
}
checker := schema.FieldMap(fields, defaults)
coerced, err := checker.Coerce(source, nil)
if err != nil {
return nil, WrapWithDeserializationError(err, "filesystem 2.0 schema check failed")
}
valid := coerced.(map[string]interface{})
// From here we know that the map returned from the schema coercion
// contains fields of the right type.
mount_point, _ := valid["mount_point"].(string)
label, _ := valid["label"].(string)
result := &filesystem{
fstype: valid["fstype"].(string),
mountPoint: mount_point,
label: label,
uuid: valid["uuid"].(string),
}
return result, nil
}