Skip to content

Commit

Permalink
Merge branch 'master' into scrapli-cleanup-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Sep 1, 2021
2 parents 455fc8d + 325c0eb commit 05309b9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ func (c *CLab) verifyVirtSupport() error {
return err
}

return fmt.Errorf("virtualization seems to be not supported and it is required by vrnetlab routers. Check if virtualization can been enabled")
return fmt.Errorf("virtualization seems to be not supported and it is required for VM based nodes. Check if virtualization can be enabled")
}

// checkEndpoint runs checks on the endpoint syntax
Expand Down
23 changes: 21 additions & 2 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,29 @@ var deployCmd = &cobra.Command{

// a set of workers that do not support concurrency
serialNodes := make(map[string]struct{})

// extraHosts holds host entries for nodes with static IPv4/6 addresses
// these entries will be used by container runtime to populate /etc/hosts file
extraHosts := make([]string, 0, len(c.Nodes))

for _, n := range c.Nodes {
if n.GetRuntime().GetName() == runtime.IgniteRuntime {
serialNodes[n.Config().LongName] = struct{}{}
}

if n.Config().MgmtIPv4Address != "" {
log.Debugf("Adding static ipv4 /etc/hosts entry for %s:%s", n.Config().ShortName, n.Config().MgmtIPv4Address)
extraHosts = append(extraHosts, n.Config().ShortName+":"+n.Config().MgmtIPv4Address)
}

if n.Config().MgmtIPv6Address != "" {
log.Debugf("Adding static ipv6 /etc/hosts entry for %s:%s", n.Config().ShortName, n.Config().MgmtIPv6Address)
extraHosts = append(extraHosts, n.Config().ShortName+":"+n.Config().MgmtIPv6Address)
}
}

for _, n := range c.Nodes {
n.Config().ExtraHosts = extraHosts
}

nodesStaticWg, nodesDynWg := c.CreateNodes(ctx, nodeWorkers, serialNodes)
Expand All @@ -153,7 +172,7 @@ var deployCmd = &cobra.Command{
}

log.Debug("enriching nodes with IP information...")
enrichNodes(containers, c.Nodes, c.Config.Mgmt.Network)
enrichNodes(containers, c.Nodes)

if err := c.GenerateInventories(); err != nil {
return err
Expand Down Expand Up @@ -226,7 +245,7 @@ func setFlags(conf *clab.Config) {
}
}

func enrichNodes(containers []types.GenericContainer, nodesMap map[string]nodes.Node, mgmtNet string) {
func enrichNodes(containers []types.GenericContainer, nodesMap map[string]nodes.Node) {
for _, c := range containers {
name = c.Labels["clab-node-name"]
if node, ok := nodesMap[name]; ok {
Expand Down
9 changes: 5 additions & 4 deletions runtime/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (c *DockerRuntime) Init(opts ...runtime.RuntimeOption) error {
func (c *DockerRuntime) WithKeepMgmtNet() {
c.config.KeepMgmtNet = true
}
func (c *DockerRuntime) GetName() string { return runtimeName }
func (*DockerRuntime) GetName() string { return runtimeName }
func (c *DockerRuntime) Config() runtime.RuntimeConfig { return c.config }

func (c *DockerRuntime) WithConfig(cfg *runtime.RuntimeConfig) {
Expand Down Expand Up @@ -264,6 +264,7 @@ func (c *DockerRuntime) CreateContainer(ctx context.Context, node *types.NodeCon
Sysctls: node.Sysctls,
Privileged: true,
NetworkMode: container.NetworkMode(c.Mgmt.Network),
ExtraHosts: node.ExtraHosts, // add static /etc/hosts entries
}

containerNetworkingConfig := &network.NetworkingConfig{}
Expand Down Expand Up @@ -435,7 +436,7 @@ func (c *DockerRuntime) GetContainer(ctx context.Context, containerID string) (*
return &ctrs[0], nil
}

func (c *DockerRuntime) buildFilterString(gfilters []*types.GenericFilter) filters.Args {
func (*DockerRuntime) buildFilterString(gfilters []*types.GenericFilter) filters.Args {
filter := filters.NewArgs()
for _, filterentry := range gfilters {
filterstring := filterentry.Field
Expand Down Expand Up @@ -533,8 +534,8 @@ func (c *DockerRuntime) Exec(ctx context.Context, id string, cmd []string) ([]by
return outBuf.Bytes(), errBuf.Bytes(), nil
}

// ExecNotWait executes cmd on container identified with id but doesn't wait for output nor attaches stodout/err
func (c *DockerRuntime) ExecNotWait(ctx context.Context, id string, cmd []string) error {
// ExecNotWait executes cmd on container identified with id but doesn't wait for output nor attaches stdout/err
func (c *DockerRuntime) ExecNotWait(_ context.Context, id string, cmd []string) error {
execConfig := dockerTypes.ExecConfig{Tty: false, AttachStdout: false, AttachStderr: false, Cmd: cmd}
respID, err := c.Client.ContainerExecCreate(context.Background(), id, execConfig)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type NodeConfig struct {
TLSAnchor string
NSPath string // network namespace path for this node
Publish []string //list of ports to publish with mysocketctl
ExtraHosts []string // Extra /etc/hosts entries for all nodes
// container labels
Labels map[string]string
// Slice of pointers to local endpoints
Expand All @@ -106,7 +107,7 @@ type NodeConfig struct {
}

// GenerateConfig generates configuration for the nodes
// out of the templ based on the node configuration and saves the result to dst
// out of the template based on the node configuration and saves the result to dst
func (node *NodeConfig) GenerateConfig(dst, templ string) error {

// If the config file is already present in the node dir
Expand Down

0 comments on commit 05309b9

Please sign in to comment.