mirror of
https://github.com/containers/podman.git
synced 2025-06-21 17:38:12 +08:00
podman, start: propagate back the raw input
this is necessary as we expect "podman start $ID_NAME" to print the same arguments the user passed in instead of the full ID. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -99,7 +99,7 @@ func start(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
for _, r := range responses {
|
for _, r := range responses {
|
||||||
if r.Err == nil {
|
if r.Err == nil {
|
||||||
fmt.Println(r.Id)
|
fmt.Println(r.RawInput)
|
||||||
} else {
|
} else {
|
||||||
errs = append(errs, r.Err)
|
errs = append(errs, r.Err)
|
||||||
}
|
}
|
||||||
|
@ -227,6 +227,7 @@ type ContainerStartOptions struct {
|
|||||||
// containers from the cli
|
// containers from the cli
|
||||||
type ContainerStartReport struct {
|
type ContainerStartReport struct {
|
||||||
Id string
|
Id string
|
||||||
|
RawInput string
|
||||||
Err error
|
Err error
|
||||||
ExitCode int
|
ExitCode int
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,9 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// getContainersByContext gets pods whether all, latest, or a slice of names/ids
|
// getContainersAndInputByContext gets containers whether all, latest, or a slice of names/ids
|
||||||
// is specified.
|
// is specified. It also returns a list of the corresponding input name used to lookup each container.
|
||||||
func getContainersByContext(all, latest bool, names []string, runtime *libpod.Runtime) (ctrs []*libpod.Container, err error) {
|
func getContainersAndInputByContext(all, latest bool, names []string, runtime *libpod.Runtime) (ctrs []*libpod.Container, rawInput []string, err error) {
|
||||||
var ctr *libpod.Container
|
var ctr *libpod.Container
|
||||||
ctrs = []*libpod.Container{}
|
ctrs = []*libpod.Container{}
|
||||||
|
|
||||||
@ -43,6 +43,7 @@ func getContainersByContext(all, latest bool, names []string, runtime *libpod.Ru
|
|||||||
ctrs, err = runtime.GetAllContainers()
|
ctrs, err = runtime.GetAllContainers()
|
||||||
case latest:
|
case latest:
|
||||||
ctr, err = runtime.GetLatestContainer()
|
ctr, err = runtime.GetLatestContainer()
|
||||||
|
rawInput = append(rawInput, ctr.ID())
|
||||||
ctrs = append(ctrs, ctr)
|
ctrs = append(ctrs, ctr)
|
||||||
default:
|
default:
|
||||||
for _, n := range names {
|
for _, n := range names {
|
||||||
@ -54,6 +55,7 @@ func getContainersByContext(all, latest bool, names []string, runtime *libpod.Ru
|
|||||||
err = e
|
err = e
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
rawInput = append(rawInput, n)
|
||||||
ctrs = append(ctrs, ctr)
|
ctrs = append(ctrs, ctr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,6 +63,13 @@ func getContainersByContext(all, latest bool, names []string, runtime *libpod.Ru
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getContainersByContext gets containers whether all, latest, or a slice of names/ids
|
||||||
|
// is specified.
|
||||||
|
func getContainersByContext(all, latest bool, names []string, runtime *libpod.Runtime) (ctrs []*libpod.Container, err error) {
|
||||||
|
ctrs, _, err = getContainersAndInputByContext(all, latest, names, runtime)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Should return *entities.ContainerExistsReport, error
|
// TODO: Should return *entities.ContainerExistsReport, error
|
||||||
func (ic *ContainerEngine) ContainerExists(ctx context.Context, nameOrId string) (*entities.BoolReport, error) {
|
func (ic *ContainerEngine) ContainerExists(ctx context.Context, nameOrId string) (*entities.BoolReport, error) {
|
||||||
_, err := ic.Libpod.LookupContainer(nameOrId)
|
_, err := ic.Libpod.LookupContainer(nameOrId)
|
||||||
@ -555,12 +564,14 @@ func (ic *ContainerEngine) ContainerExec(ctx context.Context, nameOrId string, o
|
|||||||
func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []string, options entities.ContainerStartOptions) ([]*entities.ContainerStartReport, error) {
|
func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []string, options entities.ContainerStartOptions) ([]*entities.ContainerStartReport, error) {
|
||||||
var reports []*entities.ContainerStartReport
|
var reports []*entities.ContainerStartReport
|
||||||
var exitCode = define.ExecErrorCodeGeneric
|
var exitCode = define.ExecErrorCodeGeneric
|
||||||
ctrs, err := getContainersByContext(false, options.Latest, namesOrIds, ic.Libpod)
|
ctrs, rawInputs, err := getContainersAndInputByContext(false, options.Latest, namesOrIds, ic.Libpod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// There can only be one container if attach was used
|
// There can only be one container if attach was used
|
||||||
for _, ctr := range ctrs {
|
for i := range ctrs {
|
||||||
|
ctr := ctrs[i]
|
||||||
|
rawInput := rawInputs[i]
|
||||||
ctrState, err := ctr.State()
|
ctrState, err := ctr.State()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -574,6 +585,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
|||||||
// Exit cleanly immediately
|
// Exit cleanly immediately
|
||||||
reports = append(reports, &entities.ContainerStartReport{
|
reports = append(reports, &entities.ContainerStartReport{
|
||||||
Id: ctr.ID(),
|
Id: ctr.ID(),
|
||||||
|
RawInput: rawInput,
|
||||||
Err: nil,
|
Err: nil,
|
||||||
ExitCode: 0,
|
ExitCode: 0,
|
||||||
})
|
})
|
||||||
@ -584,6 +596,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
|||||||
logrus.Debugf("Deadlock error: %v", err)
|
logrus.Debugf("Deadlock error: %v", err)
|
||||||
reports = append(reports, &entities.ContainerStartReport{
|
reports = append(reports, &entities.ContainerStartReport{
|
||||||
Id: ctr.ID(),
|
Id: ctr.ID(),
|
||||||
|
RawInput: rawInput,
|
||||||
Err: err,
|
Err: err,
|
||||||
ExitCode: define.ExitCode(err),
|
ExitCode: define.ExitCode(err),
|
||||||
})
|
})
|
||||||
@ -593,6 +606,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
|||||||
if ctrRunning {
|
if ctrRunning {
|
||||||
reports = append(reports, &entities.ContainerStartReport{
|
reports = append(reports, &entities.ContainerStartReport{
|
||||||
Id: ctr.ID(),
|
Id: ctr.ID(),
|
||||||
|
RawInput: rawInput,
|
||||||
Err: nil,
|
Err: nil,
|
||||||
ExitCode: 0,
|
ExitCode: 0,
|
||||||
})
|
})
|
||||||
@ -602,6 +616,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
reports = append(reports, &entities.ContainerStartReport{
|
reports = append(reports, &entities.ContainerStartReport{
|
||||||
Id: ctr.ID(),
|
Id: ctr.ID(),
|
||||||
|
RawInput: rawInput,
|
||||||
Err: err,
|
Err: err,
|
||||||
ExitCode: exitCode,
|
ExitCode: exitCode,
|
||||||
})
|
})
|
||||||
@ -624,6 +639,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
|||||||
}
|
}
|
||||||
reports = append(reports, &entities.ContainerStartReport{
|
reports = append(reports, &entities.ContainerStartReport{
|
||||||
Id: ctr.ID(),
|
Id: ctr.ID(),
|
||||||
|
RawInput: rawInput,
|
||||||
Err: err,
|
Err: err,
|
||||||
ExitCode: exitCode,
|
ExitCode: exitCode,
|
||||||
})
|
})
|
||||||
@ -636,6 +652,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
|||||||
// If the container is in a pod, also set to recursively start dependencies
|
// If the container is in a pod, also set to recursively start dependencies
|
||||||
report := &entities.ContainerStartReport{
|
report := &entities.ContainerStartReport{
|
||||||
Id: ctr.ID(),
|
Id: ctr.ID(),
|
||||||
|
RawInput: rawInput,
|
||||||
ExitCode: 125,
|
ExitCode: 125,
|
||||||
}
|
}
|
||||||
if err := ctr.Start(ctx, ctr.PodID() != ""); err != nil {
|
if err := ctr.Start(ctx, ctr.PodID() != ""); err != nil {
|
||||||
|
Reference in New Issue
Block a user