Skip to content

Commit eeb420a

Browse files
committed
Add handlers for missing entitlement for Data Services
Signed-off-by: Webster Mudge <[email protected]>
1 parent 36aa59d commit eeb420a

File tree

6 files changed

+170
-52
lines changed

6 files changed

+170
-52
lines changed

src/cdpy/datahub.py

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,28 @@
22

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

5+
ENTITLEMENT_DISABLED='Datahubs not enabled on CDP Tenant'
6+
57

68
class CdpyDatahub(CdpSdkBase):
79
def __init__(self, *args, **kwargs):
810
super().__init__(*args, **kwargs)
911

1012
def describe_cluster(self, name):
1113
return self.sdk.call(
12-
svc='datahub', func='describe_cluster', ret_field='cluster', squelch=[Squelch('NOT_FOUND')],
14+
svc='datahub', func='describe_cluster', ret_field='cluster', squelch=[
15+
Squelch('NOT_FOUND'),
16+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
17+
],
1318
clusterName=name
1419
)
1520

1621
def list_clusters(self, environment_name=None):
1722
return self.sdk.call(
1823
svc='datahub', func='list_clusters', ret_field='clusters', squelch=[
1924
Squelch(value='INVALID_ARGUMENT', default=list(),
20-
warning='No Datahubs found in Tenant or provided Environment %s' % str(environment_name))
25+
warning='No Datahubs found in Tenant or provided Environment %s' % str(environment_name)),
26+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
2127
],
2228
environmentName=environment_name
2329
)
@@ -31,8 +37,10 @@ def describe_all_clusters(self, environment_name=None):
3137
def list_cluster_templates(self, retries=3, delay=5):
3238
# Intermittent timeout issue in CDP 7.2.10, should be reverted to bare listing in 7.2.12
3339
resp = self.sdk.call(
34-
svc='datahub', func='list_cluster_templates', ret_field='clusterTemplates',
35-
ret_error=True
40+
svc='datahub', func='list_cluster_templates', ret_field='clusterTemplates', squelch=[
41+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
42+
],
43+
ret_error=True # if not a Squelch-able error, return for further review
3644
)
3745
if isinstance(resp, CdpError):
3846
if retries > 0:
@@ -49,38 +57,72 @@ def list_cluster_templates(self, retries=3, delay=5):
4957
return resp
5058

5159
def describe_cluster_template(self, name):
52-
return self.sdk.call(svc='datahub', func='describe_cluster_template', ret_field='clusterTemplate', squelch=[
53-
Squelch(value='NOT_FOUND')], clusterTemplateName=name)
60+
return self.sdk.call(
61+
svc='datahub', func='describe_cluster_template', squelch=[
62+
Squelch(value='NOT_FOUND'),
63+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
64+
],
65+
ret_field='clusterTemplate', clusterTemplateName=name
66+
)
5467

5568
def delete_cluster(self, name):
56-
return self.sdk.call(svc='datahub', func='delete_cluster', clusterName=name)
69+
return self.sdk.call(
70+
svc='datahub', func='delete_cluster', squelch=[
71+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
72+
],
73+
clusterName=name
74+
)
5775

5876
def delete_cluster_templates(self, names):
5977
names = names if isinstance(names, list) else [names]
60-
return self.sdk.call(svc='datahub', func='delete_cluster_templates', squelch=[Squelch(value='NOT_FOUND')],
61-
ret_field='clusterTemplates', clusterTemplateNames=names)
78+
return self.sdk.call(
79+
svc='datahub', func='delete_cluster_templates', squelch=[
80+
Squelch(value='NOT_FOUND'),
81+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
82+
],
83+
ret_field='clusterTemplates', clusterTemplateNames=names
84+
)
6285

6386
def create_cluster_template(self, name, description, content):
6487
return self.sdk.call(
65-
svc='datahub', func='create_cluster_template', ret_field='clusterTemplate',
66-
clusterTemplateName=name, description=description, clusterTemplateContent=content
88+
svc='datahub', func='create_cluster_template', squelch=[
89+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
90+
],
91+
ret_field='clusterTemplate', clusterTemplateName=name,
92+
description=description, clusterTemplateContent=content
6793
)
6894

