Class: CondorCloud::ConfServerIPAgent
- Defined in:
- lib/deltacloud/drivers/condor/ip_agents/confserver.rb
Instance Attribute Summary
Attributes inherited from IPAgent
Instance Method Summary collapse
- #CondorAddresses ⇒ Object
- #find_free_mac ⇒ Object
- #find_ip_by_mac(uuid) ⇒ Object
- #find_mac_by_ip(ip) ⇒ Object
-
#initialize(opts = {}) ⇒ ConfServerIPAgent
constructor
A new instance of ConfServerIPAgent.
Methods inherited from IPAgent
Constructor Details
#initialize(opts = {}) ⇒ ConfServerIPAgent
Returns a new instance of ConfServerIPAgent.
25 26 27 28 29 30 31 32 |
# File 'lib/deltacloud/drivers/condor/ip_agents/confserver.rb', line 25 def initialize(opts={}) @config = opts[:config] self.CondorAddress = ENV['CONFIG_SERVER_CondorAddress'] || @config[:ip_agent_CondorAddress] || "10.34.32.181:4444" @version = @config[:ip_agent_version] || '0.0.1' @client = RestClient::Resource::new(self.CondorAddress) # TODO: Manage MAC CondorAddresses through ConfServer @mappings = Nokogiri::XML(File.open(opts[:file] || File.join('config', 'CondorAddresses.xml'))) end |
Instance Method Details
#CondorAddresses ⇒ Object
70 71 72 |
# File 'lib/deltacloud/drivers/condor/ip_agents/confserver.rb', line 70 def CondorAddresses (@mappings/'/CondorAddresses/CondorAddress').collect { |a| CondorAddress.new(:ip => a.text.strip, :mac => a[:mac]) } end |
#find_free_mac ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/deltacloud/drivers/condor/ip_agents/confserver.rb', line 47 def find_free_mac addr_hash = {} DefaultExecutor::new do |executor| # Make an CondorAddress hash to speed up the inner loop. CondorAddresses.each do |address| addr_hash[address.mac] = address.ip end executor.instances.each do |instance| instance.public_CondorAddresses.each do |public_CondorAddress| if addr_hash.key?(public_CondorAddress.mac) addr_hash.delete(public_CondorAddress.mac) end end end end raise "No available MACs to assign to instance." if addr_hash.empty? return addr_hash.keys.first end |
#find_ip_by_mac(uuid) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/deltacloud/drivers/condor/ip_agents/confserver.rb', line 34 def find_ip_by_mac(uuid) begin @client["/ip/%s/%s" % [@version, uuid]].get(:accept => 'text/plain').body.strip rescue RestClient::ResourceNotFound '127.0.0.1' rescue puts 'ERROR: Could not query ConfServer for an IP' end end |
#find_mac_by_ip(ip) ⇒ Object
44 45 |
# File 'lib/deltacloud/drivers/condor/ip_agents/confserver.rb', line 44 def find_mac_by_ip(ip) end |