cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
region.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 from ec2.base.action import Action
20 from ec2.error import UndefinedError, MissingParameter
21 from ec2.helpers.parse import parseFilters
22 from ec2.helpers.filters import applyEc2Filters
23 
24 ##
25 # @package src.ec2.region
26 # EC2 actions for regions
27 #
28 # @copyright Copyright (c) 2012 Institute of Nuclear Physics PAS <http://www.ifj.edu.pl/>
29 # @author Oleksandr Gituliar <gituliar@gmail.com>
30 # @author Łukasz Chrząszcz <l.chrzaszcz@gmail.com>
31 #
32 
33 
34 def getClusterManagers(endpoint , cluster_manager):
35  try:
36  base_URL = endpoint.split('.', 1)[1]
37  except IndexError:
38  raise UndefinedError
39 
40  cluster_managers = cluster_manager.cloud_manager.cluster_managers()
41 
42  return {
43  'cms': [{
44  'address': "%s.%s" % (cm.name, base_URL),
45  'name': cm.name,
46  } for cm in cluster_managers]
47  }
48 
49 
50 class DescribeRegions(Action):
51 
52  def _execute(self):
53  try:
54  filters = parseFilters(self.parameters)
55 
56  endpoint = self.parameters['Endpoint']
57  except KeyError:
58  raise MissingParameter(parameter='Endpoint')
59 
60  cms = getClusterManagers(endpoint, self.cluster_manager)
61 
62  cms = applyEc2Filters(cms, filters)
63 
64  return cms
65 
66 
68  def _execute(self):
69  try:
70  endpoint = self.parameters['Endpoint']
71  except KeyError:
72  raise MissingParameter(parameter='Endpoint')
73 
74  return getClusterManagers(endpoint, self.cluster_manager)
75