Add SearchManager to venusclient
Move get logs from ConfigManager to new SearchManager. Change-Id: I5ecfba2963846bb5fa260e141e562bc550308a4e
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
#
|
||||
import logging
|
||||
from urllib import parse
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
@@ -157,3 +158,19 @@ def args_array_to_patch(op, attributes):
|
||||
else:
|
||||
raise exc.CommandError(_('Unknown PATCH operation: %s') % op)
|
||||
return patch
|
||||
|
||||
|
||||
def prepare_query_string(params):
|
||||
"""Convert dict params to query string"""
|
||||
# Transform the dict to a sequence of two-element tuples in fixed
|
||||
# order, then the encoded string will be consistent in Python 2&3.
|
||||
if not params:
|
||||
return ''
|
||||
params = sorted(params.items(), key=lambda x: x[0])
|
||||
return '?%s' % parse.urlencode(params) if params else ''
|
||||
|
||||
|
||||
def get_url_with_filter(url, filters):
|
||||
query_string = prepare_query_string(filters)
|
||||
url = "%s%s" % (url, query_string)
|
||||
return url
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
# Copyright 2014
|
||||
# The Cloudscaling Group, Inc.
|
||||
# Copyright 2020 Inspur
|
||||
#
|
||||
# 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
|
||||
# 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
|
||||
# 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.
|
||||
# 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 os_client_config
|
||||
|
||||
@@ -19,6 +18,7 @@ from keystoneauth1 import session as ksa_session
|
||||
from oslo_utils import importutils
|
||||
from venusclient.common import httpclient
|
||||
from venusclient.v1 import config
|
||||
from venusclient.v1 import search
|
||||
|
||||
|
||||
profiler = importutils.try_import("osprofiler.profiler")
|
||||
@@ -181,6 +181,7 @@ class Client(object):
|
||||
)
|
||||
|
||||
self.config = config.ConfigManager(self.http_client)
|
||||
self.search = search.SearchManager(self.http_client)
|
||||
|
||||
profile = kwargs.pop("profile", None)
|
||||
if profiler and profile:
|
||||
|
||||
@@ -34,12 +34,3 @@ class ConfigManager(basemodels.BaseModelManager):
|
||||
return body
|
||||
except Exception as e:
|
||||
raise RuntimeError(str(e))
|
||||
|
||||
def get_logs(self, args):
|
||||
print(args)
|
||||
url = '/v1/search/logs'
|
||||
try:
|
||||
resp, body = self.api.json_request('GET', url)
|
||||
return body
|
||||
except Exception as e:
|
||||
raise RuntimeError(str(e))
|
||||
|
||||
41
venusclient/v1/search.py
Normal file
41
venusclient/v1/search.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# Copyright 2020 Inspur
|
||||
#
|
||||
# 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 venusclient.common import utils
|
||||
from venusclient.v1 import basemodels
|
||||
|
||||
|
||||
class SearchManager(basemodels.BaseModelManager):
|
||||
api_name = "search"
|
||||
base_url = "search"
|
||||
|
||||
def get_logs(self, start_time=0, end_time=20, page_size=15, page_num=1):
|
||||
url = '/v1/search/logs'
|
||||
|
||||
params = {
|
||||
'start_time': start_time,
|
||||
'end_time': end_time,
|
||||
'page_size': page_size,
|
||||
'page_num': page_num
|
||||
}
|
||||
url += utils.prepare_query_string(params)
|
||||
|
||||
print('123123123')
|
||||
print(url)
|
||||
|
||||
try:
|
||||
resp, body = self.api.json_request('GET', url)
|
||||
return body
|
||||
except Exception as e:
|
||||
raise RuntimeError(str(e))
|
||||
Reference in New Issue
Block a user