Class: Dcmgr::Endpoints::Metadata::Provider_20110519

Inherits:
Provider_20101101 show all
Defined in:
lib/dcmgr/endpoints/metadata.rb

Overview

This version implements compatibility with amazon EC2

Instance Method Summary collapse

Methods inherited from Provider_20101101

#get_instance_from_ip

Instance Method Details

#document(src_ip) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/dcmgr/endpoints/metadata.rb', line 175

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|
    nic.ip.map { |ip|
      {:ip=>ip.ipv4,
        :uuid=>ip.network.canonical_uuid,
      }
    }
  }
  ret[:volume] = inst.volume.map { |v|
  }
  ret
end

#instance_id(src_ip) ⇒ Object



231
232
233
# File 'lib/dcmgr/endpoints/metadata.rb', line 231

def instance_id(src_ip)
  get_instance_from_ip(src_ip).cuuid
end

#local_hostname(src_ip) ⇒ Object



235
236
237
# File 'lib/dcmgr/endpoints/metadata.rb', line 235

def local_hostname(src_ip)
  get_instance_from_ip(src_ip).hostname
end

#local_ipv4(src_ip) ⇒ Object



239
240
241
242
243
244
245
246
247
248
249
# File 'lib/dcmgr/endpoints/metadata.rb', line 239

def local_ipv4(src_ip)
  get_instance_from_ip(src_ip).nic.map { |nic|
    nic.ip.map { |ip|
      unless ip.is_natted?
        ip.ipv4
      else
        nil
      end
    }.compact
  }.join("\n")
end

#mac(src_ip) ⇒ Object



217
218
219
220
221
# File 'lib/dcmgr/endpoints/metadata.rb', line 217

def mac(src_ip)
  get_instance_from_ip(src_ip).nic.map { |nic|
    nic.pretty_mac_addr
  }.join("\n")
end

#network(src_ip) ⇒ Object



223
224
225
226
227
228
229
# File 'lib/dcmgr/endpoints/metadata.rb', line 223

def network(src_ip)
  get_instance_from_ip(src_ip).nic.map { |nic|
    nic.ip.map { |ip|
      ip.network.cuuid
    }
  }.join("\n")
end

#public_ipv4(src_ip) ⇒ Object



251
252
253
254
255
256
257
258
259
260
261
# File 'lib/dcmgr/endpoints/metadata.rb', line 251

def public_ipv4(src_ip)
  get_instance_from_ip(src_ip).nic.map { |nic|
    nic.ip.map { |ip|
      if ip.is_natted?
        ip.ipv4
      else
        nil
      end
    }.compact
  }.join("\n")
end

#public_keys(src_ip) ⇒ Object



263
264
265
266
267
# File 'lib/dcmgr/endpoints/metadata.rb', line 263

def public_keys(src_ip)
  i = get_instance_from_ip(src_ip)
  # ssh_key_data is possible to be nil.
  i.ssh_key_data.nil? ? '' : i.ssh_key_data[:public_key]
end

#security_groups(src_ip) ⇒ Object



269
270
271
272
273
# File 'lib/dcmgr/endpoints/metadata.rb', line 269

def security_groups(src_ip)
  get_instance_from_ip(src_ip).security_groups.map { |grp|
    grp.canonical_uuid
  }.join("\n")
end

#user_data(src_ip) ⇒ Object



275
276
277
# File 'lib/dcmgr/endpoints/metadata.rb', line 275

def user_data(src_ip)
  get_instance_from_ip(src_ip).user_data
end