Ejemplo n.º 1
0
def AddScopesFlag(parser, example_target, is_deprecated):
  min_args_length = 1 if is_deprecated else 0
  default = [] if is_deprecated else ['logging-write', 'monitoring']
  parser.add_argument(
      '--scopes',
      type=arg_parsers.ArgList(min_length=min_args_length),
      metavar='SCOPE',
      default=default,
      help="""\
Specifies scopes for the node instances. The project's default
service account is used. Examples:

  $ {{command}} {example_target} --scopes https://www.googleapis.com/auth/devstorage.read_only

  $ {{command}} {example_target} --scopes bigquery,storage-rw,compute-ro

Multiple SCOPEs can specified, separated by commas. The scopes
necessary for the cluster to function properly (compute-rw, storage-ro),
are always added, even if not explicitly specified.

SCOPE can be either the full URI of the scope or an alias.
Available aliases are:

[format="csv",options="header"]
|========
Alias,URI
{aliases}
|========

{scope_deprecation_msg}
""".format(
    aliases=compute_constants.ScopesForHelp(),
    scope_deprecation_msg=compute_constants.DEPRECATED_SCOPES_MESSAGES,
    example_target=example_target))
Ejemplo n.º 2
0
def _Args(parser):
    """Register flags for this command.

  Args:
    parser: An argparse.ArgumentParser-like object. It is mocked out in order
        to capture some information, but behaves like an ArgumentParser.
  """
    parser.add_argument('name', help='The name of this cluster.')
    # Timeout in seconds for operation
    parser.add_argument('--timeout',
                        type=int,
                        default=1800,
                        help=argparse.SUPPRESS)
    flags.AddClustersWaitAndAsyncFlags(parser)
    parser.add_argument(
        '--num-nodes',
        type=arg_parsers.BoundedInt(1),
        help=
        'The number of nodes to be created in each of the cluster\'s zones.',
        default=3)
    parser.add_argument('--additional-zones',
                        type=arg_parsers.ArgList(min_length=1),
                        metavar='ZONE',
                        help="""\
The set of additional zones in which the specified node footprint should be
replicated. All zones must be in the same region as the cluster's primary zone.
If additional-zones is not specified, all nodes will be in the cluster's primary
zone.

Note that `NUM_NODES` nodes will be created in each zone, such that if you
specify `--num-nodes=4` and choose one additional zone, 8 nodes will be created.

Multiple locations can be specified, separated by commas. For example:

  $ {command} example-cluster --zone us-central1-a --additional-zones us-central1-b,us-central1-c
""")
    parser.add_argument(
        '--machine-type',
        '-m',
        help='The type of machine to use for nodes. Defaults to '
        'server-specified')
    parser.add_argument(
        '--subnetwork',
        help='The name of the Google Compute Engine subnetwork '
        '(https://cloud.google.com/compute/docs/subnetworks) to which the '
        'cluster is connected. If specified, the cluster\'s network must be a '
        '"custom subnet" network.')
    parser.add_argument(
        '--disable-addons',
        type=arg_parsers.ArgList(
            choices=[api_adapter.INGRESS, api_adapter.HPA]),
        help='List of cluster addons to disable. Options are {0}'.format(
            ', '.join([api_adapter.INGRESS, api_adapter.HPA])))
    parser.add_argument(
        '--network',
        help='The Compute Engine Network that the cluster will connect to. '
        'Google Container Engine will use this network when creating routes '
        'and firewalls for the clusters. Defaults to the \'default\' network.')
    parser.add_argument(
        '--cluster-ipv4-cidr',
        help='The IP address range for the pods in this cluster in CIDR '
        'notation (e.g. 10.0.0.0/14). Due to kube-proxy limitations, this range '
        'must be a subset of the 10.0.0.0/8 space. Defaults to server-specified'
    )
    parser.add_argument(
        '--password',
        help='The password to use for cluster auth. Defaults to a '
        'server-specified randomly-generated string.')
    parser.add_argument('--scopes',
                        type=arg_parsers.ArgList(min_length=1),
                        metavar='SCOPE',
                        help="""\
Specifies scopes for the node instances. The project's default
service account is used. Examples:

  $ {{command}} example-cluster --scopes https://www.googleapis.com/auth/devstorage.read_only

  $ {{command}} example-cluster --scopes bigquery,storage-rw,compute-ro

Multiple SCOPEs can specified, separated by commas. The scopes
necessary for the cluster to function properly (compute-rw, storage-ro),
are always added, even if not explicitly specified.

SCOPE can be either the full URI of the scope or an alias.
Available aliases are:

[format="csv",options="header"]
|========
Alias,URI
{aliases}
|========
""".format(aliases=compute_constants.ScopesForHelp()))
    parser.add_argument(
        '--enable-cloud-endpoints',
        action='store_true',
        default=True,
        help='Automatically enable Google Cloud Endpoints to take advantage of '
        'API management features.')
    parser.add_argument('--enable-cloud-logging',
                        action='store_true',
                        default=True,
                        help='Automatically send logs from the cluster to the '
                        'Google Cloud Logging API.')
    parser.set_defaults(enable_cloud_logging=True)
    parser.add_argument(
        '--enable-cloud-monitoring',
        action='store_true',
        default=True,
        help='Automatically send metrics from pods in the cluster to the '
        'Google Cloud Monitoring API. VM metrics will be collected by Google '
        'Compute Engine regardless of this setting.')
    parser.set_defaults(enable_cloud_monitoring=True)
    parser.add_argument(
        '--disk-size',
        type=int,
        help='Size in GB for node VM boot disks. Defaults to 100GB.')
    parser.add_argument('--username',
                        '-u',
                        help='The user name to use for cluster auth.',
                        default='admin')
    parser.add_argument(
        '--max-nodes-per-pool',
        type=arg_parsers.BoundedInt(100, api_adapter.MAX_NODES_PER_POOL),
        help='The maximum number of nodes to allocate per default initial node '
        'pool. Container engine will automatically create enough nodes pools '
        'such that each node pool contains less than '
        '--max-nodes-per-pool nodes. Defaults to {nodes} nodes, but can be set '
        'as low as 100 nodes per pool on initial create.'.format(
            nodes=api_adapter.MAX_NODES_PER_POOL))
    flags.AddImageTypeFlag(parser, 'cluster')
    flags.AddNodeLabelsFlag(parser)
    flags.AddTagsFlag(
        parser, """\
Applies the given Compute Engine tags (comma separated) on all nodes in the new
node-pool. Example:

  $ {command} example-cluster --tags=tag1,tag2

New nodes, including ones created by resize or recreate, will have these tags
on the Compute Engine API instance object and can be used in firewall rules.
See https://cloud.google.com/sdk/gcloud/reference/compute/firewall-rules/create
for examples.
""")
Ejemplo n.º 3
0
def _Args(parser):
    """Register flags for this command.

  Args:
    parser: An argparse.ArgumentParser-like object. It is mocked out in order
        to capture some information, but behaves like an ArgumentParser.
  """
    flags.AddNodePoolNameArg(parser, 'The name of the node pool to create.')
    flags.AddNodePoolClusterFlag(parser,
                                 'The cluster to add the node pool to.')
    parser.add_argument(
        '--enable-cloud-endpoints',
        action='store_true',
        default=True,
        help='Automatically enable Google Cloud Endpoints to take advantage of '
        'API management features.')
    # Timeout in seconds for operation
    parser.add_argument('--timeout',
                        type=int,
                        default=1800,
                        help=argparse.SUPPRESS)
    parser.add_argument(
        '--num-nodes',
        type=int,
        help='The number of nodes in the node pool in each of the '
        'cluster\'s zones.',
        default=3)
    parser.add_argument(
        '--machine-type',
        '-m',
        help='The type of machine to use for nodes. Defaults to '
        'server-specified')
    parser.add_argument(
        '--disk-size',
        type=int,
        help='Size in GB for node VM boot disks. Defaults to 100GB.')
    parser.add_argument('--scopes',
                        type=arg_parsers.ArgList(min_length=1),
                        metavar='SCOPE',
                        help="""\
Specifies scopes for the node instances. The project's default
service account is used. Examples:

  $ {{command}} node-pool-1 --cluster=example-cluster --scopes https://www.googleapis.com/auth/devstorage.read_only

  $ {{command}} node-pool-1 --cluster=example-cluster --scopes bigquery,storage-rw,compute-ro

Multiple SCOPEs can specified, separated by commas. The scopes
necessary for the cluster to function properly (compute-rw, storage-ro),
are always added, even if not explicitly specified.

SCOPE can be either the full URI of the scope or an alias.
Available aliases are:

[options="header",format="csv",grid="none",frame="none"]
|========
Alias,URI
{aliases}
|========
""".format(aliases=compute_constants.ScopesForHelp()))
    flags.AddImageTypeFlag(parser, 'node pool')
    flags.AddNodeLabelsFlag(parser, for_node_pool=True)
    flags.AddTagsFlag(
        parser, """\
Applies the given Compute Engine tags (comma separated) on all nodes in the new
node-pool. Example:

  $ {command} node-pool-1 --cluster=example-cluster --tags=tag1,tag2

New nodes, including ones created by resize or recreate, will have these tags
on the Compute Engine API instance object and can be used in firewall rules.
See https://cloud.google.com/sdk/gcloud/reference/compute/firewall-rules/create
for examples.
""")
Ejemplo n.º 4
0
def AddNodeIdentityFlags(parser,
                         example_target,
                         is_deprecated,
                         sa_suppressed=False):
  """Adds node identity flags to the given parser.

  Node identity flags are --scopes, --[no-]enable-cloud-endpoints, and
  --service-account.  --service-account is mutually exclusive with the other
  two, which are not mutually exclusive with each other.

  Args:
    parser: A given parser.
    example_target: the target for the command, e.g. mycluster.
    is_deprecated: whether to use "deprecated" scopes behavior.
    sa_suppressed: whether to suppress help text for --service-account.
  """
  node_identity_group = parser.add_group(
      mutex=True, help='Options to specify the node identity.')
  scopes_group = node_identity_group.add_group(help='Scopes options.')

  min_args_length = 1 if is_deprecated else 0
  default = [] if is_deprecated else ['logging-write', 'monitoring']
  scopes_group.add_argument(
      '--scopes',
      type=arg_parsers.ArgList(min_length=min_args_length),
      metavar='SCOPE',
      default=default,
      help="""\
Specifies scopes for the node instances. The project's default
service account is used. Examples:

  $ {{command}} {example_target} --scopes https://www.googleapis.com/auth/devstorage.read_only

  $ {{command}} {example_target} --scopes bigquery,storage-rw,compute-ro

Multiple SCOPEs can specified, separated by commas. The scopes
necessary for the cluster to function properly (compute-rw, storage-ro),
are always added, even if not explicitly specified.

SCOPE can be either the full URI of the scope or an alias.
Available aliases are:

[format="csv",options="header"]
|========
Alias,URI
{aliases}
|========

{scope_deprecation_msg}
""".format(
    aliases=compute_constants.ScopesForHelp(),
    scope_deprecation_msg=compute_constants.DEPRECATED_SCOPES_MESSAGES,
    example_target=example_target))

  scopes_group.add_argument(
      '--enable-cloud-endpoints',
      action='store_true',
      default=True,
      help='Automatically enable Google Cloud Endpoints to take advantage of '
      'API management features.')

  if sa_suppressed:
    sa_help_text = argparse.SUPPRESS
  else:
    sa_help_text = """\
The Google Cloud Platform Service Account to be used by the node VMs.  If a \
service account is specified, the cloud-platform scope is used. If no Service \
Account is specified, the "default" service account is used.
"""
  node_identity_group.add_argument('--service-account', help=sa_help_text)
