Esempio n. 1
0
def uninstall_package(package_name,
                      app_id=None,
                      all_instances=False,
                      wait_for_completion=False,
                      timeout_sec=600):
    """ Uninstall a package using the DC/OS library.

        :param package_name: name of the package
        :type package_name: str
        :param app_id: unique app_id for the package
        :type app_id: str
        :param all_instances: uninstall all instances of package
        :type all_instances: bool
        :param wait_for_completion: whether or not to wait for task completion before returning
        :type wait_for_completion: bool
        :param timeout_sec: number of seconds to wait for task completion
        :type timeout_sec: int

        :return: True if uninstall was successful, False otherwise
        :rtype: bool
    """

    print("\n{}uninstalling package '{}'\n".format(
        shakedown.cli.helpers.fchr('>>'), package_name))

    cosmos = _get_cosmos()
    pkg = cosmos.get_package_version(package_name, None)

    # Uninstall subcommands (if defined)
    if pkg.has_cli_definition():
        print("\n{}uninstalling CLI commands for package '{}'\n".format(
            shakedown.cli.helpers.fchr('>>'), package_name))
        subcommand.uninstall(package_name)

    cosmos.uninstall_app(package_name, all_instances, app_id)

    # Optionally wait for the service to unregister as a framework
    if wait_for_completion:
        now = time.time()
        future = now + timeout_sec

        while now < future:
            if not shakedown.get_service(package_name):
                return True

            time.sleep(1)
            now = time.time()

        return False

    return True
Esempio n. 2
0
def uninstall_package(
        package_name,
        service_name=None,
        all_instances=False,
        wait_for_completion=False,
        timeout_sec=600
):
    """ Uninstall a package using the DC/OS library.

        :param package_name: name of the package
        :type package_name: str
        :param service_name: unique service name for the package
        :type service_name: str
        :param all_instances: uninstall all instances of package
        :type all_instances: bool
        :param wait_for_completion: whether or not to wait for task completion before returning
        :type wait_for_completion: bool
        :param timeout_sec: number of seconds to wait for task completion
        :type timeout_sec: int

        :return: True if uninstall was successful, False otherwise
        :rtype: bool
    """

    package_manager = _get_package_manager()
    pkg = package_manager.get_package_version(package_name, None)

    try:
        if service_name is None:
            service_name = _get_service_name(package_name, pkg)

        print("{}uninstalling package '{}' with service name '{}'\n".format(
            shakedown.cli.helpers.fchr('>>'), package_name, service_name))

        package_manager.uninstall_app(package_name, all_instances, service_name)

        # Optionally wait for the service to unregister as a framework
        if wait_for_completion:
            wait_for_mesos_task_removal(service_name, timeout_sec=timeout_sec)
    except errors.DCOSException as e:
        print('\n{}{}'.format(
            shakedown.cli.helpers.fchr('>>'), e))

    # Uninstall subcommands (if defined)
    if pkg.cli_definition():
        print("{}uninstalling CLI commands for package '{}'".format(
            shakedown.cli.helpers.fchr('>>'), package_name))
        subcommand.uninstall(package_name)

    return True
Esempio n. 3
0
def uninstall_package(
        package_name,
        service_name=None,
        all_instances=False,
        wait_for_completion=False,
        timeout_sec=600
):
    """ Uninstall a package using the DC/OS library.

        :param package_name: name of the package
        :type package_name: str
        :param service_name: unique service name for the package
        :type service_name: str
        :param all_instances: uninstall all instances of package
        :type all_instances: bool
        :param wait_for_completion: whether or not to wait for task completion before returning
        :type wait_for_completion: bool
        :param timeout_sec: number of seconds to wait for task completion
        :type timeout_sec: int

        :return: True if uninstall was successful, False otherwise
        :rtype: bool
    """

    package_manager = _get_package_manager()
    pkg = package_manager.get_package_version(package_name, None)

    try:
        if service_name is None:
            service_name = _get_service_name(package_name, pkg)

        print("{}uninstalling package '{}' with service name '{}'\n".format(
            shakedown.cli.helpers.fchr('>>'), package_name, service_name))

        package_manager.uninstall_app(package_name, all_instances, service_name)

        # Optionally wait for the service to unregister as a framework
        if wait_for_completion:
            wait_for_mesos_task_removal(service_name, timeout_sec=timeout_sec)
    except errors.DCOSException as e:
        print('\n{}{}'.format(
            shakedown.cli.helpers.fchr('>>'), e))

    # Uninstall subcommands (if defined)
    if pkg.cli_definition():
        print("{}uninstalling CLI commands for package '{}'".format(
            shakedown.cli.helpers.fchr('>>'), package_name))
        subcommand.uninstall(package_name)

    return True