6995
def list_cluster_definitions(self):
70-
return self.sdk.call(svc='datahub', func='list_cluster_definitions', ret_field='clusterDefinitions')
96+
return self.sdk.call(
97+
svc='datahub', func='list_cluster_definitions', squelch=[
98+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
99+
],
100+
ret_field='clusterDefinitions'
101+
)
71102

72103
def describe_cluster_definition(self, name):
73-
return self.sdk.call(svc='datahub', func='describe_cluster_definition', ret_field='clusterDefinition', squelch=[
74-
Squelch(value='NOT_FOUND')], clusterDefinitionName=name)
104+
return self.sdk.call(
105+
svc='datahub', func='describe_cluster_definition', squelch=[
106+
Squelch(value='NOT_FOUND'),
107+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
108+
],
109+
ret_field='clusterDefinition', clusterDefinitionName=name
110+
)
75111

76112
def start_cluster(self, name):
77113
return self.sdk.call(
78-
svc='datahub', func='start_cluster', squelch=[Squelch('NOT_FOUND')],
114+
svc='datahub', func='start_cluster', squelch=[
115+
Squelch('NOT_FOUND'),
116+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
117+
],
79118
clusterName=name
80119
)
81120

82121
def stop_cluster(self, name):
83122
return self.sdk.call(
84-
svc='datahub', func='stop_cluster', squelch=[Squelch('NOT_FOUND')],
123+
svc='datahub', func='stop_cluster', squelch=[
124+
Squelch('NOT_FOUND'),
125+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
126+
],
85127
clusterName=name
86128
)

src/cdpy/de.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
from cdpy.common import CdpSdkBase, Squelch, CdpcliWrapper
44

5+
ENTITLEMENT_DISABLED='Data Engineering not enabled on CDP Tenant'
6+
7+
58
class CdpyDe(CdpSdkBase):
69
def __init__(self, *args, **kwargs):
710
super().__init__(*args, **kwargs)
811

912
def describe_vc(self, cluster_id, vc_id):
1013
return self.sdk.call(
1114
svc='de', func='describe_vc', ret_field='vc', squelch=[
12-
Squelch('NOT_FOUND'), Squelch('INVALID_ARGUMENT')
15+
Squelch('NOT_FOUND'), Squelch('INVALID_ARGUMENT'),
16+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
1317
],
1418
clusterId=cluster_id,
1519
vcId=vc_id
@@ -21,14 +25,17 @@ def list_vcs(self, cluster_id):
2125
Squelch(value='NOT_FOUND', default=list()),
2226
Squelch(field='status_code', value='504', default=list(),
2327
warning="No VCS in this Cluster"),
28+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
2429
],
2530
clusterId=cluster_id
2631
)
2732

2833
def create_vc(self, name, cluster_id, cpu_requests, memory_requests, chart_value_overrides=None,
2934
runtime_spot_component=None, spark_version=None, acl_users=None):
3035
return self.sdk.call(
31-
svc='de', func='create_vc', ret_field='Vc',
36+
svc='de', func='create_vc', ret_field='Vc', squelch=[
37+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
38+
],
3239
name=name,
3340
clusterId=cluster_id,
3441
cpuRequests=cpu_requests,
@@ -41,22 +48,28 @@ def create_vc(self, name, cluster_id, cpu_requests, memory_requests, chart_value
4148

4249
def delete_vc(self, cluster_id, vc_id):
4350
return self.sdk.call(
44-
svc='de', func='delete_vc', ret_field='status', squelch=[Squelch('NOT_FOUND')],
51+
svc='de', func='delete_vc', ret_field='status', squelch=[
52+
Squelch('NOT_FOUND'),
53+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
54+
],
4555
clusterId=cluster_id, vcId=vc_id
4656
)
4757

4858
def describe_service(self, cluster_id):
4959
return self.sdk.call(
5060
svc='de', func='describe_service', ret_field='service', squelch=[
51-
Squelch('NOT_FOUND'), Squelch('INVALID_ARGUMENT')
61+
Squelch('NOT_FOUND'), Squelch('INVALID_ARGUMENT'),
62+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
5263
],
5364
clusterId=cluster_id,
5465
)
5566

5667
def list_services(self, env=None, remove_deleted=False):
5768
services = self.sdk.call(
5869
svc='de', func='list_services', ret_field='services', squelch=[
59-
Squelch(value='NOT_FOUND', default=list())], removeDeleted=remove_deleted
70+
Squelch(value='NOT_FOUND', default=list()),
71+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED, default=list())
72+
], removeDeleted=remove_deleted
6073
)
6174
return [s for s in services if env is None or s['environmentName'] == env]
6275

