2
* Copyright (C) 2016 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Author: Benjamin Zeller <benjamin.zeller@canonical.com>
22
"launchpad.net/ubuntu-sdk-tools"
25
"github.com/lxc/lxd/shared"
28
type DevicesFixable struct { }
30
func (*DevicesFixable) run(client *lxd.Client, container *shared.ContainerInfo, doFix bool) error {
32
for devName, dev := range container.Devices {
33
var toCheck string = ""
36
toCheck,_ = dev["source"]
38
_, hasMaj := dev["major"]
39
_, hasMin := dev["minor"]
40
optional, hasOptional := dev["optional"]
42
//do not care about optional devices
43
if (hasOptional && optional == "true") {
47
if !(hasMaj && hasMin) {
48
toCheck = fmt.Sprintf("/%s", dev["path"])
53
if _, err := os.Stat(toCheck); os.IsNotExist(err) {
55
err = ubuntu_sdk_tools.RemoveDeviceSync(client, container.Name, devName)
60
return fmt.Errorf("Device %s does not exist on the host.", toCheck)
68
func (c *DevicesFixable) CheckContainer(client *lxd.Client, container string) error {
69
info, err := client.ContainerInfo(container)
74
return c.run(client, info, false)
77
func (c *DevicesFixable) FixContainer(client *lxd.Client, container string) error {
78
info, err := client.ContainerInfo(container)
83
return c.run(client, info, true)
86
func (c *DevicesFixable) Check(client *lxd.Client) error {
87
fmt.Printf("Checking for broken devices...\n")
89
targets, err := ubuntu_sdk_tools.FindClickTargets(client)
94
for _, target := range targets {
95
err = c.run(client, &target.Container, false)
102
func (c *DevicesFixable) Fix(client *lxd.Client) error {
103
fmt.Println("Checking for and removing broken devices....")
104
targets, err := ubuntu_sdk_tools.FindClickTargets(client)
109
for _, target := range targets {
110
err = c.run(client, &target.Container, true)
118
func (*DevicesFixable) NeedsRoot () bool {
b'\\ No newline at end of file'