Add --ip flag and plumbing into libpod

Add the --ip flag back with bash completions. Manpages still
missing.

Add plumbing to pass appropriate the appropriate option down to
libpod to connect the flag to backend logic added in the previous
commits.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
This commit is contained in:
Matthew Heon 2018-10-10 14:04:17 -04:00
parent b3cde231ab
commit 4882a6dd9d
5 changed files with 8876 additions and 23 deletions

View file

@ -248,6 +248,10 @@ var createFlags = []cli.Flag{
Name: "interactive, i",
Usage: "Keep STDIN open even if not attached",
},
cli.StringFlag{
Name: "ip",
Usage: "Specify a static IPv4 address for the container",
},
cli.StringFlag{
Name: "ipc",
Usage: "IPC namespace to use",

View file

@ -1512,6 +1512,7 @@ _podman_container_run() {
--hostname -h
--image-volume
--init-path
--ip
--ipc
--kernel-memory
--label-file

File diff suppressed because it is too large Load diff

749
libpod/pod_easyjson.go Normal file
View file

@ -0,0 +1,749 @@
// +build seccomp ostree selinux varlink exclude_graphdriver_devicemapper
// Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT.
package libpod
import (
json "encoding/json"
easyjson "github.com/mailru/easyjson"
jlexer "github.com/mailru/easyjson/jlexer"
jwriter "github.com/mailru/easyjson/jwriter"
)
// suppress unused package warning
var (
_ *json.RawMessage
_ *jlexer.Lexer
_ *jwriter.Writer
_ easyjson.Marshaler
)
func easyjsonBe091417DecodeGithubComContainersLibpodLibpod(in *jlexer.Lexer, out *podState) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "cgroupPath":
out.CgroupPath = string(in.String())
case "InfraContainerID":
out.InfraContainerID = string(in.String())
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjsonBe091417EncodeGithubComContainersLibpodLibpod(out *jwriter.Writer, in podState) {
out.RawByte('{')
first := true
_ = first
{
const prefix string = ",\"cgroupPath\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.CgroupPath))
}
{
const prefix string = ",\"InfraContainerID\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.InfraContainerID))
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v podState) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonBe091417EncodeGithubComContainersLibpodLibpod(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v podState) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonBe091417EncodeGithubComContainersLibpodLibpod(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *podState) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonBe091417DecodeGithubComContainersLibpodLibpod(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *podState) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonBe091417DecodeGithubComContainersLibpodLibpod(l, v)
}
func easyjsonBe091417DecodeGithubComContainersLibpodLibpod1(in *jlexer.Lexer, out *PodInspectState) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "cgroupPath":
out.CgroupPath = string(in.String())
case "infraContainerID":
out.InfraContainerID = string(in.String())
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjsonBe091417EncodeGithubComContainersLibpodLibpod1(out *jwriter.Writer, in PodInspectState) {
out.RawByte('{')
first := true
_ = first
{
const prefix string = ",\"cgroupPath\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.CgroupPath))
}
{
const prefix string = ",\"infraContainerID\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.InfraContainerID))
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v PodInspectState) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonBe091417EncodeGithubComContainersLibpodLibpod1(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v PodInspectState) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonBe091417EncodeGithubComContainersLibpodLibpod1(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *PodInspectState) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonBe091417DecodeGithubComContainersLibpodLibpod1(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *PodInspectState) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonBe091417DecodeGithubComContainersLibpodLibpod1(l, v)
}
func easyjsonBe091417DecodeGithubComContainersLibpodLibpod2(in *jlexer.Lexer, out *PodInspect) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "Config":
if in.IsNull() {
in.Skip()
out.Config = nil
} else {
if out.Config == nil {
out.Config = new(PodConfig)
}
if data := in.Raw(); in.Ok() {
in.AddError((*out.Config).UnmarshalJSON(data))
}
}
case "State":
if in.IsNull() {
in.Skip()
out.State = nil
} else {
if out.State == nil {
out.State = new(PodInspectState)
}
if data := in.Raw(); in.Ok() {
in.AddError((*out.State).UnmarshalJSON(data))
}
}
case "Containers":
if in.IsNull() {
in.Skip()
out.Containers = nil
} else {
in.Delim('[')
if out.Containers == nil {
if !in.IsDelim(']') {
out.Containers = make([]PodContainerInfo, 0, 2)
} else {
out.Containers = []PodContainerInfo{}
}
} else {
out.Containers = (out.Containers)[:0]
}
for !in.IsDelim(']') {
var v1 PodContainerInfo
if data := in.Raw(); in.Ok() {
in.AddError((v1).UnmarshalJSON(data))
}
out.Containers = append(out.Containers, v1)
in.WantComma()
}
in.Delim(']')
}
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjsonBe091417EncodeGithubComContainersLibpodLibpod2(out *jwriter.Writer, in PodInspect) {
out.RawByte('{')
first := true
_ = first
{
const prefix string = ",\"Config\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
if in.Config == nil {
out.RawString("null")
} else {
out.Raw((*in.Config).MarshalJSON())
}
}
{
const prefix string = ",\"State\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
if in.State == nil {
out.RawString("null")
} else {
out.Raw((*in.State).MarshalJSON())
}
}
{
const prefix string = ",\"Containers\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
if in.Containers == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
out.RawString("null")
} else {
out.RawByte('[')
for v2, v3 := range in.Containers {
if v2 > 0 {
out.RawByte(',')
}
out.Raw((v3).MarshalJSON())
}
out.RawByte(']')
}
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v PodInspect) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonBe091417EncodeGithubComContainersLibpodLibpod2(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v PodInspect) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonBe091417EncodeGithubComContainersLibpodLibpod2(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *PodInspect) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonBe091417DecodeGithubComContainersLibpodLibpod2(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *PodInspect) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonBe091417DecodeGithubComContainersLibpodLibpod2(l, v)
}
func easyjsonBe091417DecodeGithubComContainersLibpodLibpod3(in *jlexer.Lexer, out *PodContainerInfo) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "id":
out.ID = string(in.String())
case "state":
out.State = string(in.String())
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjsonBe091417EncodeGithubComContainersLibpodLibpod3(out *jwriter.Writer, in PodContainerInfo) {
out.RawByte('{')
first := true
_ = first
{
const prefix string = ",\"id\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.ID))
}
{
const prefix string = ",\"state\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.State))
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v PodContainerInfo) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonBe091417EncodeGithubComContainersLibpodLibpod3(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v PodContainerInfo) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonBe091417EncodeGithubComContainersLibpodLibpod3(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *PodContainerInfo) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonBe091417DecodeGithubComContainersLibpodLibpod3(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *PodContainerInfo) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonBe091417DecodeGithubComContainersLibpodLibpod3(l, v)
}
func easyjsonBe091417DecodeGithubComContainersLibpodLibpod4(in *jlexer.Lexer, out *PodConfig) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "id":
out.ID = string(in.String())
case "name":
out.Name = string(in.String())
case "namespace":
out.Namespace = string(in.String())
case "labels":
if in.IsNull() {
in.Skip()
} else {
in.Delim('{')
if !in.IsDelim('}') {
out.Labels = make(map[string]string)
} else {
out.Labels = nil
}
for !in.IsDelim('}') {
key := string(in.String())
in.WantColon()
var v4 string
v4 = string(in.String())
(out.Labels)[key] = v4
in.WantComma()
}
in.Delim('}')
}
case "cgroupParent":
out.CgroupParent = string(in.String())
case "sharesCgroup":
out.UsePodCgroup = bool(in.Bool())
case "sharesPid":
out.UsePodPID = bool(in.Bool())
case "sharesIpc":
out.UsePodIPC = bool(in.Bool())
case "sharesNet":
out.UsePodNet = bool(in.Bool())
case "sharesMnt":
out.UsePodMount = bool(in.Bool())
case "sharesUser":
out.UsePodUser = bool(in.Bool())
case "sharesUts":
out.UsePodUTS = bool(in.Bool())
case "infraConfig":
if in.IsNull() {
in.Skip()
out.InfraContainer = nil
} else {
if out.InfraContainer == nil {
out.InfraContainer = new(InfraContainerConfig)
}
easyjsonBe091417DecodeGithubComContainersLibpodLibpod5(in, &*out.InfraContainer)
}
case "created":
if data := in.Raw(); in.Ok() {
in.AddError((out.CreatedTime).UnmarshalJSON(data))
}
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjsonBe091417EncodeGithubComContainersLibpodLibpod4(out *jwriter.Writer, in PodConfig) {
out.RawByte('{')
first := true
_ = first
{
const prefix string = ",\"id\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.ID))
}
{
const prefix string = ",\"name\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Name))
}
if in.Namespace != "" {
const prefix string = ",\"namespace\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Namespace))
}
{
const prefix string = ",\"labels\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
if in.Labels == nil && (out.Flags&jwriter.NilMapAsEmpty) == 0 {
out.RawString(`null`)
} else {
out.RawByte('{')
v5First := true
for v5Name, v5Value := range in.Labels {
if v5First {
v5First = false
} else {
out.RawByte(',')
}
out.String(string(v5Name))
out.RawByte(':')
out.String(string(v5Value))
}
out.RawByte('}')
}
}
{
const prefix string = ",\"cgroupParent\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.CgroupParent))
}
if in.UsePodCgroup {
const prefix string = ",\"sharesCgroup\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Bool(bool(in.UsePodCgroup))
}
if in.UsePodPID {
const prefix string = ",\"sharesPid\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Bool(bool(in.UsePodPID))
}
if in.UsePodIPC {
const prefix string = ",\"sharesIpc\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Bool(bool(in.UsePodIPC))
}
if in.UsePodNet {
const prefix string = ",\"sharesNet\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Bool(bool(in.UsePodNet))
}
if in.UsePodMount {
const prefix string = ",\"sharesMnt\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Bool(bool(in.UsePodMount))
}
if in.UsePodUser {
const prefix string = ",\"sharesUser\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Bool(bool(in.UsePodUser))
}
if in.UsePodUTS {
const prefix string = ",\"sharesUts\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Bool(bool(in.UsePodUTS))
}
{
const prefix string = ",\"infraConfig\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
if in.InfraContainer == nil {
out.RawString("null")
} else {
easyjsonBe091417EncodeGithubComContainersLibpodLibpod5(out, *in.InfraContainer)
}
}
{
const prefix string = ",\"created\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Raw((in.CreatedTime).MarshalJSON())
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v PodConfig) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonBe091417EncodeGithubComContainersLibpodLibpod4(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v PodConfig) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonBe091417EncodeGithubComContainersLibpodLibpod4(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *PodConfig) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonBe091417DecodeGithubComContainersLibpodLibpod4(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *PodConfig) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonBe091417DecodeGithubComContainersLibpodLibpod4(l, v)
}
func easyjsonBe091417DecodeGithubComContainersLibpodLibpod5(in *jlexer.Lexer, out *InfraContainerConfig) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "makeInfraContainer":
out.HasInfraContainer = bool(in.Bool())
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjsonBe091417EncodeGithubComContainersLibpodLibpod5(out *jwriter.Writer, in InfraContainerConfig) {
out.RawByte('{')
first := true
_ = first
{
const prefix string = ",\"makeInfraContainer\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Bool(bool(in.HasInfraContainer))
}
out.RawByte('}')
}

View file

@ -2,6 +2,7 @@ package createconfig
import (
"encoding/json"
"net"
"os"
"strconv"
"strings"
@ -311,9 +312,6 @@ func (c *CreateConfig) GetContainerCreateOptions(runtime *libpod.Runtime) ([]lib
var pod *libpod.Pod
var err error
// Uncomment after talking to mheon about unimplemented funcs
// options = append(options, libpod.WithLabels(c.labels))
if c.Interactive {
options = append(options, libpod.WithStdin())
}
@ -442,6 +440,15 @@ func (c *CreateConfig) GetContainerCreateOptions(runtime *libpod.Runtime) ([]lib
if logPath != "" {
options = append(options, libpod.WithLogPath(logPath))
}
if c.IPAddress != "" {
ip := net.ParseIP(c.IPAddress)
if ip == nil {
return nil, errors.Wrapf(libpod.ErrInvalidArg, "cannot parse %s as IP address", c.IPAddress)
} else if ip.To4() == nil {
return nil, errors.Wrapf(libpod.ErrInvalidArg, "%s is not an IPv4 address", c.IPAddress)
}
options = append(options, libpod.WithStaticIP(ip))
}
options = append(options, libpod.WithPrivileged(c.Privileged))