Backend - OpenShift¶
-
class
conu.backend.origin.backend.
OpenshiftBackend
(api_key=None, logging_level=20, logging_kwargs=None, project=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, project=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
- project – str, project name that will be used while working with this backend. It is possible to specify it later, when deploying app. One instance of OpenshiftBackend should work with just one project at time.
-
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, name, template, name_in_template, other_images=None, oc_new_app_args=None, project=None)¶ Helper function to create app from template
Parameters: - image_name – image to be used as builder image
- name – name of app from template
- template – str, url or local path to a template to use
- name_in_template – dict, {repository:tag} image name used in the template
- 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 image name with tag and “<tag>” is a tag under which the image should be available in the OpenShift registry.
- oc_new_app_args – additional parameters for the oc new-app
- project – project where app should be created, default: current project
Returns: None
-
create_namespace
()¶ Create namespace with random name :return: name of new created namespace
-
create_new_app_from_source
(image_name, project=None, source=None, oc_new_app_args=None)¶ Deploy app using source-to-image in OpenShift cluster using ‘oc new-app’ :param image_name: image to be used as builder image :param project: project where app should be created, default: current project :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_name, oc_new_app_args=None, project=None, name=None)¶ Deploy image in OpenShift cluster using ‘oc new-app’ :param image_name: image name with tag :param oc_new_app_args: additional parameters for the oc new-app, env variables etc. :param project: project where app should be created, default: current project :param name:str, name of application, if None random name is generated :return: str, name of the app
-
get_current_project
()¶ Get name of current project using oc project command. Raise ConuException in case of an error. :return: str, project name
-
get_image_registry_url
(image_name)¶ Helper function for obtain registry url of image from it’s name
Parameters: image_name – str, short name of an image, example: - conu:0.5.0 Returns: str, image registry url, example: - 172.30.1.1:5000/myproject/conu:0.5.0
-
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
-
import_image
(imported_image_name, image_name)¶ Import image using oc import-image command.
Parameters: - imported_image_name – str, short name of an image in internal registry, example: - hello-openshift:latest
- image_name – full repository name, example: - docker.io/openshift/hello-openshift:latest
Returns: str, short name in internal registry
-
list_containers
()¶ list all available containers for this backend
Returns: collection of instances of conu.apidefs.container.Container
-
list_deployments
(namespace=None)¶ List all available deployments.
Parameters: namespace – str, if not specified list deployments for all namespaces 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
(namespace=None)¶ List all available pods.
Parameters: namespace – str, if not specified list pods for all namespaces Returns: collection of instances of conu.backend.k8s.pod.Pod
-
list_services
(namespace=None)¶ List all available services.
Parameters: namespace – str, if not specified list services for all namespaces 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.
Parameters: - app_name – str, name of the app
- expected_output – str, If not None method will check output returned from request and try to find matching string.
- 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
Parameters: - app_name – str, name of the app
- port – str or int, port of the service
- expected_output – If not None method will check output returned from request and try to find matching string.
- timeout – int or float (seconds), time to wait for pod to run
Returns: None
-