コード例 #1
0
def SetIamPolicy(lake_ref, policy):
    """Set Iam Policy request."""
    set_iam_policy_req = dataplex_api.GetMessageModule(
    ).DataplexProjectsLocationsLakesSetIamPolicyRequest(
        resource=lake_ref.RelativeName(),
        googleIamV1SetIamPolicyRequest=dataplex_api.GetMessageModule(
        ).GoogleIamV1SetIamPolicyRequest(policy=policy))
    return dataplex_api.GetClientInstance(
    ).projects_locations_lakes.SetIamPolicy(set_iam_policy_req)
コード例 #2
0
def GenerateSessionSpec(args):
    """Generate SessionSpec From Arguments."""
    module = dataplex_api.GetMessageModule()
    session_spec = module.GoogleCloudDataplexV1EnvironmentSessionSpec(
        enableFastStartup=args.session_enable_fast_startup,
        maxIdleDuration=args.session_max_idle_duration)
    return session_spec
コード例 #3
0
    def Run(self, args):
        environment_ref = args.CONCEPTS.environment.Parse()
        dataplex_client = dataplex_util.GetClientInstance()
        create_req_op = dataplex_client.projects_locations_lakes_environments.Create(
            dataplex_util.GetMessageModule(
            ).DataplexProjectsLocationsLakesEnvironmentsCreateRequest(
                environmentId=environment_ref.Name(),
                parent=environment_ref.Parent().RelativeName(),
                validateOnly=args.validate_only,
                googleCloudDataplexV1Environment=environment.
                GenerateEnvironmentForCreateRequest(args)))

        validate_only = getattr(args, 'validate_only', False)
        if validate_only:
            log.status.Print('Validation complete.')
            return

        async_ = getattr(args, 'async_', False)
        if not async_:
            response = environment.WaitForOperation(create_req_op)
            log.CreatedResource(
                response.name,
                details=
                'Environment created in lake [{0}] in project [{1}] with location [{2}]'
                .format(environment_ref.lakesId, environment_ref.projectsId,
                        environment_ref.locationsId))
            return response

        log.status.Print(
            'Creating environment with path [{0}] and operation [{1}].'.format(
                environment_ref, create_req_op.name))
        return create_req_op
コード例 #4
0
def GenerateCsvOptions(args):
    return dataplex_api.GetMessageModule(
    ).GoogleCloudDataplexV1ZoneDiscoverySpecCsvOptions(
        delimiter=args.csv_delimiter,
        disableTypeInference=args.csv_disable_type_inference,
        encoding=args.csv_encoding,
        headerRows=args.csv_header_rows)
コード例 #5
0
def AddIamPolicyBinding(lake_ref, member, role):
    """Add iam policy binding request."""
    policy = GetIamPolicy(lake_ref)
    iam_util.AddBindingToIamPolicy(
        dataplex_api.GetMessageModule().GoogleIamV1Binding, policy, member,
        role)
    return SetIamPolicy(lake_ref, policy)
コード例 #6
0
    def Run(self, args):
        update_mask = environment.GenerateUpdateMask(args)
        if len(update_mask) < 1:
            raise exceptions.HttpException(
                'Update commands must specify at least one additional parameter to change.'
            )

        environment_ref = args.CONCEPTS.environment.Parse()
        dataplex_client = dataplex_util.GetClientInstance()
        message = dataplex_util.GetMessageModule()
        update_req_op = dataplex_client.projects_locations_lakes_environments.Patch(
            message.DataplexProjectsLocationsLakesEnvironmentsPatchRequest(
                name=environment_ref.RelativeName(),
                validateOnly=args.validate_only,
                updateMask=u','.join(update_mask),
                googleCloudDataplexV1Environment=environment.
                GenerateEnvironmentForUpdateRequest(args)))

        validate_only = getattr(args, 'validate_only', False)
        if validate_only:
            log.status.Print('Validation complete.')
            return

        async_ = getattr(args, 'async_', False)
        if not async_:
            response = environment.WaitForOperation(update_req_op)
            log.UpdatedResource(environment_ref,
                                details='Operation was successful.')
            return response

        log.status.Print('Updating [{0}] with operation [{1}].'.format(
            environment_ref, update_req_op.name))
        return update_req_op
