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/vcloud/terremark/ecloud/models/internet_service.rb
Edward Muller 61155040e1 Internet Services and tweaks to Vcloud collection/model.
configure internet service

flesh out internet services a bit more

more tweaks to vcloud collection/model related stuff

remove debugging
2010-06-11 01:52:58 +08:00

69 lines
1.6 KiB
Ruby

require 'fog/model'
module Fog
module Vcloud
module Terremark
module Ecloud
class InternetService < Fog::Vcloud::Model
identity :href
attribute :name
attribute :id
attribute :type
attribute :protocol
attribute :port
attribute :enabled
attribute :description
attribute :public_ip
attribute :timeout
attribute :url_send_string
attribute :http_header
attr_accessor :new
def delete
requires :href
connection.delete_internet_service( self.href )
collection.reload
end
def save
if new?
result = connection.add_internet_service( collection.href, _compose_service_data )
self.href = result.body.href
self.reload
@new = false
else
connection.configure_internet_service( self.href, _compose_service_data, _compose_ip_data )
end
end
def new?
@new ||= false
end
private
def _compose_service_data
service_data = {}
self.class.attributes.select{ |attribute| !attribute.nil? }.each { |attribute| service_data[attribute] = send(attribute).to_s }
service_data
end
def _compose_ip_data
if public_ip.nil?
{}
else
{ :id => self.public_ip.id, :href => self.public_ip.href.to_s, :name => self.public_ip.name }
end
end
end
end
end
end
end