|
@@ -82,23 +82,26 @@ func (n *network) handleSubnetEvents(batch []subnet.Event) {
|
|
|
}
|
|
|
|
|
|
if len(n.subnetAddCommand) > 0 {
|
|
|
- var dat interface{}
|
|
|
- if err := json.Unmarshal(evt.Lease.Attrs.BackendData, &dat); err != nil {
|
|
|
- log.Errorf("failed to unmarshal BackendData: %v", err)
|
|
|
- } else {
|
|
|
- backendData := dat.(string)
|
|
|
- cmd_output, err := runCmd([]string{
|
|
|
- fmt.Sprintf("SUBNET=%s", evt.Lease.Subnet),
|
|
|
- fmt.Sprintf("PUBLIC_IP=%s", evt.Lease.Attrs.PublicIP)},
|
|
|
- backendData,
|
|
|
- "sh", "-c", n.subnetAddCommand)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- log.Errorf("failed to run command: %s Err: %v Output: %s", n.subnetAddCommand, err, cmd_output)
|
|
|
- } else {
|
|
|
- log.Infof("Ran command: %s\n Output: %s", n.subnetAddCommand, cmd_output)
|
|
|
+ backendData := ""
|
|
|
+
|
|
|
+ if len(evt.Lease.Attrs.BackendData) > 0 {
|
|
|
+ if err := json.Unmarshal(evt.Lease.Attrs.BackendData, &backendData); err != nil {
|
|
|
+ log.Errorf("failed to unmarshal BackendData: %v", err)
|
|
|
+ continue
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ cmd_output, err := runCmd([]string{
|
|
|
+ fmt.Sprintf("SUBNET=%s", evt.Lease.Subnet),
|
|
|
+ fmt.Sprintf("PUBLIC_IP=%s", evt.Lease.Attrs.PublicIP)},
|
|
|
+ backendData,
|
|
|
+ "sh", "-c", n.subnetAddCommand)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ log.Errorf("failed to run command: %s Err: %v Output: %s", n.subnetAddCommand, err, cmd_output)
|
|
|
+ } else {
|
|
|
+ log.Infof("Ran command: %s\n Output: %s", n.subnetAddCommand, cmd_output)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
case subnet.EventRemoved:
|
|
@@ -110,23 +113,25 @@ func (n *network) handleSubnetEvents(batch []subnet.Event) {
|
|
|
}
|
|
|
|
|
|
if len(n.subnetRemoveCommand) > 0 {
|
|
|
- var dat interface{}
|
|
|
- if err := json.Unmarshal(evt.Lease.Attrs.BackendData, &dat); err != nil {
|
|
|
- log.Errorf("failed to unmarshal BackendData: %v", err)
|
|
|
- } else {
|
|
|
- backendData := dat.(string)
|
|
|
- cmd_output, err := runCmd([]string{
|
|
|
- fmt.Sprintf("SUBNET=%s", evt.Lease.Subnet),
|
|
|
- fmt.Sprintf("PUBLIC_IP=%s", evt.Lease.Attrs.PublicIP)},
|
|
|
- backendData,
|
|
|
- "sh", "-c", n.subnetRemoveCommand)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- log.Errorf("failed to run command: %s Err: %v Output: %s", n.subnetRemoveCommand, err, cmd_output)
|
|
|
- } else {
|
|
|
- log.Infof("Ran command: %s\n Output: %s", n.subnetRemoveCommand, cmd_output)
|
|
|
+ backendData := ""
|
|
|
+
|
|
|
+ if len(evt.Lease.Attrs.BackendData) > 0 {
|
|
|
+ if err := json.Unmarshal(evt.Lease.Attrs.BackendData, &backendData); err != nil {
|
|
|
+ log.Errorf("failed to unmarshal BackendData: %v", err)
|
|
|
+ continue
|
|
|
}
|
|
|
}
|
|
|
+ cmd_output, err := runCmd([]string{
|
|
|
+ fmt.Sprintf("SUBNET=%s", evt.Lease.Subnet),
|
|
|
+ fmt.Sprintf("PUBLIC_IP=%s", evt.Lease.Attrs.PublicIP)},
|
|
|
+ backendData,
|
|
|
+ "sh", "-c", n.subnetRemoveCommand)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ log.Errorf("failed to run command: %s Err: %v Output: %s", n.subnetRemoveCommand, err, cmd_output)
|
|
|
+ } else {
|
|
|
+ log.Infof("Ran command: %s\n Output: %s", n.subnetRemoveCommand, cmd_output)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
default:
|