Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F24551255
D3979.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D3979.diff
View Options
diff --git a/_modules/node.py b/_modules/node.py
--- a/_modules/node.py
+++ b/_modules/node.py
@@ -12,6 +12,7 @@
from salt.exceptions import CommandExecutionError, SaltCloudConfigError
from salt._compat import ipaddress
+from collections import OrderedDict
DEPLOY_ROLES = [
@@ -504,3 +505,26 @@
routes.update(_get_routes_for_private_networks())
return routes
+
+
+def get_carp_entries():
+ network = get("network")
+
+ carp_entries = []
+
+ for interface_name, interface in network["interfaces"].items():
+ device = interface["device"]
+
+ for fhrp in interface.get('fhrp', []) :
+ if fhrp["protocol"] == 'carp' :
+ # Salt will actually recreate a dictionary, so it won't respect the order
+ # even with OrderedDict
+ entry = OrderedDict()
+ entry["device"] = device
+ entry["vhid"] = fhrp["id"]
+ entry["vip"] = fhrp["vip"]
+ entry["advskew"] = fhrp.get("advskew", 0)
+
+ carp_entries.append(entry)
+
+ return carp_entries
diff --git a/_tests/data/forests.yaml b/_tests/data/forests.yaml
--- a/_tests/data/forests.yaml
+++ b/_tests/data/forests.yaml
@@ -12,13 +12,25 @@
network:
interfaces:
net01:
+ device: net01
ipv4:
address: 1.2.3.4 #public
gateway: 1.2.3.254
+ fhrp:
+ - protocol: carp
+ id: 1
+ vip: 1.2.3.10
+ advskew: 0
net02:
+ device: net02
ipv4:
address: 172.27.27.4 #private
gateway: 172.27.27.1
+ fhrp:
+ - protocol: no-carp
+ id: 2
+ vip: 172.27.27.6
+ advskew: 100
entwash:
forest: fangorn
@@ -28,6 +40,7 @@
network:
interfaces:
net02:
+ device: net02
ipv4:
address: 172.27.27.5 #private
gateway: 172.27.27.1
diff --git a/_tests/modules/test_node.py b/_tests/modules/test_node.py
--- a/_tests/modules/test_node.py
+++ b/_tests/modules/test_node.py
@@ -146,6 +146,22 @@
self.assertIn(k, actual)
self.assertEqual(v, actual[k], f"Unexpected value for key {k} in {actual}")
+ def test_get_carp_entries_returns_expected_values_and_ignores_non_carp(self):
+ expected = [
+ {
+ "device": "net01",
+ "vhid": 1,
+ "vip": "1.2.3.10",
+ "advskew": 0,
+ }
+ ]
+
+ self.assertEqual(expected, node.get_carp_entries())
+
+ def test_get_carp_entries_fhrp_is_empty(self):
+ self.grains["id"] = "entwash"
+ self.assertEqual([], node.get_carp_entries())
+
if __name__ == "__main__":
unittest.main()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Feb 27, 20:17 (22 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3478826
Default Alt Text
D3979.diff (2 KB)
Attached To
Mode
D3979: add helper get_carp_entries() to _modules/node.py and unit tests
Attached
Detach File
Event Timeline
Log In to Comment