Skip to content

Instantly share code, notes, and snippets.

@jcpowermac
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save jcpowermac/9504b2f2884fdbcc2503 to your computer and use it in GitHub Desktop.

Select an option

Save jcpowermac/9504b2f2884fdbcc2503 to your computer and use it in GitHub Desktop.
diff --git a/core/image_service/base.rb b/core/image_service/base.rb
index 90433cb..be09592 100644
--- a/core/image_service/base.rb
+++ b/core/image_service/base.rb
@@ -9,7 +9,7 @@ module ProjectHanlon
MOUNT_COMMAND = (Process::uid == 0 ? "mount" : "sudo -n mount")
UMOUNT_COMMAND = (Process::uid == 0 ? "umount" : "sudo -n umount")
- # I absolutely do not like hardcoding this
+ # TODO - determine another method for providing the path to 7z, configuration file?
SEVENZIP_COMMAND = "/usr/bin/7z"
@@ -69,7 +69,6 @@ module ProjectHanlon
return cleanup([false, "Cannot create image path: '#{image_path}'",handler])
end
-
if !handler
unless mount(fullpath)
logger.error "Could not mount '#{fullpath}' on '#{mount_path}'"
@@ -80,26 +79,8 @@ module ProjectHanlon
copy_to_image_path(handler, fullpath)
verification(handler, fullpath)
-
- # if handler
- # #add_iso(fullpath)
- # # Attempt to copy from mount path to image path
- # copy_to_image_path(true, fullpath)
- # verification(handler, fullpath)
- # else
- # unless mount(fullpath)
- # logger.error "Could not mount '#{fullpath}' on '#{mount_path}'"
- # return cleanup([false, "Could not mount '#{fullpath}' on '#{mount_path}'"])
- # end
- # end
- #
- # # Attempt to copy from mount path to image path
- # copy_to_image_path(false, fullpath)
- # verification(handler, fullpath)
- # #add_mount(fullpath)
- # end
-
- File.size(src_image_path)
+ # Commented out don't see it being used anywhere
+ #File.size(src_image_path)
rescue => e
logger.error e.message
@@ -107,8 +88,12 @@ module ProjectHanlon
end
cleanup([true , '',handler])
+ # umount
+ #TODO - umount & return array
end
+
+ # TODO - modify, instead of invoke clean, use whatever to cleanup the directory
# Used to remove an image to the service
# Within each child class the methods are overridden for that child template
def remove(lcl_image_path)
@@ -117,25 +102,6 @@ module ProjectHanlon
!File.directory?(image_path)
end
- # def add_mount(fullpath)
- # #Confirm a mount doesn't already exist
- # unless is_mounted?(fullpath)
- # unless mount(fullpath)
- # logger.error "Could not mount '#{fullpath}' on '#{mount_path}'"
- # return cleanup([false,"Could not mount '#{fullpath}' on '#{mount_path}'",false])
- # end
- # end
- #
- # # Attempt to copy from mount path to image path
- # copy_to_image_path(false, fullpath)
- # verification(handler, fullpath)
- # end
- #
- # def add_iso(fullpath)
- # # Attempt to copy from mount path to image path
- # copy_to_image_path(true, fullpath)
- # verification(handler, fullpath)
- # end
# Verify diff between mount / image paths
# For speed/flexibility reasons we just verify all files exists and not their contents
@@ -153,7 +119,6 @@ module ProjectHanlon
end
end
-
def archive_handler?
# if 7zip exists use it to extract the ISO,
# if not fall back to mount and/or sudo mount
@@ -168,8 +133,6 @@ module ProjectHanlon
end
end
-
-
# Used to verify an image within the filesystem (local/remote/possible Glance)
# Within each child class the methods are overridden for that child emplate
def verify(lcl_image_path)
@@ -217,6 +180,15 @@ module ProjectHanlon
`#{MOUNT_COMMAND}`.split("\n").map! {|x| x.split("on")}.map! {|x| [x[0],x[1].split(" ")[0]]}
end
+ def cleanup_on_failure(errormsg)
+ # unmount, if mounted
+ # remove directory if created
+ logger.error "Error: #{errormsg}"
+ # raise errormsg
+ end
+ # TODO - need to see the error in the response of the restful interface
+ # TODO - an array with three values, replace with three args
+ # TODO - split this into multiple methods success and the other for failure
def cleanup(ret)
umount if !ret[2]
remove_dir_completely(mount_path) if !ret[2]
@@ -247,9 +219,7 @@ module ProjectHanlon
def copy_to_image_path(handler, fullpath)
if handler
- puts "/usr/bin/7z x -xr'![BOOT]' -y -o#{image_path} #{fullpath}"
output = %x{ /usr/bin/7z x -xr'![BOOT]' -y -o#{image_path} #{fullpath}}
- puts output
else
FileUtils.cp_r(mount_path + "/.", image_path)
end
@@ -257,15 +227,13 @@ module ProjectHanlon
def get_dir_hash(dir)
logger.debug "Generating hash for path: #{dir}"
-
files_string = Dir.glob("#{dir}/**/*").map {|x| x.sub("#{dir}/","")}.sort.join("\n")
Digest::SHA2.hexdigest(files_string)
end
def get_iso_hash(fullpath)
logger.debug "Generating hash for path: #{image_path}"
- #puts "/usr/bin/7z l -slt #{image_path}"
- files_string =%x[7z l -slt #{fullpath}].split("\n").map{ |x| val = /^Path\s+=\s+(.*)$/.match(x); val[1] if val && val[1] != @filename }.compact.select{ |x| !(/^\[BOOT\]/.match(x)) }.sort.join("\n")
+ files_string =%x[7z l -slt #{fullpath}].split("\n").map{ |x| val = /^Path\s+=\s+(.*)$/.match(x); val[1] if val && val[1] != fullpath }.compact.select{ |x| !/^\[BOOT\]/.match(x) && !/^\./.match(x) }.sort.join("\n")
Digest::SHA2.hexdigest(files_string)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment