Add linuxkit metadata command

Only subcommand is currently `create` which is a thin wrapper to create an iso
file in the format expected by `pkg/metadata`.

Currently very basic and just takes the content on the command line but could
be extended to read from a file etc.

Signed-off-by: Ian Campbell <ian.campbell@docker.com>
This commit is contained in:
Ian Campbell 2017-05-10 17:39:08 +01:00
parent e0bcac3a28
commit 36eaa44d7e
3 changed files with 85 additions and 0 deletions

View File

@ -51,6 +51,15 @@ This hierarchy can then be used by individual containers, who can bind
mount the config sub-directory into their namespace where it is
needed.
# Metadata image creation
Run `linuxkit run` backends accept a `--data=STRING` option which will
cause the given string to be passed to the VM in a platform specific
manner to be picked up by the `pkg/metadata` component.
Alternatively `linuxkit metadata create meta.iso STRING` will produce
a correctly formatted ISO image which can be passed to a VM as a CDROM
device for consumption by the `pkg/metadata` component.
# Providers

View File

@ -41,6 +41,7 @@ func main() {
flag.Usage = func() {
fmt.Printf("USAGE: %s [options] COMMAND\n\n", filepath.Base(os.Args[0]))
fmt.Printf("Commands:\n")
fmt.Printf(" metadata Metadata utilities\n")
fmt.Printf(" push Push a VM image to a cloud or image store\n")
fmt.Printf(" run Run a VM image on a local hypervisor or remote cloud\n")
fmt.Printf(" version Print version information\n")
@ -79,6 +80,8 @@ func main() {
}
switch args[0] {
case "metadata":
metadata(args[1:])
case "push":
push(args[1:])
case "run":

View File

@ -0,0 +1,73 @@
package main
import (
"fmt"
"os"
"path/filepath"
log "github.com/Sirupsen/logrus"
"github.com/rneugeba/iso9660wrap"
)
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 linuxkit/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]
outfh, err := os.OpenFile(isoImage, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatal("Cannot create user data ISOs", "err", err)
}
defer outfh.Close()
err = iso9660wrap.WriteBuffer(outfh, []byte(metadata), "config")
if err != nil {
log.Fatal("Cannot write user data ISO", "err", 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)
}
}