/
typeNextNetworkAutoConfiguration.go
48 lines (43 loc) · 1.13 KB
/
typeNextNetworkAutoConfiguration.go
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
38
39
40
41
42
43
44
45
46
47
48
package iotmakerdocker
import (
"github.com/docker/docker/api/types/network"
)
type NextNetworkAutoConfiguration struct {
ip IPv4Generator
id string
name string
gateway string
subnet string
err error
}
// init a network for new container
// nInit("test", 10, 0, 0, 1)
// before use this function, use whaleAquarium.Docker.NetworkCreate("test")
func (el *NextNetworkAutoConfiguration) Init(id, name, gateway, subnet string) {
el.id = id
el.name = name
el.gateway = gateway
el.subnet = subnet
el.err = el.ip.InitWithString(gateway, subnet)
}
func (el *NextNetworkAutoConfiguration) GetNext() (IP string, networkConfig *network.NetworkingConfig, err error) {
IP = el.ip.String()
el.err = el.ip.IncCurrentIP()
return IP,
&network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
el.name: {
NetworkID: el.id,
Gateway: el.gateway,
IPAMConfig: &network.EndpointIPAMConfig{
IPv4Address: IP,
},
IPAddress: IP,
},
},
},
el.err
}
func (el *NextNetworkAutoConfiguration) GetCurrentIpAddress() (IP string, err error) {
return el.ip.String(), el.err
}