|
| 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