コード例 #7
0
    def Run(self, args):
        asset_ref = args.CONCEPTS.asset.Parse()
        dataplex_client = dataplex_util.GetClientInstance()
        create_req_op = dataplex_client.projects_locations_lakes_zones_assets.Create(
            dataplex_util.GetMessageModule(
            ).DataplexProjectsLocationsLakesZonesAssetsCreateRequest(
                assetId=asset_ref.Name(),
                parent=asset_ref.Parent().RelativeName(),
                validateOnly=args.validate_only,
                googleCloudDataplexV1Asset=asset.GenerateAssetForCreateRequest(
                    args)))
        validate_only = getattr(args, 'validate_only', False)
        if validate_only:
            log.status.Print('Validation complete.')
            return

        async_ = getattr(args, 'async_', False)
        if not async_:
            asset.WaitForOperation(create_req_op)
            log.CreatedResource(asset_ref.Name(),
                                details='Asset created in [{0}]'.format(
                                    asset_ref.Parent().RelativeName()))
            return

        log.status.Print('Creating [{0}] with operation [{1}].'.format(
            asset_ref, create_req_op.name))
コード例 #8
0
    def Run(self, args):
        update_mask = lake.GenerateUpdateMask(args)
        if len(update_mask) < 1:
            raise exceptions.HttpException(
                'Update commands must specify at least one additional parameter to change.'
            )

        lake_ref = args.CONCEPTS.lake.Parse()
        dataplex_client = dataplex_util.GetClientInstance()
        message = dataplex_util.GetMessageModule()
        update_req_op = dataplex_client.projects_locations_lakes.Patch(
            message.DataplexProjectsLocationsLakesPatchRequest(
                name=lake_ref.RelativeName(),
                validateOnly=args.validate_only,
                updateMask=u','.join(update_mask),
                googleCloudDataplexV1Lake=message.GoogleCloudDataplexV1Lake(
                    description=args.description,
                    displayName=args.display_name,
                    metastore=message.GoogleCloudDataplexV1LakeMetastore(
                        service=args.metastore_service),
                    labels=dataplex_util.CreateLabels(
                        message.GoogleCloudDataplexV1Lake, args))))
        validate_only = getattr(args, 'validate_only', False)
        if validate_only:
            log.status.Print('Validation complete with errors:')
            return update_req_op

        async_ = getattr(args, 'async_', False)
        if not async_:
            lake.WaitForOperation(update_req_op)
            log.UpdatedResource(lake_ref, details='Operation was sucessful.')
            return

        log.status.Print('Updating [{0}] with operation [{1}].'.format(
            lake_ref, update_req_op.name))
コード例 #9
0
    def Run(self, args):
        """Constructs and sends request.

    Args:
      args: argparse.Namespace, An object that contains the values for the
        arguments specified in the .Args() method.
    """
        # We extract lake reference, instead of content reference as content id
        # is not provided at the time of create content and is auto-generated
        # and returned in response.
        lake_ref = args.CONCEPTS.lake.Parse()
        dataplex_client = dataplex_util.GetClientInstance()
        content_response = dataplex_client.projects_locations_lakes_contentitems.Create(
            dataplex_util.GetMessageModule(
            ).DataplexProjectsLocationsLakesContentitemsCreateRequest(
                parent=lake_ref.RelativeName(),
                validateOnly=args.validate_only,
                googleCloudDataplexV1Content=content.
                GenerateContentForCreateRequest(args)))

        validate_only = getattr(args, 'validate_only', False)
        if validate_only:
            log.status.Print('Validation complete.')
            return

        log.CreatedResource(
            content_response.name,
            details=
            'Content created in lake [{0}] in project [{1}] with location [{2}]'
            .format(lake_ref.lakesId, lake_ref.projectsId,
                    lake_ref.locationsId))
コード例 #10
0
    def Run(self, args):
        lake_ref = args.CONCEPTS.lake.Parse()
        dataplex_client = dataplex_util.GetClientInstance()
        message = dataplex_util.GetMessageModule()
        create_req_op = dataplex_client.projects_locations_lakes.Create(
            message.DataplexProjectsLocationsLakesCreateRequest(
                lakeId=lake_ref.Name(),
                parent=lake_ref.Parent().RelativeName(),
                validateOnly=args.validate_only,
                googleCloudDataplexV1Lake=message.GoogleCloudDataplexV1Lake(
                    description=args.description,
                    displayName=args.display_name,
                    labels=dataplex_util.CreateLabels(
                        message.GoogleCloudDataplexV1Lake, args),
                    metastore=message.GoogleCloudDataplexV1LakeMetastore(
                        service=args.metastore_service))))

        validate_only = getattr(args, 'validate_only', False)
        if validate_only:
            log.status.Print('Validation complete.')
            return

        async_ = getattr(args, 'async_', False)
        if not async_:
            lake.WaitForOperation(create_req_op)
            log.CreatedResource(lake_ref.Name(),
                                details='Lake created in [{0}]'.format(
                                    lake_ref.Parent().RelativeName()))
            return

        log.status.Print('Creating [{0}] with operation [{1}].'.format(
            lake_ref, create_req_op.name))
