mirror of
https://github.com/gravitl/netmaker.git
synced 2025-02-25 00:24:37 +08:00
Merge pull request #160 from gravitl/feature_v0.5_uiint
feature_v0.5_uiint
This commit is contained in:
commit
0ffb590b99
2 changed files with 43 additions and 21 deletions
|
@ -565,17 +565,28 @@ func CreateEgressGateway(gateway models.EgressGatewayRequest) (models.Node, erro
|
|||
var nodechange models.Node
|
||||
nodechange.IsEgressGateway = true
|
||||
nodechange.EgressGatewayRange = gateway.RangeString
|
||||
if gateway.PostUp == "" {
|
||||
nodechange.PostUp = "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + gateway.Interface + " -j MASQUERADE"
|
||||
} else {
|
||||
nodechange.PostUp = "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + gateway.Interface + " -j MASQUERADE"
|
||||
nodechange.PostDown = "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + gateway.Interface + " -j MASQUERADE"
|
||||
if gateway.PostUp != "" {
|
||||
nodechange.PostUp = gateway.PostUp
|
||||
}
|
||||
if gateway.PostDown == "" {
|
||||
nodechange.PostDown = "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + gateway.Interface + " -j MASQUERADE"
|
||||
} else {
|
||||
if gateway.PostDown != "" {
|
||||
nodechange.PostDown = gateway.PostDown
|
||||
}
|
||||
|
||||
if node.PostUp != "" {
|
||||
if !strings.Contains(node.PostUp, nodechange.PostUp) {
|
||||
nodechange.PostUp = node.PostUp + "; " + nodechange.PostUp
|
||||
} else {
|
||||
nodechange.PostUp = node.PostUp
|
||||
}
|
||||
}
|
||||
if node.PostDown != "" {
|
||||
if !strings.Contains(node.PostDown, nodechange.PostDown) {
|
||||
nodechange.PostDown = node.PostDown + "; " + nodechange.PostDown
|
||||
} else {
|
||||
nodechange.PostDown = node.PostDown
|
||||
}
|
||||
}
|
||||
collection := mongoconn.Client.Database("netmaker").Collection("nodes")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
// Create filter
|
||||
|
@ -705,16 +716,26 @@ func CreateIngressGateway(netid string, macaddress string) (models.Node, error)
|
|||
log.Println("Could not find network.")
|
||||
return models.Node{}, err
|
||||
}
|
||||
var nodechange models.Node
|
||||
nodechange.IngressGatewayRange = network.AddressRange
|
||||
nodechange.PostUp = "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + node.Interface + " -j MASQUERADE"
|
||||
nodechange.PostDown = "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + node.Interface + " -j MASQUERADE"
|
||||
if node.PostUp != "" {
|
||||
if !strings.Contains(node.PostUp, nodechange.PostUp) {
|
||||
nodechange.PostUp = node.PostUp + "; " + nodechange.PostUp
|
||||
} else {
|
||||
nodechange.PostUp = node.PostUp
|
||||
}
|
||||
}
|
||||
if node.PostDown != "" {
|
||||
if !strings.Contains(node.PostDown, nodechange.PostDown) {
|
||||
nodechange.PostDown = node.PostDown + "; " + nodechange.PostDown
|
||||
} else {
|
||||
nodechange.PostDown = node.PostDown
|
||||
}
|
||||
}
|
||||
|
||||
if node.IsEgressGateway {
|
||||
errors.New("Node cannot be both Ingress and Egress Gateway in same network.")
|
||||
return models.Node{}, err
|
||||
}
|
||||
|
||||
node.IngressGatewayRange = network.AddressRange
|
||||
node.PostUp = "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + node.Interface + " -j MASQUERADE"
|
||||
node.PostDown = "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + node.Interface + " -j MASQUERADE"
|
||||
collection := mongoconn.Client.Database("netmaker").Collection("nodes")
|
||||
collection := mongoconn.Client.Database("netmaker").Collection("nodes")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
// Create filter
|
||||
filter := bson.M{"macaddress": macaddress, "network": netid}
|
||||
|
@ -722,10 +743,10 @@ func CreateIngressGateway(netid string, macaddress string) (models.Node, error)
|
|||
// prepare update model.
|
||||
update := bson.D{
|
||||
{"$set", bson.D{
|
||||
{"postup", node.PostUp},
|
||||
{"postdown", node.PostDown},
|
||||
{"postup", nodechange.PostUp},
|
||||
{"postdown", nodechange.PostDown},
|
||||
{"isingressgateway", true},
|
||||
{"ingressgatewayrange", node.IngressGatewayRange},
|
||||
{"ingressgatewayrange", nodechange.IngressGatewayRange},
|
||||
{"lastmodified", node.LastModified},
|
||||
}},
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@ set -e
|
|||
|
||||
[ -z "$KEY" ] && KEY=nokey;
|
||||
|
||||
wget -O netclient https://github.com/gravitl/netmaker/releases/download/latest/netclient
|
||||
wget -O netclient https://github.com/gravitl/netmaker/releases/download/v0.5/netclient
|
||||
chmod +x netclient
|
||||
sudo ./netclient -c install -t $KEY
|
||||
sudo ./netclient register -t $KEY
|
||||
sudo ./netclient join -t $KEY
|
||||
rm -f netclient
|
||||
|
|
Loading…
Reference in a new issue