def _sync_base(self): ctx = context.get_admin_context() # Sync Networks # Unroll to avoid unwanted additions during sync networks = [x for x in self.core_plugin.get_networks(ctx)] for network in networks: if (network['name'].startswith( constants.HOST_SNAT_NETWORK_PREFIX) or constants.APIC_SYNC_NETWORK == network['name']): continue mech_context = driver_context.NetworkContext( self.core_plugin, ctx, network) try: self.driver.create_network_postcommit(mech_context) except aexc.ReservedSynchronizationName as e: LOG.debug(e.message) except Exception as e: LOG.exception(e) # Sync Subnets subnets = [x for x in self.core_plugin.get_subnets(ctx)] for subnet in subnets: if constants.HOST_SNAT_POOL in subnet['name']: continue network = self.core_plugin.get_network( ctx, subnet['network_id']) mech_context = driver_context.SubnetContext(self.core_plugin, ctx, subnet, network) try: self.driver.create_subnet_postcommit(mech_context) except Exception as e: LOG.exception(e) # Sync Ports (compute/gateway/dhcp) ports = [x for x in self.core_plugin.get_ports(ctx)] for port in ports: if constants.HOST_SNAT_POOL_PORT in port['name']: continue _, binding = l2_db.get_locked_port_and_binding(ctx.session, port['id']) levels = l2_db.get_binding_levels(ctx.session, port['id'], binding.host) network = self.core_plugin.get_network(ctx, port['network_id']) mech_context = driver_context.PortContext(self.core_plugin, ctx, port, network, binding, levels) try: self.driver.create_port_postcommit(mech_context) except Exception as e: LOG.exception(e)
def _sync_base(self): ctx = context.get_admin_context() # Sync Networks # Unroll to avoid unwanted additions during sync networks = [x for x in self.core_plugin.get_networks(ctx)] for network in networks: if constants.APIC_SYNC_NETWORK == network['name']: continue mech_context = driver_context.NetworkContext( self.core_plugin, ctx, network) try: self.driver.create_network_postcommit(mech_context) except aexc.ReservedSynchronizationName as e: LOG.debug(e.message) except Exception as e: LOG.warning(_LW("Create network postcommit failed for " "network %(net_id)s: %(message)s"), net_id=network['id'], message=e.message) # Sync Subnets subnets = [x for x in self.core_plugin.get_subnets(ctx)] for subnet in subnets: mech_context = driver_context.SubnetContext(self.core_plugin, ctx, subnet) try: self.driver.create_subnet_postcommit(mech_context) except Exception as e: LOG.warning(_LW("Create subnet postcommit failed for " "subnet %(sub_id)s: %(message)s"), sub_id=subnet['id'], message=e.message) # Sync Ports (compute/gateway/dhcp) ports = [x for x in self.core_plugin.get_ports(ctx)] for port in ports: binding = l2_db.get_locked_port_and_binding(ctx.session, port['id'])[1] levels = l2_db.get_binding_levels(ctx.session, port['id'], binding.host) network = self.core_plugin.get_network(ctx, port['network_id']) mech_context = driver_context.PortContext(self.core_plugin, ctx, port, network, binding, levels) try: self.driver.create_port_postcommit(mech_context) except Exception as e: LOG.warning(_LW("Create port postcommit failed for " "port %(port_id)s: %(message)s"), port_id=port['id'], message=e.message)
def get_segment_id(self, context, port_id, agent_hosts): try: segment = None if agent_hosts: for host_id in agent_hosts: levels = db.get_binding_levels(context.session, port_id, host_id) if levels: LOG.debug('XXXX levels: %s binding host_id: %s' % (levels, host_id)) for level in levels: segment = db.get_segment_by_id( context.session, level.segment_id) LOG.debug( 'XXXX vlanx to vlan segment id %s: segment %s' % (level.segment_id, segment)) if segment: break return segment except Exception as exc: LOG.error("could not get segment id by port %s and host %s, %s" % (port_id, agent_hosts, exc.message))
def get_segment_id(self, context, port_id, agent_hosts): try: segment = None if agent_hosts: for host_id in agent_hosts: levels = db.get_binding_levels(context, port_id, host_id) if levels: LOG.debug('levels: %s binding host_id: %s' % (levels, host_id)) for level in levels: if level.driver in ('f5networks', 'huawei_ac_ml2'): LOG.debug('level with driver f5networks') segment = segments_db.get_segment_by_id( context, level.segment_id) LOG.debug( 'vxlan 2 vlan seg id %s: segment %s' % (level.segment_id, segment)) if segment: break return segment except Exception as exc: LOG.error("could not get segment id by port %s and host %s, %s" % (port_id, agent_hosts, exc.message))
def get_ports_details_list(self, rpc_context, **kwargs): """Agent requests device details.""" agent_id = kwargs.get('agent_id') port_ids = kwargs.get('port_ids') vcenter_id = kwargs['vcenter_id'] cluster_id = kwargs['cluster_id'] LOG.debug("Port details requested by agent " "%(agent_id)s for ports %(ports)s.", {'ports': port_ids, 'agent_id': agent_id}) out_ports = [] for port_id in port_ids: port_db = self._get_port_db(rpc_context.session, port_id, agent_id) if not port_db: continue port = self.plugin._make_port_dict(port_db) network = self.plugin.get_network(rpc_context, port['network_id']) levels = db.get_binding_levels(rpc_context.session, port_id, port_db.port_binding.host) port_context = driver_context.PortContext(self.plugin, rpc_context, port, network, port_db.port_binding, levels) segment = port_context.top_bound_segment # Reference: ML2 Driver API changes for hierarchical port binding. bound_port = port_context.current if not segment: LOG.warning(_("Port %(port_id)s requested by agent " "%(agent_id)s on network %(network_id)s not " "bound, vif_type: %(vif_type)s."), {'port_id': port['id'], 'agent_id': agent_id, 'network_id': port['network_id'], 'vif_type': port[portbindings.VIF_TYPE]}) continue bound_port['lvid'] = None if segment[api.NETWORK_TYPE] == 'vxlan': port_info = {'port_id': bound_port['id'], 'vcenter_id': vcenter_id, 'cluster_id': cluster_id, 'network_id': bound_port['network_id']} lvid = ovsvapp_db.get_local_vlan(port_info, False) if lvid: bound_port['lvid'] = lvid else: # Local VLANs are exhausted !! No point processing # further. LOG.error(_("Local VLAN not available in the cluster" " %(cluster)s for port" " %(port_id)s in vcenter %(vcenter)s."), {'port_id': bound_port['id'], 'cluster': cluster_id, 'vcenter': vcenter_id}) continue # Skip sending back this port as there is no lvid. else: bound_port['lvid'] = segment[api.SEGMENTATION_ID] entry = {'network_id': bound_port['network_id'], 'port_id': bound_port['id'], 'lvid': bound_port['lvid'], 'mac_address': bound_port['mac_address'], 'admin_state_up': bound_port['admin_state_up'], 'network_type': segment[api.NETWORK_TYPE], 'segmentation_id': segment[api.SEGMENTATION_ID], 'physical_network': segment[api.PHYSICAL_NETWORK], 'fixed_ips': bound_port['fixed_ips'], 'device_id': bound_port['device_id'], 'device_owner': bound_port['device_owner']} LOG.debug("Adding port detail: %s.", entry) out_ports.append(entry) return out_ports
def get_ports_details_list(self, rpc_context, **kwargs): """Agent requests device details.""" agent_id = kwargs.get('agent_id') port_ids = kwargs.get('port_ids') vcenter_id = kwargs['vcenter_id'] cluster_id = kwargs['cluster_id'] LOG.debug( "Port details requested by agent " "%(agent_id)s for ports %(ports)s.", { 'ports': port_ids, 'agent_id': agent_id }) out_ports = [] for port_id in port_ids: port_db = self._get_port_db(rpc_context.session, port_id, agent_id) if not port_db: continue port = self.plugin._make_port_dict(port_db) network = self.plugin.get_network(rpc_context, port['network_id']) levels = db.get_binding_levels(rpc_context, port_id, port_db.port_binding.host) port_context = driver_context.PortContext(self.plugin, rpc_context, port, network, port_db.port_binding, levels) segment = port_context.top_bound_segment # Reference: ML2 Driver API changes for hierarchical port binding. bound_port = port_context.current if not segment: LOG.warning( _LW("Port %(port_id)s requested by agent " "%(agent_id)s on network %(network_id)s not " "bound, vif_type: %(vif_type)s."), { 'port_id': port['id'], 'agent_id': agent_id, 'network_id': port['network_id'], 'vif_type': port[portbindings.VIF_TYPE] }) continue bound_port['lvid'] = None port_info = { 'port_id': bound_port['id'], 'vcenter_id': vcenter_id, 'cluster_id': cluster_id, 'network_id': bound_port['network_id'] } lvid = ovsvapp_db.get_local_vlan(port_info, False) if lvid: bound_port['lvid'] = lvid else: # Local VLANs are exhausted !! No point processing # further. LOG.error( _LE("Local VLAN not available in the cluster" " %(cluster)s for port" " %(port_id)s in vcenter %(vcenter)s."), { 'port_id': bound_port['id'], 'cluster': cluster_id, 'vcenter': vcenter_id }) # Skip sending back this port as there is no lvid. continue entry = { 'network_id': bound_port['network_id'], 'port_id': bound_port['id'], 'lvid': bound_port['lvid'], 'mac_address': bound_port['mac_address'], 'admin_state_up': bound_port['admin_state_up'], 'network_type': segment[api.NETWORK_TYPE], 'segmentation_id': segment[api.SEGMENTATION_ID], 'physical_network': segment[api.PHYSICAL_NETWORK], 'fixed_ips': bound_port['fixed_ips'], 'device_id': bound_port['device_id'], 'security_groups': bound_port['security_groups'], 'device_owner': bound_port['device_owner'] } LOG.debug("Adding port detail: %s.", entry) out_ports.append(entry) return out_ports