コード例 #11
0
def GetIamPolicy(lake_ref):
    """Get Iam Policy request."""
    get_iam_policy_req = dataplex_api.GetMessageModule(
    ).DataplexProjectsLocationsLakesGetIamPolicyRequest(
        resource=lake_ref.RelativeName())
    return dataplex_api.GetClientInstance(
    ).projects_locations_lakes.GetIamPolicy(get_iam_policy_req)
コード例 #12
0
def GenerateZoneForUpdateRequest(args):
    """Create Zone for Message Update Requests."""
    module = dataplex_api.GetMessageModule()
    return module.GoogleCloudDataplexV1Zone(
        description=args.description,
        displayName=args.display_name,
        labels=dataplex_api.CreateLabels(module.GoogleCloudDataplexV1Zone,
                                         args),
        discoverySpec=GenerateDiscoverySpec(args))
コード例 #13
0
def GenerateDiscoverySpec(args):
    return dataplex_api.GetMessageModule(
    ).GoogleCloudDataplexV1ZoneDiscoverySpec(
        enabled=args.discovery_enabled,
        includePatterns=args.discovery_include_patterns,
        excludePatterns=args.discovery_exclude_patterns,
        schedule=args.discovery_schedule,
        csvOptions=GenerateCsvOptions(args),
        jsonOptions=GenerateJsonOptions(args))
コード例 #14
0
def GenerateSqlScript(args):
    """Creates SQL Script field for Content Message Create/Update Requests."""
    module = dataplex_api.GetMessageModule()
    query_engine_field = module.GoogleCloudDataplexV1ContentSqlScript
    sql_script = module.GoogleCloudDataplexV1ContentSqlScript()
    if args.query_engine:
        sql_script.engine = query_engine_field.EngineValueValuesEnum(
            args.query_engine)
    return sql_script
コード例 #15
0
def GenerateNotebook(args):
    """Creates Notebook field for Content Message Create/Update Requests."""
    module = dataplex_api.GetMessageModule()
    kernel_type_field = module.GoogleCloudDataplexV1ContentNotebook
    notebook = module.GoogleCloudDataplexV1ContentNotebook()
    if args.kernel_type:
        notebook.kernelType = kernel_type_field.KernelTypeValueValuesEnum(
            args.kernel_type)
    return notebook
コード例 #16
0
def GenerateEnvironmentForUpdateRequest(args):
    """Create Environment for Message Update Requests."""
    module = dataplex_api.GetMessageModule()
    return module.GoogleCloudDataplexV1Environment(
        description=args.description,
        displayName=args.display_name,
        labels=dataplex_api.CreateLabels(
            module.GoogleCloudDataplexV1Environment, args),
        infrastructureSpec=GenerateInfrastructureSpec(args),
        sessionSpec=GenerateSessionSpec(args))
コード例 #17
0
def GenerateZoneForCreateRequest(args):
    """Create Zone for Message Create Requests."""
    module = dataplex_api.GetMessageModule()
    return module.GoogleCloudDataplexV1Zone(
        description=args.description,
        displayName=args.display_name,
        labels=dataplex_api.CreateLabels(module.GoogleCloudDataplexV1Zone,
                                         args),
        type=module.GoogleCloudDataplexV1Zone.TypeValueValuesEnum(args.type),
        discoverySpec=GenerateDiscoverySpec(args),
        resourceSpec=module.GoogleCloudDataplexV1ZoneResourceSpec(
            locationType=module.GoogleCloudDataplexV1ZoneResourceSpec.
            LocationTypeValueValuesEnum(args.resource_location_type)))
コード例 #18
0
def GenerateContentForUpdateRequest(args):
    """Creates Content for Message Update Requests."""
    module = dataplex_api.GetMessageModule()
    content = module.GoogleCloudDataplexV1Content(
        dataText=args.data_text,
        description=args.description,
        labels=dataplex_api.CreateLabels(module.GoogleCloudDataplexV1Content,
                                         args),
        path=args.path)
    if args.kernel_type:
        content.notebook = GenerateNotebook(args)
    if args.query_engine:
        content.sqlScript = GenerateSqlScript(args)
    return content
