~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/govmomi/guest/process_manager.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
        "github.com/juju/govmomi/vim25"
 
21
        "github.com/juju/govmomi/vim25/methods"
 
22
        "github.com/juju/govmomi/vim25/types"
 
23
        "golang.org/x/net/context"
 
24
)
 
25
 
 
26
type ProcessManager struct {
 
27
        types.ManagedObjectReference
 
28
 
 
29
        vm types.ManagedObjectReference
 
30
 
 
31
        c *vim25.Client
 
32
}
 
33
 
 
34
func (m ProcessManager) Reference() types.ManagedObjectReference {
 
35
        return m.ManagedObjectReference
 
36
}
 
37
 
 
38
func (m ProcessManager) ListProcesses(ctx context.Context, auth types.BaseGuestAuthentication, pids []int64) ([]types.GuestProcessInfo, error) {
 
39
        req := types.ListProcessesInGuest{
 
40
                This: m.Reference(),
 
41
                Vm:   m.vm,
 
42
                Auth: auth,
 
43
                Pids: pids,
 
44
        }
 
45
 
 
46
        res, err := methods.ListProcessesInGuest(ctx, m.c, &req)
 
47
        if err != nil {
 
48
                return nil, err
 
49
        }
 
50
 
 
51
        return res.Returnval, err
 
52
}
 
53
 
 
54
func (m ProcessManager) ReadEnvironmentVariable(ctx context.Context, auth types.BaseGuestAuthentication, names []string) ([]string, error) {
 
55
        req := types.ReadEnvironmentVariableInGuest{
 
56
                This:  m.Reference(),
 
57
                Vm:    m.vm,
 
58
                Auth:  auth,
 
59
                Names: names,
 
60
        }
 
61
 
 
62
        res, err := methods.ReadEnvironmentVariableInGuest(ctx, m.c, &req)
 
63
        if err != nil {
 
64
                return nil, err
 
65
        }
 
66
 
 
67
        return res.Returnval, err
 
68
}
 
69
 
 
70
func (m ProcessManager) StartProgram(ctx context.Context, auth types.BaseGuestAuthentication, spec types.BaseGuestProgramSpec) (int64, error) {
 
71
        req := types.StartProgramInGuest{
 
72
                This: m.Reference(),
 
73
                Vm:   m.vm,
 
74
                Auth: auth,
 
75
                Spec: spec,
 
76
        }
 
77
 
 
78
        res, err := methods.StartProgramInGuest(ctx, m.c, &req)
 
79
        if err != nil {
 
80
                return 0, err
 
81
        }
 
82
 
 
83
        return res.Returnval, err
 
84
}
 
85
 
 
86
func (m ProcessManager) TerminateProcess(ctx context.Context, auth types.BaseGuestAuthentication, pid int64) error {
 
87
        req := types.TerminateProcessInGuest{
 
88
                This: m.Reference(),
 
89
                Vm:   m.vm,
 
90
                Auth: auth,
 
91
                Pid:  pid,
 
92
        }
 
93
 
 
94
        _, err := methods.TerminateProcessInGuest(ctx, m.c, &req)
 
95
        return err
 
96
}