diff options
author | baude <bbaude@redhat.com> | 2021-03-15 14:52:43 -0500 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2021-03-25 08:43:51 -0500 |
commit | b5f54a9b23e8d9418700494da9aa78d8db354c43 (patch) | |
tree | 59dfb9edf3faf6d184f6af40522f71968948133a /pkg/specgen | |
parent | a861f6fd3ebe4fe0b63a1b550e6b99d7525228c0 (diff) | |
download | podman-b5f54a9b23e8d9418700494da9aa78d8db354c43.tar.gz podman-b5f54a9b23e8d9418700494da9aa78d8db354c43.tar.bz2 podman-b5f54a9b23e8d9418700494da9aa78d8db354c43.zip |
introduce podman machine
podman machine allows podman to create, manage, and interact with a vm
running some form of linux (default is fcos). podman is then configured
to be able to interact with the vm automatically.
while this is usable on linux, the real push is to get this working on
both current apple architectures in macos.
Ashley Cui contributed to this PR and was a great help.
[NO TESTS NEEDED]
Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/specgen')
-rw-r--r-- | pkg/specgen/generate/ports.go | 22 | ||||
-rw-r--r-- | pkg/specgen/ports.go | 26 |
2 files changed, 28 insertions, 20 deletions
diff --git a/pkg/specgen/generate/ports.go b/pkg/specgen/generate/ports.go index 6cf83ed81..d5d779c8f 100644 --- a/pkg/specgen/generate/ports.go +++ b/pkg/specgen/generate/ports.go @@ -218,7 +218,7 @@ func parsePortMapping(portMappings []specgen.PortMapping) ([]ocicni.PortMapping, // Only get a random candidate for single entries or the start // of a range. Otherwise we just increment the candidate. if !tmp.isInRange || tmp.startOfRange { - candidate, err = getRandomPort() + candidate, err = specgen.GetRandomPort() if err != nil { return nil, nil, nil, errors.Wrapf(err, "error getting candidate host port for container port %d", p.ContainerPort) } @@ -344,7 +344,7 @@ func createPortMappings(ctx context.Context, s *specgen.SpecGenerator, img *imag for hostPort == 0 && tries > 0 { // We can't select a specific protocol, which is // unfortunate for the UDP case. - candidate, err := getRandomPort() + candidate, err := specgen.GetRandomPort() if err != nil { return nil, err } @@ -419,21 +419,3 @@ func checkProtocol(protocol string, allowSCTP bool) ([]string, error) { return finalProto, nil } - -// Find a random, open port on the host -func getRandomPort() (int, error) { - l, err := net.Listen("tcp", ":0") - if err != nil { - return 0, errors.Wrapf(err, "unable to get free TCP port") - } - defer l.Close() - _, randomPort, err := net.SplitHostPort(l.Addr().String()) - if err != nil { - return 0, errors.Wrapf(err, "unable to determine free port") - } - rp, err := strconv.Atoi(randomPort) - if err != nil { - return 0, errors.Wrapf(err, "unable to convert random port to int") - } - return rp, nil -} diff --git a/pkg/specgen/ports.go b/pkg/specgen/ports.go new file mode 100644 index 000000000..940b2a564 --- /dev/null +++ b/pkg/specgen/ports.go @@ -0,0 +1,26 @@ +package specgen + +import ( + "net" + "strconv" + + "github.com/pkg/errors" +) + +// Find a random, open port on the host +func GetRandomPort() (int, error) { + l, err := net.Listen("tcp", ":0") + if err != nil { + return 0, errors.Wrapf(err, "unable to get free TCP port") + } + defer l.Close() + _, randomPort, err := net.SplitHostPort(l.Addr().String()) + if err != nil { + return 0, errors.Wrapf(err, "unable to determine free port") + } + rp, err := strconv.Atoi(randomPort) + if err != nil { + return 0, errors.Wrapf(err, "unable to convert random port to int") + } + return rp, nil +} |