コード例 #1
0
    def compare(self, hostname, presnap_timestamp, postsnap_timestamp):

        try:
            device_info = Utility.get_device_info(hostname)

            # Breaking DI by instantiating JSnapComparison here, but I don't foresee making a custom comparison engine for awhile.
            #  But for easier future proofing, I'm leaving this essentially useless class in the process, as it will serve
            #   as an abstraction layer when I do design my own comparison engine

            return Utility.return_json(
                1, "Compare()",
                JSnapComparison().compare(
                    hostname, presnap_timestamp, postsnap_timestamp,
                    Utility.get_vendor_models()[device_info['vendor']][
                        device_info['model']]))
        except Exception as e:
            return Utility.return_json(
                0, 'Failed - ensure you can access sense.one.twcbiz.com APIs')
コード例 #2
0
    def snapshot(self, hostname):
        device_info = Utility.get_device_info(hostname)

        if device_info == None:
            return Utility.return_json(0, 'Invalid hostname or IP')

        class_path_name = Utility.get_vendor_models()[device_info['vendor']][device_info['model']]
        class_name = class_path_name.capitalize()

        # Dynamically import and instantiate the correct snapshot class
        module_name = import_module(f'drivers.snapshot.{device_info["vendor_lower"]}.{class_path_name}')
        class_ref = getattr(module_name, class_name)

        snapshot = class_ref()

        credentials = {
            'device_type': Utility.get_device_types()[device_info['vendor']],
            'host': hostname,
            'username': Utility.get_credentials()['username'],
            'password': Utility.get_credentials()['password']
        }

        return snapshot.snapshot(credentials)