Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handlers for missing entitlements for Data Services #46

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 58 additions & 16 deletions src/cdpy/datahub.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@

from cdpy.common import CdpSdkBase, Squelch, CdpError, CdpWarning

ENTITLEMENT_DISABLED='Datahubs not enabled on CDP Tenant'


class CdpyDatahub(CdpSdkBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def describe_cluster(self, name):
return self.sdk.call(
svc='datahub', func='describe_cluster', ret_field='cluster', squelch=[Squelch('NOT_FOUND')],
svc='datahub', func='describe_cluster', ret_field='cluster', squelch=[
Squelch('NOT_FOUND'),
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
clusterName=name
)

def list_clusters(self, environment_name=None):
return self.sdk.call(
svc='datahub', func='list_clusters', ret_field='clusters', squelch=[
Squelch(value='INVALID_ARGUMENT', default=list(),
warning='No Datahubs found in Tenant or provided Environment %s' % str(environment_name))
warning='No Datahubs found in Tenant or provided Environment %s' % str(environment_name)),
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
environmentName=environment_name
)
Expand All @@ -31,8 +37,10 @@ def describe_all_clusters(self, environment_name=None):
def list_cluster_templates(self, retries=3, delay=5):
# Intermittent timeout issue in CDP 7.2.10, should be reverted to bare listing in 7.2.12
resp = self.sdk.call(
svc='datahub', func='list_cluster_templates', ret_field='clusterTemplates',
ret_error=True
svc='datahub', func='list_cluster_templates', ret_field='clusterTemplates', squelch=[
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
ret_error=True # if not a Squelch-able error, return for further review
)
if isinstance(resp, CdpError):
if retries > 0:
Expand All @@ -49,38 +57,72 @@ def list_cluster_templates(self, retries=3, delay=5):
return resp

def describe_cluster_template(self, name):
return self.sdk.call(svc='datahub', func='describe_cluster_template', ret_field='clusterTemplate', squelch=[
Squelch(value='NOT_FOUND')], clusterTemplateName=name)
return self.sdk.call(
svc='datahub', func='describe_cluster_template', squelch=[
Squelch(value='NOT_FOUND'),
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
ret_field='clusterTemplate', clusterTemplateName=name
)

def delete_cluster(self, name):
return self.sdk.call(svc='datahub', func='delete_cluster', clusterName=name)
return self.sdk.call(
svc='datahub', func='delete_cluster', squelch=[
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
clusterName=name
)

def delete_cluster_templates(self, names):
names = names if isinstance(names, list) else [names]
return self.sdk.call(svc='datahub', func='delete_cluster_templates', squelch=[Squelch(value='NOT_FOUND')],
ret_field='clusterTemplates', clusterTemplateNames=names)
return self.sdk.call(
svc='datahub', func='delete_cluster_templates', squelch=[
Squelch(value='NOT_FOUND'),
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
ret_field='clusterTemplates', clusterTemplateNames=names
)

def create_cluster_template(self, name, description, content):
return self.sdk.call(
svc='datahub', func='create_cluster_template', ret_field='clusterTemplate',
clusterTemplateName=name, description=description, clusterTemplateContent=content
svc='datahub', func='create_cluster_template', squelch=[
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
ret_field='clusterTemplate', clusterTemplateName=name,
description=description, clusterTemplateContent=content
)

def list_cluster_definitions(self):
return self.sdk.call(svc='datahub', func='list_cluster_definitions', ret_field='clusterDefinitions')
return self.sdk.call(
svc='datahub', func='list_cluster_definitions', squelch=[
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
ret_field='clusterDefinitions'
)

def describe_cluster_definition(self, name):
return self.sdk.call(svc='datahub', func='describe_cluster_definition', ret_field='clusterDefinition', squelch=[
Squelch(value='NOT_FOUND')], clusterDefinitionName=name)
return self.sdk.call(
svc='datahub', func='describe_cluster_definition', squelch=[
Squelch(value='NOT_FOUND'),
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
ret_field='clusterDefinition', clusterDefinitionName=name
)

def start_cluster(self, name):
return self.sdk.call(
svc='datahub', func='start_cluster', squelch=[Squelch('NOT_FOUND')],
svc='datahub', func='start_cluster', squelch=[
Squelch('NOT_FOUND'),
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
clusterName=name
)

def stop_cluster(self, name):
return self.sdk.call(
svc='datahub', func='stop_cluster', squelch=[Squelch('NOT_FOUND')],
svc='datahub', func='stop_cluster', squelch=[
Squelch('NOT_FOUND'),
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
clusterName=name
)
37 changes: 29 additions & 8 deletions src/cdpy/de.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

from cdpy.common import CdpSdkBase, Squelch, CdpcliWrapper

ENTITLEMENT_DISABLED='Data Engineering not enabled on CDP Tenant'


class CdpyDe(CdpSdkBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def describe_vc(self, cluster_id, vc_id):
return self.sdk.call(
svc='de', func='describe_vc', ret_field='vc', squelch=[
Squelch('NOT_FOUND'), Squelch('INVALID_ARGUMENT')
Squelch('NOT_FOUND'), Squelch('INVALID_ARGUMENT'),
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
clusterId=cluster_id,
vcId=vc_id
Expand All @@ -21,14 +25,17 @@ def list_vcs(self, cluster_id):
Squelch(value='NOT_FOUND', default=list()),
Squelch(field='status_code', value='504', default=list(),
warning="No VCS in this Cluster"),
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
clusterId=cluster_id
)

def create_vc(self, name, cluster_id, cpu_requests, memory_requests, chart_value_overrides=None,
runtime_spot_component=None, spark_version=None, acl_users=None):
return self.sdk.call(
svc='de', func='create_vc', ret_field='Vc',
svc='de', func='create_vc', ret_field='Vc', squelch=[
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
name=name,
clusterId=cluster_id,
cpuRequests=cpu_requests,
Expand All @@ -41,22 +48,28 @@ def create_vc(self, name, cluster_id, cpu_requests, memory_requests, chart_value

def delete_vc(self, cluster_id, vc_id):
return self.sdk.call(
svc='de', func='delete_vc', ret_field='status', squelch=[Squelch('NOT_FOUND')],
svc='de', func='delete_vc', ret_field='status', squelch=[
Squelch('NOT_FOUND'),
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
clusterId=cluster_id, vcId=vc_id
)

def describe_service(self, cluster_id):
return self.sdk.call(
svc='de', func='describe_service', ret_field='service', squelch=[
Squelch('NOT_FOUND'), Squelch('INVALID_ARGUMENT')
Squelch('NOT_FOUND'), Squelch('INVALID_ARGUMENT'),
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
clusterId=cluster_id,
)

def list_services(self, env=None, remove_deleted=False):
services = self.sdk.call(
svc='de', func='list_services', ret_field='services', squelch=[
Squelch(value='NOT_FOUND', default=list())], removeDeleted=remove_deleted
Squelch(value='NOT_FOUND', default=list()),
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED, default=list())
], removeDeleted=remove_deleted
)
return [s for s in services if env is None or s['environmentName'] == env]

Expand All @@ -66,7 +79,9 @@ def enable_service(self, name, env, instance_type, minimum_instances, maximum_in
enable_workload_analytics=False, root_volume_size=None, skip_validation=False,
tags=None, use_ssd=False, whitelist_ips=None):
return self.sdk.call(
svc='de', func='enable_service', ret_field='service',
svc='de', func='enable_service', ret_field='service', squelch=[
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
name=name,
env=env,
instanceType=instance_type,
Expand All @@ -88,13 +103,19 @@ def enable_service(self, name, env, instance_type, minimum_instances, maximum_in

def disable_service(self, cluster_id, force=False):
return self.sdk.call(
svc='de', func='disable_service', ret_field='status', squelch=[Squelch('NOT_FOUND')],
svc='de', func='disable_service', ret_field='status', squelch=[
Squelch('NOT_FOUND'),
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
clusterId=cluster_id, force=force
)

def get_kubeconfig(self, cluster_id):
return self.sdk.call(
svc='de', func='get_kubeconfig', ret_field='kubeconfig', squelch=[Squelch('NOT_FOUND')],
svc='de', func='get_kubeconfig', ret_field='kubeconfig', squelch=[
Squelch('NOT_FOUND'),
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
],
clusterId=cluster_id
)

Expand Down
23 changes: 12 additions & 11 deletions src/cdpy/df.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from cdpy.common import CdpSdkBase, Squelch, CdpError, CdpWarning
from cdpcli.extensions.df.createdeployment import CreateDeploymentOperationCaller

ENTITLEMENT_DISABLED='DataFlow not enabled on CDP Tenant'

class CdpyDf(CdpSdkBase):
def __init__(self, *args, **kwargs):
Expand All @@ -15,7 +16,7 @@ def list_services(self, only_enabled=False, env_crn=None, df_crn=None, name=None
Squelch(value='NOT_FOUND', default=list(),
warning='No DataFlow Services found'),
Squelch(value='PATH_DISABLED', default=list(),
warning='DataFlow not enabled on CDP Tenant')
warning=ENTITLEMENT_DISABLED)
],
pageSize=self.sdk.DEFAULT_PAGE_SIZE
)
Expand Down Expand Up @@ -51,7 +52,7 @@ def describe_service(self, df_crn: str = None, env_crn: str = None):
Squelch(value='NOT_FOUND',
warning='No DataFlow Service with crn %s found' % df_crn),
Squelch(value='PATH_DISABLED',
warning='DataFlow not enabled on CDP Tenant'),
warning=ENTITLEMENT_DISABLED),
Squelch(value='PERMISSION_DENIED') # DF GRPC sometimes returns 403 when finishing deletion
],
serviceCrn=resolved_df_crn
Expand Down Expand Up @@ -102,7 +103,7 @@ def list_deployments(self, env_crn=None, df_crn=None, name=None, dep_crn=None, d
Squelch(value='NOT_FOUND', default=list(),
warning='No DataFlow Deployments found'),
Squelch(value='PATH_DISABLED', default=list(),
warning='DataFlow not enabled on CDP Tenant')
warning=ENTITLEMENT_DISABLED)
],
pageSize=self.sdk.DEFAULT_PAGE_SIZE
)
Expand Down Expand Up @@ -143,7 +144,7 @@ def describe_deployment(self, dep_crn=None, df_crn=None, name=None):
Squelch(value='NOT_FOUND',
warning='No DataFlow Deployment with crn %s found' % dep_crn),
Squelch(value='PATH_DISABLED',
warning='DataFlow not enabled on CDP Tenant')
warning=ENTITLEMENT_DISABLED)
],
deploymentCrn=dep_crn
)
Expand All @@ -155,7 +156,7 @@ def list_readyflows(self, name=None):
Squelch(value='NOT_FOUND',
warning='No ReadyFlows found within your CDP Tenant'),
Squelch(value='PATH_DISABLED',
warning='DataFlow not enabled on CDP Tenant')
warning=ENTITLEMENT_DISABLED)
],
)
if name is not None:
Expand All @@ -169,7 +170,7 @@ def list_flow_definitions(self, name=None):
Squelch(value='NOT_FOUND',
warning='No Flow Definitions found within your CDP Tenant Catalog'),
Squelch(value='PATH_DISABLED',
warning='DataFlow not enabled on CDP Tenant')
warning=ENTITLEMENT_DISABLED)
],
)
if name is not None:
Expand All @@ -184,7 +185,7 @@ def describe_readyflow(self, def_crn):
Squelch(value='NOT_FOUND',
warning='No ReadyFlow Definition with crn %s found' % def_crn),
Squelch(value='PATH_DISABLED',
warning='DataFlow not enabled on CDP Tenant')
warning=ENTITLEMENT_DISABLED)
],
readyflowCrn=def_crn
)
Expand All @@ -197,7 +198,7 @@ def import_readyflow(self, def_crn):
Squelch(value='NOT_FOUND',
warning='No ReadyFlow Definition with crn %s found' % def_crn),
Squelch(value='PATH_DISABLED',
warning='DataFlow not enabled on CDP Tenant')
warning=ENTITLEMENT_DISABLED)
],
readyflowCrn=def_crn
)
Expand All @@ -210,7 +211,7 @@ def delete_added_readyflow(self, def_crn):
Squelch(value='NOT_FOUND',
warning='No ReadyFlow Definition with crn %s found' % def_crn),
Squelch(value='PATH_DISABLED',
warning='DataFlow not enabled on CDP Tenant')
warning=ENTITLEMENT_DISABLED)
],
readyflowCrn=def_crn
)
Expand All @@ -223,7 +224,7 @@ def describe_added_readyflow(self, def_crn, sort_versions=True):
Squelch(value='NOT_FOUND',
warning='No ReadyFlow Definition with crn %s found' % def_crn),
Squelch(value='PATH_DISABLED',
warning='DataFlow not enabled on CDP Tenant')
warning=ENTITLEMENT_DISABLED)
],
readyflowCrn=def_crn
)
Expand All @@ -241,7 +242,7 @@ def describe_customflow(self, def_crn, sort_versions=True):
Squelch(value='NOT_FOUND',
warning='No Flow Definition with crn %s found' % def_crn),
Squelch(value='PATH_DISABLED',
warning='DataFlow not enabled on CDP Tenant')
warning=ENTITLEMENT_DISABLED)
],
flowCrn=def_crn
)
Expand Down
Loading