Added Designate servers api
Change-Id: I0dac1ad056e3c9f7571739925aaa59448b1a37b2
This commit is contained in:
@@ -18,6 +18,8 @@ from cafe.engine.clients.rest import AutoMarshallingRestClient
|
||||
from cloudcafe.designate.v1.domain_api.models.requests import DomainRequest
|
||||
from cloudcafe.designate.v1.domain_api.models.responses import (
|
||||
DomainResponse, DomainListResponse)
|
||||
from cloudcafe.designate.v1.server_api.models.responses import (
|
||||
ServerResponse, ServerListResponse)
|
||||
|
||||
|
||||
class DomainAPIClient(AutoMarshallingRestClient):
|
||||
@@ -74,3 +76,10 @@ class DomainAPIClient(AutoMarshallingRestClient):
|
||||
url = self._get_domain_url(domain_id)
|
||||
return self.request('DELETE', url, response_entity_type=DomainResponse,
|
||||
requestslib_kwargs=requestslib_kwargs)
|
||||
|
||||
def list_domain_servers(self, domain_id, **requestslib_kwargs):
|
||||
"""GET v1/domains/{domainID}/servers"""
|
||||
url = self._get_domain_url(domain_id) + "/servers"
|
||||
return self.request('GET', url,
|
||||
response_entity_type=ServerListResponse,
|
||||
requestslib_kwargs=requestslib_kwargs)
|
||||
|
||||
15
cloudcafe/designate/v1/server_api/__init__.py
Normal file
15
cloudcafe/designate/v1/server_api/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
"""
|
||||
Copyright 2013 Rackspace
|
||||
|
||||
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.
|
||||
"""
|
||||
74
cloudcafe/designate/v1/server_api/client.py
Normal file
74
cloudcafe/designate/v1/server_api/client.py
Normal file
@@ -0,0 +1,74 @@
|
||||
"""
|
||||
Copyright 2013 Rackspace
|
||||
|
||||
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 cafe.engine.clients.rest import AutoMarshallingRestClient
|
||||
from cloudcafe.designate.v1.server_api.models.requests import ServerRequest
|
||||
from cloudcafe.designate.v1.server_api.models.responses import \
|
||||
ServerResponse, ServerListResponse
|
||||
|
||||
|
||||
class ServerAPIClient(AutoMarshallingRestClient):
|
||||
|
||||
def __init__(self, url, serialize_format=None,
|
||||
deserialize_format=None):
|
||||
super(ServerAPIClient, self).__init__(serialize_format,
|
||||
deserialize_format)
|
||||
self.url = url.rstrip('/')
|
||||
self.default_headers['Content-Type'] = 'application/{0}'.format(
|
||||
self.serialize_format)
|
||||
self.default_headers['Accept'] = 'application/{0}'.format(
|
||||
self.serialize_format)
|
||||
|
||||
def _get_servers_url(self):
|
||||
return "{0}/servers".format(self.url)
|
||||
|
||||
def _get_server_url(self, server_id):
|
||||
return "{0}/{1}".format(self._get_servers_url(), server_id)
|
||||
|
||||
def create_server(self, name=None, **requestslib_kwargs):
|
||||
"""POST /servers"""
|
||||
server = ServerRequest(name=name)
|
||||
url = self._get_servers_url()
|
||||
return self.request('POST', url, response_entity_type=ServerResponse,
|
||||
request_entity=server,
|
||||
requestslib_kwargs=requestslib_kwargs)
|
||||
|
||||
def update_server(self, server_id, name, **requestslib_kwargs):
|
||||
"""PUT /servers/{serverID}"""
|
||||
server = ServerRequest(name=name)
|
||||
url = self._get_server_url(server_id)
|
||||
return self.request('PUT', url, response_entity_type=ServerResponse,
|
||||
request_entity=server,
|
||||
requestslib_kwargs=requestslib_kwargs)
|
||||
|
||||
def list_servers(self, **requestslib_kwargs):
|
||||
"""GET /servers"""
|
||||
url = self._get_servers_url()
|
||||
return self.request('GET', url,
|
||||
response_entity_type=ServerListResponse,
|
||||
requestslib_kwargs=requestslib_kwargs)
|
||||
|
||||
def get_server(self, server_id, **requestslib_kwargs):
|
||||
"""GET /servers/{serverID}"""
|
||||
url = self._get_server_url(server_id)
|
||||
return self.request('GET', url, response_entity_type=ServerResponse,
|
||||
requestslib_kwargs=requestslib_kwargs)
|
||||
|
||||
def delete_server(self, server_id, **requestslib_kwargs):
|
||||
"""DELETE /servers/{serverID}"""
|
||||
url = self._get_server_url(server_id)
|
||||
return self.request('DELETE', url,
|
||||
requestslib_kwargs=requestslib_kwargs)
|
||||
15
cloudcafe/designate/v1/server_api/models/__init__.py
Normal file
15
cloudcafe/designate/v1/server_api/models/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
"""
|
||||
Copyright 2013 Rackspace
|
||||
|
||||
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.
|
||||
"""
|
||||
31
cloudcafe/designate/v1/server_api/models/requests.py
Normal file
31
cloudcafe/designate/v1/server_api/models/requests.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""
|
||||
Copyright 2013 Rackspace
|
||||
|
||||
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
|
||||
|
||||
from cafe.engine.models.base import AutoMarshallingModel
|
||||
|
||||
|
||||
class ServerRequest(AutoMarshallingModel):
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
def _obj_to_json(self):
|
||||
return json.dumps(self._obj_to_dict())
|
||||
|
||||
def _obj_to_dict(self):
|
||||
return {"name": self.name}
|
||||
62
cloudcafe/designate/v1/server_api/models/responses.py
Normal file
62
cloudcafe/designate/v1/server_api/models/responses.py
Normal file
@@ -0,0 +1,62 @@
|
||||
"""
|
||||
Copyright 2013 Rackspace
|
||||
|
||||
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
|
||||
|
||||
from cafe.engine.models.base import AutoMarshallingModel
|
||||
from cafe.engine.models.base import AutoMarshallingListModel
|
||||
|
||||
|
||||
class ServerResponse(AutoMarshallingModel):
|
||||
|
||||
def __init__(self, id=None, name=None, created_at=None, updated_at=None):
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.created_at = created_at
|
||||
self.updated_at = updated_at
|
||||
|
||||
@classmethod
|
||||
def _from_dict(self, server_dict):
|
||||
"""
|
||||
{
|
||||
"id": "384a9b20-239c-11e2-81c1-0800200c9a66",
|
||||
"name": "ns1.example.org."
|
||||
"created_at": "2011-01-21T11:33:21Z",
|
||||
"updated_at": null
|
||||
}
|
||||
"""
|
||||
return ServerResponse(server_dict.get("id"),
|
||||
server_dict.get("name"),
|
||||
server_dict.get("updated_at"),
|
||||
server_dict.get("created_at"))
|
||||
|
||||
@classmethod
|
||||
def _json_to_obj(cls, serialized_str):
|
||||
response_json = json.loads(serialized_str)
|
||||
return cls._from_dict(response_json)
|
||||
|
||||
|
||||
class ServerListResponse(AutoMarshallingListModel):
|
||||
|
||||
@classmethod
|
||||
def _json_to_obj(cls, serialized_str):
|
||||
response_json = json.loads(serialized_str)
|
||||
return cls._list_to_obj(response_json.get("servers"))
|
||||
|
||||
@classmethod
|
||||
def _list_to_obj(cls, server_list):
|
||||
return ServerListResponse(
|
||||
[ServerResponse._from_dict(server) for server in server_list])
|
||||
Reference in New Issue
Block a user