441542c234
1. Use keystoneauth1 for making session
2. Nailgun/OSTF client uses keystoneauth1 session
3. Drop HTTPClient
4. Support NailgunClient construction by providing session
5. Requests has on-demand authorization and re-authorization
by keystoneauth1.
Pros:
* interface unification, after implementation of bugfix fr 1581024
we could transparently switch the most methods
from our implmentation to python-fuelclient implementation.
* Less decorators magic (@jsonparse is not required)
Blueprint: python-fuel-client-in-system-tests
Change-Id: Idc0c0b3b0039f64d852ea1a08e02a9c3ecd65c46
(cherry picked from commit 92006f3
)
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
# Copyright 2013 Mirantis, Inc.
|
|
#
|
|
# 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 json
|
|
# pylint: disable=import-error
|
|
# noinspection PyUnresolvedReferences
|
|
from six.moves.urllib import request
|
|
# pylint: enable=import-error
|
|
|
|
|
|
class HTTPClientZabbix(object):
|
|
"""HTTPClientZabbix.""" # TODO documentation
|
|
|
|
def __init__(self, url):
|
|
self.url = url
|
|
self.opener = request.build_opener(request.HTTPHandler)
|
|
|
|
def get(self, endpoint=None, cookie=None):
|
|
req = request.Request(self.url + endpoint)
|
|
if cookie:
|
|
req.add_header('cookie', cookie)
|
|
return self.opener.open(req)
|
|
|
|
def post(self, endpoint=None, data=None, content_type="text/css",
|
|
cookie=None):
|
|
if not data:
|
|
data = {}
|
|
req = request.Request(self.url + endpoint, data=json.dumps(data))
|
|
req.add_header('Content-Type', content_type)
|
|
if cookie:
|
|
req.add_header('cookie', cookie)
|
|
return self.opener.open(req)
|