def firmware_add_remote(handle, remote_path, file_name, protocol, hostname, username="", password=""): ''' Import the firmware to UcsCentral from remote location Args: remote_path (str): Remote path where image resides file_name (str): Name of the image in the remote directory protocol (str): Protocol for the remote communication hostname (str): IP address or the host name of the remote server username (str): Username for the remote server access password (str): Password for the remote server access Example: firmware_add_remote(handle, file_name="ucs-k9-bundle-b-series.3.1.1h.B.bin", remote_path="/remote_path/", hostname="10.10.1.1", protocol="scp",username="******",password="******") ''' if not hostname: raise UcscValidationException("Missing hostname argument") if not remote_path: raise UcscValidationException("Missing remote_path argument") if not file_name: raise UcscValidationException("Missing file_name argument") if not protocol: raise UcscValidationException("Missing protocol argument") if protocol is not FirmwareDownloaderConsts.PROTOCOL_TFTP: if not username: raise UcscValidationException("Missing username argument") if not password: raise UcscValidationException("Missing password argument") top_system = TopSystem() firmware_catalogue = FirmwareCatalogue(parent_mo_or_dn=top_system) firmware_downloader = FirmwareDownloader( parent_mo_or_dn=firmware_catalogue, file_name=file_name) firmware_downloader.remote_path = remote_path firmware_downloader.protocol = protocol firmware_downloader.server = hostname firmware_downloader.user = username firmware_downloader.pwd = password firmware_downloader.admin_state = \ FirmwareDownloaderConsts.ADMIN_STATE_RESTART handle.add_mo(firmware_downloader, modify_present=True) handle.commit()
def firmware_add_local(handle, local_path, file_name, timeout=15 * 60, progress=Progress()): ''' Import the firmware to UcsCentral from local drive Args: local_path (str): Local directory where image resides file_name (str): Name of the image in the local directory timeout (number): Timeout in seconds for the image to get uploaded to ucs central Example: firmware_add_local(handle,"/Users/guest/Downloads/", "ucs-k9-bundle-b-series.3.1.1h.B.bin") ''' if not local_path: raise UcscValidationException("Missing local_path argument") if not file_name: raise UcscValidationException("Missing file_name argument") file_path = os.path.join(local_path, file_name) if not os.path.exists(file_path): raise UcscValidationException("File does not exist") top_system = TopSystem() firmware_catalogue = FirmwareCatalogue(parent_mo_or_dn=top_system) firmware_downloader = FirmwareDownloader( parent_mo_or_dn=firmware_catalogue, file_name=file_name) firmware_downloader.server = FirmwareDownloaderConsts.PROTOCOL_LOCAL firmware_downloader.protocol = FirmwareDownloaderConsts.PROTOCOL_LOCAL firmware_downloader.admin_state = \ FirmwareDownloaderConsts.ADMIN_STATE_RESTART try: log.debug("Start uploading firmware") uri_suffix = "operations/file-%s/image.txt?Cookie=%s" % (file_name, handle.cookie) handle.file_upload(url_suffix=uri_suffix, file_dir=local_path, file_name=file_name, progress=progress) except Exception as err: UcscWarning(str(err)) raise UcscOperationError("Upload firmware", "upload failed") handle.add_mo(firmware_downloader, modify_present=True) handle.commit() start = datetime.datetime.now() while not firmware_downloader.transfer_state == \ FirmwareDownloaderConsts.TRANSFER_STATE_DOWNLOADED: firmware_downloader = handle.query_dn(firmware_downloader.dn) if firmware_downloader.transfer_state == \ FirmwareDownloaderConsts.TRANSFER_STATE_FAILED: raise UcscOperationError( "Import of %s " % file_name, "%s" % firmware_downloader.fsm_rmt_inv_err_descr) if (datetime.datetime.now() - start).total_seconds() > timeout: raise UcscOperationError("Import of %s" % file_name, "operation timed out") time.sleep(1) return firmware_downloader
def firmware_add_local(handle, local_path, file_name, timeout=15 * 60, progress=Progress()): ''' Import the firmware to UcsCentral from local drive Args: local_path (str): Local directory where image resides file_name (str): Name of the image in the local directory timeout (number): Timeout in seconds for the image to get uploaded to ucs central Example: firmware_add_local(handle,"/Users/guest/Downloads/", "ucs-k9-bundle-b-series.3.1.1h.B.bin") ''' if not local_path: raise UcscValidationException("Missing local_path argument") if not file_name: raise UcscValidationException("Missing file_name argument") file_path = os.path.join(local_path, file_name) if not os.path.exists(file_path): raise UcscValidationException("File does not exist") top_system = TopSystem() firmware_catalogue = FirmwareCatalogue(parent_mo_or_dn=top_system) firmware_downloader = FirmwareDownloader( parent_mo_or_dn=firmware_catalogue, file_name=file_name) firmware_downloader.server = FirmwareDownloaderConsts.PROTOCOL_LOCAL firmware_downloader.protocol = FirmwareDownloaderConsts.PROTOCOL_LOCAL firmware_downloader.admin_state = \ FirmwareDownloaderConsts.ADMIN_STATE_RESTART try: log.debug("Start uploading firmware") uri_suffix = "operations/file-%s/image.txt?Cookie=%s" % ( file_name, handle.cookie) handle.file_upload(url_suffix=uri_suffix, file_dir=local_path, file_name=file_name, progress=progress) except Exception as err: UcscWarning(str(err)) raise UcscOperationError("Upload firmware", "upload failed") handle.add_mo(firmware_downloader, modify_present=True) handle.commit() start = datetime.datetime.now() while not firmware_downloader.transfer_state == \ FirmwareDownloaderConsts.TRANSFER_STATE_DOWNLOADED: firmware_downloader = handle.query_dn(firmware_downloader.dn) if firmware_downloader.transfer_state == \ FirmwareDownloaderConsts.TRANSFER_STATE_FAILED: raise UcscOperationError( "Import of %s " % file_name, "%s" % firmware_downloader.fsm_rmt_inv_err_descr) if (datetime.datetime.now() - start).total_seconds() > timeout: raise UcscOperationError( "Import of %s" % file_name, "operation timed out") time.sleep(1) return firmware_downloader