Exemplo n.º 1
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
        adapter = self.context['api_adapter']
        location_get = self.context['location_get']
        location = location_get(args)

        self._upgrade_hint = None
        vv = VersionVerifier()
        c = adapter.GetCluster(adapter.ParseCluster(args.name, location))
        ver_status = vv.Compare(c.currentMasterVersion, c.currentNodeVersion)

        if ver_status == VersionVerifier.UPGRADE_AVAILABLE:
            self._upgrade_hint = UpgradeHelpText.UPGRADE_AVAILABLE
        elif ver_status == VersionVerifier.SUPPORT_ENDING:
            self._upgrade_hint = UpgradeHelpText.SUPPORT_ENDING
        elif ver_status == VersionVerifier.UNSUPPORTED:
            self._upgrade_hint = UpgradeHelpText.UNSUPPORTED

        if ver_status != VersionVerifier.UP_TO_DATE:
            self._upgrade_hint += UpgradeHelpText.UPGRADE_COMMAND.format(
                name=c.name)

        return c
Exemplo n.º 2
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
        adapter = self.context['api_adapter']

        project = properties.VALUES.core.project.Get(required=True)
        zone = None
        if args.zone:
            zone = adapter.registry.Parse(args.zone,
                                          collection='compute.zones').zone

        def sort_key(cluster):
            return (cluster.zone, cluster.name)

        try:
            clusters = adapter.ListClusters(project, zone)
            clusters.clusters = sorted(clusters.clusters, key=sort_key)

            if clusters.missingZones:
                log.warning(
                    'The following zones did not respond: {0}. List results may be '
                    'incomplete.'.format(', '.join(clusters.missingZones)))

            upgrade_available = False
            support_ending = False
            unsupported = False
            self._upgrade_hint = ''
            vv = VersionVerifier()
            for c in clusters.clusters:
                ver_status = vv.Compare(c.currentMasterVersion,
                                        c.currentNodeVersion)
                if ver_status == VersionVerifier.UPGRADE_AVAILABLE:
                    c.currentNodeVersion += ' *'
                    upgrade_available = True
                elif ver_status == VersionVerifier.SUPPORT_ENDING:
                    c.currentNodeVersion += ' **'
                    support_ending = True
                elif ver_status == VersionVerifier.UNSUPPORTED:
                    c.currentNodeVersion += ' ***'
                    unsupported = True

            if upgrade_available:
                self._upgrade_hint += UpgradeHelpText.UPGRADE_AVAILABLE
            if support_ending:
                self._upgrade_hint += UpgradeHelpText.SUPPORT_ENDING
            if unsupported:
                self._upgrade_hint += UpgradeHelpText.UNSUPPORTED
            if self._upgrade_hint:
                self._upgrade_hint += UpgradeHelpText.UPGRADE_COMMAND.format(
                    name='NAME')
            return clusters.clusters
        except apitools_exceptions.HttpError as error:
            raise exceptions.HttpException(util.GetError(error))
Exemplo n.º 3
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
        adapter = self.context['api_adapter']
        location_get = self.context['location_get']
        location = location_get(args)

        if getattr(args, 'region', None):
            message = messages.NonGAFeatureUsingV1APIWarning(
                self._release_track)
            if message:
                console_io.PromptContinue(message=message, cancel_on_no=True)

        self._upgrade_hint = None
        vv = VersionVerifier()
        c = adapter.GetCluster(adapter.ParseCluster(args.name, location))
        ver_status = vv.Compare(c.currentMasterVersion, c.currentNodeVersion)

        if ver_status == VersionVerifier.UPGRADE_AVAILABLE:
            self._upgrade_hint = UpgradeHelpText.UPGRADE_AVAILABLE
        elif ver_status == VersionVerifier.SUPPORT_ENDING:
            self._upgrade_hint = UpgradeHelpText.SUPPORT_ENDING
        elif ver_status == VersionVerifier.UNSUPPORTED:
            self._upgrade_hint = UpgradeHelpText.UNSUPPORTED

        if ver_status != VersionVerifier.UP_TO_DATE:
            self._upgrade_hint += UpgradeHelpText.UPGRADE_COMMAND.format(
                name=c.name)

        return c
Exemplo n.º 4
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
        adapter = self.context['api_adapter']
        location_get = self.context['location_get']
        location = location_get(args, ignore_property=True, required=False)
        project = properties.VALUES.core.project.Get(required=True)

        def sort_key(cluster):
            return (cluster.zone, cluster.name)

        try:
            clusters = adapter.ListClusters(project, location)
            clusters.clusters = sorted(clusters.clusters, key=sort_key)

            if clusters.missingZones:
                log.warning(
                    'The following zones did not respond: {0}. List results may be '
                    'incomplete.'.format(', '.join(clusters.missingZones)))

            upgrade_available = False
            support_ending = False
            unsupported = False
            expiring = False
            self._upgrade_hint = ''
            self._expire_warning = ''
            self._degraded_warning = ''
            vv = VersionVerifier()
            for c in clusters.clusters:
                time_left = transforms.ParseExpireTime(c.expireTime)
                if time_left and time_left.days < constants.EXPIRE_WARNING_DAYS:
                    expiring = True
                if adapter.IsDegraded(c):
                    self._degraded_warning += constants.DEGRADED_WARNING.format(
                        cluster_name=c.name,
                        cluster_degraded_warning=adapter.GetDegradedWarning(c))
                if c.enableKubernetesAlpha:
                    # Don't print upgrade hints for alpha clusters, they aren't
                    # upgradeable.
                    continue
                ver_status = vv.Compare(c.currentMasterVersion,
                                        c.currentNodeVersion)
                if ver_status == VersionVerifier.UPGRADE_AVAILABLE:
                    c.currentNodeVersion += ' *'

                    upgrade_available = True
                elif ver_status == VersionVerifier.SUPPORT_ENDING:
                    c.currentNodeVersion += ' **'
                    support_ending = True
                elif ver_status == VersionVerifier.UNSUPPORTED:
                    c.currentNodeVersion += ' ***'
                    unsupported = True

            if upgrade_available:
                self._upgrade_hint += UpgradeHelpText.UPGRADE_AVAILABLE
            if support_ending:
                self._upgrade_hint += UpgradeHelpText.SUPPORT_ENDING
            if unsupported:
                self._upgrade_hint += UpgradeHelpText.UNSUPPORTED
            if self._upgrade_hint:
                self._upgrade_hint += UpgradeHelpText.UPGRADE_COMMAND.format(
                    name='NAME')
            if expiring:
                self._expire_warning = constants.EXPIRE_WARNING

            return clusters.clusters
        except apitools_exceptions.HttpError as error:
            raise exceptions.HttpException(error, util.HTTP_ERROR_FORMAT)