#NEWLINE# def show_pricing( kwargs = None , call = None ) : #NEWLINE# #INDENT# '\n    Show pricing for a particular profile. This is only an estimate, based on\n    unofficial pricing sources.\n\n    .. versionadded:: 2015.8.0\n\n    CLI Examples:\n\n    .. code-block:: bash\n\n        salt-cloud -f show_pricing my-gce-config profile=my-profile\n    ' #NEWLINE# profile = __opts__ [ 'profiles' ] . get ( kwargs [ 'profile' ] , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# if ( not profile ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'Error' : 'The requested profile was not found' , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# provider = profile . get ( 'provider' , '0:0' ) #NEWLINE# comps = provider . split ( ':' ) #NEWLINE# if ( ( len ( comps ) < 2 ) or ( comps [ 1 ] != 'gce' ) ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'Error' : 'The requested profile does not belong to GCE' , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# comps = profile . get ( 'location' , 'us' ) . split ( '-' ) #NEWLINE# region = comps [ 0 ] #NEWLINE# size = 'CP-COMPUTEENGINE-VMIMAGE-{0}' . format ( profile [ 'size' ] . upper ( ) ) #NEWLINE# pricefile = os . path . join ( syspaths . CACHE_DIR , 'cloud' , 'gce-pricing.p' ) #NEWLINE# if ( not os . path . exists ( pricefile ) ) : #NEWLINE# #INDENT# update_pricing ( ) #NEWLINE# #UNINDENT# with salt . utils . fopen ( pricefile , 'r' ) as fho : #NEWLINE# #INDENT# sizes = msgpack . load ( fho ) #NEWLINE# #UNINDENT# per_hour = float ( sizes [ 'gcp_price_list' ] [ size ] [ region ] ) #NEWLINE# week1_discount = float ( sizes [ 'gcp_price_list' ] [ 'sustained_use_tiers' ] [ '0.25' ] ) #NEWLINE# week2_discount = float ( sizes [ 'gcp_price_list' ] [ 'sustained_use_tiers' ] [ '0.50' ] ) #NEWLINE# week3_discount = float ( sizes [ 'gcp_price_list' ] [ 'sustained_use_tiers' ] [ '0.75' ] ) #NEWLINE# week4_discount = float ( sizes [ 'gcp_price_list' ] [ 'sustained_use_tiers' ] [ '1.0' ] ) #NEWLINE# week1 = ( ( per_hour * ( 730 / 4 ) ) * week1_discount ) #NEWLINE# week2 = ( ( per_hour * ( 730 / 4 ) ) * week2_discount ) #NEWLINE# week3 = ( ( per_hour * ( 730 / 4 ) ) * week3_discount ) #NEWLINE# week4 = ( ( per_hour * ( 730 / 4 ) ) * week4_discount ) #NEWLINE# raw = ret #NEWLINE# ret = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# ret [ 'per_hour' ] = per_hour #NEWLINE# ret [ 'per_day' ] = ( ret [ 'per_hour' ] * 24 ) #NEWLINE# ret [ 'per_week' ] = ( ret [ 'per_day' ] * 7 ) #NEWLINE# ret [ 'per_month' ] = ( ( ( week1 + week2 ) + week3 ) + week4 ) #NEWLINE# ret [ 'per_year' ] = ( ret [ 'per_month' ] * 12 ) #NEWLINE# if kwargs . get ( 'raw' , False ) : #NEWLINE# #INDENT# ret [ '_raw' ] = raw #NEWLINE# #UNINDENT# return { #NEWLINE# #INDENT# profile [ 'profile' ] : ret , #NEWLINE# #UNINDENT# }