Class: Fog::Image::OpenStack::Mock
- Inherits:
-
Object
- Object
- Fog::Image::OpenStack::Mock
- Defined in:
- lib/fog/openstack/requests/image/get_image.rb,
lib/fog/openstack/image.rb,
lib/fog/openstack/requests/image/set_tenant.rb,
lib/fog/openstack/requests/image/create_image.rb,
lib/fog/openstack/requests/image/delete_image.rb,
lib/fog/openstack/requests/image/update_image.rb,
lib/fog/openstack/requests/image/get_image_by_id.rb,
lib/fog/openstack/requests/image/get_image_members.rb,
lib/fog/openstack/requests/image/get_shared_images.rb,
lib/fog/openstack/requests/image/list_public_images.rb,
lib/fog/openstack/requests/image/add_member_to_image.rb,
lib/fog/openstack/requests/image/remove_member_from_image.rb,
lib/fog/openstack/requests/image/list_public_images_detailed.rb
Overview
class Real
Class Method Summary collapse
Instance Method Summary collapse
- #add_member_to_image(image_id, tenant_id) ⇒ Object
- #create_image(attributes) ⇒ Object
- #credentials ⇒ Object
- #data ⇒ Object
- #delete_image(image_id) ⇒ Object
- #get_image(image_id) ⇒ Object
- #get_image_by_id(image_id) ⇒ Object
- #get_image_members(image_id) ⇒ Object
- #get_shared_images(tenant_id) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_public_images ⇒ Object
- #list_public_images_detailed ⇒ Object
- #remove_member_from_image(image_id, member_id) ⇒ Object
- #reset_data ⇒ Object
- #set_tenant(tenant) ⇒ Object
- #update_image(attributes) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fog/openstack/image.rb', line 48 def initialize(={}) require 'multi_json' @openstack_username = [:openstack_username] @data ||= { :users => {} } unless @data[:users].find {|u| u['name'] == [:openstack_username]} id = Fog::Mock.random_numbers(6).to_s @data[:users][id] = { 'id' => id, 'name' => [:openstack_username], 'email' => "#{[:openstack_username]}@mock.com", 'tenantId' => Fog::Mock.random_numbers(6).to_s, 'enabled' => true } end end |
Class Method Details
.data ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/fog/openstack/image.rb', line 35 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :users => {}, :tenants => {} } end end |
.reset ⇒ Object
44 45 46 |
# File 'lib/fog/openstack/image.rb', line 44 def self.reset @data = nil end |
Instance Method Details
#add_member_to_image(image_id, tenant_id) ⇒ Object
15 16 17 18 19 |
# File 'lib/fog/openstack/requests/image/add_member_to_image.rb', line 15 def add_member_to_image(image_id, tenant_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response end |
#create_image(attributes) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fog/openstack/requests/image/create_image.rb', line 49 def create_image(attributes) response = Excon::Response.new response.status = 201 response.body = {"image"=> {"name"=>"new image", "size"=>0, "min_disk"=>0, "disk_format"=>nil, "created_at"=>"2012-02-24T06:45:00", "container_format"=>nil, "deleted_at"=>nil, "updated_at"=>"2012-02-24T06:45:00", "checksum"=>nil, "id"=>"e41304f3-2453-42b4-9829-2e220a737395", "deleted"=>false, "protected"=>false, "is_public"=>false, "status"=>"queued", "min_ram"=>0, "owner"=>"728ecc7c10614a1faa6fbabd1a68a4a0", "properties"=>{} } } response end |
#credentials ⇒ Object
73 74 75 76 77 78 |
# File 'lib/fog/openstack/image.rb', line 73 def credentials { :provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_management_url => @openstack_management_url } end |
#data ⇒ Object
65 66 67 |
# File 'lib/fog/openstack/image.rb', line 65 def data self.class.data[@openstack_username] end |
#delete_image(image_id) ⇒ Object
18 19 20 21 22 |
# File 'lib/fog/openstack/requests/image/delete_image.rb', line 18 def delete_image(image_id) response = Excon::Response.new response.status = 200 response end |
#get_image(image_id) ⇒ Object
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 |
# File 'lib/fog/openstack/requests/image/get_image.rb', line 15 def get_image(image_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response.headers= {"X-Image-Meta-Is_public"=>"True", "X-Image-Meta-Min_disk"=>"0", "X-Image-Meta-Property-Ramdisk_id"=>"b45aa128-cd36-4ad9-a026-1a1c2bfd8fdc", "X-Image-Meta-Disk_format"=>"ami", "X-Image-Meta-Created_at"=>"2012-02-21T07:32:26", "X-Image-Meta-Container_format"=>"ami", "Etag"=>"2f81976cae15c16ef0010c51e3a6c163", "Location"=>"http://192.168.27.100:9292/v1/images/0e09fbd6-43c5-448a-83e9-0d3d05f9747e", "X-Image-Meta-Protected"=>"False", "Date"=>"Fri, 24 Feb 2012 02:14:25 GMT", "X-Image-Meta-Name"=>"cirros-0.3.0-x86_64-blank", "X-Image-Meta-Min_ram"=>"0", "Content-Type"=>"text/html; charset=UTF-8", "X-Image-Meta-Updated_at"=>"2012-02-21T07:32:29", "X-Image-Meta-Property-Kernel_id"=>"cd28951e-e1c2-4bc5-95d3-f0495abbcdc5", "X-Image-Meta-Size"=>"25165824", "X-Image-Meta-Checksum"=>"2f81976cae15c16ef0010c51e3a6c163", "X-Image-Meta-Deleted"=>"False", "Content-Length"=>"0", "X-Image-Meta-Owner"=>"ff528b20431645ebb5fa4b0a71ca002f", "X-Image-Meta-Status"=>"active", "X-Image-Meta-Id"=>"0e09fbd6-43c5-448a-83e9-0d3d05f9747e"} response.body = "" response end |
#get_image_by_id(image_id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/openstack/requests/image/get_image_by_id.rb', line 15 def get_image_by_id(image_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "images"=>[{ "name"=>"mock-image-name", "size"=>25165824, "disk_format"=>"ami", "container_format"=>"ami", "id"=>"0e09fbd6-43c5-448a-83e9-0d3d05f9747e", "checksum"=>"2f81976cae15c16ef0010c51e3a6c163"}] } response end |
#get_image_members(image_id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fog/openstack/requests/image/get_image_members.rb', line 15 def get_image_members(image_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "members"=>[ {"member_id"=>"ff528b20431645ebb5fa4b0a71ca002f", "can_share"=>false} ] } response end |
#get_shared_images(tenant_id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fog/openstack/requests/image/get_shared_images.rb', line 15 def get_shared_images(tenant_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "shared_images"=>[ {"image_id"=>"ff528b20431645ebb5fa4b0a71ca002f", "can_share"=>false} ] } response end |
#list_public_images ⇒ Object
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 |
# File 'lib/fog/openstack/requests/image/list_public_images.rb', line 15 def list_public_images response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "images"=>[{ "name"=>"mock-image-name", "size"=>25165824, "disk_format"=>"ami", "container_format"=>"ami", "id"=>"0e09fbd6-43c5-448a-83e9-0d3d05f9747e", "checksum"=>"2f81976cae15c16ef0010c51e3a6c163"}, {"name"=>"new image", "size"=>0, "min_disk"=>0, "disk_format"=>nil, "created_at"=>"2012-02-24T06:45:00", "container_format"=>nil, "deleted_at"=>nil, "updated_at"=>"2012-02-24T06:45:00", "checksum"=>nil, "id"=>"e41304f3-2453-42b4-9829-2e220a737395", "deleted"=>false, "protected"=>false, "is_public"=>false, "status"=>"queued", "min_ram"=>0, "owner"=>"728ecc7c10614a1faa6fbabd1a68a4a0", "properties"=>{} }] } response end |
#list_public_images_detailed ⇒ Object
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fog/openstack/requests/image/list_public_images_detailed.rb', line 22 def list_public_images_detailed response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = {"images"=>[{ "name"=>"cirros-0.3.0-x86_64-blank", "size"=>25165824, "min_disk"=>0, "disk_format"=>"ami", "created_at"=>"2012-02-21T07:32:26", "container_format"=>"ami", "deleted_at"=>nil, "updated_at"=>"2012-02-21T07:32:29", "checksum"=>"2f81976cae15c16ef0010c51e3a6c163", "id"=>"0e09fbd6-43c5-448a-83e9-0d3d05f9747e", "deleted"=>false, "protected"=>false, "is_public"=>true, "status"=>"active", "min_ram"=>0, "owner"=>"ff528b20431645ebb5fa4b0a71ca002f", "properties"=>{ "ramdisk_id"=>"b45aa128-cd36-4ad9-a026-1a1c2bfd8fdc", "kernel_id"=>"cd28951e-e1c2-4bc5-95d3-f0495abbcdc5"} }, {"name"=>"new image", "size"=>0, "min_disk"=>0, "disk_format"=>nil, "created_at"=>"2012-02-24T06:45:00", "container_format"=>nil, "deleted_at"=>nil, "updated_at"=>"2012-02-24T06:45:00", "checksum"=>nil, "id"=>"e41304f3-2453-42b4-9829-2e220a737395", "deleted"=>false, "protected"=>false, "is_public"=>false, "status"=>"queued", "min_ram"=>0, "owner"=>"728ecc7c10614a1faa6fbabd1a68a4a0", "properties"=>{} }] } response end |
#remove_member_from_image(image_id, member_id) ⇒ Object
15 16 17 18 19 |
# File 'lib/fog/openstack/requests/image/remove_member_from_image.rb', line 15 def remove_member_from_image(image_id, member_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response end |
#reset_data ⇒ Object
69 70 71 |
# File 'lib/fog/openstack/image.rb', line 69 def reset_data self.class.data.delete(@openstack_username) end |
#set_tenant(tenant) ⇒ Object
14 15 16 |
# File 'lib/fog/openstack/requests/image/set_tenant.rb', line 14 def set_tenant(tenant) true end |
#update_image(attributes) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fog/openstack/requests/image/update_image.rb', line 35 def update_image(attributes) response = Excon::Response.new response.status = 200 response.body = {"image"=> {"name"=>"edit test image", "size"=>0, "min_disk"=>0, "disk_format"=>nil, "created_at"=>"2012-02-24T06:45:00", "container_format"=>nil, "deleted_at"=>nil, "updated_at"=>"2012-02-24T06:45:00", "checksum"=>nil, "id"=>"e41304f3-2453-42b4-9829-2e220a737395", "deleted"=>false, "protected"=>false, "is_public"=>false, "status"=>"queued", "min_ram"=>0, "owner"=>"728ecc7c10614a1faa6fbabd1a68a4a0", "properties"=>{} } } response end |