forked from cloudfoundry-attic/bosh-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummy_platform.go
198 lines (157 loc) · 5.15 KB
/
dummy_platform.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package platform
import (
"encoding/json"
"path/filepath"
bosherr "github.com/cloudfoundry/bosh-agent/errors"
boshdpresolv "github.com/cloudfoundry/bosh-agent/infrastructure/devicepathresolver"
boshlog "github.com/cloudfoundry/bosh-agent/logger"
boshcmd "github.com/cloudfoundry/bosh-agent/platform/commands"
boshstats "github.com/cloudfoundry/bosh-agent/platform/stats"
boshvitals "github.com/cloudfoundry/bosh-agent/platform/vitals"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
boshdir "github.com/cloudfoundry/bosh-agent/settings/directories"
boshdirs "github.com/cloudfoundry/bosh-agent/settings/directories"
boshsys "github.com/cloudfoundry/bosh-agent/system"
)
type dummyPlatform struct {
collector boshstats.Collector
fs boshsys.FileSystem
cmdRunner boshsys.CmdRunner
compressor boshcmd.Compressor
copier boshcmd.Copier
dirProvider boshdirs.Provider
vitalsService boshvitals.Service
devicePathResolver boshdpresolv.DevicePathResolver
logger boshlog.Logger
}
func NewDummyPlatform(
collector boshstats.Collector,
fs boshsys.FileSystem,
cmdRunner boshsys.CmdRunner,
dirProvider boshdirs.Provider,
devicePathResolver boshdpresolv.DevicePathResolver,
logger boshlog.Logger,
) Platform {
return &dummyPlatform{
fs: fs,
cmdRunner: cmdRunner,
collector: collector,
compressor: boshcmd.NewTarballCompressor(cmdRunner, fs),
copier: boshcmd.NewCpCopier(cmdRunner, fs, logger),
dirProvider: dirProvider,
devicePathResolver: devicePathResolver,
vitalsService: boshvitals.NewService(collector, dirProvider),
}
}
func (p dummyPlatform) GetFs() (fs boshsys.FileSystem) {
return p.fs
}
func (p dummyPlatform) GetRunner() (runner boshsys.CmdRunner) {
return p.cmdRunner
}
func (p dummyPlatform) GetCompressor() (compressor boshcmd.Compressor) {
return p.compressor
}
func (p dummyPlatform) GetCopier() (copier boshcmd.Copier) {
return p.copier
}
func (p dummyPlatform) GetDirProvider() (dirProvider boshdir.Provider) {
return p.dirProvider
}
func (p dummyPlatform) GetVitalsService() (service boshvitals.Service) {
return p.vitalsService
}
func (p dummyPlatform) GetDevicePathResolver() (devicePathResolver boshdpresolv.DevicePathResolver) {
return p.devicePathResolver
}
func (p dummyPlatform) SetupRuntimeConfiguration() (err error) {
return
}
func (p dummyPlatform) CreateUser(username, password, basePath string) (err error) {
return
}
func (p dummyPlatform) AddUserToGroups(username string, groups []string) (err error) {
return
}
func (p dummyPlatform) DeleteEphemeralUsersMatching(regex string) (err error) {
return
}
func (p dummyPlatform) SetupSSH(publicKey, username string) (err error) {
return
}
func (p dummyPlatform) SetUserPassword(user, encryptedPwd string) (err error) {
return
}
func (p dummyPlatform) SetupHostname(hostname string) (err error) {
return
}
func (p dummyPlatform) SetupNetworking(networks boshsettings.Networks) (err error) {
return
}
func (p dummyPlatform) GetConfiguredNetworkInterfaces() (interfaces []string, err error) {
return
}
func (p dummyPlatform) SetupLogrotate(groupName, basePath, size string) (err error) {
return
}
func (p dummyPlatform) SetTimeWithNtpServers(servers []string) (err error) {
return
}
func (p dummyPlatform) SetupEphemeralDiskWithPath(devicePath string) (err error) {
return
}
func (p dummyPlatform) SetupDataDir() error {
return nil
}
func (p dummyPlatform) SetupTmpDir() error {
return nil
}
func (p dummyPlatform) MountPersistentDisk(diskSettings boshsettings.DiskSettings, mountPoint string) (err error) {
return
}
func (p dummyPlatform) UnmountPersistentDisk(diskSettings boshsettings.DiskSettings) (didUnmount bool, err error) {
return
}
func (p dummyPlatform) GetEphemeralDiskPath(diskSettings boshsettings.DiskSettings) string {
return "/dev/sdb"
}
func (p dummyPlatform) GetFileContentsFromCDROM(filePath string) (contents []byte, err error) {
return
}
func (p dummyPlatform) GetFilesContentsFromDisk(diskPath string, fileNames []string) (contents [][]byte, err error) {
return
}
func (p dummyPlatform) MigratePersistentDisk(fromMountPoint, toMountPoint string) (err error) {
return
}
func (p dummyPlatform) IsMountPoint(path string) (result bool, err error) {
return
}
func (p dummyPlatform) IsPersistentDiskMounted(diskSettings boshsettings.DiskSettings) (bool, error) {
return true, nil
}
func (p dummyPlatform) StartMonit() (err error) {
return
}
func (p dummyPlatform) SetupMonitUser() (err error) {
return
}
func (p dummyPlatform) GetMonitCredentials() (username, password string, err error) {
return
}
func (p dummyPlatform) PrepareForNetworkingChange() error {
return nil
}
func (p dummyPlatform) GetDefaultNetwork() (boshsettings.Network, error) {
var network boshsettings.Network
networkPath := filepath.Join(p.dirProvider.BoshDir(), "dummy-default-network-settings.json")
contents, err := p.fs.ReadFile(networkPath)
if err != nil {
return network, nil
}
err = json.Unmarshal([]byte(contents), &network)
if err != nil {
return network, bosherr.WrapError(err, "Unmarshal json settings")
}
return network, nil
}