Skip to content

Instantly share code, notes, and snippets.

@jjam3774
Last active October 21, 2015 04:35
Show Gist options
  • Save jjam3774/979ea5102970fbd48f3a to your computer and use it in GitHub Desktop.
Save jjam3774/979ea5102970fbd48f3a to your computer and use it in GitHub Desktop.
def disk_size
require 'win32ole'
###
# This Enables us to download files via the internet
###
require 'open-uri'
disk_size = nil
disk_free_space = nil
###
# Access to gwmi or wmi modules
###
wmi = WIN32OLE.connect("winmgmts://")
###
# Query win32_logicaldisk
###
disk = wmi.ExecQuery("select * from win32_logicaldisk where DeviceID='C:'")
disk.each{|i|
###
# Convert to G
###
puts "Disk Size is #{(i.Size.to_f/1073741824.0).to_i}G".upcase
###
# Find out Disk Capacity
###
puts "Disk Free Space is #{(i.FreeSpace.to_f/1073741824.0).to_i}G".upcase
disk_size = (i.Size.to_f/1073741824.0).to_f
disk_free_space = (i.FreeSpace.to_f/1073741824.0).to_f
}
disk_space = ((disk_free_space/disk_size)*100).to_f
puts "The percentage free is #{disk_space}%".upcase
#Checking if there is enough room for installation
if disk_space <= 4.0
puts "System Does not have enough disk space..\ Will not continue with installation...".upcase
else
#
puts "System Has Enough Space for installation....".upcase
puts "Downloading file for installation to: #{Chef::Config[:file_cache_path]}"
###
# Download the install file
###
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment