Files
kata-containers/vendor/github.com/intel/govmm/qemu/image.go
Sebastien Boeuf 018c8c1468 vendor: Update govmm vendoring
Shortlog:

f9b31c0 qemu: Allow disable-modern option from QMP
d617307 Run tests for the s390x build
b36b5a8 Contributors: Add Clare Chen to CONTRIBUTORS.md
b41939c Contributors: Add my name
dab4cf1 qmp: Add tests
5ea6da1 Verify govmm builds on s390x
ee75813 contributors: add my name
c80fc3b qemu: Add s390x support
ca477a1 Update source file headers
e68e005 Update the CONTRIBUTING.md
2b7db54 Add the CONTRIBUTORS.md file
b3b765c qemu: test Valid for Vsock for Context ID
3becff5 qemu: change of ContextID from uint32 to uint64
f30fd13 qmp: Output error detail when execute QMP command failed
7da6a4c qmp: fix mem-path properties for hotplug memory.
e4892e3 qemu/qmp: preparation for s390x support
110d2fa qemu/qmp: add new function ExecuteBlockdevAddWithCache
a0b0c86 qmp_test: Change QMP version from 2.6 to 2.9
10c36a1 qemu: add support for pidfile option

Fixes #983

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2018-12-06 00:13:15 -08:00

78 lines
2.6 KiB
Go

/*
// Copyright contributors to the Virtual Machine Manager for Go project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
package qemu
import (
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
"syscall"
)
// CreateCloudInitISO creates a cloud-init ConfigDrive ISO image. This is
// useful for configuring newly booted VMs. Before it can create the ISO
// image it needs to create a file tree with the various files that will
// make up the image. This directory is created under scratchDir and is
// deleted when when the function returns, successfully or otherwise. ctx is
// a context that can be used to timeout or cancel the image creation.
// isoPath contains the desired path of the ISO image to be created. The
// userdata and metadata parameters are byte slices that contain the
// ConfigDrive userdata and metadata that will be stored with the ISO image.
// The attrs parameter can be used to control aspects of the newly created
// qemu process, such as the user and group under which it runs. It may be nil.
func CreateCloudInitISO(ctx context.Context, scratchDir, isoPath string,
userData, metaData []byte, attr *syscall.SysProcAttr) error {
configDrivePath := path.Join(scratchDir, "clr-cloud-init")
dataDirPath := path.Join(configDrivePath, "openstack", "latest")
metaDataPath := path.Join(dataDirPath, "meta_data.json")
userDataPath := path.Join(dataDirPath, "user_data")
defer func() {
/* #nosec */
_ = os.RemoveAll(configDrivePath)
}()
err := os.MkdirAll(dataDirPath, 0750)
if err != nil {
return fmt.Errorf("Unable to create config drive directory %s : %v",
dataDirPath, err)
}
err = ioutil.WriteFile(metaDataPath, metaData, 0644)
if err != nil {
return fmt.Errorf("Unable to create %s : %v", metaDataPath, err)
}
err = ioutil.WriteFile(userDataPath, userData, 0644)
if err != nil {
return fmt.Errorf("Unable to create %s : %v", userDataPath, err)
}
cmd := exec.CommandContext(ctx, "xorriso", "-as", "mkisofs", "-R", "-V", "config-2",
"-o", isoPath, configDrivePath)
cmd.SysProcAttr = attr
err = cmd.Run()
if err != nil {
return fmt.Errorf("Unable to create cloudinit iso image %v", err)
}
return nil
}