def init(reset_config, skip_logging=False): if os.path.exists(os.path.join( utils.get_cwd(), constants.CLOUDIFY_WD_SETTINGS_DIRECTORY_NAME, constants.CLOUDIFY_WD_SETTINGS_FILE_NAME)): if not reset_config: msg = 'Current directory is already initialized' error = exceptions.CloudifyCliError(msg) error.possible_solutions = [ "Run 'cfy init -r' to force re-initialization " "(might overwrite existing " "configuration files if exist) " ] raise error else: shutil.rmtree(os.path.join( utils.get_cwd(), constants.CLOUDIFY_WD_SETTINGS_DIRECTORY_NAME)) settings = utils.CloudifyWorkingDirectorySettings() utils.dump_cloudify_working_dir_settings(settings) utils.dump_configuration_file() configure_loggers() if not skip_logging: get_logger().info('Initialization completed successfully')
def instances(node_id): logger = get_logger() env = _load_env() node_instances = env.storage.get_node_instances() if node_id: node_instances = [instance for instance in node_instances if instance.node_id == node_id] if not node_instances: raise exceptions.CloudifyCliError('No node with id: {0}' .format(node_id)) logger.info(json.dumps(node_instances, sort_keys=True, indent=2))
def _load_env(): if not os.path.isdir(_storage_dir()): error = exceptions.CloudifyCliError( '{0} has not been initialized with a blueprint.' .format(utils.get_cwd())) # init was probably not executed. # suggest solution. error.possible_solutions = [ "Run 'aria init' in this directory" ] raise error return local.load_env(name=_NAME, storage=_storage())
def create_requirements(blueprint_path, output): logger = get_logger() if output and os.path.exists(output): raise exceptions.CloudifyCliError('output path already exists : {0}' .format(output)) requirements = common.create_requirements( blueprint_path=blueprint_path ) if output: utils.dump_to_file(requirements, output) logger.info('Requirements created successfully --> {0}' .format(output)) else: # we don't want to use just lgr # since we want this output to be prefix free. # this will make it possible to pipe the # output directly to pip for requirement in requirements: print(requirement) logger.info(requirement)
def install_blueprint_plugins(blueprint_path): requirements = create_requirements(blueprint_path=blueprint_path) if requirements: # validate we are inside a virtual env if not utils.is_virtual_env(): raise exceptions.CloudifyCliError( 'You must be running inside a ' 'virtualenv to install blueprint plugins') runner = LocalCommandRunner(get_logger()) # dump the requirements to a file # and let pip install it. # this will utilize pip's mechanism # of cleanup in case an installation fails. tmp_path = tempfile.mkstemp(suffix='.txt', prefix='requirements_')[1] utils.dump_to_file(collection=requirements, file_path=tmp_path) runner.run(command='pip install -r {0}'.format(tmp_path), stdout_pipe=False) else: get_logger().debug('There are no plugins to install..')