cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
__init__.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # @COPYRIGHT_begin
3 #
4 # Copyright [2010-2014] Institute of Nuclear Physics PAN, Krakow, Poland
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # @COPYRIGHT_end
19 
20 from cm.models.vm import VM
21 from cm.utils import log
22 from cm.utils.decorators import ec2ctx_log
23 from cm.utils.exception import CMException
24 from cm.views.ec2ctx.helpers.request import get_vm_by_ip
25 from django.conf.urls import patterns, include, url
26 from django.http import HttpResponse
27 from meta_data import meta_data, meta_data_patterns
28 import base64
29 
30 ##
31 # @package src.cm.views.ec2ctx.latest
32 #
33 # @copyright Copyright (c) 2013 Institute of Nuclear Physics PAS <http://www.ifj.edu.pl/>
34 # @author Łukasz Chrząszcz <l.chrzaszcz@gmail.com>
35 #
36 
37 
38 @ec2ctx_log(log=True)
39 def user_data(request):
40  vm_ip = request.META.get('REMOTE_ADDR')
41 
42  vm = VM.get_by_ip(vm_ip)
43  user_data = vm.long_dict['user_data']
44 
45  return base64.b64decode(user_data)
46 
47 
48 @ec2ctx_log(log=True)
49 def latest(request):
50  # na razie zahardkodowane, ale to sie zmieni
51  return 'user-data\nmeta-data'
52 
53 latest_patterns = patterns('',
54  url(r'^$', latest),
55  url(r'^meta-data/', include(meta_data_patterns)),
56  url(r'^user-data/?$', user_data))
57