~ubuntu-branches/ubuntu/quantal/quantum/quantal-updates

« back to all changes in this revision

Viewing changes to quantum/db/db_base_plugin_v2.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-09-21 13:01:18 UTC
  • mfrom: (2.1.13)
  • Revision ID: package-import@ubuntu.com-20120921130118-1g2oowz454jlbu40
Tags: 2012.2~rc2-0ubuntu1
[ Adam Gandelman ]
* debian/quantum-server.{default, upstart}: Use default file to specify
  path to plugin config, which is passed to quantum-server as
  '--config-file' during startup. (LP: #1009294)
* debian/control:
  - Remove quantum-server's dependency on 'quantum-plugin'.
  - Specify >= 1:0.1.0.1-0ubuntu1 requirement for python-quantumclient.
  - Add dnsmasq dependencies to quantum-dhcp-agent Depends.

[ Chuck Short ]
* New upstream version.
* debian/patches/fix-ubuntu-tests.patch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
200
200
                         if key in fields))
201
201
        return resource
202
202
 
203
 
    def _get_collection(self, context, model, dict_func, filters=None,
204
 
                        fields=None):
205
 
        collection = self._model_query(context, model)
 
203
    def _apply_filters_to_query(self, query, model, filters):
206
204
        if filters:
207
205
            for key, value in filters.iteritems():
208
206
                column = getattr(model, key, None)
209
207
                if column:
210
 
                    collection = collection.filter(column.in_(value))
 
208
                    query = query.filter(column.in_(value))
 
209
        return query
 
210
 
 
211
    def _get_collection(self, context, model, dict_func, filters=None,
 
212
                        fields=None):
 
213
        collection = self._model_query(context, model)
 
214
        collection = self._apply_filters_to_query(collection, model, filters)
211
215
        return [dict_func(c, fields) for c in collection.all()]
212
216
 
213
217
    @staticmethod
1236
1240
        return self._make_port_dict(port, fields)
1237
1241
 
1238
1242
    def get_ports(self, context, filters=None, fields=None):
1239
 
        fixed_ips = filters.pop('fixed_ips', []) if filters else []
1240
 
        ports = self._get_collection(context, models_v2.Port,
1241
 
                                     self._make_port_dict,
1242
 
                                     filters=filters, fields=fields)
1243
 
 
1244
 
        if ports and fixed_ips:
1245
 
            filtered_ports = []
1246
 
            for port in ports:
1247
 
                if port['fixed_ips']:
1248
 
                    ips = port['fixed_ips']
1249
 
                    for fixed in fixed_ips:
1250
 
                        found = False
1251
 
                        # Convert to dictionary (deserialize)
1252
 
                        fixed = eval(fixed)
1253
 
                        for ip in ips:
1254
 
                            if 'ip_address' in fixed and 'subnet_id' in fixed:
1255
 
                                if (ip['ip_address'] == fixed['ip_address'] and
1256
 
                                        ip['subnet_id'] == fixed['subnet_id']):
1257
 
                                    found = True
1258
 
                            elif 'ip_address' in fixed:
1259
 
                                if ip['ip_address'] == fixed['ip_address']:
1260
 
                                    found = True
1261
 
                            elif 'subnet_id' in fixed:
1262
 
                                if ip['subnet_id'] == fixed['subnet_id']:
1263
 
                                    found = True
1264
 
                            if found:
1265
 
                                filtered_ports.append(port)
1266
 
                                break
1267
 
                        if found:
1268
 
                            break
1269
 
            return filtered_ports
1270
 
        return ports
 
1243
        Port = models_v2.Port
 
1244
        IPAllocation = models_v2.IPAllocation
 
1245
 
 
1246
        if not filters:
 
1247
            filters = {}
 
1248
 
 
1249
        query = self._model_query(context, Port)
 
1250
 
 
1251
        fixed_ips = filters.pop('fixed_ips', {})
 
1252
        ip_addresses = fixed_ips.get('ip_address')
 
1253
        subnet_ids = fixed_ips.get('subnet_id')
 
1254
        if ip_addresses or subnet_ids:
 
1255
            query = query.join(Port.fixed_ips)
 
1256
            if ip_addresses:
 
1257
                query = query.filter(IPAllocation.ip_address.in_(ip_addresses))
 
1258
            if subnet_ids:
 
1259
                query = query.filter(IPAllocation.subnet_id.in_(subnet_ids))
 
1260
 
 
1261
        query = self._apply_filters_to_query(query, Port, filters)
 
1262
        return [self._make_port_dict(c, fields) for c in query.all()]