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



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/dcmgr/endpoints/metadata.rb', line 170

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



226
227
228
# File 'lib/dcmgr/endpoints/metadata.rb', line 226

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

#local_hostname(src_ip) ⇒ Object



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

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

#local_ipv4(src_ip) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
# File 'lib/dcmgr/endpoints/metadata.rb', line 234

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



212
213
214
215
216
# File 'lib/dcmgr/endpoints/metadata.rb', line 212

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

#network(src_ip) ⇒ Object



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

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



246
247
248
249
250
251
252
253
254
255
256
# File 'lib/dcmgr/endpoints/metadata.rb', line 246

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



258
259
260
261
262
# File 'lib/dcmgr/endpoints/metadata.rb', line 258

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



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

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

#user_data(src_ip) ⇒ Object



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

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