|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +from cdpy.common import CdpSdkBase, Squelch, CdpcliWrapper |
| 4 | + |
| 5 | +class CdpyDe(CdpSdkBase): |
| 6 | + def __init__(self, *args, **kwargs): |
| 7 | + super().__init__(*args, **kwargs) |
| 8 | + |
| 9 | + def describe_vc(self, cluster_id, vc_id): |
| 10 | + return self.sdk.call( |
| 11 | + svc='de', func='describe_vc', ret_field='vc', squelch=[ |
| 12 | + Squelch('NOT_FOUND'), Squelch('INVALID_ARGUMENT') |
| 13 | + ], |
| 14 | + clusterId=cluster_id, |
| 15 | + vcId=vc_id |
| 16 | + ) |
| 17 | + |
| 18 | + def list_vcs(self, cluster_id): |
| 19 | + return self.sdk.call( |
| 20 | + svc='de', func='list_vcs', ret_field='vcs', squelch=[ |
| 21 | + Squelch(value='NOT_FOUND', default=list()), |
| 22 | + Squelch(field='status_code', value='504', default=list(), |
| 23 | + warning="No VCS in this Cluster"), |
| 24 | + ], |
| 25 | + clusterId=cluster_id |
| 26 | + ) |
| 27 | + |
| 28 | + def create_vc(self, name, cluster_id, cpu_requests, memory_requests, |
| 29 | + chart_value_overrides=None, runtime_spot_component=None): |
| 30 | + return self.sdk.call( |
| 31 | + svc='de', func='create_vc', ret_field='Vc', |
| 32 | + name=name, |
| 33 | + clusterId=cluster_id, |
| 34 | + cpuRequests=cpu_requests, |
| 35 | + memoryRequests=memory_requests, |
| 36 | + chartValueOverrides=chart_value_overrides, |
| 37 | + runtimeSpotComponent=runtime_spot_component |
| 38 | + ) |
| 39 | + |
| 40 | + def delete_vc(self, cluster_id, vc_id): |
| 41 | + return self.sdk.call( |
| 42 | + svc='de', func='delete_vc', ret_field='status', squelch=[Squelch('NOT_FOUND')], |
| 43 | + clusterId=cluster_id, vcId=vc_id |
| 44 | + ) |
| 45 | + |
| 46 | + def describe_service(self, cluster_id): |
| 47 | + return self.sdk.call( |
| 48 | + svc='de', func='describe_service', ret_field='service', squelch=[ |
| 49 | + Squelch('NOT_FOUND'), Squelch('INVALID_ARGUMENT') |
| 50 | + ], |
| 51 | + clusterId=cluster_id, |
| 52 | + ) |
| 53 | + |
| 54 | + def list_services(self, env=None, remove_deleted=False): |
| 55 | + services = self.sdk.call( |
| 56 | + svc='de', func='list_services', ret_field='services', squelch=[ |
| 57 | + Squelch(value='NOT_FOUND', default=list())], removeDeleted=remove_deleted |
| 58 | + ) |
| 59 | + return [s for s in services if env is None or s['environmentName'] == env] |
| 60 | + |
| 61 | + def enable_service(self, name, env, instance_type, minimum_instances, maximum_instances, |
| 62 | + initial_instances=None, minimum_spot_instances=None, maximum_spot_instances=None, |
| 63 | + initial_spot_instances=None, chart_value_overrides=None, enable_public_endpoint=False, |
| 64 | + enable_workload_analytics=False, root_volume_size=None, skip_validation=False, |
| 65 | + tags=None, use_ssd=False, whitelist_ips=None): |
| 66 | + return self.sdk.call( |
| 67 | + svc='de', func='enable_service', ret_field='service', |
| 68 | + name=name, |
| 69 | + env=env, |
| 70 | + instanceType=instance_type, |
| 71 | + minimumInstances=minimum_instances, |
| 72 | + maximumInstances=maximum_instances, |
| 73 | + initialInstances=initial_instances, |
| 74 | + minimumSpotInstances=minimum_spot_instances, |
| 75 | + maximumSpotInstances=maximum_spot_instances, |
| 76 | + initialSpotInstances=initial_spot_instances, |
| 77 | + chartValueOverrides=chart_value_overrides, |
| 78 | + enablePublicEndpoint=enable_public_endpoint, |
| 79 | + enableWorkloadAnalytics=enable_workload_analytics, |
| 80 | + rootVolumeSize=root_volume_size, |
| 81 | + skipValidation=skip_validation, |
| 82 | + tags=tags, |
| 83 | + useSsd=use_ssd, |
| 84 | + whitelistIps=whitelist_ips |
| 85 | + ) |
| 86 | + |
| 87 | + def disable_service(self, cluster_id, force=False): |
| 88 | + return self.sdk.call( |
| 89 | + svc='de', func='disable_service', ret_field='status', squelch=[Squelch('NOT_FOUND')], |
| 90 | + clusterId=cluster_id, force=force |
| 91 | + ) |
| 92 | + |
| 93 | + def get_kubeconfig(self, cluster_id): |
| 94 | + return self.sdk.call( |
| 95 | + svc='de', func='get_kubeconfig', ret_field='kubeconfig', squelch=[Squelch('NOT_FOUND')], |
| 96 | + clusterId=cluster_id |
| 97 | + ) |
0 commit comments