Skip to content

Instantly share code, notes, and snippets.

@stajkowski
Last active November 30, 2016 20:47
Show Gist options
  • Save stajkowski/3ecc734e649b71215913f29c19f040ec to your computer and use it in GitHub Desktop.
Save stajkowski/3ecc734e649b71215913f29c19f040ec to your computer and use it in GitHub Desktop.
bindings extension
# Copyright (c) 2012 OpenStack Foundation.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# 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 neutron_lib import constants
from neutron_lib.plugins import directory
from neutron.api import extensions
from neutron.api.v2 import attributes as attr
from neutron.api.v2 import base
BINDINGS = 'bindings'
RESOURCE_NAME = 'binding'
VNIC_NORMAL = 'normal'
VNIC_DIRECT = 'direct'
VNIC_MACVTAP = 'macvtap'
VNIC_BAREMETAL = 'baremetal'
VNIC_DIRECT_PHYSICAL = 'direct-physical'
VNIC_TYPES = [VNIC_NORMAL, VNIC_DIRECT, VNIC_MACVTAP, VNIC_BAREMETAL,
VNIC_DIRECT_PHYSICAL]
RESOURCE_ATTRIBUTE_MAP = {
'bindings': {
'host_id': {'allow_post': True, 'allow_put': True,
'default': constants.ATTR_NOT_SPECIFIED,
'is_visible': True, 'primary_key': True,
'required_by_policy': True},
'vif_type': {'allow_post': True, 'allow_put': True,
'default': constants.ATTR_NOT_SPECIFIED,
'enforce_policy': True,
'is_visible': True},
'vif_details': {'allow_post': True, 'allow_put': True,
'default': constants.ATTR_NOT_SPECIFIED,
'enforce_policy': True,
'is_visible': True},
'vnic_type': {'allow_post': True, 'allow_put': True,
'default': VNIC_NORMAL,
'is_visible': True,
'validate': {'type:values': VNIC_TYPES},
'enforce_policy': True},
'profile': {'allow_post': True, 'allow_put': True,
'default': constants.ATTR_NOT_SPECIFIED,
'enforce_policy': True,
'validate': {'type:dict_or_none': None},
'is_visible': True},
}
}
class Portbindings_extended(extensions.ExtensionDescriptor):
"""Extension class supporting port bindings.
This class is used by neutron's extension framework to make
metadata about the port bindings available to external applications.
With admin rights one will be able to update and read the values.
"""
@classmethod
def get_name(cls):
return "Port Bindings"
@classmethod
def get_alias(cls):
return "bindings_extended"
@classmethod
def get_description(cls):
return "Expose port bindings of a virtual port to external application"
@classmethod
def get_updated(cls):
return "2016-11-30T10:00:00-00:00"
@classmethod
def get_resources(cls):
"""Returns Ext Resources."""
my_plurals = [(key, key[:-1]) for key in RESOURCE_ATTRIBUTE_MAP.keys()]
attr.PLURALS.update(dict(my_plurals))
plugin = directory.get_plugin()
parent = {'collection_name': 'ports', 'member_name': 'port'}
params = RESOURCE_ATTRIBUTE_MAP.get(BINDINGS)
controller = base.create_resource(BINDINGS,
RESOURCE_NAME, plugin, params,
parent=parent,
allow_pagination=True,
allow_sorting=True)
ex = extensions.ResourceExtension(BINDINGS, controller, parent,
attr_map=params)
return [ex]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment