def _install(package_name, package_version, options_path, app_id, cli, global_, app, yes): """Install the specified package. :param package_name: the package to install :type package_name: str :param package_version: package version to install :type package_version: str :param options_path: path to file containing option values :type options_path: str :param app_id: app ID for installation of this package :type app_id: str :param cli: indicates if the cli should be installed :type cli: bool :param global_: indicates that the cli should be installed globally :type global_: bool :param app: indicate if the application should be installed :type app: bool :param yes: automatically assume yes to all prompts :type yes: bool :returns: process status :rtype: int """ if cli is False and app is False: # Install both if neither flag is specified cli = app = True # Fail early if options file isn't valid user_options = util.read_file_json(options_path) package_manager = get_package_manager() pkg = package_manager.get_package_version(package_name, package_version) pkg_json = pkg.package_json() selected = pkg_json.get('selected') if selected: link = ('https://mesosphere.com/' 'catalog-terms-conditions/#certified-services') else: link = ('https://mesosphere.com/' 'catalog-terms-conditions/#community-services') emitter.publish(('By Deploying, you agree to ' 'the Terms and Conditions ' + link)) pre_install_notes = pkg_json.get('preInstallNotes') if app and pre_install_notes: emitter.publish(pre_install_notes) if not confirm('Continue installing?', yes): emitter.publish('Exiting installation.') return 0 if app and pkg.marathon_template(): # Even though package installation will check for template rendering # errors, we want to fail early, before trying to install. pkg.options(user_options) # Install in Marathon msg = 'Installing Marathon app for package [{}] version [{}]'.format( pkg.name(), pkg.version()) if app_id is not None: msg += ' with app id [{}]'.format(app_id) emitter.publish(msg) if app_id is not None: msg = "Usage of --app-id is deprecated. Use --options instead " \ "and specify a file that contains [service.name] property" emitter.publish(msg) package_manager.install_app(pkg, user_options, app_id) if cli and pkg.cli_definition(): # Install subcommand msg = 'Installing CLI subcommand for package [{}] version [{}]'.format( pkg.name(), pkg.version()) emitter.publish(msg) subcommand.install(pkg, global_) subcommand_paths = subcommand.get_package_commands(package_name) new_commands = [ os.path.basename(p).replace('-', ' ', 1) for p in subcommand_paths ] if new_commands: commands = ', '.join(new_commands) plural = "s" if len(new_commands) > 1 else "" emitter.publish("New command{} available: {}".format( plural, commands)) post_install_notes = pkg_json.get('postInstallNotes') if app and post_install_notes: emitter.publish(post_install_notes) return 0
def _install(package_name, package_version, options_path, app_id, cli, app, yes): """Install the specified package. :param package_name: the package to install :type package_name: str :param package_version: package version to install :type package_version: str :param options_path: path to file containing option values :type options_path: str :param app_id: app ID for installation of this package :type app_id: str :param cli: indicates if the cli should be installed :type cli: bool :param app: indicate if the application should be installed :type app: bool :param yes: automatically assume yes to all prompts :type yes: bool :returns: process status :rtype: int """ if cli is False and app is False: # Install both if neither flag is specified cli = app = True # Expand ~ in the options file path if options_path: options_path = os.path.expanduser(options_path) user_options = _user_options(options_path) package_manager = _get_package_manager() pkg = package_manager.get_package_version(package_name, package_version) pkg_json = pkg.package_json() pre_install_notes = pkg_json.get('preInstallNotes') if app and pre_install_notes: emitter.publish(pre_install_notes) if not _confirm('Continue installing?', yes): emitter.publish('Exiting installation.') return 0 # render options before start installation options = pkg.options(user_options) if app and pkg.has_mustache_definition(): # Install in Marathon msg = 'Installing Marathon app for package [{}] version [{}]'.format( pkg.name(), pkg.version()) if app_id is not None: msg += ' with app id [{}]'.format(app_id) emitter.publish(msg) package_manager.install_app(pkg, options, app_id) if cli and pkg.has_command_definition(): # Install subcommand msg = 'Installing CLI subcommand for package [{}] version [{}]'.format( pkg.name(), pkg.version()) emitter.publish(msg) subcommand.install(pkg, pkg.options(user_options)) subcommand_paths = subcommand.get_package_commands(package_name) new_commands = [ os.path.basename(p).replace('-', ' ', 1) for p in subcommand_paths ] if new_commands: commands = ', '.join(new_commands) plural = "s" if len(new_commands) > 1 else "" emitter.publish("New command{} available: {}".format( plural, commands)) post_install_notes = pkg_json.get('postInstallNotes') if app and post_install_notes: emitter.publish(post_install_notes) return 0
def _install(package_name, package_version, options_path, app_id, cli, app, yes): """Install the specified package. :param package_name: the package to install :type package_name: str :param package_version: package version to install :type package_version: str :param options_path: path to file containing option values :type options_path: str :param app_id: app ID for installation of this package :type app_id: str :param cli: indicates if the cli should be installed :type cli: bool :param app: indicate if the application should be installed :type app: bool :param yes: automatically assume yes to all prompts :type yes: bool :returns: process status :rtype: int """ if cli is False and app is False: # Install both if neither flag is specified cli = app = True # Expand ~ in the options file path if options_path: options_path = os.path.expanduser(options_path) user_options = _user_options(options_path) package_manager = _get_package_manager() pkg = package_manager.get_package_version(package_name, package_version) pkg_json = pkg.package_json() pre_install_notes = pkg_json.get('preInstallNotes') if app and pre_install_notes: emitter.publish(pre_install_notes) if not _confirm('Continue installing?', yes): emitter.publish('Exiting installation.') return 0 if app and pkg.has_mustache_definition(): # render options before start installation options = pkg.options(user_options) # Install in Marathon msg = 'Installing Marathon app for package [{}] version [{}]'.format( pkg.name(), pkg.version()) if app_id is not None: msg += ' with app id [{}]'.format(app_id) emitter.publish(msg) package_manager.install_app( pkg, options, app_id) if cli and pkg.has_cli_definition(): # Install subcommand msg = 'Installing CLI subcommand for package [{}] version [{}]'.format( pkg.name(), pkg.version()) emitter.publish(msg) subcommand.install(pkg) subcommand_paths = subcommand.get_package_commands(package_name) new_commands = [os.path.basename(p).replace('-', ' ', 1) for p in subcommand_paths] if new_commands: commands = ', '.join(new_commands) plural = "s" if len(new_commands) > 1 else "" emitter.publish("New command{} available: {}".format(plural, commands)) post_install_notes = pkg_json.get('postInstallNotes') if app and post_install_notes: emitter.publish(post_install_notes) return 0
def _install(package_name, package_version, options_path, app_id, cli, app, yes): """Install the specified package. :param package_name: the package to install :type package_name: str :param package_version: package version to install :type package_version: str :param options_path: path to file containing option values :type options_path: str :param app_id: app ID for installation of this package :type app_id: str :param cli: indicates if the cli should be installed :type cli: bool :param app: indicate if the application should be installed :type app: bool :param yes: automatically assume yes to all prompts :type yes: bool :returns: process status :rtype: int """ if cli is False and app is False: # Install both if neither flag is specified cli = app = True config = util.get_config() pkg = package.resolve_package(package_name, config) if pkg is None: msg = "Package [{}] not found\n".format(package_name) + \ "You may need to run 'dcos package update' to update your " + \ "repositories" raise DCOSException(msg) pkg_revision = pkg.latest_package_revision(package_version) if pkg_revision is None: if package_version is not None: msg = "Version {} of package [{}] is not available".format( package_version, package_name) else: msg = "Package [{}] not available".format(package_name) raise DCOSException(msg) user_options = _user_options(options_path) pkg_json = pkg.package_json(pkg_revision) pre_install_notes = pkg_json.get('preInstallNotes') if pre_install_notes: emitter.publish(pre_install_notes) if not _confirm('Continue installing?', yes): emitter.publish('Exiting installation.') return 0 options = pkg.options(pkg_revision, user_options) revision_map = pkg.package_revisions_map() package_version = revision_map.get(pkg_revision) if app and pkg.has_marathon_definition(pkg_revision): # Install in Marathon msg = 'Installing Marathon app for package [{}] version [{}]'.format( pkg.name(), package_version) if app_id is not None: msg += ' with app id [{}]'.format(app_id) emitter.publish(msg) init_client = marathon.create_client(config) package.install_app( pkg, pkg_revision, init_client, options, app_id) if cli and pkg.has_command_definition(pkg_revision): # Install subcommand msg = 'Installing CLI subcommand for package [{}] version [{}]'.format( pkg.name(), package_version) emitter.publish(msg) subcommand.install(pkg, pkg_revision, options) subcommand_paths = subcommand.get_package_commands(package_name) new_commands = [os.path.basename(p).replace('-', ' ', 1) for p in subcommand_paths] if new_commands: commands = ', '.join(new_commands) plural = "s" if len(new_commands) > 1 else "" emitter.publish("New command{} available: {}".format(plural, commands)) post_install_notes = pkg_json.get('postInstallNotes') if post_install_notes: emitter.publish(post_install_notes) return 0
def _install(package_name, package_version, options_path, app_id, cli, app, yes): """Install the specified package. :param package_name: the package to install :type package_name: str :param package_version: package version to install :type package_version: str :param options_path: path to file containing option values :type options_path: str :param app_id: app ID for installation of this package :type app_id: str :param cli: indicates if the cli should be installed :type cli: bool :param app: indicate if the application should be installed :type app: bool :param yes: automatically assume yes to all prompts :type yes: bool :returns: process status :rtype: int """ if cli is False and app is False: # Install both if neither flag is specified cli = app = True config = util.get_config() pkg = package.resolve_package(package_name, config) if pkg is None: msg = "Package [{}] not found\n".format(package_name) + \ "You may need to run 'dcos package update' to update your " + \ "repositories" raise DCOSException(msg) pkg_revision = pkg.latest_package_revision(package_version) if pkg_revision is None: if package_version is not None: msg = "Version {} of package [{}] is not available".format( package_version, package_name) else: msg = "Package [{}] not available".format(package_name) raise DCOSException(msg) user_options = _user_options(options_path) pkg_json = pkg.package_json(pkg_revision) pre_install_notes = pkg_json.get('preInstallNotes') if pre_install_notes: emitter.publish(pre_install_notes) if not _confirm('Continue installing?', yes): emitter.publish('Exiting installation.') return 0 options = pkg.options(pkg_revision, user_options) revision_map = pkg.package_revisions_map() package_version = revision_map.get(pkg_revision) if app and (pkg.has_marathon_definition(pkg_revision) or pkg.has_marathon_mustache_definition(pkg_revision)): # Install in Marathon msg = 'Installing Marathon app for package [{}] version [{}]'.format( pkg.name(), package_version) if app_id is not None: msg += ' with app id [{}]'.format(app_id) emitter.publish(msg) init_client = marathon.create_client(config) package.install_app(pkg, pkg_revision, init_client, options, app_id) if cli and pkg.has_command_definition(pkg_revision): # Install subcommand msg = 'Installing CLI subcommand for package [{}] version [{}]'.format( pkg.name(), package_version) emitter.publish(msg) subcommand.install(pkg, pkg_revision, options) subcommand_paths = subcommand.get_package_commands(package_name) new_commands = [ os.path.basename(p).replace('-', ' ', 1) for p in subcommand_paths ] if new_commands: commands = ', '.join(new_commands) plural = "s" if len(new_commands) > 1 else "" emitter.publish("New command{} available: {}".format( plural, commands)) post_install_notes = pkg_json.get('postInstallNotes') if post_install_notes: emitter.publish(post_install_notes) return 0