def _service_start(json, package_name, package_version, options_path): """Starts a DC/OS service from a package that has been added :param json: wether to output json :type json: bool :param package_name: :type package_name: str :param package_version: :type package_version: None | str :param options_path: :type options_path: None | str :return: process status :rtype: int """ manager = servicemanager.ServiceManager() options = util.read_file_json(options_path) if options_path else None response = manager.start_service(package_name, package_version, options) response_json = response.json() if json: emitter.publish(response_json) else: message = ("The service [{}] version [{}] has been started".format( response_json['packageName'], response_json['packageVersion'])) emitter.publish(message) return 0
def _describe(package_name, app, cli, options_path, render, package_versions, package_version, config, app_id): """Describe the specified package. :param package_name: The package to describe :type package_name: str :param app: If True, marathon.json will be printed :type app: boolean :param cli: If True, command.json | resource.json's cli property should be printed :type cli: boolean :param options_path: Path to json file with options to override config.json defaults. :type options_path: str :param render: If True, marathon.json will be rendered :type render: boolean :param package_versions: If True, a list of all package versions will be printed :type package_versions: boolean :param package_version: package version :type package_version: str | None :param config: If True, config.json will be printed :type config: boolean :param app_id: app ID to specify which app to describe :type app_id: str | None :returns: Process status :rtype: int """ # If the user supplied template options, they definitely want to # render the template if options_path: render = 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) if package_versions: emitter.publish(pkg.package_versions()) elif cli or app or config: if cli: emitter.publish(pkg.cli_definition()) if app: if render: app_output = pkg.marathon_json(user_options, app_id) else: app_output = pkg.marathon_template().decode("UTF-8") if app_output and app_output[-1] == '\n': app_output = app_output[:-1] emitter.publish(app_output) if config: config_output = pkg.config_json() emitter.publish(config_output) else: emitter.publish(pkg.package_response()) return 0
def _service_start(json, package_name, package_version, options_path): """Starts a DC/OS service from a package that has been added :param json: wether to output json :type json: bool :param package_name: :type package_name: str :param package_version: :type package_version: None | str :param options_path: :type options_path: None | str :return: process status :rtype: int """ manager = servicemanager.ServiceManager() options = util.read_file_json(options_path) if options_path else None response = manager.start_service( package_name, package_version, options) response_json = response.json() if json: emitter.publish(response_json) else: message = ( "The service [{}] version [{}] has been started".format( response_json['packageName'], response_json['packageVersion'] )) emitter.publish(message) return 0
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 # 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() 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(): # 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) package_manager.install_app(pkg, user_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 _describe(package_name, app, cli, options_path, render, package_versions, package_version, config): """Describe the specified package. :param package_name: The package to describe :type package_name: str :param app: If True, marathon.json will be printed :type app: boolean :param cli: If True, command.json | resource.json's cli property should be printed :type cli: boolean :param options_path: Path to json file with options to override config.json defaults. :type options_path: str :param render: If True, marathon.json will be rendered :type render: boolean :param package_versions: If True, a list of all package versions will be printed :type package_versions: boolean :param package_version: package version :type package_version: str | None :param config: If True, config.json will be printed :type config: boolean :returns: Process status :rtype: int """ # If the user supplied template options, they definitely want to # render the template if options_path: render = 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() if package_versions: emitter.publish(pkg.package_versions()) elif cli or app or config: if cli: emitter.publish(pkg.cli_definition()) if app: if render: app_output = pkg.marathon_json(user_options) else: app_output = pkg.marathon_template() if app_output and app_output[-1] == '\n': app_output = app_output[:-1] emitter.publish(app_output) if config: config_output = pkg.config_json() emitter.publish(config_output) else: emitter.publish(pkg_json) return 0