def AddNodeIdentityFlags(parser, example_target, new_behavior=True):
    """Adds node identity flags to the given parser.

  Node identity flags are --scopes, --[no-]enable-cloud-endpoints (deprecated),
  and --service-account.  --service-account is mutually exclusive with the
  others.  --[no-]enable-cloud-endpoints is not allowed if property
  container/new_scopes_behavior is set to true, and is removed completely if
  new_behavior is set to true.

  Args:
    parser: A given parser.
    example_target: the target for the command, e.g. mycluster.
    new_behavior: Use new (alpha & beta) behavior: remove
    --[no-]enable-cloud-endpoints.
  """
    node_identity_group = parser.add_group(
        mutex=True, help='Options to specify the node identity.')
    scopes_group = node_identity_group.add_group(help='Scopes options.')

    if new_behavior:
        track_help = """
Unless container/new_scopes_behavior property is true, compute-rw and storage-ro
are always added, even if not explicitly specified, and --enable-cloud-endpoints
(by default) adds service-control and service-management scopes.

If container/new_scopes_behavior property is true, none of the above scopes are
added (though storage-ro, service-control, and service-management are all
included in the default scopes.  In a future release, this will be the default
behavior.
"""
    else:
        track_help = ''
    scopes_group.add_argument('--scopes',
                              type=arg_parsers.ArgList(),
                              metavar='SCOPE',
                              default='gke-default',
                              help="""\
Specifies scopes for the node instances. The project's default service account
is used. Examples:

    $ {{command}} {example_target} --scopes=https://www.googleapis.com/auth/devstorage.read_only

    $ {{command}} {example_target} --scopes=bigquery,storage-rw,compute-ro

Multiple SCOPEs can specified, separated by commas.  logging-write and/or
monitoring are added unless Cloud Logging and/or Cloud Monitoring are disabled
(see --enable-cloud-logging and --enable-cloud-monitoring for more info).
{track_help}
SCOPE can be either the full URI of the scope or an alias. Available aliases
are:

[format="csv",options="header"]
|========
Alias,URI
{aliases}
|========

{scope_deprecation_msg}
""".format(aliases=compute_constants.ScopesForHelp(),
           scope_deprecation_msg=compute_constants.DEPRECATED_SCOPES_MESSAGES,
           example_target=example_target,
           track_help=track_help))

    cloud_endpoints_help_text = """\
Automatically enable Google Cloud Endpoints to take advantage of API management
features by adding service-control and service-management scopes.

If --no-enable-cloud-endpoints is set, remove service-control and
service-management scopes, even if they are implicitly (via default) or
explicitly set via --scopes.

--[no-]enable-cloud-endpoints is not allowed if container/new_scopes_behavior
property is set to true.
"""
    scopes_group.add_argument(
        '--enable-cloud-endpoints',
        action=actions.DeprecationAction(
            '--[no-]enable-cloud-endpoints',
            warn='Flag --[no-]enable-cloud-endpoints is deprecated and will be '
            'removed in a future release.  Scopes necessary for Google Cloud '
            'Endpoints are now included in the default set and may be '
            'excluded using --scopes.',
            removed=new_behavior,
            action='store_true'),
        default=True,
        help=cloud_endpoints_help_text)

    sa_help_text = """\
The Google Cloud Platform Service Account to be used by the node VMs.  If a \
service account is specified, the cloud-platform scope is used. If no Service \
Account is specified, the project default service account is used.
"""
    node_identity_group.add_argument('--service-account', help=sa_help_text)
