azure-container-networking/ipam/null.go

66 строки
1.1 KiB
Go
Исходник Обычный вид История

// Copyright 2017 Microsoft. All rights reserved.
// MIT License
2016-05-11 03:47:51 +03:00
package ipam
import (
"net"
)
// Null IPAM configuration source.
type nullSource struct {
name string
2016-09-16 06:27:36 +03:00
sink addressConfigSink
2016-05-11 03:47:51 +03:00
initialized bool
}
// Creates the null source.
2016-09-16 06:27:36 +03:00
func newNullSource() (*nullSource, error) {
2016-05-11 03:47:51 +03:00
return &nullSource{
name: "Null",
}, nil
}
// Starts the null source.
2016-09-16 06:27:36 +03:00
func (s *nullSource) start(sink addressConfigSink) error {
s.sink = sink
2016-05-11 03:47:51 +03:00
return nil
}
// Stops the null source.
func (s *nullSource) stop() {
2016-09-16 06:27:36 +03:00
s.sink = nil
2016-05-11 03:47:51 +03:00
return
}
// Refreshes configuration.
func (s *nullSource) refresh() error {
// Initialize once.
if s.initialized == true {
return nil
}
s.initialized = true
2016-05-11 03:47:51 +03:00
// Configure the local default address space.
local, err := s.sink.newAddressSpace(LocalDefaultAddressSpaceId, LocalScope)
2016-05-11 03:47:51 +03:00
if err != nil {
return err
}
subnet := net.IPNet{
IP: net.IPv4(0, 0, 0, 0),
Mask: net.IPv4Mask(0, 0, 0, 0),
}
_, err = local.newAddressPool("", 0, &subnet)
2016-05-11 03:47:51 +03:00
if err != nil {
return err
}
// Set the local address space as active.
s.sink.setAddressSpace(local)
return nil
}