Clean up show toml format

This commit is contained in:
Joel Elkins 2022-07-27 21:49:30 -05:00
parent ddd391c8b0
commit a501fb0308
No known key found for this signature in database
GPG Key ID: 133589DC38921AE2
3 changed files with 24 additions and 30 deletions

View File

@ -41,7 +41,7 @@ var showCmd = &cobra.Command{
to use as a ccl config file.`,
Run: func(cmd *cobra.Command, args []string) {
type parse struct {
Containers []container.Container
Containers []container.Container `toml:"containers,omitempty"`
}
conts := config.Union(args, contMask)

View File

@ -36,21 +36,22 @@ import (
"github.com/containers/podman/v4/pkg/specgen"
spec "github.com/opencontainers/runtime-spec/specs-go"
log "github.com/sirupsen/logrus"
"gopkg.in/guregu/null.v4"
)
type Container struct {
Category string
Name string
Image string
Hostname string
Command []string
Arguments string
Networks []network.Network
Env map[string]string
Mounts []spec.Mount
Restart string
Umask uint
User string
Category string `toml:"category"`
Name string `toml:"name"`
Image string `toml:"image"`
Hostname string `toml:"hostname,omitempty"`
Command []string `toml:"command,omitempty"`
Arguments string `toml:"arguments,omitempty"`
Networks []network.Network `toml:"networks,omitempty"`
Env map[string]string `toml:"env,omitempty"`
Mounts []spec.Mount `toml:"mounts,omitempty"`
Restart string `toml:"restart,omitempty"`
Umask null.Int `toml:"umask,omitempty"`
User string `toml:"user,omitempty"`
conn context.Context
cdata *define.InspectContainerData
@ -86,8 +87,8 @@ func (c *Container) Init(conn context.Context, nets []network.Network) error {
}
c.conn = conn
if c.Umask == 0 {
c.Umask = 0o022
if !c.Umask.Valid {
c.Umask.SetValid(0o022)
}
return c.populateCData()
}
@ -108,10 +109,6 @@ func (c *Container) LogEntry() *log.Entry {
func (c *Container) pull() error {
_, err := images.Pull(c.conn, c.Image, &images.PullOptions{})
return err
// if err != nil {
// return err
// }
// return c.populateCData()
}
func (c *Container) PullCommands() []command.Command {
@ -172,7 +169,7 @@ func (c *Container) CreateCommands() []command.Command {
},
ContainerSecurityConfig: specgen.ContainerSecurityConfig{
User: c.User,
Umask: fmt.Sprintf("%#o", c.Umask),
Umask: fmt.Sprintf("%#o", c.Umask.Int64),
},
}
if err := spec.Validate(); err != nil {
@ -323,7 +320,7 @@ func (c *Container) UpdateCommands() []command.Command {
func (c *Container) StopCommands() []command.Command {
return []command.Command{
command.NewErrFunc("do_stop", func() error {
command.NewErrFunc("stop_if_running", func() error {
if c.IsRunning() {
var timeout uint = 10
err := containers.Stop(c.conn, c.cdata.ID, &containers.StopOptions{Timeout: &timeout})
@ -336,10 +333,7 @@ func (c *Container) StopCommands() []command.Command {
}
return c.populateCData()
}
log.WithFields(log.Fields{
"container": c.Name,
"id": c.cdata.ID,
}).Debugf("Container stopped but wasn't running. Not a problem.")
c.LogEntry().Debugf("Container stopped but wasn't running. Not a problem.")
return nil
}),
}

View File

@ -28,9 +28,9 @@ import (
)
type Network struct {
Name string
DNS []net.IP
IPv6 null.Bool `toml:"ipv6"`
IPv4Address net.IP `toml:"ipv4_address"`
IPv6Address net.IP `toml:"ipv6_address"`
Name string `toml:"name"`
DNS []net.IP `toml:"dns,omitempty"`
IPv6 null.Bool `toml:"ipv6,omitempty"`
IPv4Address net.IP `toml:"ipv4_address,omitempty"`
IPv6Address net.IP `toml:"ipv6_address,omitempty"`
}