Merge pull request #29 from byjg/reload_static
Reload Static configuration when it changed
This commit is contained in:
commit
9f482a4a55
4 changed files with 75 additions and 15 deletions
|
|
@ -90,7 +90,7 @@ class HaproxyConfigGenerator:
|
|||
self.label.set_data(d)
|
||||
|
||||
# Parse each definition found.
|
||||
for definition in definitions.keys():
|
||||
for definition in sorted(definitions.keys()):
|
||||
mode = self.label.get(
|
||||
self.label.create([definition, "mode"]),
|
||||
"http"
|
||||
|
|
@ -134,7 +134,7 @@ class HaproxyConfigGenerator:
|
|||
""
|
||||
)
|
||||
|
||||
for hostname in d[host_label].split(","):
|
||||
for hostname in sorted(d[host_label].split(",")):
|
||||
hostname = hostname.strip()
|
||||
self.serving_hosts.append("%s:%s" % (hostname, port))
|
||||
easymapping[port]["hosts"].setdefault(hostname, {})
|
||||
|
|
|
|||
|
|
@ -101,10 +101,21 @@ class ProcessorInterface:
|
|||
class Static(ProcessorInterface):
|
||||
def inspect_network(self):
|
||||
self.parsed_object = {}
|
||||
self.static_content = None
|
||||
|
||||
def get_parsed_object(self):
|
||||
return self.static_content["easymapping"] if "easymapping" in self.static_content else []
|
||||
|
||||
def get_hosts(self):
|
||||
hosts = []
|
||||
for object in self.get_parsed_object():
|
||||
for host in object["hosts"].keys():
|
||||
hosts.append("%s:%s" % (host, object["port"]))
|
||||
return hosts
|
||||
|
||||
def parse(self):
|
||||
static_content = yaml.load(Functions.load(self.filename), Loader=yaml.FullLoader)
|
||||
self.cfg = HaproxyConfigGenerator(static_content)
|
||||
self.static_content = yaml.load(Functions.load(self.filename), Loader=yaml.FullLoader)
|
||||
self.cfg = HaproxyConfigGenerator(self.static_content)
|
||||
|
||||
|
||||
class Docker(ProcessorInterface):
|
||||
|
|
|
|||
|
|
@ -48,15 +48,15 @@ frontend http_in_19901
|
|||
mode http
|
||||
redirect prefix www.google.com code 301 if { hdr(host) -i google.helloworld.com }
|
||||
|
||||
acl is_rule_hello_com_19901_1 hdr(host) -i hello.com
|
||||
acl is_rule_hello_com_19901_2 hdr(host) -i hello.com:19901
|
||||
use_backend srv_hello_com_19901 if is_rule_hello_com_19901_1 OR is_rule_hello_com_19901_2
|
||||
|
||||
acl is_rule_www_helloworld_com_19901_1 hdr(host) -i www.helloworld.com
|
||||
acl is_rule_www_helloworld_com_19901_2 hdr(host) -i www.helloworld.com:19901
|
||||
use_backend srv_www_helloworld_com_19901 if is_rule_www_helloworld_com_19901_1 OR is_rule_www_helloworld_com_19901_2
|
||||
|
||||
backend srv_hello_com_19901
|
||||
acl is_rule_hello_com_19901_1 hdr(host) -i hello.com
|
||||
acl is_rule_hello_com_19901_2 hdr(host) -i hello.com:19901
|
||||
use_backend srv_hello_com_19901 if is_rule_hello_com_19901_1 OR is_rule_hello_com_19901_2
|
||||
|
||||
backend srv_www_helloworld_com_19901
|
||||
balance roundrobin
|
||||
mode http
|
||||
option forwardfor
|
||||
|
|
@ -64,7 +64,7 @@ backend srv_hello_com_19901
|
|||
http-request add-header X-Forwarded-Proto https if { ssl_fc }
|
||||
server srv-0 3e63154954b0:80 check weight 1
|
||||
server srv-1 eb294c110eb1:80 check weight 1
|
||||
backend srv_www_helloworld_com_19901
|
||||
backend srv_hello_com_19901
|
||||
balance roundrobin
|
||||
mode http
|
||||
option forwardfor
|
||||
|
|
|
|||
|
|
@ -8,9 +8,58 @@ def test_processor_static():
|
|||
ProcessorInterface.static_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "./fixtures/static.yml")
|
||||
static = ProcessorInterface.factory("static")
|
||||
|
||||
parsed_object = [
|
||||
{
|
||||
"hosts":{
|
||||
"host1.com.br":{
|
||||
"containers":[
|
||||
"container:5000"
|
||||
],
|
||||
"letsencrypt": True
|
||||
},
|
||||
"host2.com.br":{
|
||||
"containers":[
|
||||
"other:3000"
|
||||
]
|
||||
}
|
||||
},
|
||||
"port":80,
|
||||
"redirect":{
|
||||
"www.host1.com.br":"http://host1.com.br"
|
||||
}
|
||||
},
|
||||
{
|
||||
"hosts":{
|
||||
"host1.com.br":{
|
||||
"containers":[
|
||||
"container:80"
|
||||
]
|
||||
}
|
||||
},
|
||||
"port":443,
|
||||
"ssl": True
|
||||
},
|
||||
{
|
||||
"hosts":{
|
||||
"host3.com.br":{
|
||||
"containers":[
|
||||
"domain:8181"
|
||||
]
|
||||
}
|
||||
},
|
||||
"port":8080
|
||||
}
|
||||
]
|
||||
hosts = [
|
||||
'host1.com.br:80',
|
||||
'host2.com.br:80',
|
||||
'host1.com.br:443',
|
||||
'host3.com.br:8080'
|
||||
]
|
||||
|
||||
assert static.get_letsencrypt_hosts() is None
|
||||
assert static.get_parsed_object() == {}
|
||||
assert static.get_hosts() is None
|
||||
assert static.get_parsed_object() == parsed_object
|
||||
assert static.get_hosts() == hosts
|
||||
|
||||
haproxy_cfg = static.get_haproxy_conf()
|
||||
|
||||
|
|
@ -18,7 +67,7 @@ def test_processor_static():
|
|||
|
||||
# @todo: Static doesnt populate this fields
|
||||
assert static.get_letsencrypt_hosts() == []
|
||||
assert static.get_parsed_object() == {}
|
||||
assert static.get_hosts() == []
|
||||
assert static.get_parsed_object() == parsed_object
|
||||
assert static.get_hosts() == hosts
|
||||
|
||||
# test_processor_static()
|
||||
Loading…
Add table
Add a link
Reference in a new issue