Skip to content

Commit

Permalink
allow bridge/tap on instance create for onprem provider (#1486)
Browse files Browse the repository at this point in the history
* allow bridge/tap for linux local

* .

* .

* .

* .

---------

Co-authored-by: eyberg <[email protected]>
  • Loading branch information
eyberg and eyberg authored Jun 21, 2023
1 parent dc83aee commit 6f030d7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
16 changes: 15 additions & 1 deletion cmd/cmd_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func instanceCreateCommand() *cobra.Command {
cmdInstanceCreate.PersistentFlags().StringP("instance-name", "i", "", "instance name (overrides default instance name format)")
cmdInstanceCreate.PersistentFlags().StringP("instance-group", "", "", "instance group")

cmdInstanceCreate.PersistentFlags().Bool("bridged", false, "bridge [local only]")
cmdInstanceCreate.PersistentFlags().StringP("tap", "", "", "tap interface [local only]")
cmdInstanceCreate.PersistentFlags().StringP("ip-address", "", "", "static ip address [local only]")

return cmdInstanceCreate
}

Expand All @@ -78,9 +82,19 @@ func instanceCreateCommandHandler(cmd *cobra.Command, args []string) {
c.CloudConfig.ImageName = args[0]

instanceName, _ := cmd.Flags().GetString("instance-name")

instanceGroup, _ := cmd.Flags().GetString("instance-group")

// local only
bridged, _ := cmd.Flags().GetBool("bridged")
tap, _ := cmd.Flags().GetString("tap")
ipAddress, _ := cmd.Flags().GetString("ip-address")
if bridged && tap != "" && ipAddress != "" {
c.RunConfig.TapName = tap
c.RunConfig.Bridged = bridged
c.RunConfig.IPAddress = ipAddress
c.RunConfig.NetMask = "255.255.255.0" // stubbed
}

if instanceName == "" {
c.RunConfig.InstanceName = fmt.Sprintf("%v-%v",
strings.Split(filepath.Base(c.CloudConfig.ImageName), ".")[0],
Expand Down
1 change: 1 addition & 0 deletions network/setup_network_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Service interface {

// SetupNetworkInterfaces changes network configuration to support requirements
func SetupNetworkInterfaces(network Service, tapDeviceName string, bridgeName string, ipaddress string, netmask string) error {

tapExists, err := network.CheckNetworkInterfaceExists(tapDeviceName)
if err != nil {
return errors.New("Not able to check tap exists")
Expand Down
26 changes: 25 additions & 1 deletion provider/onprem/onprem_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ import (
"os"
"os/exec"
"path"
"runtime"
"strconv"
"strings"
"syscall"
"time"

"github.com/nanovms/ops/lepton"
"github.com/nanovms/ops/log"
"github.com/nanovms/ops/network"
"github.com/nanovms/ops/qemu"
"github.com/olekukonko/tablewriter"

"github.com/olekukonko/tablewriter"
"golang.org/x/sys/unix"
)

Expand All @@ -42,6 +44,28 @@ func (p *OnPrem) createInstance(ctx *lepton.Context) (string, error) {
}
}

// linux local only; mac uses diff bridge
if runtime.GOOS == "linux" && c.RunConfig.Bridged {
tapDeviceName := c.RunConfig.TapName
bridged := c.RunConfig.Bridged
ipaddress := c.RunConfig.IPAddress
netmask := c.RunConfig.NetMask

bridgeName := c.RunConfig.BridgeName
if bridged && bridgeName == "" {
bridgeName = "br0"
}

networkService := network.NewIprouteNetworkService()

if tapDeviceName != "" {
err := network.SetupNetworkInterfaces(networkService, tapDeviceName, bridgeName, ipaddress, netmask)
if err != nil {
return "", err
}
}
}

hypervisor := qemu.HypervisorInstance()
if hypervisor == nil {
fmt.Println("No hypervisor found on $PATH")
Expand Down

0 comments on commit 6f030d7

Please sign in to comment.