hpecp.base_resource module¶
Base classes for Controllers and Resources.
- class hpecp.base_resource.AbstractResourceController(client)[source]¶
Bases:
object
Base class for Resource Controllers.
- abstract property base_resource_path¶
Declare the resource base path for the API resource.
- Getter:
Returns the resource base path
- Setter:
Sets the resource base path
- Type:
str
- class K8sClusterController(AbstractResourceController):
… base_resource_path = “/api/v2/k8scluster”
- abstract property resource_class¶
Declare the implementing Resource class for the API resource. The resource class contains properties mapping to attributes in the response.
- Getter:
Returns the Resource class
- Setter:
Sets the Resource class
- Type:
class
- class K8sClusterController(AbstractResourceController):
… resource_class = K8sCluster
- abstract property resource_list_path¶
Declare the implementing resource list path for the API resource. The resource list path is where the resources are after the ‘_embedded’ element in the API response json.
- Getter:
Returns the resource list path
- Setter:
Sets the resource list path
- Type:
str
- class K8sClusterController(AbstractResourceController):
… resource_list_path = “k8sclusters”
- get(id, params={})[source]¶
Make an API call to retrieve a Resource.
- idstr
The ID with the format /resource/path/id
- paramsstr, optional
API Parameters.
- Instance of self.resource_class
An instance of the class defined by the property self.resource_class
- APIException
The remote API returned an error.
- APIItemNotFoundException
The item with {id} was not found.
- class hpecp.base_resource.AbstractWaitableResourceController(client)[source]¶
Bases:
AbstractResourceController
Resource Controller that is able to wait for the resource’s status.
- abstract property status_class¶
Declare the implementing Status class for the API resource. The status class contains properties mapping to attributes in the response.
- Getter:
Returns the Status class
- Setter:
Sets the Status class
- Type:
class
- class K8sClusterController(AbstractResourceController):
… status_class = K8sClusterStatus
- abstract property status_fieldname¶
Declare the Status fieldname in the API resource.
Usually either: status or state
- Getter:
Returns the Status fieldname
- Setter:
Sets the Status fieldname
- Type:
str
- class K8sClusterController(AbstractResourceController):
… status_fieldname = status
- wait_for_status(id, status=[], timeout_secs=1200)[source]¶
Wait for K8S worker status.
- id: str
The resource ID - format: ‘/resource/path/[0-9]+’
- status: list[:py:method:`status_class`]
Status(es) to wait for. Use an empty array if you want to wait for the resource existence to cease.
- timeout_secs: int
How long to wait for the status(es) before raising an exception.
- bool
True if status was found before timeout, otherwise False True if item does not exist before timeout and status is empty
- class hpecp.base_resource.AbstractResource(json)[source]¶
Bases:
object
Base class for Resource class repreenting an API resource.
The resource class contains properties mapping to attributes in the response.
The implementing class is declared in the ResourceController:
- class K8sClusterController(AbstractResourceController):
… resource_class = K8sCluster
- abstract property all_fields¶
- property id¶
@Field: from json[‘_links’][‘self’][‘href’].
- class hpecp.base_resource.ResourceList(resource_class, json)[source]¶
Bases:
object
List of Resource objects.
- tabulate(columns=[], style='pretty', display_headers=True)[source]¶
Return a tabule output of the ResourceList.
- columnslist, optional
List of columns to output. The default value of an empty list will output all the available fields
- stylestr, optional
Table styles, by default “pretty”
The available styles are:
“plain” “simple” “github” “grid” “fancy_grid” “pipe” “orgtbl” “jira” “presto” “pretty” “psql” “rst” “mediawiki” “moinmoin” “youtrack” “html” “latex” “latex_raw” “latex_booktabs” “textile”
See section ‘Table Format’ in https://pypi.org/project/tabulate/ for more information
- str
table output of Resource
Print the cluster list with all of the avaialble fields >>> print(hpeclient.cluster.list().tabulate())
Print the cluster list with a subset of the fields >>> print(hpeclient.cluster.list().tabulate( … columns=[‘id’, ‘name’,’description’]))