diff options
Diffstat (limited to 'cmd/podmanV2/common')
-rw-r--r-- | cmd/podmanV2/common/inspect.go | 18 | ||||
-rw-r--r-- | cmd/podmanV2/common/netflags.go | 108 | ||||
-rw-r--r-- | cmd/podmanV2/common/types.go | 3 | ||||
-rw-r--r-- | cmd/podmanV2/common/util.go | 43 |
4 files changed, 0 insertions, 172 deletions
diff --git a/cmd/podmanV2/common/inspect.go b/cmd/podmanV2/common/inspect.go deleted file mode 100644 index dfc6fe679..000000000 --- a/cmd/podmanV2/common/inspect.go +++ /dev/null @@ -1,18 +0,0 @@ -package common - -import ( - "github.com/containers/libpod/pkg/domain/entities" - "github.com/spf13/cobra" -) - -// AddInspectFlagSet takes a command and adds the inspect flags and returns an InspectOptions object -// Since this cannot live in `package main` it lives here until a better home is found -func AddInspectFlagSet(cmd *cobra.Command) *entities.InspectOptions { - opts := entities.InspectOptions{} - - flags := cmd.Flags() - flags.BoolVarP(&opts.Size, "size", "s", false, "Display total file size") - flags.StringVarP(&opts.Format, "format", "f", "", "Change the output format to a Go template") - - return &opts -} diff --git a/cmd/podmanV2/common/netflags.go b/cmd/podmanV2/common/netflags.go deleted file mode 100644 index 758f155c8..000000000 --- a/cmd/podmanV2/common/netflags.go +++ /dev/null @@ -1,108 +0,0 @@ -package common - -import ( - "net" - - "github.com/containers/libpod/pkg/domain/entities" - "github.com/containers/libpod/pkg/rootless" - "github.com/spf13/cobra" - "github.com/spf13/pflag" -) - -func getDefaultNetwork() string { - if rootless.IsRootless() { - return "slirp4netns" - } - return "bridge" -} - -func GetNetFlags() *pflag.FlagSet { - netFlags := pflag.FlagSet{} - netFlags.StringSlice( - "add-host", []string{}, - "Add a custom host-to-IP mapping (host:ip) (default [])", - ) - netFlags.StringSlice( - "dns", []string{}, - "Set custom DNS servers", - ) - netFlags.StringSlice( - "dns-opt", []string{}, - "Set custom DNS options", - ) - netFlags.StringSlice( - "dns-search", []string{}, - "Set custom DNS search domains", - ) - netFlags.String( - "ip", "", - "Specify a static IPv4 address for the container", - ) - netFlags.String( - "mac-address", "", - "Container MAC address (e.g. 92:d0:c6:0a:29:33)", - ) - netFlags.String( - "network", getDefaultNetwork(), - "Connect a container to a network", - ) - netFlags.StringSliceP( - "publish", "p", []string{}, - "Publish a container's port, or a range of ports, to the host (default [])", - ) - netFlags.Bool( - "no-hosts", false, - "Do not create /etc/hosts within the container, instead use the version from the image", - ) - return &netFlags -} - -func NetFlagsToNetOptions(cmd *cobra.Command) (*entities.NetOptions, error) { - var ( - err error - ) - opts := entities.NetOptions{} - opts.AddHosts, err = cmd.Flags().GetStringSlice("add-host") - if err != nil { - return nil, err - } - servers, err := cmd.Flags().GetStringSlice("dns") - if err != nil { - return nil, err - } - for _, d := range servers { - if d == "none" { - opts.DNSHost = true - break - } - opts.DNSServers = append(opts.DNSServers, net.ParseIP(d)) - } - opts.DNSSearch, err = cmd.Flags().GetStringSlice("dns-search") - if err != nil { - return nil, err - } - - m, err := cmd.Flags().GetString("mac-address") - if err != nil { - return nil, err - } - if len(m) > 0 { - mac, err := net.ParseMAC(m) - if err != nil { - return nil, err - } - opts.StaticMAC = &mac - } - inputPorts, err := cmd.Flags().GetStringSlice("publish") - if err != nil { - return nil, err - } - if len(inputPorts) > 0 { - opts.PublishPorts, err = createPortBindings(inputPorts) - if err != nil { - return nil, err - } - } - opts.NoHosts, err = cmd.Flags().GetBool("no-hosts") - return &opts, err -} diff --git a/cmd/podmanV2/common/types.go b/cmd/podmanV2/common/types.go deleted file mode 100644 index 2427ae975..000000000 --- a/cmd/podmanV2/common/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package common - -var DefaultKernelNamespaces = "cgroup,ipc,net,uts" diff --git a/cmd/podmanV2/common/util.go b/cmd/podmanV2/common/util.go deleted file mode 100644 index 47bbe12fa..000000000 --- a/cmd/podmanV2/common/util.go +++ /dev/null @@ -1,43 +0,0 @@ -package common - -import ( - "strconv" - - "github.com/cri-o/ocicni/pkg/ocicni" - "github.com/docker/go-connections/nat" - "github.com/pkg/errors" -) - -// createPortBindings iterates ports mappings and exposed ports into a format CNI understands -func createPortBindings(ports []string) ([]ocicni.PortMapping, error) { - // TODO wants someone to rewrite this code in the future - var portBindings []ocicni.PortMapping - // The conversion from []string to natBindings is temporary while mheon reworks the port - // deduplication code. Eventually that step will not be required. - _, natBindings, err := nat.ParsePortSpecs(ports) - if err != nil { - return nil, err - } - for containerPb, hostPb := range natBindings { - var pm ocicni.PortMapping - pm.ContainerPort = int32(containerPb.Int()) - for _, i := range hostPb { - var hostPort int - var err error - pm.HostIP = i.HostIP - if i.HostPort == "" { - hostPort = containerPb.Int() - } else { - hostPort, err = strconv.Atoi(i.HostPort) - if err != nil { - return nil, errors.Wrapf(err, "unable to convert host port to integer") - } - } - - pm.HostPort = int32(hostPort) - pm.Protocol = containerPb.Proto() - portBindings = append(portBindings, pm) - } - } - return portBindings, nil -} |