Example #1
0
def pickup() :
    global __PICKUP_CALLED__
    if __PICKUP_CALLED__ != None:
        return
    
    from preferences import resource_filename
    an_rcfilename = resource_filename()

    import os.path;
    an_rcfilename = os.path.expanduser( an_rcfilename )
    an_rcfilename = os.path.abspath( an_rcfilename )
    if not os.path.isfile( an_rcfilename ) :
        # If resource file does not exist - write a predefined one
        an_rcfile = open( an_rcfilename, "w" )
        import cloudflu; an_rcfile.write( """
#--------------------------------------------------------------------------------------
## Copyright 2010 Alexey Petrov
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
##     http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
## See http://sourceforge.net/apps/mediawiki/cloudflu
##
## Author : Automatically generated (%s-%s)
##


#--------------------------------------------------------------------------------------
REGION2PARAMS = { 'us-east-1' : [ '', { 'openfoam171_0-1ubuntu2' : 'ami-ecf50385', 
                                        'openfoam171_0-1' : 'ami-62fa0c0b', 
                                        'openfoam-dev-1.5' : 'ami-98f701f1' } ] }


#--------------------------------------------------------------------------------------
class Helper :
    def __init__( self, the_ec2_region, the_openfoam_version, the_debug = False, the_develop = False ) :
        self._cluster_location = the_ec2_region
        self._data_location = REGION2PARAMS[ the_ec2_region ][ 0 ]
        self._image_id = REGION2PARAMS[ the_ec2_region ][ 1 ][ the_openfoam_version ]

        self._enable_debug = the_debug
        self._develop = the_develop

        self._instance_type = 'c1.xlarge'
        if the_debug == True :
            self._instance_type = 'm1.large'
            pass

        pass

    def cluster_location( self ) :
        return self._cluster_location

    def image_id( self ) :
        return self._image_id
    
    def data_location( self ) :
        return self._data_location
    
    def enable_debug( self ) :
        return self._enable_debug
    
    def production( self ) :
        return not self._develop
    
    def instance_type( self ) :
        return self._instance_type
    
    pass


#--------------------------------------------------------------------------------------
a_helper = Helper( 'us-east-1', 'openfoam171_0-1ubuntu2' )


#--------------------------------------------------------------------------------------
""" % ( cloudflu.NAME, cloudflu.VERSION ) )

        import cStringIO
        an_output = cStringIO.StringIO()

        from common.options import dump as common_dump;  common_dump( 0, an_output )

        from amazon.options import dump as amazon_dump;  amazon_dump( 0, an_output )
        
        an_rcfile.write( an_output.getvalue() )

        an_rcfile.write( '\n' )
        an_rcfile.write( '#--------------------------------------------------------------------------------------' )
        an_rcfile.write( '\n' )
    
        an_rcfile.close()

        import stat
        # os.chmod( an_rcfilename, stat.S_IRUSR ) # To protect user data
        pass

    __PICKUP_CALLED__ = True

    pass
Example #2
0
##     http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
## See http://sourceforge.net/apps/mediawiki/cloudflu
##
## Author : Alexey Petrov
##


#--------------------------------------------------------------------------------------
from preferences import pickup; pickup()
from preferences import resource_filename; an_rcfilename = resource_filename()

import os.path;
an_rcfilename = os.path.expanduser( an_rcfilename )
an_rcfilename = os.path.abspath( an_rcfilename )

an_rcfile = open( an_rcfilename )
a_preferences = compile( "".join( an_rcfile.readlines() ), an_rcfilename, 'exec' )
an_rcfile.close()

exec a_preferences


#--------------------------------------------------------------------------------------
Example #3
0
def main() :
    #----------------------- Defining utility command-line interface -------------------------    
    from cloudflu import amazon

    an_usage_description = "%prog --precision=10 --start-size=65536 --solution-window=50 --number-mesurements=5"

    from cloudflu import VERSION
    a_version = "%s" % VERSION

    from optparse import IndentedHelpFormatter
    a_help_formatter = IndentedHelpFormatter( width = 127 )

    from optparse import OptionParser
    an_option_parser = OptionParser( usage = an_usage_description, version = a_version, formatter = a_help_formatter )


    #----------------------- Definition of the command line arguments ------------------------
    an_option_parser.add_option( "--precision",
                                 metavar = "< algorithm precision, % >",
                                 type = "int",
                                 action = "store",
                                 dest = "precision",
                                 help = "(%default, by default)",
                                 default = 10 )
    
    an_option_parser.add_option( "--start-size",
                                 metavar = "< start value for the search algorithm, bytes >",
                                 type = "int",
                                 action = "store",
                                 dest = "start_size",
                                 help = "(%default, by default)",
                                 default = 65536 )
    
    an_option_parser.add_option( "--solution-window",
                                 metavar = "< initial solution window considered to, %>",
                                 type = "int",
                                 action = "store",
                                 dest = "solution_window",
                                 help = "(%default, by default)",
                                 default = 50 )
                             
    an_option_parser.add_option( "--number-mesurements",
                                 metavar = "< number mesurements to be done in the solution window>",
                                 type = "int",
                                 action = "store",
                                 dest = "number_mesurements",
                                 help = "(%default, by default)",
                                 default = 5 )
    
    amazon.security_options.add( an_option_parser )

    
    #------------------ Extracting and verifying command-line arguments ----------------------
    an_options, an_args = an_option_parser.parse_args()

    AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY = amazon.security_options.extract( an_option_parser )

    a_precision = an_options.precision

    a_center_x = an_options.start_size

    a_region_x = an_options.solution_window

    a_nb_attempts = an_options.number_mesurements

    from cloudflu.preferences import get
    a_data_location = get( 'amazon.data_transfer.location' )

    an_engine = SeedSizeMesurement( AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, a_data_location )

    from cloudflu.common import Timer
    a_spent_time = Timer()

    an_optimize_x, a_cost = entry_point( an_engine, a_center_x, a_region_x, a_precision, a_nb_attempts, get_stats )

    from preferences import resource_filename; an_rcfilename = resource_filename()

    import time; an_rcfilename_save = '%s_%s' % ( an_rcfilename, time.strftime( '%Y-%m-%d_%H:%M' ) )

    import os; os.system( "cp %s %s" % ( an_rcfilename, an_rcfilename_save ) )

    import os; os.system( "perl -p -i -e 's/(socket_timeout =)\s*[0-9]+/\\1 %d/' %s" % 
                          ( an_engine.timeout(), an_rcfilename ) )

    import os; os.system( "perl -p -i -e 's/(upload_seed_size =)\s*[0-9]+/\\1 %d/' %s" % 
                          ( an_optimize_x, an_rcfilename ) )

    print "a_spent_time = %s, sec\n" % a_spent_time
    pass