2011-07-28 13:21:26 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Rackspace
|
2011-08-04 16:21:22 -05:00
|
|
|
class LoadBalancers
|
2011-07-28 13:21:26 -04:00
|
|
|
class AccessRule < Fog::Model
|
|
|
|
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :address
|
|
|
|
attribute :type
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :identity, :load_balancer
|
2012-12-22 23:24:03 +00:00
|
|
|
service.delete_access_rule(load_balancer.identity, identity)
|
2011-07-28 13:21:26 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2012-12-23 02:45:05 +00:00
|
|
|
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
2011-07-28 13:21:26 -04:00
|
|
|
requires :load_balancer, :address, :type
|
2012-12-22 23:24:03 +00:00
|
|
|
service.create_access_rule(load_balancer.id, address, type)
|
2011-07-28 13:21:26 -04:00
|
|
|
|
|
|
|
#Unfortunately, access rules creation doesn't return an ID, we require a subsequent list call and comparison
|
2012-12-22 23:24:03 +00:00
|
|
|
data = service.list_access_rules(load_balancer.id).body['accessList'].select do |ar|
|
2011-08-04 16:21:22 -05:00
|
|
|
ar['address'] == address && ar['type'] == type
|
|
|
|
end.first
|
2011-07-28 13:21:26 -04:00
|
|
|
merge_attributes(data)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def load_balancer
|
|
|
|
collection.load_balancer
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|