hpecp.k8s_cluster module

class hpecp.k8s_cluster.K8sClusterStatus(value)[source]

Bases: Enum

Bases: enum.Enum

The statuses for a K8S Cluster

Note:

The integer values do not have a meaning outside of this library. The API uses a string identifier with the status name rather than an integer value.

ready = 1
creating = 2
updating = 3
upgrading = 4
deleting = 5
error = 6
warning = 7
class hpecp.k8s_cluster.K8sCluster(json)[source]

Bases: AbstractResource

Create an instance of K8sCluster from json data returned from the HPE Container Platform API.

Users of this library are not expected to create an instance of this class.

jsonstr

The json returned by the API representing a K8sCluster.

K8sCluster:

An instance of K8sCluster

all_fields = ['id', 'name', 'description', 'k8s_version', 'addons', 'created_by_user_id', 'created_by_user_name', 'created_time', 'k8shosts_config', 'admin_kube_config', 'dashboard_token', 'api_endpoint_access', 'dashboard_endpoint_access', 'cert_data', 'status', 'status_message', '_links']

All of the fields of a K8s Cluster objects that are returned by the HPE Container Platform API

default_display_fields = ['id', 'name', 'description', 'k8s_version', 'status']
property name

@Field: from json[‘label’][‘name’]

property description

@Field: from json[‘label’][‘description’]

property k8s_version

@Field: from json[‘k8s_version’]

property addons

@Field: from json[‘addons’]

property created_by_user_id

@Field: from json[‘created_by_user_id’]

property created_by_user_name

@Field: from json[‘created_by_user_name’]

property created_time

@Field: from json[‘created_time’]

property k8shosts_config

@Field: from json[‘k8shosts_config’]

property admin_kube_config

@Field: from json[‘admin_kube_config’]

property dashboard_token

@Field: from json[‘dashboard_token’]

property api_endpoint_access

@Field: from json[‘api_endpoint_access’]

property dashboard_endpoint_access

@Field: from json[‘dashboard_endpoint_access’]

property cert_data

@Field: from json[‘cert_data’] or None if cert_data not available

property status

@Field: from json[‘status’]

property status_message

@Field: from json[‘status_message’]

class hpecp.k8s_cluster.K8sClusterHostConfig(node, role)[source]

Bases: object

Object to represent a pair of host node and the role of the host - master or worker.

classmethod create_from_list(noderole)[source]

Factory method to create K8sClusterHostConfig from a list.

noderole: list

the noderole must only have two values: [ node, role ]

See K8sClusterHostConfig() for the allowed node and role values.

to_dict()[source]

Returns a dict representation of the object.

dict

>>> .to_dict()
{
    'node': '/api/v2/worker/k8shost/12',
    'role': 'master'
}
class hpecp.k8s_cluster.K8sClusterController(client)[source]

Bases: AbstractWaitableResourceController

Class for interacting with K8S Clusters.

An instance of this class is available in the client.ContainerPlatformClient with the attribute name k8s_cluster. The methods of this class can be invoked using client.k8s_cluster.method(). See the example below:

>>> client = ContainerPlatformClient(...).create_session()
>>> client.k8s_cluster.list()
base_resource_path = '/api/v2/k8scluster'

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”

resource_list_path = 'k8sclusters'

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”

resource_class

alias of K8sCluster

status_class

alias of K8sClusterStatus

status_fieldname = 'status'

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

create(name=None, description=None, k8s_version=None, pod_network_range='10.192.0.0/12', service_network_range='10.96.0.0/12', pod_dns_domain='cluster.local', persistent_storage_local=False, persistent_storage_nimble_csi=False, k8shosts_config=[], addons=[], external_identity_server={}, external_groups=[], datafabric=False, datafabric_name=None)[source]

Send an API request to create a K8s Cluster. The cluster creation will be asynchronous - use the wait_for_status() method to wait for the cluster to be created.

For the list of possible statuses see K8sClusterStatus.

name: str

Cluster name - required parameter. Name must be at least 1 character

description: str

Cluster description - defaults to empty string if not provided

k8s_version: str

Kubernetes version to configure. If not specified defaults to the latest version as supported by the rpms.

pod_network_range: str

Network range to be used for kubernetes pods. Defaults to 10.192.0.0/12

addons: list

Addons - See :py:method:`get_available_addons`.

service_network_range: str

Network range to be used for kubernetes services that are exposed with Cluster IP. Defaults to 10.96.0.0/12

pod_dns_domain: str

DNS Domain to be used for kubernetes pods. Defaults to cluster.local

persistent_storage_local: str

Enables local host storage to be available in the kubernetes cluster

persistent_storage_nimble_csi: bool

Set to True to installs the Nimble CSI plugin for Nimble storage to be available in the kubernetes cluster

k8shosts_config: list[K8sClusterHostConfig]

list of K8sClusterHostConfig objects determining which hosts to add and their role (master or worker)

external_identity_server: dict
Example {

“bind_pwd”:”password”, “user_attribute”:”CN”, “bind_type”:”search_bind”, “bind_dn”:”cn=Administrator,CN=Users,DC=samdom,DC=example,DC=com”, “host”:”10.1.0.15”, “group_attribute”:”member”, “security_protocol”:”ldaps”, “base_dn”:”CN=Users,DC=samdom,DC=example,DC=com”, “verify_peer”:false, “type”:”Active Directory”, “port”:636}

datafabric: bool datafabric_name: str optional

str

K8s Cluster ID with the format: ‘/api/v2/k8scluster/[0-9]+’

APIException

get(id, params={}, setup_log=False)[source]

Retrieve a K8s Cluster.

id: str

The k8s cluster ID

k8smanifest()[source]

Retrieve the k8smanifest.

json

K8sManifest

APIException

k8s_supported_versions()[source]

Retrieve list of K8S Supported Versions.

list[str]

List of K8s Supported Versions

APIException

get_available_addons(id=None, k8s_version=None)[source]

Retrieve list of K8S Supported Versions.

id: str

The k8s cluster ID

list[str]

List of available addons

APIException

add_addons(id, addons=[])[source]

Retrieve list of K8S Supported Versions.

id: str

The k8s cluster ID

addons: list

The list of addons to add.

APIException

upgrade_cluster(id, k8s_upgrade_version, worker_upgrade_percent=20)[source]

Upgrade a cluster.

TODO

TODO

APIException

import_cluster(cluster_type, name, description, pod_dns_domain, server_url, ca, bearer_token)[source]

Import a k8s cluster.

TODO

TODO

APIException

import_generic_cluster(name, description, pod_dns_domain, server_url, ca, bearer_token)[source]
import_generic_cluster_with_json(json)[source]

Import a generic k8s cluster.

TODO

TODO

APIException

run_kubectl_command(id, op='apply', yaml='')[source]

Run a kubectl command on k8s cluster.

id: str

The k8s cluster ID (i.e., ‘/api/v2/k8s_cluster/1’)

op: str

op can be either ‘create’, ‘apply’ or ‘delete’

yaml: str

base64 encoding of the yaml file

TODO

APIException