summaryrefslogtreecommitdiff
path: root/pkg/varlinkapi
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/varlinkapi')
-rw-r--r--pkg/varlinkapi/config.go2
-rw-r--r--pkg/varlinkapi/containers.go23
-rw-r--r--pkg/varlinkapi/containers_create.go212
-rw-r--r--pkg/varlinkapi/events.go2
-rw-r--r--pkg/varlinkapi/images.go2
-rw-r--r--pkg/varlinkapi/mount.go2
-rw-r--r--pkg/varlinkapi/pods.go2
-rw-r--r--pkg/varlinkapi/remote_client.go29
-rw-r--r--pkg/varlinkapi/system.go2
-rw-r--r--pkg/varlinkapi/transfers.go2
-rw-r--r--pkg/varlinkapi/util.go2
-rw-r--r--pkg/varlinkapi/volumes.go2
12 files changed, 54 insertions, 228 deletions
diff --git a/pkg/varlinkapi/config.go b/pkg/varlinkapi/config.go
index f557d04e5..e75170547 100644
--- a/pkg/varlinkapi/config.go
+++ b/pkg/varlinkapi/config.go
@@ -1,3 +1,5 @@
+// +build varlink
+
package varlinkapi
import (
diff --git a/pkg/varlinkapi/containers.go b/pkg/varlinkapi/containers.go
index 7a6ae3507..ac1352dac 100644
--- a/pkg/varlinkapi/containers.go
+++ b/pkg/varlinkapi/containers.go
@@ -1,3 +1,5 @@
+// +build varlink
+
package varlinkapi
import (
@@ -583,27 +585,6 @@ func (i *LibpodAPI) GetContainerStatsWithHistory(call iopodman.VarlinkCall, prev
return call.ReplyGetContainerStatsWithHistory(cStats)
}
-// ContainerStatsToLibpodContainerStats converts the varlink containerstats to a libpod
-// container stats
-func ContainerStatsToLibpodContainerStats(stats iopodman.ContainerStats) libpod.ContainerStats {
- cstats := libpod.ContainerStats{
- ContainerID: stats.Id,
- Name: stats.Name,
- CPU: stats.Cpu,
- CPUNano: uint64(stats.Cpu_nano),
- SystemNano: uint64(stats.System_nano),
- MemUsage: uint64(stats.Mem_usage),
- MemLimit: uint64(stats.Mem_limit),
- MemPerc: stats.Mem_perc,
- NetInput: uint64(stats.Net_input),
- NetOutput: uint64(stats.Net_output),
- BlockInput: uint64(stats.Block_input),
- BlockOutput: uint64(stats.Block_output),
- PIDs: uint64(stats.Pids),
- }
- return cstats
-}
-
// GetContainersLogs is the varlink endpoint to obtain one or more container logs
func (i *LibpodAPI) GetContainersLogs(call iopodman.VarlinkCall, names []string, follow, latest bool, since string, tail int64, timestamps bool) error {
var wg sync.WaitGroup
diff --git a/pkg/varlinkapi/containers_create.go b/pkg/varlinkapi/containers_create.go
index 8990ac001..6b23dce5e 100644
--- a/pkg/varlinkapi/containers_create.go
+++ b/pkg/varlinkapi/containers_create.go
@@ -1,220 +1,18 @@
+// +build varlink
+
package varlinkapi
import (
- "context"
- "encoding/json"
- "fmt"
- "os"
- "strings"
- "syscall"
-
+ "github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/cmd/podman/varlink"
- "github.com/containers/libpod/libpod"
- "github.com/containers/libpod/libpod/image"
- "github.com/containers/libpod/pkg/inspect"
- "github.com/containers/libpod/pkg/namespaces"
- "github.com/containers/libpod/pkg/rootless"
- cc "github.com/containers/libpod/pkg/spec"
- "github.com/containers/libpod/pkg/util"
- "github.com/docker/docker/pkg/signal"
- "github.com/sirupsen/logrus"
)
// CreateContainer ...
func (i *LibpodAPI) CreateContainer(call iopodman.VarlinkCall, config iopodman.Create) error {
- rtc, err := i.Runtime.GetConfig()
- if err != nil {
- return call.ReplyErrorOccurred(err.Error())
- }
- ctx := getContext()
-
- newImage, err := i.Runtime.ImageRuntime().New(ctx, config.Image, rtc.SignaturePolicyPath, "", os.Stderr, nil, image.SigningOptions{}, false, nil)
- if err != nil {
- return call.ReplyErrorOccurred(err.Error())
- }
- data, err := newImage.Inspect(ctx)
-
- createConfig, err := varlinkCreateToCreateConfig(ctx, config, i.Runtime, config.Image, data)
- if err != nil {
- return call.ReplyErrorOccurred(err.Error())
- }
-
- runtimeSpec, err := cc.CreateConfigToOCISpec(createConfig)
+ generic := shared.VarlinkCreateToGeneric(config)
+ ctr, _, err := shared.CreateContainer(getContext(), &generic, i.Runtime)
if err != nil {
return call.ReplyErrorOccurred(err.Error())
}
-
- // TODO fix when doing remote client and dealing with the ability to create a container
- // within a non-existing pod (i.e. --pod new:foobar)
- options, err := createConfig.GetContainerCreateOptions(i.Runtime, nil)
- if err != nil {
- return call.ReplyErrorOccurred(err.Error())
- }
-
- ctr, err := i.Runtime.NewContainer(ctx, runtimeSpec, options...)
- if err != nil {
- return call.ReplyErrorOccurred(err.Error())
- }
- createConfigJSON, err := json.Marshal(createConfig)
- if err != nil {
- return call.ReplyErrorOccurred(err.Error())
- }
- if err := ctr.AddArtifact("create-config", createConfigJSON); err != nil {
- return call.ReplyErrorOccurred(err.Error())
- }
-
- logrus.Debug("new container created ", ctr.ID())
-
return call.ReplyCreateContainer(ctr.ID())
}
-
-// varlinkCreateToCreateConfig takes the varlink input struct and maps it to a pointer
-// of a CreateConfig, which eventually can be used to create the OCI spec.
-func varlinkCreateToCreateConfig(ctx context.Context, create iopodman.Create, runtime *libpod.Runtime, imageName string, data *inspect.ImageData) (*cc.CreateConfig, error) {
- idmappings, err := util.ParseIDMapping(create.Uidmap, create.Gidmap, create.Subuidname, create.Subgidname)
- if err != nil {
- return nil, err
- }
- inputCommand := create.Command
- entrypoint := create.Entrypoint
-
- // ENTRYPOINT
- // User input entrypoint takes priority over image entrypoint
- if len(entrypoint) == 0 {
- entrypoint = data.Config.Entrypoint
- }
- // if entrypoint=, we need to clear the entrypoint
- if len(entrypoint) == 1 && strings.Join(create.Entrypoint, "") == "" {
- entrypoint = []string{}
- }
- // Build the command
- // If we have an entry point, it goes first
- command := entrypoint
- if len(inputCommand) > 0 {
- // User command overrides data CMD
- command = append(command, inputCommand...)
- } else if len(data.Config.Cmd) > 0 && len(command) == 0 {
- // If not user command, add CMD
- command = append(command, data.Config.Cmd...)
- }
-
- stopSignal := syscall.SIGTERM
- if create.Stop_signal > 0 {
- stopSignal, err = signal.ParseSignal(fmt.Sprintf("%d", create.Stop_signal))
- if err != nil {
- return nil, err
- }
- }
-
- user := create.User
- if user == "" {
- user = data.Config.User
- }
-
- // EXPOSED PORTS
- portBindings, err := cc.ExposedPorts(create.Exposed_ports, create.Publish, create.Publish_all, data.Config.ExposedPorts)
- if err != nil {
- return nil, err
- }
-
- // NETWORK MODE
- networkMode := create.Net_mode
- if networkMode == "" {
- if rootless.IsRootless() {
- networkMode = "slirp4netns"
- } else {
- networkMode = "bridge"
- }
- }
-
- // WORKING DIR
- workDir := create.Work_dir
- if workDir == "" {
- workDir = "/"
- }
-
- imageID := data.ID
- var ImageVolumes map[string]struct{}
- if data != nil && create.Image_volume_type != "ignore" {
- ImageVolumes = data.Config.Volumes
- }
-
- config := &cc.CreateConfig{
- Runtime: runtime,
- BuiltinImgVolumes: ImageVolumes,
- ConmonPidFile: create.Conmon_pidfile,
- ImageVolumeType: create.Image_volume_type,
- CapAdd: create.Cap_add,
- CapDrop: create.Cap_drop,
- CgroupParent: create.Cgroup_parent,
- Command: command,
- Detach: create.Detach,
- Devices: create.Devices,
- DNSOpt: create.Dns_opt,
- DNSSearch: create.Dns_search,
- DNSServers: create.Dns_servers,
- Entrypoint: create.Entrypoint,
- Env: create.Env,
- GroupAdd: create.Group_add,
- Hostname: create.Hostname,
- HostAdd: create.Host_add,
- IDMappings: idmappings,
- Image: imageName,
- ImageID: imageID,
- Interactive: create.Interactive,
- Labels: create.Labels,
- LogDriver: create.Log_driver,
- LogDriverOpt: create.Log_driver_opt,
- Name: create.Name,
- Network: networkMode,
- IpcMode: namespaces.IpcMode(create.Ipc_mode),
- NetMode: namespaces.NetworkMode(networkMode),
- UtsMode: namespaces.UTSMode(create.Uts_mode),
- PidMode: namespaces.PidMode(create.Pid_mode),
- Pod: create.Pod,
- Privileged: create.Privileged,
- Publish: create.Publish,
- PublishAll: create.Publish_all,
- PortBindings: portBindings,
- Quiet: create.Quiet,
- ReadOnlyRootfs: create.Readonly_rootfs,
- Resources: cc.CreateResourceConfig{
- BlkioWeight: uint16(create.Resources.Blkio_weight),
- BlkioWeightDevice: create.Resources.Blkio_weight_device,
- CPUShares: uint64(create.Resources.Cpu_shares),
- CPUPeriod: uint64(create.Resources.Cpu_period),
- CPUsetCPUs: create.Resources.Cpuset_cpus,
- CPUsetMems: create.Resources.Cpuset_mems,
- CPUQuota: create.Resources.Cpu_quota,
- CPURtPeriod: uint64(create.Resources.Cpu_rt_period),
- CPURtRuntime: create.Resources.Cpu_rt_runtime,
- CPUs: create.Resources.Cpus,
- DeviceReadBps: create.Resources.Device_read_bps,
- DeviceReadIOps: create.Resources.Device_write_bps,
- DeviceWriteBps: create.Resources.Device_read_iops,
- DeviceWriteIOps: create.Resources.Device_write_iops,
- DisableOomKiller: create.Resources.Disable_oomkiller,
- ShmSize: create.Resources.Shm_size,
- Memory: create.Resources.Memory,
- MemoryReservation: create.Resources.Memory_reservation,
- MemorySwap: create.Resources.Memory_swap,
- MemorySwappiness: int(create.Resources.Memory_swappiness),
- KernelMemory: create.Resources.Kernel_memory,
- OomScoreAdj: int(create.Resources.Oom_score_adj),
- PidsLimit: create.Resources.Pids_limit,
- Ulimit: create.Resources.Ulimit,
- },
- Rm: create.Rm,
- StopSignal: stopSignal,
- StopTimeout: uint(create.Stop_timeout),
- Sysctl: create.Sys_ctl,
- Tmpfs: create.Tmpfs,
- Tty: create.Tty,
- User: user,
- UsernsMode: namespaces.UsernsMode(create.Userns_mode),
- Volumes: create.Volumes,
- WorkDir: workDir,
- }
-
- return config, nil
-}
diff --git a/pkg/varlinkapi/events.go b/pkg/varlinkapi/events.go
index 47c628ead..1e5696fbe 100644
--- a/pkg/varlinkapi/events.go
+++ b/pkg/varlinkapi/events.go
@@ -1,3 +1,5 @@
+// +build varlink
+
package varlinkapi
import (
diff --git a/pkg/varlinkapi/images.go b/pkg/varlinkapi/images.go
index 2e72ec65b..470eadaeb 100644
--- a/pkg/varlinkapi/images.go
+++ b/pkg/varlinkapi/images.go
@@ -1,3 +1,5 @@
+// +build varlink
+
package varlinkapi
import (
diff --git a/pkg/varlinkapi/mount.go b/pkg/varlinkapi/mount.go
index 3b4fe87e3..63ce44291 100644
--- a/pkg/varlinkapi/mount.go
+++ b/pkg/varlinkapi/mount.go
@@ -1,3 +1,5 @@
+// +build varlink
+
package varlinkapi
import (
diff --git a/pkg/varlinkapi/pods.go b/pkg/varlinkapi/pods.go
index c79cee4c2..ac8e24747 100644
--- a/pkg/varlinkapi/pods.go
+++ b/pkg/varlinkapi/pods.go
@@ -1,3 +1,5 @@
+// +build varlink
+
package varlinkapi
import (
diff --git a/pkg/varlinkapi/remote_client.go b/pkg/varlinkapi/remote_client.go
new file mode 100644
index 000000000..dd0613494
--- /dev/null
+++ b/pkg/varlinkapi/remote_client.go
@@ -0,0 +1,29 @@
+// +build varlink remoteclient
+
+package varlinkapi
+
+import (
+ "github.com/containers/libpod/cmd/podman/varlink"
+ "github.com/containers/libpod/libpod"
+)
+
+// ContainerStatsToLibpodContainerStats converts the varlink containerstats to a libpod
+// container stats
+func ContainerStatsToLibpodContainerStats(stats iopodman.ContainerStats) libpod.ContainerStats {
+ cstats := libpod.ContainerStats{
+ ContainerID: stats.Id,
+ Name: stats.Name,
+ CPU: stats.Cpu,
+ CPUNano: uint64(stats.Cpu_nano),
+ SystemNano: uint64(stats.System_nano),
+ MemUsage: uint64(stats.Mem_usage),
+ MemLimit: uint64(stats.Mem_limit),
+ MemPerc: stats.Mem_perc,
+ NetInput: uint64(stats.Net_input),
+ NetOutput: uint64(stats.Net_output),
+ BlockInput: uint64(stats.Block_input),
+ BlockOutput: uint64(stats.Block_output),
+ PIDs: uint64(stats.Pids),
+ }
+ return cstats
+}
diff --git a/pkg/varlinkapi/system.go b/pkg/varlinkapi/system.go
index 816143e9f..7f436a954 100644
--- a/pkg/varlinkapi/system.go
+++ b/pkg/varlinkapi/system.go
@@ -1,3 +1,5 @@
+// +build varlink
+
package varlinkapi
import (
diff --git a/pkg/varlinkapi/transfers.go b/pkg/varlinkapi/transfers.go
index 9a97bc810..96f76bcdc 100644
--- a/pkg/varlinkapi/transfers.go
+++ b/pkg/varlinkapi/transfers.go
@@ -1,3 +1,5 @@
+// +build varlink
+
package varlinkapi
import (
diff --git a/pkg/varlinkapi/util.go b/pkg/varlinkapi/util.go
index 7e487c03a..3c4b9b79a 100644
--- a/pkg/varlinkapi/util.go
+++ b/pkg/varlinkapi/util.go
@@ -1,3 +1,5 @@
+// +build varlink
+
package varlinkapi
import (
diff --git a/pkg/varlinkapi/volumes.go b/pkg/varlinkapi/volumes.go
index 02874d2b1..19ba38e7c 100644
--- a/pkg/varlinkapi/volumes.go
+++ b/pkg/varlinkapi/volumes.go
@@ -1,3 +1,5 @@
+// +build varlink
+
package varlinkapi
import (