From 76f64c70d0f6af4b4d934db928997ac5649affb9 Mon Sep 17 00:00:00 2001 From: Zhenmei Date: Fri, 25 Sep 2015 06:51:02 +0800 Subject: [PATCH] Enable HA on the edge which works as L2 gateway Change-Id: I93023bbe508d22d1095a1682402f0ab1d99ed05d --- vmware_nsx/plugins/nsx_v/vshield/edge_appliance_driver.py | 6 ++++++ vmware_nsx/plugins/nsx_v/vshield/vcns.py | 5 +++++ vmware_nsx/services/l2gateway/nsx_v/driver.py | 5 +++++ vmware_nsx/tests/unit/nsx_v/vshield/fake_vcns.py | 7 +++++++ 4 files changed, 23 insertions(+) diff --git a/vmware_nsx/plugins/nsx_v/vshield/edge_appliance_driver.py b/vmware_nsx/plugins/nsx_v/vshield/edge_appliance_driver.py index 8297563463..a77565009b 100644 --- a/vmware_nsx/plugins/nsx_v/vshield/edge_appliance_driver.py +++ b/vmware_nsx/plugins/nsx_v/vshield/edge_appliance_driver.py @@ -1060,3 +1060,9 @@ class EdgeApplianceDriver(object): except exceptions.VcnsApiException: LOG.exception(_LE("Failed to delete bridge in the %s"), device_name) + + def update_edge_ha(self, edge_id): + ha_request = { + 'featureType': "highavailability_4.0", + 'enabled': True} + self.vcns.enable_ha(edge_id, ha_request) diff --git a/vmware_nsx/plugins/nsx_v/vshield/vcns.py b/vmware_nsx/plugins/nsx_v/vshield/vcns.py index 15961f37cb..3b7d41c4ab 100644 --- a/vmware_nsx/plugins/nsx_v/vshield/vcns.py +++ b/vmware_nsx/plugins/nsx_v/vshield/vcns.py @@ -787,3 +787,8 @@ class Vcns(object): tuning.append(child) return self.do_request(HTTP_PUT, uri, et.tostring(tuning), format='xml', decode=True) + + def enable_ha(self, edge_id, request_config): + """Enable HA in the given edge.""" + uri = "/api/4.0/edges/%s/highavailability/config?async=true" % edge_id + return self.do_request(HTTP_PUT, uri, request_config) diff --git a/vmware_nsx/services/l2gateway/nsx_v/driver.py b/vmware_nsx/services/l2gateway/nsx_v/driver.py index 68eae76828..36176c8482 100644 --- a/vmware_nsx/services/l2gateway/nsx_v/driver.py +++ b/vmware_nsx/services/l2gateway/nsx_v/driver.py @@ -35,6 +35,8 @@ LOG = logging.getLogger(__name__) class NsxvL2GatewayDriver(l2gateway_db.L2GatewayMixin): + """Class to handle API calls for L2 gateway and NSXv backend.""" + @property def _core_plugin(self): return manager.NeutronManager.get_plugin() @@ -95,6 +97,9 @@ class NsxvL2GatewayDriver(l2gateway_db.L2GatewayMixin): lrouter['id']) if not edge_binding: raise nsx_exc.NsxL2GWDeviceNotFound() + # Enable edge HA on the DLR + edge_id = edge_binding['edge_id'] + self._edge_manager.nsxv_manager.update_edge_ha(edge_id) return edge_binding['edge_id'] def _get_device(self, context, l2gw_id): diff --git a/vmware_nsx/tests/unit/nsx_v/vshield/fake_vcns.py b/vmware_nsx/tests/unit/nsx_v/vshield/fake_vcns.py index 60e9ede4fe..274f7d0e94 100644 --- a/vmware_nsx/tests/unit/nsx_v/vshield/fake_vcns.py +++ b/vmware_nsx/tests/unit/nsx_v/vshield/fake_vcns.py @@ -1096,3 +1096,10 @@ class FakeVcns(object): def configure_aggregate_publishing(self): pass + + def enable_ha(self, edge_id, request_config): + header = { + 'status': 201 + } + response = '' + return (header, response)