~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/govmomi/govc/vm/guest/start.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

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 guest
 
18
 
 
19
import (
 
20
        "flag"
 
21
        "fmt"
 
22
        "strings"
 
23
 
 
24
        "github.com/juju/govmomi/govc/cli"
 
25
        "github.com/juju/govmomi/vim25/types"
 
26
        "golang.org/x/net/context"
 
27
)
 
28
 
 
29
type start struct {
 
30
        *GuestFlag
 
31
 
 
32
        dir  string
 
33
        vars env
 
34
}
 
35
 
 
36
type env []string
 
37
 
 
38
func (e *env) String() string {
 
39
        return fmt.Sprint(*e)
 
40
}
 
41
 
 
42
func (e *env) Set(value string) error {
 
43
        *e = append(*e, value)
 
44
        return nil
 
45
}
 
46
 
 
47
func init() {
 
48
        cli.Register("guest.start", &start{})
 
49
}
 
50
 
 
51
func (cmd *start) Register(f *flag.FlagSet) {
 
52
        f.StringVar(&cmd.dir, "C", "", "The absolute path of the working directory for the program to start")
 
53
        f.Var(&cmd.vars, "e", "Set environment variable (key=val)")
 
54
}
 
55
 
 
56
func (cmd *start) Process() error { return nil }
 
57
 
 
58
func (cmd *start) Run(f *flag.FlagSet) error {
 
59
        m, err := cmd.ProcessManager()
 
60
        if err != nil {
 
61
                return err
 
62
        }
 
63
 
 
64
        spec := types.GuestProgramSpec{
 
65
                ProgramPath:      f.Arg(0),
 
66
                Arguments:        strings.Join(f.Args()[1:], " "),
 
67
                WorkingDirectory: cmd.dir,
 
68
                EnvVariables:     cmd.vars,
 
69
        }
 
70
 
 
71
        pid, err := m.StartProgram(context.TODO(), cmd.Auth(), &spec)
 
72
        if err != nil {
 
73
                return err
 
74
        }
 
75
 
 
76
        fmt.Printf("%d\n", pid)
 
77
 
 
78
        return nil
 
79
}