DB models

This commit is contained in:
Ofer Ben-Yacov 2017-01-04 11:08:30 +02:00
parent 9fcdf7db82
commit 41f73e2327
8 changed files with 118 additions and 24 deletions

View File

@ -2,7 +2,7 @@
# Show debugging output in log (sets DEBUG log level output) # Show debugging output in log (sets DEBUG log level output)
# debug = False # debug = False
[WANQOS] [WANTC]
lan_port_name = 'enp1s0f0' lan_port_name = 'enp1s0f0'
lan_max_rate = '100mbit' lan_max_rate = '100mbit'
wan_port_name = 'enp1s0f1' wan_port_name = 'enp1s0f1'

View File

@ -13,6 +13,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
WANQOS = 'WANQOS' WANTC = 'WANTC'
WAN_QOS = 'wan_tc' WAN_TC = 'wan_tc'
WAN_QOS_PATH = 'wan-tcs' WAN_TC_PATH = 'wan-tcs'

View File

View File

@ -0,0 +1,48 @@
# Copyright 2016 Huawei corp.
# 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.db import model_base
import sqlalchemy as sa
class WanTcClass(model_base.BASEV2,
model_base.HasId, model_base.HasProject):
__tablename__ = 'wan_tc_class'
class_ext_id = sa.Column(sa.Integer)
parent_class = sa.Column(sa.String(36),
sa.ForeignKey('wan_tc_class.id',
ondelete='CASCADE'),
nullable=True)
network_id = sa.Column(sa.String(36),
sa.ForeignKey('networks.id',
ondelete='CASCADE'),
nullable=False,
unique=True,
primary_key=True)
min_rate = sa.Column(sa.String(15), nullable=False)
max_rate = sa.Column(sa.String(15))
class WanTcSelector(model_base.BASEV2,
model_base.HasId, model_base.HasProject):
__tablename__ = 'wan_tc_selector'
class_id = sa.Column(sa.String(36),
sa.ForeignKey('wan_tc_class.id',
ondelete='CASCADE'),
nullable=False,
primary_key=True)
protocol = sa.Column(sa.String(15))
match = sa.Column(sa.String(15))

24
wan_qos/db/wan_qos_db.py Normal file
View File

@ -0,0 +1,24 @@
# Copyright 2016 Huawei corp.
# 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 oslo_utils import uuidutils
from wan_qos.db.models import wan_tc as model
from wan_qos.common import constants
class WanTcDb():
def create_wan_tc_class(self, context, wan_qos_class):
pass

View File

