Backend - OpenShift

class conu.backend.origin.backend.OpenshiftBackend(api_key=None, logging_level=20, logging_kwargs=None)

Bases: conu.backend.k8s.backend.K8sBackend

ContainerClass

alias of conu.apidefs.container.Container

ImageClass

alias of conu.apidefs.image.Image

__init__(api_key=None, logging_level=20, logging_kwargs=None)

This method serves as a configuration interface for conu.

Parameters:
  • api_key – str, Bearer API token
  • logging_level – int, control logger verbosity: see logging.{DEBUG,INFO,ERROR}
  • logging_kwargs – dict, additional keyword arguments for logger set up, for more info see docstring of set_logging function
all_pods_are_ready(app_name)

Check if all pods are ready for specific app :param app_name: str, name of the app :return: bool

clean_project(app_name=None, delete_all=False)

Delete objects in current project in OpenShift cluster. If both parameters are passed, delete all objects in project. :param app_name: str, name of app :param delete_all: bool, if true delete all objects in current project :return: None

cleanup_containers()

Remove containers associated with this backend instance

Returns:None
cleanup_deployments()

Delete all deployments created in namespaces associated with this backend :return: None

cleanup_images()

Remove images associated with this backend instance

Returns:None
cleanup_namespaces()

Delete all namespaces created by this backend :return: None

cleanup_pods()

Delete all pods created in namespaces associated with this backend :return: None

cleanup_services()

Delete all services created in namespaces associated with this backend :return: None

cleanup_volumes()

Remove volumes associated with this backend instance

Returns:None
create_app_from_template(image, name, template, name_in_template, other_images, oc_new_app_args, project)

Helper function to create app from template :param image: image to be used as builder image :param name: name of app from template :param template: str, url or local path to a template to use :param name_in_template: dict, {repository:tag} image name used in the template :param other_images: list of dict, some templates need other image to be pushed into the

OpenShift registry, specify them in this parameter as list of dict [{<image>:<tag>}], where “<image>” is DockerImage and “<tag>” is a tag under which the image should be available in the OpenShift registry.
Parameters:
  • oc_new_app_args – additional parameters for the oc new-app
  • project – project where app should be created
Returns:

None

create_namespace()

Create namespace with random name :return: name of new created namespace

create_new_app_from_source(image, project, source=None, oc_new_app_args=None)

Deploy app using source-to-image in OpenShift cluster using ‘oc new-app’ :param image: image to be used as builder image :param project: project where app should be created :param source: source used to extend the image, can be path or url :param oc_new_app_args: additional parameters for the oc new-app :return: str, name of the app

delete_namespace(name)

Delete namespace with specific name :param name: str, namespace to delete :return: None

deploy_image(image, oc_new_app_args, project, name=None)

Deploy image in OpenShift cluster using ‘oc new-app’ :param image: DockerImage, image to be deployed :param oc_new_app_args: additional parameters for the oc new-app, env variables etc. :param project: project where app should be created :param name:str, name of application, if None random name is generated :return: str, name of the app

get_logs(name)

Obtain cluster status and logs from all pods and print them using logger. This method is useful for debugging. :param name: str, name of app generated by oc new-app :return: str, cluster status and logs from all pods

get_status()

Get status of OpenShift cluster, similar to oc status :return: str

http_request(path='/', method='GET', host=None, port=None, json=False, data=None)

perform a HTTP request

Parameters:
  • path – str, path within the request, e.g. “/api/version”
  • method – str, HTTP method
  • host – str, if None, set to 127.0.0.1
  • port – str or int, if None, set to 8080
  • json – bool, should we expect json?
  • data – data to send (can be dict, list, str)
Returns:

dict

list_containers()

list all available containers for this backend

Returns:collection of instances of conu.apidefs.container.Container
list_deployments()

List all available deployments.

Returns:collection of instances of conu.backend.k8s.deployment.Deployment
list_images()

list all available images for this backend

Returns:collection of instances of conu.apidefs.image.Image
list_pods()

List all available pods.

Returns:collection of instances of conu.backend.k8s.pod.Pod
list_services()

List all available services.

Returns:collection of instances of conu.backend.k8s.service.Service
request_service(app_name, port, expected_output=None)

Make request on service of app. If there is connection error function return False. :param app_name: str, name of the app :param expected_output: str, If not None method will check output returned from request

and try to find matching string.
Parameters:port – str or int, port of the service
Returns:bool, True if connection was established False if there was connection error
start_build(build, args=None)

Start new build, raise exception if build failed :param build: str, name of the build :param args: list of str, another args of ‘oc start-build’ commands :return: None

wait_for_service(app_name, port, expected_output=None, timeout=100)

Block until service is not ready to accept requests, raises an exc ProbeTimeout if timeout is reached :param app_name: str, name of the app :param port: str or int, port of the service :param expected_output: If not None method will check output returned from request

and try to find matching string.
Parameters:timeout – int or float (seconds), time to wait for pod to run
Returns:None