Last active
October 21, 2015 04:35
-
-
Save jjam3774/979ea5102970fbd48f3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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