-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the first part of 'trust launch'
Trust launch creates a new SUDI keyset, creates a machine, provisions it for that SUDI keyset, then installs it. Signed-off-by: Serge Hallyn <[email protected]>
- Loading branch information
Showing
3 changed files
with
121 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package main | ||
|
||
import ( | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
var launchCmd = cli.Command{ | ||
Name: "launch", | ||
Usage: "launch a new machine", | ||
UsageText: `name install-url | ||
name: name to give the VM | ||
install-url: install.json distoci URL to install (e.g. zothub.io/machine/zot/install:1.0.0) | ||
Note that install is not yet supported.`, | ||
Action: doLaunch, | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "project", | ||
Usage: "keyset:project to which this machine will belong (TRUST_PROJECT)", | ||
}, | ||
cli.StringFlag{ | ||
Name: "serial, uuid", | ||
Usage: "Serial number UUID to assign to the machine, empty to use a random UUID", | ||
Value: "", | ||
}, | ||
cli.BoolFlag{ | ||
Name: "skip-provisioning", | ||
Usage: "Skip provisioning the machine", | ||
}, | ||
cli.BoolFlag{ | ||
Name: "skip-install", | ||
Usage: "Skip running the install ISO", | ||
}, | ||
cli.StringFlag{ | ||
Name: "type", | ||
Usage: "Type of machine to launch.", | ||
Value: "kvm", | ||
}, | ||
}, | ||
} | ||
|
||
func splitFullProject(full string) (string, string, error) { | ||
s := strings.Split(full, ":") | ||
if len(s) != 2 { | ||
return "", "", errors.Errorf("Bad project name %q, should be keyset:project, e.g. snakeoil:default.", full) | ||
} | ||
return s[0], s[1], nil | ||
} | ||
|
||
func doLaunch(ctx *cli.Context) error { | ||
args := ctx.Args() | ||
if len(args) < 1 { | ||
return errors.New("A name for the new machine is required") | ||
} | ||
|
||
if !ctx.Bool("skip-install") && len(args) != 2 { | ||
return errors.New("Install manifest URL is required") | ||
} | ||
|
||
mname := args[0] | ||
if mname == "" { | ||
return errors.New("Please specify machine name") | ||
} | ||
|
||
fullProject := ctx.String("project") | ||
keyset, project, err := splitFullProject(fullProject) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
trustDir, err := getMosKeyPath() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
keysetDir := filepath.Join(trustDir, keyset) | ||
projDir := filepath.Join(keysetDir, "manifest", project) | ||
if !PathExists(projDir) { | ||
return errors.Errorf("Project %s not found", fullProject) | ||
} | ||
|
||
uuid := ctx.String("uuid") | ||
sudiPath, err := genSudi(keysetDir, projDir, uuid) | ||
if err != nil { | ||
return errors.Wrapf(err, "Failed generating SUDI") | ||
} | ||
|
||
return errors.Errorf("Created SUDI (%q), now need to launch a machine", sudiPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters