2012-01-10 17:20:56 -05:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class IBM
|
|
|
|
class Address < Fog::Model
|
|
|
|
|
2012-02-29 22:11:48 -05:00
|
|
|
STATES = {
|
|
|
|
0 => 'New',
|
|
|
|
1 => 'Allocating',
|
|
|
|
2 => 'Free',
|
|
|
|
3 => 'Attached',
|
|
|
|
4 => 'Releasing',
|
|
|
|
5 => 'Released',
|
|
|
|
6 => 'Failed',
|
|
|
|
7 => 'Release pending',
|
|
|
|
}
|
|
|
|
|
2012-01-10 17:20:56 -05:00
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :type
|
|
|
|
attribute :location
|
|
|
|
attribute :ip
|
|
|
|
attribute :state
|
|
|
|
attribute :instance_id, :aliases => 'instanceId'
|
|
|
|
attribute :offering_id, :aliases => 'offeringId'
|
|
|
|
attribute :vlan_id, :aliases => 'vlanId'
|
|
|
|
attribute :hostname
|
|
|
|
attribute :mode
|
|
|
|
attribute :owner
|
|
|
|
|
|
|
|
def initialize(new_attributes={})
|
|
|
|
super(new_attributes)
|
|
|
|
self.offering_id ||= '20001223'
|
|
|
|
self.location ||= '82'
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
|
|
|
requires :offering_id, :location
|
2012-12-22 18:26:06 -05:00
|
|
|
data = service.create_address(location, offering_id,
|
2012-02-23 18:26:35 -05:00
|
|
|
:vlan_id => vlan_id,
|
|
|
|
:ip => ip)
|
2012-01-10 17:20:56 -05:00
|
|
|
merge_attributes(data.body)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2012-02-29 22:11:48 -05:00
|
|
|
def state
|
|
|
|
STATES[attributes[:state]]
|
|
|
|
end
|
|
|
|
|
|
|
|
def ready?
|
|
|
|
state == 'Free' || state == 'Released'
|
|
|
|
end
|
|
|
|
|
2012-01-10 17:20:56 -05:00
|
|
|
def destroy
|
|
|
|
requires :id
|
2012-12-22 18:26:06 -05:00
|
|
|
service.delete_address(id).body['success']
|
2012-01-10 17:20:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|