forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.go
95 lines (74 loc) · 2.11 KB
/
manager.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
91
92
93
94
95
package disk
import (
"github.com/cloudfoundry/bosh-agent/platform/windows/powershell"
"github.com/cloudfoundry/bosh-utils/system"
)
//go:generate counterfeiter -o fakes/fake_windows_disk_formatter.go . WindowsDiskFormatter
type WindowsDiskFormatter interface {
Format(diskNumber, partitionNumber string) error
}
//go:generate counterfeiter -o fakes/fake_windows_disk_linker.go . WindowsDiskLinker
type WindowsDiskLinker interface {
LinkTarget(location string) (target string, err error)
Link(location, target string) error
}
//go:generate counterfeiter -o fakes/fake_windows_disk_partitioner.go . WindowsDiskPartitioner
type WindowsDiskPartitioner interface {
GetCountOnDisk(diskNumber string) (string, error)
GetFreeSpaceOnDisk(diskNumber string) (int, error)
InitializeDisk(diskNumber string) error
PartitionDisk(diskNumber string) (string, error)
AssignDriveLetter(diskNumber, partitionNumber string) (string, error)
}
//go:generate counterfeiter -o fakes/fake_windows_disk_protector.go . WindowsDiskProtector
type WindowsDiskProtector interface {
CommandExists() bool
ProtectPath(path string) error
}
type Manager struct {
formatter WindowsDiskFormatter
linker WindowsDiskLinker
partitioner WindowsDiskPartitioner
protector WindowsDiskProtector
}
func NewWindowsDiskManager(cmdRunner system.CmdRunner) *Manager {
var runner system.CmdRunner
switch cmdRunner.(type) {
case *powershell.Runner:
runner = cmdRunner
default:
runner = &powershell.Runner{
BaseCmdRunner: cmdRunner,
}
}
formatter := &Formatter{
Runner: runner,
}
linker := &Linker{
Runner: runner,
}
partitioner := &Partitioner{
Runner: runner,
}
protector := &Protector{
Runner: runner,
}
return &Manager{
formatter: formatter,
linker: linker,
partitioner: partitioner,
protector: protector,
}
}
func (m *Manager) GetFormatter() WindowsDiskFormatter {
return m.formatter
}
func (m *Manager) GetLinker() WindowsDiskLinker {
return m.linker
}
func (m *Manager) GetPartitioner() WindowsDiskPartitioner {
return m.partitioner
}
func (m *Manager) GetProtector() WindowsDiskProtector {
return m.protector
}