<s> try : <EOL> import simplejson as json <EOL> except : <EOL> import json <EOL> import boto <EOL> from boto . cloudformation . stack import Stack , StackSummary , StackEvent <EOL> from boto . cloudformation . stack import StackResource , StackResourceSummary <EOL> from boto . cloudformation . template import Template <EOL> from boto . connection import AWSQueryConnection <EOL> from boto . regioninfo import RegionInfo <EOL> class CloudFormationConnection ( AWSQueryConnection ) : <EOL> """<STR_LIT>""" <EOL> DefaultRegionName = '<STR_LIT>' <EOL> DefaultRegionEndpoint = '<STR_LIT>' <EOL> APIVersion = '<STR_LIT>' <EOL> valid_states = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def __init__ ( self , aws_access_key_id = None , aws_secret_access_key = None , <EOL> is_secure = True , port = None , proxy = None , proxy_port = None , <EOL> proxy_user = None , proxy_pass = None , debug = <NUM_LIT:0> , <EOL> https_connection_factory = None , region = None , path = '<STR_LIT:/>' , <EOL> converter = None ) : <EOL> if not region : <EOL> region = RegionInfo ( self , self . DefaultRegionName , <EOL> self . DefaultRegionEndpoint , CloudFormationConnection ) <EOL> self . region = region <EOL> AWSQueryConnection . __init__ ( self , aws_access_key_id , <EOL> aws_secret_access_key , <EOL> is_secure , port , proxy , proxy_port , <EOL> proxy_user , proxy_pass , <EOL> self . region . endpoint , debug , <EOL> https_connection_factory , path ) <EOL> def _required_auth_capability ( self ) : <EOL> return [ '<STR_LIT>' ] <EOL> def encode_bool ( self , v ) : <EOL> v = bool ( v ) <EOL> return { True : "<STR_LIT:true>" , False : "<STR_LIT:false>" } [ v ] <EOL> def create_stack ( self , stack_name , template_body = None , template_url = None , <EOL> parameters = [ ] , notification_arns = [ ] , disable_rollback = False , <EOL> timeout_in_minutes = None , capabilities = None ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : "<STR_LIT>" , '<STR_LIT>' : stack_name , <EOL> '<STR_LIT>' : self . encode_bool ( disable_rollback ) } <EOL> if template_body : <EOL> params [ '<STR_LIT>' ] = template_body <EOL> if template_url : <EOL> params [ '<STR_LIT>' ] = template_url <EOL> if template_body and template_url : <EOL> boto . log . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if len ( parameters ) > <NUM_LIT:0> : <EOL> for i , ( key , value ) in enumerate ( parameters ) : <EOL> params [ '<STR_LIT>' % ( i + <NUM_LIT:1> ) ] = key <EOL> params [ '<STR_LIT>' % ( i + <NUM_LIT:1> ) ] = value <EOL> if capabilities : <EOL> for i , value in enumerate ( capabilities ) : <EOL> params [ '<STR_LIT>' % ( i + <NUM_LIT:1> ) ] = value <EOL> if len ( notification_arns ) > <NUM_LIT:0> : <EOL> self . build_list_params ( params , notification_arns , <EOL> "<STR_LIT>" ) <EOL> if timeout_in_minutes : <EOL> params [ '<STR_LIT>' ] = int ( timeout_in_minutes ) <EOL> response = self . make_request ( '<STR_LIT>' , params , '<STR_LIT:/>' , '<STR_LIT:POST>' ) <EOL> body = response . read ( ) <EOL> if response . status == <NUM_LIT:200> : <EOL> body = json . loads ( body ) <EOL> return body [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> else : <EOL> boto . log . error ( '<STR_LIT>' % ( response . status , response . reason ) ) <EOL> boto . log . error ( '<STR_LIT:%s>' % body ) <EOL> raise self . ResponseError ( response . status , response . reason , body ) <EOL> def update_stack ( self , stack_name , template_body = None , template_url = None , <EOL> parameters = [ ] , notification_arns = [ ] , disable_rollback = False , <EOL> timeout_in_minutes = None ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : "<STR_LIT>" , '<STR_LIT>' : stack_name , <EOL> '<STR_LIT>' : self . encode_bool ( disable_rollback ) } <EOL> if template_body : <EOL> params [ '<STR_LIT>' ] = template_body <EOL> if template_url : <EOL> params [ '<STR_LIT>' ] = template_url <EOL> if template_body and template_url : <EOL> boto . log . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if len ( parameters ) > <NUM_LIT:0> : <EOL> for i , ( key , value ) in enumerate ( parameters ) : <EOL> params [ '<STR_LIT>' % ( i + <NUM_LIT:1> ) ] = key <EOL> params [ '<STR_LIT>' % ( i + <NUM_LIT:1> ) ] = value <EOL> if len ( notification_arns ) > <NUM_LIT:0> : <EOL> self . build_list_params ( params , notification_arns , <EOL> "<STR_LIT>" ) <EOL> if timeout_in_minutes : <EOL> params [ '<STR_LIT>' ] = int ( timeout_in_minutes ) <EOL> response = self . make_request ( '<STR_LIT>' , params , '<STR_LIT:/>' , '<STR_LIT:POST>' ) <EOL> body = response . read ( ) <EOL> if response . status == <NUM_LIT:200> : <EOL> body = json . loads ( body ) <EOL> return body [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> else : <EOL> boto . log . error ( '<STR_LIT>' % ( response . status , response . reason ) ) <EOL> boto . log . error ( '<STR_LIT:%s>' % body ) <EOL> raise self . ResponseError ( response . status , response . reason , body ) <EOL> def delete_stack ( self , stack_name_or_id ) : <EOL> params = { '<STR_LIT>' : "<STR_LIT>" , '<STR_LIT>' : stack_name_or_id } <EOL> response = self . make_request ( '<STR_LIT>' , params , '<STR_LIT:/>' , '<STR_LIT:GET>' ) <EOL> body = response . read ( ) <EOL> if response . status == <NUM_LIT:200> : <EOL> return json . loads ( body ) <EOL> else : <EOL> boto . log . error ( '<STR_LIT>' % ( response . status , response . reason ) ) <EOL> boto . log . error ( '<STR_LIT:%s>' % body ) <EOL> raise self . ResponseError ( response . status , response . reason , body ) <EOL> def describe_stack_events ( self , stack_name_or_id = None , next_token = None ) : <EOL> params = { } <EOL> if stack_name_or_id : <EOL> params [ '<STR_LIT>' ] = stack_name_or_id <EOL> if next_token : <EOL> params [ '<STR_LIT>' ] = next_token <EOL> return self . get_list ( '<STR_LIT>' , params , [ ( '<STR_LIT>' , <EOL> StackEvent ) ] ) <EOL> def describe_stack_resource ( self , stack_name_or_id , logical_resource_id ) : <EOL> params = { '<STR_LIT>' : "<STR_LIT>" , '<STR_LIT>' : stack_name_or_id , <EOL> '<STR_LIT>' : logical_resource_id } <EOL> response = self . make_request ( '<STR_LIT>' , params , <EOL> '<STR_LIT:/>' , '<STR_LIT:GET>' ) <EOL> body = response . read ( ) <EOL> if response . status == <NUM_LIT:200> : <EOL> return json . loads ( body ) <EOL> else : <EOL> boto . log . error ( '<STR_LIT>' % ( response . status , response . reason ) ) <EOL> boto . log . error ( '<STR_LIT:%s>' % body ) <EOL> raise self . ResponseError ( response . status , response . reason , body ) <EOL> def describe_stack_resources ( self , stack_name_or_id = None , <EOL> logical_resource_id = None , <EOL> physical_resource_id = None ) : <EOL> params = { } <EOL> if stack_name_or_id : <EOL> params [ '<STR_LIT>' ] = stack_name_or_id <EOL> if logical_resource_id : <EOL> params [ '<STR_LIT>' ] = logical_resource_id <EOL> if physical_resource_id : <EOL> params [ '<STR_LIT>' ] = physical_resource_id <EOL> return self . get_list ( '<STR_LIT>' , params , <EOL> [ ( '<STR_LIT>' , StackResource ) ] ) <EOL> def describe_stacks ( self , stack_name_or_id = None ) : <EOL> params = { } <EOL> if stack_name_or_id : <EOL> params [ '<STR_LIT>' ] = stack_name_or_id <EOL> return self . get_list ( '<STR_LIT>' , params , [ ( '<STR_LIT>' , Stack ) ] ) <EOL> def get_template ( self , stack_name_or_id ) : <EOL> params = { '<STR_LIT>' : "<STR_LIT>" , '<STR_LIT>' : stack_name_or_id } <EOL> response = self . make_request ( '<STR_LIT>' , params , '<STR_LIT:/>' , '<STR_LIT:GET>' ) <EOL> body = response . read ( ) <EOL> if response . status == <NUM_LIT:200> : <EOL> return json . loads ( body ) <EOL> else : <EOL> boto . log . error ( '<STR_LIT>' % ( response . status , response . reason ) ) <EOL> boto . log . error ( '<STR_LIT:%s>' % body ) <EOL> raise self . ResponseError ( response . status , response . reason , body ) <EOL> def list_stack_resources ( self , stack_name_or_id , next_token = None ) : <EOL> params = { '<STR_LIT>' : stack_name_or_id } <EOL> if next_token : <EOL> params [ '<STR_LIT>' ] = next_token <EOL> return self . get_list ( '<STR_LIT>' , params , <EOL> [ ( '<STR_LIT>' , StackResourceSummary ) ] ) <EOL> def list_stacks ( self , stack_status_filters = [ ] , next_token = None ) : <EOL> params = { } <EOL> if next_token : <EOL> params [ '<STR_LIT>' ] = next_token <EOL> if len ( stack_status_filters ) > <NUM_LIT:0> : <EOL> self . build_list_params ( params , stack_status_filters , <EOL> "<STR_LIT>" ) <EOL> return self . get_list ( '<STR_LIT>' , params , <EOL> [ ( '<STR_LIT>' , StackSummary ) ] ) <EOL> def validate_template ( self , template_body = None , template_url = None ) : <EOL> params = { } <EOL> if template_body : <EOL> params [ '<STR_LIT>' ] = template_body <EOL> if template_url : <EOL> params [ '<STR_LIT>' ] = template_url <EOL> if template_body and template_url : <EOL> boto . log . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return self . get_object ( '<STR_LIT>' , params , Template , <EOL> verb = "<STR_LIT:POST>" ) </s>
