cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
storage.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 ##
21 # @package src.cm.views.ci.storage
22 # @author Maciej Nabozny <mn@mnabozny.pl>
23 # @alldecoratedby{src.cm.utils.decorators.ni_log}
24 #
25 
26 from cm.utils.decorators import ci_log
27 from cm.models.storage import Storage
28 from cm.models.node import Node
29 from common.states import storage_states
30 from django.template import loader, Context
31 from cm.utils.exception import CMException
32 
33 
34 @ci_log(log=True)
35 ##
36 #
37 # @cmview_ci
38 # @param_post{remote_ip,string}
39 #
40 def get_list(remote_ip):
41  storages = Storage.objects.filter(state=storage_states['ok'])
42  return [storage.name for storage in storages]
43 
44 
45 @ci_log(log=True)
46 ##
47 #
48 # @cmview_ci
49 # @param_post{remote_ip,string}
50 # @param_post{name}
51 #
52 def get_template(remote_ip, name):
53  storage = Storage.objects.get(name=name)
54  return storage.libvirt_template()
55 
56 
57 @ci_log(log=True)
58 ##
59 #
60 # @cmview_ci
61 # @param_post{remote_ip,string}
62 #
63 def get_images_template(remote_ip):
64  try:
65  node = Node.objects.get(address=remote_ip)
66  except:
67  raise CMException('node_not_found')
68 
69  template_images = loader.get_template('pools/images.xml')
70  template_info = loader.get_template('volumes/file.xml')
71  images_pool = template_images.render(Context({'node': node}))
72  volume_info = template_info.render(Context({'name': 'info', 'size': 1, 'node': node}))
73  return {'images_pool': images_pool, 'volume_info': volume_info}
74