Example #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)
        cluster_ref = adapter.ParseCluster(args.name, location)
        concurrent_node_count = getattr(args, 'concurrent_node_count', None)

        try:
            cluster = adapter.GetCluster(cluster_ref)
        except (exceptions.HttpException,
                apitools_exceptions.HttpForbiddenError, util.Error) as error:
            log.warning(
                ('Problem loading details of cluster to upgrade:\n\n{}\n\n' +
                 'You can still attempt to upgrade the cluster.\n').format(
                     console_attr.SafeText(error)))
            cluster = None

        upgrade_message = container_command_util.ClusterUpgradeMessage(
            name=args.name,
            cluster=cluster,
            master=args.master,
            node_pool_name=args.node_pool,
            new_version=args.cluster_version,
            concurrent_node_count=concurrent_node_count)

        console_io.PromptContinue(message=upgrade_message,
                                  throw_if_unattended=True,
                                  cancel_on_no=True)

        options = api_adapter.UpdateClusterOptions(
            version=args.cluster_version,
            update_master=args.master,
            update_nodes=(not args.master),
            node_pool=args.node_pool,
            image_type=args.image_type,
            image=args.image,
            image_project=args.image_project,
            concurrent_node_count=concurrent_node_count)

        try:
            op_ref = adapter.UpdateCluster(cluster_ref, options)
        except apitools_exceptions.HttpError as error:
            raise exceptions.HttpException(error, util.HTTP_ERROR_FORMAT)

        if not args. async:
            adapter.WaitForOperation(
                op_ref, 'Upgrading {0}'.format(cluster_ref.clusterId))

            log.UpdatedResource(cluster_ref)
Example #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']
        location_get = self.context['location_get']
        location = location_get(args)
        cluster_ref = adapter.ParseCluster(args.name, location)
        concurrent_node_count = getattr(args, 'concurrent_node_count', None)

        # Make sure it exists (will raise appropriate error if not)
        cluster = adapter.GetCluster(cluster_ref)

        options = api_adapter.UpdateClusterOptions(
            version=args.cluster_version,
            update_master=args.master,
            update_nodes=(not args.master),
            node_pool=args.node_pool,
            image_type=args.image_type,
            image=args.image,
            image_project=args.image_project,
            concurrent_node_count=concurrent_node_count)

        upgrade_message = container_command_util.ClusterUpgradeMessage(
            cluster,
            master=args.master,
            node_pool=args.node_pool,
            new_version=options.version,
            concurrent_node_count=concurrent_node_count)

        console_io.PromptContinue(message=upgrade_message,
                                  throw_if_unattended=True,
                                  cancel_on_no=True)

        try:
            op_ref = adapter.UpdateCluster(cluster_ref, options)
        except apitools_exceptions.HttpError as error:
            raise exceptions.HttpException(error, util.HTTP_ERROR_FORMAT)

        if not args. async:
            adapter.WaitForOperation(
                op_ref, 'Upgrading {0}'.format(cluster_ref.clusterId))

            log.UpdatedResource(cluster_ref)
Example #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)
        cluster_ref = adapter.ParseCluster(args.name, location)
        project_id = properties.VALUES.core.project.Get(required=True)

        try:
            cluster = adapter.GetCluster(cluster_ref)
            MaybeLogDataplaneV2ScaleWarning(cluster)
        except (exceptions.HttpException,
                apitools_exceptions.HttpForbiddenError, util.Error) as error:
            log.warning(
                ('Problem loading details of cluster to upgrade:\n\n{}\n\n'
                 'You can still attempt to upgrade the cluster.\n').format(
                     console_attr.SafeText(error)))
            cluster = None

        try:
            server_conf = adapter.GetServerConfig(project_id, location)
        except (exceptions.HttpException,
                apitools_exceptions.HttpForbiddenError, util.Error) as error:
            log.warning(
                ('Problem loading server config:\n\n{}\n\n'
                 'You can still attempt to upgrade the cluster.\n').format(
                     console_attr.SafeText(error)))
            server_conf = None

        upgrade_message = container_command_util.ClusterUpgradeMessage(
            name=args.name,
            server_conf=server_conf,
            cluster=cluster,
            master=args.master,
            node_pool_name=args.node_pool,
            new_version=args.cluster_version,
            new_image_type=args.image_type)

        if args.master:
            MaybeLog122UpgradeWarning(cluster)

        console_io.PromptContinue(message=upgrade_message,
                                  throw_if_unattended=True,
                                  cancel_on_no=True)

        options = self.ParseUpgradeOptions(args)

        try:
            op_ref = adapter.UpdateCluster(cluster_ref, options)
        except apitools_exceptions.HttpError as error:
            raise exceptions.HttpException(error, util.HTTP_ERROR_FORMAT)

        if not args.async_:
            adapter.WaitForOperation(op_ref,
                                     'Upgrading {0}'.format(
                                         cluster_ref.clusterId),
                                     timeout_s=args.timeout)

            log.UpdatedResource(cluster_ref)