Support /health and /products API
Change-Id: I3cfe101a50553af9e2eeae0614becfe4b32984ea
This commit is contained in:
parent
33226737b0
commit
cd548fc2ce
37
distilclient/tests/unit/v2/test_health.py
Normal file
37
distilclient/tests/unit/v2/test_health.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# Copyright (c) 2017 Catalyst IT Ltd.
|
||||||
|
#
|
||||||
|
# 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 mock
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
import distilclient
|
||||||
|
from distilclient import base
|
||||||
|
from distilclient.tests.unit import utils
|
||||||
|
from distilclient.v2 import client
|
||||||
|
|
||||||
|
|
||||||
|
class HealthTest(utils.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(HealthTest, self).setUp()
|
||||||
|
self.client = client.Client(session=client.session.Session(),
|
||||||
|
api_version=distilclient.API_MAX_VERSION,
|
||||||
|
distil_url=uuid.uuid4().hex, retries=3,
|
||||||
|
input_auth_token='token')
|
||||||
|
|
||||||
|
@mock.patch.object(base.Manager, '_list')
|
||||||
|
def test_get(self, mock_list):
|
||||||
|
self.client.health.get()
|
||||||
|
mock_list.assert_called_with('/v2/health', 'health')
|
43
distilclient/tests/unit/v2/test_products.py
Normal file
43
distilclient/tests/unit/v2/test_products.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# Copyright (c) 2017 Catalyst IT Ltd.
|
||||||
|
#
|
||||||
|
# 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 mock
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
import distilclient
|
||||||
|
from distilclient import base
|
||||||
|
from distilclient.tests.unit import utils
|
||||||
|
from distilclient.v2 import client
|
||||||
|
|
||||||
|
|
||||||
|
class ProductsTest(utils.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(ProductsTest, self).setUp()
|
||||||
|
self.client = client.Client(session=client.session.Session(),
|
||||||
|
api_version=distilclient.API_MAX_VERSION,
|
||||||
|
distil_url=uuid.uuid4().hex, retries=3,
|
||||||
|
input_auth_token='token')
|
||||||
|
|
||||||
|
@mock.patch.object(base.Manager, '_list')
|
||||||
|
def test_list(self, mock_list):
|
||||||
|
self.client.products.list()
|
||||||
|
mock_list.assert_called_with('/v2/products', 'products')
|
||||||
|
|
||||||
|
@mock.patch.object(base.Manager, '_list')
|
||||||
|
def test_list_with_regions(self, mock_list):
|
||||||
|
self.client.products.list(regions=["nz-hlz-1", "nz-por-1"])
|
||||||
|
mock_list.assert_called_with('/v2/products?regions=nz-hlz-1,nz-por-1',
|
||||||
|
'products')
|
@ -21,8 +21,10 @@ import six
|
|||||||
from distilclient.common import httpclient
|
from distilclient.common import httpclient
|
||||||
from distilclient import exceptions
|
from distilclient import exceptions
|
||||||
from distilclient.v2 import credits
|
from distilclient.v2 import credits
|
||||||
|
from distilclient.v2 import health
|
||||||
from distilclient.v2 import invoices
|
from distilclient.v2 import invoices
|
||||||
from distilclient.v2 import measurements
|
from distilclient.v2 import measurements
|
||||||
|
from distilclient.v2 import products
|
||||||
from distilclient.v2 import quotations
|
from distilclient.v2 import quotations
|
||||||
|
|
||||||
|
|
||||||
@ -192,6 +194,8 @@ class Client(object):
|
|||||||
self.invoices = invoices.InvoiceManager(self)
|
self.invoices = invoices.InvoiceManager(self)
|
||||||
self.quotations = quotations.QuotationManager(self)
|
self.quotations = quotations.QuotationManager(self)
|
||||||
self.credits = credits.CreditManager(self)
|
self.credits = credits.CreditManager(self)
|
||||||
|
self.products = products.ProductManager(self)
|
||||||
|
self.health = health.HealthManager(self)
|
||||||
|
|
||||||
self._load_extensions(extensions)
|
self._load_extensions(extensions)
|
||||||
|
|
||||||
|
32
distilclient/v2/health.py
Normal file
32
distilclient/v2/health.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Copyright 2017 Catalyst IT Ltd.
|
||||||
|
#
|
||||||
|
# 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 distilclient import base
|
||||||
|
|
||||||
|
|
||||||
|
class HealthManager(base.Manager):
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
"""Retrieve the health status of Distil server.
|
||||||
|
|
||||||
|
:returns: A list of checking items for Distil health.
|
||||||
|
"""
|
||||||
|
|
||||||
|
url = "/v2/health"
|
||||||
|
|
||||||
|
# TODO(flwang): Here is using _list instead of _get because by default
|
||||||
|
# _get function will try to parse the response as a resource object.
|
||||||
|
# However, we don't have a well-defined health object yet. So let just
|
||||||
|
# use _list() for now.
|
||||||
|
return self._list(url, 'health')
|
30
distilclient/v2/products.py
Normal file
30
distilclient/v2/products.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Copyright 2017 Catalyst IT Ltd.
|
||||||
|
#
|
||||||
|
# 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 distilclient import base
|
||||||
|
|
||||||
|
|
||||||
|
class ProductManager(base.Manager):
|
||||||
|
|
||||||
|
def list(self, regions=[]):
|
||||||
|
"""Retrieve a list of products.
|
||||||
|
|
||||||
|
:returns: A list of products.
|
||||||
|
"""
|
||||||
|
|
||||||
|
url = "/v2/products"
|
||||||
|
if regions:
|
||||||
|
url += "?regions=" + ",".join(regions)
|
||||||
|
|
||||||
|
return self._list(url, "products")
|
Loading…
x
Reference in New Issue
Block a user