@@ -66,7 +79,9 @@ def enable_service(self, name, env, instance_type, minimum_instances, maximum_in
6679
enable_workload_analytics=False, root_volume_size=None, skip_validation=False,
6780
tags=None, use_ssd=False, whitelist_ips=None):
6881
return self.sdk.call(
69-
svc='de', func='enable_service', ret_field='service',
82+
svc='de', func='enable_service', ret_field='service', squelch=[
83+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
84+
],
7085
name=name,
7186
env=env,
7287
instanceType=instance_type,
@@ -88,13 +103,19 @@ def enable_service(self, name, env, instance_type, minimum_instances, maximum_in
88103

89104
def disable_service(self, cluster_id, force=False):
90105
return self.sdk.call(
91-
svc='de', func='disable_service', ret_field='status', squelch=[Squelch('NOT_FOUND')],
106+
svc='de', func='disable_service', ret_field='status', squelch=[
107+
Squelch('NOT_FOUND'),
108+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
109+
],
92110
clusterId=cluster_id, force=force
93111
)
94112

95113
def get_kubeconfig(self, cluster_id):
96114
return self.sdk.call(
97-
svc='de', func='get_kubeconfig', ret_field='kubeconfig', squelch=[Squelch('NOT_FOUND')],
115+
svc='de', func='get_kubeconfig', ret_field='kubeconfig', squelch=[
116+
Squelch('NOT_FOUND'),
117+
Squelch(value='PATH_DISABLED', warning=ENTITLEMENT_DISABLED)
118+
],
98119
clusterId=cluster_id
99120
)
100121

src/cdpy/df.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from cdpy.common import CdpSdkBase, Squelch, CdpError, CdpWarning
44
from cdpcli.extensions.df.createdeployment import CreateDeploymentOperationCaller
55

6+
ENTITLEMENT_DISABLED='DataFlow not enabled on CDP Tenant'
67

78
class CdpyDf(CdpSdkBase):
89
def __init__(self, *args, **kwargs):
@@ -15,7 +16,7 @@ def list_services(self, only_enabled=False, env_crn=None, df_crn=None, name=None
1516
Squelch(value='NOT_FOUND', default=list(),
1617
warning='No DataFlow Services found'),
1718
Squelch(value='PATH_DISABLED', default=list(),
18-
warning='DataFlow not enabled on CDP Tenant')
19+
warning=ENTITLEMENT_DISABLED)
1920
],
2021
pageSize=self.sdk.DEFAULT_PAGE_SIZE
2122
)
@@ -51,7 +52,7 @@ def describe_service(self, df_crn: str = None, env_crn: str = None):
5152
Squelch(value='NOT_FOUND',
5253
warning='No DataFlow Service with crn %s found' % df_crn),
5354
Squelch(value='PATH_DISABLED',
54-
warning='DataFlow not enabled on CDP Tenant'),
55+
warning=ENTITLEMENT_DISABLED),
5556
Squelch(value='PERMISSION_DENIED') # DF GRPC sometimes returns 403 when finishing deletion
5657
],
5758
serviceCrn=resolved_df_crn
@@ -102,7 +103,7 @@ def list_deployments(self, env_crn=None, df_crn=None, name=None, dep_crn=None, d
102103
Squelch(value='NOT_FOUND', default=list(),
103104
warning='No DataFlow Deployments found'),
104105
Squelch(value='PATH_DISABLED', default=list(),
105-
warning='DataFlow not enabled on CDP Tenant')
106+
warning=ENTITLEMENT_DISABLED)
106107
],
107108
pageSize=self.sdk.DEFAULT_PAGE_SIZE
108109
)
@@ -143,7 +144,7 @@ def describe_deployment(self, dep_crn=None, df_crn=None, name=None):
143144
Squelch(value='NOT_FOUND',
144145
warning='No DataFlow Deployment with crn %s found' % dep_crn),
145146
Squelch(value='PATH_DISABLED',
146-
warning='DataFlow not enabled on CDP Tenant')
147+
warning=ENTITLEMENT_DISABLED)
147148
],
148149
deploymentCrn=dep_crn
149150
)
@@ -155,7 +156,7 @@ def list_readyflows(self, name=None):
155156
Squelch(value='NOT_FOUND',
156157
warning='No ReadyFlows found within your CDP Tenant'),
157158
Squelch(value='PATH_DISABLED',
158-
warning='DataFlow not enabled on CDP Tenant')
159+
warning=ENTITLEMENT_DISABLED)
159160
],
160161
)
161162
if name is not None:
@@ -169,7 +170,7 @@ def list_flow_definitions(self, name=None):
169170
Squelch(value='NOT_FOUND',
170171
warning='No Flow Definitions found within your CDP Tenant Catalog'),
171172
Squelch(value='PATH_DISABLED',
172-
warning='DataFlow not enabled on CDP Tenant')
173+
warning=ENTITLEMENT_DISABLED)
173174
],
174175
)
175176
if name is not None:
@@ -184,7 +185,7 @@ def describe_readyflow(self, def_crn):
184185
Squelch(value='NOT_FOUND',
185186
warning='No ReadyFlow Definition with crn %s found' % def_crn),
186187
Squelch(value='PATH_DISABLED',
187-
warning='DataFlow not enabled on CDP Tenant')
188+
warning=ENTITLEMENT_DISABLED)
188189
],
189190
readyflowCrn=def_crn
190191
)
@@ -197,7 +198,7 @@ def import_readyflow(self, def_crn):
197198
Squelch(value='NOT_FOUND',
198199
warning='No ReadyFlow Definition with crn %s found' % def_crn),
199200
Squelch(value='PATH_DISABLED',
200-
warning='DataFlow not enabled on CDP Tenant')
201+
warning=ENTITLEMENT_DISABLED)
201202
],
202203
readyflowCrn=def_crn
203204
)
@@ -210,7 +211,7 @@ def delete_added_readyflow(self, def_crn):
210211
Squelch(value='NOT_FOUND',
211212
warning='No ReadyFlow Definition with crn %s found' % def_crn),
212213
Squelch(value='PATH_DISABLED',
213-
warning='DataFlow not enabled on CDP Tenant')
214+
warning=ENTITLEMENT_DISABLED)
214215
],
215216
readyflowCrn=def_crn
216217
)
@@ -223,7 +224,7 @@ def describe_added_readyflow(self, def_crn, sort_versions=True):
223224
Squelch(value='NOT_FOUND',
224225
warning='No ReadyFlow Definition with crn %s found' % def_crn),
225226
Squelch(value='PATH_DISABLED',
226-
warning='DataFlow not enabled on CDP Tenant')
227+
warning=ENTITLEMENT_DISABLED)
227228
],
228229
readyflowCrn=def_crn
229230
)
@@ -241,7 +242,7 @@ def describe_customflow(self, def_crn, sort_versions=True):
241242
Squelch(value='NOT_FOUND',
242243
warning='No Flow Definition with crn %s found' % def_crn),
243244
Squelch(value='PATH_DISABLED',
244-
warning='DataFlow not enabled on CDP Tenant')
245+
warning=ENTITLEMENT_DISABLED)
245246
],
246247
flowCrn=def_crn
247248
)

0 commit comments

Comments
 (0)