From 3df55d3c47082717ffe7450ed7eacc77c58992d6 Mon Sep 17 00:00:00 2001 From: Ofer Ben-Yacov Date: Thu, 29 Dec 2016 12:03:24 +0200 Subject: [PATCH] Add Neutron client --- wan_qos/common/constants.py | 5 +- wan_qos/extensions/wanqos.py | 6 +-- wan_qos/services/plugin.py | 17 ++----- wan_qos/wanqos_client/_wanqos.py | 79 ++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 19 deletions(-) create mode 100644 wan_qos/wanqos_client/_wanqos.py diff --git a/wan_qos/common/constants.py b/wan_qos/common/constants.py index 1183adb..1754e3f 100644 --- a/wan_qos/common/constants.py +++ b/wan_qos/common/constants.py @@ -13,5 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -WAN_QOS = 'WAN_QOS' -WANQOS = 'wanqos' \ No newline at end of file +WANQOS = 'WANQOS' +WAN_QOS = 'wan_qos' +WAN_QOS_PATH = 'wan-qos' \ No newline at end of file diff --git a/wan_qos/extensions/wanqos.py b/wan_qos/extensions/wanqos.py index 71b3ed6..ca4f285 100644 --- a/wan_qos/extensions/wanqos.py +++ b/wan_qos/extensions/wanqos.py @@ -21,7 +21,7 @@ from neutron.api.v2 import resource_helper from wan_qos.common import constants RESOURCE_ATTRIBUTE_MAP = { - constants.WAN_QOS: { + constants.WAN_QOS_PATH: { 'id': {'allow_post': False, 'allow_put': False, 'is_visible': True}, 'max_rate': {'allow_post': True, 'allow_put': False, @@ -41,7 +41,7 @@ RESOURCE_ATTRIBUTE_MAP = { } -class WanQos(extensions.ExtensionDescriptor): +class Wanqos(extensions.ExtensionDescriptor): @classmethod def get_name(cls): @@ -49,7 +49,7 @@ class WanQos(extensions.ExtensionDescriptor): @classmethod def get_alias(cls): - return "wan_qos" + return "wan-qos" @classmethod def get_description(cls): diff --git a/wan_qos/services/plugin.py b/wan_qos/services/plugin.py index ff9e801..c7d404e 100644 --- a/wan_qos/services/plugin.py +++ b/wan_qos/services/plugin.py @@ -21,8 +21,6 @@ from oslo_log import log as logging from oslo_utils import importutils import oslo_messaging as messaging -from neutron.services import service_base - from wan_qos.common import api from wan_qos.common import constants from wan_qos.common import topics @@ -44,19 +42,10 @@ class PluginRpcCallback(object): self.plugin.agent_up_notification(host) -class WanQosDriver(service_base.ServicePluginBase): - def get_plugin_description(self): - pass - - def get_plugin_type(self): - pass - - @property - def service_type(self): - return 'wan_qos' - - class WanQosPlugin(wanqos.WanQosPluginBase): + + supported_extension_aliases = ["wan-qos"] + def __init__(self): rpc_callback = importutils.import_object( 'wan_qos.services.plugin.PluginRpcCallback', self) diff --git a/wan_qos/wanqos_client/_wanqos.py b/wan_qos/wanqos_client/_wanqos.py new file mode 100644 index 0000000..09b9385 --- /dev/null +++ b/wan_qos/wanqos_client/_wanqos.py @@ -0,0 +1,79 @@ +# 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 = {'wan_qos': {}, } + return body + + +class WanQos(extension.NeutronClientExtension): + resource = constants.WAN_QOS + resource_plural = '%ss' % constants.WAN_QOS + path = constants.WAN_QOS_PATH + object_path = '/%s' % path + resource_path = '/%s/%%s' % path + versions = ['2.0'] + + +class WanQosShow(extension.ClientExtensionShow, WanQos): + + shell_command = 'wan-qos-show' + + +class WanQosList(extension.ClientExtensionList, WanQos): + + shell_command = 'wan-qos-list' + list_columns = ['id', 'name', 'network'] + pagination_support = True + sorting_support = True + + +class WanQosCreate(extension.ClientExtensionCreate, WanQos): + + shell_command = 'wan-qos-create' + + def add_known_arguments(self, parser): + pass + + def args2body(self, parsed_args): + body = args2body(self, parsed_args) + if parsed_args.tenant_id: + body['wan_qos']['tenant_id'] = parsed_args.tenant_id + return body + + +class WanQosDelete(extension.ClientExtensionDelete, WanQos): + + shell_command = 'wan-qos-delete' + + +class WanQosUpdate(extension.ClientExtensionUpdate, WanQos): + + shell_command = 'wan-qos-update' + + def add_known_arguments(self, parser): + pass + + def args2body(self, parsed_args): + body = args2body(self, parsed_args) + return body + + +