Skip to content

Commit f318f01

Browse files
committed
Change emulator example to exploit env file
1 parent ae8a903 commit f318f01

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

Diff for: dfaasagent.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ AGENT_HAPROXY_CONFIG_FILE="/etc/haproxy/haproxy.cfg"
2222
AGENT_HAPROXY_CONFIG_UPDATE_COMMAND="/usr/bin/systemctl restart haproxy.service"
2323
AGENT_HAPROXY_HOST=127.0.0.1
2424
AGENT_HAPROXY_PORT=80
25-
AGENT_HA_SOCK_PATH="unix:///run/haproxy/admin.sock"
25+
AGENT_HAPROXY_SOCK_PATH="unix:///run/haproxy/admin.sock"
2626

2727
AGENT_OPENFAAS_HOST=127.0.0.1
2828
AGENT_OPENFAAS_PORT=8080

Diff for: dfaasagent/agent/config/config.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type Configuration struct {
3535
HAProxyConfigUpdateCommand string `mapstructure:"AGENT_HAPROXY_CONFIG_UPDATE_COMMAND"`
3636
HAProxyHost string `mapstructure:"AGENT_HAPROXY_HOST"`
3737
HAProxyPort uint `mapstructure:"AGENT_HAPROXY_PORT"`
38-
HAProxySockPath string `mapstructure:"AGENT_HA_SOCK_PATH"`
38+
HAProxySockPath string `mapstructure:"AGENT_HAPROXY_SOCK_PATH"`
3939

4040
OpenFaaSHost string `mapstructure:"AGENT_OPENFAAS_HOST"`
4141
OpenFaaSPort uint `mapstructure:"AGENT_OPENFAAS_PORT"`
@@ -60,8 +60,6 @@ func LoadConfig(path string) (config Configuration, err error) {
6060
return
6161
}
6262

63-
viper.Debug()
64-
6563
err = viper.Unmarshal(&config)
6664
return
6765
}

Diff for: emulator/example.py

+19-5
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,32 @@
44
from mininet.net import Containernet
55
from mininet.node import Controller
66
from mininet.cli import CLI
7-
from mininet.link import TCLink
87
from mininet.log import info, setLogLevel
8+
from dotenv import dotenv_values
9+
import copy
10+
11+
12+
def prepare_env(env, ip):
13+
_env = copy.deepcopy(env)
14+
_env['AGENT_LISTEN'] = '/ip4/{}/tcp/6000'.format(ip)
15+
_env['AGENT_HAPROXY_HOST'] = ip
16+
return _env
17+
18+
19+
agent_env = dotenv_values('../dfaasagent.env')
920

1021
setLogLevel('info')
1122

1223
net = Containernet(controller=Controller)
1324
net.addController('c0')
1425

1526
info('*** Adding container\n')
16-
n1 = net.addDocker('n1', ip='10.0.0.1', dcmd='/sbin/init --log-level=err', dimage="dfaas-node:latest", runtime='sysbox-runc', environment={"AGENT_IPV4": "10.0.0.1"})
17-
n2 = net.addDocker('n2', ip='10.0.0.2', dcmd='/sbin/init --log-level=err', dimage="dfaas-node:latest", runtime='sysbox-runc', environment={"AGENT_IPV4": "10.0.0.2"})
18-
n3 = net.addDocker('n3', ip='10.0.0.3', dcmd='/sbin/init --log-level=err', dimage="dfaas-node:latest", runtime='sysbox-runc', environment={"AGENT_IPV4": "10.0.0.3"})
27+
n1 = net.addDocker('n1', ip='10.0.0.1', dcmd='./entrypoint.sh', dimage="dfaas-node:latest", runtime='sysbox-runc',
28+
environment=prepare_env(agent_env, '10.0.0.1'))
29+
n2 = net.addDocker('n2', ip='10.0.0.2', dcmd='./entrypoint.sh', dimage="dfaas-node:latest", runtime='sysbox-runc',
30+
environment=prepare_env(agent_env, '10.0.0.2'))
31+
n3 = net.addDocker('n3', ip='10.0.0.3', dcmd='./entrypoint.sh', dimage="dfaas-node:latest", runtime='sysbox-runc',
32+
environment=prepare_env(agent_env, '10.0.0.3'))
1933

2034
info('*** Setup network\n')
2135
s1 = net.addSwitch('s1')
@@ -28,4 +42,4 @@
2842

2943
CLI(net)
3044

31-
net.stop()
45+
net.stop()

Diff for: emulator/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dotenv==0.20.*

0 commit comments

Comments
 (0)