summaryrefslogtreecommitdiff
path: root/pkg/api
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-12-15 15:25:14 +0100
committerGitHub <noreply@github.com>2021-12-15 15:25:14 +0100
commit7dabcbd7bcf78f3b5d310ed547801106da382618 (patch)
tree7b92c3ca37025a833a0d9651afeb19ba7c903cc8 /pkg/api
parentb01a421f3413ba01b2c189b82c8153bdbd2a05fb (diff)
parentef325bc8c4824537e4bfb21aa7e6114a6e5a8c09 (diff)
downloadpodman-7dabcbd7bcf78f3b5d310ed547801106da382618.tar.gz
podman-7dabcbd7bcf78f3b5d310ed547801106da382618.tar.bz2
podman-7dabcbd7bcf78f3b5d310ed547801106da382618.zip
Merge pull request #12534 from Luap99/network-db
network db rewrite
Diffstat (limited to 'pkg/api')
-rw-r--r--pkg/api/handlers/compat/networks.go52
-rw-r--r--pkg/api/handlers/compat/swagger.go10
-rw-r--r--pkg/api/handlers/libpod/networks.go2
-rw-r--r--pkg/api/handlers/libpod/play.go4
-rw-r--r--pkg/api/handlers/libpod/swagger.go6
-rw-r--r--pkg/api/server/register_networks.go6
-rw-r--r--pkg/api/server/register_play.go6
7 files changed, 69 insertions, 17 deletions
diff --git a/pkg/api/handlers/compat/networks.go b/pkg/api/handlers/compat/networks.go
index 8aab29658..db3af7d0b 100644
--- a/pkg/api/handlers/compat/networks.go
+++ b/pkg/api/handlers/compat/networks.go
@@ -299,20 +299,66 @@ func Connect(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
var (
- aliases []string
netConnect types.NetworkConnect
)
if err := json.NewDecoder(r.Body).Decode(&netConnect); err != nil {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
return
}
+
+ netOpts := nettypes.PerNetworkOptions{}
+
name := utils.GetName(r)
if netConnect.EndpointConfig != nil {
if netConnect.EndpointConfig.Aliases != nil {
- aliases = netConnect.EndpointConfig.Aliases
+ netOpts.Aliases = netConnect.EndpointConfig.Aliases
+ }
+
+ // if IP address is provided
+ if len(netConnect.EndpointConfig.IPAddress) > 0 {
+ staticIP := net.ParseIP(netConnect.EndpointConfig.IPAddress)
+ if staticIP == nil {
+ utils.Error(w, "failed to parse the ip address", http.StatusInternalServerError,
+ errors.Errorf("failed to parse the ip address %q", netConnect.EndpointConfig.IPAddress))
+ return
+ }
+ netOpts.StaticIPs = append(netOpts.StaticIPs, staticIP)
+ }
+
+ if netConnect.EndpointConfig.IPAMConfig != nil {
+ // if IPAMConfig.IPv4Address is provided
+ if len(netConnect.EndpointConfig.IPAMConfig.IPv4Address) > 0 {
+ staticIP := net.ParseIP(netConnect.EndpointConfig.IPAMConfig.IPv4Address)
+ if staticIP == nil {
+ utils.Error(w, "failed to parse the ipv4 address", http.StatusInternalServerError,
+ errors.Errorf("failed to parse the ipv4 address %q", netConnect.EndpointConfig.IPAMConfig.IPv4Address))
+ return
+ }
+ netOpts.StaticIPs = append(netOpts.StaticIPs, staticIP)
+ }
+ // if IPAMConfig.IPv6Address is provided
+ if len(netConnect.EndpointConfig.IPAMConfig.IPv6Address) > 0 {
+ staticIP := net.ParseIP(netConnect.EndpointConfig.IPAMConfig.IPv6Address)
+ if staticIP == nil {
+ utils.Error(w, "failed to parse the ipv6 address", http.StatusInternalServerError,
+ errors.Errorf("failed to parse the ipv6 address %q", netConnect.EndpointConfig.IPAMConfig.IPv6Address))
+ return
+ }
+ netOpts.StaticIPs = append(netOpts.StaticIPs, staticIP)
+ }
+ }
+ // If MAC address is provided
+ if len(netConnect.EndpointConfig.MacAddress) > 0 {
+ staticMac, err := net.ParseMAC(netConnect.EndpointConfig.MacAddress)
+ if err != nil {
+ utils.Error(w, "failed to parse the mac address", http.StatusInternalServerError,
+ errors.Errorf("failed to parse the mac address %q", netConnect.EndpointConfig.IPAMConfig.IPv6Address))
+ return
+ }
+ netOpts.StaticMAC = nettypes.HardwareAddr(staticMac)
}
}
- err := runtime.ConnectContainerToNetwork(netConnect.Container, name, aliases)
+ err := runtime.ConnectContainerToNetwork(netConnect.Container, name, netOpts)
if err != nil {
if errors.Cause(err) == define.ErrNoSuchCtr {
utils.ContainerNotFound(w, netConnect.Container, err)
diff --git a/pkg/api/handlers/compat/swagger.go b/pkg/api/handlers/compat/swagger.go
index cfbdd1154..32167d6b5 100644
--- a/pkg/api/handlers/compat/swagger.go
+++ b/pkg/api/handlers/compat/swagger.go
@@ -55,15 +55,13 @@ type swagCompatNetworkCreateResponse struct {
}
// Network disconnect
-// swagger:model NetworkConnectRequest
+// swagger:model NetworkCompatConnectRequest
type swagCompatNetworkConnectRequest struct {
- // in:body
- Body struct{ types.NetworkConnect }
+ types.NetworkConnect
}
// Network disconnect
-// swagger:model NetworkDisconnectRequest
+// swagger:model NetworkCompatDisconnectRequest
type swagCompatNetworkDisconnectRequest struct {
- // in:body
- Body struct{ types.NetworkDisconnect }
+ types.NetworkDisconnect
}
diff --git a/pkg/api/handlers/libpod/networks.go b/pkg/api/handlers/libpod/networks.go
index 1f7f2e26c..a28c3c57c 100644
--- a/pkg/api/handlers/libpod/networks.go
+++ b/pkg/api/handlers/libpod/networks.go
@@ -125,7 +125,7 @@ func Connect(w http.ResponseWriter, r *http.Request) {
return
}
name := utils.GetName(r)
- err := runtime.ConnectContainerToNetwork(netConnect.Container, name, netConnect.Aliases)
+ err := runtime.ConnectContainerToNetwork(netConnect.Container, name, netConnect.PerNetworkOptions)
if err != nil {
if errors.Cause(err) == define.ErrNoSuchCtr {
utils.ContainerNotFound(w, netConnect.Container, err)
diff --git a/pkg/api/handlers/libpod/play.go b/pkg/api/handlers/libpod/play.go
index f943fc240..312aa32de 100644
--- a/pkg/api/handlers/libpod/play.go
+++ b/pkg/api/handlers/libpod/play.go
@@ -23,7 +23,7 @@ func PlayKube(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
query := struct {
- Network string `schema:"network"`
+ Network []string `schema:"network"`
TLSVerify bool `schema:"tlsVerify"`
LogDriver string `schema:"logDriver"`
LogOptions []string `schema:"logOptions"`
@@ -103,7 +103,7 @@ func PlayKube(w http.ResponseWriter, r *http.Request) {
Authfile: authfile,
Username: username,
Password: password,
- Network: query.Network,
+ Networks: query.Network,
NoHosts: query.NoHosts,
Quiet: true,
LogDriver: query.LogDriver,
diff --git a/pkg/api/handlers/libpod/swagger.go b/pkg/api/handlers/libpod/swagger.go
index 7ccfdd0f3..8d7058b1e 100644
--- a/pkg/api/handlers/libpod/swagger.go
+++ b/pkg/api/handlers/libpod/swagger.go
@@ -133,6 +133,12 @@ type swagNetworkPruneResponse struct {
Body []entities.NetworkPruneReport
}
+// Network connect
+// swagger:model NetworkConnectRequest
+type swagNetworkConnectRequest struct {
+ entities.NetworkConnectOptions
+}
+
func ServeSwagger(w http.ResponseWriter, r *http.Request) {
path := DefaultPodmanSwaggerSpec
if p, found := os.LookupEnv("PODMAN_SWAGGER_SPEC"); found {
diff --git a/pkg/api/server/register_networks.go b/pkg/api/server/register_networks.go
index 641bce333..344486299 100644
--- a/pkg/api/server/register_networks.go
+++ b/pkg/api/server/register_networks.go
@@ -131,7 +131,7 @@ func (s *APIServer) registerNetworkHandlers(r *mux.Router) error {
// name: create
// description: attributes for connecting a container to a network
// schema:
- // $ref: "#/definitions/NetworkConnectRequest"
+ // $ref: "#/definitions/NetworkCompatConnectRequest"
// responses:
// 200:
// description: OK
@@ -159,7 +159,7 @@ func (s *APIServer) registerNetworkHandlers(r *mux.Router) error {
// name: create
// description: attributes for disconnecting a container from a network
// schema:
- // $ref: "#/definitions/NetworkDisconnectRequest"
+ // $ref: "#/definitions/NetworkCompatDisconnectRequest"
// responses:
// 200:
// description: OK
@@ -368,7 +368,7 @@ func (s *APIServer) registerNetworkHandlers(r *mux.Router) error {
// name: create
// description: attributes for disconnecting a container from a network
// schema:
- // $ref: "#/definitions/NetworkDisconnectRequest"
+ // $ref: "#/definitions/NetworkCompatDisconnectRequest"
// responses:
// 200:
// description: OK
diff --git a/pkg/api/server/register_play.go b/pkg/api/server/register_play.go
index 915d0d02e..5ace01929 100644
--- a/pkg/api/server/register_play.go
+++ b/pkg/api/server/register_play.go
@@ -18,8 +18,10 @@ func (s *APIServer) registerPlayHandlers(r *mux.Router) error {
// parameters:
// - in: query
// name: network
- // type: string
- // description: Connect the pod to this network.
+ // type: array
+ // description: USe the network mode or specify an array of networks.
+ // items:
+ // type: string
// - in: query
// name: tlsVerify
// type: boolean