forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux_cdrom.go
58 lines (50 loc) · 1.44 KB
/
linux_cdrom.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
package cdrom
import (
boshudev "github.com/cloudfoundry/bosh-agent/platform/udevdevice"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshsys "github.com/cloudfoundry/bosh-utils/system"
)
type LinuxCdrom struct {
udev boshudev.UdevDevice
devicePath string
runner boshsys.CmdRunner
}
func NewLinuxCdrom(devicePath string, udev boshudev.UdevDevice, runner boshsys.CmdRunner) (cdrom LinuxCdrom) {
cdrom = LinuxCdrom{
udev: udev,
devicePath: devicePath,
runner: runner,
}
return
}
func (cdrom LinuxCdrom) WaitForMedia() (err error) {
cdrom.udev.KickDevice("/dev/sr0")
err = cdrom.udev.Settle()
if err != nil {
err = bosherr.WrapError(err, "Waiting for udev to settle")
return
}
err = cdrom.udev.EnsureDeviceReadable(cdrom.devicePath)
return
}
func (cdrom LinuxCdrom) Mount(mountPath string) (err error) {
_, stderr, _, err := cdrom.runner.RunCommand("mount", cdrom.devicePath, mountPath)
if err != nil {
err = bosherr.WrapErrorf(err, "Mounting CDROM: %s", stderr)
}
return
}
func (cdrom LinuxCdrom) Unmount() (err error) {
_, stderr, _, err := cdrom.runner.RunCommand("umount", cdrom.devicePath)
if err != nil {
err = bosherr.WrapErrorf(err, "Unmounting CDROM: %s", stderr)
}
return
}
func (cdrom LinuxCdrom) Eject() (err error) {
_, stderr, _, err := cdrom.runner.RunCommand("eject", "-v", cdrom.devicePath)
if err != nil {
err = bosherr.WrapErrorf(err, "Ejecting CDROM: %s", stderr)
}
return
}