@ -21,7 +21,7 @@ from neutron.api.v2 import resource_helper
from wan_qos.common import constants from wan_qos.common import constants
RESOURCE_ATTRIBUTE_MAP = { RESOURCE_ATTRIBUTE_MAP = {
constants.WAN_QOS_PATH: { constants.WAN_TC_PATH: {
'id': {'allow_post': False, 'allow_put': False, 'id': {'allow_post': False, 'allow_put': False,
'is_visible': True}, 'is_visible': True},
'max_rate': {'allow_post': True, 'allow_put': False, 'max_rate': {'allow_post': True, 'allow_put': False,
@ -45,7 +45,7 @@ class Wanqos(extensions.ExtensionDescriptor):
@classmethod @classmethod
def get_name(cls): def get_name(cls):
return "WAN QoS" return "WAN Traffic Control"
@classmethod @classmethod
def get_alias(cls): def get_alias(cls):
@ -68,7 +68,7 @@ class Wanqos(extensions.ExtensionDescriptor):
{}, RESOURCE_ATTRIBUTE_MAP) {}, RESOURCE_ATTRIBUTE_MAP)
resources = resource_helper.build_resource_info(plural_mappings, resources = resource_helper.build_resource_info(plural_mappings,
RESOURCE_ATTRIBUTE_MAP, RESOURCE_ATTRIBUTE_MAP,
constants.WANQOS, constants.WANTC,
action_map=mem_actions, action_map=mem_actions,
register_quota=True, register_quota=True,
translate_name=True) translate_name=True)

View File

@ -15,10 +15,12 @@
from neutron.common import rpc as n_rpc from neutron.common import rpc as n_rpc
from neutron.db import agents_db from neutron.db import agents_db
from neutron_lib import exceptions
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from oslo_utils import importutils from oslo_utils import importutils
import oslo_messaging as messaging import oslo_messaging as messaging
from wan_qos.common import api from wan_qos.common import api
@ -60,7 +62,7 @@ class WanQosPlugin(wanqos.WanQosPluginBase):
def get_plugin_type(self): def get_plugin_type(self):
"""Get type of the plugin.""" """Get type of the plugin."""
return constants.WANQOS return constants.WANTC
def get_plugin_description(self): def get_plugin_description(self):
"""Get description of the plugin.""" """Get description of the plugin."""
@ -84,6 +86,26 @@ class WanQosPlugin(wanqos.WanQosPluginBase):
pass pass
# self.agent_rpc.create_wan_qos(context, wan_qos) # self.agent_rpc.create_wan_qos(context, wan_qos)
def agent_up_notification(self, host): tenant_id = self._get_tenant_id_for_create(context, wan_qos_class)
@staticmethod
def _get_tenant_id_for_create(self, context, resource):
"""Get tenant id for creation of resources."""
if context.is_admin and 'tenant_id' in resource:
tenant_id = resource['tenant_id']
elif ('tenant_id' in resource and
resource['tenant_id'] != context.tenant_id):
reason = 'Cannot create resource for another tenant'
raise exceptions.AdminRequired(reason=reason)
else:
tenant_id = context.tenant_id
return tenant_id
def agent_up_notification(self, host):
LOG.debug('agent %s is up' % host) LOG.debug('agent %s is up' % host)
return 'OK' return 'OK'

View File

@ -19,35 +19,35 @@ from wan_qos.common import constants
def args2body(self, parsed_args): def args2body(self, parsed_args):
body = {'wan_tc': {}, } body = {constants.WAN_TC: {}, }
return body return body
class WanQos(extension.NeutronClientExtension): class WanTc(extension.NeutronClientExtension):
resource = constants.WAN_QOS resource = constants.WAN_TC
resource_plural = '%ss' % constants.WAN_QOS resource_plural = '%ss' % constants.WAN_TC
path = constants.WAN_QOS_PATH path = constants.WAN_TC_PATH
object_path = '/%s' % path object_path = '/%s' % path
resource_path = '/%s/%%s' % path resource_path = '/%s/%%s' % path
versions = ['2.0'] versions = ['2.0']
class WanQosShow(extension.ClientExtensionShow, WanQos): class WanTcShow(extension.ClientExtensionShow, WanTc):
shell_command = 'wan-qos-show' shell_command = 'wan-tc-show'
class WanQosList(extension.ClientExtensionList, WanQos): class WanTcList(extension.ClientExtensionList, WanTc):
shell_command = 'wan-qos-list' shell_command = 'wan-tc-list'
list_columns = ['id', 'name', 'network'] list_columns = ['id', 'name', 'network']
pagination_support = True pagination_support = True
sorting_support = True sorting_support = True
class WanQosCreate(extension.ClientExtensionCreate, WanQos): class WanTcCreate(extension.ClientExtensionCreate, WanTc):
shell_command = 'wan-qos-create' shell_command = 'wan-tc-create'
def add_known_arguments(self, parser): def add_known_arguments(self, parser):
pass pass
@ -59,14 +59,14 @@ class WanQosCreate(extension.ClientExtensionCreate, WanQos):
return body return body
class WanQosDelete(extension.ClientExtensionDelete, WanQos): class WanTcDelete(extension.ClientExtensionDelete, WanTc):
shell_command = 'wan-qos-delete' shell_command = 'wan-tc-delete'
class WanQosUpdate(extension.ClientExtensionUpdate, WanQos): class WanTcUpdate(extension.ClientExtensionUpdate, WanTc):
shell_command = 'wan-qos-update' shell_command = 'wan-tc-update'
def add_known_arguments(self, parser): def add_known_arguments(self, parser):
pass pass