updated to include fabric IP allocation for compute node configuration
diff --git a/ip-allocator/allocator.go b/ip-allocator/allocator.go
index ff474b6..e5a64cb 100644
--- a/ip-allocator/allocator.go
+++ b/ip-allocator/allocator.go
@@ -9,10 +9,10 @@
)
type Config struct {
- Port int `default:"4242"`
- Listen string `default:"0.0.0.0"`
- StartAddress string `default:"10.0.0.2" envconfig:"start_address"`
- AddressCount uint `default:"252" envconfig:"address_count"`
+ Port int `default:"4242"`
+ Listen string `default:"0.0.0.0"`
+ Network string `default:"10.0.0.0/24"`
+ Skip int `default:"1"`
}
type Context struct {
@@ -31,11 +31,11 @@
log.Printf(`Configuration:
Listen: %s
Port: %d
- StartAddress: %s
- AddressCount: %d`, config.Listen, config.Port, config.StartAddress, config.AddressCount)
+ Network: %s
+ SKip: %d`, config.Listen, config.Port, config.Network, config.Skip)
context.storage = &MemoryStorage{}
- context.storage.Init(config.StartAddress, config.AddressCount)
+ context.storage.Init(config.Network, config.Skip)
router := mux.NewRouter()
router.HandleFunc("/allocations/{mac}", context.ReleaseAllocationHandler).Methods("DELETE")
diff --git a/ip-allocator/storage.go b/ip-allocator/storage.go
index 26be353..ac5ce6d 100644
--- a/ip-allocator/storage.go
+++ b/ip-allocator/storage.go
@@ -1,7 +1,14 @@
package main
+import (
+ "math"
+ "net"
+ "strconv"
+ "strings"
+)
+
type Storage interface {
- Init(start string, count uint) error
+ Init(networkIn string, skip int) error
Get(mac string) (string, error)
GetAll() map[string]string
Put(mac, ip string) error
@@ -16,17 +23,38 @@
readIdx, writeIdx, size uint
}
-func (s *MemoryStorage) Init(start string, count uint) error {
- ip, err := ParseIP(start)
+func (s *MemoryStorage) Init(networkIn string, skip int) error {
+ _, network, err := net.ParseCIDR(networkIn)
if err != nil {
return err
}
+ start, _, err := net.ParseCIDR(network.String())
+ if err != nil {
+ return err
+ }
+
+ parts := strings.Split(network.String(), "/")
+ ip, err := ParseIP(start.String())
+ if err != nil {
+ return err
+ }
+ bits, err := strconv.Atoi(parts[1])
+ if err != nil {
+ return err
+ }
+ hostCount := int(math.Pow(2, float64(32-bits))) - skip
s.readIdx = 0
s.writeIdx = 0
- s.size = count
+ s.size = uint(hostCount)
s.allocated = make(map[string]IPv4)
- s.available = make([]IPv4, count)
- for i := uint(0); i < count; i += 1 {
+ s.available = make([]IPv4, hostCount)
+ for i := 0; i < skip; i += 1 {
+ ip, err = ip.Next()
+ if err != nil {
+ return err
+ }
+ }
+ for i := 0; i < hostCount; i += 1 {
s.available[i] = ip
ip, err = ip.Next()
if err != nil {
diff --git a/roles/maas/tasks/main.yml b/roles/maas/tasks/main.yml
index fc2d40b..5e7e349 100644
--- a/roles/maas/tasks/main.yml
+++ b/roles/maas/tasks/main.yml
@@ -282,6 +282,16 @@
group: root
mode: 0400
+- name: Initialize Interface Configuration Fact
+ set_fact:
+ interface_config: 0
+
+- name: Set Interface Configuration Fact
+ set_fact:
+ interface_config: 1
+ tags:
+ - interface_config
+
- name: Custom Automation Compose Configurations
become: yes
template:
diff --git a/roles/maas/templates/automation-compose.yml.j2 b/roles/maas/templates/automation-compose.yml.j2
index 7beb0c3..7a45e03 100644
--- a/roles/maas/templates/automation-compose.yml.j2
+++ b/roles/maas/templates/automation-compose.yml.j2
@@ -1,12 +1,28 @@
+allocator:
+ image: opencord/cord-ip-allocator:latest
+ labels:
+ - "lab.solution=CORD"
+ - "lab.component=allocator"
+ environment:
+ # need to explicitly set the resolver, else go will skip the /etc/hosts file
+ - "GODEBUG=netdns=go"
+ - "ALLOCATE_PORT=4242"
+ - "ALLOCATE_LISTEN=0.0.0.0"
+ - "ALLOCATE_NETWORK={{ networks.fabric }}"
+ - "ALLOCATE_SKIP=2"
+
provisioner:
image: opencord/cord-provisioner:latest
container_name: provisioner
labels:
- "lab.solution=CORD"
- "lab.component=provisioner"
+ links:
+ - allocator
environment:
# need to explicitly set the resolver, else go will skip the /etc/hosts file
- "GODEBUG=netdns=go"
+ - "INTERFACE_CONFIG={{ interface_config }}"
- "PROVISION_PORT=4243"
- "PROVISION_LISTEN=0.0.0.0"
- "PROVISION_DEFAULT_ROLE=compute-node"