|  | 
|  | 1 | +#!/usr/bin/env python | 
|  | 2 | +# -*- coding: utf-8 -*- | 
|  | 3 | + | 
|  | 4 | +# Copyright 2021 Cloudera, Inc. All Rights Reserved. | 
|  | 5 | +# | 
|  | 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 7 | +# you may not use this file except in compliance with the License. | 
|  | 8 | +# You may obtain a copy of the License at | 
|  | 9 | +# | 
|  | 10 | +#      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 11 | +# | 
|  | 12 | +# Unless required by applicable law or agreed to in writing, software | 
|  | 13 | +# distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 15 | +# See the License for the specific language governing permissions and | 
|  | 16 | +# limitations under the License. | 
|  | 17 | + | 
|  | 18 | +from ansible.module_utils.basic import AnsibleModule | 
|  | 19 | +from ansible_collections.cloudera.cloud.plugins.module_utils.cdp_common import CdpModule | 
|  | 20 | + | 
|  | 21 | +ANSIBLE_METADATA = {'metadata_version': '1.1', | 
|  | 22 | +                    'status': ['preview'], | 
|  | 23 | +                    'supported_by': 'community'} | 
|  | 24 | + | 
|  | 25 | +DOCUMENTATION = r''' | 
|  | 26 | +--- | 
|  | 27 | +module: df_customflow_info | 
|  | 28 | +short_description: Gather information about CDP DataFlow CustomFlow Definitions | 
|  | 29 | +description: | 
|  | 30 | +    - Gather information about CDP DataFlow CustomFlow Definitions | 
|  | 31 | +author: | 
|  | 32 | +  - "Dan Chaffelson (@chaffelson)" | 
|  | 33 | +requirements: | 
|  | 34 | +  - cdpy | 
|  | 35 | +options: | 
|  | 36 | +  name: | 
|  | 37 | +    description: | 
|  | 38 | +      - If a name is provided, that DataFlow Flow Definition will be described | 
|  | 39 | +    type: str | 
|  | 40 | +    required: False | 
|  | 41 | +  include_details: | 
|  | 42 | +    description: | 
|  | 43 | +      - If set to false, only a summary of each flow is returned | 
|  | 44 | +    type: bool | 
|  | 45 | +    required: False | 
|  | 46 | +    default: True | 
|  | 47 | +
 | 
|  | 48 | +notes: | 
|  | 49 | +  - The feature this module is for is in Technical Preview | 
|  | 50 | +extends_documentation_fragment: | 
|  | 51 | +  - cloudera.cloud.cdp_sdk_options | 
|  | 52 | +  - cloudera.cloud.cdp_auth_options | 
|  | 53 | +''' | 
|  | 54 | + | 
|  | 55 | +EXAMPLES = r''' | 
|  | 56 | +# Note: These examples do not set authentication details. | 
|  | 57 | +
 | 
|  | 58 | +# List summary information about all Custom DataFlow Flow Definitions | 
|  | 59 | +- cloudera.cloud.df_customflow_info: | 
|  | 60 | +
 | 
|  | 61 | +# Gather summary information about a specific DataFlow Flow Definition using a name | 
|  | 62 | +- cloudera.cloud.df_customflow_info: | 
|  | 63 | +    name: my-flow-name | 
|  | 64 | +    include_details: False | 
|  | 65 | +''' | 
|  | 66 | + | 
|  | 67 | +RETURN = r''' | 
|  | 68 | +--- | 
|  | 69 | +flows: | 
|  | 70 | +  description: The listing of CustomFlow Definitions in the DataFlow Catalog in this CDP Tenant | 
|  | 71 | +  type: list | 
|  | 72 | +  returned: always | 
|  | 73 | +  elements: complex | 
|  | 74 | +  contains: | 
|  | 75 | +    crn: | 
|  | 76 | +      description:  The DataFlow Flow Definition's CRN. | 
|  | 77 | +      returned: always | 
|  | 78 | +      type: str | 
|  | 79 | +    name: | 
|  | 80 | +      description: The DataFlow Flow Definition's name. | 
|  | 81 | +      returned: always | 
|  | 82 | +      type: str | 
|  | 83 | +    modifiedTimestamp: | 
|  | 84 | +      description: The timestamp the entry was last modified. | 
|  | 85 | +      returned: always | 
|  | 86 | +      type: int | 
|  | 87 | +    versionCount: | 
|  | 88 | +      description: The number of versions uploaded to the catalog. | 
|  | 89 | +      returned: always | 
|  | 90 | +      type: str | 
|  | 91 | +    artifactType: | 
|  | 92 | +      description: The type of artifact | 
|  | 93 | +      type: str | 
|  | 94 | +      returned: when include_details is False | 
|  | 95 | +    createdTimestamp: | 
|  | 96 | +      description: The created timestamp. | 
|  | 97 | +      returned: when include_details is True | 
|  | 98 | +      type: int | 
|  | 99 | +    author: | 
|  | 100 | +      description: Author of the most recent version. | 
|  | 101 | +      returned: when include_details is True | 
|  | 102 | +      type: str | 
|  | 103 | +    description: | 
|  | 104 | +      description: The artifact description. | 
|  | 105 | +      returned: when include_details is True | 
|  | 106 | +      type: str | 
|  | 107 | +    versions: | 
|  | 108 | +      description: The list of artifactDetail versions. | 
|  | 109 | +      returned: when include_details is True | 
|  | 110 | +      type: array | 
|  | 111 | +      contains: | 
|  | 112 | +        crn: | 
|  | 113 | +          description: The flow version CRN. | 
|  | 114 | +          returned: when include_details is True | 
|  | 115 | +          type: str | 
|  | 116 | +        bucketIdentifier: | 
|  | 117 | +          description: The bucketIdentifier of the flow. | 
|  | 118 | +          returned: when include_details is True | 
|  | 119 | +          type: str | 
|  | 120 | +        author: | 
|  | 121 | +          description: The author of the flow. | 
|  | 122 | +          returned: when include_details is True | 
|  | 123 | +          type: str | 
|  | 124 | +        version: | 
|  | 125 | +          description: The version of the flow. | 
|  | 126 | +          returned: when include_details is True | 
|  | 127 | +          type: int | 
|  | 128 | +        timestamp: | 
|  | 129 | +          description: The timestamp of the flow. | 
|  | 130 | +          returned: when include_details is True | 
|  | 131 | +          type: int | 
|  | 132 | +        deploymentCount: | 
|  | 133 | +          description: The number of deployments of the flow. | 
|  | 134 | +          returned: when include_details is True | 
|  | 135 | +          type: int | 
|  | 136 | +        comments: | 
|  | 137 | +          description: Comments about the flow. | 
|  | 138 | +          returned: when include_details is True | 
|  | 139 | +          type: str | 
|  | 140 | +sdk_out: | 
|  | 141 | +  description: Returns the captured CDP SDK log. | 
|  | 142 | +  returned: when supported | 
|  | 143 | +  type: str | 
|  | 144 | +sdk_out_lines: | 
|  | 145 | +  description: Returns a list of each line of the captured CDP SDK log. | 
|  | 146 | +  returned: when supported | 
|  | 147 | +  type: list | 
|  | 148 | +  elements: str | 
|  | 149 | +''' | 
|  | 150 | + | 
|  | 151 | + | 
|  | 152 | +class DFCustomFlowInfo(CdpModule): | 
|  | 153 | +    def __init__(self, module): | 
|  | 154 | +        super(DFCustomFlowInfo, self).__init__(module) | 
|  | 155 | + | 
|  | 156 | +        # Set variables | 
|  | 157 | +        self.name = self._get_param('name') | 
|  | 158 | +        self.include_details = self._get_param('include_details') | 
|  | 159 | + | 
|  | 160 | +        # Initialize internal values | 
|  | 161 | +        self.listing = [] | 
|  | 162 | + | 
|  | 163 | +        # Initialize return values | 
|  | 164 | +        self.flows = [] | 
|  | 165 | + | 
|  | 166 | +        # Execute logic process | 
|  | 167 | +        self.process() | 
|  | 168 | + | 
|  | 169 | +    @CdpModule._Decorators.process_debug | 
|  | 170 | +    def process(self): | 
|  | 171 | +        self.listing = self.cdpy.df.list_flow_definitions(name=self.name) | 
|  | 172 | +        if self.include_details: | 
|  | 173 | +            self.flows = [ | 
|  | 174 | +                self.cdpy.df.describe_customflow(x['crn']) | 
|  | 175 | +                for x in self.listing | 
|  | 176 | +                if x['artifactType'] == 'flow'  # ReadyFlow have different fields | 
|  | 177 | +            ] | 
|  | 178 | +        else: | 
|  | 179 | +            self.flows = self.listing | 
|  | 180 | + | 
|  | 181 | + | 
|  | 182 | +def main(): | 
|  | 183 | +    module = AnsibleModule( | 
|  | 184 | +        argument_spec=CdpModule.argument_spec( | 
|  | 185 | +            name=dict(required=False, type='str'), | 
|  | 186 | +            include_details=dict(required=False, type='bool', default=True) | 
|  | 187 | +        ), | 
|  | 188 | +        supports_check_mode=True | 
|  | 189 | +    ) | 
|  | 190 | + | 
|  | 191 | +    result = DFCustomFlowInfo(module) | 
|  | 192 | +    output = dict(changed=False, flows=result.flows) | 
|  | 193 | + | 
|  | 194 | +    if result.debug: | 
|  | 195 | +        output.update(sdk_out=result.log_out, sdk_out_lines=result.log_lines) | 
|  | 196 | + | 
|  | 197 | +    module.exit_json(**output) | 
|  | 198 | + | 
|  | 199 | + | 
|  | 200 | +if __name__ == '__main__': | 
|  | 201 | +    main() | 
0 commit comments