Best Python code snippet using localstack_python
test.py
Source:test.py
...32 api_response = api_instance.create_namespaced_deployment(33 body=deployment,34 namespace="default")35 print("Deployment created. status='%s'" % str(api_response.status))36def update_deployment(api_instance, deployment, deployment_name, new_image):37 # Update container image38 deployment.spec.template.spec.containers[0].image = new_image39 # Update the deployment40 api_response = api_instance.patch_namespaced_deployment(41 name=deployment_name,42 namespace="default",43 body=deployment)44 print("Deployment updated. status='%s'" % str(api_response.status))45def delete_deployment(api_instance, deployment_name):46 # Delete deployment47 api_response = api_instance.delete_namespaced_deployment(48 name=deployment_name,49 namespace="default",50 body=client.V1DeleteOptions(51 propagation_policy='Foreground',52 grace_period_seconds=5))53 print("Deployment deleted. status='%s'" % str(api_response.status))54# Create an instance of the API class55config.load_kube_config() # de fora cluster K8s56#config.load_incluster_config() # de dentro do cluster K8s57apps_v1 = client.AppsV1Api()58apps_core = client.CoreV1Api()59# Getting the deployment60#deployment_name = "fidelity-mc-kubow"61#deployment_image = "cmendes/kubow:yellow"62#current_deployment = apps_v1.read_namespaced_deployment(deployment_name, "default")63#current_deployment.spec.replicas = current_deployment.spec.replicas + 164#update_deployment(apps_v1, current_deployment, deployment_name, deployment_image)65deployment_name = "kube-znn"66deployment_image = "cmendes/znn:600k"67current_deployment = apps_v1.read_namespaced_deployment(deployment_name, "default")68#current_deployment.spec.replicas = current_deployment.spec.replicas + 169#update_deployment(apps_v1, current_deployment, deployment_name, deployment_image)70#apps_core.list_component_status71#apps_core.list_event_for_all_namespaces72#apps_core.list_event_for_all_namespaces_with_http_info73#apps_core.list_namespace74#apps_core.list_namespaced_event75#apps_core.list_namespaced_limit_range76#apps_core.list_namespaced_resource_quota77#apps_core.list_resource_quota_for_all_namespaces78#w = watch.Watch()79#for event in w.stream(apps_core.list_namespace, timeout_seconds=5):80# print("Event: %s %s" % (event['type'], event['object'].metadata.name))81#deployment_replicas = 182#current_deployment.spec.replicas = 083#update_deployment(apps_v1, current_deployment, deployment_name, deployment_image)84#delete_deployment(apps_v1, deployment_name)85#deployament = create_deployment_object(deployment_name, deployment_image, deployment_replicas)86#create_deployment(apps_v1, deployament)87#delete_deployment(apps_v1, deployment_name)88#deployment_name = "kube-znn"89#deployment_image = "cmendes/kube-znn:text"90#deployment_replicas = 291#deployment = create_deployment_object(deployment_name, deployment_image, deployment_replicas)92#create_deployment(apps_v1, deployment)93#print("finished!")94#current_deployment = apps_v1.read_namespaced_deployment("kube-znn", "default")95#current_deployment.spec.template.spec.containers[0].image = "cmendes/kube-znn:text"96#created_object = create_deployment_object(current_deployment)97#delete_deployment(apps_v1, current_deployment)98#create_deployment(apps_v1, created_object)99#print(deployment.metadata.name)100#print(deployment.spec.template.spec.containers[0].image)101#print(deployment.spec.replicas)102#print(deployment)103# Rollout104#deployment.spec.replicas = 0105#update_deployment(apps_v1, deployment)106#deployment.spec.template.spec.containers[0].image = "cmendes/kube-znn:text"107#deployment.spec.replicas = 2108#update_deployment(apps_v1, deployment)109# Scale110#deployment.spec.replicas = 2...
sqs.py
Source:sqs.py
...42 deployment = self.deployment()43 if deployment.spec.replicas < self.options.max_pods:44 logger.info("Scaling up")45 deployment.spec.replicas += 146 self.update_deployment(deployment)47 elif deployment.spec.replicas > self.options.max_pods:48 self.scale_down()49 else:50 logger.info("Max pods reached")51 def scale_down(self):52 deployment = self.deployment()53 if deployment.spec.replicas > self.options.min_pods:54 logger.info("Scaling Down")55 deployment.spec.replicas -= 156 self.update_deployment(deployment)57 elif deployment.spec.replicas < self.options.min_pods:58 self.scale_up()59 else:60 logger.info("Min pods reached")61 def deployment(self):62 logger.debug("loading deployment: {} from namespace: {}".format(self.options.kubernetes_deployment, self.options.kubernetes_namespace))63 deployments = self.extensions_v1_beta1.list_namespaced_deployment(self.options.kubernetes_namespace, label_selector="app={}".format(self.options.kubernetes_deployment))64 return deployments.items[0]65 def update_deployment(self, deployment):66 # Update the deployment67 api_response = self.extensions_v1_beta1.patch_namespaced_deployment(68 name=self.options.kubernetes_deployment,69 namespace=self.options.kubernetes_namespace,70 body=deployment)71 logger.debug("Deployment updated. status='%s'" % str(api_response.status))72 def run(self):73 options = self.options74 logger.debug("Starting poll for {} every {}s".format(options.sqs_queue_url, options.poll_period))75 while True:76 self.poll()77def run(options):78 """79 poll_period is set as as part of k8s deployment env variable...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!