summaryrefslogtreecommitdiff
path: root/pkg/bindings/network.go
blob: 383615e5d3fa46da36523dc8b3862e65a4b81bec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package bindings

import (
	"fmt"
	"net/http"

	"github.com/containernetworking/cni/libcni"
)

func (c Connection) CreateNetwork() {}
func (c Connection) InspectNetwork(nameOrID string) (map[string]interface{}, error) {
	n := make(map[string]interface{})
	response, err := c.newRequest(http.MethodGet, fmt.Sprintf("/networks/%s/json", nameOrID), nil, nil)
	if err != nil {
		return n, err
	}
	return n, response.Process(&n)
}

func (c Connection) RemoveNetwork(nameOrID string) error {
	response, err := c.newRequest(http.MethodDelete, fmt.Sprintf("/networks/%s", nameOrID), nil, nil)
	if err != nil {
		return err
	}
	return response.Process(nil)
}

func (c Connection) ListNetworks() ([]*libcni.NetworkConfigList, error) {
	var (
		netList []*libcni.NetworkConfigList
	)
	response, err := c.newRequest(http.MethodGet, "/networks/json", nil, nil)
	if err != nil {
		return netList, err
	}
	return netList, response.Process(&netList)
}