mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
more ec2 model work
This commit is contained in:
parent
c43cd2a91e
commit
b60558e663
11 changed files with 117 additions and 23 deletions
|
@ -4,7 +4,8 @@ module Fog
|
|||
|
||||
class Address < Fog::Model
|
||||
|
||||
attr_accessor :instance_id, :public_ip
|
||||
attr_accessor :instance_id,
|
||||
:public_ip
|
||||
|
||||
def initialize(attributes = {})
|
||||
remap_attributes(attributes, {
|
||||
|
@ -16,13 +17,11 @@ module Fog
|
|||
|
||||
def delete
|
||||
connection.release_address(@public_ip)
|
||||
true
|
||||
end
|
||||
|
||||
def save
|
||||
data = connection.allocate_address
|
||||
@public_ip = data.body['publicIp']
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -9,9 +9,9 @@ module Fog
|
|||
class Addresses < Fog::Collection
|
||||
|
||||
def all
|
||||
data = connection.get_addresses.body
|
||||
data = connection.describe_addresses.body
|
||||
addresses = []
|
||||
body['addressesSet'].each do |address|
|
||||
data['addressesSet'].each do |address|
|
||||
addresses << Fog::AWS::EC2::Address.new({
|
||||
:connection => connection
|
||||
}.merge!(address))
|
||||
|
|
|
@ -4,7 +4,9 @@ module Fog
|
|||
|
||||
class KeyPair < Fog::Model
|
||||
|
||||
attr_accessor :fingerprint, :material, :name
|
||||
attr_accessor :fingerprint,
|
||||
:material,
|
||||
:name
|
||||
|
||||
def initialize(attributes = {})
|
||||
remap_attributes(attributes, {
|
||||
|
@ -17,14 +19,13 @@ module Fog
|
|||
|
||||
def delete
|
||||
connection.delete_key_pair(@name)
|
||||
true
|
||||
end
|
||||
|
||||
def save
|
||||
data = connection.create_key_pair(@name)
|
||||
new_attributes = data['Body'].reject {|key,value| !['keyFingerprint', 'keyMaterial', 'keyName'].include?(key)}
|
||||
data = connection.create_key_pair(@name).body
|
||||
new_attributes = data.reject {|key,value| !['keyFingerprint', 'keyMaterial', 'keyName'].include?(key)}
|
||||
update_attributes(new_attributes)
|
||||
true
|
||||
data
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ module Fog
|
|||
class KeyPairs < Fog::Collection
|
||||
|
||||
def all(key_names = [])
|
||||
data = connection.describe_key_pairs(key_names)
|
||||
data = connection.describe_key_pairs(key_names).body
|
||||
key_pairs = []
|
||||
data['keySet'].each do |key|
|
||||
key_pairs << Fog::AWS::EC2::KeyPair.new({
|
||||
|
|
47
lib/fog/aws/models/ec2/volume.rb
Normal file
47
lib/fog/aws/models/ec2/volume.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
||||
class Volume < Fog::Model
|
||||
|
||||
attr_accessor :attachment_time,
|
||||
:availability_zone,
|
||||
:device,
|
||||
:instance_id
|
||||
:size,
|
||||
:snapshot_id,
|
||||
:status,
|
||||
:volume_id
|
||||
|
||||
def initialize(attributes = {})
|
||||
if attributes['attachmentSet']
|
||||
attributes.merge!(attributes.delete('attachmentSet'))
|
||||
end
|
||||
remap_attributes(attributes, {
|
||||
'attachmentTime' => :attachment_time,
|
||||
'availabilityZone' => :availability_zone,
|
||||
'createTime' => :create_time,
|
||||
'instanceId' => :instance_id,
|
||||
'snapshotId' => :snapshot_id,
|
||||
'status' => :status
|
||||
'volumeId' => :volume_id
|
||||
})
|
||||
super
|
||||
end
|
||||
|
||||
def delete
|
||||
connection.delete_volume(@volume_id)
|
||||
end
|
||||
|
||||
def save
|
||||
data = connection.create_volume(@availability_zone, @size, @snapshot_id).body
|
||||
new_attributes = data.reject {|key,value| key == 'requestId'}
|
||||
update_attributes(new_attributes)
|
||||
data
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
36
lib/fog/aws/models/ec2/volumes.rb
Normal file
36
lib/fog/aws/models/ec2/volumes.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
||||
def volumes
|
||||
Fog::AWS::EC2::Volumes.new(:connection => self)
|
||||
end
|
||||
|
||||
class Volumes < Fog::Collection
|
||||
|
||||
def all(volume_ids = [])
|
||||
data = connection.describe_volumes(volume_ids)
|
||||
volumes = []
|
||||
data['volumeSet'].each do |volume|
|
||||
volumes << Fog::AWS::EC2::Volume.new({
|
||||
:connection => connection
|
||||
}.merge!(volume))
|
||||
end
|
||||
volumes
|
||||
end
|
||||
|
||||
def create(attributes = {})
|
||||
volume = new(attributes)
|
||||
volume.save
|
||||
volume
|
||||
end
|
||||
|
||||
def new(attributes = {})
|
||||
Fog::AWS::EC2::Volume.new(attributes.merge!(:connection => connection))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,7 +4,10 @@ module Fog
|
|||
|
||||
class Bucket < Fog::Model
|
||||
|
||||
attr_accessor :creation_date, :location, :name, :owner
|
||||
attr_accessor :creation_date,
|
||||
:location,
|
||||
:name,
|
||||
:owner
|
||||
|
||||
def initialize(attributes = {})
|
||||
remap_attributes(attributes, {
|
||||
|
@ -16,7 +19,6 @@ module Fog
|
|||
|
||||
def delete
|
||||
connection.delete_bucket(name)
|
||||
true
|
||||
end
|
||||
|
||||
def location
|
||||
|
@ -48,7 +50,6 @@ module Fog
|
|||
options['LocationConstraint'] = @location
|
||||
end
|
||||
connection.put_bucket(name, options)
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -4,7 +4,14 @@ module Fog
|
|||
|
||||
class Object < Fog::Model
|
||||
|
||||
attr_accessor :body, :content_length, :etag, :key, :last_modified, :owner, :size, :storage_class
|
||||
attr_accessor :body,
|
||||
:content_length,
|
||||
:etag,
|
||||
:key,
|
||||
:last_modified,
|
||||
:owner,
|
||||
:size,
|
||||
:storage_class
|
||||
|
||||
def initialize(attributes = {})
|
||||
remap_attributes(attributes, {
|
||||
|
@ -42,7 +49,6 @@ module Fog
|
|||
|
||||
def delete
|
||||
connection.delete_object(bucket, key)
|
||||
true
|
||||
end
|
||||
|
||||
def etag
|
||||
|
@ -56,7 +62,6 @@ module Fog
|
|||
def save(options = {})
|
||||
data = connection.put_object(bucket, key, body, options)
|
||||
@etag = data.headers['ETag']
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -4,7 +4,10 @@ module Fog
|
|||
|
||||
class Objects < Fog::Collection
|
||||
|
||||
attr_accessor :is_truncated, :marker, :max_keys, :prefix
|
||||
attr_accessor :is_truncated,
|
||||
:marker,
|
||||
:max_keys,
|
||||
:prefix
|
||||
|
||||
def initialize(attributes = {})
|
||||
remap_attributes(attributes, {
|
||||
|
|
|
@ -4,7 +4,8 @@ module Fog
|
|||
|
||||
class Owner < Fog::Model
|
||||
|
||||
attr_accessor :display_name, :id
|
||||
attr_accessor :display_name,
|
||||
:id
|
||||
|
||||
def initialize(attributes = {})
|
||||
remap_attributes(attributes, {
|
||||
|
|
|
@ -12,12 +12,13 @@ module Fog
|
|||
# ==== Returns
|
||||
# * response<~Fog::AWS::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'volumeId'<~String> - Reference to volume
|
||||
# * 'size'<~Integer> - Size in GiBs for volume
|
||||
# * 'status's<~String> - State of volume
|
||||
# * 'createTime'<~Time> - Timestamp for creation
|
||||
# * 'availabilityZone'<~String> - Availability zone for volume
|
||||
# * 'createTime'<~Time> - Timestamp for creation
|
||||
# * 'requestId'<~String> - Id of request
|
||||
# * 'size'<~Integer> - Size in GiBs for volume
|
||||
# * 'snapshotId'<~String> - Snapshot volume was created from, if any
|
||||
# * 'status'<~String> - State of volume
|
||||
# * 'volumeId'<~String> - Reference to volume
|
||||
def create_volume(availability_zone, size, snapshot_id = nil)
|
||||
request({
|
||||
'Action' => 'CreateVolume',
|
||||
|
|
Loading…
Reference in a new issue