class Chef::Knife::SceVolumeCreate

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/sce_volume_create.rb, line 55
def run
  
  $stdout.sync = true
  
  Fog.timeout = Chef::Config[:knife][:sce_max_timeout] || 6000

  validate!
  
  disk_launch_desc = {
    :name => config[:name],
    :offering_id => config[:offering_id],
    :format => config[:format].upcase,
    :location_id => datacenter_id,
    :size => config[:size]
  }
  
  puts "Creating volume #{config[:name]}"
  
  volume = connection_storage.volumes.create(disk_launch_desc)
  
  puts "Volume #{config[:name]} created, volume ID is #{volume.id}. Waiting for ready..."
  
  volume.wait_for { ready? }
  
  puts "Volume #{config[:name]} ready to use."
  
  puts "\n"
  
  volume.id.to_s
  msg_pair("Volume ID", volume.id.to_s )
  msg_pair("Name", volume.name.to_s )
  msg_pair("State", volume.state.to_s )
  msg_pair("Size", volume.size.to_s )
  msg_pair("Location", connection.locations.get(volume.location_id).name )
  msg_pair("Format", volume.format.to_s )
  msg_pair("Offering ID", volume.offering_id.to_s )
  msg_pair("Owner", volume.owner.to_s )
  
end
validate!() click to toggle source
Calls superclass method
# File lib/chef/knife/sce_volume_create.rb, line 95
def validate!

  super([:ibm_username, :ibm_password, :size, :format, :offering_id, :datacenter, :name])
  
  @offering = connection_storage.offerings.get( config[:offering_id] )
  
  if @offering.nil?
    ui.error("Storage offering #{config[:offering_id]} does not exist.")
    exit 1
  else
    
    formats = []
    @offering.supported_formats.each do |format|
      formats << format["id"]
    end
    sizes = @offering.supported_sizes.split(",")
    
    if !formats.include?( config[:format].upcase )
      ui.error("Format #{config[:format].upcase} not supported.")
      exit 1
    end
    if !sizes.include?( config[:size] )
      ui.error("Format #{config[:size]} not supported.")
      exit 1
    end
  end

end