def _manage_port(self, vlan_name, vlan_id, host, instance): """Called during create and update port events. Create a VLAN in the appropriate switch/port and configure the appropriate interfaces for this VLAN. """ # Grab the switch IP and port for this host for switch_ip, attr in self._nexus_switches: if str(attr) == str(host): port_id = self._nexus_switches[switch_ip, attr] break else: raise excep.NexusComputeHostNotConfigured(host=host) # Check if this network is already in the DB vlan_created = False vlan_trunked = False try: nxos_db.get_port_vlan_switch_binding(port_id, vlan_id, switch_ip) except excep.NexusPortBindingNotFound: # Check for vlan/switch binding try: nxos_db.get_nexusvlan_binding(vlan_id, switch_ip) except excep.NexusPortBindingNotFound: # Create vlan and trunk vlan on the port LOG.debug(_("Nexus: create & trunk vlan %s"), vlan_name) self.driver.create_and_trunk_vlan(switch_ip, vlan_id, vlan_name, port_id) vlan_created = True vlan_trunked = True else: # Only trunk vlan on the port LOG.debug(_("Nexus: trunk vlan %s"), vlan_name) self.driver.enable_vlan_on_trunk_int(switch_ip, vlan_id, port_id) vlan_trunked = True try: nxos_db.add_nexusport_binding(port_id, str(vlan_id), switch_ip, instance) except Exception: with excutils.save_and_reraise_exception(): # Add binding failed, roll back any vlan creation/enabling if vlan_created and vlan_trunked: LOG.debug(_("Nexus: delete & untrunk vlan %s"), vlan_name) self.driver.delete_and_untrunk_vlan(switch_ip, vlan_id, port_id) elif vlan_created: LOG.debug(_("Nexus: delete vlan %s"), vlan_name) self.driver.delete_vlan(switch_ip, vlan_id) elif vlan_trunked: LOG.debug(_("Nexus: untrunk vlan %s"), vlan_name) self.driver.disable_vlan_on_trunk_int(switch_ip, vlan_id, port_id)
def _manage_port(self, vlan_name, vlan_id, host, instance): """Called during create and update port events. Create a VLAN in the appropriate switch/port and configure the appropriate interfaces for this VLAN. """ # Grab the switch IP and port for this host for switch_ip, attr in self._nexus_switches: if str(attr) == str(host): port_id = self._nexus_switches[switch_ip, attr] break else: raise excep.NexusComputeHostNotConfigured(host=host) # Check if this network is already in the DB vlan_created = False vlan_trunked = False try: nxos_db.get_port_vlan_switch_binding(port_id, vlan_id, switch_ip) except excep.NexusPortBindingNotFound: # Check for vlan/switch binding try: nxos_db.get_nexusvlan_binding(vlan_id, switch_ip) except excep.NexusPortBindingNotFound: # Create vlan and trunk vlan on the port LOG.debug(_("Nexus: create & trunk vlan %s"), vlan_name) self.driver.create_and_trunk_vlan(switch_ip, vlan_id, vlan_name, port_id) vlan_created = True vlan_trunked = True else: # Only trunk vlan on the port LOG.debug(_("Nexus: trunk vlan %s"), vlan_name) self.driver.enable_vlan_on_trunk_int(switch_ip, vlan_id, port_id) vlan_trunked = True try: nxos_db.add_nexusport_binding(port_id, str(vlan_id), switch_ip, instance) except Exception: with excutils.save_and_reraise_exception(): # Add binding failed, roll back any vlan creation/enabling if vlan_created and vlan_trunked: LOG.debug(_("Nexus: delete & untrunk vlan %s"), vlan_name) self.driver.delete_and_untrunk_vlan( switch_ip, vlan_id, port_id) elif vlan_created: LOG.debug(_("Nexus: delete vlan %s"), vlan_name) self.driver.delete_vlan(switch_ip, vlan_id) elif vlan_trunked: LOG.debug(_("Nexus: untrunk vlan %s"), vlan_name) self.driver.disable_vlan_on_trunk_int( switch_ip, vlan_id, port_id)
def test_nexusportvlanswitchbinding_get(self): """Tests get of port bindings based on port, vlan, and switch.""" npb11 = self._npb_test_obj(10, 100) npb21 = self._npb_test_obj(20, 100) self._add_bindings_to_db([npb11, npb21]) npb = self._get_port_vlan_switch_binding(npb11) self.assertEqual(len(npb), 1) self._assert_bindings_match(npb[0], npb11) with testtools.ExpectedException(exceptions.NexusPortBindingNotFound): nexus_db_v2.get_port_vlan_switch_binding( npb21.port, npb21.vlan, "dummySwitch")
def _get_port_vlan_switch_binding(self, npb): """Gets port bindings based on port, vlan, and switch.""" return nexus_db_v2.get_port_vlan_switch_binding( npb.port, npb.vlan, npb.switch)