7
7
"os"
8
8
"path/filepath"
9
9
"regexp"
10
- "strconv"
11
10
"strings"
12
11
13
12
"github.com/docker/docker/pkg/namesgenerator"
@@ -98,7 +97,7 @@ func (cli *HyperClient) JsonFromCmdline(container bool, cmdArgs, cmdEnvs, cmdPor
98
97
image = cmdArgs [0 ]
99
98
command = []string {}
100
99
env = []* apitype.EnvironmentVar {}
101
- ports = []* apitype.UserContainerPort {}
100
+ ports = []* apitype.PortMapping {}
102
101
logOpts = make (map [string ]string )
103
102
labels = make (map [string ]string )
104
103
volumesRef = []* apitype.UserVolumeReference {}
@@ -170,7 +169,6 @@ func (cli *HyperClient) JsonFromCmdline(container bool, cmdArgs, cmdEnvs, cmdPor
170
169
Command : command ,
171
170
Workdir : cmdWorkdir ,
172
171
Entrypoint : entrypoints ,
173
- Ports : ports ,
174
172
Envs : env ,
175
173
Volumes : volumesRef ,
176
174
Files : []* apitype.UserFileReference {},
@@ -190,6 +188,7 @@ func (cli *HyperClient) JsonFromCmdline(container bool, cmdArgs, cmdEnvs, cmdPor
190
188
Type : cmdLogDriver ,
191
189
Config : logOpts ,
192
190
},
191
+ Portmappings : ports ,
193
192
}
194
193
body = userPod
195
194
}
@@ -265,45 +264,36 @@ func parseVolume(volStr string) (*apitype.UserVolume, *apitype.UserVolumeReferen
265
264
return & vol , & volRef , nil
266
265
}
267
266
268
- func parsePortMapping (portmap string ) (* apitype.UserContainerPort , error ) {
267
+ func parsePortMapping (portmap string ) (* apitype.PortMapping , error ) {
269
268
270
269
var (
271
- port = apitype.UserContainerPort {}
272
- proto string
273
- hPort string
274
- cPort string
275
- err error
270
+ tmp * apitype.PortMapping
271
+ port * apitype.PortMapping
272
+ err error
276
273
)
277
274
278
275
fields := strings .Split (portmap , ":" )
279
276
if len (fields ) < 2 {
280
277
return nil , fmt .Errorf ("flag needs host port and container port: --publish" )
281
278
} else if len (fields ) == 2 {
282
- proto = "tcp"
283
- hPort = fields [0 ]
284
- cPort = fields [1 ]
279
+ tmp = & apitype.PortMapping {
280
+ Protocol : "tcp" ,
281
+ ContainerPort : fields [1 ],
282
+ HostPort : fields [0 ],
283
+ }
285
284
} else {
286
- proto = fields [0 ]
287
- if proto != "tcp" && proto != "udp" {
288
- return nil , fmt .Errorf ("flag needs protocol(tcp or udp): --publish" )
285
+ tmp = & apitype.PortMapping {
286
+ Protocol : fields [0 ],
287
+ ContainerPort : fields [2 ],
288
+ HostPort : fields [1 ],
289
289
}
290
- hPort = fields [1 ]
291
- cPort = fields [2 ]
292
290
}
293
291
294
- port .Protocol = proto
295
- hp , err := strconv .Atoi (hPort )
296
- port .HostPort = int32 (hp )
297
- if err != nil {
298
- return nil , fmt .Errorf ("flag needs host port and container port: --publish: %v" , err )
299
- }
300
- cp , err := strconv .Atoi (cPort )
301
- port .ContainerPort = int32 (cp )
292
+ port , err = tmp .Formalize ()
302
293
if err != nil {
303
- return nil , fmt . Errorf ( "flag needs host port and container port: --publish: %v" , err )
294
+ return nil , err
304
295
}
305
-
306
- return & port , nil
296
+ return port , nil
307
297
}
308
298
309
299
func imageToName (image string ) string {
0 commit comments