Ejemplo n.º 6
0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Constants for the dataproc tool."""

from googlecloudsdk.api_lib.compute import base_classes as compute_base
from googlecloudsdk.api_lib.compute import constants as compute_constants
from googlecloudsdk.api_lib.compute import utils as compute_utils
from googlecloudsdk.command_lib.compute import flags
from googlecloudsdk.command_lib.compute import scope as compute_scope
from googlecloudsdk.command_lib.compute import scope_prompter
from googlecloudsdk.core import properties

# Copy into dataproc for cleaner separation
SCOPE_ALIASES = compute_constants.SCOPES
SCOPE_ALIASES_FOR_HELP = compute_constants.ScopesForHelp()


def ExpandScopeAliases(scopes):
    """Replace known aliases in the list of scopes provided by the user."""
    scopes = scopes or []
    expanded_scopes = []
    for scope in scopes:
        if scope in SCOPE_ALIASES:
            expanded_scopes += SCOPE_ALIASES[scope]
        else:
            # Validate scopes server side.
            expanded_scopes.append(scope)
    return sorted(expanded_scopes)

def AddNodeIdentityFlags(parser, example_target):
    """Adds node identity flags to the given parser.

  Node identity flags are --scopes, --[no-]enable-cloud-endpoints, and
  --service-account.  --service-account is mutually exclusive with the other
  two, which are not mutually exclusive with each other.

  Args:
    parser: A given parser.
    example_target: the target for the command, e.g. mycluster.
  """
    node_identity_group = parser.add_group(
        mutex=True, help='Options to specify the node identity.')
    scopes_group = node_identity_group.add_group(help='Scopes options.')

    scopes_group.add_argument('--scopes',
                              type=arg_parsers.ArgList(),
                              metavar='SCOPE',
                              default='gke-default',
                              help="""\
