
    Vh                     b    d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ d Zd Zed	k(  r e        yy)
    )absolute_importdivisionprint_functiona  

module: openshift_build

short_description: Start a new build or Cancel running, pending, or new builds.

version_added: "2.3.0"

author:
  - Aubin Bikouo (@abikouo)

description:
  - This module starts a new build from the provided build config or build name.
  - This module also cancel a new, pending or running build by requesting a graceful shutdown of the build.
    There may be a delay between requesting the build and the time the build is terminated.
  - This can also restart a new build when the current is cancelled.
  - Analogous to C(oc cancel-build) and C(oc start-build).

extends_documentation_fragment:
  - kubernetes.core.k8s_auth_options

options:
  state:
    description:
      - Determines if a Build should be started ,cancelled or restarted.
      - When set to C(restarted) a new build will be created after the current build is cancelled.
    choices:
      - started
      - cancelled
      - restarted
    default: started
    type: str
  build_name:
    description:
    - Specify the name of a build which should be re-run.
    - Mutually exclusive with parameter I(build_config_name).
    type: str
  build_config_name:
    description:
    - Specify the name of a build config from which a new build will be run.
    - Mutually exclusive with parameter I(build_name).
    type: str
  namespace:
    description:
    - Specify the namespace for the build or the build config.
    type: str
    required: True
  build_args:
    description:
    - Specify a list of key-value pair to pass to Docker during the build.
    type: list
    elements: dict
    suboptions:
      name:
        description:
          - docker build argument name.
        type: str
        required: true
      value:
        description:
          - docker build argument value.
        type: str
        required: true
  commit:
    description:
    - Specify the source code commit identifier the build should use;
      requires a build based on a Git repository.
    type: str
  env_vars:
    description:
    - Specify a list of key-value pair for an environment variable to set for the build container.
    type: list
    elements: dict
    suboptions:
      name:
        description:
          - Environment variable name.
        type: str
        required: true
      value:
        description:
          - Environment variable value.
        type: str
        required: true
  incremental:
    description:
    - Overrides the incremental setting in a source-strategy build, ignored if not specified.
    type: bool
  no_cache:
    description:
    - Overrides the noCache setting in a docker-strategy build, ignored if not specified.
    type: bool
  wait:
    description:
    - When C(state=started), specify whether to wait for a build to complete
      and exit with a non-zero return code if the build fails.
    - When I(state=cancelled), specify whether to wait for a build phase to be Cancelled.
    default: False
    type: bool
  wait_sleep:
    description:
    - Number of seconds to sleep between checks.
    - Ignored if C(wait=false).
    default: 5
    type: int
  wait_timeout:
    description:
    - How long in seconds to wait for a build to complete.
    - Ignored if C(wait=false).
    default: 120
    type: int
  build_phases:
    description:
    - List of state for build to cancel.
    - Ignored when C(state=started).
    type: list
    elements: str
    choices:
      - New
      - Pending
      - Running
    default: []

requirements:
  - python >= 3.6
  - kubernetes >= 12.0.0
aW  
# Starts build from build config default/hello-world
- name: Starts build from build config
  community.okd.openshift_build:
    namespace: default
    build_config_name: hello-world

# Starts build from a previous build "default/hello-world-1"
- name: Starts build from a previous build
  community.okd.openshift_build:
    namespace: default
    build_name: hello-world-1

# Cancel the build with the given name
- name: Cancel build from default namespace
  community.okd.openshift_build:
    namespace: "default"
    build_name: ruby-build-1
    state: cancelled

# Cancel the named build and create a new one with the same parameters
- name: Cancel build from default namespace and create a new one
  community.okd.openshift_build:
    namespace: "default"
    build_name: ruby-build-1
    state: restarted

# Cancel all builds created from 'ruby-build' build configuration that are in 'new' state
- name: Cancel build from default namespace and create a new one
  community.okd.openshift_build:
    namespace: "default"
    build_config_name: ruby-build
    build_phases:
      - New
    state: cancelled
a  
builds:
  description:
  - The builds that were started/cancelled.
  returned: success
  type: complex
  contains:
    api_version:
      description: The versioned schema of this representation of an object.
      returned: success
      type: str
    kind:
      description: Represents the REST resource this object represents.
      returned: success
      type: str
    metadata:
      description: Standard object metadata. Includes name, namespace, annotations, labels, etc.
      returned: success
      type: dict
    spec:
      description: Specific attributes of the build.
      returned: success
      type: dict
    status:
      description: Current status details for the object.
      returned: success
      type: dict
N)AUTH_ARG_SPECc                     t        j                  t              } t        t        dd      t        dd            }| j	                  t        t        dg dd      t        dd	|
      t        d      t        dd	|
      t        d      t        d      t        dd      t        d      t        d      t        dd      t        dd      t        dd      t        ddg g d                   | S )NstrT)typerequired)namevalue)started	cancelled	restartedr   )r	   choicesdefaultlistdict)r	   elementsoptions)r	   boolF)r	   r   int   x   )NewPendingRunning)r	   r   r   r   )state
build_argscommitenv_vars
build_namebuild_config_name	namespaceincrementalno_cachewait
wait_sleepwait_timeoutbuild_phases)copydeepcopyr   r   update)argsargs_optionss     q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/okd/plugins/modules/openshift_build.pyargument_specr0      s    =='Dut,Ded4SL 	KK=!
 &,OU#vM'".5&)v&65125#65	#	
4 K    c                  b    dg} ddl m}  |t               | ddgg      }|j                          y )N)r!   r"   r   )OpenShiftBuildsr!   r"   )r0   mutually_exclusiverequired_one_of)Gansible_collections.community.okd.plugins.module_utils.openshift_buildsr3   r0   
run_module)r4   r3   modules      r/   mainr9      sF    + #o- #
	F r1   __main__)
__future__r   r   r   r	   __metaclass__DOCUMENTATIONEXAMPLESRETURNr*   Dansible_collections.kubernetes.core.plugins.module_utils.args_commonr   r0   r9   __name__ r1   r/   <module>rC      sT    A @~@#J
< 
!H* zF r1   