mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
setting up basics of first ec2 models
This commit is contained in:
parent
703f91a4d1
commit
ce75cef46a
4 changed files with 144 additions and 0 deletions
35
lib/fog/aws/models/ec2/address.rb
Normal file
35
lib/fog/aws/models/ec2/address.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
||||
class Address < Fog::Model
|
||||
|
||||
attr_accessor :instance_id, :public_ip
|
||||
|
||||
def initialize(attributes = {})
|
||||
remap_attributes(attributes, {
|
||||
'instanceId' => :instance_id,
|
||||
'publicIp' => :public_ip
|
||||
})
|
||||
super
|
||||
end
|
||||
|
||||
def delete
|
||||
return false if new_record?
|
||||
connection.release_address(@public_ip)
|
||||
@new_record = true
|
||||
true
|
||||
end
|
||||
|
||||
def save
|
||||
data = connection.allocate_address
|
||||
@public_ip = data.body['publicIp']
|
||||
@new_record = false
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
36
lib/fog/aws/models/ec2/addresses.rb
Normal file
36
lib/fog/aws/models/ec2/addresses.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
||||
def addresses
|
||||
Fog::AWS::EC2::Addresses.new(:connection => self)
|
||||
end
|
||||
|
||||
class Addresses < Fog::Collection
|
||||
|
||||
def all
|
||||
data = connection.get_addresses.body
|
||||
addresses = []
|
||||
body['addressesSet'].each do |address|
|
||||
addresses << Fog::AWS::EC2::Address.new({
|
||||
:connection => connection
|
||||
}.merge!(address))
|
||||
end
|
||||
addresses
|
||||
end
|
||||
|
||||
def create
|
||||
address = new
|
||||
address.save
|
||||
address
|
||||
end
|
||||
|
||||
def new
|
||||
Fog::AWS::S3::Address.new(:connection => connection)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
37
lib/fog/aws/models/ec2/key_pair.rb
Normal file
37
lib/fog/aws/models/ec2/key_pair.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
||||
class KeyPair < Fog::Model
|
||||
|
||||
attr_accessor :fingerprint, :material, :name
|
||||
|
||||
def initialize(attributes = {})
|
||||
remap_attributes(attributes, {
|
||||
'keyFingerprint' => :fingerprint,
|
||||
'keyMaterial' => :material,
|
||||
'keyName' => :name
|
||||
})
|
||||
super
|
||||
end
|
||||
|
||||
def delete
|
||||
return false if new_record?
|
||||
connection.delete_key_pair(@name)
|
||||
@new_record = true
|
||||
true
|
||||
end
|
||||
|
||||
def save
|
||||
data = connection.create_key_pair(@name)
|
||||
new_attributes = data['Body'].reject {|key,value| !['keyFingerprint', 'keyMaterial', 'keyName'].include?(key)}
|
||||
update_attributes(new_attributes)
|
||||
@new_record = false
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
36
lib/fog/aws/models/ec2/key_pairs.rb
Normal file
36
lib/fog/aws/models/ec2/key_pairs.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
||||
def key_pairs
|
||||
Fog::AWS::EC2::KeyPairs.new(:connection => self)
|
||||
end
|
||||
|
||||
class KeyPairs < Fog::Collection
|
||||
|
||||
def all(key_names = [])
|
||||
data = connection.describe_key_pairs(key_names)
|
||||
key_pairs = []
|
||||
data['keySet'].each do |key|
|
||||
key_pairs << Fog::AWS::EC2::KeyPair.new({
|
||||
:connection => connection
|
||||
}.merge!(key))
|
||||
end
|
||||
key_pairs
|
||||
end
|
||||
|
||||
def create(attributes = {})
|
||||
bucket = new(attributes)
|
||||
bucket.save
|
||||
bucket
|
||||
end
|
||||
|
||||
def new(attributes = {})
|
||||
Fog::AWS::EC2::KeyPair.new(attributes.merge!(:connection => connection))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue