Exemple #1
0
    def get(self, uuid, page):

        try:
            rows_uuid = TokensModel.find_by_uuid(uuid, "device_store")
        except:
            return {"message": "Data search operation failed!"}, 500

        if not rows_uuid:
            return {'message': "Request with UUID: '{}' doesn't exists.".format(uuid)}, 404

        config.NO_OF_DEVICES = len(rows_uuid)
        config.NO_OF_PAGES = ceil(config.NO_OF_DEVICES/10)
        print("Pagination: UUID for this request is:", uuid)
        print("Pagination: Total number of pages:", config.NO_OF_PAGES)
        print("Pagination: Page number requested is:", page)

        if page < 1 or page > config.NO_OF_PAGES:
            return {'message': "Page doesn't exists!"}, 400
        try:
            rows = TokensModel.find_by_uuid_slice(uuid, page, "device_store")
        except:
            return {"message": "Data search operation failed!"}, 500

        devices = []

        for row in rows:
            devices.append({'ipaddr': row[1], 'username': row[2], 'password': row[3], 'sa_name': row[4],
                            'va_name': row[5], 'domain': row[6]})
        print("==>> Printing devices from within get method for resource: Tokens <<==")
        print(devices)
        if rows:
            return {'uuid': uuid,
                    'totalpages': config.NO_OF_PAGES,
                    'devices': devices}
        return {"message": "Request with UUID: '{}' not found!".format(uuid)}, 404
Exemple #2
0
    def get(self, uuid, page):
        data = File.parser.parse_args()
        print("OAuth token is:", data['oauth_token'])
        if page < 1 or page > config.NO_OF_PAGES:
            return {'message': "Page doesn't exists!"}, 400
        try:
            rows = TokensModel.find_by_uuid_slice(uuid, "device_store", page)
        except:
            return {"message": "Data search operation failed!"}, 500

        devices = []

        for row in rows:
            devices.append({
                'ipaddr': row[1],
                'username': row[2],
                'password': row[3],
                'sa_name': row[4],
                'va_name': row[5],
                'domain': row[6]
            })
        print(
            "==>> Printing devices from within get method for resource: Tokens <<=="
        )
        print(devices)
        if rows:
            return {'uuid': uuid, 'devices': devices}
        return {
            "message": "Request with UUID: '{}' not found!".format(uuid)
        }, 404
    def generate_output(self, uuid, page):
        slr_table = None
        slr_table = slr_req_tbl

        if (slr_table == None):
            return invalid_request, 404

        response = {}
        try:
            total_rows = TokensModel.find_by_uuid(uuid, "device_store")
        except Exception as e:
            print(e)
            return database_err, 500

        config.NO_OF_DEVICES = len(total_rows)
        config.NO_OF_PAGES = ceil(config.NO_OF_DEVICES /
                                  num_of_device_per_page)
        response[pages] = config.NO_OF_PAGES

        response[device] = []

        try:
            rows = TokensModel.find_by_uuid_slice(uuid, page, "device_store")
        except Exception as e:
            print(e)
            return database_err, 500

        for row in rows:
            ip_address = row[ip_addr]
            try:
                val = self.slr.find_by_uuid_ipaddr(uuid, slr_table, ip_address)
            except Exception as e:
                print(e)
                return database_err, 500

            device_dict = {}
            for i in col:
                device_dict[col[i]] = row[i]
            print(val)
            device_dict['s2Status'] = ""
            device_dict['s3Status'] = ""
            device_dict['s4Status'] = ""
            try:
                device_dict['s2Status'] = val[0][2]
                device_dict['s3Status'] = val[0][3]
                device_dict['s4Status'] = val[0][4]
            except Exception as e:
                print(e)

            response[device].append(device_dict)
            del (device_dict)

        print("Final response")
        print(response)
        return (response), 201
Exemple #4
0
    def generate_output(self, uuid, page):
        slr_table = SLR_REQUEST_CODE_TABLE_NAME
        response = {}
        try:
            total_rows = TokensModel.find_by_uuid(uuid, "device_store")
        except Exception as e:
            print(e)
            logger.error({"message": "Data search operation failed!"},
                         exc_info=True)
            return {"message": "Data search operation failed!"}, 500

        config.NO_OF_DEVICES = len(total_rows)
        config.NO_OF_PAGES = ceil(config.NO_OF_DEVICES /
                                  NUMBER_OF_DEVICES_PER_PAGE)
        response["totalpages"] = config.NO_OF_PAGES
        response["devices"] = []

        try:
            rows = TokensModel.find_by_uuid_slice(uuid, page, "device_store")
        except Exception as e:
            print(e)
            logger.error({"message": "Data search operation failed!"},
                         exc_info=True)
            return {"message": "Data search operation failed!"}, 500

        for row in rows:
            ip_address = row[1]
            try:
                val = self.slr.find_by_uuid_ipaddr(uuid, slr_table, ip_address)
            except Exception as e:
                print(e)
                logger.error({"message": "Data search operation failed!"},
                             exc_info=True)
                return {"message": "Data search operation failed!"}, 500

            device_dict = {}
            for i in col:
                device_dict[col[i]] = row[i]
            logger.info(val)
            device_dict['s2Status'] = ""
            device_dict['s3Status'] = ""
            device_dict['s4Status'] = ""
            try:
                device_dict['s2Status'] = val[0][2]
                device_dict['s3Status'] = val[0][3]
                device_dict['s4Status'] = val[0][4]
            except Exception as e:
                print(e)

            response["devices"].append(device_dict)
            del device_dict

        logger.info("Final response")
        logger.info(response)
        return response, 201