mirror of
https://github.com/containers/podman.git
synced 2025-05-21 17:16:22 +08:00
Merge pull request #6197 from baude/v2remotenetwork
enable podman v2 networking for remote client
This commit is contained in:
@ -46,7 +46,7 @@ func networkCreateFlags(flags *pflag.FlagSet) {
|
|||||||
}
|
}
|
||||||
func init() {
|
func init() {
|
||||||
registry.Commands = append(registry.Commands, registry.CliCommand{
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
||||||
Mode: []entities.EngineMode{entities.ABIMode},
|
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
|
||||||
Command: networkCreateCommand,
|
Command: networkCreateCommand,
|
||||||
Parent: networkCmd,
|
Parent: networkCmd,
|
||||||
})
|
})
|
||||||
|
@ -26,7 +26,7 @@ var (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.Commands = append(registry.Commands, registry.CliCommand{
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
||||||
Mode: []entities.EngineMode{entities.ABIMode},
|
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
|
||||||
Command: networkinspectCommand,
|
Command: networkinspectCommand,
|
||||||
Parent: networkCmd,
|
Parent: networkCmd,
|
||||||
})
|
})
|
||||||
|
@ -4,13 +4,12 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"text/tabwriter"
|
||||||
"github.com/containers/libpod/cmd/podman/validate"
|
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/registry"
|
"github.com/containers/libpod/cmd/podman/registry"
|
||||||
|
"github.com/containers/libpod/cmd/podman/validate"
|
||||||
"github.com/containers/libpod/pkg/domain/entities"
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
"github.com/containers/libpod/pkg/network"
|
"github.com/containers/libpod/pkg/network"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -47,7 +46,7 @@ func networkListFlags(flags *pflag.FlagSet) {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.Commands = append(registry.Commands, registry.CliCommand{
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
||||||
Mode: []entities.EngineMode{entities.ABIMode},
|
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
|
||||||
Command: networklistCommand,
|
Command: networklistCommand,
|
||||||
Parent: networkCmd,
|
Parent: networkCmd,
|
||||||
})
|
})
|
||||||
@ -57,7 +56,6 @@ func init() {
|
|||||||
|
|
||||||
func networkList(cmd *cobra.Command, args []string) error {
|
func networkList(cmd *cobra.Command, args []string) error {
|
||||||
var (
|
var (
|
||||||
w io.Writer = os.Stdout
|
|
||||||
nlprs []NetworkListPrintReports
|
nlprs []NetworkListPrintReports
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -95,13 +93,11 @@ func networkList(cmd *cobra.Command, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||||
if err := tmpl.Execute(w, nlprs); err != nil {
|
if err := tmpl.Execute(w, nlprs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if flusher, ok := w.(interface{ Flush() error }); ok {
|
return w.Flush()
|
||||||
return flusher.Flush()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func quietOut(responses []*entities.NetworkListReport) error {
|
func quietOut(responses []*entities.NetworkListReport) error {
|
||||||
|
@ -20,7 +20,7 @@ var (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.Commands = append(registry.Commands, registry.CliCommand{
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
||||||
Mode: []entities.EngineMode{entities.ABIMode},
|
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
|
||||||
Command: networkCmd,
|
Command: networkCmd,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func networkRmFlags(flags *pflag.FlagSet) {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.Commands = append(registry.Commands, registry.CliCommand{
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
||||||
Mode: []entities.EngineMode{entities.ABIMode},
|
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
|
||||||
Command: networkrmCommand,
|
Command: networkrmCommand,
|
||||||
Parent: networkCmd,
|
Parent: networkCmd,
|
||||||
})
|
})
|
||||||
|
@ -5,10 +5,9 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/containers/libpod/pkg/domain/entities"
|
|
||||||
|
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/pkg/api/handlers/utils"
|
"github.com/containers/libpod/pkg/api/handlers/utils"
|
||||||
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
"github.com/containers/libpod/pkg/specgen"
|
"github.com/containers/libpod/pkg/specgen"
|
||||||
"github.com/containers/libpod/pkg/specgen/generate"
|
"github.com/containers/libpod/pkg/specgen/generate"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -1,39 +1,59 @@
|
|||||||
package libpod
|
package libpod
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/pkg/api/handlers/utils"
|
"github.com/containers/libpod/pkg/api/handlers/utils"
|
||||||
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
|
"github.com/containers/libpod/pkg/domain/infra/abi"
|
||||||
"github.com/containers/libpod/pkg/network"
|
"github.com/containers/libpod/pkg/network"
|
||||||
"github.com/gorilla/schema"
|
"github.com/gorilla/schema"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateNetwork(w http.ResponseWriter, r *http.Request) {}
|
func CreateNetwork(w http.ResponseWriter, r *http.Request) {
|
||||||
|
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||||
|
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||||
|
options := entities.NetworkCreateOptions{}
|
||||||
|
if err := json.NewDecoder(r.Body).Decode(&options); err != nil {
|
||||||
|
utils.Error(w, "unable to marshall input", http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
query := struct {
|
||||||
|
Name string `schema:"name"`
|
||||||
|
}{
|
||||||
|
// override any golang type defaults
|
||||||
|
}
|
||||||
|
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
|
||||||
|
utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
|
||||||
|
errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ic := abi.ContainerEngine{Libpod: runtime}
|
||||||
|
report, err := ic.NetworkCreate(r.Context(), query.Name, options)
|
||||||
|
if err != nil {
|
||||||
|
utils.InternalServerError(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
utils.WriteResponse(w, http.StatusOK, report)
|
||||||
|
|
||||||
|
}
|
||||||
func ListNetworks(w http.ResponseWriter, r *http.Request) {
|
func ListNetworks(w http.ResponseWriter, r *http.Request) {
|
||||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||||
config, err := runtime.GetConfig()
|
options := entities.NetworkListOptions{}
|
||||||
|
ic := abi.ContainerEngine{Libpod: runtime}
|
||||||
|
reports, err := ic.NetworkList(r.Context(), options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.InternalServerError(w, err)
|
utils.InternalServerError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
configDir := config.Network.NetworkConfigDir
|
utils.WriteResponse(w, http.StatusOK, reports)
|
||||||
if len(configDir) < 1 {
|
|
||||||
configDir = network.CNIConfigDir
|
|
||||||
}
|
|
||||||
networks, err := network.LoadCNIConfsFromDir(configDir)
|
|
||||||
if err != nil {
|
|
||||||
utils.InternalServerError(w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
utils.WriteResponse(w, http.StatusOK, networks)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
|
func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
|
||||||
// 200 ok
|
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||||
// 404 no such
|
|
||||||
// 500 internal
|
|
||||||
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||||
query := struct {
|
query := struct {
|
||||||
Force bool `schema:"force"`
|
Force bool `schema:"force"`
|
||||||
@ -46,22 +66,30 @@ func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
name := utils.GetName(r)
|
name := utils.GetName(r)
|
||||||
if err := network.RemoveNetwork(name); err != nil {
|
|
||||||
|
options := entities.NetworkRmOptions{
|
||||||
|
Force: query.Force,
|
||||||
|
}
|
||||||
|
ic := abi.ContainerEngine{Libpod: runtime}
|
||||||
|
reports, err := ic.NetworkRm(r.Context(), []string{name}, options)
|
||||||
|
if err != nil {
|
||||||
|
utils.InternalServerError(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if reports[0].Err != nil {
|
||||||
// If the network cannot be found, we return a 404.
|
// If the network cannot be found, we return a 404.
|
||||||
if errors.Cause(err) == network.ErrNetworkNotFound {
|
if errors.Cause(err) == network.ErrNetworkNotFound {
|
||||||
utils.Error(w, "Something went wrong", http.StatusNotFound, err)
|
utils.Error(w, "Something went wrong", http.StatusNotFound, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
utils.InternalServerError(w, err)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
utils.WriteResponse(w, http.StatusOK, "")
|
utils.WriteResponse(w, http.StatusOK, reports)
|
||||||
}
|
}
|
||||||
|
|
||||||
func InspectNetwork(w http.ResponseWriter, r *http.Request) {
|
func InspectNetwork(w http.ResponseWriter, r *http.Request) {
|
||||||
|
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||||
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||||
query := struct {
|
query := struct {
|
||||||
Force bool `schema:"force"`
|
|
||||||
}{
|
}{
|
||||||
// override any golang type defaults
|
// override any golang type defaults
|
||||||
}
|
}
|
||||||
@ -71,7 +99,9 @@ func InspectNetwork(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
name := utils.GetName(r)
|
name := utils.GetName(r)
|
||||||
n, err := network.InspectNetwork(name)
|
options := entities.NetworkInspectOptions{}
|
||||||
|
ic := abi.ContainerEngine{Libpod: runtime}
|
||||||
|
reports, err := ic.NetworkInspect(r.Context(), []string{name}, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If the network cannot be found, we return a 404.
|
// If the network cannot be found, we return a 404.
|
||||||
if errors.Cause(err) == network.ErrNetworkNotFound {
|
if errors.Cause(err) == network.ErrNetworkNotFound {
|
||||||
@ -81,5 +111,5 @@ func InspectNetwork(w http.ResponseWriter, r *http.Request) {
|
|||||||
utils.InternalServerError(w, err)
|
utils.InternalServerError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
utils.WriteResponse(w, http.StatusOK, n)
|
utils.WriteResponse(w, http.StatusOK, reports)
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,34 @@ type swagInfoResponse struct {
|
|||||||
Body define.Info
|
Body define.Info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Network rm
|
||||||
|
// swagger:response NetworkRmReport
|
||||||
|
type swagNetworkRmReport struct {
|
||||||
|
// in:body
|
||||||
|
Body entities.NetworkRmReport
|
||||||
|
}
|
||||||
|
|
||||||
|
// Network inspect
|
||||||
|
// swagger:response NetworkInspectReport
|
||||||
|
type swagNetworkInspectReport struct {
|
||||||
|
// in:body
|
||||||
|
Body []entities.NetworkInspectReport
|
||||||
|
}
|
||||||
|
|
||||||
|
// Network list
|
||||||
|
// swagger:response NetworkListReport
|
||||||
|
type swagNetworkListReport struct {
|
||||||
|
// in:body
|
||||||
|
Body []entities.NetworkListReport
|
||||||
|
}
|
||||||
|
|
||||||
|
// Network create
|
||||||
|
// swagger:response NetworkCreateReport
|
||||||
|
type swagNetworkCreateReport struct {
|
||||||
|
// in:body
|
||||||
|
Body entities.NetworkCreateReport
|
||||||
|
}
|
||||||
|
|
||||||
func ServeSwagger(w http.ResponseWriter, r *http.Request) {
|
func ServeSwagger(w http.ResponseWriter, r *http.Request) {
|
||||||
path := DefaultPodmanSwaggerSpec
|
path := DefaultPodmanSwaggerSpec
|
||||||
if p, found := os.LookupEnv("PODMAN_SWAGGER_SPEC"); found {
|
if p, found := os.LookupEnv("PODMAN_SWAGGER_SPEC"); found {
|
||||||
|
100
pkg/api/server/register_networks.go
Normal file
100
pkg/api/server/register_networks.go
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/containers/libpod/pkg/api/handlers/libpod"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *APIServer) registerNetworkHandlers(r *mux.Router) error {
|
||||||
|
// swagger:operation DELETE /libpod/networks/{name} libpod libpodRemoveNetwork
|
||||||
|
// ---
|
||||||
|
// tags:
|
||||||
|
// - networks
|
||||||
|
// summary: Remove a network
|
||||||
|
// description: Remove a CNI configured network
|
||||||
|
// parameters:
|
||||||
|
// - in: path
|
||||||
|
// name: name
|
||||||
|
// type: string
|
||||||
|
// required: true
|
||||||
|
// description: the name of the network
|
||||||
|
// - in: query
|
||||||
|
// name: Force
|
||||||
|
// type: boolean
|
||||||
|
// description: remove containers associated with network
|
||||||
|
// produces:
|
||||||
|
// - application/json
|
||||||
|
// responses:
|
||||||
|
// 200:
|
||||||
|
// $ref: "#/responses/NetworkRmReport"
|
||||||
|
// 404:
|
||||||
|
// $ref: "#/responses/NoSuchNetwork"
|
||||||
|
// 500:
|
||||||
|
// $ref: "#/responses/InternalError"
|
||||||
|
r.HandleFunc(VersionedPath("/libpod/networks/{name}"), s.APIHandler(libpod.RemoveNetwork)).Methods(http.MethodDelete)
|
||||||
|
// swagger:operation GET /libpod/networks/{name}/json libpod libpodInspectNetwork
|
||||||
|
// ---
|
||||||
|
// tags:
|
||||||
|
// - networks
|
||||||
|
// summary: Inspect a network
|
||||||
|
// description: Display low level configuration for a CNI network
|
||||||
|
// parameters:
|
||||||
|
// - in: path
|
||||||
|
// name: name
|
||||||
|
// type: string
|
||||||
|
// required: true
|
||||||
|
// description: the name of the network
|
||||||
|
// produces:
|
||||||
|
// - application/json
|
||||||
|
// responses:
|
||||||
|
// 200:
|
||||||
|
// $ref: "#/responses/NetworkInspectReport"
|
||||||
|
// 404:
|
||||||
|
// $ref: "#/responses/NoSuchNetwork"
|
||||||
|
// 500:
|
||||||
|
// $ref: "#/responses/InternalError"
|
||||||
|
r.HandleFunc(VersionedPath("/libpod/networks/{name}/json"), s.APIHandler(libpod.InspectNetwork)).Methods(http.MethodGet)
|
||||||
|
// swagger:operation GET /libpod/networks/json libpod libpodListNetwork
|
||||||
|
// ---
|
||||||
|
// tags:
|
||||||
|
// - networks
|
||||||
|
// summary: List networks
|
||||||
|
// description: Display summary of network configurations
|
||||||
|
// produces:
|
||||||
|
// - application/json
|
||||||
|
// responses:
|
||||||
|
// 200:
|
||||||
|
// $ref: "#/responses/NetworkListReport"
|
||||||
|
// 500:
|
||||||
|
// $ref: "#/responses/InternalError"
|
||||||
|
r.HandleFunc(VersionedPath("/libpod/networks/json"), s.APIHandler(libpod.ListNetworks)).Methods(http.MethodGet)
|
||||||
|
// swagger:operation POST /libpod/networks/create libpod libpodCreateNetwork
|
||||||
|
// ---
|
||||||
|
// tags:
|
||||||
|
// - networks
|
||||||
|
// summary: Create network
|
||||||
|
// description: Create a new CNI network configuration
|
||||||
|
// produces:
|
||||||
|
// - application/json
|
||||||
|
// parameters:
|
||||||
|
// - in: query
|
||||||
|
// name: name
|
||||||
|
// type: string
|
||||||
|
// description: optional name for new network
|
||||||
|
// - in: body
|
||||||
|
// name: create
|
||||||
|
// description: attributes for creating a container
|
||||||
|
// schema:
|
||||||
|
// $ref: "#/definitions/NetworkCreateOptions"
|
||||||
|
// responses:
|
||||||
|
// 200:
|
||||||
|
// $ref: "#/responses/NetworkCreateReport"
|
||||||
|
// 400:
|
||||||
|
// $ref: "#/responses/BadParamError"
|
||||||
|
// 500:
|
||||||
|
// $ref: "#/responses/InternalError"
|
||||||
|
r.HandleFunc(VersionedPath("/libpod/networks/create"), s.APIHandler(libpod.CreateNetwork)).Methods(http.MethodPost)
|
||||||
|
return nil
|
||||||
|
}
|
@ -104,6 +104,7 @@ func newServer(runtime *libpod.Runtime, duration time.Duration, listener *net.Li
|
|||||||
server.registerInfoHandlers,
|
server.registerInfoHandlers,
|
||||||
server.registerManifestHandlers,
|
server.registerManifestHandlers,
|
||||||
server.registerMonitorHandlers,
|
server.registerMonitorHandlers,
|
||||||
|
server.registerNetworkHandlers,
|
||||||
server.registerPingHandlers,
|
server.registerPingHandlers,
|
||||||
server.registerPlayHandlers,
|
server.registerPlayHandlers,
|
||||||
server.registerPluginsHandlers,
|
server.registerPluginsHandlers,
|
||||||
|
@ -24,6 +24,15 @@ type swagErrNoSuchContainer struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No such network
|
||||||
|
// swagger:response NoSuchNetwork
|
||||||
|
type swagErrNoSuchNetwork struct {
|
||||||
|
// in:body
|
||||||
|
Body struct {
|
||||||
|
entities.ErrorModel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// No such exec instance
|
// No such exec instance
|
||||||
// swagger:response NoSuchExecInstance
|
// swagger:response NoSuchExecInstance
|
||||||
type swagErrNoSuchExecInstance struct {
|
type swagErrNoSuchExecInstance struct {
|
||||||
|
@ -5,9 +5,11 @@ tags:
|
|||||||
description: Actions related to exec
|
description: Actions related to exec
|
||||||
- name: images
|
- name: images
|
||||||
description: Actions related to images
|
description: Actions related to images
|
||||||
- name: pods
|
|
||||||
description: Actions related to manifests
|
|
||||||
- name: manifests
|
- name: manifests
|
||||||
|
description: Actions related to manifests
|
||||||
|
- name: networks
|
||||||
|
description: Actions related to networks
|
||||||
|
- name: pods
|
||||||
description: Actions related to pods
|
description: Actions related to pods
|
||||||
- name: volumes
|
- name: volumes
|
||||||
description: Actions related to volumes
|
description: Actions related to volumes
|
||||||
|
@ -3,40 +3,76 @@ package network
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/libcni"
|
|
||||||
"github.com/containers/libpod/pkg/bindings"
|
"github.com/containers/libpod/pkg/bindings"
|
||||||
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Create() {}
|
// Create makes a new CNI network configuration
|
||||||
func Inspect(ctx context.Context, nameOrID string) (map[string]interface{}, error) {
|
func Create(ctx context.Context, options entities.NetworkCreateOptions, name *string) (*entities.NetworkCreateReport, error) {
|
||||||
|
var report entities.NetworkCreateReport
|
||||||
conn, err := bindings.GetClient(ctx)
|
conn, err := bindings.GetClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
n := make(map[string]interface{})
|
params := url.Values{}
|
||||||
response, err := conn.DoRequest(nil, http.MethodGet, "/networks/%s/json", nil, nameOrID)
|
if name != nil {
|
||||||
if err != nil {
|
params.Set("name", *name)
|
||||||
return n, err
|
|
||||||
}
|
}
|
||||||
return n, response.Process(&n)
|
networkConfig, err := jsoniter.MarshalToString(options)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
stringReader := strings.NewReader(networkConfig)
|
||||||
|
response, err := conn.DoRequest(stringReader, http.MethodPost, "/networks/create", params)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &report, response.Process(&report)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Remove(ctx context.Context, nameOrID string) error {
|
// Inspect returns low level information about a CNI network configuration
|
||||||
|
func Inspect(ctx context.Context, nameOrID string) ([]entities.NetworkInspectReport, error) {
|
||||||
|
var reports []entities.NetworkInspectReport
|
||||||
conn, err := bindings.GetClient(ctx)
|
conn, err := bindings.GetClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
response, err := conn.DoRequest(nil, http.MethodDelete, "/networks/%s", nil, nameOrID)
|
response, err := conn.DoRequest(nil, http.MethodGet, "/networks/%s/json", nil, nameOrID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
return response.Process(nil)
|
return reports, response.Process(&reports)
|
||||||
}
|
}
|
||||||
|
|
||||||
func List(ctx context.Context) ([]*libcni.NetworkConfigList, error) {
|
// Remove deletes a defined CNI network configuration by name. The optional force boolean
|
||||||
|
// will remove all containers associated with the network when set to true. A slice
|
||||||
|
// of NetworkRemoveReports are returned.
|
||||||
|
func Remove(ctx context.Context, nameOrID string, force *bool) ([]*entities.NetworkRmReport, error) {
|
||||||
|
var reports []*entities.NetworkRmReport
|
||||||
|
conn, err := bindings.GetClient(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
params := url.Values{}
|
||||||
|
if force != nil {
|
||||||
|
params.Set("size", strconv.FormatBool(*force))
|
||||||
|
}
|
||||||
|
response, err := conn.DoRequest(nil, http.MethodDelete, "/networks/%s", params, nameOrID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return reports, response.Process(&reports)
|
||||||
|
}
|
||||||
|
|
||||||
|
// List returns a summary of all CNI network configurations
|
||||||
|
func List(ctx context.Context) ([]*entities.NetworkListReport, error) {
|
||||||
var (
|
var (
|
||||||
netList []*libcni.NetworkConfigList
|
netList []*entities.NetworkListReport
|
||||||
)
|
)
|
||||||
conn, err := bindings.GetClient(ctx)
|
conn, err := bindings.GetClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -36,6 +36,7 @@ type NetworkRmReport struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NetworkCreateOptions describes options to create a network
|
// NetworkCreateOptions describes options to create a network
|
||||||
|
// swagger:model NetworkCreateOptions
|
||||||
type NetworkCreateOptions struct {
|
type NetworkCreateOptions struct {
|
||||||
DisableDNS bool
|
DisableDNS bool
|
||||||
Driver string
|
Driver string
|
||||||
|
@ -2,22 +2,39 @@ package tunnel
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
|
|
||||||
|
"github.com/containers/libpod/pkg/bindings/network"
|
||||||
"github.com/containers/libpod/pkg/domain/entities"
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ic *ContainerEngine) NetworkList(ctx context.Context, options entities.NetworkListOptions) ([]*entities.NetworkListReport, error) {
|
func (ic *ContainerEngine) NetworkList(ctx context.Context, options entities.NetworkListOptions) ([]*entities.NetworkListReport, error) {
|
||||||
return nil, errors.New("not implemented")
|
return network.List(ic.ClientCxt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ic *ContainerEngine) NetworkInspect(ctx context.Context, namesOrIds []string, options entities.NetworkInspectOptions) ([]entities.NetworkInspectReport, error) {
|
func (ic *ContainerEngine) NetworkInspect(ctx context.Context, namesOrIds []string, options entities.NetworkInspectOptions) ([]entities.NetworkInspectReport, error) {
|
||||||
return nil, errors.New("not implemented")
|
var reports []entities.NetworkInspectReport
|
||||||
|
for _, name := range namesOrIds {
|
||||||
|
report, err := network.Inspect(ic.ClientCxt, name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
reports = append(reports, report...)
|
||||||
|
}
|
||||||
|
return reports, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, options entities.NetworkRmOptions) ([]*entities.NetworkRmReport, error) {
|
func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, options entities.NetworkRmOptions) ([]*entities.NetworkRmReport, error) {
|
||||||
return nil, errors.New("not implemented")
|
var reports []*entities.NetworkRmReport
|
||||||
|
for _, name := range namesOrIds {
|
||||||
|
report, err := network.Remove(ic.ClientCxt, name, &options.Force)
|
||||||
|
if err != nil {
|
||||||
|
report[0].Err = err
|
||||||
|
}
|
||||||
|
reports = append(reports, report...)
|
||||||
|
}
|
||||||
|
return reports, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ic *ContainerEngine) NetworkCreate(ctx context.Context, name string, options entities.NetworkCreateOptions) (*entities.NetworkCreateReport, error) {
|
func (ic *ContainerEngine) NetworkCreate(ctx context.Context, name string, options entities.NetworkCreateOptions) (*entities.NetworkCreateReport, error) {
|
||||||
return nil, errors.New("not implemented")
|
return network.Create(ic.ClientCxt, options, &name)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user