mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[openstack|image] Added image module, model and request
This commit is contained in:
parent
8e5ac8d9ed
commit
74fe4885c9
4 changed files with 75 additions and 42 deletions
|
@ -27,6 +27,7 @@ module Fog
|
|||
request :add_member_to_image
|
||||
request :remove_member_from_image
|
||||
request :delete_image
|
||||
request :get_image_by_id
|
||||
|
||||
|
||||
class Mock
|
||||
|
|
|
@ -29,52 +29,51 @@ module Fog
|
|||
attribute :properties
|
||||
|
||||
|
||||
def initialize(attributes)
|
||||
@connection = attributes[:connection]
|
||||
attributes[:size] ||= 0
|
||||
super
|
||||
end
|
||||
def initialize(attributes)
|
||||
@connection = attributes[:connection]
|
||||
attributes[:size] ||= 0
|
||||
super
|
||||
end
|
||||
|
||||
def save
|
||||
requires :name
|
||||
identity ? update : create
|
||||
end
|
||||
def save
|
||||
requires :name
|
||||
identity ? update : create
|
||||
end
|
||||
|
||||
def create
|
||||
requires :name
|
||||
merge_attributes(connection.create_image(self.attributes).body['image'])
|
||||
def create
|
||||
requires :name
|
||||
merge_attributes(connection.create_image(self.attributes).body['image'])
|
||||
self
|
||||
end
|
||||
|
||||
def update
|
||||
requires :name
|
||||
merge_attributes(connection.update_image(self.attributes).body['image'])
|
||||
self
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
connection.delete_image(self.id)
|
||||
true
|
||||
end
|
||||
|
||||
def add_member(member_id)
|
||||
requires :id
|
||||
connection.add_member_to_image(self.id, member_id)
|
||||
end
|
||||
|
||||
def remove_member(member_id)
|
||||
requires :id
|
||||
connection.remove_member_from_image(self.id, member_id)
|
||||
end
|
||||
|
||||
def members
|
||||
requires :id
|
||||
connection.get_image_members(self.id).body['members']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
requires :name
|
||||
merge_attributes(connection.update_image(self.attributes).body['image'])
|
||||
self
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
connection.delete_image(self.id)
|
||||
true
|
||||
end
|
||||
|
||||
def add_member(member_id)
|
||||
requires :id
|
||||
connection.add_member_to_image(self.id, member_id)
|
||||
end
|
||||
|
||||
def remove_member(member_id)
|
||||
requires :id
|
||||
connection.remove_member_from_image(self.id, member_id)
|
||||
end
|
||||
|
||||
def members
|
||||
requires :id
|
||||
connection.get_image_members(self.id).body['members']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,6 +25,7 @@ module Fog
|
|||
image = self.find_by_id(id)
|
||||
image.destroy
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
32
lib/fog/openstack/requests/image/get_image_by_id.rb
Normal file
32
lib/fog/openstack/requests/image/get_image_by_id.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Fog
|
||||
module Image
|
||||
class OpenStack
|
||||
class Real
|
||||
def get_image_by_id(image_id)
|
||||
request(
|
||||
:expects => [200, 204],
|
||||
:method => 'GET',
|
||||
:path => "images/#{image_id}"
|
||||
)
|
||||
end
|
||||
end # class Real
|
||||
|
||||
class Mock
|
||||
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 # def list_tenants
|
||||
end # class Mock
|
||||
end # class OpenStack
|
||||
end # module Identity
|
||||
end # module Fog
|
Loading…
Reference in a new issue