mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-22 18:41:37 +00:00
Move metadata ISO creation to common code
This code was identical in the QEMU and HyperKit cases. Move it to util.go and wrap it in a function, with minimal changes for returning an error. Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
parent
db9a783821
commit
a5e5d42368
@ -141,22 +141,11 @@ func runHyperKit(args []string) {
|
|||||||
log.Fatalf("Could not create state directory: %v", err)
|
log.Fatalf("Could not create state directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *data != "" {
|
metadataPaths, err := CreateMetadataISO(*state, *data)
|
||||||
var d []byte
|
if err != nil {
|
||||||
if _, err := os.Stat(*data); os.IsNotExist(err) {
|
log.Fatalf("%v", err)
|
||||||
d = []byte(*data)
|
|
||||||
} else {
|
|
||||||
d, err = ioutil.ReadFile(*data)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Cannot read user data: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isoPath := filepath.Join(*state, "data.iso")
|
|
||||||
if err := WriteMetadataISO(isoPath, d); err != nil {
|
|
||||||
log.Fatalf("Cannot write user data ISO: %v", err)
|
|
||||||
}
|
|
||||||
isoPaths = append(isoPaths, isoPath)
|
|
||||||
}
|
}
|
||||||
|
isoPaths = append(isoPaths, metadataPaths...)
|
||||||
|
|
||||||
// Create UUID for VPNKit or reuse an existing one from state dir. IP addresses are
|
// Create UUID for VPNKit or reuse an existing one from state dir. IP addresses are
|
||||||
// assigned to the UUID, so to get the same IP we have to store the initial UUID. If
|
// assigned to the UUID, so to get the same IP we have to store the initial UUID. If
|
||||||
|
@ -223,22 +223,11 @@ func runQemu(args []string) {
|
|||||||
isoPaths = append(isoPaths, path)
|
isoPaths = append(isoPaths, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *data != "" {
|
metadataPaths, err := CreateMetadataISO(*state, *data)
|
||||||
var d []byte
|
if err != nil {
|
||||||
if _, err := os.Stat(*data); os.IsNotExist(err) {
|
log.Fatalf("%v", err)
|
||||||
d = []byte(*data)
|
|
||||||
} else {
|
|
||||||
d, err = ioutil.ReadFile(*data)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Cannot read user data: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isoPath := filepath.Join(*state, "data.iso")
|
|
||||||
if err := WriteMetadataISO(isoPath, d); err != nil {
|
|
||||||
log.Fatalf("Cannot write user data ISO: %v", err)
|
|
||||||
}
|
|
||||||
isoPaths = append(isoPaths, isoPath)
|
|
||||||
}
|
}
|
||||||
|
isoPaths = append(isoPaths, metadataPaths...)
|
||||||
|
|
||||||
for i, d := range disks {
|
for i, d := range disks {
|
||||||
id := ""
|
id := ""
|
||||||
|
@ -3,7 +3,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -252,3 +254,25 @@ func NewPublishedPort(publish string) (PublishedPort, error) {
|
|||||||
p.Protocol = protocol
|
p.Protocol = protocol
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateMetadataISO writes the provided meta data to an iso file in the given state directory
|
||||||
|
func CreateMetadataISO(state, data string) ([]string, error) {
|
||||||
|
if data == "" {
|
||||||
|
return []string{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var d []byte
|
||||||
|
if _, err := os.Stat(data); os.IsNotExist(err) {
|
||||||
|
d = []byte(data)
|
||||||
|
} else {
|
||||||
|
d, err = ioutil.ReadFile(data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Cannot read user data: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
isoPath := filepath.Join(state, "data.iso")
|
||||||
|
if err := WriteMetadataISO(isoPath, d); err != nil {
|
||||||
|
return nil, fmt.Errorf("Cannot write user data ISO: %v", err)
|
||||||
|
}
|
||||||
|
return []string{isoPath}, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user