<s> from tripleo_common . core import constants <EOL> from tripleo_common . core import exception <EOL> from tripleo_common . core . models import Plan <EOL> from tripleo_common . utils import meta <EOL> default_container_headers = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> constants . TRIPLEO_META_USAGE_KEY : '<STR_LIT>' <EOL> } <EOL> class SwiftPlanStorageBackend ( object ) : <EOL> def __init__ ( self , swiftclient ) : <EOL> self . swiftclient = swiftclient <EOL> def create ( self , plan_name ) : <EOL> """<STR_LIT>""" <EOL> if plan_name not in self . list ( ) : <EOL> self . swiftclient . put_container ( <EOL> plan_name , <EOL> headers = default_container_headers <EOL> ) <EOL> else : <EOL> raise exception . PlanAlreadyExistsError ( name = plan_name ) <EOL> def delete ( self , plan_name ) : <EOL> """<STR_LIT>""" <EOL> for data in self . swiftclient . get_container ( plan_name ) [ <NUM_LIT:1> ] : <EOL> self . swiftclient . delete_object ( plan_name , data [ '<STR_LIT:name>' ] ) <EOL> self . swiftclient . delete_container ( plan_name ) <EOL> def delete_file ( self , plan_name , filepath ) : <EOL> """<STR_LIT>""" <EOL> self . swiftclient . delete_object ( plan_name , filepath ) <EOL> def get ( self , plan_name ) : <EOL> """<STR_LIT>""" <EOL> plan = Plan ( plan_name ) <EOL> container = self . swiftclient . get_container ( plan_name ) <EOL> plan . metadata = container [ <NUM_LIT:0> ] <EOL> for data in container [ <NUM_LIT:1> ] : <EOL> filename = data [ '<STR_LIT:name>' ] <EOL> plan_obj = self . swiftclient . get_object ( plan_name , filename ) <EOL> plan . files [ filename ] = { } <EOL> plan . files [ filename ] [ '<STR_LIT>' ] = plan_obj [ <NUM_LIT:1> ] <EOL> meta_info = { k : v for ( k , v ) in plan_obj [ <NUM_LIT:0> ] . items ( ) <EOL> if constants . OBJECT_META_KEY_PREFIX in k } <EOL> if len ( meta_info ) > <NUM_LIT:0> : <EOL> plan . files [ filename ] [ '<STR_LIT>' ] = meta . remove_key_prefix ( meta_info ) <EOL> return plan <EOL> def list ( self ) : <EOL> """<STR_LIT>""" <EOL> plan_list = [ ] <EOL> for item in self . swiftclient . get_account ( ) [ <NUM_LIT:1> ] : <EOL> container = self . swiftclient . get_container ( item [ '<STR_LIT:name>' ] ) [ <NUM_LIT:0> ] <EOL> if constants . TRIPLEO_META_USAGE_KEY in container . keys ( ) : <EOL> plan_list . append ( item [ '<STR_LIT:name>' ] ) <EOL> return plan_list <EOL> def update ( self , plan_name , plan_files ) : <EOL> """<STR_LIT>""" <EOL> for filename , details in plan_files . items ( ) : <EOL> custom_headers = { } <EOL> if '<STR_LIT>' in details : <EOL> custom_headers = meta . add_key_prefix ( details [ '<STR_LIT>' ] ) <EOL> self . swiftclient . put_object ( <EOL> plan_name , <EOL> filename , <EOL> details [ '<STR_LIT>' ] , <EOL> headers = custom_headers <EOL> ) </s>
