~gandelman-a/ubuntu/precise/nova/UCA_2012.2.1

« back to all changes in this revision

Viewing changes to nova/api/openstack/compute/flavors.py

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman, Adam Gandelman, Chuck Short
  • Date: 2012-08-27 15:37:18 UTC
  • mfrom: (1.1.60)
  • Revision ID: package-import@ubuntu.com-20120827153718-lj8er44eqqz1gsrj
Tags: 2012.2~rc1~20120827.15815-0ubuntu1
[ Adam Gandelman ]
* New upstream release.

[ Chuck Short ]
* debian/patches/0001-Update-tools-hacking-for-pep8-1.2-and-
  beyond.patch: Dropped we dont run pep8 tests anymore.
* debian/control: Drop pep8 build depends
* debian/*.upstart.in: Make sure we transition correctly from runlevel
  1 to 2. (LP: #820694)

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
 
92
92
        return self._view_builder.show(req, flavor)
93
93
 
 
94
    def _get_is_public(self, req):
 
95
        """Parse is_public into something usable."""
 
96
        is_public = req.params.get('is_public', None)
 
97
 
 
98
        if is_public is None:
 
99
            # preserve default value of showing only public flavors
 
100
            return True
 
101
        elif is_public is True or \
 
102
            is_public.lower() in ['t', 'true', 'yes', '1']:
 
103
            return True
 
104
        elif is_public is False or \
 
105
            is_public.lower() in ['f', 'false', 'no', '0']:
 
106
            return False
 
107
        elif is_public.lower() == 'none':
 
108
            # value to match all flavors, ignore is_public
 
109
            return None
 
110
        else:
 
111
            msg = _('Invalid is_public filter [%s]') % req.params['is_public']
 
112
            raise webob.exc.HTTPBadRequest(explanation=msg)
 
113
 
94
114
    def _get_flavors(self, req):
95
115
        """Helper function that returns a list of flavor dicts."""
96
116
        filters = {}
97
117
 
98
118
        context = req.environ['nova.context']
99
 
        if not context.is_admin:
 
119
        if context.is_admin:
 
120
            # Only admin has query access to all flavor types
 
121
            filters['is_public'] = self._get_is_public(req)
 
122
        else:
 
123
            filters['is_public'] = True
100
124
            filters['disabled'] = False
101
125
 
102
126
        if 'minRam' in req.params:
113
137
                msg = _('Invalid minDisk filter [%s]') % req.params['minDisk']
114
138
                raise webob.exc.HTTPBadRequest(explanation=msg)
115
139
 
116
 
        flavors = instance_types.get_all_types(filters=filters)
 
140
        flavors = instance_types.get_all_types(context, filters=filters)
117
141
        flavors_list = flavors.values()
118
142
        sorted_flavors = sorted(flavors_list,
119
143
                                key=lambda item: item['flavorid'])