Add TC Device
This commit is contained in:
parent
4332f7eb76
commit
ec91e081f9
@ -34,3 +34,4 @@ neutron.db.alembic_migrations =
|
|||||||
wan-qos = wan_qos.db.migration:alembic_migrations
|
wan-qos = wan_qos.db.migration:alembic_migrations
|
||||||
neutronclient.extension =
|
neutronclient.extension =
|
||||||
wan_qos = wan_qos.wanqos_client._wanqos
|
wan_qos = wan_qos.wanqos_client._wanqos
|
||||||
|
wan_tc_device = wan_qos.wanqos_client._wantcdevice
|
||||||
|
@ -15,4 +15,7 @@
|
|||||||
|
|
||||||
WANTC = 'WANTC'
|
WANTC = 'WANTC'
|
||||||
WAN_TC = 'wan_tc'
|
WAN_TC = 'wan_tc'
|
||||||
WAN_TC_PATH = 'wan-tcs'
|
WAN_TC_PATH = 'wan-tcs'
|
||||||
|
|
||||||
|
WAN_TC_DEVICE = 'wan_tc_device'
|
||||||
|
WAN_TC_DEVICE_PATH = 'wan-tc-devices'
|
@ -32,19 +32,24 @@ import sqlalchemy as sa
|
|||||||
def upgrade():
|
def upgrade():
|
||||||
op.create_table('wan_tc_class',
|
op.create_table('wan_tc_class',
|
||||||
sa.Column('id', sa.String(length=36), nullable=False),
|
sa.Column('id', sa.String(length=36), nullable=False),
|
||||||
sa.Column('networks_id', sa.String(length=36),
|
sa.Column('parent_class', sa.String(length=36), nullable=False),
|
||||||
|
sa.Column('device_id', sa.String(length=36),
|
||||||
|
nullable=False),
|
||||||
|
sa.Column('project_id', sa.String(length=36),
|
||||||
|
nullable=False),
|
||||||
|
sa.Column('network_id', sa.String(length=36),
|
||||||
nullable=False),
|
nullable=False),
|
||||||
sa.Column('class_ext_id', sa.Integer()),
|
sa.Column('class_ext_id', sa.Integer()),
|
||||||
sa.Column('min_rate',
|
sa.Column('min_rate',
|
||||||
sa.String(length=15), nullable=False),
|
sa.String(length=15), nullable=False),
|
||||||
sa.Column('min_rate', sa.String(length=15)),
|
sa.Column('max_rate', sa.String(length=15)),
|
||||||
sa.PrimaryKeyConstraint('id')
|
sa.PrimaryKeyConstraint('id')
|
||||||
)
|
)
|
||||||
|
|
||||||
op.create_foreign_key(
|
op.create_foreign_key(
|
||||||
'fk_wan_tc_class_networks',
|
'fk_wan_tc_class_networks',
|
||||||
'wan_tc_class', 'networks',
|
'wan_tc_class', 'networks',
|
||||||
['networks_id'], ['id'],
|
['network_id'], ['id'],
|
||||||
)
|
)
|
||||||
|
|
||||||
op.create_table('wan_tc_selector',
|
op.create_table('wan_tc_selector',
|
||||||
|
@ -32,12 +32,14 @@ class WanTcDb(object):
|
|||||||
with context.session.begin(subtransactions=True):
|
with context.session.begin(subtransactions=True):
|
||||||
if not device:
|
if not device:
|
||||||
LOG.debug('New device connected: %s' % host_info)
|
LOG.debug('New device connected: %s' % host_info)
|
||||||
|
now = timeutils.utcnow()
|
||||||
wan_tc_device = models.WanTcDevice(
|
wan_tc_device = models.WanTcDevice(
|
||||||
id=uuidutils.generate_uuid(),
|
id=uuidutils.generate_uuid(),
|
||||||
host=host_info['host'],
|
host=host_info['host'],
|
||||||
lan_port=host_info['lan_port'],
|
lan_port=host_info['lan_port'],
|
||||||
wan_port=host_info['wan_port'],
|
wan_port=host_info['wan_port'],
|
||||||
uptime=timeutils.utcnow()
|
uptime=now,
|
||||||
|
heartbeat_timestamp=now
|
||||||
)
|
)
|
||||||
context.session.add(wan_tc_device)
|
context.session.add(wan_tc_device)
|
||||||
else:
|
else:
|
||||||
@ -70,11 +72,29 @@ class WanTcDb(object):
|
|||||||
|
|
||||||
def _device_to_dict(self, device):
|
def _device_to_dict(self, device):
|
||||||
device_dict = {
|
device_dict = {
|
||||||
|
'id': device.id,
|
||||||
'host': device.host,
|
'host': device.host,
|
||||||
'lan_port': device.lan_port,
|
'lan_port': device.lan_port,
|
||||||
'wan_port': device.wan_port,
|
'wan_port': device.wan_port,
|
||||||
'uptime': device.uptime,
|
'uptime': device.uptime,
|
||||||
'heartbeat': device.heartbeat
|
'last_seen': device.heartbeat_timestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
return device_dict
|
return device_dict
|
||||||
|
|
||||||
|
def delete_wan_tc_device(self, context, id):
|
||||||
|
device = context.session.query(models.WanTcDevice).filter_by(
|
||||||
|
id=id
|
||||||
|
).first()
|
||||||
|
if device:
|
||||||
|
with context.session.begin(subtransactions=True):
|
||||||
|
context.session.delete(device)
|
||||||
|
else:
|
||||||
|
LOG.error('Trying to delete none existing device. id=%s' % id)
|
||||||
|
|
||||||
|
def get_device(self, context, id):
|
||||||
|
device = context.session.query(models.WanTcDevice).filter_by(
|
||||||
|
id=id
|
||||||
|
).first()
|
||||||
|
if device:
|
||||||
|
return self._device_to_dict(device)
|
||||||
|
@ -33,7 +33,7 @@ RESOURCE_ATTRIBUTE_MAP = {
|
|||||||
'network_id': {'allow_post': True, 'allow_put': False,
|
'network_id': {'allow_post': True, 'allow_put': False,
|
||||||
'validate': {'type:string': None},
|
'validate': {'type:string': None},
|
||||||
'is_visible': True},
|
'is_visible': True},
|
||||||
'tenant_id': {'allow_post': True, 'allow_put': False,
|
'project_id': {'allow_post': True, 'allow_put': False,
|
||||||
'validate': {'type:string': None},
|
'validate': {'type:string': None},
|
||||||
'required_by_policy': True,
|
'required_by_policy': True,
|
||||||
'is_visible': True}
|
'is_visible': True}
|
||||||
|
99
wan_qos/extensions/wantcdevice.py
Normal file
99
wan_qos/extensions/wantcdevice.py
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
import abc
|
||||||
|
|
||||||
|
from neutron_lib.api import extensions
|
||||||
|
from neutron.api.v2 import resource_helper
|
||||||
|
|
||||||
|
from wan_qos.common import constants
|
||||||
|
|
||||||
|
RESOURCE_ATTRIBUTE_MAP = {
|
||||||
|
constants.WAN_TC_DEVICE_PATH: {
|
||||||
|
'id': {'allow_post': False, 'allow_put': False,
|
||||||
|
'is_visible': True},
|
||||||
|
'host': {'allow_post': True, 'allow_put': False,
|
||||||
|
'validate': {'type:string': None},
|
||||||
|
'is_visible': True, 'default': ''},
|
||||||
|
'lan_port': {'allow_post': True, 'allow_put': False,
|
||||||
|
'validate': {'type:string': None},
|
||||||
|
'is_visible': True, 'default': ''},
|
||||||
|
'wan_port': {'allow_post': True, 'allow_put': False,
|
||||||
|
'validate': {'type:string': None},
|
||||||
|
'is_visible': True},
|
||||||
|
'uptime': {'allow_post': True, 'allow_put': False,
|
||||||
|
'validate': {'type:string': None},
|
||||||
|
'is_visible': True},
|
||||||
|
'last_seen': {'allow_post': True, 'allow_put': False,
|
||||||
|
'validate': {'type:string': None},
|
||||||
|
'is_visible': True}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Wantcdevice(extensions.ExtensionDescriptor):
|
||||||
|
@classmethod
|
||||||
|
def get_name(cls):
|
||||||
|
return "WAN Traffic Control device"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_alias(cls):
|
||||||
|
return "wan-tc-device"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_description(cls):
|
||||||
|
return "Device for limiting traffic on WAN links"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_updated(cls):
|
||||||
|
return "2017-01-15T00:00:00-00:00"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_resources(cls):
|
||||||
|
"""Returns Ext Resources."""
|
||||||
|
|
||||||
|
mem_actions = {}
|
||||||
|
plural_mappings = resource_helper.build_plural_mappings(
|
||||||
|
{}, RESOURCE_ATTRIBUTE_MAP)
|
||||||
|
resources = resource_helper.build_resource_info(plural_mappings,
|
||||||
|
RESOURCE_ATTRIBUTE_MAP,
|
||||||
|
constants.WANTC,
|
||||||
|
action_map=mem_actions,
|
||||||
|
register_quota=True,
|
||||||
|
translate_name=True)
|
||||||
|
|
||||||
|
return resources
|
||||||
|
|
||||||
|
def get_extended_resources(self, version):
|
||||||
|
if version == "2.0":
|
||||||
|
return RESOURCE_ATTRIBUTE_MAP
|
||||||
|
else:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
class WanTcDevicePluginBase(object):
|
||||||
|
@abc.abstractmethod
|
||||||
|
def get_wan_tc_device(self, context, id, fields=None):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def get_wan_tc_devices(self, context, filters=None, fields=None,
|
||||||
|
sorts=None, limit=None, marker=None,
|
||||||
|
page_reverse=False):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def delete_wan_tc_device(self, context, id):
|
||||||
|
pass
|
@ -27,6 +27,7 @@ from wan_qos.common import api
|
|||||||
from wan_qos.common import constants
|
from wan_qos.common import constants
|
||||||
from wan_qos.common import topics
|
from wan_qos.common import topics
|
||||||
from wan_qos.extensions import wanqos
|
from wan_qos.extensions import wanqos
|
||||||
|
from wan_qos.extensions import wantcdevice
|
||||||
from wan_qos.db import wan_qos_db
|
from wan_qos.db import wan_qos_db
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -48,8 +49,9 @@ class PluginRpcCallback(object):
|
|||||||
self.plugin.db.device_heartbeat(context, host)
|
self.plugin.db.device_heartbeat(context, host)
|
||||||
|
|
||||||
|
|
||||||
class WanQosPlugin(wanqos.WanQosPluginBase):
|
class WanQosPlugin(wanqos.WanQosPluginBase,
|
||||||
supported_extension_aliases = ["wan-tc"]
|
wantcdevice.WanTcDevicePluginBase):
|
||||||
|
supported_extension_aliases = ['wan-tc', 'wan-tc-device']
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.db = wan_qos_db.WanTcDb()
|
self.db = wan_qos_db.WanTcDb()
|
||||||
@ -64,6 +66,17 @@ class WanQosPlugin(wanqos.WanQosPluginBase):
|
|||||||
fanout=False)
|
fanout=False)
|
||||||
self.conn.consume_in_threads()
|
self.conn.consume_in_threads()
|
||||||
|
|
||||||
|
def delete_wan_tc_device(self, context, id):
|
||||||
|
self.db.delete_wan_tc_device(context, id)
|
||||||
|
|
||||||
|
def get_wan_tc_device(self, context, id, fields=None):
|
||||||
|
return self.db.get_device(context, id)
|
||||||
|
|
||||||
|
def get_wan_tc_devices(self, context, filters=None, fields=None,
|
||||||
|
sorts=None, limit=None, marker=None,
|
||||||
|
page_reverse=False):
|
||||||
|
return self.db.get_all_devices(context)
|
||||||
|
|
||||||
def get_plugin_type(self):
|
def get_plugin_type(self):
|
||||||
"""Get type of the plugin."""
|
"""Get type of the plugin."""
|
||||||
return constants.WANTC
|
return constants.WANTC
|
||||||
|
48
wan_qos/wanqos_client/_wantcdevice.py
Normal file
48
wan_qos/wanqos_client/_wantcdevice.py
Normal 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 neutronclient.common import extension
|
||||||
|
|
||||||
|
from wan_qos.common import constants
|
||||||
|
|
||||||
|
|
||||||
|
def args2body(self, parsed_args):
|
||||||
|
body = {constants.WAN_TC_DEVICE: {}, }
|
||||||
|
return body
|
||||||
|
|
||||||
|
|
||||||
|
class WanTcDevice(extension.NeutronClientExtension):
|
||||||
|
resource = constants.WAN_TC_DEVICE
|
||||||
|
resource_plural = '%ss' % constants.WAN_TC_DEVICE
|
||||||
|
path = constants.WAN_TC_DEVICE_PATH
|
||||||
|
object_path = '/%s' % path
|
||||||
|
resource_path = '/%s/%%s' % path
|
||||||
|
versions = ['2.0']
|
||||||
|
|
||||||
|
|
||||||
|
class WanTcDeviceShow(extension.ClientExtensionShow, WanTcDevice):
|
||||||
|
shell_command = 'wan-tc-device-show'
|
||||||
|
|
||||||
|
|
||||||
|
class WanTcDeviceList(extension.ClientExtensionList, WanTcDevice):
|
||||||
|
shell_command = 'wan-tc-device-list'
|
||||||
|
list_columns = ['id', 'host', 'lan_port', 'wan_port',
|
||||||
|
'uptime', 'last_seen']
|
||||||
|
pagination_support = True
|
||||||
|
sorting_support = True
|
||||||
|
|
||||||
|
|
||||||
|
class WanTcDeviceDelete(extension.ClientExtensionDelete, WanTcDevice):
|
||||||
|
shell_command = 'wan-tc-device-delete'
|
Loading…
x
Reference in New Issue
Block a user