Parent

Class/Module Index [+]

Quicksearch

Fog::Image::OpenStack::Mock

Public Class Methods

data() click to toggle source
# File lib/fog/openstack/image.rb, line 36
def self.data
  @data ||= Hash.new do |hash, key|
    hash[key] = {
      :images => {}
    }
  end
end
new(options={}) click to toggle source
# File lib/fog/openstack/image.rb, line 48
def initialize(options={})
  @openstack_username = options[:openstack_username]
  @openstack_tenant   = options[:openstack_tenant]
  @openstack_auth_uri = URI.parse(options[:openstack_auth_url])

  @auth_token = Fog::Mock.random_base64(64)
  @auth_token_expiration = (Time.now.utc + 86400).iso8601

  management_url = URI.parse(options[:openstack_auth_url])
  management_url.port = 9292
  management_url.path = '/v1'
  @openstack_management_url = management_url.to_s

  @data ||= { :users => {} }
  unless @data[:users].find {|u| u['name'] == options[:openstack_username]}
    id = Fog::Mock.random_numbers(6).to_s
    @data[:users][id] = {
      'id'       => id,
      'name'     => options[:openstack_username],
      'email'    => "#{options[:openstack_username]}@mock.com",
      'tenantId' => Fog::Mock.random_numbers(6).to_s,
      'enabled'  => true
    }
  end
end
reset() click to toggle source
# File lib/fog/openstack/image.rb, line 44
def self.reset
  @data = nil
end

Public Instance Methods

add_member_to_image(image_id, tenant_id) click to toggle source
# 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) click to toggle source
# File lib/fog/openstack/requests/image/create_image.rb, line 49
def create_image(attributes)
  response = Excon::Response.new
  response.status = 201

  image_id = Fog::Mock.random_hex(32)
  image = self.data[:images][image_id] = {
    'name'             => attributes['name'] || attributes[:name],
    'size'             => Fog::Mock.random_numbers(8).to_i,
    'min_disk'         => 0,
    'disk_format'      => attributes['disk_format'] || attributes[:disk_format] || 'raw',
    'created_at'       => Time.now.to_s,
    'container_format' => attributes['container_format'] || attributes[:container_format] || 'bare',
    'deleted_at'       => nil,
    'updated_at'       => Time.now.to_s,
    'checksum'         => Fog::Mock.random_hex(32),
    'id'               => image_id,
    'deleted'          => false,
    'protected'        => false,
    'is_public'        => false,
    'status'           => 'queued',
    'min_ram'          => 0,
    'owner'            => attributes['owner'] || attributes[:owner],
    'properties'       => attributes['properties'] || attributes[:properties] || {}
  }
  response.body = { 'image'=> image }
  response
end
credentials() click to toggle source
# File lib/fog/openstack/image.rb, line 82
def credentials
  { :provider                 => 'openstack',
    :openstack_auth_url       => @openstack_auth_uri.to_s,
    :openstack_auth_token     => @auth_token,
    :openstack_region         => @openstack_region,
    :openstack_management_url => @openstack_management_url }
end
data() click to toggle source
# File lib/fog/openstack/image.rb, line 74
def data
  self.class.data[@openstack_username]
end
delete_image(image_id) click to toggle source
# File lib/fog/openstack/requests/image/delete_image.rb, line 17
def delete_image(image_id)
  response = Excon::Response.new
  response.status = 200
  response
end
get_image(image_id) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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"             => Fog::Mock.random_letters(10),
      "size"             => Fog::Mock.random_numbers(8).to_i,
      "disk_format"      => "iso",
      "container_format" => "bare",
      "id"               => Fog::Mock.random_hex(36),
      "checksum"         => Fog::Mock.random_hex(32)}]
  }
  response
end
list_public_images_detailed(attribute=nil, query=nil) click to toggle source
# File lib/fog/openstack/requests/image/list_public_images_detailed.rb, line 22
def list_public_images_detailed(attribute=nil, query=nil)
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = {'images' => self.data[:images].values}
  response
end
remove_member_from_image(image_id, member_id) click to toggle source
# 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() click to toggle source
# File lib/fog/openstack/image.rb, line 78
def reset_data
  self.class.data.delete(@openstack_username)
end
set_tenant(tenant) click to toggle source
# File lib/fog/openstack/requests/image/set_tenant.rb, line 14
def set_tenant(tenant)
  true
end
update_image(attributes) click to toggle source
# File lib/fog/openstack/requests/image/update_image.rb, line 38
def update_image(attributes)
  response = Excon::Response.new
  response.status = 200
  image = self.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
update_image_members(image_id, members) click to toggle source
# File lib/fog/openstack/requests/image/update_image_members.rb, line 23
def update_image_members(image_id, members)
  response = Excon::Response.new
  response.status = [200, 202][rand(1)]
  response.body = {
    'members' => [
      { 'member_id'=>'ff528b20431645ebb5fa4b0a71ca002f', 'can_share' => false },
      { 'member_id'=>'ff528b20431645ebb5fa4b0a71ca002f', 'can_share' => true  }
    ]
  }
  response
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.