def test_nexusvmbinding_get(self): """Test get of port bindings based on vlan and instance.""" npb11 = self._npb_test_obj(10, 100) npb21 = self._npb_test_obj(20, 100) npb22 = self._npb_test_obj(20, 200) self._add_bindings_to_db([npb11, npb21, npb22]) npb = self._get_nexusvm_binding(npb21) self._assert_bindings_match(npb, npb21) npb = self._get_nexusvm_binding(npb22) self._assert_bindings_match(npb, npb22) with testtools.ExpectedException(exceptions.NexusPortBindingNotFound): nexus_db_v2.get_nexusvm_binding(npb21.vlan, "dummyInstance")
def delete_port_precommit(self, context): """Delete port pre-database commit event. Delete port bindings from the database and scan whether the network is still required on the interfaces trunked. """ if not self._is_deviceowner_compute(context.current): return port = context.current device_id = port['device_id'] vlan_id = self._get_vlanid(context) if not vlan_id or not device_id: return # Delete DB row for this port try: row = nxos_db.get_nexusvm_binding(vlan_id, device_id) except excep.NexusPortBindingNotFound: return switch_ip = row.switch_ip nexus_port = None if row.port_id != 'router': nexus_port = row.port_id nxos_db.remove_nexusport_binding(row.port_id, row.vlan_id, row.switch_ip, row.instance_id) # Check for any other bindings with the same vlan_id and switch_ip try: nxos_db.get_nexusvlan_binding(row.vlan_id, row.switch_ip) except excep.NexusPortBindingNotFound: try: # Delete this vlan from this switch if nexus_port: self.driver.disable_vlan_on_trunk_int(switch_ip, row.vlan_id, nexus_port) self.driver.delete_vlan(switch_ip, row.vlan_id) except Exception: # The delete vlan operation on the Nexus failed, # so this delete_port request has failed. For # consistency, roll back the Nexus database to what # it was before this request. with excutils.save_and_reraise_exception(): nxos_db.add_nexusport_binding(row.port_id, row.vlan_id, row.switch_ip, row.instance_id)
def delete_port_precommit(self, context): """Delete port pre-database commit event. Delete port bindings from the database and scan whether the network is still required on the interfaces trunked. """ if not self._is_deviceowner_compute(context.current): return port = context.current device_id = port['device_id'] vlan_id = self._get_vlanid(context) if not vlan_id or not device_id: return # Delete DB row for this port try: row = nxos_db.get_nexusvm_binding(vlan_id, device_id) except excep.NexusPortBindingNotFound: return switch_ip = row.switch_ip nexus_port = None if row.port_id != 'router': nexus_port = row.port_id nxos_db.remove_nexusport_binding(row.port_id, row.vlan_id, row.switch_ip, row.instance_id) # Check for any other bindings with the same vlan_id and switch_ip try: nxos_db.get_nexusvlan_binding(row.vlan_id, row.switch_ip) except excep.NexusPortBindingNotFound: try: # Delete this vlan from this switch if nexus_port: self.driver.disable_vlan_on_trunk_int( switch_ip, row.vlan_id, nexus_port) self.driver.delete_vlan(switch_ip, row.vlan_id) except Exception: # The delete vlan operation on the Nexus failed, # so this delete_port request has failed. For # consistency, roll back the Nexus database to what # it was before this request. with excutils.save_and_reraise_exception(): nxos_db.add_nexusport_binding(row.port_id, row.vlan_id, row.switch_ip, row.instance_id)
def _get_nexusvm_binding(self, npb): """Gets port bindings based on vlan and instance.""" return nexus_db_v2.get_nexusvm_binding(npb.vlan, npb.instance)