Prechádzať zdrojové kódy

add discover host action

abhishek9686 5 mesiacov pred
rodič
commit
8ee23e61f4
2 zmenil súbory, kde vykonal 20 pridanie a 5 odobranie
  1. 18 4
      controllers/hosts.go
  2. 2 1
      models/host.go

+ 18 - 4
controllers/hosts.go

@@ -272,10 +272,7 @@ func updateHost(w http.ResponseWriter, r *http.Request) {
 		logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
 		return
 	}
-	if !reflect.DeepEqual(currHost.EgressServices, newHost.EgressServices) {
-		// update egress range on nodes
-		logic.MapExternalServicesToHostNodes(newHost)
-	}
+
 	// publish host update through MQ
 	if err := mq.HostUpdate(&models.HostUpdate{
 		Action: models.UpdateHost,
@@ -289,6 +286,23 @@ func updateHost(w http.ResponseWriter, r *http.Request) {
 			err.Error(),
 		)
 	}
+	if !reflect.DeepEqual(newHost.EgressServices, currHost.EgressServices) {
+		// update egress range on nodes
+		logic.MapExternalServicesToHostNodes(newHost)
+		// publish host update through MQ
+		if err := mq.HostUpdate(&models.HostUpdate{
+			Action: models.DiscoverEgressIps,
+			Host:   *newHost,
+		}); err != nil {
+			logger.Log(
+				0,
+				r.Header.Get("user"),
+				"failed to send host update: ",
+				currHost.ID.String(),
+				err.Error(),
+			)
+		}
+	}
 	go func() {
 		if err := mq.PublishPeerUpdate(false); err != nil {
 			logger.Log(0, "fail to publish peer update: ", err.Error())

+ 2 - 1
models/host.go

@@ -78,7 +78,6 @@ type Host struct {
 type EgressIPNat struct {
 	EgressIP net.IP `json:"egress_ip"`
 	NATIP    net.IP `json:"egress_nat_ip"`
-	Discover bool   `json:"discover"`
 }
 
 // FormatBool converts a boolean to a [yes|no] string
@@ -129,6 +128,8 @@ const (
 	SignalPull HostMqAction = "SIGNAL_PULL"
 	// UpdateMetrics - updates metrics data
 	UpdateMetrics HostMqAction = "UPDATE_METRICS"
+	// DiscoverEgressServices - action to trigger discover egress ips
+	DiscoverEgressIps HostMqAction = "DISCOVER_EGRESS_SERVICE"
 )
 
 // SignalAction - turn peer signal action