github.com/vmware/govmomi@v0.37.2/guest/process_manager.go (about)

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