class IpamApiRequest: """IPAM API Call Definition.""" # pylint: disable = R0903 # This class is just meant to house the api construct. def __init__(self): self._env_cls = EnvironmentValues() self._log_cls = LoggingValues() self._ipam_url = self._env_cls.payload_url() self._ipam_username = self._env_cls.payload_username() self._ipam_password = self._env_cls.payload_password() logging.getLogger("urllib3").setLevel(logging.WARNING) logging.basicConfig(filename=self._log_cls.log_filename(), level=logging.INFO, format=self._log_cls.log_format()) self._logger = logging.getLogger(__name__) def ipam_api_request(self, _): """ IPAM API Call. Args: self._item: The missing puzzle piece needed for the api call. The return value of Class IpamCallTypes. Returns: The requests content decoded to 'utf-8' then returns as a python object after going through a json.loads process. """ try_call_countdown = 3 net_call = None self._logger.info('Calling IPAM for: %s', _) for countdown in range(try_call_countdown): try: net_call = requests.get(self._ipam_url + _, auth=(self._ipam_username, self._ipam_password), verify=False) break except requests.exceptions.ConnectionError as nerrt: if countdown < try_call_countdown - 1: self._logger.warning('Failed %s lookup. Round %s of 3.', _, countdown) time.sleep(5) continue else: self._logger.warning( 'Timeout Error for container view: %s, %s, %s', _, countdown, nerrt) return [] return net_call
class TestProjEnvVariables(unittest.TestCase): def setUp(self): self.env_cls = EnvironmentValues() def test_type_of_env_cls_payload_url(self): self.assertIsInstance(self.env_cls.payload_url(), str) def test_type_of_env_cls_payload_username(self): self.assertIsInstance(self.env_cls.payload_username(), str) def test_type_of_env_cls_payload_password(self): self.assertIsInstance(self.env_cls.payload_password(), str) def test_type_of_env_cls_header_row(self): self.assertIsInstance(self.env_cls.header_row(), list)