File: create_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 (51 lines) | stat: -rw-r--r-- 1,744 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
50
51
module Fog
  module OpenStack
    class Image
      class V2
        class Real
          def create_image(image)
            location = image.delete :location
            headers = {}
            headers["Location"] = location if location

            request(
              :headers => headers,
              :expects => [201],
              :method  => 'POST',
              :path    => "images",
              :body    => Fog::JSON.encode(image)
            )
          end
        end

        class Mock
          def create_image(attributes)
            response = Excon::Response.new
            response.status = 201

            image_id = Fog::Mock.random_hex(32)
            image = data[:images][image_id] = {
              'tags'             => attributes[:tags] || [],
              'name'             => attributes[:name],
              'size'             => nil,
              'min_disk'         => attributes[:min_disk] || 0,
              'disk_format'      => attributes[:disk_format] || 'raw',
              'created_at'       => Time.now.strftime('%FT%T.%6N'),
              'container_format' => attributes[:container_format] || 'bare',
              'deleted_at'       => nil,
              'updated_at'       => Time.now.strftime('%FT%T.%6N'),
              'checksum'         => nil,
              'id'               => image_id,
              'visibility'       => attributes[:visibility] || 'public',
              'status'           => 'queued',
              'min_ram'          => attributes[:min_ram] || 0,
              'owner'            => attributes[:owner] || Fog::Mock.random_hex(32)
            }
            response.body = image
            response
          end
        end
      end
    end
  end
end