Skip to content

Commit 01bb733

Browse files
authored
Support for DFX (#17)
* Add BAD_HEALTH to failed status for DFX * Correct not found error for DFX Environment to return None instead of an empty list * Correct spelling of DFX authorisedIpRanges to authorizedIpRanges Signed-off-by: Daniel Chaffelson <[email protected]>
1 parent 8f08461 commit 01bb733

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

src/cdpy/cdpy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from cdpy.ml import CdpyMl
1313
from cdpy.opdb import CdpyOpdb
1414
from cdpy.dw import CdpyDw
15+
from cdpy.df import CdpyDf
1516

1617

1718
class Cdpy(CdpSdkBase):
@@ -25,3 +26,4 @@ def __init__(self, *args, **kwargs):
2526
self.ml = CdpyMl(*args, **kwargs)
2627
self.opdb = CdpyOpdb(*args, **kwargs)
2728
self.dw = CdpyDw(*args, **kwargs)
29+
self.df = CdpyDf(*args, **kwargs)

src/cdpy/common.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,25 @@ def _warning_format(message, category, filename, lineno, line=None):
156156
'STACK_CREATION_IN_PROGRESS',
157157
'CREATION_INITIATED',
158158
'FREEIPA_CREATION_IN_PROGRESS',
159-
'STARTING'
159+
'STARTING',
160+
'ENABLING' # DF
160161
]
161162

162163
self.TERMINATION_STATES = [
163164
'EXTERNAL_DATABASE_DELETION_IN_PROGRESS',
164165
'STACK_DELETION_IN_PROGRESS',
165166
'FREEIPA_DELETE_IN_PROGRESS',
166-
'STOPPING'
167+
'STOPPING',
168+
'DISABLING' # DF
167169
]
168170

169171
self.STARTED_STATES = [
170172
'EXTERNAL_DATABASE_START_IN_PROGRESS',
171173
'AVAILABLE',
172174
'START_IN_PROGRESS',
173175
'RUNNING',
174-
'Running'
176+
'Running', # DW
177+
'GOOD_HEALTH' # DF
175178
]
176179

177180
self.STOPPED_STATES = [
@@ -189,13 +192,15 @@ def _warning_format(message, category, filename, lineno, line=None):
189192
'TIMEDOUT',
190193
'DELETE_FAILED',
191194
'Error', # DW
192-
'installation:failed' # ML
195+
'installation:failed', # ML
196+
'BAD_HEALTH' # DF
193197
]
194198

195199
self.REMOVABLE_STATES = [
196200
'AVAILABLE', 'UPDATE_FAILED', 'CREATE_FAILED', 'ENABLE_SECURITY_FAILED', 'DELETE_FAILED',
197201
'DELETE_COMPLETED', 'DELETED_ON_PROVIDER_SIDE', 'STOPPED', 'START_FAILED', 'STOP_FAILED',
198-
'Error', 'Running'
202+
'Error', 'Running', # DW
203+
'GOOD_HEALTH', 'CONCERNING_HEALTH', 'BAD_HEALTH' # DF
199204
]
200205

201206
# common regex patterns

src/cdpy/df.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from cdpy.common import CdpSdkBase, Squelch
4+
5+
6+
class CdpyDf(CdpSdkBase):
7+
def __init__(self, *args, **kwargs):
8+
super().__init__(*args, **kwargs)
9+
10+
def list_environments(self, only_enabled=False):
11+
result = self.sdk.call(
12+
svc='df', func='list_environments', ret_field='environments', squelch=[
13+
Squelch(value='NOT_FOUND', default=list(),
14+
warning='No Environments for DataFlow found in Tenant')
15+
],
16+
pageSize=self.sdk.DEFAULT_PAGE_SIZE
17+
)
18+
if only_enabled:
19+
return [x for x in result if x['status']['state'] not in ['NOT_ENABLED']]
20+
return result
21+
22+
def describe_environment(self, env_crn: str):
23+
return self.sdk.call(
24+
svc='df', func='get_environment', ret_field='environment', squelch=[
25+
Squelch(value='NOT_FOUND',
26+
warning='No Environment with crn %s for DataFlow found in Tenant' % env_crn)
27+
],
28+
crn=env_crn
29+
)
30+
31+
def enable_environment(self, env_crn: str, authorized_ips: list = None, min_nodes: int = 3, max_nodes: int = 3,
32+
enable_public_ip: bool = True):
33+
self.sdk.validate_crn(env_crn)
34+
return self.sdk.call(
35+
svc='df', func='enable_environment', ret_field='environment',
36+
crn=env_crn, minK8sNodeCount=min_nodes, maxK8sNodeCount=max_nodes,
37+
usePublicLoadBalancer=enable_public_ip, authorizedIpRanges=authorized_ips
38+
)
39+
40+
def disable_environment(self, env_crn: str, persist: bool = False):
41+
self.sdk.validate_crn(env_crn)
42+
return self.sdk.call(
43+
svc='df', func='disable_environment', ret_field='status',
44+
crn=env_crn, persist=persist
45+
)

0 commit comments

Comments
 (0)