From 72af9f1b3401f7201c8be03296b46274b104b1b2 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Sun, 26 Mar 2017 10:21:30 +0300 Subject: [PATCH] NSX-V| Adding datacenter to availability zones config The datacenter_moid will be a part of each availability zone. If not configured inside the AZ, the global (default) one will be used. Change-Id: I80d8dfdaaeb1745f5f2fa59a80b5f8c74d2d7b31 --- vmware_nsx/common/config.py | 3 +++ vmware_nsx/plugins/nsx_v/availability_zones.py | 8 ++++++++ vmware_nsx/plugins/nsx_v/vshield/edge_appliance_driver.py | 4 ++-- vmware_nsx/plugins/nsx_v/vshield/vcns_driver.py | 1 - vmware_nsx/tests/unit/nsx_v/test_availability_zones.py | 6 ++++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/vmware_nsx/common/config.py b/vmware_nsx/common/config.py index cf96589f05..a56005cdca 100644 --- a/vmware_nsx/common/config.py +++ b/vmware_nsx/common/config.py @@ -702,6 +702,9 @@ nsxv_az_opts = [ 'that active/backup edges are placed in the listed ' 'host groups. 2 predefined host groups need to be ' 'configured.')), + cfg.StrOpt('datacenter_moid', + help=_('(Optional) Identifying the ID of datacenter to deploy ' + 'NSX Edges')), cfg.ListOpt('backup_edge_pool', help=_("(Optional) Defines edge pool's management range for " "the availability zone. If not defined, the global one " diff --git a/vmware_nsx/plugins/nsx_v/availability_zones.py b/vmware_nsx/plugins/nsx_v/availability_zones.py index 74047329ea..cc292de701 100644 --- a/vmware_nsx/plugins/nsx_v/availability_zones.py +++ b/vmware_nsx/plugins/nsx_v/availability_zones.py @@ -60,6 +60,7 @@ class NsxVAvailabilityZone(common_az.ConfiguredAvailabilityZone): # Some parameters are not supported in this format. # using the global ones instead. self.ha_placement_random = cfg.CONF.nsxv.ha_placement_random + self.datacenter_moid = cfg.CONF.nsxv.datacenter_moid self.backup_edge_pool = cfg.CONF.nsxv.backup_edge_pool self.external_network = cfg.CONF.nsxv.external_network self.vdn_scope_id = cfg.CONF.nsxv.vdn_scope_id @@ -102,6 +103,10 @@ class NsxVAvailabilityZone(common_az.ConfiguredAvailabilityZone): self.ha_placement_random = ( cfg.CONF.nsxv.ha_placement_random) + self.datacenter_moid = az_info.get('datacenter_moid') + if not self.datacenter_moid: + self.datacenter_moid = cfg.CONF.nsxv.datacenter_moid + self.backup_edge_pool = az_info.get('backup_edge_pool', []) if not self.backup_edge_pool: self.backup_edge_pool = cfg.CONF.nsxv.backup_edge_pool @@ -170,6 +175,7 @@ class NsxVAvailabilityZone(common_az.ConfiguredAvailabilityZone): self.edge_ha = cfg.CONF.nsxv.edge_ha self.ha_datastore_id = cfg.CONF.nsxv.ha_datastore_id self.ha_placement_random = cfg.CONF.nsxv.ha_placement_random + self.datacenter_moid = cfg.CONF.nsxv.datacenter_moid self.backup_edge_pool = cfg.CONF.nsxv.backup_edge_pool self.az_metadata_support = True self.mgt_net_moid = cfg.CONF.nsxv.mgt_net_moid @@ -213,4 +219,6 @@ class NsxVAvailabilityZones(common_az.ConfiguredAvailabilityZones): resources.append(az.vdn_scope_id) if az.mgt_net_moid: resources.append(az.mgt_net_moid) + if az.datacenter_moid: + resources.append(az.datacenter_moid) return resources 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 56c4810345..2edc8a29bc 100644 --- a/vmware_nsx/plugins/nsx_v/vshield/edge_appliance_driver.py +++ b/vmware_nsx/plugins/nsx_v/vshield/edge_appliance_driver.py @@ -386,7 +386,7 @@ class EdgeApplianceDriver(object): edge_name = name edge = self._assemble_edge( - edge_name, datacenter_moid=self.datacenter_moid, + edge_name, datacenter_moid=availability_zone.datacenter_moid, deployment_container_id=self.deployment_container_id, appliance_size=appliance_size, remote_access=False, dist=dist, edge_ha=availability_zone.edge_ha) @@ -459,7 +459,7 @@ class EdgeApplianceDriver(object): set_errors=False, availability_zone=None): """Update edge name.""" edge = self._assemble_edge( - name, datacenter_moid=self.datacenter_moid, + name, datacenter_moid=availability_zone.datacenter_moid, deployment_container_id=self.deployment_container_id, appliance_size=appliance_size, remote_access=False, dist=dist, edge_ha=availability_zone.edge_ha) diff --git a/vmware_nsx/plugins/nsx_v/vshield/vcns_driver.py b/vmware_nsx/plugins/nsx_v/vshield/vcns_driver.py index c8a741df2b..856161ae60 100644 --- a/vmware_nsx/plugins/nsx_v/vshield/vcns_driver.py +++ b/vmware_nsx/plugins/nsx_v/vshield/vcns_driver.py @@ -40,7 +40,6 @@ class VcnsDriver(edge_appliance_driver.EdgeApplianceDriver, self.vcns_passwd = cfg.CONF.nsxv.password self.ca_file = cfg.CONF.nsxv.ca_file self.insecure = cfg.CONF.nsxv.insecure - self.datacenter_moid = cfg.CONF.nsxv.datacenter_moid self.deployment_container_id = cfg.CONF.nsxv.deployment_container_id self._pid = None self._task_manager = None diff --git a/vmware_nsx/tests/unit/nsx_v/test_availability_zones.py b/vmware_nsx/tests/unit/nsx_v/test_availability_zones.py index 5064889ff4..1863c8dd66 100644 --- a/vmware_nsx/tests/unit/nsx_v/test_availability_zones.py +++ b/vmware_nsx/tests/unit/nsx_v/test_availability_zones.py @@ -44,6 +44,7 @@ class NsxvAvailabilityZonesTestCase(base.BaseTestCase): ha_datastore_id="hastore", backup_edge_pool=DEF_AZ_POOL, ha_placement_random=False, + datacenter_moid="datacenter", mgt_net_moid="portgroup-407", mgt_net_proxy_ips=["1.1.1.1"], mgt_net_proxy_netmask="255.255.255.0", @@ -64,6 +65,10 @@ class NsxvAvailabilityZonesTestCase(base.BaseTestCase): cfg.CONF.set_override("ha_placement_random", ha_placement_random, group=self.group_name) + if datacenter_moid is not None: + cfg.CONF.set_override("datacenter_moid", + datacenter_moid, + group=self.group_name) if backup_edge_pool is not None: cfg.CONF.set_override("backup_edge_pool", backup_edge_pool, group=self.group_name) @@ -100,6 +105,7 @@ class NsxvAvailabilityZonesTestCase(base.BaseTestCase): self.assertTrue(az.edge_ha) self.assertEqual("hastore", az.ha_datastore_id) self.assertFalse(az.ha_placement_random) + self.assertEqual("datacenter", az.datacenter_moid) self.assertEqual(DEF_AZ_POOL, az.backup_edge_pool) self.assertEqual("portgroup-407", az.mgt_net_moid) self.assertEqual(["1.1.1.1"], az.mgt_net_proxy_ips)