def _get_extensions(self, context): """Filter extensions list based on policy.""" discoverable_extensions = dict() for alias, ext in self.extension_info.get_extensions().iteritems(): authorize = extensions.os_compute_soft_authorizer(alias) if authorize(context, action='discoverable'): discoverable_extensions[alias] = ext else: LOG.debug("Filter out extension %s from discover list", alias) # Add fake v2 extensions to list extra_exts = {} for alias in discoverable_extensions: if alias in v21_to_v2_extension_list_mapping: for extra_ext in v21_to_v2_extension_list_mapping[alias]: extra_exts[extra_ext["alias"]] = self._create_fake_ext( extra_ext["name"], extra_ext["alias"]) discoverable_extensions.update(extra_exts) # Suppress extensions which we don't want to see in v2 for suppress_ext in v2_extension_suppress_list: try: del discoverable_extensions[suppress_ext] except KeyError: pass # v2.1 to v2 extension name mapping for rename_ext in v21_to_v2_alias_mapping: if rename_ext in discoverable_extensions: new_name = v21_to_v2_alias_mapping[rename_ext] mod_ext = copy.deepcopy( discoverable_extensions.pop(rename_ext)) mod_ext.alias = new_name discoverable_extensions[new_name] = mod_ext return discoverable_extensions
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """The Extended Availability Zone Status API extension.""" from patron.api.openstack import extensions from patron.api.openstack import wsgi from patron import availability_zones as avail_zone ALIAS = "os-extended-availability-zone" authorize = extensions.os_compute_soft_authorizer(ALIAS) PREFIX = "OS-EXT-AZ" class ExtendedAZController(wsgi.Controller): def _extend_server(self, context, server, instance): key = "%s:availability_zone" % PREFIX az = avail_zone.get_instance_availability_zone(context, instance) if not az and instance.get('availability_zone'): # Likely hasn't reached a viable compute node yet so give back the # desired availability_zone that *may* exist in the instance # record itself. az = instance.availability_zone server[key] = az @wsgi.extends
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import webob.exc from patron.api.openstack import extensions from patron.api.openstack import wsgi from patron import compute from patron import exception from patron import objects ALIAS = 'os-pci' soft_authorize = extensions.os_compute_soft_authorizer(ALIAS + ':pci_servers') authorize = extensions.os_compute_authorizer(ALIAS) PCI_ADMIN_KEYS = ['id', 'address', 'vendor_id', 'product_id', 'status', 'compute_node_id'] PCI_DETAIL_KEYS = ['dev_type', 'label', 'instance_uuid', 'dev_id', 'extra_info'] class PciServerController(wsgi.Controller): def _extend_server(self, server, instance): dev_id = [] for dev in instance.pci_devices: dev_id.append({'id': dev['id']}) server['%s:pci_devices' % Pci.alias] = dev_id
# a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """The Flavor Rxtx API extension.""" from patron.api.openstack import extensions from patron.api.openstack import wsgi ALIAS = 'os-flavor-rxtx' authorize = extensions.os_compute_soft_authorizer(ALIAS) class FlavorRxtxController(wsgi.Controller): def _extend_flavors(self, req, flavors): for flavor in flavors: db_flavor = req.get_db_flavor(flavor['id']) key = 'rxtx_factor' flavor[key] = db_flavor['rxtx_factor'] or "" def _show(self, req, resp_obj): if not authorize(req.environ['patron.context']): return if 'flavor' in resp_obj.obj: self._extend_flavors(req, [resp_obj.obj['flavor']])