コード例 #19
0
def GenerateInfrastructureSpec(args):
    """Generate InfrastructureSpec From Arguments."""
    module = dataplex_api.GetMessageModule()
    compute_resource = module.GoogleCloudDataplexV1EnvironmentInfrastructureSpecComputeResources(
        diskSizeGb=args.compute_disk_size_gb,
        nodeCount=args.compute_node_count,
        maxNodeCount=args.compute_max_node_count)
    os_image_runtime = module.GoogleCloudDataplexV1EnvironmentInfrastructureSpecOsImageRuntime(
        imageVersion=args.os_image_version,
        javaLibraries=args.os_image_java_libraries,
        pythonPackages=args.os_image_python_packages,
        properties=args.os_image_properties)
    infrastructure_spec = module.GoogleCloudDataplexV1EnvironmentInfrastructureSpec(
        compute=compute_resource, osImage=os_image_runtime)
    return infrastructure_spec
コード例 #20
0
def GenerateAssetForCreateRequest(args):
    """Create Asset for Message Create Requests."""
    module = dataplex_api.GetMessageModule()
    resource_spec_field = module.GoogleCloudDataplexV1AssetResourceSpec
    resource_spec = module.GoogleCloudDataplexV1AssetResourceSpec(
        name=args.resource_name,
        type=resource_spec_field.TypeValueValuesEnum(args.resource_type))
    request = module.GoogleCloudDataplexV1Asset(
        description=args.description,
        displayName=args.display_name,
        labels=dataplex_api.CreateLabels(module.GoogleCloudDataplexV1Asset,
                                         args),
        resourceSpec=resource_spec)
    discovery = GenerateDiscoverySpec(args)
    if discovery != module.GoogleCloudDataplexV1AssetDiscoverySpec():
        setattr(request, 'discoverySpec', discovery)
    return request
コード例 #21
0
    def Run(self, args):
        update_mask = content.GenerateUpdateMask(args)
        if len(update_mask) < 1:
            raise exceptions.HttpException(
                'Update commands must specify at least one additional parameter to change.'
            )

        content_ref = args.CONCEPTS.content.Parse()
        dataplex_client = dataplex_util.GetClientInstance()
        dataplex_client.projects_locations_lakes_contentitems.Patch(
            dataplex_util.GetMessageModule(
            ).DataplexProjectsLocationsLakesContentitemsPatchRequest(
                name=content_ref.RelativeName(),
                validateOnly=args.validate_only,
                updateMask=u','.join(update_mask),
                googleCloudDataplexV1Content=content.
                GenerateContentForUpdateRequest(args)))
        validate_only = getattr(args, 'validate_only', False)
        if validate_only:
            log.status.Print('Validation complete.')
            return

        log.UpdatedResource(content_ref)
コード例 #22
0
def GenerateDiscoverySpec(args):
    """Create Discovery Spec for Assets."""
    module = dataplex_api.GetMessageModule()

    discovery_spec = module.GoogleCloudDataplexV1AssetDiscoverySpec(
        enabled=args.discovery_enabled,
        includePatterns=args.discovery_include_patterns,
        excludePatterns=args.discovery_exclude_patterns)

    if args.discovery_schedule:
        discovery_spec.schedule = args.discovery_schedule

    csv_options = GenerateCsvOptions(args)
    if csv_options != module.GoogleCloudDataplexV1AssetDiscoverySpecCsvOptions(
    ):
        discovery_spec.csvOptions = csv_options

    json_options = GenerateJsonOptions(args)
    if json_options != module.GoogleCloudDataplexV1AssetDiscoverySpecJsonOptions(
    ):
        discovery_spec.jsonOptions = json_options

    return discovery_spec
コード例 #23
0
def SetIamPolicyFromFile(lake_ref, policy_file):
    """Set iam policy binding request from file."""
    policy = iam_util.ParsePolicyFile(
        policy_file,
        dataplex_api.GetMessageModule().GoogleIamV1Policy)
    return SetIamPolicy(lake_ref, policy)
コード例 #24
0
def GenerateJsonOptions(args):
    return dataplex_api.GetMessageModule(
    ).GoogleCloudDataplexV1ZoneDiscoverySpecJsonOptions(
        encoding=args.json_encoding,
        disableTypeInference=args.json_disable_type_inference)