mirror of
https://github.com/containers/podman.git
synced 2025-06-20 00:51:16 +08:00
fixed docs and schemas
Signed-off-by: cdoern <cbdoer23@g.holycross.edu>
This commit is contained in:
@ -28,19 +28,24 @@ import (
|
|||||||
func InspectNetwork(w http.ResponseWriter, r *http.Request) {
|
func InspectNetwork(w http.ResponseWriter, r *http.Request) {
|
||||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||||
|
|
||||||
// FYI scope and version are currently unused but are described by the API
|
// scope is only used to see if the user passes any illegal value, verbose is not used but implemented
|
||||||
// Leaving this for if/when we have to enable these
|
// for compatibility purposes only.
|
||||||
// query := struct {
|
query := struct {
|
||||||
// scope string
|
scope string `schema:"scope"`
|
||||||
// verbose bool
|
verbose bool `schema:"verbose"`
|
||||||
// }{
|
}{
|
||||||
// // override any golang type defaults
|
scope: "local",
|
||||||
// }
|
}
|
||||||
// decoder := r.Context().Value("decoder").(*schema.Decoder)
|
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||||
// if err := decoder.Decode(&query, r.URL.Query()); err != nil {
|
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
|
||||||
// utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
|
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
if query.scope != "local" {
|
||||||
|
utils.Error(w, "Invalid scope value. Can only be local.", http.StatusBadRequest, define.ErrInvalidArg)
|
||||||
|
return
|
||||||
|
}
|
||||||
config, err := runtime.GetConfig()
|
config, err := runtime.GetConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.InternalServerError(w, err)
|
utils.InternalServerError(w, err)
|
||||||
|
@ -44,6 +44,16 @@ func (s *APIServer) registerNetworkHandlers(r *mux.Router) error {
|
|||||||
// type: string
|
// type: string
|
||||||
// required: true
|
// required: true
|
||||||
// description: the name of the network
|
// description: the name of the network
|
||||||
|
// - in: query
|
||||||
|
// name: verbose
|
||||||
|
// type: boolean
|
||||||
|
// required: false
|
||||||
|
// description: Detailed inspect output for troubleshooting
|
||||||
|
// - in: query
|
||||||
|
// name: scope
|
||||||
|
// type: string
|
||||||
|
// required: false
|
||||||
|
// description: Filter the network by scope (swarm, global, or local)
|
||||||
// produces:
|
// produces:
|
||||||
// - application/json
|
// - application/json
|
||||||
// responses:
|
// responses:
|
||||||
|
@ -102,6 +102,33 @@ class NetworkTestCase(APITestCase):
|
|||||||
"TestNetwork",
|
"TestNetwork",
|
||||||
payload["NetworkSettings"]["Networks"]["TestNetwork"]["NetworkID"],
|
payload["NetworkSettings"]["Networks"]["TestNetwork"]["NetworkID"],
|
||||||
)
|
)
|
||||||
|
def test_inspect(self):
|
||||||
|
name = f"Network_{random.getrandbits(160):x}"
|
||||||
|
create = requests.post(self.podman_url + "/v1.40/networks/create", json={"Name": name})
|
||||||
|
self.assertEqual(create.status_code, 201, create.text)
|
||||||
|
self.assertId(create.content)
|
||||||
|
|
||||||
|
net = create.json()
|
||||||
|
self.assertIsInstance(net, dict)
|
||||||
|
self.assertNotEqual(net["Id"], name)
|
||||||
|
ident = net["Id"]
|
||||||
|
|
||||||
|
ls = requests.get(self.podman_url + "/v1.40/networks")
|
||||||
|
self.assertEqual(ls.status_code, 200, ls.text)
|
||||||
|
|
||||||
|
networks = ls.json()
|
||||||
|
self.assertIsInstance(networks, list)
|
||||||
|
|
||||||
|
found = False
|
||||||
|
for net in networks:
|
||||||
|
if net["Name"] == name:
|
||||||
|
found = True
|
||||||
|
break
|
||||||
|
self.assertTrue(found, f"Network '{name}' not found")
|
||||||
|
|
||||||
|
inspect = requests.get(self.podman_url + f"/v1.40/networks/{ident}?verbose=false&scope=local")
|
||||||
|
self.assertEqual(inspect.status_code, 200, inspect.text)
|
||||||
|
|
||||||
|
|
||||||
def test_crud(self):
|
def test_crud(self):
|
||||||
name = f"Network_{random.getrandbits(160):x}"
|
name = f"Network_{random.getrandbits(160):x}"
|
||||||
|
Reference in New Issue
Block a user