Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new Definition to upload firmware images greater than 2GB in size #243

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update ucsgenutils.py
aapatwa authored Mar 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 51eca299033b40657363401bb0d56152ad3da5b0
19 changes: 11 additions & 8 deletions ucsmsdk/ucsgenutils.py
Original file line number Diff line number Diff line change
@@ -236,7 +236,7 @@ def read_in_chunks(file_object, chunk_size=10*1024*1024):
yield data


def generate_uri_for_chunks(uri,counter,flag):
def generate_uri_for_chunks(uri, counter, flag):
"""(generator) to generate uri for chunks
and return URI"""
index = uri.rfind("/")
@@ -269,27 +269,30 @@ def upload_firmware(driver, uri, file_dir, file_name, progress=Progress()):
content_path = os.path.join(file_dir, file_name)
content_size = os.path.getsize(content_path)

if not os.path.exists(content_path):
raise IOError("File does not exist")

f = open(content_path,'rb')
CHUNK_SIZE = 10*1024*1024
chunk_size = 10*1024*1024
counter = 0
flag = 0

for chunk in read_in_chunks(f,CHUNK_SIZE):
for chunk in read_in_chunks(f, chunk_size):
if len(chunk) > 0:
try:
counter += 1
uri1 = generate_uri_for_chunks(uri,counter,flag)
response = driver.post(uri1, data = chunk)
progress.update(content_size,len(chunk))
chunk_uri = generate_uri_for_chunks(uri, counter, flag)
response = driver.post(chunk_uri, data = chunk)
progress.update(content_size, len(chunk))
if not response:
raise ValueError("File upload failed.")
except Exception as e:
raise Exception(e)
try:
counter += 1
flag = 1
uri2 = generate_uri_for_chunks(uri,counter,flag)
response = driver.post(uri2)
merge_uri = generate_uri_for_chunks(uri, counter, flag)
response = driver.post(merge_uri)
if not response:
raise ValueError("File upload failed.")
except Exception as e: