Sha256: c5d647e34e323d7d79a2d69f02423236232ef9df15d5acc49c272d3e1c754247

Contents?: true

Size: 1.61 KB

Versions: 12

Compression:

Stored size: 1.61 KB

Contents

module Fog
  module Compute
    class Google

      class Mock

        def insert_disk(disk_name)
          Fog::Mock.not_implemented
        end

      end

      class Real

        def insert_disk(disk_name, zone_name, image_name=nil, opts={})
          api_method = @compute.disks.insert
          parameters = {
            'project' => @project,
            'zone' => zone_name
          }

          if image_name
            image = images.get(image_name)
            raise ArgumentError.new('Invalid image specified') unless image
            @image_url = @api_url + image.resource_url
            parameters['sourceImage'] = @image_url
          end

          body_object = { 'name' => disk_name }

          # These must be present if image_name is not specified
          if image_name.nil?
            unless opts.has_key?('sourceSnapshot') and opts.has_key?('sizeGb')
              raise ArgumentError.new('Must specify image OR snapshot and '\
                                      'disk size when creating a disk.')
            end

            body_object['sizeGb'] = opts.delete('sizeGb')

            snap = snapshots.get(opts.delete('sourceSnapshot'))
            raise ArgumentError.new('Invalid source snapshot') unless snap
            body_object['sourceSnapshot'] = @api_url + snap.resource_url
          end

          # Merge in any remaining options (only 'description' should remain)
          body_object.merge(opts)

          result = self.build_result(api_method, parameters,
                                     body_object)
          response = self.build_response(result)
        end

      end

    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
fog-maestrodev-1.18.0.20131121075022 lib/fog/google/requests/compute/insert_disk.rb
fog-maestrodev-1.18.0.20131118164830 lib/fog/google/requests/compute/insert_disk.rb
fog-maestrodev-1.18.0.20131115184302 lib/fog/google/requests/compute/insert_disk.rb
fog-maestrodev-1.18.0.20131114200144 lib/fog/google/requests/compute/insert_disk.rb
fog-maestrodev-1.18.0.20131112185232 lib/fog/google/requests/compute/insert_disk.rb
fog-maestrodev-1.18.0.20131111203459 lib/fog/google/requests/compute/insert_disk.rb
fog-1.18.0 lib/fog/google/requests/compute/insert_disk.rb
fog-1.17.0 lib/fog/google/requests/compute/insert_disk.rb
fog-1.16.0 lib/fog/google/requests/compute/insert_disk.rb
fog-maestrodev-1.15.0.20130927082724 lib/fog/google/requests/compute/insert_disk.rb
fog-maestrodev-1.15.0.20130829165835 lib/fog/google/requests/compute/insert_disk.rb
fog-1.15.0 lib/fog/google/requests/compute/insert_disk.rb