gitee.com/leisunstar/runtime@v0.0.0-20200521203717-5cef3e7b53f9/virtcontainers/factory/direct/direct.go (about) 1 // Copyright (c) 2018 HyperHQ Inc. 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 // direct implements base vm factory without vm templating. 6 7 package direct 8 9 import ( 10 "context" 11 12 pb "github.com/kata-containers/runtime/protocols/cache" 13 vc "github.com/kata-containers/runtime/virtcontainers" 14 "github.com/kata-containers/runtime/virtcontainers/factory/base" 15 ) 16 17 type direct struct { 18 config vc.VMConfig 19 } 20 21 // New returns a new direct vm factory. 22 func New(ctx context.Context, config vc.VMConfig) base.FactoryBase { 23 return &direct{config} 24 } 25 26 // Config returns the direct factory's configuration. 27 func (d *direct) Config() vc.VMConfig { 28 return d.config 29 } 30 31 // GetBaseVM create a new VM directly. 32 func (d *direct) GetBaseVM(ctx context.Context, config vc.VMConfig) (*vc.VM, error) { 33 vm, err := vc.NewVM(ctx, config) 34 if err != nil { 35 return nil, err 36 } 37 38 err = vm.Pause() 39 if err != nil { 40 vm.Stop() 41 return nil, err 42 } 43 44 return vm, nil 45 } 46 47 // CloseFactory closes the direct vm factory. 48 func (d *direct) CloseFactory(ctx context.Context) { 49 } 50 51 // GetVMStatus is not supported 52 func (d *direct) GetVMStatus() []*pb.GrpcVMStatus { 53 panic("ERROR: package direct does not support GetVMStatus") 54 }