Skip to content

Commit

Permalink
Merge pull request #17 from baude/apiv2create
Browse files Browse the repository at this point in the history
pod create and container create
  • Loading branch information
baude authored Nov 8, 2019
2 parents 08a1fc6 + 02a8c6b commit 847a42d
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/serviceapi/handler_containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
)

func registerContainersHandlers(r *mux.Router) error {
r.Handle(unversionedPath("/containers/create"), serviceHandler(createContainer))
r.Handle(unversionedPath("/containers/{name:..*}"), serviceHandler(removeContainer)).Methods("DELETE")
r.Handle(unversionedPath("/containers/{name:..*}/json"), serviceHandler(container))
r.Handle(unversionedPath("/containers/{name:..*}/kill"), serviceHandler(killContainer))
Expand Down
121 changes: 121 additions & 0 deletions pkg/serviceapi/handler_containers_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package serviceapi

import (
"context"
"encoding/json"
"net/http"

"github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/libpod"
createconfig "github.com/containers/libpod/pkg/spec"
)

func createContainer(w http.ResponseWriter, r *http.Request, runtime *libpod.Runtime) {
ctx := context.Background()
input := CreateContainer{}
if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
Error(w, "Something went wrong.", http.StatusInternalServerError, err)
return
}
cc, err := makeCreateConfig(input)
if err != nil {
Error(w, "Something went wrong.", http.StatusInternalServerError, err)
return
}

var pod *libpod.Pod
_, err = shared.CreateContainerFromCreateConfig(runtime, &cc, ctx, pod)
if err != nil {
Error(w, "Something went wrong.", http.StatusInternalServerError, err)
return
}
return
}

func makeCreateConfig(input CreateContainer) (createconfig.CreateConfig, error) {
m := createconfig.CreateConfig{
Annotations: nil,
Args: nil,
CapAdd: input.HostConfig.CapAdd,
CapDrop: input.HostConfig.CapDrop,
CidFile: "",
ConmonPidFile: "", //podman
Cgroupns: "", //podman
Cgroups: "", //podman
CgroupParent: input.HostConfig.CgroupParent,
Command: input.Cmd,
UserCommand: nil, //podman
Detach: false, //
//Devices: input.HostConfig.Devices,
DNSOpt: input.HostConfig.DNSOptions,
DNSSearch: input.HostConfig.DNSSearch,
DNSServers: input.HostConfig.DNS,
Entrypoint: input.Entrypoint,
//Env: input.Env,
ExposedPorts: input.ExposedPorts,
GroupAdd: input.HostConfig.GroupAdd,
HealthCheck: nil, //
NoHosts: false, //podman
HostAdd: input.HostConfig.ExtraHosts,
Hostname: input.Hostname,
HTTPProxy: false, //podman
//Init: input.HostConfig.Init,
InitPath: "", // tbd
Image: input.Image,
ImageID: "", // added later
BuiltinImgVolumes: nil, //podman
IDMappings: nil, //podman
ImageVolumeType: "", //podman
Interactive: false,
//IpcMode: input.HostConfig.IpcMode,
IP6Address: "",
IPAddress: "",
Labels: input.Labels,
LinkLocalIP: nil, //docker-only
LogDriver: input.HostConfig.LogConfig.Type, // is this correct
//LogDriverOpt: input.HostConfig.LogConfig.Config,
MacAddress: input.MacAddress,
Name: input.Name,
//NetMode: input.HostConfig.NetworkMode,
Network: input.HostConfig.NetworkMode.NetworkName(),
NetworkAlias: nil, // dockeronly ?
//PidMode: input.HostConfig.PidMode,
Pod: "", //podman
PodmanPath: "", //podman
CgroupMode: "", //podman
PortBindings: input.HostConfig.PortBindings,
Privileged: input.HostConfig.Privileged,
Publish: nil, //podman
PublishAll: input.HostConfig.PublishAllPorts,
Quiet: false, //front-end only
ReadOnlyRootfs: input.HostConfig.ReadonlyRootfs,
ReadOnlyTmpfs: false, //podman
Resources: createconfig.CreateResourceConfig{},
//RestartPolicy: input.HostConfig.RestartPolicy,
Rm: input.HostConfig.AutoRemove,
//StopSignal: input.StopSignal,
//StopTimeout: input.StopTimeout,
Sysctl: input.HostConfig.Sysctls,
Systemd: false, //podman
//Tmpfs: input.HostConfig.Tmpfs,
Tty: input.Tty,
//UsernsMode: input.HostConfig.UsernsMode,
User: input.User,
//UtsMode: input.HostConfig.UTSMode,
Mounts: nil, //we populate
//MountsFlag: input.HostConfig.Mounts,
NamedVolumes: nil, // we populate
//Volumes: input.Volumes,
VolumesFrom: input.HostConfig.VolumesFrom,
WorkDir: input.WorkingDir,
LabelOpts: nil, // we populate
NoNewPrivs: false, // we populate
ApparmorProfile: "", // we populate
SeccompProfilePath: "", //we populate
SecurityOpts: input.HostConfig.SecurityOpt,
Rootfs: "", //podman
Syslog: false, //podman
}

return m, nil
}
2 changes: 2 additions & 0 deletions pkg/serviceapi/handler_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func registerPodsHandlers(r *mux.Router) error {
}

func podCreate(w http.ResponseWriter, r *http.Request, runtime *libpod.Runtime) {
//TODO This is ALL wrong. Brent to completely redo. Should be using JSON structures
// and not forms.
var (
options []libpod.PodCreateOption
err error
Expand Down
9 changes: 9 additions & 0 deletions pkg/serviceapi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package serviceapi

import (
"context"
"github.com/docker/docker/api/types/network"
"time"

podmanImage "github.com/containers/libpod/libpod/image"
Expand Down Expand Up @@ -34,6 +35,7 @@ type Info struct {
}

type Container struct {
docker.ContainerCreateConfig
docker.ContainerJSON
}

Expand Down Expand Up @@ -88,6 +90,13 @@ type ContainerWaitOKBody struct {
}
}

type CreateContainer struct {
Name string
dockerContainer.Config
HostConfig dockerContainer.HostConfig
NetworkingConfig network.NetworkingConfig
}

func ImageToImageSummary(p *podmanImage.Image) (*ImageSummary, error) {
containers, err := p.Containers()
if err != nil {
Expand Down

0 comments on commit 847a42d

Please sign in to comment.