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.soft_extension_authorizer("compute", "v3:" + alias) if authorize(context, action="discoverable"): discoverable_extensions[alias] = ext else: LOG.debug(_("Filter out extension %s from discover list"), alias) return discoverable_extensions
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.soft_extension_authorizer( 'compute', 'v3:' + 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) # Supress extensions which we don't want to see in v2 for supress_ext in v2_extension_suppress_list: try: del discoverable_extensions[supress_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
import six from webob import exc from nova.api.openstack.compute import servers from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import objects from nova.openstack.common import jsonutils #from nova.openstack.common import hw_host_networklist authorize = extensions.soft_extension_authorizer('compute', 'affinity_mask') class ServerAffinityMaskTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('server') root.set('vcpuAffinity', 'vcpuAffinity') root.set('hyperThreadAffinity', 'hyperThreadAffinity') return xmlutil.SlaveTemplate(root, 1) class ServersAffinityMaskTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('servers') elem = xmlutil.SubTemplateElement(root, 'server', selector='servers') elem.set('vcpuAffinity', 'vcpuAffinity') elem.set('hyperThreadAffinity', 'hyperThreadAffinity') return xmlutil.SlaveTemplate(root, 1)
# 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 Status Admin API extension.""" from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute authorize = extensions.soft_extension_authorizer('compute', 'extended_status') class ExtendedStatusController(wsgi.Controller): def __init__(self, *args, **kwargs): super(ExtendedStatusController, self).__init__(*args, **kwargs) self.compute_api = compute.API() def _extend_server(self, server, instance): for state in ['task_state', 'vm_state', 'power_state']: key = "%s:%s" % (Extended_status.alias, state) server[key] = instance[state] @wsgi.extends def show(self, req, resp_obj, id): context = req.environ['nova.context']
# not use this file except in compliance with the License. You may obtain # 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 from nova.api.openstack import extensions from nova.api.openstack.compute import servers from nova.api.openstack.compute import views authorize = extensions.soft_extension_authorizer('compute', 'createserverext') class ViewBuilder(views.servers.ViewBuilder): """Adds security group output when viewing server details.""" def show(self, request, instance): """Detailed view of a single instance.""" server = super(ViewBuilder, self).show(request, instance) context = request.environ['nova.context'] if authorize(context): server["server"]["security_groups"] = self._get_groups(instance) return server def _get_groups(self, instance): """Get a list of security groups for this instance.""" groups = instance.get('security_groups')
# 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 access extension.""" import webob from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova.compute import instance_types from nova import exception authorize = extensions.soft_extension_authorizer('compute', 'flavor_access') def make_flavor(elem): elem.set('{%s}is_public' % Flavor_access.namespace, '%s:is_public' % Flavor_access.alias) def make_flavor_access(elem): elem.set('flavor_id') elem.set('tenant_id') class FlavorTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('flavor', selector='flavor')
# under the License. """Disk Config extension.""" from oslo_utils import strutils from webob import exc from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.i18n import _ ALIAS = 'OS-DCF' XMLNS_DCF = "http://docs.openstack.org/compute/ext/disk_config/api/v1.1" API_DISK_CONFIG = "%s:diskConfig" % ALIAS INTERNAL_DISK_CONFIG = "auto_disk_config" authorize = extensions.soft_extension_authorizer('compute', 'disk_config') def disk_config_to_api(value): return 'AUTO' if value else 'MANUAL' def disk_config_from_api(value): if value == 'AUTO': return True elif value == 'MANUAL': return False else: msg = _("%s must be either 'MANUAL' or 'AUTO'.") % API_DISK_CONFIG raise exc.HTTPBadRequest(explanation=msg)
# 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. from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.openstack.common import jsonutils ALIAS = 'os-pci' instance_authorize = extensions.soft_extension_authorizer( 'compute', 'v3:' + ALIAS + ':pci_servers') 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 @wsgi.extends def show(self, req, resp_obj, id): context = req.environ['nova.context'] if instance_authorize(context): server = resp_obj.obj['server'] instance = req.get_db_instance(server['id'])
from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.compute import vm_states opts = [ cfg.ListOpt('osapi_hide_server_address_states', default=[vm_states.BUILDING], help='List of instance states that should hide network info'), ] CONF = cfg.CONF CONF.register_opts(opts) ALIAS = 'os-hide-server-addresses' authorize = extensions.soft_extension_authorizer('compute', 'v3:' + ALIAS) class Controller(wsgi.Controller): def __init__(self, *args, **kwargs): super(Controller, self).__init__(*args, **kwargs) hidden_states = CONF.osapi_hide_server_address_states # NOTE(jkoelker) _ is not considered uppercase ;) valid_vm_states = [ getattr(vm_states, state) for state in dir(vm_states) if state.isupper() ] self.hide_address_states = [ state.lower() for state in hidden_states if state in valid_vm_states
from webob import exc from nova.api.openstack import common from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute from nova import exception from nova.openstack.common.gettextutils import _ from nova.openstack.common import log as logging from nova.openstack.common import uuidutils from nova import volume ALIAS = "os-extended-volumes" LOG = logging.getLogger(__name__) authorize = extensions.soft_extension_authorizer('compute', 'v3:' + ALIAS) authorize_attach = extensions.soft_extension_authorizer('compute', 'v3:%s:attach' % ALIAS) authorize_detach = extensions.soft_extension_authorizer('compute', 'v3:%s:detach' % ALIAS) class ExtendedVolumesController(wsgi.Controller): def __init__(self, *args, **kwargs): super(ExtendedVolumesController, self).__init__(*args, **kwargs) self.compute_api = compute.API() self.volume_api = volume.API() def _extend_server(self, context, server, instance): bdms = self.compute_api.get_instance_bdms(context, instance) volume_ids = [bdm['volume_id'] for bdm in bdms if bdm['volume_id']]
from webob import exc from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute from nova import db from nova import exception from nova import flags from nova import log as logging FLAGS = flags.FLAGS LOG = logging.getLogger("nova.api.openstack.compute.contrib." "extended_server_attributes") authorize = extensions.soft_extension_authorizer('compute', 'extended_server_attributes') class ExtendedServerAttributesController(wsgi.Controller): def __init__(self, *args, **kwargs): super(ExtendedServerAttributesController, self).__init__(*args, **kwargs) self.compute_api = compute.API() def _get_instances(self, context, instance_uuids): filters = {'uuid': instance_uuids} instances = self.compute_api.get_all(context, filters) return dict((instance['uuid'], instance) for instance in instances) def _get_hypervisor_hostname(self, context, instance): compute_node = db.compute_node_get_by_host(context, instance["host"])
# 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 """Logs actions performed on instances""" from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.db.api import instance_action_log_create import pprint ALIAS = 'OS-IAL' # Instance Action Log XMLNS_DCF = "http://docs.openstack.org/compute/ext/instance_action_log/api/v2.0" authorize = extensions.soft_extension_authorizer('compute', 'action_instance_log') class InstanceActionLogController(wsgi.Controller): def _do_log(self, req, resp_obj, action_name, id, extra=''): context = req.environ['nova.context'] user_name = req._headers.get('X-Auth-User') if user_name is None: # If this system is using noauth, the user name will actually be # in the auth-token, in the format: username:password token = req._headers.get('X-Auth-Token') if token is not None: user_name = token.split(':', 1)[0] # Don't want the password if not user_name: user_name = 'NOT-FOUND'
# 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 Volumes API extension.""" from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute from nova.objects import block_device as block_device_obj authorize = extensions.soft_extension_authorizer('compute', 'extended_volumes') class ExtendedVolumesController(wsgi.Controller): def __init__(self, *args, **kwargs): super(ExtendedVolumesController, self).__init__(*args, **kwargs) self.compute_api = compute.API() def _extend_server(self, context, server, instance): bdms = block_device_obj.BlockDeviceMappingList.get_by_instance_uuid( context, instance['uuid']) volume_ids = [bdm.volume_id for bdm in bdms if bdm.volume_id] key = "%s:volumes_attached" % Extended_volumes.alias server[key] = [{'id': volume_id} for volume_id in volume_ids] @wsgi.extends
from xml.dom import minidom from nova.api.openstack import common from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute from nova.compute import api as compute_api from nova import exception from nova.network.security_group import neutron_driver from nova.network.security_group import openstack_driver from nova.virt import netutils authorize = extensions.extension_authorizer("compute", "security_groups") softauth = extensions.soft_extension_authorizer("compute", "security_groups") def make_rule(elem): elem.set("id") elem.set("parent_group_id") proto = xmlutil.SubTemplateElement(elem, "ip_protocol") proto.text = "ip_protocol" from_port = xmlutil.SubTemplateElement(elem, "from_port") from_port.text = "from_port" to_port = xmlutil.SubTemplateElement(elem, "to_port") to_port.text = "to_port"
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from webob import exc from nova.api.openstack import common from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova import compute from nova.openstack.common.gettextutils import _ ALIAS = "os-server-actions" authorize_actions = extensions.extension_authorizer('compute', 'v3:' + ALIAS) authorize_events = extensions.soft_extension_authorizer('compute', 'v3:' + ALIAS + ':events') ACTION_KEYS = ['action', 'instance_uuid', 'request_id', 'user_id', 'project_id', 'start_time', 'message'] EVENT_KEYS = ['event', 'start_time', 'finish_time', 'result', 'traceback'] class ServerActionsController(wsgi.Controller): def __init__(self): super(ServerActionsController, self).__init__() self.compute_api = compute.API() self.action_api = compute.InstanceActionAPI() def _format_action(self, action_raw): action = {}
# from webob import exc from webob import Response from nova import compute from nova import exception from nova.api.openstack import extensions from nova.api.openstack import wsgi from oslo_log import log __author__ = 'Platform9' LOG = log.getLogger(__name__) ALIAS = "OS-EXT-PF9-discovery-task" authorize = extensions.soft_extension_authorizer('compute', 'discovery_task_pf9') class DiscoveryTaskPf9Controller(wsgi.Controller): def __init__(self, *args, **kwargs): super(DiscoveryTaskPf9Controller, self).__init__(*args, **kwargs) self.host_api = compute.HostAPI() @wsgi.action('discovery_task_state_pf9') def _discovery_task_state_pf9(self, req, id, body): """ Pf9 task to query the state of the discovery task Returns: {"running": True} if discovery is in progress {"running": False} if discovery is complete / not running """ context = req.environ['nova.context']
# 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. from webob import exc from nova.api.openstack import common from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute authorize_actions = extensions.extension_authorizer('compute', 'instance_actions') authorize_events = extensions.soft_extension_authorizer( 'compute', 'instance_actions:events') ACTION_KEYS = [ 'action', 'instance_uuid', 'request_id', 'user_id', 'project_id', 'start_time', 'message' ] EVENT_KEYS = ['event', 'start_time', 'finish_time', 'result', 'traceback'] def make_actions(elem): for key in ACTION_KEYS: elem.set(key) def make_action(elem): for key in ACTION_KEYS:
# 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. from webob import exc from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova import compute from nova import exception from nova.openstack.common.gettextutils import _ ALIAS = "os-instance-actions" authorize_actions = extensions.extension_authorizer('compute', 'v3:' + ALIAS) authorize_events = extensions.soft_extension_authorizer( 'compute', 'v3:' + ALIAS + ':events') ACTION_KEYS = [ 'action', 'instance_uuid', 'request_id', 'user_id', 'project_id', 'start_time', 'message' ] EVENT_KEYS = ['event', 'start_time', 'finish_time', 'result', 'traceback'] class InstanceActionsController(wsgi.Controller): def __init__(self): super(InstanceActionsController, self).__init__() self.compute_api = compute.API() self.action_api = compute.InstanceActionAPI() def _format_action(self, action_raw):
# 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 Volumes API extension.""" from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute authorize = extensions.soft_extension_authorizer('compute', 'extended_volumes') class ExtendedVolumesController(wsgi.Controller): def __init__(self, *args, **kwargs): super(ExtendedVolumesController, self).__init__(*args, **kwargs) self.compute_api = compute.API() def _extend_server(self, context, server, instance): bdms = self.compute_api.get_instance_bdms(context, instance) volume_ids = [bdm['volume_id'] for bdm in bdms if bdm['volume_id']] key = "%s:volumes_attached" % Extended_volumes.alias server[key] = [{'id': volume_id} for volume_id in volume_ids] @wsgi.extends def show(self, req, resp_obj, id):
"""Scope management extension.""" import traceback import webob import webob.exc from nova.api.openstack.compute import servers from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova.compute import api as compute_api from nova import exception from nova.openstack.common.gettextutils import _ authorize = extensions.extension_authorizer('compute', 'scopes') soft_authorize = extensions.soft_extension_authorizer('compute', 'scopes') class ScopeTemplate(xmlutil.TemplateBuilder): def construct(self): return xmlutil.MasterTemplate(xmlutil.make_flat_dict('scope'), 1) class ScopesTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('scopes') elem = xmlutil.make_flat_dict('scope', selector='scopes', subselector='scope') root.append(elem) return xmlutil.MasterTemplate(root, 1)
"""Keypair management extension.""" import webob import webob.exc from nova.api.openstack.compute import servers from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova.compute import api as compute_api from nova import exception from nova.openstack.common.gettextutils import _ authorize = extensions.extension_authorizer('compute', 'keypairs') soft_authorize = extensions.soft_extension_authorizer('compute', 'keypairs') class KeypairTemplate(xmlutil.TemplateBuilder): def construct(self): return xmlutil.MasterTemplate(xmlutil.make_flat_dict('keypair'), 1) class KeypairsTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('keypairs') elem = xmlutil.make_flat_dict('keypair', selector='keypairs', subselector='keypair') root.append(elem) return xmlutil.MasterTemplate(root, 1)
"""Attribute management extension.""" import traceback import webob import webob.exc from nova.api.openstack.compute import servers from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova.compute import api as compute_api from nova import exception from nova.openstack.common.gettextutils import _ authorize = extensions.extension_authorizer("compute", "attributes") soft_authorize = extensions.soft_extension_authorizer("compute", "attributes") class AttributeTemplate(xmlutil.TemplateBuilder): def construct(self): return xmlutil.MasterTemplate(xmlutil.make_flat_dict("attribute"), 1) class AttributesTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement("attributes") elem = xmlutil.make_flat_dict("attribute", selector="attributes", subselector="attribute") root.append(elem) return xmlutil.MasterTemplate(root, 1)
# under the License. """The flavor access extension.""" import webob from nova.api.openstack import common from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova import context as nova_context from nova import exception from nova.i18n import _ from nova import objects soft_authorize = extensions.soft_extension_authorizer('compute', 'flavor_access') authorize = extensions.extension_authorizer('compute', 'flavor_access') def _marshall_flavor_access(flavor): rval = [] for project_id in flavor.projects: rval.append({'flavor_id': flavor.flavorid, 'tenant_id': project_id}) return {'flavor_access': rval} class FlavorAccessController(object): """The flavor access API controller for the OpenStack API."""
# not use this file except in compliance with the License. You may obtain # 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. from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil authorize = extensions.soft_extension_authorizer('compute', 'image_size') def make_image(elem): elem.set('{%s}size' % Image_size.namespace, '%s:size' % Image_size.alias) class ImagesSizeTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('images') elem = xmlutil.SubTemplateElement(root, 'image', selector='images') make_image(elem) return xmlutil.SlaveTemplate( root, 1, nsmap={Image_size.alias: Image_size.namespace})
from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute from nova.compute import api as compute_api from nova import db from nova import exception from nova.network.security_group import openstack_driver from nova.network.security_group import quantum_driver from nova.openstack.common import log as logging from nova import utils from nova.virt import netutils LOG = logging.getLogger(__name__) authorize = extensions.extension_authorizer('compute', 'security_groups') softauth = extensions.soft_extension_authorizer('compute', 'security_groups') def make_rule(elem): elem.set('id') elem.set('parent_group_id') proto = xmlutil.SubTemplateElement(elem, 'ip_protocol') proto.text = 'ip_protocol' from_port = xmlutil.SubTemplateElement(elem, 'from_port') from_port.text = 'from_port' to_port = xmlutil.SubTemplateElement(elem, 'to_port') to_port.text = 'to_port'
# 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. from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova import network authorize = extensions.soft_extension_authorizer('compute', 'extended_vif_net') class ExtendedServerVIFNetController(wsgi.Controller): def __init__(self): super(ExtendedServerVIFNetController, self).__init__() self.network_api = network.API() @wsgi.extends def index(self, req, resp_obj, server_id): key = "%s:net_id" % Extended_virtual_interfaces_net.alias context = req.environ['nova.context'] if authorize(context): for vif in resp_obj.obj['virtual_interfaces']: vif1 = self.network_api.get_vif_by_mac_address(context, vif['mac_address'])
# # 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 nova.api.openstack import extensions from nova.api.openstack import wsgi from nova import availability_zones as avail_zone authorize = extensions.soft_extension_authorizer('compute', 'extended_availability_zone') class ExtendedAZController(wsgi.Controller): def _extend_server(self, context, server, instance): key = "{0!s}:availability_zone".format(Extended_availability_zone.alias) az = avail_zone.get_instance_availability_zone(context, instance) server[key] = az or '' @wsgi.extends def show(self, req, resp_obj, id): context = req.environ['nova.context'] if authorize(context): server = resp_obj.obj['server'] db_instance = req.get_db_instance(server['id']) self._extend_server(context, server, db_instance)
# under the License. """The Flavor extra data extension OpenStack API version 1.1 lists "name", "ram", "disk", "vcpus" as flavor attributes. This extension adds to that list: - OS-FLV-EXT-DATA:ephemeral """ from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil authorize = extensions.soft_extension_authorizer('compute', 'flavorextradata') class FlavorextradataController(wsgi.Controller): def _extend_flavors(self, req, flavors): for flavor in flavors: db_flavor = req.get_db_flavor(flavor['id']) key = "%s:ephemeral" % Flavorextradata.alias flavor[key] = db_flavor['ephemeral_gb'] def _show(self, req, resp_obj): if not authorize(req.environ['nova.context']): return if 'flavor' in resp_obj.obj: resp_obj.attach(xml=FlavorextradatumTemplate()) self._extend_flavors(req, [resp_obj.obj['flavor']])
# under the License. """The Extended Server Attributes API extension.""" from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute from nova import db from nova import flags from nova import log as logging FLAGS = flags.FLAGS LOG = logging.getLogger(__name__) authorize = extensions.soft_extension_authorizer('compute', 'extended_server_attributes') class ExtendedServerAttributesController(wsgi.Controller): def __init__(self, *args, **kwargs): super(ExtendedServerAttributesController, self).__init__(*args, **kwargs) self.compute_api = compute.API() def _get_hypervisor_hostname(self, context, instance): compute_node = db.compute_node_get_by_host(context, instance["host"]) try: return compute_node["hypervisor_hostname"] except TypeError: return
from webob import exc from nova.api.openstack.compute import servers from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import objects from nova.openstack.common import jsonutils from nova.openstack.common import log as logging LOG = logging.getLogger(__name__) authorize = extensions.soft_extension_authorizer('compute', 'numa') class ServerNumaOptsTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('server') root.set('numaOpts', 'numaOpts') root.set('evsOpts', 'evsOpts') return xmlutil.SlaveTemplate(root, 1) class ServersNumaOptsTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('servers') elem = xmlutil.SubTemplateElement(root, 'server', selector='servers') elem.set('numaOpts', 'numaOpts') elem.set('evsOpts', 'evsOpts') return xmlutil.SlaveTemplate(root, 1)
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova.openstack.common import log as logging from nova import quota LOG = logging.getLogger(__name__) QUOTAS = quota.QUOTAS XMLNS = "http://docs.openstack.org/compute/ext/used_limits/api/v1.1" ALIAS = "os-used-limits" authorize = extensions.soft_extension_authorizer('compute', 'used_limits') class UsedLimitsTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('limits', selector='limits') root.set('{%s}usedLimits' % XMLNS, '%s:usedLimits' % ALIAS) return xmlutil.SlaveTemplate(root, 1, nsmap={ALIAS: XMLNS}) class UsedLimitsController(wsgi.Controller): @staticmethod def _reserved(req): try: return int(req.GET['reserved']) except (ValueError, KeyError):
# 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. from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute from nova.openstack.common import log as logging LOG = logging.getLogger(__name__) authorize = extensions.soft_extension_authorizer('compute', 'server_usage') class ServerUsageController(wsgi.Controller): def __init__(self, *args, **kwargs): super(ServerUsageController, self).__init__(*args, **kwargs) self.compute_api = compute.API() def _extend_server(self, server, instance): for k in ['launched_at', 'terminated_at']: key = "%s:%s" % (Server_usage.alias, k) # NOTE(danms): Historically, this timestamp has been generated # merely by grabbing str(datetime) of a TZ-naive object. The # only way we can keep that with instance objects is to strip # the tzinfo from the stamp and str() it. server[key] = (instance[k].replace(
# 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 Disabled API extension.""" from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil authorize = extensions.soft_extension_authorizer('compute', 'flavor_disabled') class FlavorDisabledController(wsgi.Controller): def _extend_flavors(self, req, flavors): for flavor in flavors: db_flavor = req.get_db_flavor(flavor['id']) key = "%s:disabled" % Flavor_disabled.alias flavor[key] = db_flavor['disabled'] def _show(self, req, resp_obj): if not authorize(req.environ['nova.context']): return if 'flavor' in resp_obj.obj: resp_obj.attach(xml=FlavorDisabledTemplate()) self._extend_flavors(req, [resp_obj.obj['flavor']])
# 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. from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import network authorize = extensions.soft_extension_authorizer('compute', 'extended_vif_net') def make_vif(elem): elem.set('{%s}net_id' % Extended_virtual_interfaces_net.namespace, '%s:net_id' % Extended_virtual_interfaces_net.alias) class ExtendedVirtualInterfaceNetTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('virtual_interfaces', selector='virtual_interfaces') elem = xmlutil.SubTemplateElement(root, 'virtual_interface', selector='virtual_interfaces') make_vif(elem)
# Copyright 2013 IBM Corp. """The Extended Server Attributes API extension.""" from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil authorize = extensions.soft_extension_authorizer('compute', 'extended_powervm') class ExtendedPowerVMAttributesController(wsgi.Controller): def gen_pvc_key(self, key): self.LOCAL_PVC_PREFIX = 'powervm:' if key is None: return key if key.startswith(self.LOCAL_PVC_PREFIX): return key return self.LOCAL_PVC_PREFIX + key def _extend_server(self, context, server, instance): metadata = instance['metadata'] pvc_attrs = ['cpus', 'min_cpus', 'max_cpus', 'cpu_utilization', 'min_vcpus', 'max_vcpus', 'min_memory_mb', 'max_memory_mb', 'root_gb'] key = "%s:id" % (Extended_powervm.alias) if 'pvc_id' in metadata:
from webob import exc from nova.api.openstack import common from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute from nova import exception from nova.openstack.common.gettextutils import _ from nova.openstack.common import log as logging from nova.openstack.common import uuidutils from nova import volume ALIAS = "os-extended-volumes" LOG = logging.getLogger(__name__) authorize = extensions.soft_extension_authorizer('compute', 'v3:' + ALIAS) authorize_attach = extensions.soft_extension_authorizer( 'compute', 'v3:%s:attach' % ALIAS) authorize_detach = extensions.soft_extension_authorizer( 'compute', 'v3:%s:detach' % ALIAS) class ExtendedVolumesController(wsgi.Controller): def __init__(self, *args, **kwargs): super(ExtendedVolumesController, self).__init__(*args, **kwargs) self.compute_api = compute.API() self.volume_api = volume.API() def _extend_server(self, context, server, instance): bdms = self.compute_api.get_instance_bdms(context, instance) volume_ids = [bdm['volume_id'] for bdm in bdms if bdm['volume_id']]
# # Copyright (c) 2015, Platform 9 Systems. All rights reserved. # from nova.api.openstack import extensions from nova.api.openstack import wsgi from oslo_log import log as logging __author__ = 'Platform9' """"The extended flavors attributes API extension.""" authorize = extensions.soft_extension_authorizer( 'compute', 'extended_flavor_attributes_pf9') LOG = logging.getLogger(__name__) class ExtendedFlavorAttribPf9Controller(wsgi.Controller): def _extend_flavor(self, context, flavor, instance): key = "%s:extra_specs" % Extended_flavor_attributes_pf9.alias if 'extra_specs' not in instance.keys(): flavor[key] = {} else: flavor[key] = instance['extra_specs'] @wsgi.extends def detail(self, req, resp_obj): context = req.environ['nova.context'] if authorize(context): resp_obj.attach(xml=ExtendedFlavorAttribPf9Template()) flavors = list(resp_obj.obj['flavors'])
# under the License from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova.openstack.common import log as logging from nova import quota LOG = logging.getLogger(__name__) QUOTAS = quota.QUOTAS XMLNS = "http://docs.openstack.org/compute/ext/used_limits/api/v1.1" ALIAS = "os-used-limits" authorize = extensions.soft_extension_authorizer('compute', 'used_limits') class UsedLimitsTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('limits', selector='limits') root.set('{%s}usedLimits' % XMLNS, '%s:usedLimits' % ALIAS) return xmlutil.SlaveTemplate(root, 1, nsmap={ALIAS: XMLNS}) class UsedLimitsController(wsgi.Controller): @wsgi.extends def index(self, req, resp_obj): resp_obj.attach(xml=UsedLimitsTemplate()) context = req.environ['nova.context']
# 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. from webob import exc from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute from nova import exception authorize_actions = extensions.extension_authorizer('compute', 'instance_actions') authorize_events = extensions.soft_extension_authorizer('compute', 'instance_actions:events') ACTION_KEYS = ['action', 'instance_uuid', 'request_id', 'user_id', 'project_id', 'start_time', 'message'] EVENT_KEYS = ['event', 'start_time', 'finish_time', 'result', 'traceback'] def make_actions(elem): for key in ACTION_KEYS: elem.set(key) def make_action(elem): for key in ACTION_KEYS: elem.set(key) event = xmlutil.TemplateElement('events', selector='events')
# License for the specific language governing permissions and limitations # under the License. """Keypair management extension.""" import webob import webob.exc from nova.api.openstack.compute import servers from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.compute import api as compute_api from nova import exception from nova.i18n import _ authorize = extensions.extension_authorizer('compute', 'keypairs') soft_authorize = extensions.soft_extension_authorizer('compute', 'keypairs') class KeypairController(object): """Keypair API controller for the OpenStack API.""" def __init__(self): self.api = compute_api.KeypairAPI() def _filter_keypair(self, keypair, **attrs): clean = { 'name': keypair.name, 'public_key': keypair.public_key, 'fingerprint': keypair.fingerprint, } for attr in attrs: clean[attr] = keypair[attr]
# # 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 Disabled API extension.""" from nova.api.openstack import extensions from nova.api.openstack import wsgi authorize = extensions.soft_extension_authorizer('compute', 'flavor_disabled') class FlavorDisabledController(wsgi.Controller): def _extend_flavors(self, req, flavors): for flavor in flavors: db_flavor = req.get_db_flavor(flavor['id']) key = "%s:disabled" % Flavor_disabled.alias flavor[key] = db_flavor['disabled'] def _show(self, req, resp_obj): if not authorize(req.environ['nova.context']): return if 'flavor' in resp_obj.obj: self._extend_flavors(req, [resp_obj.obj['flavor']])
# 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 from nova.api.openstack.compute import servers from nova.api.openstack.compute import views from nova.api.openstack import extensions authorize = extensions.soft_extension_authorizer("compute", "createserverext") class ViewBuilder(views.servers.ViewBuilder): """Adds security group output when viewing server details.""" def show(self, request, instance): """Detailed view of a single instance.""" server = super(ViewBuilder, self).show(request, instance) context = request.environ["nova.context"] if authorize(context): server["server"]["security_groups"] = self._get_groups(instance) return server def _get_groups(self, instance): """Get a list of security groups for this instance."""
# under the License """Disk Config extension.""" from webob import exc from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import db from nova import utils ALIAS = 'OS-DCF' XMLNS_DCF = "http://docs.openstack.org/compute/ext/disk_config/api/v1.1" API_DISK_CONFIG = "%s:diskConfig" % ALIAS INTERNAL_DISK_CONFIG = "auto_disk_config" authorize = extensions.soft_extension_authorizer('compute', 'disk_config') def disk_config_to_api(value): return 'AUTO' if value else 'MANUAL' def disk_config_from_api(value): if value == 'AUTO': return True elif value == 'MANUAL': return False else: msg = _("%s must be either 'MANUAL' or 'AUTO'." % API_DISK_CONFIG) raise exc.HTTPBadRequest(explanation=msg)
# 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. from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.openstack.common import jsonutils ALIAS = 'os-pci' instance_authorize = extensions.soft_extension_authorizer( 'compute', 'v3:' + ALIAS + ':pci_servers') 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 @wsgi.extends def show(self, req, resp_obj, id): context = req.environ['nova.context'] if instance_authorize(context): server = resp_obj.obj['server'] instance = req.get_db_instance(server['id'])
# 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 nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil authorize = extensions.soft_extension_authorizer('compute', 'flavor_rxtx') 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['nova.context']): return if 'flavor' in resp_obj.obj: resp_obj.attach(xml=FlavorRxtxTemplate()) self._extend_flavors(req, [resp_obj.obj['flavor']])
# 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 nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil authorize = extensions.soft_extension_authorizer('compute', 'flavor_rxtx') 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['nova.context']): return if 'flavor' in resp_obj.obj: resp_obj.attach(xml=FlavorRxtxTemplate()) self._extend_flavors(req, [resp_obj.obj['flavor']])
# # 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 nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import availability_zones as avail_zone authorize = extensions.soft_extension_authorizer('compute', 'extended_availability_zone') class ExtendedAZController(wsgi.Controller): def _extend_server(self, context, server, instance): key = "%s:availability_zone" % Extended_availability_zone.alias 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 def show(self, req, resp_obj, id):
# # Copyright (c) 2014, Platform9 Systems, All rights reserved # __author__ = 'Platform9' import webob from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import network from nova import exception from nova.openstack.common.gettextutils import _ authorize = extensions.soft_extension_authorizer('compute', 'network_access_pf9') def make_network_access_pf9(elem): elem.set('{%s}access' % Network_access_pf9.namespace) elem.set('%s:access' % Network_access_pf9.alias) class NetworkAccessTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('network', selector='network') make_network_access_pf9(root) alias = Network_access_pf9.alias namespace = Network_access_pf9.namespace return xmlutil.MasterTemplate(root, 1, nsmap={alias: namespace}) class NetworkAccessesTemplate(xmlutil.TemplateBuilder): def construct(self):
# # 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 Ips API extension.""" import itertools from nova.api.openstack import common from nova.api.openstack import extensions from nova.api.openstack import wsgi authorize = extensions.soft_extension_authorizer('compute', 'extended_ips_mac') class ExtendedIpsMacController(wsgi.Controller): def __init__(self, *args, **kwargs): super(ExtendedIpsMacController, self).__init__(*args, **kwargs) def _extend_server(self, context, server, instance): key = "%s:mac_addr" % Extended_ips_mac.alias networks = common.get_networks_for_instance(context, instance) for label, network in networks.items(): # NOTE(vish): ips are hidden in some states via the # hide_server_addresses extension. if label in server['addresses']: all_ips = itertools.chain(network["ips"], network["floating_ips"])
# under the License. """Extension for hiding server addresses in certain states.""" from oslo.config import cfg from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.compute import vm_states CONF = cfg.CONF CONF.import_opt('osapi_hide_server_address_states', 'nova.api.openstack.compute.plugins.v3.hide_server_addresses') authorize = extensions.soft_extension_authorizer('compute', 'hide_server_addresses') class Controller(wsgi.Controller): def __init__(self, *args, **kwargs): super(Controller, self).__init__(*args, **kwargs) hidden_states = CONF.osapi_hide_server_address_states # NOTE(jkoelker) _ is not considered uppercase ;) valid_vm_states = [getattr(vm_states, state) for state in dir(vm_states) if state.isupper()] self.hide_address_states = [state.lower() for state in hidden_states if state in valid_vm_states]
# under the License. """The Extended Status Admin API extension.""" from webob import exc from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute from nova import exception from nova import flags from nova import log as logging FLAGS = flags.FLAGS LOG = logging.getLogger("nova.api.openstack.compute.contrib.extendedstatus") authorize = extensions.soft_extension_authorizer('compute', 'extended_status') class ExtendedStatusController(wsgi.Controller): def __init__(self, *args, **kwargs): super(ExtendedStatusController, self).__init__(*args, **kwargs) self.compute_api = compute.API() def _get_and_extend_one(self, context, server_id, body): try: inst_ref = self.compute_api.routing_get(context, server_id) except exception.NotFound: LOG.warn("Instance %s not found" % server_id) raise for state in ['task_state', 'vm_state', 'power_state']:
# # 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. """Config Drive extension.""" from nova.api.openstack.compute.legacy_v2 import servers from nova.api.openstack import extensions from nova.api.openstack import wsgi authorize = extensions.soft_extension_authorizer('compute', 'config_drive') class Controller(servers.Controller): def _add_config_drive(self, req, servers): for server in servers: db_server = req.get_db_instance(server['id']) # server['id'] is guaranteed to be in the cache due to # the core API adding it in its 'show'/'detail' methods. server['config_drive'] = db_server['config_drive'] def _show(self, req, resp_obj): if 'server' in resp_obj.obj: server = resp_obj.obj['server'] self._add_config_drive(req, [server])
# 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. """Config Drive extension.""" from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil ALIAS = "os-config-drive" authorize = extensions.soft_extension_authorizer("compute", "v3:" + ALIAS) class ServerConfigDriveTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement("server") root.set("config_drive", "config_drive") return xmlutil.SlaveTemplate(root, 1) class ServersConfigDriveTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement("servers") elem = xmlutil.SubTemplateElement(root, "server", selector="servers") elem.set("config_drive", "config_drive") return xmlutil.SlaveTemplate(root, 1)
from nova.api.openstack import common from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute from nova.compute import api as compute_api from nova import exception from nova.network.security_group import neutron_driver from nova.network.security_group import openstack_driver from nova.openstack.common.gettextutils import _ from nova.openstack.common import xmlutils from nova.virt import netutils authorize = extensions.extension_authorizer('compute', 'security_groups') softauth = extensions.soft_extension_authorizer('compute', 'security_groups') def make_rule(elem): elem.set('id') elem.set('parent_group_id') proto = xmlutil.SubTemplateElement(elem, 'ip_protocol') proto.text = 'ip_protocol' from_port = xmlutil.SubTemplateElement(elem, 'from_port') from_port.text = 'from_port' to_port = xmlutil.SubTemplateElement(elem, 'to_port') to_port.text = 'to_port'
# # Copyright (c) 2014, Platform 9 Systems. All rights reserved. # __author__ = 'Platform9' """"The extended hypervisor resource information API extension.""" from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil import nova.virt.resource_types as res_types import logging authorize = extensions.soft_extension_authorizer( 'compute', 'extended_hypervisor_resinfo') db_to_api_map = { res_types.CPU: 'cpu_util_percent', res_types.MEMORY: 'mem_used_percent', res_types.DISK_USED: 'disk_used_gb', res_types.DISK_TOTAL: 'disk_total_gb', res_types.NETWORK_SEND_RATE: 'net_sent_mibps', res_types.NETWORK_RECV_RATE: 'net_recvd_mibps', res_types.NETWORK_SENT_PKTS: 'net_sent_pkts_k', res_types.NETWORK_RECV_PKTS: 'net_recvd_pkts_k' } LOG = logging.getLogger(__name__) class ExtendedHypervisorResInfoController(wsgi.Controller): def _extend_hypervisor(self, context, hypervisor, instance):
from webob import exc from nova.api.openstack import common from nova.api.openstack.compute.schemas.v3 import extended_volumes from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api import validation from nova import compute from nova import exception from nova.openstack.common.gettextutils import _ from nova.openstack.common import log as logging from nova import volume ALIAS = "os-extended-volumes" LOG = logging.getLogger(__name__) authorize = extensions.soft_extension_authorizer('compute', 'v3:' + ALIAS) authorize_attach = extensions.extension_authorizer('compute', 'v3:%s:attach' % ALIAS) authorize_detach = extensions.extension_authorizer('compute', 'v3:%s:detach' % ALIAS) authorize_swap = extensions.extension_authorizer('compute', 'v3:%s:swap' % ALIAS) class ExtendedVolumesController(wsgi.Controller): def __init__(self, *args, **kwargs): super(ExtendedVolumesController, self).__init__(*args, **kwargs) self.compute_api = compute.API() self.volume_api = volume.API() def _extend_server(self, context, server, instance):
# # 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. """Config Drive extension""" from nova.api.openstack.compute import servers from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil authorize = extensions.soft_extension_authorizer('compute', 'config_drive') class ServerConfigDriveTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('server') root.set('config_drive', 'config_drive') return xmlutil.SlaveTemplate(root, 1) class ServersConfigDriveTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('servers') elem = xmlutil.SubTemplateElement(root, 'server', selector='servers') elem.set('config_drive', 'config_drive') return xmlutil.SlaveTemplate(root, 1)