本文整理汇总了Golang中minilog.LogAll函数的典型用法代码示例。如果您正苦于以下问题:Golang LogAll函数的具体用法?Golang LogAll怎么用?Golang LogAll使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LogAll函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: formatQcow2
// formatQcow2 formats a partition with the default linux filesystem type.
func formatQcow2(dev string) error {
// make an ext4 filesystem
p := process("mkfs")
cmd := &exec.Cmd{
Path: p,
Args: []string{
p,
dev,
},
Env: nil,
Dir: "",
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
log.LogAll(stdout, log.INFO, "mkfs")
log.LogAll(stderr, log.INFO, "mkfs")
log.Debug("formatting with with cmd: %v", cmd)
return cmd.Run()
}
示例2: DisconnectDevice
// DisconnectDevice disconnects a given NBD using qemu-nbd.
func DisconnectDevice(dev string) error {
// disconnect nbd
p := process("qemu-nbd")
cmd := &exec.Cmd{
Path: p,
Args: []string{
p,
"-d",
dev,
},
Env: nil,
Dir: "",
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
log.LogAll(stdout, log.INFO, "qemu-nbd")
log.LogAll(stderr, log.ERROR, "qemu-nbd")
log.Debug("disconnecting nbd with cmd: %v", cmd)
return cmd.Run()
}
示例3: extlinuxMBR
// extlinuxMBR installs the specified master boot record in the partition table
// for the provided device.
func extlinuxMBR(dev, mbr string) error {
// dd the mbr image
p := process("dd")
cmd := &exec.Cmd{
Path: p,
Args: []string{
p,
fmt.Sprintf("if=%v", mbr),
"conv=notrunc",
"bs=440",
"count=1",
fmt.Sprintf("of=%v", dev),
},
Env: nil,
Dir: "",
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
log.LogAll(stdout, log.INFO, "dd")
log.LogAll(stderr, log.INFO, "dd")
log.Debug("installing mbr with cmd: %v", cmd)
return cmd.Run()
}
示例4: umountQcow2
// umountQcow2 unmounts qcow2 image that was previously mounted with
// mountQcow2.
func umountQcow2(path string) error {
// unmount
p := process("umount")
cmd := &exec.Cmd{
Path: p,
Args: []string{
p,
path,
},
Env: nil,
Dir: "",
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
log.LogAll(stdout, log.INFO, "umount")
log.LogAll(stderr, log.ERROR, "umount")
log.Debug("unmounting with cmd: %v", cmd)
return cmd.Run()
}
示例5: copyQcow2
// copyQcow2 recursively copies files from src to dst using cp.
func copyQcow2(src, dst string) error {
// copy everything over
p := process("cp")
cmd := &exec.Cmd{
Path: p,
Args: []string{
p,
"-a",
"-v",
src + "/.",
dst,
},
Env: nil,
Dir: "",
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
log.LogAll(stdout, log.INFO, "cp")
log.LogAll(stderr, log.ERROR, "cp")
log.Debug("copy with with cmd: %v", cmd)
return cmd.Run()
}
示例6: Debootstrap
// Debootstrap will invoke the debootstrap tool with a target build directory
// in build_path, using configuration from c.
func Debootstrap(buildPath string, c vmconfig.Config) error {
p := process("debootstrap")
// build debootstrap parameters
var args []string
args = append(args, "--variant=minbase")
args = append(args, fmt.Sprintf("--include=%v", strings.Join(c.Packages, ",")))
args = append(args, *f_branch)
args = append(args, buildPath)
args = append(args, *f_debian_mirror)
log.Debugln("args:", args)
cmd := exec.Command(p, args...)
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
log.LogAll(stdout, log.INFO, "debootstrap")
log.LogAll(stderr, log.ERROR, "debootstrap")
err = cmd.Run()
if err != nil {
return err
}
return nil
}
示例7: PostBuildCommands
// PostBuildCommands invokes any commands listed in the postbuild variable
// of a config file. It does so by copying the entire string of the postbuild
// variable into a bash script under /tmp of the build directory, and then
// executing it with bash inside of a chroot. Post build commands are executed
// in depth-first order.
func PostBuildCommands(buildPath string, c vmconfig.Config) error {
for _, pb := range c.Postbuilds {
log.Debugln("postbuild:", pb)
tmpfile := buildPath + "/tmp/postbuild.bash"
ioutil.WriteFile(tmpfile, []byte(pb), 0770)
p := process("chroot")
cmd := exec.Command(p, buildPath, "/bin/bash", "/tmp/postbuild.bash")
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
log.LogAll(stdout, log.INFO, "postbuild")
log.LogAll(stderr, log.ERROR, "postbuild")
err = cmd.Run()
if err != nil {
return err
}
os.Remove(tmpfile)
}
return nil
}
示例8: createQcow2
// createQcow2 creates a target qcow2 image using qemu-img. Size specifies the
// size of the image in bytes but optional suffixes such as "K" and "G" can be
// used. See qemu-img(8) for details.
func createQcow2(target, size string) error {
// create our qcow image
p := process("qemu-img")
cmd := &exec.Cmd{
Path: p,
Args: []string{
p,
"create",
"-f",
"qcow2",
target,
size,
},
Env: nil,
Dir: "",
}
log.Debug("creating disk image with cmd: %v", cmd)
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
log.LogAll(stdout, log.INFO, "qemu-img")
log.LogAll(stderr, log.ERROR, "qemu-img")
return cmd.Run()
}
示例9: BuildRootFS
// BuildRootFS generates simple rootfs a from the stage 1 directory.
func BuildRootFS(buildPath string, c vmconfig.Config) error {
targetName := strings.Split(filepath.Base(c.Path), ".")[0] + "_rootfs"
log.Debugln("using target name:", targetName)
err := os.Mkdir(targetName, 0666)
if err != nil {
return err
}
p := process("cp")
cmd := exec.Command(p, "-r", "-v", buildPath+"/.", targetName)
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
log.LogAll(stdout, log.INFO, "cp")
log.LogAll(stderr, log.ERROR, "cp")
err = cmd.Run()
if err != nil {
return err
}
return nil
}
示例10: transcode
func transcode(in, out string) error {
p := "ffmpeg"
var args []string
args = append(args, "-f")
args = append(args, "mjpeg")
args = append(args, "-r")
args = append(args, "10") // minimega uses 10 frames per second
args = append(args, "-i")
args = append(args, fmt.Sprintf("http://localhost:%v/%v", *f_port, in))
args = append(args, out)
log.Debugln("args:", args)
cmd := exec.Command(p, args...)
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
log.LogAll(stdout, log.INFO, "ffmpeg")
log.LogAll(stderr, log.INFO, "ffmpeg")
err = cmd.Run()
if err != nil {
return err
}
return nil
}
示例11: ConnectImage
// ConnectImage exports a image using the NBD protocol using the qemu-nbd. If
// successful, returns the NBD device.
func ConnectImage(image string) (string, error) {
var nbdPath string
var err error
for i := 0; i < maxConnectRetries; i++ {
nbdPath, err = GetDevice()
if err != ErrNoDeviceAvailable {
break
}
log.Debug("all nbds in use, sleeping before retrying")
time.Sleep(time.Second * 10)
}
if err != nil {
return "", err
}
// connect it to qemu-nbd
p := process("qemu-nbd")
cmd := &exec.Cmd{
Path: p,
Args: []string{
p,
"-c",
nbdPath,
image,
},
Env: nil,
Dir: "",
}
log.Debug("connecting to nbd with cmd: %v", cmd)
stdout, err := cmd.StdoutPipe()
if err != nil {
return "", err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return "", err
}
log.LogAll(stdout, log.INFO, "qemu-nbd")
log.LogAll(stderr, log.ERROR, "qemu-nbd")
err = cmd.Run()
if err != nil {
return "", err
}
return nbdPath, nil
}
示例12: Overlays
// Overlays copies any overlay directories indicated in c into the build
// directory build_path. Overlays are copied in depth-first order, so that
// the oldest parent overlay data is copied in first. This allows a child
// to overwrite any overlay data created by a parent.
func Overlays(buildPath string, c vmconfig.Config) error {
// copy the overlays in order
for i, o := range c.Overlays {
log.Infoln("copying overlay:", o)
var sourcePath string
// check if overlay exists as absolute path or relative to cwd
if _, err := os.Stat(o); os.IsNotExist(err) {
// it doesn't, so we'll check relative to config file
log.Debugln("overlay directory '%v' does not exist as an absolute path or relative to the current working directory.", o)
var path string
base := filepath.Base(o) // get base path of overlay directory
if i == len(c.Overlays)-1 { // if this is the last overlay, we'll check relative to c.Path
log.Debugln("non-parent overlay")
path = filepath.Join(filepath.Dir(c.Path), base)
} else { // if not, it's a parent overlay and we'll check relative to c.Parents[i]
log.Debugln("parent overlay")
path = filepath.Join(filepath.Dir(c.Parents[i]), base)
}
log.Debugln("checking path relative to config location: '%v'", path)
if _, err := os.Stat(path); os.IsNotExist(err) { // check if we can find overlay relative to config file
return err // nope
} else { // yep
sourcePath = path
}
} else {
sourcePath = o
}
p := process("cp")
cmd := exec.Command(p, "-r", "-v", sourcePath+"/.", buildPath)
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
log.LogAll(stdout, log.INFO, "cp")
log.LogAll(stderr, log.ERROR, "cp")
err = cmd.Run()
if err != nil {
return err
}
}
return nil
}
示例13: extlinux
// extlinux installs the SYSLINUX bootloader using extlinux. Path should be the
// root directory for the filesystem. extlinux also writes out a
// minimega-specific configuration file for SYSLINUX.
func extlinux(path string) error {
// install extlinux
p := process("extlinux")
cmd := &exec.Cmd{
Path: p,
Args: []string{
p,
"--install",
filepath.Join(path, "boot"),
},
Env: nil,
Dir: "",
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
log.LogAll(stdout, log.INFO, "extlinux")
log.LogAll(stderr, log.INFO, "extlinux")
log.Debug("installing bootloader with cmd: %v", cmd)
err = cmd.Run()
if err != nil {
return err
}
// write out the bootloader config, but first figure out the kernel and
// initrd files in /boot
filepath.Walk(filepath.Join(path, "boot"), kernelWalker)
if kernelName == "" {
return fmt.Errorf("could not find kernel name")
}
if initrdName == "" {
return fmt.Errorf("could not find initrd name")
}
extlinuxConfig := fmt.Sprintf("DEFAULT minimegalinux\nLABEL minimegalinux\nSAY booting minimegalinux\nLINUX /boot/%v\nAPPEND root=/dev/sda1\nINITRD /boot/%v", kernelName, initrdName)
return ioutil.WriteFile(filepath.Join(path, "/boot/extlinux.conf"), []byte(extlinuxConfig), os.FileMode(0660))
}
示例14: BuildTargets
// BuildTargets generates the initrd and kernel files as the last stage of the
// build process. It does so by writing a find/cpio/gzip command as a script
// to a temporary file and executing that in a bash shell. The output filenames
// are equal to the base name of the input config file. So a config called
// 'my_vm.conf' will generate 'my_vm.initrd' and 'my_vm.kernel'. The kernel
// image is the one found in /boot of the build directory.
func BuildTargets(buildPath string, c vmconfig.Config) error {
targetName := strings.Split(filepath.Base(c.Path), ".")[0]
log.Debugln("using target name:", targetName)
wd, err := os.Getwd()
if err != nil {
return err
}
targetInitrd := fmt.Sprintf("%v/%v.initrd", wd, targetName)
targetKernel := fmt.Sprintf("%v/%v.kernel", wd, targetName)
f, err := ioutil.TempFile("", "vmbetter_cpio")
if err != nil {
return err
}
eName := f.Name()
initrdCommand := fmt.Sprintf("cd %v && find . -print0 | cpio --quiet --null -ov --format=newc | gzip -9 > %v\ncp boot/vmlinu* %v", buildPath, targetInitrd, targetKernel)
f.WriteString(initrdCommand)
f.Close()
log.Debugln("initrd command:", initrdCommand)
p := process("bash")
cmd := exec.Command(p, eName)
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
log.LogAll(stdout, log.INFO, "cpio")
// the cpio command outputs regular stuff to stderr, so i have a hack to push all output to the INFO level, instead of INFO/ERROR
log.LogAll(stderr, log.INFO, "cpio")
err = cmd.Run()
if err != nil {
return err
}
os.Remove(eName)
return nil
}
示例15: mountQcow2
// mountQcow2 mounts a partition to a temporary directory. If successful,
// returns the path to that temporary directory.
func mountQcow2(dev string) (string, error) {
// mount the filesystem
mountPath, err := ioutil.TempDir("", "vmbetter_mount_")
if err != nil {
log.Fatalln("cannot create temporary directory:", err)
}
log.Debugln("using mount path:", mountPath)
p := process("mount")
cmd := &exec.Cmd{
Path: p,
Args: []string{
p,
dev,
mountPath,
},
Env: nil,
Dir: "",
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return "", err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return "", err
}
log.LogAll(stdout, log.INFO, "mount")
log.LogAll(stderr, log.ERROR, "mount")
log.Debug("mounting with with cmd: %v", cmd)
err = cmd.Run()
if err != nil {
return "", err
}
return mountPath, nil
}