File: update_image.rb

package info (click to toggle)
ruby-fog-openstack 1.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,784 kB
  • sloc: ruby: 47,937; makefile: 5; sh: 4
file content (49 lines) | stat: -rw-r--r-- 1,883 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module Fog
  module OpenStack
    class Image
      class V2
        class Real
          def update_image(id, json_patch)
            request(
              :headers => {'Content-Type' => 'application/openstack-images-v2.1-json-patch'},
              :expects => [200],
              :method  => 'PATCH',
              :path    => "images/#{id}",
              :body    => Fog::JSON.encode(json_patch)
            )
          end
        end

        class Mock
          def update_image(attributes)
            response = Excon::Response.new
            response.status = 200
            image = images.last
            response.body = {
              'image' => {
                'name'             => attributes[:name] || image.name,
                'size'             => image.size,
                'min_disk'         => (attributes[:min_disk] || image.min_disk).to_i,
                'disk_format'      => attributes[:disk_format] || image.disk_format,
                'created_at'       => image.created_at,
                'container_format' => attributes[:container_format] || image.container_format,
                'deleted_at'       => nil,
                'updated_at'       => Time.now.to_s,
                'checksum'         => image.checksum,
                'id'               => attributes[:id],
                'deleted'          => false,
                'protected'        => false,
                'is_public'        => attributes[:is_public] || image.is_public,
                'status'           => image.status,
                'min_ram'          => (attributes[:min_ram] || image.min_ram).to_i,
                'owner'            => attributes[:owner] || image.owner,
                'properties'       => attributes[:properties] || image.properties
              }
            }
            response
          end
        end
      end
    end
  end
end