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

Source Code for Module occi.core_model

  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  OCCI's core model. 
 21   
 22  Created on Jun 27, 2011 
 23   
 24  @author: tmetsch 
 25  ''' 
 26   
 27  # disabling 'Too few public methods' pylint check (It's a model...) 
 28  # disabling 'Too many arguments' pylint check (It's more elegant this way...) 
 29  # pylint: disable=R0903, R0913 
 30   
 31  #============================================================================== 
 32  # Categories 
 33  #============================================================================== 
 34   
 35   
36 -class Category(object):
37 ''' 38 OCCI Category. 39 ''' 40
41 - def __init__(self, scheme, term, title, attributes, location):
42 self.scheme = scheme 43 self.term = term 44 self.title = title 45 self.attributes = attributes 46 47 # location 48 self.location = location 49 self.extras = None
50
51 - def __eq__(self, instance):
52 if instance is None or not isinstance(instance, Category): 53 return False 54 if self.term == instance.term and self.scheme == instance.scheme \ 55 and self.extras == instance.extras: 56 return True 57 else: 58 return False
59
60 - def __hash__(self):
61 return hash(self.scheme) ^ hash(self.term) ^ hash(str(self.extras))
62
63 - def __str__(self):
64 return self.scheme + self.term
65 66
67 -class Kind(Category):
68 ''' 69 OCCI Kind. 70 ''' 71
72 - def __init__(self, scheme, term, related=None, actions=None, title='', 73 attributes=None, location=None):
74 super(Kind, self).__init__(scheme, term, title, attributes or {}, 75 location or '/' + term + '/') 76 self.related = related or [] 77 self.actions = actions or []
78
79 - def __repr__(self):
80 return 'kind'
81 82
83 -class Action(Category):
84 ''' 85 OCCI Action. 86 ''' 87
88 - def __init__(self, scheme, term, title='', attributes=None):
89 super(Action, self).__init__(scheme, term, title, attributes or {}, 90 location=None)
91
92 - def __repr__(self):
93 return 'action'
94 95
96 -class Mixin(Category):
97 ''' 98 OCCI Mixin. 99 ''' 100
101 - def __init__(self, scheme, term, related=None, actions=None, title='', 102 attributes=None, location=None):
103 super(Mixin, self).__init__(scheme, term, title, attributes or {}, 104 location or '/' + term + '/') 105 self.related = related or [] 106 self.actions = actions or []
107
108 - def __repr__(self):
109 return 'mixin'
110 111 112 #============================================================================== 113 # Entities 114 #============================================================================== 115 116
117 -class Entity(object):
118 ''' 119 OCCI Entity. 120 ''' 121
122 - def __init__(self, identifier, title, kind, mixins):
123 self.identifier = identifier 124 self.title = title 125 self.kind = kind 126 self.mixins = mixins 127 128 # Attributes of resource entities 129 self.attributes = {} 130 self.actions = [] 131 self.extras = None
132 133
134 -class Resource(Entity):
135 ''' 136 OCCI Resource. 137 ''' 138 139 kind = Kind('http://schemas.ogf.org/occi/core#', 'resource') 140
141 - def __init__(self, identifier, kind, mixins, links=None, summary=None, 142 title=None):
143 super(Resource, self).__init__(identifier, title, kind, mixins) 144 self.links = links or [] 145 self.summary = summary
146 147 159