Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This method will pull the public ip off of the zone and create a VIP from it and forward
- # for ports 80 and 22
- def virtualize_public_ip!
- # TODO: Raising these errors are kind of useless. Raise exception classes so we can act on them
- # Paths of action: do we keep going, do we destroy a zone depending on type of exception
- raise ZoneError::NoPublicIp, "Cannot virtualize ip on a zone without a public ip.", caller unless public_ip = public_ips.first
- raise ZoneError::NoPrivateIp, "Cannot virtualize ip on a zone without a private ip.", caller unless private_ip = private_ips.first
- raise ZoneError::NoLoadBalancer, "Cannot find load balancer to use for virtualization.", caller unless load_balancer = LoadBalancer.find_aptana
- raise ZoneError::Inactive, "Cannot virtualize ip on an inactive zone.", caller unless active? # could be removed if good reason for it
- # raise "Cannot virtualize ip on a zone without a customer." unless customer # a bit arbitrary, but include for now
- # NOTE: This likely should be put in a transaction and dealt with more cleanly in case of an error
- # In order to do so we would need to rollback the objects and the writing to the load balancer
- # if that in fact happened.
- # NOTE: I would love to figure out a way to elegantly remove the need for this object, but
- # currently it is the 'addressable' that is needed to 'utilize' an ip address
- vip = (customer ? customer.virtual_ips.create : VirtualIp.create)
- vip.zones << self
- vip.ips << public_ip
- [22, 80, 3306].each do |port|
- lb_virtual_server = vip.load_balanced_virtual_servers.create!(:name => "vs_#{name}_#{port}",
- :ip => public_ip,
- :port => port,
- :load_balancer => load_balancer)
- lb_virtual_server.add_member_to_pool(private_ip, port)
- end
- # This is the last step for aptana zone creation
- update_attribute(:creation_state, "unverified")
- {:success => true, :virtual_ip => vip}
- end
Add Comment
Please, Sign In to add comment