finish work
This commit is contained in:
parent
cc8e04a41f
commit
16e779a450
27
client.go
27
client.go
@ -1,27 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import "github.com/containers/podman/v5/libpod/define"
|
|
||||||
|
|
||||||
type clientInfo struct {
|
|
||||||
OSArch string `json:"OS"`
|
|
||||||
Provider string `json:"provider"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
BuildOrigin string `json:"buildOrigin,omitempty" yaml:",omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func getClientInfo() (*clientInfo, error) {
|
|
||||||
p, err := getProvider()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
vinfo, err := define.GetVersion()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &clientInfo{
|
|
||||||
OSArch: vinfo.OsArch,
|
|
||||||
Provider: p,
|
|
||||||
Version: vinfo.Version,
|
|
||||||
BuildOrigin: vinfo.BuildOrigin,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
//go:build amd64 || arm64
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/containers/podman/v5/pkg/machine/provider"
|
|
||||||
)
|
|
||||||
|
|
||||||
func getProvider() (string, error) {
|
|
||||||
p, err := provider.Get()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return p.VMType().String(), nil
|
|
||||||
}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
func setRLimits() error {
|
|
||||||
rlimits := new(syscall.Rlimit)
|
|
||||||
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, rlimits); err != nil {
|
|
||||||
return fmt.Errorf("getting rlimits: %w", err)
|
|
||||||
}
|
|
||||||
rlimits.Cur = rlimits.Max
|
|
||||||
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, rlimits); err != nil {
|
|
||||||
return fmt.Errorf("setting new rlimits: %w", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setUMask() {
|
|
||||||
// Be sure we can create directories with 0755 mode.
|
|
||||||
syscall.Umask(0022)
|
|
||||||
}
|
|
||||||
|
|
||||||
func earlyInitHook() {
|
|
||||||
if err := setRLimits(); err != nil {
|
|
||||||
logrus.Errorf("Failed to set rlimits: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
setUMask()
|
|
||||||
}
|
|
||||||
8
go.mod
8
go.mod
@ -14,7 +14,6 @@ require (
|
|||||||
github.com/samber/lo v1.49.1
|
github.com/samber/lo v1.49.1
|
||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/sirupsen/logrus v1.9.3
|
||||||
github.com/spf13/cobra v1.9.1
|
github.com/spf13/cobra v1.9.1
|
||||||
github.com/spf13/pflag v1.0.6
|
|
||||||
github.com/vishvananda/netlink v1.3.1-0.20240922070040-084abd93d350
|
github.com/vishvananda/netlink v1.3.1-0.20240922070040-084abd93d350
|
||||||
go.uber.org/zap v1.27.0
|
go.uber.org/zap v1.27.0
|
||||||
sigs.k8s.io/yaml v1.4.0
|
sigs.k8s.io/yaml v1.4.0
|
||||||
@ -99,7 +98,6 @@ require (
|
|||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/go-playground/validator/v10 v10.20.0 // indirect
|
github.com/go-playground/validator/v10 v10.20.0 // indirect
|
||||||
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
|
|
||||||
github.com/goccy/go-json v0.10.2 // indirect
|
github.com/goccy/go-json v0.10.2 // indirect
|
||||||
github.com/godbus/dbus/v5 v5.1.1-0.20241109141217-c266b19b28e9 // indirect
|
github.com/godbus/dbus/v5 v5.1.1-0.20241109141217-c266b19b28e9 // indirect
|
||||||
github.com/gogo/protobuf v1.3.2 // indirect
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
@ -108,7 +106,6 @@ require (
|
|||||||
github.com/google/go-containerregistry v0.20.2 // indirect
|
github.com/google/go-containerregistry v0.20.2 // indirect
|
||||||
github.com/google/go-intervals v0.0.2 // indirect
|
github.com/google/go-intervals v0.0.2 // indirect
|
||||||
github.com/google/gofuzz v1.2.0 // indirect
|
github.com/google/gofuzz v1.2.0 // indirect
|
||||||
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
|
|
||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/gorilla/handlers v1.5.2 // indirect
|
github.com/gorilla/handlers v1.5.2 // indirect
|
||||||
@ -154,7 +151,6 @@ require (
|
|||||||
github.com/morikuni/aec v1.0.0 // indirect
|
github.com/morikuni/aec v1.0.0 // indirect
|
||||||
github.com/nxadm/tail v1.4.11 // indirect
|
github.com/nxadm/tail v1.4.11 // indirect
|
||||||
github.com/oklog/ulid v1.3.1 // indirect
|
github.com/oklog/ulid v1.3.1 // indirect
|
||||||
github.com/onsi/ginkgo/v2 v2.22.2 // indirect
|
|
||||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||||
github.com/opencontainers/image-spec v1.1.0 // indirect
|
github.com/opencontainers/image-spec v1.1.0 // indirect
|
||||||
github.com/opencontainers/runc v1.2.4 // indirect
|
github.com/opencontainers/runc v1.2.4 // indirect
|
||||||
@ -171,7 +167,6 @@ require (
|
|||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
||||||
github.com/proglottis/gpgme v0.1.4 // indirect
|
github.com/proglottis/gpgme v0.1.4 // indirect
|
||||||
github.com/quic-go/quic-go v0.50.1 // indirect
|
|
||||||
github.com/rivo/uniseg v0.4.7 // indirect
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
github.com/seccomp/libseccomp-golang v0.10.0 // indirect
|
github.com/seccomp/libseccomp-golang v0.10.0 // indirect
|
||||||
github.com/secure-systems-lab/go-securesystemslib v0.9.0 // indirect
|
github.com/secure-systems-lab/go-securesystemslib v0.9.0 // indirect
|
||||||
@ -183,6 +178,7 @@ require (
|
|||||||
github.com/skeema/knownhosts v1.3.0 // indirect
|
github.com/skeema/knownhosts v1.3.0 // indirect
|
||||||
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect
|
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect
|
||||||
github.com/smallstep/pkcs7 v0.1.1 // indirect
|
github.com/smallstep/pkcs7 v0.1.1 // indirect
|
||||||
|
github.com/spf13/pflag v1.0.6 // indirect
|
||||||
github.com/stefanberger/go-pkcs11uri v0.0.0-20230803200340-78284954bff6 // indirect
|
github.com/stefanberger/go-pkcs11uri v0.0.0-20230803200340-78284954bff6 // indirect
|
||||||
github.com/sylabs/sif/v2 v2.20.2 // indirect
|
github.com/sylabs/sif/v2 v2.20.2 // indirect
|
||||||
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
|
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
|
||||||
@ -204,7 +200,6 @@ require (
|
|||||||
go.opentelemetry.io/otel v1.31.0 // indirect
|
go.opentelemetry.io/otel v1.31.0 // indirect
|
||||||
go.opentelemetry.io/otel/metric v1.31.0 // indirect
|
go.opentelemetry.io/otel/metric v1.31.0 // indirect
|
||||||
go.opentelemetry.io/otel/trace v1.31.0 // indirect
|
go.opentelemetry.io/otel/trace v1.31.0 // indirect
|
||||||
go.uber.org/mock v0.5.0 // indirect
|
|
||||||
go.uber.org/multierr v1.11.0 // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
golang.org/x/arch v0.8.0 // indirect
|
golang.org/x/arch v0.8.0 // indirect
|
||||||
golang.org/x/crypto v0.35.0 // indirect
|
golang.org/x/crypto v0.35.0 // indirect
|
||||||
@ -217,7 +212,6 @@ require (
|
|||||||
golang.org/x/term v0.29.0 // indirect
|
golang.org/x/term v0.29.0 // indirect
|
||||||
golang.org/x/text v0.22.0 // indirect
|
golang.org/x/text v0.22.0 // indirect
|
||||||
golang.org/x/time v0.9.0 // indirect
|
golang.org/x/time v0.9.0 // indirect
|
||||||
golang.org/x/tools v0.28.0 // indirect
|
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250102185135-69823020774d // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250102185135-69823020774d // indirect
|
||||||
google.golang.org/grpc v1.69.4 // indirect
|
google.golang.org/grpc v1.69.4 // indirect
|
||||||
google.golang.org/protobuf v1.36.3 // indirect
|
google.golang.org/protobuf v1.36.3 // indirect
|
||||||
|
|||||||
8
go.sum
8
go.sum
@ -106,7 +106,6 @@ github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f h1:JOrtw2xFKzlg+
|
|||||||
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||||
github.com/coreos/go-systemd/v22 v22.5.1-0.20231103132048-7d375ecc2b09 h1:OoRAFlvDGCUqDLampLQjk0yeeSGdF9zzst/3G9IkBbc=
|
github.com/coreos/go-systemd/v22 v22.5.1-0.20231103132048-7d375ecc2b09 h1:OoRAFlvDGCUqDLampLQjk0yeeSGdF9zzst/3G9IkBbc=
|
||||||
github.com/coreos/go-systemd/v22 v22.5.1-0.20231103132048-7d375ecc2b09/go.mod h1:m2r/smMKsKwgMSAoFKHaa68ImdCSNuKE1MxvQ64xuCQ=
|
github.com/coreos/go-systemd/v22 v22.5.1-0.20231103132048-7d375ecc2b09/go.mod h1:m2r/smMKsKwgMSAoFKHaa68ImdCSNuKE1MxvQ64xuCQ=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||||
github.com/crc-org/crc/v2 v2.45.0 h1:7rScVQwFc3oy99SaiGSgQmTiIQf7UKKYIcZQ963NsdE=
|
github.com/crc-org/crc/v2 v2.45.0 h1:7rScVQwFc3oy99SaiGSgQmTiIQf7UKKYIcZQ963NsdE=
|
||||||
github.com/crc-org/crc/v2 v2.45.0/go.mod h1:ALUixzv85cMYNDEqone8jEn3m2ZKyu9oRzrQdEAjnzk=
|
github.com/crc-org/crc/v2 v2.45.0/go.mod h1:ALUixzv85cMYNDEqone8jEn3m2ZKyu9oRzrQdEAjnzk=
|
||||||
@ -426,8 +425,6 @@ github.com/prometheus/common v0.57.0 h1:Ro/rKjwdq9mZn1K5QPctzh+MA4Lp0BuYk5ZZEVho
|
|||||||
github.com/prometheus/common v0.57.0/go.mod h1:7uRPFSUTbfZWsJ7MHY56sqt7hLQu3bxXHDnNhl8E9qI=
|
github.com/prometheus/common v0.57.0/go.mod h1:7uRPFSUTbfZWsJ7MHY56sqt7hLQu3bxXHDnNhl8E9qI=
|
||||||
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
||||||
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
||||||
github.com/quic-go/quic-go v0.50.1 h1:unsgjFIUqW8a2oopkY7YNONpV1gYND6Nt9hnt1PN94Q=
|
|
||||||
github.com/quic-go/quic-go v0.50.1/go.mod h1:Vim6OmUvlYdwBhXP9ZVrtGmCMWa3wEqhq3NgYrI8b4E=
|
|
||||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
@ -462,11 +459,8 @@ github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EE
|
|||||||
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog=
|
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog=
|
||||||
github.com/smallstep/pkcs7 v0.1.1 h1:x+rPdt2W088V9Vkjho4KtoggyktZJlMduZAtRHm68LU=
|
github.com/smallstep/pkcs7 v0.1.1 h1:x+rPdt2W088V9Vkjho4KtoggyktZJlMduZAtRHm68LU=
|
||||||
github.com/smallstep/pkcs7 v0.1.1/go.mod h1:dL6j5AIz9GHjVEBTXtW+QliALcgM19RtXaTeyxI+AfA=
|
github.com/smallstep/pkcs7 v0.1.1/go.mod h1:dL6j5AIz9GHjVEBTXtW+QliALcgM19RtXaTeyxI+AfA=
|
||||||
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
|
|
||||||
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
|
|
||||||
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
|
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
|
||||||
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
|
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
|
||||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
|
||||||
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
|
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
|
||||||
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
github.com/stefanberger/go-pkcs11uri v0.0.0-20230803200340-78284954bff6 h1:pnnLyeX7o/5aX8qUQ69P/mLojDqwda8hFOCBTmP/6hw=
|
github.com/stefanberger/go-pkcs11uri v0.0.0-20230803200340-78284954bff6 h1:pnnLyeX7o/5aX8qUQ69P/mLojDqwda8hFOCBTmP/6hw=
|
||||||
@ -559,8 +553,6 @@ go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeX
|
|||||||
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
|
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
|
||||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||||
go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
|
|
||||||
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
|
|
||||||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||||
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||||
|
|||||||
@ -16,6 +16,8 @@ type Create struct {
|
|||||||
Network string `json:"network,required"`
|
Network string `json:"network,required"`
|
||||||
Port string `json:"port,omitempty"`
|
Port string `json:"port,omitempty"`
|
||||||
Start bool `json:"start,omitempty"`
|
Start bool `json:"start,omitempty"`
|
||||||
|
Volume string `json:"volume,omitzero"`
|
||||||
|
Source string `json:"source,omitzero"`
|
||||||
}
|
}
|
||||||
type CreateJson struct {
|
type CreateJson struct {
|
||||||
Cause string `json:"cause"`
|
Cause string `json:"cause"`
|
||||||
@ -33,6 +35,11 @@ type create struct {
|
|||||||
} `json:"netns"`
|
} `json:"netns"`
|
||||||
Port []PortMapping `json:"portmappings"`
|
Port []PortMapping `json:"portmappings"`
|
||||||
Networks map[string]NetSettings `json:"networks"`
|
Networks map[string]NetSettings `json:"networks"`
|
||||||
|
Volumes []VolumeMap `json:"volumes,omitzero"`
|
||||||
|
}
|
||||||
|
type VolumeMap struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Dest string `json:"dest"`
|
||||||
}
|
}
|
||||||
type NetSettings struct {
|
type NetSettings struct {
|
||||||
Aliases []string `json:"aliases,omitempty"`
|
Aliases []string `json:"aliases,omitempty"`
|
||||||
@ -60,10 +67,14 @@ func (c *Create) Create() (string, error) {
|
|||||||
ContainerPort: port2,
|
ContainerPort: port2,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
container.Networks = make(map[string]NetSettings)
|
if c.Source != c.Volume {
|
||||||
container.Networks["podman"] = NetSettings{
|
container.Volumes = append(container.Volumes, VolumeMap{
|
||||||
InterfaceName: "ens0",
|
Name: c.Volume,
|
||||||
|
Dest: c.Source,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
container.Networks = make(map[string]NetSettings)
|
||||||
|
container.Networks["podman"] = NetSettings{}
|
||||||
for k, v := range strings.Split(c.Network, ",") {
|
for k, v := range strings.Split(c.Network, ",") {
|
||||||
log.Println(v)
|
log.Println(v)
|
||||||
container.Networks[v] = NetSettings{
|
container.Networks[v] = NetSettings{
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
package network
|
package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"floares/config"
|
"floares/config"
|
||||||
|
"floares/lib/model"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/go-jose/go-jose/v3/json"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -29,11 +32,26 @@ func DisConnect(ns string, id string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func Connect(ns string, id string) (err error) {
|
type ConnectInfo struct {
|
||||||
reader := strings.NewReader(fmt.Sprintf(`{
|
ContainerID string `json:"container"`
|
||||||
"container":"%s"
|
Aliases []string `json:"aliases,aliases"`
|
||||||
}`, id))
|
StaticIPs []string `json:"static_ips,omitempty"`
|
||||||
req, _ := http.NewRequest(http.MethodPost, config.Entrypoint+"/v4.0.0/libpod/networks/"+ns+"/connect", reader)
|
StaticMac string `json:"static_mac,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func Connect(ns string, r model.ConnectRequest) (err error) {
|
||||||
|
var con ConnectInfo
|
||||||
|
con.ContainerID = r.Id
|
||||||
|
if r.Ip != "" {
|
||||||
|
con.StaticIPs = strings.Split(r.Ip, ",")
|
||||||
|
}
|
||||||
|
if r.Alias != "" {
|
||||||
|
con.Aliases = strings.Split(r.Alias, ",")
|
||||||
|
}
|
||||||
|
con.StaticMac = r.Mac
|
||||||
|
b, _ := json.Marshal(&con)
|
||||||
|
fmt.Println(string(b))
|
||||||
|
req, _ := http.NewRequest(http.MethodPost, config.Entrypoint+"/v4.0.0/libpod/networks/"+ns+"/connect", bytes.NewReader(b))
|
||||||
res, err := http.DefaultClient.Do(req)
|
res, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("request for network list error:", err)
|
log.Println("request for network list error:", err)
|
||||||
|
|||||||
39
lib/http/network/create.go
Normal file
39
lib/http/network/create.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package network
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"floares/config"
|
||||||
|
"floares/lib/model"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Create(r model.CreateNetworkRequest) error {
|
||||||
|
var create CreatNet
|
||||||
|
create.DnsEnabled = r.EnableDns
|
||||||
|
create.Driver = "bridge"
|
||||||
|
create.Name = r.Name
|
||||||
|
if r.Subnet != "" {
|
||||||
|
create.Subnets = []SubNet{
|
||||||
|
{
|
||||||
|
Subnet: r.Subnet,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b, _ := json.Marshal(&create)
|
||||||
|
log.Println(string(b))
|
||||||
|
req, _ := http.NewRequest(http.MethodPost, config.Entrypoint+"/v4.0.0/libpod/networks/create", bytes.NewReader(b))
|
||||||
|
res, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
var e model.ErrInfo
|
||||||
|
json.NewDecoder(res.Body).Decode(&e)
|
||||||
|
if e.Response > 400 {
|
||||||
|
return errors.New(e.Message)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
63
lib/http/network/maker.go
Normal file
63
lib/http/network/maker.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package network
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"floares/config"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CreatNet struct {
|
||||||
|
Name string `json:"name,omitzero"`
|
||||||
|
Id string `json:"id,omitzero"`
|
||||||
|
Driver string `json:"driver,omitzero"`
|
||||||
|
NetworkInterface string `json:"network_interface,omitzero"`
|
||||||
|
Created time.Time `json:"created,omitzero"`
|
||||||
|
Subnets []SubNet `json:"subnets,omitzero"`
|
||||||
|
Ipv6Enabled bool `json:"ipv6_enabled,omitzero"`
|
||||||
|
Internal bool `json:"internal,omitzero"`
|
||||||
|
DnsEnabled bool `json:"dns_enabled,omitzero"`
|
||||||
|
IpamOptions struct {
|
||||||
|
Driver string `json:"driver,omitzero"`
|
||||||
|
} `json:"ipam_options,omitzero"`
|
||||||
|
}
|
||||||
|
type SubNet struct {
|
||||||
|
Subnet string `json:"subnet"`
|
||||||
|
Gateway string `json:"gateway"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func MakerNet(name string, id []string) (err error) {
|
||||||
|
var create CreatNet
|
||||||
|
create.DnsEnabled = true
|
||||||
|
create.Driver = "bridge"
|
||||||
|
create.Name = name
|
||||||
|
b, _ := json.Marshal(&create)
|
||||||
|
log.Println(string(b))
|
||||||
|
req, _ := http.NewRequest(http.MethodPost, config.Entrypoint+"/v4.0.0/libpod/networks/create", bytes.NewReader(b))
|
||||||
|
res, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("request for network list error:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
str, _ := io.ReadAll(res.Body)
|
||||||
|
log.Println(string(str))
|
||||||
|
}
|
||||||
|
log.Println(id)
|
||||||
|
var c ConnectInfo
|
||||||
|
for _, v := range id {
|
||||||
|
c.ContainerID = v
|
||||||
|
b, _ = json.Marshal(&c)
|
||||||
|
req, _ = http.NewRequest(http.MethodPost, config.Entrypoint+"/v4.0.0/libpod/networks/"+name+"/connect", bytes.NewReader(b))
|
||||||
|
_, err = http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
26
lib/http/network/remove.go
Normal file
26
lib/http/network/remove.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package network
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"floares/config"
|
||||||
|
"floares/lib/model"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Delete(ns string) error {
|
||||||
|
req, _ := http.NewRequest(http.MethodDelete, config.Entrypoint+"/v4.0.0/libpod/networks/"+ns, nil)
|
||||||
|
res, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
var e model.ErrInfo
|
||||||
|
json.NewDecoder(res.Body).Decode(&e)
|
||||||
|
if e.Response > 400 {
|
||||||
|
return errors.New(e.Message)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
40
lib/http/volume/create.go
Normal file
40
lib/http/volume/create.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package volume
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"floares/config"
|
||||||
|
"floares/lib/model"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Create(r model.CreateVolume) error {
|
||||||
|
b, _ := json.Marshal(&r)
|
||||||
|
req, _ := http.NewRequest(http.MethodPost, config.Entrypoint+"/v4.0.0/libpod/volumes/create", bytes.NewReader(b))
|
||||||
|
res, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var e model.ErrInfo
|
||||||
|
if err := json.NewDecoder(res.Body).Decode(&e); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if e.Cause != "" {
|
||||||
|
return errors.New(e.Cause)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
func Delete(name string) error {
|
||||||
|
req, _ := http.NewRequest(http.MethodDelete, config.Entrypoint+"/v4.0.0/libpod/volumes/"+name, nil)
|
||||||
|
res, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if res.StatusCode >= 300 {
|
||||||
|
return errors.New("delete failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
5
lib/libpod/const.go
Normal file
5
lib/libpod/const.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package libpod
|
||||||
|
|
||||||
|
const (
|
||||||
|
Defaultruntime = "youki"
|
||||||
|
)
|
||||||
74
lib/libpod/root.go
Normal file
74
lib/libpod/root.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package libpod
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/containers/podman/v5/pkg/parallel"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/containers/podman/v5/cmd/podman/registry"
|
||||||
|
"github.com/containers/podman/v5/pkg/domain/entities"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
defaultLogLevel = "warn"
|
||||||
|
logLevel = defaultLogLevel
|
||||||
|
dockerConfig = ""
|
||||||
|
debug bool
|
||||||
|
|
||||||
|
noStdout = false
|
||||||
|
useStdout = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
func persistentPreRunE(cmd *cobra.Command, args []string) error {
|
||||||
|
logrus.Infof("Called %s.PersistentPreRunE(%s)", cmd.Name(), strings.Join(os.Args, " "))
|
||||||
|
podmanConfig := registry.PodmanConfig()
|
||||||
|
c := &cobra.Command{}
|
||||||
|
if _, err := registry.NewImageEngine(c, args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := registry.NewContainerEngine(c, args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := os.LookupEnv("TMPDIR"); !ok {
|
||||||
|
if tmpdir, err := podmanConfig.ContainersConfDefaultsRO.ImageCopyTmpDir(); err != nil {
|
||||||
|
logrus.Warnf("Failed to retrieve default tmp dir: %s", err.Error())
|
||||||
|
} else {
|
||||||
|
os.Setenv("TMPDIR", tmpdir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_, found := c.Annotations[registry.ParentNSRequired]
|
||||||
|
if !registry.IsRemote() && !found {
|
||||||
|
cgroupMode := ""
|
||||||
|
_, noMoveProcess := c.Annotations[registry.NoMoveProcess]
|
||||||
|
if flag := c.LocalFlags().Lookup("cgroups"); flag != nil {
|
||||||
|
cgroupMode = flag.Value.String()
|
||||||
|
}
|
||||||
|
err := registry.ContainerEngine().SetupRootless(registry.Context(), noMoveProcess, cgroupMode)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupRuntime(podmanConfig *entities.PodmanConfig) {
|
||||||
|
podmanConfig.ContainersConf.Engine.DBBackend = podmanConfig.ContainersConfDefaultsRO.Engine.DBBackend
|
||||||
|
podmanConfig.ContainersConf.Engine.CgroupManager = podmanConfig.ContainersConfDefaultsRO.Engine.CgroupManager
|
||||||
|
podmanConfig.ContainersConf.Engine.NetworkCmdPath = podmanConfig.ContainersConfDefaultsRO.Engine.NetworkCmdPath
|
||||||
|
podmanConfig.ContainersConf.Network.NetworkConfigDir = podmanConfig.ContainersConfDefaultsRO.Network.NetworkConfigDir
|
||||||
|
podmanConfig.ContainersConf.Containers.DefaultMountsFile = podmanConfig.ContainersConfDefaultsRO.Containers.DefaultMountsFile
|
||||||
|
podmanConfig.ContainersConf.Engine.EventsLogger = podmanConfig.ContainersConfDefaultsRO.Engine.EventsLogger
|
||||||
|
podmanConfig.MaxWorks = (runtime.NumCPU() * 3) + 1
|
||||||
|
podmanConfig.ContainersConf.Engine.Namespace = podmanConfig.ContainersConfDefaultsRO.Engine.Namespace
|
||||||
|
podmanConfig.ContainersConf.Network.NetworkBackend = podmanConfig.ContainersConfDefaultsRO.Network.NetworkBackend
|
||||||
|
podmanConfig.RuntimePath = "youki"
|
||||||
|
podmanConfig.ContainersConf.Engine.TmpDir = podmanConfig.ContainersConfDefaultsRO.Engine.TmpDir
|
||||||
|
podmanConfig.Trace = true
|
||||||
|
podmanConfig.ContainersConf.Engine.VolumePath = podmanConfig.ContainersConfDefaultsRO.Engine.VolumePath
|
||||||
|
parallel.SetMaxThreads(uint(podmanConfig.MaxWorks))
|
||||||
|
}
|
||||||
40
lib/libpod/server.go
Normal file
40
lib/libpod/server.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package libpod
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"github.com/containers/podman/v5/cmd/podman/registry"
|
||||||
|
api "github.com/containers/podman/v5/pkg/api/server"
|
||||||
|
"github.com/containers/podman/v5/pkg/domain/entities"
|
||||||
|
"github.com/containers/podman/v5/pkg/domain/infra"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewServer() {
|
||||||
|
cmd := &cobra.Command{}
|
||||||
|
cfg := registry.PodmanConfig()
|
||||||
|
defaultConf := cfg.ContainersConfDefaultsRO
|
||||||
|
defaultConf.Engine.OCIRuntime = Defaultruntime
|
||||||
|
setupRuntime(cfg)
|
||||||
|
persistentPreRunE(cmd, nil)
|
||||||
|
libpodRuntime, err := infra.GetRuntime(registry.Context(), cmd.PersistentFlags(), cfg)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
listener, err := net.Listen("tcp", "127.0.0.1:8888")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
libpodRuntime.SetRemoteURI("tcp://localhost:8888")
|
||||||
|
infra.StartWatcher(libpodRuntime)
|
||||||
|
|
||||||
|
server, err := api.NewServerWithSettings(libpodRuntime, listener, entities.ServiceOptions{
|
||||||
|
URI: "tcp://localhost:8888",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
go server.Serve()
|
||||||
|
}
|
||||||
7
lib/model/err.go
Normal file
7
lib/model/err.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
type ErrInfo struct {
|
||||||
|
Cause string `json:"cause"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Response int `json:"response"`
|
||||||
|
}
|
||||||
@ -62,3 +62,14 @@ type NetConnect struct {
|
|||||||
Ip string `json:"ip"`
|
Ip string `json:"ip"`
|
||||||
Mac string `json:"mac"`
|
Mac string `json:"mac"`
|
||||||
}
|
}
|
||||||
|
type ConnectRequest struct {
|
||||||
|
Mac string `json:"mac"`
|
||||||
|
Ip string `json:"ip"`
|
||||||
|
Alias string `json:"alias"`
|
||||||
|
Id string `json:"id"`
|
||||||
|
}
|
||||||
|
type CreateNetworkRequest struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
EnableDns bool `json:"enable_dns"`
|
||||||
|
Subnet string `json:"subnet"`
|
||||||
|
}
|
||||||
|
|||||||
@ -11,3 +11,7 @@ type Volume struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Scope string `json:"scope"`
|
Scope string `json:"scope"`
|
||||||
}
|
}
|
||||||
|
type CreateVolume struct {
|
||||||
|
Name string
|
||||||
|
Type string
|
||||||
|
}
|
||||||
|
|||||||
51
main.go
51
main.go
@ -1,32 +1,25 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"floares/lib/libpod"
|
||||||
"floares/service/auth"
|
"floares/service/auth"
|
||||||
"floares/service/containers"
|
"floares/service/containers"
|
||||||
"floares/service/images"
|
"floares/service/images"
|
||||||
"floares/service/network"
|
"floares/service/network"
|
||||||
"floares/service/system"
|
"floares/service/system"
|
||||||
"github.com/containers/podman/v5/cmd/podman/registry"
|
|
||||||
api "github.com/containers/podman/v5/pkg/api/server"
|
|
||||||
"github.com/containers/podman/v5/pkg/domain/entities"
|
|
||||||
"github.com/containers/storage/pkg/reexec"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"net"
|
|
||||||
|
|
||||||
"floares/service/volume"
|
"floares/service/volume"
|
||||||
"github.com/containers/podman/v5/pkg/domain/infra"
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
if reexec.Init() {
|
//if reexec.Init() {
|
||||||
// We were invoked with a different argv[0] indicating that we
|
// // We were invoked with a different argv[0] indicating that we
|
||||||
// had a specific job to do as a subprocess, and it's done.
|
// // had a specific job to do as a subprocess, and it's done.
|
||||||
return
|
// return
|
||||||
}
|
//}
|
||||||
//c := cobra.Command{}
|
//c := cobra.Command{}
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
r.Use(func(c *gin.Context) {
|
r.Use(func(c *gin.Context) {
|
||||||
@ -53,32 +46,6 @@ func main() {
|
|||||||
images.RegisterRouter(r.Group("/images"))
|
images.RegisterRouter(r.Group("/images"))
|
||||||
network.RegisterRouter(r.Group("/network"))
|
network.RegisterRouter(r.Group("/network"))
|
||||||
volume.RegisterRouter(r.Group("/volumes"))
|
volume.RegisterRouter(r.Group("/volumes"))
|
||||||
//flags := flag.NewFlagSet("", flag.ExitOnError)
|
libpod.NewServer()
|
||||||
cmd := &cobra.Command{}
|
|
||||||
cfg := registry.PodmanConfig()
|
|
||||||
de := cfg.ContainersConfDefaultsRO
|
|
||||||
de.Engine.OCIRuntime = "youki"
|
|
||||||
rootFlags(cmd, cfg)
|
|
||||||
persistentPreRunE(cmd, nil)
|
|
||||||
log.Println(*cfg)
|
|
||||||
libpodRuntime, err := infra.GetRuntime(registry.Context(), cmd.PersistentFlags(), cfg)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
listener, err := net.Listen("tcp", "127.0.0.1:8888")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
libpodRuntime.SetRemoteURI("tcp://localhost:8888")
|
|
||||||
infra.StartWatcher(libpodRuntime)
|
|
||||||
|
|
||||||
server, err := api.NewServerWithSettings(libpodRuntime, listener, entities.ServiceOptions{
|
|
||||||
URI: "tcp://localhost:8888",
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
go server.Serve()
|
|
||||||
r.Run()
|
r.Run()
|
||||||
}
|
}
|
||||||
|
|||||||
485
root.go
485
root.go
@ -1,485 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"runtime"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/containers/common/pkg/ssh"
|
|
||||||
"github.com/containers/podman/v5/cmd/podman/common"
|
|
||||||
"github.com/containers/podman/v5/cmd/podman/registry"
|
|
||||||
"github.com/containers/podman/v5/pkg/bindings"
|
|
||||||
"github.com/containers/podman/v5/pkg/domain/entities"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"sigs.k8s.io/yaml"
|
|
||||||
)
|
|
||||||
|
|
||||||
// HelpTemplate is the help template for podman commands
|
|
||||||
// This uses the short and long options.
|
|
||||||
// command should not use this.
|
|
||||||
const helpTemplate = `{{.Short}}
|
|
||||||
|
|
||||||
Description:
|
|
||||||
{{.Long}}
|
|
||||||
|
|
||||||
{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
|
|
||||||
|
|
||||||
// UsageTemplate is the usage template for podman commands
|
|
||||||
// This blocks the displaying of the global options. The main podman
|
|
||||||
// command should not use this.
|
|
||||||
const usageTemplate = `Usage:{{if (and .Runnable (not .HasAvailableSubCommands))}}
|
|
||||||
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
|
|
||||||
{{.UseLine}} [command]{{end}}{{if gt (len .Aliases) 0}}
|
|
||||||
|
|
||||||
Aliases:
|
|
||||||
{{.NameAndAliases}}{{end}}{{if .HasExample}}
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
{{.Example}}{{end}}{{if .HasAvailableSubCommands}}
|
|
||||||
|
|
||||||
Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}}
|
|
||||||
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}
|
|
||||||
|
|
||||||
Options:
|
|
||||||
{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}
|
|
||||||
{{end}}
|
|
||||||
`
|
|
||||||
|
|
||||||
var (
|
|
||||||
//rootCmd = &cobra.Command{
|
|
||||||
// // In shell completion, there is `.exe` suffix on Windows.
|
|
||||||
// // This does not provide the same experience across platforms
|
|
||||||
// // and was mentioned in [#16499](https://github.com/containers/podman/issues/16499).
|
|
||||||
// Use: strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe") + " [options]",
|
|
||||||
// Long: "Manage pods, containers and images",
|
|
||||||
// SilenceUsage: true,
|
|
||||||
// SilenceErrors: true,
|
|
||||||
// TraverseChildren: true,
|
|
||||||
// PersistentPreRunE: persistentPreRunE,
|
|
||||||
// RunE: validate.SubCommandExists,
|
|
||||||
// //PersistentPostRunE: persistentPostRunE,
|
|
||||||
// Version: version.Version.String(),
|
|
||||||
// DisableFlagsInUseLine: true,
|
|
||||||
//}
|
|
||||||
|
|
||||||
defaultLogLevel = "warn"
|
|
||||||
logLevel = defaultLogLevel
|
|
||||||
dockerConfig = ""
|
|
||||||
debug bool
|
|
||||||
|
|
||||||
requireCleanup = true
|
|
||||||
|
|
||||||
// Defaults for capturing/redirecting the command output since (the) cobra is
|
|
||||||
// global-hungry and doesn't allow you to attach anything that allows us to
|
|
||||||
// transform the noStdout BoolVar to a string that we can assign to useStdout.
|
|
||||||
noStdout = false
|
|
||||||
useStdout = ""
|
|
||||||
)
|
|
||||||
|
|
||||||
func Init() {
|
|
||||||
// Hooks are called before PersistentPreRunE(). These hooks affect global
|
|
||||||
// state and are executed after processing the command-line, but before
|
|
||||||
// actually running the command.
|
|
||||||
cobra.OnInitialize(
|
|
||||||
stdOutHook, // Caution, this hook redirects stdout and output from any following hooks may be affected.
|
|
||||||
loggingHook,
|
|
||||||
syslogHook,
|
|
||||||
earlyInitHook,
|
|
||||||
configHook,
|
|
||||||
)
|
|
||||||
|
|
||||||
// backwards compat still allow --cni-config-dir
|
|
||||||
//rootCmd.Flags().SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName {
|
|
||||||
// if name == "cni-config-dir" {
|
|
||||||
// name = "network-config-dir"
|
|
||||||
// }
|
|
||||||
// return pflag.NormalizedName(name)
|
|
||||||
//})
|
|
||||||
//rootCmd.SetUsageTemplate(usageTemplate)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Execute() {
|
|
||||||
//if err := rootCmd.ExecuteContext(registry.Context()); err != nil {
|
|
||||||
// if registry.GetExitCode() == 0 {
|
|
||||||
// registry.SetExitCode(define.ExecErrorCodeGeneric)
|
|
||||||
// }
|
|
||||||
// if registry.IsRemote() {
|
|
||||||
// if errors.As(err, &bindings.ConnectError{}) {
|
|
||||||
// fmt.Fprintln(os.Stderr, "Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// fmt.Fprintln(os.Stderr, formatError(err))
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//_ = shutdown.Stop()
|
|
||||||
//
|
|
||||||
//if requireCleanup {
|
|
||||||
// // The cobra post-run is not being executed in case of
|
|
||||||
// // a previous error, so make sure that the engine(s)
|
|
||||||
// // are correctly shutdown.
|
|
||||||
// //
|
|
||||||
// // See https://github.com/spf13/cobra/issues/914
|
|
||||||
// logrus.Debugf("Shutting down engines")
|
|
||||||
// if engine := registry.ImageEngine(); engine != nil {
|
|
||||||
// engine.Shutdown(registry.Context())
|
|
||||||
// }
|
|
||||||
// if engine := registry.ContainerEngine(); engine != nil {
|
|
||||||
// engine.Shutdown(registry.Context())
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//os.Exit(registry.GetExitCode())
|
|
||||||
}
|
|
||||||
|
|
||||||
// readRemoteCliFlags reads cli flags related to operating podman remotely
|
|
||||||
func readRemoteCliFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) error {
|
|
||||||
|
|
||||||
conf := podmanConfig.ContainersConfDefaultsRO
|
|
||||||
contextConn, host := cmd.Root().LocalFlags().Lookup("context"), cmd.Root().LocalFlags().Lookup("host")
|
|
||||||
conn, url := cmd.Root().LocalFlags().Lookup("connection"), cmd.Root().LocalFlags().Lookup("url")
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case conn != nil && conn.Changed:
|
|
||||||
if contextConn != nil && contextConn.Changed {
|
|
||||||
return fmt.Errorf("use of --connection and --context at the same time is not allowed")
|
|
||||||
}
|
|
||||||
con, err := conf.GetConnection(conn.Value.String(), false)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
podmanConfig.URI = con.URI
|
|
||||||
podmanConfig.Identity = con.Identity
|
|
||||||
podmanConfig.MachineMode = con.IsMachine
|
|
||||||
case url.Changed:
|
|
||||||
podmanConfig.URI = url.Value.String()
|
|
||||||
case contextConn != nil && contextConn.Changed:
|
|
||||||
service := contextConn.Value.String()
|
|
||||||
if service != "default" {
|
|
||||||
con, err := conf.GetConnection(service, false)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
podmanConfig.URI = con.URI
|
|
||||||
podmanConfig.Identity = con.Identity
|
|
||||||
podmanConfig.MachineMode = con.IsMachine
|
|
||||||
}
|
|
||||||
case host.Changed:
|
|
||||||
podmanConfig.URI = host.Value.String()
|
|
||||||
default:
|
|
||||||
// No cli options set, in case CONTAINER_CONNECTION was set to something
|
|
||||||
// invalid this contains the error, see setupRemoteConnection().
|
|
||||||
// Important so that we can show a proper useful error message but still
|
|
||||||
// allow the cli overwrites (https://github.com/containers/podman/pull/22997).
|
|
||||||
return podmanConfig.ConnectionError
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// setupRemoteConnection returns information about the active service destination
|
|
||||||
// The order of priority is:
|
|
||||||
// 1. cli flags (--connection ,--url ,--context ,--host);
|
|
||||||
// 2. Env variables (CONTAINER_HOST and CONTAINER_CONNECTION);
|
|
||||||
// 3. ActiveService from containers.conf;
|
|
||||||
// 4. RemoteURI;
|
|
||||||
// Returns the name of the default connection if any.
|
|
||||||
func setupRemoteConnection(podmanConfig *entities.PodmanConfig) string {
|
|
||||||
conf := podmanConfig.ContainersConfDefaultsRO
|
|
||||||
connEnv, hostEnv, sshkeyEnv := os.Getenv("CONTAINER_CONNECTION"), os.Getenv("CONTAINER_HOST"), os.Getenv("CONTAINER_SSHKEY")
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case connEnv != "":
|
|
||||||
con, err := conf.GetConnection(connEnv, false)
|
|
||||||
if err != nil {
|
|
||||||
podmanConfig.ConnectionError = err
|
|
||||||
return connEnv
|
|
||||||
}
|
|
||||||
podmanConfig.URI = con.URI
|
|
||||||
podmanConfig.Identity = con.Identity
|
|
||||||
podmanConfig.MachineMode = con.IsMachine
|
|
||||||
return con.Name
|
|
||||||
case hostEnv != "":
|
|
||||||
if sshkeyEnv != "" {
|
|
||||||
podmanConfig.Identity = sshkeyEnv
|
|
||||||
}
|
|
||||||
podmanConfig.URI = hostEnv
|
|
||||||
default:
|
|
||||||
con, err := conf.GetConnection("", true)
|
|
||||||
if err == nil {
|
|
||||||
podmanConfig.URI = con.URI
|
|
||||||
podmanConfig.Identity = con.Identity
|
|
||||||
podmanConfig.MachineMode = con.IsMachine
|
|
||||||
return con.Name
|
|
||||||
}
|
|
||||||
podmanConfig.URI = registry.DefaultAPIAddress()
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func persistentPreRunE(cmd *cobra.Command, args []string) error {
|
|
||||||
logrus.Debugf("Called %s.PersistentPreRunE(%s)", cmd.Name(), strings.Join(os.Args, " "))
|
|
||||||
podmanConfig := registry.PodmanConfig()
|
|
||||||
log.Println(*podmanConfig)
|
|
||||||
if !registry.IsRemote() {
|
|
||||||
if cmd.Flag("hooks-dir").Changed {
|
|
||||||
podmanConfig.ContainersConf.Engine.HooksDir.Set(podmanConfig.HooksDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := readRemoteCliFlags(cmd, podmanConfig); err != nil {
|
|
||||||
return fmt.Errorf("read cli flags: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
c := &cobra.Command{}
|
|
||||||
// Prep the engines
|
|
||||||
if _, err := registry.NewImageEngine(c, args); err != nil {
|
|
||||||
// Note: this is gross, but it is the hand we are dealt
|
|
||||||
if registry.IsRemote() && errors.As(err, &bindings.ConnectError{}) && cmd.Name() == "info" && c.Parent() == c.Root() {
|
|
||||||
clientDesc, err := getClientInfo()
|
|
||||||
// we eat the error here. if this fails, they just don't any client info
|
|
||||||
if err == nil {
|
|
||||||
b, _ := yaml.Marshal(clientDesc)
|
|
||||||
fmt.Println(string(b))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := registry.NewContainerEngine(c, args); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := os.LookupEnv("TMPDIR"); !ok {
|
|
||||||
if tmpdir, err := podmanConfig.ContainersConfDefaultsRO.ImageCopyTmpDir(); err != nil {
|
|
||||||
logrus.Warnf("Failed to retrieve default tmp dir: %s", err.Error())
|
|
||||||
} else {
|
|
||||||
os.Setenv("TMPDIR", tmpdir)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_, found := c.Annotations[registry.ParentNSRequired]
|
|
||||||
if !registry.IsRemote() && !found {
|
|
||||||
cgroupMode := ""
|
|
||||||
_, noMoveProcess := c.Annotations[registry.NoMoveProcess]
|
|
||||||
if flag := c.LocalFlags().Lookup("cgroups"); flag != nil {
|
|
||||||
cgroupMode = flag.Value.String()
|
|
||||||
}
|
|
||||||
err := registry.ContainerEngine().SetupRootless(registry.Context(), noMoveProcess, cgroupMode)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func configHook() {
|
|
||||||
if dockerConfig != "" {
|
|
||||||
if err := os.Setenv("DOCKER_CONFIG", dockerConfig); err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "cannot set DOCKER_CONFIG=%s: %s", dockerConfig, err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func loggingHook() {
|
|
||||||
var found bool
|
|
||||||
if debug {
|
|
||||||
if logLevel != defaultLogLevel {
|
|
||||||
fmt.Fprintf(os.Stderr, "Setting --log-level and --debug is not allowed\n")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
logLevel = "debug"
|
|
||||||
}
|
|
||||||
for _, l := range common.LogLevels {
|
|
||||||
if l == strings.ToLower(logLevel) {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
fmt.Fprintf(os.Stderr, "Log Level %q is not supported, choose from: %s\n", logLevel, strings.Join(common.LogLevels, ", "))
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
level, err := logrus.ParseLevel(logLevel)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprint(os.Stderr, err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
logrus.SetLevel(level)
|
|
||||||
|
|
||||||
if logrus.IsLevelEnabled(logrus.InfoLevel) {
|
|
||||||
logrus.Infof("%s filtering at log level %s", os.Args[0], logrus.GetLevel())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// used for capturing podman's formatted output to some file as per the -out and -noout flags.
|
|
||||||
func stdOutHook() {
|
|
||||||
// if noStdOut was specified, then assign /dev/null as the standard file for output.
|
|
||||||
if noStdout {
|
|
||||||
useStdout = os.DevNull
|
|
||||||
}
|
|
||||||
// if we were given a filename for output, then open that and use it. we end up leaking
|
|
||||||
// the file since it's intended to be in scope as long as our process is running.
|
|
||||||
if useStdout != "" {
|
|
||||||
if fd, err := os.OpenFile(useStdout, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm); err == nil {
|
|
||||||
os.Stdout = fd
|
|
||||||
|
|
||||||
// if we couldn't open the file for write, then just bail with an error.
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(os.Stderr, "unable to open file for standard output: %s\n", err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) {
|
|
||||||
connectionName := setupRemoteConnection(podmanConfig)
|
|
||||||
|
|
||||||
lFlags := cmd.Flags()
|
|
||||||
|
|
||||||
sshFlagName := "ssh"
|
|
||||||
lFlags.StringVar(&podmanConfig.SSHMode, sshFlagName, string(ssh.GolangMode), "define the ssh mode")
|
|
||||||
|
|
||||||
connectionFlagName := "connection"
|
|
||||||
lFlags.StringP(connectionFlagName, "c", connectionName, "Connection to use for remote Podman service (CONTAINER_CONNECTION)")
|
|
||||||
|
|
||||||
urlFlagName := "url"
|
|
||||||
lFlags.StringVar(&podmanConfig.URI, urlFlagName, podmanConfig.URI, "URL to access Podman service (CONTAINER_HOST)")
|
|
||||||
lFlags.StringVarP(&podmanConfig.URI, "host", "H", podmanConfig.URI, "Used for Docker compatibility")
|
|
||||||
_ = lFlags.MarkHidden("host")
|
|
||||||
|
|
||||||
lFlags.StringVar(&dockerConfig, "config", "", "Location of authentication config file")
|
|
||||||
|
|
||||||
// Context option added just for compatibility with DockerCLI.
|
|
||||||
lFlags.String("context", "default", "Name of the context to use to connect to the daemon (This flag is a NOOP and provided solely for scripting compatibility.)")
|
|
||||||
_ = lFlags.MarkHidden("context")
|
|
||||||
|
|
||||||
identityFlagName := "identity"
|
|
||||||
lFlags.StringVar(&podmanConfig.Identity, identityFlagName, podmanConfig.Identity, "path to SSH identity file, (CONTAINER_SSHKEY)")
|
|
||||||
|
|
||||||
// Flags that control or influence any kind of output.
|
|
||||||
outFlagName := "out"
|
|
||||||
lFlags.StringVar(&useStdout, outFlagName, "", "Send output (stdout) from podman to a file")
|
|
||||||
|
|
||||||
lFlags.BoolVar(&noStdout, "noout", false, "do not output to stdout")
|
|
||||||
_ = lFlags.MarkHidden("noout") // Superseded by --out
|
|
||||||
|
|
||||||
lFlags.BoolVarP(&podmanConfig.Remote, "remote", "r", registry.IsRemote(), "Access remote Podman service")
|
|
||||||
pFlags := cmd.PersistentFlags()
|
|
||||||
if registry.IsRemote() {
|
|
||||||
if err := lFlags.MarkHidden("remote"); err != nil {
|
|
||||||
logrus.Warnf("Unable to mark --remote flag as hidden: %s", err.Error())
|
|
||||||
}
|
|
||||||
podmanConfig.Remote = true
|
|
||||||
} else {
|
|
||||||
moduleFlagName := "module"
|
|
||||||
lFlags.StringArray(moduleFlagName, nil, "Load the containers.conf(5) module")
|
|
||||||
|
|
||||||
pFlags.StringVar(&podmanConfig.ContainersConf.Engine.DBBackend, "db-backend", podmanConfig.ContainersConfDefaultsRO.Engine.DBBackend, "Database backend to use")
|
|
||||||
|
|
||||||
cgroupManagerFlagName := "cgroup-manager"
|
|
||||||
pFlags.StringVar(&podmanConfig.ContainersConf.Engine.CgroupManager, cgroupManagerFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.CgroupManager, "Cgroup manager to use (\"cgroupfs\"|\"systemd\")")
|
|
||||||
|
|
||||||
pFlags.StringVar(&podmanConfig.CPUProfile, "cpu-profile", "", "Path for the cpu-profiling results")
|
|
||||||
pFlags.StringVar(&podmanConfig.MemoryProfile, "memory-profile", "", "Path for the memory-profiling results")
|
|
||||||
|
|
||||||
conmonFlagName := "conmon"
|
|
||||||
pFlags.StringVar(&podmanConfig.ConmonPath, conmonFlagName, "", "Path of the conmon binary")
|
|
||||||
|
|
||||||
// TODO (6.0): --network-cmd-path is deprecated, remove this option with the next major release
|
|
||||||
// We need to find all the places that use r.config.Engine.NetworkCmdPath and remove it
|
|
||||||
networkCmdPathFlagName := "network-cmd-path"
|
|
||||||
pFlags.StringVar(&podmanConfig.ContainersConf.Engine.NetworkCmdPath, networkCmdPathFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.NetworkCmdPath, "Path to the command for configuring the network")
|
|
||||||
|
|
||||||
networkConfigDirFlagName := "network-config-dir"
|
|
||||||
pFlags.StringVar(&podmanConfig.ContainersConf.Network.NetworkConfigDir, networkConfigDirFlagName, podmanConfig.ContainersConfDefaultsRO.Network.NetworkConfigDir, "Path of the configuration directory for networks")
|
|
||||||
|
|
||||||
pFlags.StringVar(&podmanConfig.ContainersConf.Containers.DefaultMountsFile, "default-mounts-file", podmanConfig.ContainersConfDefaultsRO.Containers.DefaultMountsFile, "Path to default mounts file")
|
|
||||||
|
|
||||||
eventsBackendFlagName := "events-backend"
|
|
||||||
pFlags.StringVar(&podmanConfig.ContainersConf.Engine.EventsLogger, eventsBackendFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.EventsLogger, `Events backend to use ("file"|"journald"|"none")`)
|
|
||||||
|
|
||||||
hooksDirFlagName := "hooks-dir"
|
|
||||||
pFlags.StringArrayVar(&podmanConfig.HooksDir, hooksDirFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.HooksDir.Get(), "Set the OCI hooks directory path (may be set multiple times)")
|
|
||||||
|
|
||||||
pFlags.IntVar(&podmanConfig.MaxWorks, "max-workers", (runtime.NumCPU()*3)+1, "The maximum number of workers for parallel operations")
|
|
||||||
|
|
||||||
namespaceFlagName := "namespace"
|
|
||||||
pFlags.StringVar(&podmanConfig.ContainersConf.Engine.Namespace, namespaceFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.Namespace, "Set the libpod namespace, used to create separate views of the containers and pods on the system")
|
|
||||||
_ = pFlags.MarkHidden(namespaceFlagName)
|
|
||||||
|
|
||||||
networkBackendFlagName := "network-backend"
|
|
||||||
pFlags.StringVar(&podmanConfig.ContainersConf.Network.NetworkBackend, networkBackendFlagName, podmanConfig.ContainersConfDefaultsRO.Network.NetworkBackend, `Network backend to use ("cni"|"netavark")`)
|
|
||||||
_ = pFlags.MarkHidden(networkBackendFlagName)
|
|
||||||
|
|
||||||
rootFlagName := "root"
|
|
||||||
pFlags.StringVar(&podmanConfig.GraphRoot, rootFlagName, "", "Path to the graph root directory where images, containers, etc. are stored")
|
|
||||||
|
|
||||||
pFlags.StringVar(&podmanConfig.RegistriesConf, "registries-conf", "", "Path to a registries.conf to use for image processing")
|
|
||||||
|
|
||||||
runrootFlagName := "runroot"
|
|
||||||
pFlags.StringVar(&podmanConfig.Runroot, runrootFlagName, "", "Path to the 'run directory' where all state information is stored")
|
|
||||||
|
|
||||||
imageStoreFlagName := "imagestore"
|
|
||||||
pFlags.StringVar(&podmanConfig.ImageStore, imageStoreFlagName, "", "Path to the 'image store', different from 'graph root', use this to split storing the image into a separate 'image store', see 'man containers-storage.conf' for details")
|
|
||||||
|
|
||||||
pFlags.BoolVar(&podmanConfig.TransientStore, "transient-store", false, "Enable transient container storage")
|
|
||||||
|
|
||||||
pFlags.StringArrayVar(&podmanConfig.PullOptions, "pull-option", nil, "Specify an option to change how the image is pulled")
|
|
||||||
|
|
||||||
runtimeFlagName := "runtime"
|
|
||||||
pFlags.StringVar(&podmanConfig.RuntimePath, runtimeFlagName, "youki", "Path to the OCI-compatible binary used to run containers.")
|
|
||||||
|
|
||||||
// -s is deprecated due to conflict with -s on subcommands
|
|
||||||
storageDriverFlagName := "storage-driver"
|
|
||||||
pFlags.StringVar(&podmanConfig.StorageDriver, storageDriverFlagName, "", "Select which storage driver is used to manage storage of images and containers")
|
|
||||||
|
|
||||||
tmpdirFlagName := "tmpdir"
|
|
||||||
pFlags.StringVar(&podmanConfig.ContainersConf.Engine.TmpDir, tmpdirFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.TmpDir, "Path to the tmp directory for libpod state content.\n\nNote: use the environment variable 'TMPDIR' to change the temporary storage location for container images, '/var/tmp'.\n")
|
|
||||||
|
|
||||||
pFlags.BoolVar(&podmanConfig.Trace, "trace", true, "Enable opentracing output (default false)")
|
|
||||||
|
|
||||||
volumePathFlagName := "volumepath"
|
|
||||||
pFlags.StringVar(&podmanConfig.ContainersConf.Engine.VolumePath, volumePathFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.VolumePath, "Path to the volume directory in which volume data is stored")
|
|
||||||
|
|
||||||
// Hide these flags for both ABI and Tunneling
|
|
||||||
for _, f := range []string{
|
|
||||||
"cpu-profile",
|
|
||||||
"db-backend",
|
|
||||||
"default-mounts-file",
|
|
||||||
"max-workers",
|
|
||||||
"memory-profile",
|
|
||||||
"pull-option",
|
|
||||||
"registries-conf",
|
|
||||||
"trace",
|
|
||||||
} {
|
|
||||||
if err := pFlags.MarkHidden(f); err != nil {
|
|
||||||
logrus.Warnf("Unable to mark %s flag as hidden: %s", f, err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
storageOptFlagName := "storage-opt"
|
|
||||||
pFlags.StringArrayVar(&podmanConfig.StorageOpts, storageOptFlagName, []string{}, "Used to pass an option to the storage driver")
|
|
||||||
|
|
||||||
// Override default --help information of `--help` global flag
|
|
||||||
var dummyHelp bool
|
|
||||||
pFlags.BoolVar(&dummyHelp, "help", false, "Help for podman")
|
|
||||||
|
|
||||||
logLevelFlagName := "log-level"
|
|
||||||
pFlags.StringVar(&logLevel, logLevelFlagName, logLevel, fmt.Sprintf("Log messages above specified level (%s)", strings.Join(common.LogLevels, ", ")))
|
|
||||||
|
|
||||||
lFlags.BoolVarP(&debug, "debug", "D", false, "Docker compatibility, force setting of log-level")
|
|
||||||
_ = lFlags.MarkHidden("debug")
|
|
||||||
|
|
||||||
// Only create these flags for ABI connections
|
|
||||||
if !registry.IsRemote() {
|
|
||||||
runtimeflagFlagName := "runtime-flag"
|
|
||||||
pFlags.StringArrayVar(&podmanConfig.RuntimeFlags, runtimeflagFlagName, []string{}, "add global flags for the container runtime")
|
|
||||||
|
|
||||||
pFlags.BoolVar(&podmanConfig.Syslog, "syslog", false, "Output logging information to syslog as well as the console (default false)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,8 +1,11 @@
|
|||||||
package network
|
package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"floares/lib/http/network"
|
"floares/lib/http/network"
|
||||||
|
"floares/lib/model"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,10 +23,37 @@ func Disconnect(c *gin.Context) {
|
|||||||
"err": "",
|
"err": "",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func Connect(c *gin.Context) {
|
func Connect(c *gin.Context) {
|
||||||
ns := c.Param("ns")
|
ns := c.Param("ns")
|
||||||
id := c.Query("id")
|
var req model.ConnectRequest
|
||||||
err := network.Connect(ns, id)
|
json.NewDecoder(c.Request.Body).Decode(&req)
|
||||||
|
err := network.Connect(ns, req)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{
|
||||||
|
"error": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"err": "",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
func ConnectALl(c *gin.Context) {
|
||||||
|
type Containers struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Id []string `json:"id"`
|
||||||
|
}
|
||||||
|
var id Containers
|
||||||
|
err := json.NewDecoder(c.Request.Body).Decode(&id)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{
|
||||||
|
"error": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = network.MakerNet(id.Name, id.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{
|
c.JSON(http.StatusBadRequest, gin.H{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
|
|||||||
43
service/network/create.go
Normal file
43
service/network/create.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package network
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"floares/lib/http/network"
|
||||||
|
"floares/lib/model"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Create(c *gin.Context) {
|
||||||
|
var req model.CreateNetworkRequest
|
||||||
|
json.NewDecoder(c.Request.Body).Decode(&req)
|
||||||
|
err := network.Create(req)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": http.StatusBadRequest,
|
||||||
|
"error": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": http.StatusOK,
|
||||||
|
"error": "",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func Delete(c *gin.Context) {
|
||||||
|
var req model.CreateNetworkRequest
|
||||||
|
json.NewDecoder(c.Request.Body).Decode(&req)
|
||||||
|
err := network.Delete(req.Name)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": http.StatusBadRequest,
|
||||||
|
"err": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": http.StatusOK,
|
||||||
|
"err": "",
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -7,5 +7,8 @@ func RegisterRouter(r *gin.RouterGroup) {
|
|||||||
r.GET("/:ns/inspect", ListConnect)
|
r.GET("/:ns/inspect", ListConnect)
|
||||||
r.DELETE("/:ns/disconnect", Disconnect)
|
r.DELETE("/:ns/disconnect", Disconnect)
|
||||||
r.POST("/:ns/connect", Connect)
|
r.POST("/:ns/connect", Connect)
|
||||||
|
r.POST("/group", ConnectALl)
|
||||||
|
r.POST("/create", Create)
|
||||||
|
r.POST("/delete", Delete)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
46
service/volume/create.go
Normal file
46
service/volume/create.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package volume
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"floares/lib/http/volume"
|
||||||
|
"floares/lib/model"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Create(c *gin.Context) {
|
||||||
|
var req model.CreateVolume
|
||||||
|
if err := json.NewDecoder(c.Request.Body).Decode(&req); err != nil {
|
||||||
|
c.JSON(200, gin.H{
|
||||||
|
"code": 400,
|
||||||
|
"err": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := volume.Create(req)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(200, gin.H{
|
||||||
|
"code": 400,
|
||||||
|
"err": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(200, gin.H{
|
||||||
|
"code": 200,
|
||||||
|
"err": "",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
func Delete(c *gin.Context) {
|
||||||
|
|
||||||
|
err := volume.Delete(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(200, gin.H{
|
||||||
|
"code": 400,
|
||||||
|
"err": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(200, gin.H{
|
||||||
|
"code": 200,
|
||||||
|
"err": "",
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -4,4 +4,7 @@ import "github.com/gin-gonic/gin"
|
|||||||
|
|
||||||
func RegisterRouter(c *gin.RouterGroup) {
|
func RegisterRouter(c *gin.RouterGroup) {
|
||||||
c.GET("/", List)
|
c.GET("/", List)
|
||||||
|
c.POST("/", Create)
|
||||||
|
c.DELETE("/:id", Delete)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,24 +0,0 @@
|
|||||||
//go:build linux || freebsd
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log/syslog"
|
|
||||||
|
|
||||||
"github.com/containers/podman/v5/cmd/podman/registry"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
logrusSyslog "github.com/sirupsen/logrus/hooks/syslog"
|
|
||||||
)
|
|
||||||
|
|
||||||
func syslogHook() {
|
|
||||||
if !registry.PodmanConfig().Syslog {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
hook, err := logrusSyslog.NewSyslogHook("", "", syslog.LOG_INFO, "")
|
|
||||||
if err != nil {
|
|
||||||
logrus.Debug("Failed to initialize syslog hook: " + err.Error())
|
|
||||||
} else {
|
|
||||||
logrus.AddHook(hook)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user