#NEWLINE# def pull( server , secret , name ) : #NEWLINE# #INDENT# '\n    Pull a blueprint from the secret and name on the configured server.\n    ' #NEWLINE# r = http . get ( '/{0}/{1}' . format ( secret , name ) , server = server ) #NEWLINE# if ( 200 == r . status ) : #NEWLINE# #INDENT# b = Blueprint . load ( r , name ) #NEWLINE# for filename in b . sources . itervalues ( ) : #NEWLINE# #INDENT# logging . info ( 'fetching source tarballs - this may take a while' ) #NEWLINE# r = http . get ( '/{0}/{1}/{2}' . format ( secret , name , filename ) , server = r ) #NEWLINE# if ( 200 == r . status ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# f = open ( filename , 'w' ) #NEWLINE# f . write ( r . read ( ) ) #NEWLINE# #UNINDENT# except OSError : #NEWLINE# #INDENT# logging . error ( 'could not open {0}' . format ( filename ) ) #NEWLINE# return None #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# f . close ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( 404 == r . status ) : #NEWLINE# #INDENT# logging . error ( '{0} not found' . format ( filename ) ) #NEWLINE# return None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 502 == r . status ) : #NEWLINE# #INDENT# logging . error ( 'upstream storage service failed' ) #NEWLINE# return None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# logging . error ( 'unexpected {0} fetching tarball' . format ( r . status ) ) #NEWLINE# return None #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return b #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 404 == r . status ) : #NEWLINE# #INDENT# logging . error ( 'blueprint not found' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 502 == r . status ) : #NEWLINE# #INDENT# logging . error ( 'upstream storage service failed' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# logging . error ( 'unexpected {0} fetching blueprint' . format ( r . status ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return None