本文整理汇总了Golang中github.com/coreos/flannel/subnet.Manager类的典型用法代码示例。如果您正苦于以下问题:Golang Manager类的具体用法?Golang Manager怎么用?Golang Manager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Manager类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleWatchLeases
// GET /{network}/leases?next=cursor
func handleWatchLeases(ctx context.Context, sm subnet.Manager, w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
network := mux.Vars(r)["network"]
if network == "_" {
network = ""
}
cursor := getCursor(r.URL)
wr, err := sm.WatchLeases(ctx, network, cursor)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, err)
return
}
switch wr.Cursor.(type) {
case string:
case fmt.Stringer:
wr.Cursor = wr.Cursor.(fmt.Stringer).String()
default:
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, fmt.Errorf("internal error: watch cursor is of unknown type"))
return
}
jsonResponse(w, http.StatusOK, wr)
}
示例2: handleGetNetworkConfig
// GET /{network}/config
func handleGetNetworkConfig(ctx context.Context, sm subnet.Manager, w http.ResponseWriter, r *http.Request) {
network := mux.Vars(r)["network"]
if network == "_" {
network = ""
}
c, err := sm.GetNetworkConfig(ctx, network)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, err)
return
}
jsonResponse(w, http.StatusOK, c)
}
示例3: doTestWatch
func doTestWatch(t *testing.T, sm subnet.Manager) {
ctx, cancel := context.WithCancel(context.Background())
wg := sync.WaitGroup{}
wg.Add(1)
defer func() {
cancel()
wg.Wait()
}()
events := make(chan []subnet.Event)
go func() {
subnet.WatchLeases(ctx, sm, "_", nil, events)
wg.Done()
}()
// skip over the initial snapshot
<-events
attrs := &subnet.LeaseAttrs{
PublicIP: mustParseIP4("1.1.1.2"),
}
l, err := sm.AcquireLease(ctx, "_", attrs)
if err != nil {
t.Errorf("AcquireLease failed: %v", err)
return
}
if !mustParseIP4Net(expectedNetwork).Contains(l.Subnet.IP) {
t.Errorf("AcquireLease returned subnet not in network: %v (in %v)", l.Subnet, expectedNetwork)
}
evtBatch := <-events
if len(evtBatch) != 1 {
t.Fatalf("WatchSubnets produced wrong sized event batch")
}
evt := evtBatch[0]
if evt.Type != subnet.SubnetAdded {
t.Fatalf("WatchSubnets produced wrong event type")
}
if evt.Lease.Key() != l.Key() {
t.Errorf("WatchSubnet produced wrong subnet: expected %s, got %s", l.Key(), evt.Lease.Key())
}
}
示例4: handleAddReservation
// POST /{network}/reservations
func handleAddReservation(ctx context.Context, sm subnet.Manager, w http.ResponseWriter, r *http.Request) {
network := mux.Vars(r)["network"]
if network == "_" {
network = ""
}
rsv := &subnet.Reservation{}
if err := json.NewDecoder(r.Body).Decode(rsv); err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprint(w, "JSON decoding error: ", err)
return
}
if err := sm.AddReservation(ctx, network, rsv); err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, fmt.Errorf("internal error: %v", err))
return
}
}
示例5: handleRevokeLease
func handleRevokeLease(ctx context.Context, sm subnet.Manager, w http.ResponseWriter, r *http.Request) {
network := mux.Vars(r)["network"]
if network == "_" {
network = ""
}
sn := subnet.ParseSubnetKey(mux.Vars(r)["subnet"])
if sn == nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprint(w, "failed to parse subnet")
return
}
if err := sm.RevokeLease(ctx, network, *sn); err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, err)
return
}
}
示例6: handleRenewLease
// PUT /{network}/{lease.network}
func handleRenewLease(ctx context.Context, sm subnet.Manager, w http.ResponseWriter, r *http.Request) {
network := mux.Vars(r)["network"]
if network == "_" {
network = ""
}
lease := subnet.Lease{}
if err := json.NewDecoder(r.Body).Decode(&lease); err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprint(w, "JSON decoding error: ", err)
return
}
if err := sm.RenewLease(ctx, network, &lease); err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, err)
return
}
jsonResponse(w, http.StatusOK, lease)
}
示例7: handleNetworks
// GET /?next=cursor watches
// GET / retrieves all networks
func handleNetworks(ctx context.Context, sm subnet.Manager, w http.ResponseWriter, r *http.Request) {
cursor := getCursor(r.URL)
wr, err := sm.WatchNetworks(ctx, cursor)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, err)
return
}
switch wr.Cursor.(type) {
case string:
case fmt.Stringer:
wr.Cursor = wr.Cursor.(fmt.Stringer).String()
default:
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, fmt.Errorf("internal error: watch cursor is of unknown type"))
return
}
jsonResponse(w, http.StatusOK, wr)
}
示例8: handleAcquireLease
// POST /{network}/leases
func handleAcquireLease(ctx context.Context, sm subnet.Manager, w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
network := mux.Vars(r)["network"]
if network == "_" {
network = ""
}
attrs := subnet.LeaseAttrs{}
if err := json.NewDecoder(r.Body).Decode(&attrs); err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprint(w, "JSON decoding error: ", err)
return
}
lease, err := sm.AcquireLease(ctx, network, &attrs)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, err)
return
}
jsonResponse(w, http.StatusOK, lease)
}