~nskaggs/+junk/juju-packaging-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/govmomi/govc/device/floppy/insert.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-27 20:23:11 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161027202311-sux4jk2o73p1d6rg
Re-add src

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 2014 VMware, Inc. All Rights Reserved.
 
3
 
 
4
Licensed under the Apache License, Version 2.0 (the "License");
 
5
you may not use this file except in compliance with the License.
 
6
You may obtain a copy of the License at
 
7
 
 
8
    http://www.apache.org/licenses/LICENSE-2.0
 
9
 
 
10
Unless required by applicable law or agreed to in writing, software
 
11
distributed under the License is distributed on an "AS IS" BASIS,
 
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
See the License for the specific language governing permissions and
 
14
limitations under the License.
 
15
*/
 
16
 
 
17
package floppy
 
18
 
 
19
import (
 
20
        "flag"
 
21
 
 
22
        "github.com/juju/govmomi/govc/cli"
 
23
        "github.com/juju/govmomi/govc/flags"
 
24
        "golang.org/x/net/context"
 
25
)
 
26
 
 
27
type insert struct {
 
28
        *flags.DatastoreFlag
 
29
        *flags.VirtualMachineFlag
 
30
 
 
31
        device string
 
32
}
 
33
 
 
34
func init() {
 
35
        cli.Register("device.floppy.insert", &insert{})
 
36
}
 
37
 
 
38
func (cmd *insert) Register(f *flag.FlagSet) {
 
39
        f.StringVar(&cmd.device, "device", "", "Floppy device name")
 
40
}
 
41
 
 
42
func (cmd *insert) Process() error { return nil }
 
43
 
 
44
func (cmd *insert) Usage() string {
 
45
        return "IMG"
 
46
}
 
47
 
 
48
func (cmd *insert) Description() string {
 
49
        return `Insert image on datastore into floppy device.
 
50
 
 
51
If device is not specified, the first floppy device is used.`
 
52
}
 
53
 
 
54
func (cmd *insert) Run(f *flag.FlagSet) error {
 
55
        vm, err := cmd.VirtualMachine()
 
56
        if err != nil {
 
57
                return err
 
58
        }
 
59
 
 
60
        if vm == nil || f.NArg() != 1 {
 
61
                return flag.ErrHelp
 
62
        }
 
63
 
 
64
        devices, err := vm.Device(context.TODO())
 
65
        if err != nil {
 
66
                return err
 
67
        }
 
68
 
 
69
        c, err := devices.FindFloppy(cmd.device)
 
70
        if err != nil {
 
71
                return err
 
72
        }
 
73
 
 
74
        img, err := cmd.DatastorePath(f.Arg(0))
 
75
        if err != nil {
 
76
                return nil
 
77
        }
 
78
 
 
79
        return vm.EditDevice(context.TODO(), devices.InsertImg(c, img))
 
80
}