diff --git a/runtime/docker/docker.go b/runtime/docker/docker.go index 806e9bf7e..673d7cb10 100644 --- a/runtime/docker/docker.go +++ b/runtime/docker/docker.go @@ -1044,3 +1044,26 @@ func (d *DockerRuntime) IsHealthy(ctx context.Context, cID string) (bool, error) } return inspect.State.Health.Status == "healthy", nil } + +func (d *DockerRuntime) WriteToStdinNoWait(ctx context.Context, cID string, data []byte) error { + + stdin, err := d.Client.ContainerAttach(ctx, cID, container.AttachOptions{ + Stdin: true, + Stream: true, + Stdout: true, + Stderr: true, + }) + + if err != nil { + return err + } + + log.Debugf("Writing to %s: %v", cID, data) + + _, err = stdin.Conn.Write(data) + if err != nil { + return err + } + + return stdin.Conn.Close() +} diff --git a/runtime/ignite/ignite.go b/runtime/ignite/ignite.go index ed8f41b59..54cddf066 100644 --- a/runtime/ignite/ignite.go +++ b/runtime/ignite/ignite.go @@ -471,3 +471,8 @@ func (*IgniteRuntime) IsHealthy(_ context.Context, _ string) (bool, error) { log.Errorf("function GetContainerHealth(...) not implemented in the Containerlab IgniteRuntime") return true, nil } + +func (*IgniteRuntime) WriteToStdinNoWait(ctx context.Context, cID string, data []byte) error { + log.Infof("WriteToStdinNoWait is not yet implemented for Ignite runtime") + return nil +} diff --git a/runtime/runtime.go b/runtime/runtime.go index 6d8571600..3167ba618 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -62,6 +62,8 @@ type ContainerRuntime interface { GetContainerStatus(ctx context.Context, cID string) ContainerStatus // IsHealthy returns true is the container is reported as being healthy, false otherwise IsHealthy(ctx context.Context, cID string) (bool, error) + // Immediately write to the stdin of a container, returns error + WriteToStdinNoWait(ctx context.Context, cID string, data []byte) error } type ContainerStatus string