Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions cmd/create/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,23 @@ func execute(cmd *cobra.Command) {
if err := validateAccounts(accounts); err != nil {
log.Fatal("Invalid accounts parameter: ", err)
}
err := environmentClient.CreateEnvironment(&ctx, &environmentProto.CreateEnvironmentRequest{

// Auto-detect MAC address to use as routing key
macAddr, err := util.GetDefaultMACAddress()
if err != nil {
log.Fatalf("Failed to auto-detect MAC address: %v", err)
}
log.Debugf("Using MAC address as routing key: %s", macAddr)

// Create the request
req := &environmentProto.CreateEnvironmentRequest{
EnvName: envName,
Accounts: util.SplitProviderAccount(accounts),
ProvisioningType: provisioningType,
})
RoutingKey: &macAddr,
}

err = environmentClient.CreateEnvironment(&ctx, req)

if err != nil {
util.LogGrpcError(err, "Failed to create environment: ")
Expand Down
32 changes: 32 additions & 0 deletions pkg/util/network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package util

import (
"fmt"
"net"
)

// GetDefaultMACAddress returns the MAC address of the first non-loopback network interface
// with a valid MAC address. Returns empty string if no suitable interface is found.
func GetDefaultMACAddress() (string, error) {
interfaces, err := net.Interfaces()
if err != nil {
return "", fmt.Errorf("failed to get network interfaces: %w", err)
}

for _, iface := range interfaces {
// Skip loopback, down interfaces, and interfaces without hardware address
if iface.Flags&net.FlagLoopback != 0 || iface.Flags&net.FlagUp == 0 {
continue
}

// Check if interface has a valid MAC address
if len(iface.HardwareAddr) > 0 {
macAddr := iface.HardwareAddr.String()
if macAddr != "" && macAddr != "00:00:00:00:00:00" {
return macAddr, nil
}
}
}

return "", fmt.Errorf("no suitable network interface with valid MAC address found")
}
1 change: 1 addition & 0 deletions proto/dream11/od/environment/v1/environment.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ message CreateEnvironmentRequest {
string env_name = 1;
repeated string accounts = 2;
string provisioning_type = 3;
optional string routing_key = 4;
}

message CreateEnvironmentResponse {
Expand Down
Loading