Skip to content

Commit

Permalink
Update vlab to work with nat
Browse files Browse the repository at this point in the history
  • Loading branch information
Frostman committed Oct 3, 2023
1 parent 75ac745 commit ddc1b0f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pkg/fab/assemly.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
REF_ZOT_TARGET_IMAGE = cnc.Ref{Repo: "ghcr.io/project-zot", Name: "zot-minimal-linux-amd64"}

// Das Boot
REF_DASBOOT_VERSION = cnc.Ref{Tag: "v0.7.5"}
REF_DASBOOT_VERSION = cnc.Ref{Tag: "v0.7.6"}
REF_DASBOOT_CRDS_CHART = cnc.Ref{Name: "das-boot/charts/das-boot-crds"}
REF_DASBOOT_SEEDER_CHART = cnc.Ref{Name: "das-boot/charts/das-boot-seeder"}
REF_DASBOOT_SEEDER_IMAGE = cnc.Ref{Name: "das-boot/das-boot-seeder"}
Expand All @@ -74,7 +74,7 @@ var (
}

// Fabric
REF_FABRIC_VERSION = cnc.Ref{Tag: "v0.17.3"}
REF_FABRIC_VERSION = cnc.Ref{Tag: "v0.17.10"}
REF_FABRIC_API_CHART = cnc.Ref{Name: "fabric/charts/fabric-api"}
REF_FABRIC_CHART = cnc.Ref{Name: "fabric/charts/fabric"}
REF_FABRIC_IMAGE = cnc.Ref{Name: "fabric/fabric"}
Expand Down
8 changes: 4 additions & 4 deletions pkg/fab/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ func (cfg *Base) Hydrate(preset cnc.Preset) error {
cfg.Dev = true
}

if cfg.Dev {
slog.Warn("Attention! Development mode enabled - this is not secure! Default users and keys will be created.")
}

return nil
}

func (cfg *Base) Build(basedir string, preset cnc.Preset, get cnc.GetComponent, wiring *wiring.Data, run cnc.AddBuildOp, install cnc.AddRunOp) error {
if cfg.Dev {
slog.Warn("Attention! Development mode enabled - this is not secure! Default users and keys will be created.")
}

if preset == PRESET_VLAB {
key, err := cnc.ReadOrGenerateSSHKey(basedir, DEFAULT_VLAB_SSH_KEY, "vlab")
if err != nil {
Expand Down
50 changes: 43 additions & 7 deletions pkg/fab/vlab/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
REGISTRY_PORT = 31000
SSH_PORT_BASE = 22000
IF_PORT_BASE = 30000
IF_PORT_NULL = IF_PORT_BASE + 9000
IF_PORT_VM_ID_MULT = 100
IF_PORT_PORT_ID_MULT = 1
)
Expand Down Expand Up @@ -144,6 +145,9 @@ func (svc *Service) checkForStaleVMs(ctx context.Context, killStaleVMs bool) err
for _, pr := range processes {
cmd, err := pr.CmdlineSliceWithContext(ctx)
if err != nil {
if strings.Contains(err.Error(), "no such file or directory") {
continue
}
return errors.Wrap(err, "error getting process cmdline")
}

Expand Down Expand Up @@ -282,16 +286,27 @@ func (svc *Service) AddConnection(conn *wiringapi.Connection) error {
switch2 := link.Switch2
links = append(links, [2]wiringapi.IPort{&switch1, &switch2})
}
} else if conn.Spec.NAT != nil {
links = append(links, [2]wiringapi.IPort{&conn.Spec.NAT.Link.Switch, &wiringapi.BasePortName{
Port: "nat",
}})
}

for _, link := range links {
err := svc.AddLink(link[0], link[1])
if err != nil {
return err
}
err = svc.AddLink(link[1], link[0])
if err != nil {
return err
if link[1].DeviceName() == "nat" {
err := svc.AddNullLink(link[0])
if err != nil {
return err
}
} else {
err := svc.AddLink(link[0], link[1])
if err != nil {
return err
}
err = svc.AddLink(link[1], link[0])
if err != nil {
return err
}
}
}

Expand Down Expand Up @@ -324,6 +339,27 @@ func (svc *Service) AddLink(local wiringapi.IPort, dest wiringapi.IPort) error {
return nil
}

func (svc *Service) AddNullLink(local wiringapi.IPort) error {
localVM := svc.vms[local.DeviceName()]

localPortID, err := portIdForName(local.LocalPortName())
if err != nil {
return err
}

localVM.Links = append(localVM.Links, &Link{
DevID: fmt.Sprintf("eth%d", localPortID),
MAC: svc.macFor(localVM, localPortID),
LocalIfPort: svc.ifPortFor(localVM, localPortID),
LocalPortName: local.PortName(),
DestName: "null",
DestIfPort: IF_PORT_NULL,
DestPortName: "null",
})

return nil
}

func (svc *Service) AddControlHostFwdLink(vm *VM) error {
sshPort := svc.sshPortFor(vm)

Expand Down

0 comments on commit ddc1b0f

Please sign in to comment.