2
0
mirror of https://github.com/linka-cloud/d2vm.git synced 2025-06-27 23:52:27 +00:00

chore: d2vm/run: cleanup unused code, add source reference

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
2022-08-05 11:34:24 +02:00
parent 56104bbc0f
commit 598dec4e32
6 changed files with 4 additions and 110 deletions

1
cmd/d2vm/run/README.md Normal file
View File

@ -0,0 +1 @@
Shamelessly taken from [linuxkit](https://github.com/linuxkit/linuxkit/tree/master/src/cmd/linuxkit)

View File

@ -1,77 +0,0 @@
package run
import (
"fmt"
"os"
"path/filepath"
"github.com/rn/iso9660wrap"
log "github.com/sirupsen/logrus"
)
// WriteMetadataISO writes a metadata ISO file in a format usable by pkg/metadata
func WriteMetadataISO(path string, content []byte) error {
outfh, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer outfh.Close()
return iso9660wrap.WriteBuffer(outfh, content, "config")
}
func metadataCreateUsage() {
invoked := filepath.Base(os.Args[0])
fmt.Printf("USAGE: %s metadata create [file.iso] [metadata]\n\n", invoked)
fmt.Printf("'file.iso' is the file to create.\n")
fmt.Printf("'metadata' will be written to '/config' in the ISO.\n")
fmt.Printf("This is compatible with the d2vm/metadata package\n")
}
func metadataCreate(args []string) {
if len(args) != 2 {
metadataCreateUsage()
os.Exit(1)
}
switch args[0] {
case "help", "-h", "-help", "--help":
metadataCreateUsage()
os.Exit(0)
}
isoImage := args[0]
metadata := args[1]
if err := WriteMetadataISO(isoImage, []byte(metadata)); err != nil {
log.Fatal("Failed to write user data ISO: ", err)
}
}
func metadataUsage() {
invoked := filepath.Base(os.Args[0])
fmt.Printf("USAGE: %s metadata COMMAND [options]\n\n", invoked)
fmt.Printf("Commands:\n")
fmt.Printf(" create Create a metadata ISO\n")
}
func metadata(args []string) {
if len(args) < 1 {
metadataUsage()
os.Exit(1)
}
switch args[0] {
case "help", "-h", "-help", "--help":
metadataUsage()
os.Exit(0)
}
switch args[0] {
case "create":
metadataCreate(args[1:])
default:
fmt.Printf("%q is not a valid metadata command.\n\n", args[0])
metadataUsage()
os.Exit(1)
}
}

View File

@ -17,9 +17,7 @@ package run
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
)
@ -276,30 +274,3 @@ func NewPublishedPort(publish string) (PublishedPort, error) {
p.Protocol = protocol
return p, nil
}
// CreateMetadataISO writes the provided meta data to an iso file in the given state directory
func CreateMetadataISO(state, data string, dataPath string) ([]string, error) {
var d []byte
// if we have neither data nor dataPath, nothing to return
switch {
case data != "" && dataPath != "":
return nil, fmt.Errorf("Cannot specify options for both data and dataPath")
case data == "" && dataPath == "":
return []string{}, nil
case data != "":
d = []byte(data)
case dataPath != "":
var err error
d, err = ioutil.ReadFile(dataPath)
if err != nil {
return nil, fmt.Errorf("Cannot read user data from path %s: %v", dataPath, 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
}