Пример #1
0
    def send_request_cssm(self, uuid, oauthToken):
        logger.info("contact CSSM debugs")
        threads = []
        slr_table = SLR_REQUEST_CODE_TABLE_NAME
        try:
            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
        if not rows:
            logger.error("No Devices with this UUID")
            return ({"request": "No Devices with this UUID"}), 400

        for row in rows:
            logger.info("Launching threads to get auth tokens")
            # Updating the response status to Step 3 started
            response_update = {'status': "S3s"}
            TokensModel.update(uuid, response_update, "upload_info_store")
            self.slr.update_status(slr_table, row[0], row[1], "Started", "step2")
            ''' Bulk DLC Call'''
            if TokensModel.find_fileType(uuid) != "sl" and TokensModel.find_slr_type(uuid) == "slr":
                domain_name, dlcRequest = SlrRequestCode.get_dlc_conversion_api_body(uuid)
                if dlcRequest:
                    self.slr_bulkDLC(uuid, domain_name, dlcRequest, config.OAUTH_TOKEN)
            if TokensModel.find_fileType(uuid) != "sl" and TokensModel.find_slr_type(uuid) == "slrx":
                domain_name, dlcRequest = ImportCodes.get_dlc_payload(uuid)
                if dlcRequest:
                    self.slr_bulkDLC(uuid, domain_name, dlcRequest, config.OAUTH_TOKEN)
            th = threading.Thread(target=SlrContactCSSM.get_cssm_response, args=(row[6], row[5], oauthToken, row[1],
                                                                                 row[0]))
            th.start()
            threads.append(th)
        logger.info({"request": "accepted"})
        return {"request": "accepted"}, 201
Пример #2
0
    def slr_bulkDLC(cls, uuid, domain_name, dlcRequest, bearerToken):
        url = "https://apmx.cisco.com/services/api/smart-accounts-and-licensing/v1/accounts/" + domain_name + \
              "/dlc_convert"
        headers = {
            "Authorization": "Bearer " + bearerToken,
            "Content-Type": "application/json"
        }

        if TokensModel.find_fileType(uuid) != "sl" and TokensModel.find_slr_type(uuid) == "slr":
            logger.info("Starting bulk dlc conversion for slr")
            dlcRequest_dict = {"virtualAccounts": []}
            for key, value in dlcRequest.items():
                dlcRequest_dict["virtualAccounts"].append({"dlcRequests": value, "name": key})
            logger.info("Before deleting device_ip from dlc_data_dict")
            logger.info(dlcRequest_dict)
            for item in dlcRequest_dict['virtualAccounts'][0]['dlcRequests']:
                item['sudi'].pop('device_ip')
            logger.info("After deleting device_ip from dlc_data_dict")
            logger.info(dlcRequest_dict)
            dlc_payload = json.dumps(dlcRequest_dict)
            logger.info(dlc_payload)
        if TokensModel.find_fileType(uuid) != "sl" and TokensModel.find_slr_type(uuid) == "slrx":
            logger.info("Starting bulk dlc conversion for slrx")
            logger.info("Before deleting device_ip from dlc_data_dict")
            logger.info(dlcRequest)
            for item in dlcRequest['virtualAccounts'][0]['dlcRequests']:
                item['sudi'].pop('device_ip')
            logger.info("After deleting device_ip from dlc_data_dict")
            logger.info(dlcRequest)
            dlc_payload = json.dumps(dlcRequest)
            logger.info(dlc_payload)
        try:
            for x in range(2):
                response = requests.request("POST", url, data=dlc_payload, headers=headers, timeout=10)
                try:
                    response = response.json()
                    for item in response["devices"]:
                        conversion_status = "dlc_" + item["conversionStatus"].lower()
                        udi_pid = item["sudi"]["udiPid"]
                        device_ip = TokensModel.find_device_ip(uuid,udi_pid)
                        if conversion_status != "dlc_in_progress":
                            TokensModel.insert_dlc_status(uuid, device_ip, conversion_status)
                        logger.info("**********DLC conversion status******")
                        logger.info(conversion_status)
                        if conversion_status == "dlc_convert_failed":
                            logger.info("DLC Failed")
                            logger.info(response)
                            break
                except Exception as e:
                    logger.error(e)
                    logger.error("Failed to parse DLC conversion response ")
                time.sleep(180)
        except Exception as e:
            logger.error(e)
            logger.error("DLC conversion request timed out")