mirror of
https://gitea.elkins.co/Networking/ccl.git
synced 2025-03-09 12:41:40 -05:00
Multithread all libpod actions
This commit is contained in:
parent
515929fd8f
commit
4f78efe42c
@ -22,7 +22,9 @@ THE SOFTWARE.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/command"
|
||||||
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/container"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,11 +38,7 @@ var createCmd = &cobra.Command{
|
|||||||
names or categories. Multiple arguments are supported.`,
|
names or categories. Multiple arguments are supported.`,
|
||||||
Run: func(_ *cobra.Command, args []string) {
|
Run: func(_ *cobra.Command, args []string) {
|
||||||
conts := config.Union(args, contMask)
|
conts := config.Union(args, contMask)
|
||||||
for _, cont := range conts {
|
getAndExecute("CREATE", conts, func(c *container.Container) command.Commands { return c.CreateCommands() })
|
||||||
if err := getAndExecute(cont.CreateCommands, "CREATE", cont.Name, output, fake); err != nil {
|
|
||||||
cont.LogEntry().WithField("error", err).Errorln("Create failed")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,15 +23,27 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"sync"
|
||||||
|
|
||||||
"gitea.elkins.co/Networking/ccl/internal/pkg/command"
|
"gitea.elkins.co/Networking/ccl/internal/pkg/command"
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/container"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getAndExecute(getCmds func() command.Commands, action, label string, output io.Writer, fake bool) error {
|
func getAndExecute(action string, tgts []container.Container, getCmds func(*container.Container) command.Commands) {
|
||||||
fmt.Fprintln(output, action, label)
|
var wg sync.WaitGroup
|
||||||
if err := getCmds().Execute(output, fake); err != nil {
|
for i := range tgts {
|
||||||
return err
|
fmt.Fprintln(output, action, tgts[i].Name)
|
||||||
|
wg.Add(1)
|
||||||
|
go func(cont *container.Container) {
|
||||||
|
defer wg.Done()
|
||||||
|
for _, cmd := range getCmds(cont) {
|
||||||
|
if err := cmd.Execute(output, fake); err != nil {
|
||||||
|
cont.LogEntry().WithField("error", err).Errorln("Could not", action)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}(&tgts[i])
|
||||||
}
|
}
|
||||||
return nil
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,9 @@ THE SOFTWARE.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/command"
|
||||||
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/container"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,11 +39,7 @@ affected: the old image will still remain, though untagged, and any defined cont
|
|||||||
will still use it.`,
|
will still use it.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
conts := config.Union(args, contMask)
|
conts := config.Union(args, contMask)
|
||||||
for _, cont := range conts {
|
getAndExecute("PULL", conts, func(c *container.Container) command.Commands { return c.PullCommands() })
|
||||||
if err := getAndExecute(cont.PullCommands, "PULL", cont.Name, output, fake); err != nil {
|
|
||||||
cont.LogEntry().WithField("error", err).Errorln("Pull failed")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,9 @@ THE SOFTWARE.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/command"
|
||||||
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/container"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,11 +38,7 @@ var recreateCmd = &cobra.Command{
|
|||||||
one or more container names or categories. If empty, "all" is assumed.`,
|
one or more container names or categories. If empty, "all" is assumed.`,
|
||||||
Run: func(_ *cobra.Command, args []string) {
|
Run: func(_ *cobra.Command, args []string) {
|
||||||
conts := config.Union(args, contMask)
|
conts := config.Union(args, contMask)
|
||||||
for _, cont := range conts {
|
getAndExecute("RECREATE", conts, func(c *container.Container) command.Commands { return c.RecreateCommands() })
|
||||||
if err := getAndExecute(cont.RecreateCommands, "RECREATE", cont.Name, output, fake); err != nil {
|
|
||||||
cont.LogEntry().WithField("error", err).Errorln("Recreation failed")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,9 @@ THE SOFTWARE.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/command"
|
||||||
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/container"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,11 +38,7 @@ var restartCmd = &cobra.Command{
|
|||||||
one or more container names or categories. If empty, "all" is assumed.`,
|
one or more container names or categories. If empty, "all" is assumed.`,
|
||||||
Run: func(_ *cobra.Command, args []string) {
|
Run: func(_ *cobra.Command, args []string) {
|
||||||
conts := config.Union(args, contMask)
|
conts := config.Union(args, contMask)
|
||||||
for _, cont := range conts {
|
getAndExecute("RESTART", conts, func(c *container.Container) command.Commands { return c.RestartCommands() })
|
||||||
if err := getAndExecute(cont.RestartCommands, "RESTART", cont.Name, output, fake); err != nil {
|
|
||||||
cont.LogEntry().WithField("error", err).Errorln("Restart failed")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,9 @@ THE SOFTWARE.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/command"
|
||||||
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/container"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,11 +39,7 @@ var rmCmd = &cobra.Command{
|
|||||||
If running, they will first be stopped.`,
|
If running, they will first be stopped.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
conts := config.Union(args, contMask)
|
conts := config.Union(args, contMask)
|
||||||
for _, cont := range conts {
|
getAndExecute("REMOVE", conts, func(c *container.Container) command.Commands { return c.DestroyCommands() })
|
||||||
if err := getAndExecute(cont.DestroyCommands, "REMOVE", cont.Name, output, fake); err != nil {
|
|
||||||
cont.LogEntry().WithField("error", err).Errorln("Remove failed")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,9 @@ THE SOFTWARE.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/command"
|
||||||
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/container"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,11 +38,7 @@ var startCmd = &cobra.Command{
|
|||||||
one or more container names or categories. If empty, "all" is assumed.`,
|
one or more container names or categories. If empty, "all" is assumed.`,
|
||||||
Run: func(_ *cobra.Command, args []string) {
|
Run: func(_ *cobra.Command, args []string) {
|
||||||
conts := config.Union(args, contMask)
|
conts := config.Union(args, contMask)
|
||||||
for _, cont := range conts {
|
getAndExecute("START", conts, func(c *container.Container) command.Commands { return c.StartCommands() })
|
||||||
if err := getAndExecute(cont.StartCommands, "START", cont.Name, output, fake); err != nil {
|
|
||||||
cont.LogEntry().WithField("error", err).Errorln("Start failed")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,9 @@ THE SOFTWARE.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/command"
|
||||||
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/container"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,11 +38,7 @@ var stopCmd = &cobra.Command{
|
|||||||
one or more container names or categories. If empty, "all" is assumed.`,
|
one or more container names or categories. If empty, "all" is assumed.`,
|
||||||
Run: func(_ *cobra.Command, args []string) {
|
Run: func(_ *cobra.Command, args []string) {
|
||||||
conts := config.Union(args, contMask)
|
conts := config.Union(args, contMask)
|
||||||
for _, cont := range conts {
|
getAndExecute("STOP", conts, func(c *container.Container) command.Commands { return c.StopCommands() })
|
||||||
if err := getAndExecute(cont.StopCommands, "STOP", cont.Name, output, fake); err != nil {
|
|
||||||
cont.LogEntry().WithField("error", err).Errorln("Stop failed")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,9 @@ THE SOFTWARE.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/command"
|
||||||
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
"gitea.elkins.co/Networking/ccl/internal/pkg/config"
|
||||||
|
"gitea.elkins.co/Networking/ccl/internal/pkg/container"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,11 +38,7 @@ var updateCmd = &cobra.Command{
|
|||||||
one or more container names or categories. If empty, "all" is assumed.`,
|
one or more container names or categories. If empty, "all" is assumed.`,
|
||||||
Run: func(_ *cobra.Command, args []string) {
|
Run: func(_ *cobra.Command, args []string) {
|
||||||
conts := config.Union(args, contMask)
|
conts := config.Union(args, contMask)
|
||||||
for _, cont := range conts {
|
getAndExecute("UPDATE", conts, func(c *container.Container) command.Commands { return c.UpdateCommands() })
|
||||||
if err := getAndExecute(cont.UpdateCommands, "UPDATE", cont.Name, output, fake); err != nil {
|
|
||||||
cont.LogEntry().WithField("error", err).Errorln("Update failed")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user