def get_agents_db(self, context, filters=None): # TODO(annp): keep this method for backward compatibility, # will need to clean it up later query = model_query.get_collection_query(context, agent_model.Agent, filters=filters) return query.all()
def _process_sync_metering_data(self, context, labels): all_routers = None routers_dict = {} for label in labels: if label.shared: if not all_routers: all_routers = model_query.get_collection_query( context, l3_models.Router) routers = all_routers else: routers = label.routers for router in routers: if not router['admin_state_up']: continue router_dict = routers_dict.get(router['id'], self._make_router_dict(router)) rules = self._get_metering_rules_dict(label) data = {'id': label['id'], 'rules': rules} router_dict[constants.METERING_LABEL_KEY].append(data) routers_dict[router['id']] = router_dict return list(routers_dict.values())
def _process_sync_metering_data(self, context, labels): all_routers = None routers_dict = {} for label in labels: if label.shared: if not all_routers: all_routers = model_query.get_collection_query( context, l3_models.Router) routers = all_routers else: routers = label.routers for router in routers: if not router['admin_state_up']: continue router_dict = routers_dict.get( router['id'], self._make_router_dict(router)) rules = self._get_metering_rules_dict(label) data = {'id': label['id'], 'rules': rules} router_dict[constants.METERING_LABEL_KEY].append(data) routers_dict[router['id']] = router_dict return list(routers_dict.values())
def _get_collection_query(context, model, filters=None, sorts=None, limit=None, marker_obj=None, page_reverse=False): return _model_query.get_collection_query(context, model, filters, sorts, limit, marker_obj, page_reverse)
def _retrieve_gateway_connections(self, context, gateway_id, mapping_info=None, only_one=False): mapping_info = mapping_info or {} filters = {'network_gateway_id': [gateway_id]} for k, v in six.iteritems(mapping_info): if v and k != NETWORK_ID: filters[k] = [v] query = model_query.get_collection_query(context, nsx_models.NetworkConnection, filters) return query.one() if only_one else query.all()
def _list_availability_zones(self, context, filters=None): result = {} query = model_query.get_collection_query(context, agent_model.Agent, filters=filters) columns = (agent_model.Agent.admin_state_up, agent_model.Agent.availability_zone, agent_model.Agent.agent_type) for agent in query.with_entities(*columns).group_by(*columns): if not agent.availability_zone: continue if agent.agent_type == constants.AGENT_TYPE_DHCP: resource = 'network' elif agent.agent_type == constants.AGENT_TYPE_L3: resource = 'router' else: continue key = (agent.availability_zone, resource) result[key] = agent.admin_state_up or result.get(key, False) return result
def get_sync_data_for_rule(self, context, rule): label = context.session.query(metering_models.MeteringLabel).get( rule['metering_label_id']) # TODO(electrocucaracha) This depends on the Router OVO implementation if label.shared: routers = model_query.get_collection_query(context, l3_models.Router) else: routers = label.routers routers_dict = {} for router in routers: router_dict = routers_dict.get(router['id'], self._make_router_dict(router)) data = {'id': label['id'], 'rule': rule} router_dict[constants.METERING_LABEL_KEY].append(data) routers_dict[router['id']] = router_dict return list(routers_dict.values())
def get_sync_data_for_rule(self, context, rule): label = context.session.query( metering_models.MeteringLabel).get( rule['metering_label_id']) # TODO(electrocucaracha) This depends on the Router OVO implementation if label.shared: routers = model_query.get_collection_query( context, l3_models.Router) else: routers = label.routers routers_dict = {} for router in routers: router_dict = routers_dict.get(router['id'], self._make_router_dict(router)) data = {'id': label['id'], 'rule': rule} router_dict[constants.METERING_LABEL_KEY].append(data) routers_dict[router['id']] = router_dict return list(routers_dict.values())
def _get_filter_query(obj_cls, context, **kwargs): with obj_cls.db_context_reader(context): filters = _kwargs_to_filters(**kwargs) query = model_query.get_collection_query(context, obj_cls.db_model, filters) return query
def _query_subnets_on_network(self, context, network_id): query = model_query.get_collection_query(context, models_v2.Subnet) return query.filter(models_v2.Subnet.network_id == network_id)
def _get_filter_query(context, model, **kwargs): with context.session.begin(subtransactions=True): filters = _kwargs_to_filters(**kwargs) query = model_query.get_collection_query(context, model, filters) return query
def query_subnets_on_network(cls, context, network_id): query = model_query.get_collection_query(context, cls.db_model) return query.filter(cls.db_model.network_id == network_id)
def get_agents_db(self, context, filters=None): query = model_query.get_collection_query(context, agent_model.Agent, filters=filters) return query.all()
def _get_filter_query(obj_cls, context, **kwargs): with obj_cls.db_context_reader(context): filters = _kwargs_to_filters(**kwargs) query = model_query.get_collection_query( context, obj_cls.db_model, filters) return query
def _is_device_in_use(self, context, device_id): query = model_query.get_collection_query( context, nsx_models.NetworkGatewayDeviceReference, {'id': [device_id]}) return query.first()