Skip to content

Commit

Permalink
Merge branch 'firecracker-socket'
Browse files Browse the repository at this point in the history
PR firecracker-microvm#23

Signed-off-by: Noah Meyerhans <[email protected]>
  • Loading branch information
Noah Meyerhans committed Feb 27, 2019
2 parents b0dddb2 + 4b40ce3 commit 0658ece
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/firecracker-microvm/firectl

require (
github.com/firecracker-microvm/firecracker-go-sdk v0.0.0-20181220230332-433f262dc33b
github.com/firecracker-microvm/firecracker-go-sdk v0.0.0-20190226020201-847e85db1412
github.com/jessevdk/go-flags v1.4.0
github.com/pkg/errors v0.8.0
github.com/sirupsen/logrus v1.1.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/firecracker-microvm/firecracker-go-sdk v0.0.0-20181220230332-433f262dc33b h1:5vIdzbfLuWaResxGLVzoNbpg2LEjSkEzDoJLJpqJqeE=
github.com/firecracker-microvm/firecracker-go-sdk v0.0.0-20181220230332-433f262dc33b/go.mod h1:7ZuTUkeKoyUmdR6Tn4eepqjYeKMXcOg9gJytYVz8TuE=
github.com/firecracker-microvm/firecracker-go-sdk v0.0.0-20190226020201-847e85db1412 h1:RwIr6dztoblljoWEcoQJ26LATycGTrgSZg+/NJYMzrM=
github.com/firecracker-microvm/firecracker-go-sdk v0.0.0-20190226020201-847e85db1412/go.mod h1:UOsA6IaI52MQntB9PrarJFReY1nA9iZg2DI04kxPNMY=
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb h1:D4uzjWwKYQ5XnAvUbuvHW93esHg7F8N/OYeBBcJoTr0=
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/go-openapi/analysis v0.0.0-20180825180245-b006789cd277/go.mod h1:k70tL6pCuVxPJOHXQ+wIac1FUrvNkHolPie/cLEU6hI=
Expand Down
49 changes: 30 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"context"
"fmt"
"os"
"os/exec"

firecracker "github.com/firecracker-microvm/firecracker-go-sdk"
flags "github.com/jessevdk/go-flags"
Expand All @@ -37,6 +38,8 @@ const (
// executableMask is the mask needed to check whether or not a file's
// permissions are executable.
executableMask = 0111

firecrackerDefaultPath = "firecracker"
)

func main() {
Expand Down Expand Up @@ -87,33 +90,41 @@ func runVMM(ctx context.Context, opts *options) error {
firecracker.WithLogger(log.NewEntry(logger)),
}

var firecrackerBinary string
if len(opts.FcBinary) != 0 {
finfo, err := os.Stat(opts.FcBinary)
if os.IsNotExist(err) {
return fmt.Errorf("Binary %q does not exist: %v", opts.FcBinary, err)
}

firecrackerBinary = opts.FcBinary
} else {
firecrackerBinary, err = exec.LookPath(firecrackerDefaultPath)
if err != nil {
return fmt.Errorf("Failed to stat binary, %q: %v", opts.FcBinary, err)
return err
}
}

if finfo.IsDir() {
return fmt.Errorf("Binary, %q, is a directory", opts.FcBinary)
} else if finfo.Mode()&executableMask == 0 {
return fmt.Errorf("Binary, %q, is not executable. Check permissions of binary", opts.FcBinary)
}
finfo, err := os.Stat(firecrackerBinary)
if os.IsNotExist(err) {
return fmt.Errorf("Binary %q does not exist: %v", firecrackerBinary, err)
}

cmd := firecracker.VMCommandBuilder{}.
WithBin(opts.FcBinary).
WithSocketPath(fcCfg.SocketPath).
WithStdin(os.Stdin).
WithStdout(os.Stdout).
WithStderr(os.Stderr).
Build(ctx)
if err != nil {
return fmt.Errorf("Failed to stat binary, %q: %v", firecrackerBinary, err)
}

machineOpts = append(machineOpts, firecracker.WithProcessRunner(cmd))
if finfo.IsDir() {
return fmt.Errorf("Binary, %q, is a directory", firecrackerBinary)
} else if finfo.Mode()&executableMask == 0 {
return fmt.Errorf("Binary, %q, is not executable. Check permissions of binary", firecrackerBinary)
}

cmd := firecracker.VMCommandBuilder{}.
WithBin(firecrackerBinary).
WithSocketPath(fcCfg.SocketPath).
WithStdin(os.Stdin).
WithStdout(os.Stdout).
WithStderr(os.Stderr).
Build(ctx)

machineOpts = append(machineOpts, firecracker.WithProcessRunner(cmd))

m, err := firecracker.NewMachine(vmmCtx, fcCfg, machineOpts...)
if err != nil {
return fmt.Errorf("Failed creating machine: %s", err)
Expand Down
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ func (opts *options) getNetwork() ([]firecracker.NetworkInterface, error) {
if err != nil {
return nil, err
}
allowMDDS := opts.validMetadata != nil
allowMMDS := opts.validMetadata != nil
NICs = []firecracker.NetworkInterface{
firecracker.NetworkInterface{
MacAddress: tapMacAddr,
HostDevName: tapDev,
AllowMDDS: allowMDDS,
AllowMMDS: allowMMDS,
},
}
}
Expand Down
8 changes: 4 additions & 4 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ func TestGetFirecrackerNetworkingConfig(t *testing.T) {
expectedNic: nil,
},
{
name: "valid FcNicConfig with mdds set to true",
name: "valid FcNicConfig with MMDS set to true",
opt: options{
FcNicConfig: "valid/things",
validMetadata: 42,
Expand All @@ -515,12 +515,12 @@ func TestGetFirecrackerNetworkingConfig(t *testing.T) {
firecracker.NetworkInterface{
MacAddress: "things",
HostDevName: "valid",
AllowMDDS: true,
AllowMMDS: true,
},
},
},
{
name: "valid FcNicConfig with mdds set to false",
name: "valid FcNicConfig with MMDS set to false",
opt: options{
FcNicConfig: "valid/things",
},
Expand All @@ -531,7 +531,7 @@ func TestGetFirecrackerNetworkingConfig(t *testing.T) {
firecracker.NetworkInterface{
MacAddress: "things",
HostDevName: "valid",
AllowMDDS: false,
AllowMMDS: false,
},
},
},
Expand Down

0 comments on commit 0658ece

Please sign in to comment.