Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not attempt creating ssh config files if ssh_config.d doesn't exist #1708

Merged
merged 2 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 11 additions & 2 deletions clab/sshconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package clab

import (
"os"
"path"
"text/template"

log "github.com/sirupsen/logrus"
"github.com/srl-labs/containerlab/types"
"github.com/srl-labs/containerlab/utils"
)

// SSHConfigTmpl is the top-level data structure for the
Expand Down Expand Up @@ -44,7 +47,13 @@ func (c *CLab) RemoveSSHConfig(topoPaths *types.TopoPaths) error {
}

// AddSSHConfig adds the lab specific ssh config file.
func (c *CLab) AddSSHConfig(topoPaths *types.TopoPaths) error {
func (c *CLab) AddSSHConfig() error {
sshConfigDir := path.Dir(c.TopoPaths.SSHConfigPath())
if !utils.FileOrDirExists(sshConfigDir) {
log.Debugf("ssh config directory %s does not exist, skipping ssh config generation", sshConfigDir)
return nil
}

tmpl := &SSHConfigTmpl{
TopologyName: c.Config.Name,
Nodes: make([]SSHConfigNodeTmpl, 0, len(c.Nodes)),
Expand All @@ -67,7 +76,7 @@ func (c *CLab) AddSSHConfig(topoPaths *types.TopoPaths) error {
return err
}

f, err := os.Create(topoPaths.SSHConfigPath())
f, err := os.Create(c.TopoPaths.SSHConfigPath())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func deployFn(_ *cobra.Command, _ []string) error {
}

log.Info("Adding ssh config for containerlab nodes")
err = c.AddSSHConfig(c.TopoPaths)
err = c.AddSSHConfig()
if err != nil {
log.Errorf("failed to create ssh config file: %v", err)
}
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2678,10 +2678,6 @@ github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5q
github.com/spf13/viper v1.13.0/go.mod h1:Icm2xNL3/8uyh/wFuB1jI7TiTNKp8632Nwegu+zgdYw=
github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980 h1:lIOOHPEbXzO3vnmx2gok1Tfs31Q8GQqKLc8vVqyQq/I=
github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980/go.mod h1:AO3tvPzVZ/ayst6UlUKUv6rcPQInYe3IknH3jYhAKu8=
github.com/steiler/acls v0.0.0-20231106135104-9c34ae82c793 h1:lY8SggLL0JyttzcNEIRzbywKiKcIlVlF7ZPwTthG9eA=
github.com/steiler/acls v0.0.0-20231106135104-9c34ae82c793/go.mod h1:kS9/GuHDS4t2YmY2ijbaK3m1iU4+BgRZS7GoDTC9BfY=
github.com/steiler/acls v0.0.0-20231106152733-bb3d5d7b05c8 h1:RqP82h2DREJxj7AJbT0k7z2Jye6lweij5s14PUHic1o=
github.com/steiler/acls v0.0.0-20231106152733-bb3d5d7b05c8/go.mod h1:kS9/GuHDS4t2YmY2ijbaK3m1iU4+BgRZS7GoDTC9BfY=
github.com/steiler/acls v0.1.0 h1:fKVnEJ7ebghq2Ed5N1cU9fZrCCRj4xVRPrP7OswaRX8=
github.com/steiler/acls v0.1.0/go.mod h1:kS9/GuHDS4t2YmY2ijbaK3m1iU4+BgRZS7GoDTC9BfY=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
Expand Down