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

Move DFX Beta implementation to GA process #30

Merged
merged 1 commit into from
Oct 25, 2021
Merged
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
63 changes: 42 additions & 21 deletions src/cdpy/df.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,69 @@ class CdpyDf(CdpSdkBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def list_environments(self, only_enabled=False, name=None):
def list_services(self, only_enabled=False, env_crn=None, df_crn=None, name=None):
result = self.sdk.call(
svc='df', func='list_environments', ret_field='environments', squelch=[
svc='df', func='list_services', ret_field='services', squelch=[
Squelch(value='NOT_FOUND', default=list(),
warning='No Environments for DataFlow found in Tenant')
warning='No DataFlow Deployments found')
],
pageSize=self.sdk.DEFAULT_PAGE_SIZE
)
if only_enabled:
result = [x for x in result if x['status']['state'] not in ['NOT_ENABLED']]
if name is not None:
result = [x for x in result if x['name'] == name]
if df_crn is not None:
result = [x for x in result if x['crn'] == df_crn]
if env_crn is not None:
result = [x for x in result if x['environmentCrn'] == env_crn]
return result

def describe_environment(self, env_crn: str = None):
def describe_service(self, df_crn: str = None, env_crn: str = None):
if df_crn is not None:
resolved_df_crn = df_crn
elif env_crn is not None:
services = self.list_services(env_crn=env_crn)
if len(services) == 0:
return None
elif len(services) == 1:
resolved_df_crn = services[0]['crn']
else:
self.sdk.throw_error(
CdpError('More than one DataFlow service found for env_crn, please try list instead')
Chaffelson marked this conversation as resolved.
Show resolved Hide resolved
)
else:
self.sdk.throw_error(CdpError("Either df_crn or env_crn must be supplied to df.describe_service"))
return self.sdk.call(
svc='df', func='get_environment', ret_field='environment', squelch=[
svc='df', func='describe_service', ret_field='service', squelch=[
Squelch(value='NOT_FOUND',
warning='No Environment with crn %s for DataFlow found in Tenant' % env_crn)
warning='No DataFlow Deployment with crn %s found' % df_crn),
Squelch(value='PERMISSION_DENIED') # DF GRPC sometimes returns 403 when finishing deletion
],
crn=env_crn
serviceCrn=resolved_df_crn
)

def enable_environment(self, env_crn: str, authorized_ips: list = None, min_nodes: int = 3, max_nodes: int = 3,
enable_public_ip: bool = True):
def enable_service(self, env_crn: str, lb_ips: list = None, min_nodes: int = 3, max_nodes: int = 3,
enable_public_ip: bool = True, kube_ips: list = None, cluster_subnets: list = None,
lb_subnets: list = None):
Chaffelson marked this conversation as resolved.
Show resolved Hide resolved
self.sdk.validate_crn(env_crn)
return self.sdk.call(
svc='df', func='enable_environment', ret_field='environment',
crn=env_crn, minK8sNodeCount=min_nodes, maxK8sNodeCount=max_nodes,
usePublicLoadBalancer=enable_public_ip, authorizedIpRanges=authorized_ips
svc='df', func='enable_service', ret_field='service',
environmentCrn=env_crn, minK8sNodeCount=min_nodes, maxK8sNodeCount=max_nodes,
usePublicLoadBalancer=enable_public_ip, kubeApiAuthorizedIpRanges=kube_ips,
loadBalancerAuthorizedIpRanges=lb_ips, clusterSubnets=cluster_subnets, loadBalancerSubnets=lb_subnets
)

def disable_environment(self, env_crn: str, persist: bool = False):
self.sdk.validate_crn(env_crn)
def disable_service(self, df_crn: str, persist: bool = False, terminate=False):
self.sdk.validate_crn(df_crn)
return self.sdk.call(
svc='df', func='disable_environment', ret_field='status', ret_error=True,
crn=env_crn, persist=persist
svc='df', func='disable_service', ret_field='status', ret_error=True,
serviceCrn=df_crn, persist=persist, terminateDeployments=terminate
)

def delete_environment(self, env_crn: str):
self.sdk.validate_crn(env_crn)
def reset_service(self, df_crn: str):
cmperro marked this conversation as resolved.
Show resolved Hide resolved
self.sdk.validate_crn(df_crn)
return self.sdk.call(
svc='df', func='delete_environment',
crn=env_crn
)
svc='df', func='reset_service',
serviceCrn=df_crn
)