def update_ruijie_vlan(vif_id, net_id, old_seg_id): LOG.debug("update_ruijie_vlan, net id is %s, vif id is %s, old vid %s",net_id, vif_id, old_seg_id) vm_eth_binding = rgos_db.get_ruijie_vm_eth_binding(vif_id) if vm_eth_binding == []: return mac_address = vm_eth_binding[0].mac_address LOG.debug("interface id %s has been connected to mac %s",vif_id, mac_address) switch_binding = rgos_db.get_ruijie_switch_eth_binding(mac_address) if switch_binding == []: return; ip = switch_binding[0].ip_address ifx = switch_binding[0].port_id ovs_binding = vlan_mgr.get_network_binding(None, net_id) if ovs_binding == None: return vlan = ovs_binding.segmentation_id # del old ruijie switch vlan rgos_db.remove_ruijie_vlan_binding(ip, ifx, old_seg_id, vif_id) ruijie_vlan_binding = rgos_db.get_ruijie_vlan_binding(ip, ifx, old_seg_id) if ruijie_vlan_binding == []: LOG.debug("to unset the vlan of ruijie switch now") unset_switch_vlan(ip, ifx, old_seg_id) ruijie_vlan_binding = rgos_db.get_ruijie_vlan_binding(ip, ifx, vlan) if ruijie_vlan_binding == []: LOG.debug("to set the vlan of ruijie switch now") set_switch_vlan(ip, ifx, vlan) rgos_db.add_ruijie_vlan_binding(ip, ifx, vlan, vif_id) return
def vm_eth_bind(self, vif, eth_mac): LOG.debug('add vm eth binding, vif: %s eth_mac: %s', vif, eth_mac) net_uuid = self.get_net_uuid(vif) rgos_db.add_ruijie_vm_eth_binding(vif, eth_mac) # update Ruijie switch switch_binding = rgos_db.get_ruijie_switch_eth_binding(eth_mac) if switch_binding == []: return; ip = switch_binding[0].ip_address ifx = switch_binding[0].port_id ovs_binding = rgos_vlanmgr.get_network_binding(None, net_uuid) if ovs_binding == None: return vlan = ovs_binding.segmentation_id LOG.info("the switch ip is %s, ifx is %s, vlan is %s" % (ip, ifx, vlan)) ruijie_vlan_binding = rgos_db.get_ruijie_vlan_binding(ip, ifx, vlan) if ruijie_vlan_binding == []: LOG.info("to set the vlan of ruijie switch now") switch_driver.set_switch_vlan(ip, 22, ifx, vlan) rgos_db.add_ruijie_vlan_binding(ip, ifx, vlan, vif)