def get_server_id_used_by_portus(conn: dict, Name: str) -> int: """ Get Server Id used by Portus by Name [Args] (dict) conn: Connection dictionary obtained after logging in (str) Name: Name of the Container Registry [Returns] (int) Id: Id of the server used by Container Registry, or None: if no match found, or (dict) Error response: If Exception occured """ portus_list = pcc.get_portus(conn)['Result']['Data'] try: for portus in portus_list: if str(portus['name']) == str(Name): return portus['nodeID'] return None except Exception as e: return {"Error": str(e)}
def clean_all_CR(self, *args, **kwargs): """ Delete All Container Registry [Args] (dict) conn: Connection dictionary obtained after logging in [Returns] (str) OK: OK if All Container Registry are deleted (includes any errors) """ banner("PCC.Clean all CR") self._load_kwargs(kwargs) conn = BuiltIn().get_variable_value("${PCC_CONN}") response = pcc.get_portus(conn) list_id = [] if get_response_data(response) == []: return "OK" else: try: for ids in get_response_data(response): list_id.append(ids['id']) print("list of id:{}".format(list_id)) except Exception as e: logger.console("Error: {}".format(e)) response_code_list = [] try: for id_ in list_id: response = pcc.delete_portus_by_id(conn, id=str(id_)) print() response_code_list.append(response['StatusCode']) result = len(response_code_list) > 0 and all( elem == response_code_list[0] for elem in response_code_list) if result: return "OK" else: return "Error" except Exception as e: logger.console("Error in clean all CR: {}".format(e))
def get_portus_version(self, *args, **kwargs): banner("Get portus Version") self._load_kwargs(kwargs) try: print("Kwargs are: {}".format(kwargs)) conn = BuiltIn().get_variable_value("${PCC_CONN}") print("conn is {}".format(conn)) portus_list = pcc.get_portus(conn) print("portus_list is {}".format(portus_list)) portus_ver_list = {} for data in portus_list["Result"]["Data"]: print("portus version of portus {} is {} ".format( data["name"], data["portusInfo"]["portusVersion"])) portus_ver_list[ data["name"]] = data["portusInfo"]["portusVersion"] print("portus_ver_list is {}".format(portus_ver_list)) return portus_ver_list except Exception as e: trace("Error in getting portus version: {}".format(e))
def wait_for_CR_deletion(self, *args, **kwargs): """ Wait for deletion of Container Registry [Args] (dict) conn: Connection dictionary obtained after logging in (str) Name: Name of the specific Container Registry to wait for delete (name=<Name>), if Name is not provided, it will wait for all Container Registries to delete [Returns] (str) OK: OK if Container Registry has been deleted on PCC, else Error """ banner("PCC.Wait for deletion of CR") self._load_kwargs(kwargs) conn = BuiltIn().get_variable_value("${PCC_CONN}") try: if self.Name == None: deletion_status = False counter = 0 while deletion_status == False: counter += 1 response = pcc.get_portus(conn) if get_response_data(response) != []: time.sleep(6) banner("All CR not yet deleted") if counter < 40: banner("Counter: {}".format(counter)) continue else: break elif get_response_data(response) == []: deletion_status = True banner("All CR deleted successfully") else: banner("Entered into continuous loop") break if deletion_status == True: return "OK" else: return "Error in deletion status of CR" elif self.Name: deletion_status = False counter = 0 while deletion_status == False: counter += 1 CR_availability_status = [] response = pcc.get_portus(conn) for node in get_response_data(response): CR_availability_status.append(node['name']) if self.Name in CR_availability_status: banner("Named CR still not deleted") time.sleep(6) if counter < 40: banner("Counter: {}".format(counter)) continue else: break elif self.Name not in CR_availability_status: banner("Named CR deleted successfully") deletion_status = True break else: banner( "Error in Named CR, Entered into continuous loop") break if deletion_status == True: return "OK" else: return "Error in deletion status of CR" else: return "Neither name provided nor name is None" except Exception as e: logger.console( "Error in wait for CR deletion with id: {}".format(e))