19 from cm.models.vm
import VM
20 from cm.utils
import log
21 from cm.utils.decorators
import ec2ctx_log
22 from cm.utils.exception
import CMException
24 from cm.views.ec2ctx.helpers.getters
import get_exposed_methods, get_submethods
25 from cm.views.ec2ctx.helpers.request
import get_vm_by_ip
26 from django.conf.urls
import patterns, include, url
27 from time
import sleep
43 vm_ip = request.META.get(
'REMOTE_ADDR')
44 vm = VM.get_by_ip(vm_ip)
46 ami =
'ami-' + str(vm.dict[
'image_id'])
49 ami_id.func_dict[
'meta_data'] =
True
54 vm_ip = request.META.get(
'REMOTE_ADDR')
55 vm = VM.get_by_ip(vm_ip)
57 instance_id = vm.dict[
'vm_id']
58 reservation_id = vm.long_dict[
'reservation_id']
60 launch_index = reservation_id - instance_id + 1
63 ami_launch_index.func_dict[
'meta_data'] =
True
68 return 'Not implemented'
69 ami_manifest_path.func_dict[
'meta_data'] =
True
74 return 'Not implemented'
75 block_device_mapping.func_dict[
'meta_data'] =
True
90 hostname.func_dict[
'meta_data'] =
True
95 return 'Not implemented'
96 instance_action.func_dict[
'meta_data'] =
True
101 vm_ip = request.META.get(
'REMOTE_ADDR')
103 vm = VM.get_by_ip(vm_ip)
105 vm_id =
'i-' + str(vm.dict[
'vm_id'])
107 instance_id.func_dict[
'meta_data'] =
True
112 vm_ip = request.META.get(
'REMOTE_ADDR')
113 vm = VM.get_by_ip(vm_ip)
115 template_name = str(vm.dict[
'template_name'])
117 instance_type.func_dict[
'meta_data'] =
True
122 return 'Not implemented'
123 kernel_id.func_dict[
'meta_data'] =
True
129 local_hostname.func_dict[
'meta_data'] =
True
134 vm_ip = request.META.get(
'REMOTE_ADDR')
135 vm = VM.get_by_ip(vm_ip)
137 leases = vm.dict[
'leases']
140 if ip.get(
'address'):
141 ip = ip.get(
'address')
146 local_ipv4.func_dict[
'meta_data'] =
True
151 return 'Not implemented'
152 mac.func_dict[
'meta_data'] =
True
157 return 'Not implemented'
158 network.func_dict[
'meta_data'] =
True
163 return 'Not implemented'
164 placement.func_dict[
'meta_data'] =
True
170 public_hostname.func_dict[
'meta_data'] =
True
175 vm_ip = request.META.get(
'REMOTE_ADDR')
176 vm = VM.get_by_ip(vm_ip)
178 leases = vm.dict[
'leases']
181 if ip.get(
'public_ip'):
182 ip = ip.get(
'public_ip')
187 public_ipv4.func_dict[
'meta_data'] =
True
192 vm_ip = request.META.get(
'REMOTE_ADDR')
194 vm = VM.get_by_ip(vm_ip)
196 if number ==
"0" and vm.long_dict.get(
'ssh_key'):
197 if key_type ==
"openssh-key":
198 return vm.long_dict.get(
'ssh_key')
205 if number
or key_type:
208 if vm.long_dict.get(
'ssh_key'):
209 return '0=public-key'
210 public_keys.func_dict[
'meta_data'] =
True
215 vm_ip = request.META.get(
'REMOTE_ADDR')
216 vm = VM.get_by_ip(vm_ip)
218 reservation_id = vm.long_dict[
'reservation_id']
220 return 'r-' + str(reservation_id)
221 reservation_id.func_dict[
'meta_data'] =
True
227 security_groups.func_dict[
'meta_data'] =
True
232 funcs = inspect.getmembers(sys.modules[__name__], inspect.isfunction)
233 funcs = [fun[0].replace(
'_',
'-')
for fun
in funcs
if fun[1].func_dict.get(
'meta_data')]
234 return '\n'.join(funcs)
237 meta_data_patterns = patterns(
'',
238 url(
r'^$', meta_data),
239 url(
r'^ami-id/?$', ami_id),
240 url(
r'^ami-manifest-path/?$', ami_manifest_path),
241 url(
r'^ami-launch-index/?$', ami_launch_index),
242 url(
r'^block-device-mapping/?$', block_device_mapping),
243 url(
r'^hostname/?$', hostname),
244 url(
r'^instance-action/?$', instance_action),
245 url(
r'^instance-id/?$', instance_id),
246 url(
r'^instance-type/?$', instance_type),
247 url(
r'^kernel-id/?$', kernel_id),
248 url(
r'^local-hostname/?$', local_hostname),
249 url(
r'^local-ipv4/?$', local_ipv4),
250 url(
r'^mac/?$', mac),
251 url(
r'^network/?$', network),
252 url(
r'^placement/?$', placement),
253 url(
r'^public-hostname/?$', public_hostname),
254 url(
r'^public-ipv4/?$', public_ipv4),
255 url(
r'^public-keys/?$', public_keys),
256 url(
r'^public-keys/(?P<number>[0-9]+)/?$', public_keys),
257 url(
r'^public-keys/(?P<number>[0-9]+)/(?P<key_type>[^/]+)/?$', public_keys),
258 url(
r'^reservation-id/?$', reservation_id),
259 url(
r'^security-groups/?$', security_groups))