Class: Dcmgr::Endpoints::Metadata::Provider_20101101

Inherits:
Provider
  • Object
show all
Defined in:
lib/dcmgr/endpoints/metadata.rb

Overview

2010-11-01 version of metadata provider

Direct Known Subclasses

Provider_20110519

Instance Method Summary collapse

Instance Method Details

#document(src_ip) ⇒ Object

{:cpu_cores=>1,

:memory_size=>100,
:state=>'running',
:user_data=>'......',
:network => [{
  :ip=>'192.168.1.1',
  :name=>'xxxxxx'
}]

}



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/dcmgr/endpoints/metadata.rb', line 144

def document(src_ip)
  inst = get_instance_from_ip(src_ip)
  ret = {
    :instance_id=>inst.canonical_uuid,
    :cpu_cores=>inst.cpu_cores,
    :memory_size=>inst.memory_size,
    :state => inst.state,
    :user_data=>inst.user_data.to_s,
  }
  # IP/network values
  ret[:network] = inst.nic.map { |nic|
    {:ip=>nic.ip.ipv4,
      :name=>nic.ip.network.name,
    }
  }
  ret[:volume] = inst.volume.map { |v|
  }
  ret
end

#get_instance_from_ip(src_ip) ⇒ Object



164
165
166
167
168
169
170
# File 'lib/dcmgr/endpoints/metadata.rb', line 164

def get_instance_from_ip(src_ip)
  ip = Models::IpLease.find(:ipv4=>src_ip)
  if ip.nil? || ip.instance_nic.nil?
    raise UnknownSourceIpError, src_ip
  end
  ip.instance_nic.instance
end