Add list_endpoint to keystone client
Add a method list endpoints and filterable by name and interface. Change-Id: Ia76602bf59e86e57ea8107d5bfda586363ae67a3
This commit is contained in:
parent
422e9448ff
commit
9964cac268
@ -57,6 +57,16 @@ class KeystoneClient:
|
|||||||
def __init__(self, api: Client):
|
def __init__(self, api: Client):
|
||||||
self.api = api
|
self.api = api
|
||||||
|
|
||||||
|
def _convert_endpoint_to_dict(self, endpoint: Endpoint) -> dict:
|
||||||
|
return {
|
||||||
|
"id": endpoint.id,
|
||||||
|
"service_id": endpoint.service_id,
|
||||||
|
"interface": endpoint.interface,
|
||||||
|
"region": endpoint.region,
|
||||||
|
"url": endpoint.url,
|
||||||
|
"enabled": endpoint.enabled,
|
||||||
|
}
|
||||||
|
|
||||||
def _convert_domain_to_dict(self, domain: Domain) -> dict:
|
def _convert_domain_to_dict(self, domain: Domain) -> dict:
|
||||||
return {
|
return {
|
||||||
"id": domain.id,
|
"id": domain.id,
|
||||||
@ -317,6 +327,54 @@ class KeystoneClient:
|
|||||||
logger.debug(f"Created endpoint {ep_string} with id {endpoint.id}")
|
logger.debug(f"Created endpoint {ep_string} with id {endpoint.id}")
|
||||||
return endpoint
|
return endpoint
|
||||||
|
|
||||||
|
def list_endpoint(
|
||||||
|
self,
|
||||||
|
name: Optional[str] = None,
|
||||||
|
interface: Optional[str] = None,
|
||||||
|
) -> list:
|
||||||
|
"""List endpoints.
|
||||||
|
|
||||||
|
Returns all the endpoints by default.
|
||||||
|
If name is specified, returns the corresponding endpoints.
|
||||||
|
If interface is specified, returns the corresponding endpoints.
|
||||||
|
Response is in the format
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": <>,
|
||||||
|
"service_id": <>,
|
||||||
|
"interface": <>,
|
||||||
|
"region": <>,
|
||||||
|
"url": <>,
|
||||||
|
"enabled": <>,
|
||||||
|
}
|
||||||
|
...
|
||||||
|
]
|
||||||
|
|
||||||
|
:param name: Endpoint name name
|
||||||
|
:param type: str | None
|
||||||
|
:param interface: Endpoint interface
|
||||||
|
:param type: str | None
|
||||||
|
:rtype: list
|
||||||
|
"""
|
||||||
|
options = {
|
||||||
|
"interface": interface,
|
||||||
|
}
|
||||||
|
if name is not None:
|
||||||
|
services = self.api.services.list(name=name)
|
||||||
|
if len(services) != 1:
|
||||||
|
return []
|
||||||
|
options["service"] = services[0]
|
||||||
|
endpoints = self.api.endpoints.list(**options)
|
||||||
|
if endpoints is None:
|
||||||
|
return []
|
||||||
|
|
||||||
|
endpoint_list = [
|
||||||
|
self._convert_endpoint_to_dict(endpoint) for endpoint in endpoints
|
||||||
|
]
|
||||||
|
|
||||||
|
logger.debug(f"Endpoint list: {endpoint_list}")
|
||||||
|
return endpoint_list
|
||||||
|
|
||||||
# Operations exposed via identity-ops relation
|
# Operations exposed via identity-ops relation
|
||||||
|
|
||||||
def list_domain(self, name: Optional[str] = None) -> list:
|
def list_domain(self, name: Optional[str] = None) -> list:
|
||||||
|
Loading…
Reference in New Issue
Block a user