Esempio n. 4
0
def uninstall_subcommand(distribution_name):
    """Uninstalls a subcommand.

    :param distribution_name: the name of the package
    :type distribution_name: str
    :returns: True if the subcommand was uninstalled
    :rtype: bool
    """

    return subcommand.uninstall(distribution_name)
Esempio n. 5
0
def uninstall_subcommand(distribution_name):
    """Uninstalls a subcommand.

    :param distribution_name: the name of the package
    :type distribution_name: str
    :returns: True if the subcommand was uninstalled
    :rtype: bool
    """

    return subcommand.uninstall(distribution_name)
Esempio n. 6
0
def uninstall(pkg, package_name, remove_all, app_id, cli, app):
    """Uninstalls a package.

    :param pkg: package manager to uninstall with
    :type pkg: PackageManager
    :param package_name: The package to uninstall
    :type package_name: str
    :param remove_all: Whether to remove all instances of the named app
    :type remove_all: boolean
    :param app_id: App ID of the app instance to uninstall
    :type app_id: str
    :param init_client: The program to use to run the app
    :type init_client: object
    :rtype: None
    """

    if cli is False and app is False:
        cli = app = True

    uninstalled = False
    installed = installed_packages(pkg, app_id, package_name)
    installed_cli = next(
        (True for installed_pkg in installed if installed_pkg.get("command")),
        False)
    installed_app = next(
        (True for installed_pkg in installed if installed_pkg.get("apps")),
        False)

    if cli and installed_cli:
        if subcommand.uninstall(package_name):
            uninstalled = True

    if app and installed_app:
        if pkg.uninstall_app(package_name, remove_all, app_id):
            uninstalled = True

    if uninstalled:
        return None
    else:
        msg = 'Package [{}]'.format(package_name)
        if app_id is not None:
            app_id = util.normalize_marathon_id_path(app_id)
            msg += " with id [{}]".format(app_id)
        msg += " is not installed"
        raise DCOSException(msg)
Esempio n. 7
0
def uninstall(pkg, package_name, remove_all, app_id, cli, app):
    """Uninstalls a package.

    :param pkg: package manager to uninstall with
    :type pkg: PackageManager
    :param package_name: The package to uninstall
    :type package_name: str
    :param remove_all: Whether to remove all instances of the named app
    :type remove_all: boolean
    :param app_id: App ID of the app instance to uninstall
    :type app_id: str
    :param init_client: The program to use to run the app
    :type init_client: object
    :rtype: None
    """

    if cli is False and app is False:
        cli = app = True

    uninstalled = False
    installed = installed_packages(
        pkg, app_id, package_name, cli_only=False)
    installed_cli = next((True for installed_pkg in installed
                          if installed_pkg.get("command")), False)
    installed_app = next((True for installed_pkg in installed
                          if installed_pkg.get("apps")), False)

    if cli and installed_cli:
        if subcommand.uninstall(package_name):
            uninstalled = True

    if app and installed_app:
        if pkg.uninstall_app(package_name, remove_all, app_id):
            uninstalled = True

    if uninstalled:
        return None
    else:
        msg = 'Package [{}]'.format(package_name)
        if app_id is not None:
            app_id = util.normalize_marathon_id_path(app_id)
            msg += " with id [{}]".format(app_id)
        msg += " is not installed"
        raise DCOSException(msg)
