Package occi :: Module backend
[hide private]
[frames] | no frames]

Source Code for Module occi.backend

  1  # coding=utf-8 
  2  # 
  3  # Copyright (C) 2010-2012 Platform Computing 
  4  # 
  5  # This library is free software; you can redistribute it and/or 
  6  # modify it under the terms of the GNU Lesser General Public 
  7  # License as published by the Free Software Foundation; either 
  8  # version 2.1 of the License, or (at your option) any later version. 
  9  # 
 10  # This library is distributed in the hope that it will be useful, 
 11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 13  # Lesser General Public License for more details. 
 14  # 
 15  # You should have received a copy of the GNU Lesser General Public 
 16  # License along with this library; if not, write to the Free Software 
 17  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA 
 18  # 
 19  ''' 
 20  Backends should derive from this class. 
 21   
 22  Created on Jun 27, 2011 
 23   
 24  @author: tmetsch 
 25  ''' 
 26   
 27   
 38   
 39   
40 -def is_attr_mutable(category, attribute_name):
41 ''' 42 Checks if an attribute is mutable. Return True if so. 43 44 category -- The category which defines the attribute. 45 attribute_name -- The name of the attribute. 46 ''' 47 if category.attributes[attribute_name] == 'mutable': 48 return True 49 else: 50 return False
51 52
53 -def is_attr_required(category, attribute_name):
54 ''' 55 Checks if an attribute is required. Return True if so. 56 57 category -- The category which defines the attribute. 58 attribute_name -- The name of the attribute. 59 ''' 60 if category.attributes[attribute_name] == 'required': 61 return True 62 else: 63 return False
64 65
66 -def is_action_applicable(entity, action):
67 ''' 68 Returns true if the action is currently applicable. 69 70 entity -- The current entity. 71 action -- The action to test for. 72 ''' 73 if action in entity.actions and action in entity.kind.actions: 74 return True 75 else: 76 return False
77 78
79 -class KindBackend(object):
80 ''' 81 A prototype backend which essentially does nothing. 82 83 Use this Backend for your Resource and Link types. 84 85 Note that it can happen that an entity has more than one backend assigned 86 (this is the case when it has a couple of mixins). But you can assign 87 multiple kinds to one backend. 88 ''' 89
90 - def create(self, entity, extras):
91 ''' 92 Call the Resource Management and create this entity. 93 94 entity -- The entity which is to be created. 95 extras -- Any extra arguments which are defined by the user. 96 ''' 97 pass
98
99 - def retrieve(self, entity, extras):
100 ''' 101 Call the Resource Management and refresh this entity so the client gets 102 up to date information. 103 104 entity -- The entity which is to be retrieved. 105 extras -- Any extra arguments which are defined by the user. 106 ''' 107 pass
108
109 - def update(self, old, new, extras):
110 ''' 111 Call the Resource Management and update this entity. 112 113 It is up to the backend implementation to decide which information from 114 new if copied into old. 115 116 Note that the new entity might no have all the information the old one 117 had. 118 119 old -- The old entity which is to be updated. 120 new -- The new entity holding the updated information. 121 extras -- Any extra arguments which are defined by the user. 122 ''' 123 pass
124
125 - def replace(self, old, new, extras):
126 ''' 127 Call the Resource Management and update this entity. This is 128 essentially a full update (Which allows removal of attributes for 129 example). 130 131 It is up to the backend implementation to decide which information from 132 new if copied into old. So if you really want to replace old with new 133 you need to have an old.* = new.* somewhere here (RECOMMENDED). 134 135 old -- The old entity which is to be updated. 136 new -- The new entity holding the updated information. 137 extras -- Any extra arguments which are defined by the user. 138 ''' 139 pass
140
141 - def delete(self, entity, extras):
142 ''' 143 Call the Resource Management and delete this entity. 144 145 entity -- The entity which is to be deleted. 146 extras -- Any extra arguments which are defined by the user. 147 ''' 148 pass
149 150
151 -class ActionBackend(object):
152 ''' 153 A prototype backend which essentially does nothing. 154 155 Use this Backend for Action types. 156 ''' 157 158 # disabling 'Too few public...' pylint check (this is for extension) 159 # pylint: disable=R0903 160
161 - def action(self, entity, action, attributes, extras):
162 ''' 163 Call the Resource Management and perform this action. 164 165 entity -- The entity on which the action is going to be performed. 166 action -- The action category definition. 167 attributes -- The acctributes for this action. 168 extras -- Any extra arguments which are defined by the user. 169 ''' 170 pass
171 172
173 -class MixinBackend(KindBackend):
174 ''' 175 A prototype backend which essentially does nothing. 176 177 Use this Backend for Mixin types. 178 ''' 179 180 pass
181 182
183 -class UserDefinedMixinBackend(MixinBackend):
184 ''' 185 A Backend for mixins defined by users. 186 187 DO NOT USE THIS CLASS IN YOUR IMPLEMENTATION! 188 ''' 189 190 pass
191