Add hosts to the v1 client
This commit is contained in:
parent
565eb70f30
commit
686eb107a1
@ -1,10 +1,29 @@
|
|||||||
"""Top-level client for version 1 of Craton's API."""
|
"""Top-level client for version 1 of Craton's API."""
|
||||||
|
from cratonclient.v1 import hosts
|
||||||
from cratonclient.v1 import regions
|
from cratonclient.v1 import regions
|
||||||
|
|
||||||
|
|
||||||
class Client(object):
|
class Client(object):
|
||||||
|
"""Craton v1 API Client."""
|
||||||
|
|
||||||
def __init__(self, session, url):
|
def __init__(self, session, url):
|
||||||
|
"""Initialize our client object with our session and url.
|
||||||
|
|
||||||
|
:param session:
|
||||||
|
Initialized Session object.
|
||||||
|
:type session:
|
||||||
|
cratonclient.session.Session
|
||||||
|
:param str url:
|
||||||
|
The URL that points us to the craton instance. For example,
|
||||||
|
'https://10.1.1.0:8080/'.
|
||||||
|
"""
|
||||||
self._url = url
|
self._url = url
|
||||||
self._session = session
|
self._session = session
|
||||||
|
|
||||||
self.regions = regions.RegionManager(self._session, self._url)
|
if not self._url.endswith('/v1'):
|
||||||
|
self._url += '/v1'
|
||||||
|
|
||||||
|
manager_kwargs = {'session': self._session, 'url': url}
|
||||||
|
|
||||||
|
self.hosts = hosts.HostManager(**manager_kwargs)
|
||||||
|
self.regions = regions.RegionManager(**manager_kwargs)
|
||||||
|
21
cratonclient/v1/hosts.py
Normal file
21
cratonclient/v1/hosts.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
"""Hosts resource and resource manager."""
|
||||||
|
from cratonclient import crud
|
||||||
|
|
||||||
|
|
||||||
|
class Host(crud.Resource):
|
||||||
|
"""Representation of a Host."""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class HostManager(crud.CRUDClient):
|
||||||
|
"""A manager for hosts."""
|
||||||
|
|
||||||
|
key = 'host'
|
||||||
|
base_path = '/hosts'
|
||||||
|
resource_class = Host
|
||||||
|
|
||||||
|
def list(self, project_id, **kwargs):
|
||||||
|
"""Retrieve the hosts in a specific region."""
|
||||||
|
kwargs['project'] = str(project_id)
|
||||||
|
super(HostManager, self).list(**kwargs)
|
Loading…
x
Reference in New Issue
Block a user