1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/brightbox/models/compute/cloud_ip.rb
Paul Thornthwaite b5ff3eaeb1 [Brightbox] Clean up Cloud IP mapping code
When passing an object that responds to `identity` which is all of our
resources, we can pass the resource's identifier in to the API call to
make it easier to use without maintaining a list of classes.

Server's need to use the interface for the destination so they override
a new `mapping_identity` method which is picked up first.

Anything else (such as a String identifier) is passed directly to the
API request as before.
2013-11-27 15:53:03 +00:00

63 lines
1.6 KiB
Ruby

require 'fog/core/model'
module Fog
module Compute
class Brightbox
class CloudIp < Fog::Model
identity :id
attribute :url
attribute :resource_type
attribute :name
attribute :status
attribute :description
attribute :reverse_dns
attribute :public_ip
# Links - to be replaced
attribute :account_id, :aliases => "account", :squash => "id"
attribute :interface_id, :aliases => "interface", :squash => "id"
attribute :server_id, :aliases => "server", :squash => "id"
attribute :load_balancer, :alias => "load_balancer", :squash => "id"
attribute :server_group, :alias => "server_group", :squash => "id"
attribute :port_translators
attribute :name
# Attempt to map or point the Cloud IP to the destination resource.
#
# @param [Object] destination
#
def map(destination)
requires :identity
if destination.respond_to?(:mapping_identity)
final_destination = destination.mapping_identity
elsif destination.respond_to?(:identity)
final_destination = destination.identity
else
final_destination = destination
end
service.map_cloud_ip(identity, :destination => final_destination)
end
def mapped?
status == "mapped"
end
def unmap
requires :identity
service.unmap_cloud_ip(identity)
end
def destroy
requires :identity
service.destroy_cloud_ip(identity)
end
end
end
end
end