Esempio n. 8
0
def uninstall(package_name, remove_all, app_id, cli, app):
    """Uninstalls a package.

    :param package_name: The package to uninstall
    :type package_name: str
    :param remove_all: Whether to remove all instances of the named app
    :type remove_all: boolean
    :param app_id: App ID of the app instance to uninstall
    :type app_id: str
    :param init_client: The program to use to run the app
    :type init_client: object
    :rtype: None
    """

    if cli is False and app is False:
        cli = app = True

    uninstalled = False
    if cli:
        if subcommand.uninstall(package_name):
            uninstalled = True

    if app:
        num_apps = uninstall_app(
            package_name,
            remove_all,
            app_id,
            marathon.create_client(),
            mesos.DCOSClient())

        if num_apps > 0:
            uninstalled = True

    if uninstalled:
        return None
    else:
        msg = 'Package [{}]'.format(package_name)
        if app_id is not None:
            msg += " with id [{}]".format(app_id)
        msg += " is not installed."
        raise DCOSException(msg)
Esempio n. 9
0
def uninstall(package_name, remove_all, app_id, cli, app):
    """Uninstalls a package.

    :param package_name: The package to uninstall
    :type package_name: str
    :param remove_all: Whether to remove all instances of the named app
    :type remove_all: boolean
    :param app_id: App ID of the app instance to uninstall
    :type app_id: str
    :param init_client: The program to use to run the app
    :type init_client: object
    :rtype: None
    """

    if cli is False and app is False:
        cli = app = True

    uninstalled = False
    if cli:
        if subcommand.uninstall(package_name):
            uninstalled = True

    if app:
        num_apps = uninstall_app(
            package_name,
            remove_all,
            app_id,
            marathon.create_client(),
            mesos.DCOSClient())

        if num_apps > 0:
            uninstalled = True

    if uninstalled:
        return None
    else:
        msg = 'Package [{}]'.format(package_name)
        if app_id is not None:
            msg += " with id [{}]".format(app_id)
        msg += " is not installed."
        raise DCOSException(msg)
Esempio n. 10
0
def uninstall(pkg, package_name, remove_all, app_id, cli, app):
    """Uninstalls a package.

    :param pkg: package manager to uninstall with
    :type pkg: PackageManager
    :param package_name: The package to uninstall
    :type package_name: str
    :param remove_all: Whether to remove all instances of the named app
    :type remove_all: boolean
    :param app_id: App ID of the app instance to uninstall
    :type app_id: str
    :param cli: Whether to remove the CLI only
    :type cli: boolean
    :param app: Whether to remove app only
    :type app: boolean
    :rtype: None
    """

    installed = installed_packages(pkg, None, package_name, cli_only=False)
    installed_pkg = next(iter(installed), None)

    if installed_pkg:
        installed_cli = installed_pkg.get("command")
        installed_app = installed_pkg.get("apps") or []
    else:
        msg = 'Package [{}]'.format(package_name)
        if app_id is not None:
            app_id = util.normalize_marathon_id_path(app_id)
            msg += " with id [{}]".format(app_id)
        msg += " is not installed"
        raise DCOSException(msg)

    # Having `app == True` means that the user supplied an explicit `--app`
    # flag on the command line. Having `cli == True` means that the user
    # supplied an explicit `--cli` flag on the command line. If either of these
    # is `True`, run the following.
    if app or cli:
        # This forces an unconditional uninstall of the app associated with the
        # supplied package (with different semantics depending on the values of
        # `remove_all` and `app_id` as described in the docstring for this
        # function).
        if app and installed_app:
            if not pkg.uninstall_app(package_name, remove_all, app_id):
                raise DCOSException("Couldn't uninstall package")

        # This forces an unconditional uninstall of the CLI associated with the
        # supplied package.
        if cli and installed_cli:
            if not subcommand.uninstall(package_name):
                raise DCOSException("Couldn't uninstall subcommand")

        return

    # Having both `app == False` and `cli == False` means that the user didn't
    # supply either `--app` or `--cli` on the command line. In this situation
    # we uninstall the app associated with the supplied package (if it exists)
    # just as if the user had explicitly passed `--app` on the command line.
    # However, we only uninstall the CLI associated with the package if the app
    # being uninstalled is the last one remaining on the system.  Otherwise, we
    # leave the CLI in place so other instances of the app can continue to
    # interact with it.
    if installed_app:
        if not pkg.uninstall_app(package_name, remove_all, app_id):
            raise DCOSException("Couldn't uninstall package")

    if installed_cli and (remove_all or len(installed_app) <= 1):
        if not subcommand.uninstall(package_name):
            raise DCOSException("Couldn't uninstall subcommand")