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
|
class Address < Fog::Model
|
||||||
|
|
||||||
attr_accessor :instance_id, :public_ip
|
attr_accessor :instance_id,
|
||||||
|
:public_ip
|
||||||
|
|
||||||
def initialize(attributes = {})
|
def initialize(attributes = {})
|
||||||
remap_attributes(attributes, {
|
remap_attributes(attributes, {
|
||||||
|
@ -16,13 +17,11 @@ module Fog
|
||||||
|
|
||||||
def delete
|
def delete
|
||||||
connection.release_address(@public_ip)
|
connection.release_address(@public_ip)
|
||||||
true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def save
|
def save
|
||||||
data = connection.allocate_address
|
data = connection.allocate_address
|
||||||
@public_ip = data.body['publicIp']
|
@public_ip = data.body['publicIp']
|
||||||
true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,9 +9,9 @@ module Fog
|
||||||
class Addresses < Fog::Collection
|
class Addresses < Fog::Collection
|
||||||
|
|
||||||
def all
|
def all
|
||||||
data = connection.get_addresses.body
|
data = connection.describe_addresses.body
|
||||||
addresses = []
|
addresses = []
|
||||||
body['addressesSet'].each do |address|
|
data['addressesSet'].each do |address|
|
||||||
addresses << Fog::AWS::EC2::Address.new({
|
addresses << Fog::AWS::EC2::Address.new({
|
||||||
:connection => connection
|
:connection => connection
|
||||||
}.merge!(address))
|
}.merge!(address))
|
||||||
|
|
|
@ -4,7 +4,9 @@ module Fog
|
||||||
|
|
||||||
class KeyPair < Fog::Model
|
class KeyPair < Fog::Model
|
||||||
|
|
||||||
attr_accessor :fingerprint, :material, :name
|
attr_accessor :fingerprint,
|
||||||
|
:material,
|
||||||
|
:name
|
||||||
|
|
||||||
def initialize(attributes = {})
|
def initialize(attributes = {})
|
||||||
remap_attributes(attributes, {
|
remap_attributes(attributes, {
|
||||||
|
@ -17,14 +19,13 @@ module Fog
|
||||||
|
|
||||||
def delete
|
def delete
|
||||||
connection.delete_key_pair(@name)
|
connection.delete_key_pair(@name)
|
||||||
true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def save
|
def save
|
||||||
data = connection.create_key_pair(@name)
|
data = connection.create_key_pair(@name).body
|
||||||
new_attributes = data['Body'].reject {|key,value| !['keyFingerprint', 'keyMaterial', 'keyName'].include?(key)}
|
new_attributes = data.reject {|key,value| !['keyFingerprint', 'keyMaterial', 'keyName'].include?(key)}
|
||||||
update_attributes(new_attributes)
|
update_attributes(new_attributes)
|
||||||
true
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,7 @@ module Fog
|
||||||
class KeyPairs < Fog::Collection
|
class KeyPairs < Fog::Collection
|
||||||
|
|
||||||
def all(key_names = [])
|
def all(key_names = [])
|
||||||
data = connection.describe_key_pairs(key_names)
|
data = connection.describe_key_pairs(key_names).body
|
||||||
key_pairs = []
|
key_pairs = []
|
||||||
data['keySet'].each do |key|
|
data['keySet'].each do |key|
|
||||||
key_pairs << Fog::AWS::EC2::KeyPair.new({
|
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
|
class Bucket < Fog::Model
|
||||||
|
|
||||||
attr_accessor :creation_date, :location, :name, :owner
|
attr_accessor :creation_date,
|
||||||
|
:location,
|
||||||
|
:name,
|
||||||
|
:owner
|
||||||
|
|
||||||
def initialize(attributes = {})
|
def initialize(attributes = {})
|
||||||
remap_attributes(attributes, {
|
remap_attributes(attributes, {
|
||||||
|
@ -16,7 +19,6 @@ module Fog
|
||||||
|
|
||||||
def delete
|
def delete
|
||||||
connection.delete_bucket(name)
|
connection.delete_bucket(name)
|
||||||
true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def location
|
def location
|
||||||
|
@ -48,7 +50,6 @@ module Fog
|
||||||
options['LocationConstraint'] = @location
|
options['LocationConstraint'] = @location
|
||||||
end
|
end
|
||||||
connection.put_bucket(name, options)
|
connection.put_bucket(name, options)
|
||||||
true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,14 @@ module Fog
|
||||||
|
|
||||||
class Object < Fog::Model
|
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 = {})
|
def initialize(attributes = {})
|
||||||
remap_attributes(attributes, {
|
remap_attributes(attributes, {
|
||||||
|
@ -42,7 +49,6 @@ module Fog
|
||||||
|
|
||||||
def delete
|
def delete
|
||||||
connection.delete_object(bucket, key)
|
connection.delete_object(bucket, key)
|
||||||
true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def etag
|
def etag
|
||||||
|
@ -56,7 +62,6 @@ module Fog
|
||||||
def save(options = {})
|
def save(options = {})
|
||||||
data = connection.put_object(bucket, key, body, options)
|
data = connection.put_object(bucket, key, body, options)
|
||||||
@etag = data.headers['ETag']
|
@etag = data.headers['ETag']
|
||||||
true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -4,7 +4,10 @@ module Fog
|
||||||
|
|
||||||
class Objects < Fog::Collection
|
class Objects < Fog::Collection
|
||||||
|
|
||||||
attr_accessor :is_truncated, :marker, :max_keys, :prefix
|
attr_accessor :is_truncated,
|
||||||
|
:marker,
|
||||||
|
:max_keys,
|
||||||
|
:prefix
|
||||||
|
|
||||||
def initialize(attributes = {})
|
def initialize(attributes = {})
|
||||||
remap_attributes(attributes, {
|
remap_attributes(attributes, {
|
||||||
|
|
|
@ -4,7 +4,8 @@ module Fog
|
||||||
|
|
||||||
class Owner < Fog::Model
|
class Owner < Fog::Model
|
||||||
|
|
||||||
attr_accessor :display_name, :id
|
attr_accessor :display_name,
|
||||||
|
:id
|
||||||
|
|
||||||
def initialize(attributes = {})
|
def initialize(attributes = {})
|
||||||
remap_attributes(attributes, {
|
remap_attributes(attributes, {
|
||||||
|
|
|
@ -12,12 +12,13 @@ module Fog
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# * response<~Fog::AWS::Response>:
|
# * response<~Fog::AWS::Response>:
|
||||||
# * body<~Hash>:
|
# * 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
|
# * '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
|
# * '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)
|
def create_volume(availability_zone, size, snapshot_id = nil)
|
||||||
request({
|
request({
|
||||||
'Action' => 'CreateVolume',
|
'Action' => 'CreateVolume',
|
||||||
|
|
Loading…
Reference in a new issue