class _LibraryBase:
    def __init__(self):
        self.env_cls = EnvironmentValues()
        self.dir_cls = DirectoryValues()
        self.filenames_cls = DataFileNames()
        self.write_cls = Writer()
        self.reader_cls = Reader()
        self.client = paramiko.SSHClient()
        self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    @staticmethod
    def _isint(value):
        try:
            int(value)
            return True
        except ValueError:
            return False

    def get_command(self, command):
        """Construct for ssh call to Tody Cools."""
        self.client.connect(
            self.env_cls.tody_cools(),
            username=self.env_cls.tacacs_username(),
            password=self.env_cls.tacacs_password())

        return self.client.exec_command(command)
 def __init__(self):
     self.env_cls = EnvironmentValues()
     self.dir_cls = DirectoryValues()
     self.filenames_cls = DataFileNames()
     self.write_cls = Writer()
     self.reader_cls = Reader()
     self.client = paramiko.SSHClient()
     self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
 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__)
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
예제 #5
0
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)
 def __init__(self):
     self._log_cls = LoggingValues()
     logging.basicConfig(filename=self._log_cls.log_filename(),
                         level=logging.DEBUG,
                         filemode='a',
                         format=self._log_cls.log_format())
     self._logger = logging.getLogger(__name__)
     self.dir_cls = DirectoryValues()
     self.filename_cls = DataFileNames()
     self.env_cls = EnvironmentValues()
     self.reader_cls = Reader()
     self.writer_cls = Writer()
OLD DATA FOR REFERENCE!!

"""
from builder import EnvironmentValues, DirectoryValues, LoggingValues, DataFileNames
from builder import Writer
from builder import Reader
from ipam_apirequest_calltypes import IpamCallTypes, IpamApiRequest
import pandas as pd
from tabulate import tabulate
import functools
from collections import MutableMapping
import netaddr

# Initialize Classes
dir_cls = DirectoryValues()
env_cls = EnvironmentValues()
filename_cls = DataFileNames
reader_cls = Reader()


def _summary_forecast():
    def get_free_space_dataset(free_space_dataset):
        # Logic for the free space initial compilation.
        free_apac_subnets = []
        free_emea_subnets = []
        free_latam_subnets = []
        free_na_subnets = []
        apac_subnet = netaddr.IPNetwork('10.224.0.0/12')
        emea_subnet = netaddr.IPNetwork('10.128.0.0/11')
        latam_subnet = netaddr.IPNetwork('10.240.0.0/13')
        na_subnet = netaddr.IPNetwork('10.192.0.0/11')
예제 #8
0
 def setUp(self):
     self.env_cls = EnvironmentValues()
예제 #9
0
def main(ext_att=False, net_view=False, get_networks=True):
    log_cls = LoggingValues()
    logging.basicConfig(filename=log_cls.log_filename(),
                        level=logging.DEBUG,
                        filemode='a',
                        format=log_cls.log_format())

    logger = logging.getLogger(__file__.split("/")[-1:][0])

    logger.info('=========================')
    logger.info('Main Script Initializing.')
    logger.info('=========================')

    logger.info('Loading Project Environment Variables.')
    env_cls = EnvironmentValues()
    dir_cls = DirectoryValues()
    write_cls = Writer()
    reader_cls = Reader()
    logger.info('Project Environment Variables Loaded.')

    logger.info('===================')
    logger.info('Compiling DDI Data.')
    logger.info('===================')
    call_types = DdiCallTypes()
    filenames = DdiCallFilenames()
    ext_call_setup = IpamApiRequestGet()

    def extensible_attribute_call():
        logger.info('Pulling current Extensible Attribute data.')
        ext_attr_data = ext_call_setup.ddi_call(
            call_types.extensibles_attribute())
        # print(ext_attr_data)
        # print(type(ext_attr_data))
        write_cls.write_to_pkl(dir_cls.raw_dir(),
                               filenames.extensibles_attribute_filename(),
                               ext_attr_data)
        logger.info('Extensible Attr data written to .pkl file in Raw Dir.')

    if ext_att:
        extensible_attribute_call()
    else:
        logger.info('Extensible Attributes data was not set to True. Skipping')

    def network_view_call():
        logger.info('Pulling current Network View Data.')
        network_view_data = ext_call_setup.ddi_call(call_types.network_views())
        # print(network_view_data)
        # print(type(network_view_data))
        write_cls.write_to_pkl(dir_cls.raw_dir(),
                               filenames.network_views_filename(),
                               network_view_data)
        logger.info('Network View data written to .pkl file in raw Dir.')

    if net_view:
        network_view_call()
    else:
        logger.info('Network View data was not set to True. Skipping.')

    def get_network():
        logger.info('Pulling current IPAM Data.')
        network_views = reader_cls.read_from_pkl(
            dir_cls.raw_dir(), filenames.network_views_filename())
        network_data = []
        start = time.perf_counter()
        for _ref in network_views:
            # if _ref == network_views[1]:
            #     break
            network_data += ext_call_setup.ddi_call(
                call_types.networks(_ref['name']))
        end = time.perf_counter()
        logging.info("Downloaded {} Networks in {} seconds".format(
            len(network_data), end - start))
        write_cls.write_to_pkl(dir_cls.raw_dir(),
                               filenames.networks_filename(), network_data)
        logger.info('Network Data written to .pkl file in raw Dir.')

    if get_networks:
        get_network()
    else:
        logger.info('Network data was not set to True.  Skipping.')
    exit()
    print(env_cls.payload_password())
    print(env_cls.header_row())
    print(type(dir_cls.reports_dir()))
    print(dir_cls.raw_dir())
    print(dir_cls.interim_dir())
    print(dir_cls.reports_dir())
    print(type(dir_cls.processed_dir()))