X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fstorage%2Fmodel.py;h=b0950429d604c37768d3a2c96a9579a1457fda62;hb=1cc8e9613cab8b5b22478de369f259e591c54e6d;hp=64da316d971652c1c6a948f86d3e6087ad1ea975;hpb=67288d32c856344f4084e93d97402d16c9a756f3;p=sfa.git diff --git a/sfa/storage/model.py b/sfa/storage/model.py index 64da316d..b0950429 100644 --- a/sfa/storage/model.py +++ b/sfa/storage/model.py @@ -1,6 +1,7 @@ from types import StringTypes from datetime import datetime +from sqlalchemy import or_, and_ from sqlalchemy import Column, Integer, String, DateTime from sqlalchemy import Table, Column, MetaData, join, ForeignKey from sqlalchemy.orm import relationship, backref @@ -311,6 +312,91 @@ class RegKey (Base): result += ">" return result +class SliverAllocation(Base,AlchemyObj): + __tablename__ = 'sliver_allocation' + sliver_id = Column(String, primary_key=True) + client_id = Column(String) + component_id = Column(String) + slice_urn = Column(String) + allocation_state = Column(String) + + def __init__(self, **kwds): + if 'sliver_id' in kwds: + self.sliver_id = kwds['sliver_id'] + if 'client_id' in kwds: + self.client_id = kwds['client_id'] + if 'component_id' in kwds: + self.component_id = kwds['component_id'] + if 'slice_urn' in kwds: + self.slice_urn = kwds['slice_urn'] + if 'allocation_state' in kwds: + self.allocation_state = kwds['allocation_state'] + + def __repr__(self): + result = ":} +# so after that, an 'authority' record will e.g. have a 'reg-pis' field with the hrns of its pi-users +augment_map={'authority': {'reg-pis':'reg_pis',}, + 'slice': {'reg-researchers':'reg_researchers',}, + 'user': {'reg-pi-authorities':'reg_authorities_as_pi', + 'reg-slices':'reg_slices_as_researcher',}, + } + +def augment_with_sfa_builtins (local_record): + # don't ruin the import of that file in a client world + from sfa.util.xrn import Xrn + # add a 'urn' field + setattr(local_record,'reg-urn',Xrn(xrn=local_record.hrn,type=local_record.type).urn) + # users have keys and this is needed to synthesize 'users' sent over to CreateSliver + if local_record.type=='user': + user_keys = [ key.key for key in local_record.reg_keys ] + setattr(local_record, 'reg-keys', user_keys) + # search in map according to record type + type_map=augment_map.get(local_record.type,{}) + # use type-dep. map to do the job + for (field_name,attribute) in type_map.items(): + # get related objects + related_records = getattr(local_record,attribute,[]) + hrns = [ r.hrn for r in related_records ] + setattr (local_record, field_name, hrns) + +