Specifies scopes for the node instances. The project's default service account
is used. Examples:

  $ {{command}} {example_target} --scopes https://www.googleapis.com/auth/devstorage.read_only

  $ {{command}} {example_target} --scopes bigquery,storage-rw,compute-ro

Multiple SCOPEs can specified, separated by commas. The scopes necessary for the
cluster to function properly (compute-rw, storage-ro), are always added, even if
not explicitly specified.

--enable-cloud-endpoints by default adds service-control and service-management
scopes.  To remove them, use --no-enable-cloud-endpoints.

SCOPE can be either the full URI of the scope or an alias. Available aliases
are:

[format="csv",options="header"]
|========
Alias,URI
{aliases}
|========

{scope_deprecation_msg}
""".format(aliases=compute_constants.ScopesForHelp(),
           scope_deprecation_msg=compute_constants.DEPRECATED_SCOPES_MESSAGES,
           example_target=example_target))

    cloud_endpoints_help_text = """\
Automatically enable Google Cloud Endpoints to take advantage of API management
features by adding service-control and service-management scopes.

If --no-enable-cloud-endpoints is set, remove service-control and
service-management scopes, even if they are implicitly (via default) or
explicitly set via --scopes.
"""
    scopes_group.add_argument('--enable-cloud-endpoints',
                              action='store_true',
                              default=True,
                              help=cloud_endpoints_help_text)

    sa_help_text = """\
The Google Cloud Platform Service Account to be used by the node VMs.  If a \
service account is specified, the cloud-platform scope is used. If no Service \
Account is specified, the "default" service account is used.
"""
    node_identity_group.add_argument('--service-account', help=sa_help_text)