Sha256: 49876fbe0ce8b964c59986d02ebdf1fb7c2afcc2249eb60f35d22938823076e1

Contents?: true

Size: 1.63 KB

Versions: 3

Compression:

Stored size: 1.63 KB

Contents

module Fog
  module Compute
    class Vsphere
      class Real
        def upload_iso_check_options(options)
          default_options = {
            'upload_directory' => 'isos',
          }
          options = default_options.merge(options)
          required_options = %w{ datacenter datastore local_path }
          required_options.each do |param|
            raise ArgumentError, "#{required_options.join(', ')} are required" unless options.key? param
          end
          raise Fog::Compute::Vsphere::NotFound, "Datacenter #{options["datacenter"]} Doesn't Exist!" unless get_datacenter(options["datacenter"])
          raise Fog::Compute::Vsphere::NotFound, "Datastore #{options["datastore"]} Doesn't Exist!" unless get_raw_datastore(options['datastore'], options['datacenter'])
          options
        end

        def upload_iso(options = {})
          options = upload_iso_check_options(options)
          datastore = get_raw_datastore(options['datastore'], options['datacenter'])
          datacenter = get_datacenter(options['datacenter'])
          filename = options['filename'] || File.basename(options['local_path'])
          unless datastore.exists? options['upload_directory']+'/'
            @connection.serviceContent.fileManager.MakeDirectory :name => "[#{options['datastore']}] #{options['directory']}",
                                                                 :datacenter => datacenter,
                                                                 :createParentDirectories => false
          end
          datastore.upload options['upload_directory']+'/'+filename, options['local_path']
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fog-vsphere-0.5.0 lib/fog/vsphere/requests/compute/upload_iso.rb
fog-vsphere-0.4.0 lib/fog/vsphere/requests/compute/upload_iso.rb
fog-vsphere-0.3.0 lib/fog/vsphere/requests/compute/upload_iso.rb