Adds basic client methods for Ironic
* Added basic API operations for chassis, drivers, nodes, and ports Change-Id: Id1cea2a1a4eb1557b4957f5b3dddeede1aea3adb
This commit is contained in:
committed by
Gerrit Code Review
parent
5f870f9058
commit
6fe167c03e
@@ -13,3 +13,109 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from cafe.engine.http.client import AutoMarshallingHTTPClient
|
||||||
|
|
||||||
|
from cloudcafe.bare_metal.chassis.models.responses import Chassis, ChassisList
|
||||||
|
from cloudcafe.bare_metal.chassis.models.requests import CreateChassis
|
||||||
|
from cloudcafe.bare_metal.nodes.models.responses import Nodes
|
||||||
|
|
||||||
|
|
||||||
|
class ChassisClient(AutoMarshallingHTTPClient):
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, url, auth_token, serialize_format=None,
|
||||||
|
deserialize_format=None):
|
||||||
|
|
||||||
|
super(ChassisClient, self).__init__(
|
||||||
|
serialize_format, deserialize_format)
|
||||||
|
|
||||||
|
self.url = url
|
||||||
|
self.auth_token = auth_token
|
||||||
|
self.default_headers['X-Auth-Token'] = auth_token
|
||||||
|
self.default_headers['Content-Type'] = 'application/{0}'.format(
|
||||||
|
self.serialize_format)
|
||||||
|
self.default_headers['Accept'] = 'application/{0}'.format(
|
||||||
|
self.deserialize_format)
|
||||||
|
|
||||||
|
def list_chassis(self, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Lists all chassis.
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
url = '{base_url}/chassis'.format(base_url=self.url)
|
||||||
|
resp = self.get(url, response_entity_type=ChassisList,
|
||||||
|
requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def list_chassis_with_details(self, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Lists all chassis with details.
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
url = '{base_url}/chassis/detail'.format(base_url=self.url)
|
||||||
|
resp = self.get(url, response_entity_type=ChassisList,
|
||||||
|
requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def list_nodes_for_chassis(self, uuid, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Lists all nodes associated with a chassis.
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
url = '{base_url}/chassis/{chassis}/nodes'.format(
|
||||||
|
base_url=self.url, chassis=uuid)
|
||||||
|
resp = self.get(url, response_entity_type=Nodes,
|
||||||
|
requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def get_chassis(self, uuid, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Retrieves the details of an individual chassis.
|
||||||
|
@param uuid: The uuid of an existing chassis
|
||||||
|
@type uuid: String
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
url = '{base_url}/chassis/{uuid}'.format(
|
||||||
|
base_url=self.url, uuid=uuid)
|
||||||
|
resp = self.get(url, response_entity_type=Chassis,
|
||||||
|
requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def create_chassis(self, description=None, extra=None,
|
||||||
|
requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Creates a chassis from the provided parameters.
|
||||||
|
@param description: Description of the chassis
|
||||||
|
@type description: String
|
||||||
|
@param description: Extra metadata for the chassis
|
||||||
|
@type description: Dict
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
request = CreateChassis(
|
||||||
|
description=description, extra=extra)
|
||||||
|
|
||||||
|
url = '{base_url}/chassis'.format(base_url=self.url)
|
||||||
|
resp = self.post(url,
|
||||||
|
response_entity_type=Chassis,
|
||||||
|
request_entity=request,
|
||||||
|
requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def delete_chassis(self, uuid, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Deletes the specified chassis.
|
||||||
|
@param uuid: The uuid of a chassis
|
||||||
|
@type uuid: String
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
url = '{base_url}/chassis/{uuid}'.format(
|
||||||
|
base_url=self.url, uuid=uuid)
|
||||||
|
resp = self.delete(url, requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|||||||
@@ -27,3 +27,19 @@ class MarshallingConfig(ConfigSectionInterface):
|
|||||||
@property
|
@property
|
||||||
def deserializer(self):
|
def deserializer(self):
|
||||||
return self.get("deserialize_format")
|
return self.get("deserialize_format")
|
||||||
|
|
||||||
|
|
||||||
|
class BareMetalEndpointConfig(ConfigSectionInterface):
|
||||||
|
SECTION_NAME = 'bare_metal_endpoint'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def region(self):
|
||||||
|
return self.get("region")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def bare_metal_endpoint_name(self):
|
||||||
|
return self.get("bare_metal_endpoint_name")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def bare_metal_endpoint_url(self):
|
||||||
|
return self.get("bare_metal_endpoint_url")
|
||||||
|
|||||||
@@ -13,3 +13,50 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from cafe.engine.http.client import AutoMarshallingHTTPClient
|
||||||
|
|
||||||
|
from cloudcafe.bare_metal.drivers.models.responses import Driver, Drivers
|
||||||
|
|
||||||
|
|
||||||
|
class DriversClient(AutoMarshallingHTTPClient):
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, url, auth_token, serialize_format=None,
|
||||||
|
deserialize_format=None):
|
||||||
|
|
||||||
|
super(DriversClient, self).__init__(
|
||||||
|
serialize_format, deserialize_format)
|
||||||
|
|
||||||
|
self.url = url
|
||||||
|
self.auth_token = auth_token
|
||||||
|
self.default_headers['X-Auth-Token'] = auth_token
|
||||||
|
self.default_headers['Content-Type'] = 'application/{0}'.format(
|
||||||
|
self.serialize_format)
|
||||||
|
self.default_headers['Accept'] = 'application/{0}'.format(
|
||||||
|
self.deserialize_format)
|
||||||
|
|
||||||
|
def list_drivers(self, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Lists all drivers with details.
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
url = '{base_url}/drivers'.format(base_url=self.url)
|
||||||
|
resp = self.get(url, response_entity_type=Drivers,
|
||||||
|
requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def get_driver(self, name, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Retrieves the details of an individual driver.
|
||||||
|
@param name: The uuid of an existing port
|
||||||
|
@type name: String
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
url = '{base_url}/drivers/{uuid}'.format(
|
||||||
|
base_url=self.url, uuid=name)
|
||||||
|
resp = self.get(url, response_entity_type=Driver,
|
||||||
|
requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
"""
|
|
||||||
Copyright 2014 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.
|
|
||||||
"""
|
|
||||||
@@ -13,3 +13,117 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from cafe.engine.http.client import AutoMarshallingHTTPClient
|
||||||
|
|
||||||
|
from cloudcafe.bare_metal.nodes.models.responses import Node, Nodes
|
||||||
|
from cloudcafe.bare_metal.nodes.models.requests import CreateNode
|
||||||
|
from cloudcafe.bare_metal.ports.models.responses import Ports
|
||||||
|
|
||||||
|
|
||||||
|
class NodesClient(AutoMarshallingHTTPClient):
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, url, auth_token, serialize_format=None,
|
||||||
|
deserialize_format=None):
|
||||||
|
|
||||||
|
super(NodesClient, self).__init__(
|
||||||
|
serialize_format, deserialize_format)
|
||||||
|
|
||||||
|
self.url = url
|
||||||
|
self.auth_token = auth_token
|
||||||
|
self.default_headers['X-Auth-Token'] = auth_token
|
||||||
|
self.default_headers['Content-Type'] = 'application/{0}'.format(
|
||||||
|
self.serialize_format)
|
||||||
|
self.default_headers['Accept'] = 'application/{0}'.format(
|
||||||
|
self.deserialize_format)
|
||||||
|
|
||||||
|
def list_nodes(self, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Lists all nodes.
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
url = '{base_url}/nodes'.format(base_url=self.url)
|
||||||
|
resp = self.get(url, response_entity_type=Nodes,
|
||||||
|
requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def list_nodes_with_details(self, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Lists all nodes with details.
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
url = '{base_url}/nodes/detail'.format(base_url=self.url)
|
||||||
|
resp = self.get(url, response_entity_type=Nodes,
|
||||||
|
requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def list_ports_for_node(self, uuid, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Lists all nodes with details.
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
url = '{base_url}/nodes/{uuid}/ports'.format(
|
||||||
|
base_url=self.url, uuid=uuid)
|
||||||
|
resp = self.get(url, response_entity_type=Ports,
|
||||||
|
requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def get_node(self, uuid, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Retrieves the details of an individual node.
|
||||||
|
@param uuid: The uuid of an existing node
|
||||||
|
@type uuid: String
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
url = '{base_url}/nodes/{uuid}'.format(
|
||||||
|
base_url=self.url, uuid=uuid)
|
||||||
|
resp = self.get(url, response_entity_type=Node,
|
||||||
|
requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def create_node(
|
||||||
|
self, chassis_uuid, driver=None, properties=None,
|
||||||
|
driver_info=None, extra=None, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Creates a node from the provided parameters.
|
||||||
|
@param chassis_uuid: The chassis the node is associated with
|
||||||
|
@type chassis_uuid: String
|
||||||
|
@param driver: The driver used to control the node
|
||||||
|
@type driver: String
|
||||||
|
@param properties: The physical characteristics of the node
|
||||||
|
@type properties: Dict
|
||||||
|
@param driver_info: Configuration parameters for the driver
|
||||||
|
@type driver_info: Dict
|
||||||
|
@param extra: Extra metadata for the node
|
||||||
|
@type extra: Dict
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
request = CreateNode(
|
||||||
|
chassis_uuid=chassis_uuid, driver=driver, properties=properties,
|
||||||
|
driver_info=driver_info, extra=extra)
|
||||||
|
|
||||||
|
url = '{base_url}/nodes'.format(base_url=self.url)
|
||||||
|
resp = self.post(url,
|
||||||
|
response_entity_type=Node,
|
||||||
|
request_entity=request,
|
||||||
|
requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def delete_node(self, uuid, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Deletes the specified node.
|
||||||
|
@param uuid: The uuid of a node
|
||||||
|
@type uuid: String
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
url = '{base_url}/nodes/{uuid}'.format(
|
||||||
|
base_url=self.url, uuid=uuid)
|
||||||
|
resp = self.delete(url, requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|||||||
@@ -13,3 +13,99 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from cafe.engine.http.client import AutoMarshallingHTTPClient
|
||||||
|
|
||||||
|
from cloudcafe.bare_metal.ports.models.responses import Port, Ports
|
||||||
|
from cloudcafe.bare_metal.ports.models.requests import CreatePort
|
||||||
|
|
||||||
|
|
||||||
|
class PortsClient(AutoMarshallingHTTPClient):
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, url, auth_token, serialize_format=None,
|
||||||
|
deserialize_format=None):
|
||||||
|
|
||||||
|
super(PortsClient, self).__init__(
|
||||||
|
serialize_format, deserialize_format)
|
||||||
|
|
||||||
|
self.url = url
|
||||||
|
self.auth_token = auth_token
|
||||||
|
self.default_headers['X-Auth-Token'] = auth_token
|
||||||
|
self.default_headers['Content-Type'] = 'application/{0}'.format(
|
||||||
|
self.serialize_format)
|
||||||
|
self.default_headers['Accept'] = 'application/{0}'.format(
|
||||||
|
self.deserialize_format)
|
||||||
|
|
||||||
|
def list_ports(self, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Lists all ports.
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
url = '{base_url}/ports'.format(base_url=self.url)
|
||||||
|
resp = self.get(url, response_entity_type=Ports,
|
||||||
|
requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def list_ports_with_detail(self, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Lists all ports with details.
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
url = '{base_url}/ports/detail'.format(base_url=self.url)
|
||||||
|
resp = self.get(url, response_entity_type=Ports,
|
||||||
|
requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def get_port(self, uuid, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Retrieves the details of an individual port.
|
||||||
|
@param uuid: The uuid of an existing port
|
||||||
|
@type uuid: String
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
url = '{base_url}/ports/{uuid}'.format(
|
||||||
|
base_url=self.url, uuid=uuid)
|
||||||
|
resp = self.get(url, response_entity_type=Port,
|
||||||
|
requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def create_port(
|
||||||
|
self, node_uuid=None, address=None, extra=None,
|
||||||
|
requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Creates a port from the provided parameters.
|
||||||
|
@param node_uuid: The node the port is associated with
|
||||||
|
@type node_uuid: String
|
||||||
|
@param address: The MAC address of the port
|
||||||
|
@type address: String
|
||||||
|
@param extra: Extra metadata for the node
|
||||||
|
@type extra: Dict
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
request = CreatePort(
|
||||||
|
node_uuid=node_uuid, address=address, extra=extra)
|
||||||
|
|
||||||
|
url = '{base_url}/ports'.format(base_url=self.url)
|
||||||
|
resp = self.post(url,
|
||||||
|
response_entity_type=Port,
|
||||||
|
request_entity=request,
|
||||||
|
requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def delete_port(self, uuid, requestslib_kwargs=None):
|
||||||
|
"""
|
||||||
|
@summary: Deletes the specified port.
|
||||||
|
@param uuid: The uuid of a port
|
||||||
|
@type uuid: String
|
||||||
|
@return: resp
|
||||||
|
@rtype: Requests.response
|
||||||
|
"""
|
||||||
|
url = '{base_url}/ports/{uuid}'.format(
|
||||||
|
base_url=self.url, uuid=uuid)
|
||||||
|
resp = self.delete(url, requestslib_kwargs=requestslib_kwargs)
|
||||||
|
return resp
|
||||||
|
|||||||
Reference in New Issue
Block a user