2017-02-12 13:03:39 +03:00
|
|
|
// 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 {
|
|
|
|
|
2016-05-13 02:40:58 +03:00
|
|
|
// 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.
|
2017-01-25 03:20:34 +03:00
|
|
|
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),
|
|
|
|
}
|
|
|
|
|
2016-06-09 14:03:43 +03:00
|
|
|
_, 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
|
|
|
|
}
|