Revision 3846dfd0 db/models.py
b/db/models.py | ||
---|---|---|
143 | 143 |
return self._cost_active |
144 | 144 |
|
145 | 145 |
def _update_costs(self): |
146 |
# if _cost |
|
146 |
# if _cost_active is not defined, then define it!
|
|
147 | 147 |
if '_cost_active' not in dir(self): |
148 |
fch = FlavorCostHistory.objects.filter(flavor=self).order_by('-effective_from')[0] |
|
149 |
self._cost_active = fch.cost_active |
|
150 |
self._cost_inactive = fch.cost_inactive |
|
148 |
fch_list = FlavorCostHistory.objects.filter(flavor=self).order_by('-effective_from') |
|
149 |
if len(fch_list) > 0: |
|
150 |
fch = fch_list[0] |
|
151 |
self._cost_active = fch.cost_active |
|
152 |
self._cost_inactive = fch.cost_inactive |
|
153 |
else: |
|
154 |
self._cost_active = 0 |
|
155 |
self._cost_inactive = 0 |
|
151 | 156 |
|
152 | 157 |
name = property(_get_name) |
153 | 158 |
cost_active = property(_get_cost_active) |
... | ... | |
155 | 160 |
|
156 | 161 |
def __unicode__(self): |
157 | 162 |
return self.name |
163 |
|
|
164 |
def get_price_list(self): |
|
165 |
fch_list = FlavorCostHistory.objects.get(flavor=self).order_by('effective_from') |
|
166 |
|
|
167 |
return fch_list |
|
158 | 168 |
|
159 | 169 |
|
160 | 170 |
class FlavorCostHistory(models.Model): |
... | ... | |
167 | 177 |
verbose_name = u'Pricing history for flavors' |
168 | 178 |
|
169 | 179 |
def __unicode__(self): |
170 |
return u'Costs (up, down)=(%d, %d) for %s since %s' % (cost_active, cost_inactive, flavor.name, effective_from) |
|
180 |
return u'Costs (up, down)=(%d, %d) for %s since %s' % (self.cost_active, self.cost_inactive, flavor.name, self.effective_from) |
|
181 |
|
|
182 |
@staticmethod |
|
183 |
def find_cost(fch_list, dat): |
|
184 |
rdate = fch_list[0] |
|
185 |
|
|
186 |
for fc in fch_list: |
|
187 |
if dat > fc.effective_from: |
|
188 |
rdate = fc |
|
189 |
|
|
190 |
return rdate |
|
171 | 191 |
|
172 | 192 |
|
173 | 193 |
class VirtualMachine(models.Model): |
... | ... | |
281 | 301 |
raise VirtualMachine.InvalidBackendIdError(str(name)) |
282 | 302 |
return int(ns) |
283 | 303 |
|
284 |
def __init__(self, *args, **kw):
|
|
304 |
def __init__(self, *args, **kw): |
|
285 | 305 |
"""Initialize state for just created VM instances.""" |
286 | 306 |
super(VirtualMachine, self).__init__(*args, **kw) |
287 | 307 |
# Before this instance gets save()d |
Also available in: Unified diff