Best Python code snippet using tempest_python
drainlist.py
Source:drainlist.py
1#!/usr/bin/python32# Copyright 2017, 2020, Oracle Corporation and/or affiliates. All rights reserved.3# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl4# Derived and adapted from https://www.ateam-oracle.com/secure-way-of-managing-secrets-in-oci5import os6import oci7from oci.container_engine import ContainerEngineClient8compartment_id = '${compartment_id}'9cluster_id = '${cluster_id}'10region = '${region}'11pools_to_drain = ['${pools_to_drain}']12signer = oci.auth.signers.InstancePrincipalsSecurityTokenSigner()13identity_client = oci.identity.IdentityClient(config={}, signer=signer)14oce = oci.container_engine.ContainerEngineClient(config={'region': region}, signer=signer)15# Get list of node pools16list_pools = []17for p in pools_to_drain:18 list_pools = oce.list_node_pools(compartment_id,cluster_id=cluster_id,name=p)19# Count number of node pools to upgrade20 number_of_node_pools = len(list_pools.data)21# Get list of node pool ids to upgrade22 pool_ids = []23 for n in range(0,number_of_node_pools):24 pool_ids.append(list_pools.data[n].id)25# for all node pool ids to upgrade, get a list of node pools26 node_pools = []27 for node_pool_id in pool_ids:28 resp = oce.get_node_pool(node_pool_id)29 node_pools.append(resp.data)30# for all node pools to upgrade, get a list of their worker nodes31 all_nodes = []32 for nodepool in node_pools:33 try:34 nodes = nodepool.nodes35 for node in nodes:36 all_nodes.append(node)37 except TypeError:38 continue39# for each node in the node pool, get their private_ip and write to file40 with open('drainlist.txt', 'a') as filehandle:41 for nodepool in node_pools:42 try:43 nodes = nodepool.nodes44 for node in nodes:45 filehandle.write('%s\n' % node.private_ip)46 except TypeError:...
is_worker_active.py
Source:is_worker_active.py
1#!/bin/python2# Copyright 2017, 2019, Oracle Corporation and/or affiliates. All rights reserved.3# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl4import os5import oci6from oci.container_engine import ContainerEngineClient7compartment_id = '${compartment_id}'8cluster_id = '${cluster_id}'9region = '${region}'10signer = oci.auth.signers.InstancePrincipalsSecurityTokenSigner()11identity_client = oci.identity.IdentityClient(config={}, signer=signer)12oce = oci.container_engine.ContainerEngineClient(config={'region': region}, signer=signer)13# Get list of node pools14list_pools = []15list_pools = oce.list_node_pools(compartment_id,cluster_id=cluster_id)16# Count number of node pools17number_of_node_pools = len(list_pools.data)18# Get list of node pool ids19pool_ids = []20for n in range(0,number_of_node_pools):21 pool_ids.append(list_pools.data[n].id)22 23# for all node pool ids, get a list of node pool24node_pools = []25for node_pool_id in pool_ids:26 resp = oce.get_node_pool(node_pool_id)27 node_pools.append(resp.data)28# for all node pools, get a list of nodes29all_nodes = [] 30for nodepool in node_pools:31 try:32 nodes = nodepool.nodes33 for node in nodes:34 all_nodes.append(node)35 except TypeError:36 continue37# for each node in the node pool, get the lifecycle_state38all_statuses = []39for nodepool in node_pools:40 try:41 nodes = nodepool.nodes42 for node in nodes:43 all_statuses.append(node.lifecycle_state)44 except TypeError:45 continue46 47# if there's a worker node that is active, create a file node.active48if "ACTIVE" in all_statuses:...
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!!