def main_update_config_instanceType(args=None, func=_print_page): """Sets the AWS EC2 instance type for new virtual machines. This feature is only relevant for the AWS EC2 deployment. By default prints entire resultant configuration in JSON. """ op = optparse.OptionParser( usage= "USAGE: %prog [options] [t1.micro | m1.small | c1.medium] CONFIG_FILE", description=main_update_config_instanceType.__doc__) # add_options(op) op.add_option("-v", "--verbose", action="store_true", dest="verbose", help="verbose output") (options, args) = op.parse_args(args) if len(args) != 2: op.error('expecting 2 argument') configFile = _open_config(args[1]) query = dict(subresource='/config') page = put_page(configFile, SECTION, json.dumps(dict(instance=args[0])), **query) if func: func(page) return page
def main_update_config_floor(args=None, func=_print_page): """Sets a floor for the number of Consumer processes that should remain running for a interval determined by the server. Currently this is only supported in the AWS EC2 deployment. By default prints entire resultant configuration in JSON. """ op = optparse.OptionParser(usage="USAGE: %prog [options] INT CONFIG_FILE", description=main_update_config_floor.__doc__) # add_options(op) op.add_option("-v", "--verbose", action="store_true", dest="verbose", help="verbose output") (options, args) = op.parse_args(args) if len(args) != 2: op.error('expecting 2 argument') configFile = _open_config(args[1]) query = dict(subresource='/config') page = put_page(configFile, SECTION, json.dumps(dict(floor=int(args[0]))), **query) if func: func(page) return page
def main_create(args=None): """Create an empty Simulation Resource """ op = optparse.OptionParser( usage= "USAGE: %prog [options] SIMULATION_NAME|GUID APPLICATION_NAME CONFIG_FILE", description=main_create.__doc__) op.add_option( "-s", "--simulation", action="store", dest="simulation_name", default=None, help= "override versioning system and specify the GUID identifier for a simulation " ) (options, args) = op.parse_args(args) if len(args) != 3: op.error('expecting 3 arguments') cp = _open_config(args[2]) application = args[1] subresource = args[0] simulation_name = None if options.simulation_name: uuid.UUID(subresource) simulation_name = options.simulation_name else: try: uuid.UUID(subresource) except ValueError: pass else: op.error('must use -s option when specifying a guid, see help') simulation_name = subresource kw = dict(subresource=subresource) data = json.dumps( dict(Application=application, StagedInputs=[], Name=simulation_name)) try: data = put_page(cp, SECTION, data, content_type='application/json', **kw) except HTTPError as ex: _log.error(ex) if hasattr(ex, 'readlines'): _log.error("".join(ex.readlines())) elif hasattr(ex, 'read'): _log.error("".join(ex.read())) raise return json.loads(data)
def main_update(args=None): """Update simulation by essentially doing a PUT with the specified file to the resource or optionally sub-resource. """ op = optparse.OptionParser( usage= "USAGE: %prog [options] SIMULATION_NAME|GUID FILE_NAME CONFIG_FILE", description=main_update.__doc__) op.add_option( "-r", "--resource", action="store", dest="resource", help="select the staged input file name (matches Application)") (options, args) = op.parse_args(args) if len(args) != 3: op.error('expecting 3 arguments') log = _log.getLogger('%s.main_update' % __name__) log.debug(args) file_name = args[1] if not os.path.isfile(file_name): op.error('expecting a file for argument 2') if options.resource is None: op.error('require resource option to be specified') configFile = _open_config(args[2]) simulation = args[0] kw = {} out = sys.stdout kw['subresource'] = '%s/input/%s' % (simulation, options.resource) with open(file_name, 'rb') as fd: contents = fd.read() try: data = put_page(configFile, SECTION, contents, **kw) except HTTPError as ex: _log.error("HTTP Code %d : %s", ex.code, ex.msg) if hasattr(ex, 'readlines'): _log.debug("".join(ex.readlines())) else: _log.debug("".join(ex.read())) raise except urllib.error.URLError as ex: _log.error("URLError : %s", ex.reason) raise return data