class Chef::Knife::VsphereDatastoreMaxfree

Gets the data store with the most free space in datacenter VsphereDatastoreMaxfree extends the BaseVspherecommand

Public Instance Methods

run() click to toggle source

The main run method for datastore_maxfree

# File lib/chef/knife/vsphere_datastore_maxfree.rb, line 48
def run
  $stdout.sync = true
  if get_config(:vlan) && get_config(:pool)
    fatal_exit("Please select either vlan or pool")
  end

  vim_connection
  regex = /#{get_config(:regex)}/
  max = nil
  datastores = find_datastores
  datastores.each do |store|
    if regex.match(store.name) &&
        (max.nil? || max.summary[:freeSpace] < store.summary[:freeSpace])
      max = store
    end
  end
  ui.output(max ? { "Datastore" => max.name } : {})
end