<s> import datetime as dt <EOL> from rally . common import db <EOL> from rally import consts <EOL> class Deployment ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , deployment = None , ** attributes ) : <EOL> if deployment : <EOL> self . deployment = deployment <EOL> else : <EOL> self . deployment = db . deployment_create ( attributes ) <EOL> def __getitem__ ( self , key ) : <EOL> return self . deployment [ key ] <EOL> @ staticmethod <EOL> def get ( deploy ) : <EOL> return Deployment ( db . deployment_get ( deploy ) ) <EOL> @ staticmethod <EOL> def list ( status = None , parent_uuid = None , name = None ) : <EOL> return db . deployment_list ( status , parent_uuid , name ) <EOL> @ staticmethod <EOL> def delete_by_uuid ( uuid ) : <EOL> db . deployment_delete ( uuid ) <EOL> def _update ( self , values ) : <EOL> self . deployment = db . deployment_update ( self . deployment [ "<STR_LIT>" ] , values ) <EOL> def update_status ( self , status ) : <EOL> self . _update ( { "<STR_LIT:status>" : status } ) <EOL> def update_name ( self , name ) : <EOL> self . _update ( { "<STR_LIT:name>" : name } ) <EOL> def update_config ( self , config ) : <EOL> self . _update ( { "<STR_LIT>" : config } ) <EOL> def update_credentials ( self , credentials ) : <EOL> admin = credentials . get ( "<STR_LIT>" , { } ) <EOL> if admin : <EOL> admin = admin . to_dict ( include_permission = True ) <EOL> self . _update ( { <EOL> "<STR_LIT>" : admin , <EOL> "<STR_LIT>" : [ e . to_dict ( include_permission = True ) <EOL> for e in credentials . get ( "<STR_LIT>" , [ ] ) ] <EOL> } ) <EOL> def set_started ( self ) : <EOL> self . _update ( { "<STR_LIT>" : dt . datetime . now ( ) , <EOL> "<STR_LIT:status>" : consts . DeployStatus . DEPLOY_STARTED } ) <EOL> def set_completed ( self ) : <EOL> self . _update ( { "<STR_LIT>" : dt . datetime . now ( ) , <EOL> "<STR_LIT:status>" : consts . DeployStatus . DEPLOY_FINISHED } ) <EOL> def add_resource ( self , provider_name , type = None , info = None ) : <EOL> return db . resource_create ( { <EOL> "<STR_LIT>" : self . deployment [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : provider_name , <EOL> "<STR_LIT:type>" : type , <EOL> "<STR_LIT:info>" : info , <EOL> } ) <EOL> def get_resources ( self , provider_name = None , type = None ) : <EOL> return db . resource_get_all ( self . deployment [ "<STR_LIT>" ] , <EOL> provider_name = provider_name , type = type ) <EOL> @ staticmethod <EOL> def delete_resource ( resource_id ) : <EOL> db . resource_delete ( resource_id ) <EOL> def delete ( self ) : <EOL> db . deployment_delete ( self . deployment [ "<STR_LIT>" ] ) </s>
