github.com/coreos/mantle@v0.13.0/platform/machine/unprivqemu/flight.go (about) 1 // Copyright 2019 Red Hat 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package unprivqemu 16 17 import ( 18 "os" 19 20 "github.com/coreos/pkg/capnslog" 21 22 "github.com/coreos/mantle/platform" 23 "github.com/coreos/mantle/platform/machine/qemu" 24 ) 25 26 const ( 27 Platform platform.Name = "qemu" 28 ) 29 30 type flight struct { 31 *platform.BaseFlight 32 opts *qemu.Options 33 34 diskImagePath string 35 diskImageFile *os.File 36 } 37 38 var ( 39 plog = capnslog.NewPackageLogger("github.com/coreos/mantle", "platform/machine/qemu") 40 ) 41 42 func NewFlight(opts *qemu.Options) (platform.Flight, error) { 43 bf, err := platform.NewBaseFlight(opts.Options, Platform, "") 44 if err != nil { 45 return nil, err 46 } 47 48 qf := &flight{ 49 BaseFlight: bf, 50 opts: opts, 51 diskImagePath: opts.DiskImage, 52 } 53 54 return qf, nil 55 } 56 57 // NewCluster creates a Cluster instance, suitable for running virtual 58 // machines in QEMU. 59 func (qf *flight) NewCluster(rconf *platform.RuntimeConfig) (platform.Cluster, error) { 60 bc, err := platform.NewBaseCluster(qf.BaseFlight, rconf) 61 if err != nil { 62 return nil, err 63 } 64 65 qc := &Cluster{ 66 BaseCluster: bc, 67 flight: qf, 68 } 69 70 qf.AddCluster(qc) 71 72 return qc, nil 73 } 74 75 func (qf *flight) Destroy() { 76 if qf.diskImageFile != nil { 77 qf.diskImageFile.Close() 78 } 79 }