Example #1
0
def _SourceArgs(parser, source_snapshot_arg):
  """Add mutually exclusive source args."""

  source_group = parser.add_mutually_exclusive_group()

  def AddImageHelp():
    """Returns detailed help for `--image` argument."""
    template = """\
        An image to apply to the disks being created. When using
        this option, the size of the disks must be at least as large as
        the image size. Use ``--size'' to adjust the size of the disks.

        This flag is mutually exclusive with ``--source-snapshot'' and
        ``--image-family''.
        """
    return template

  source_group.add_argument(
      '--image',
      help=AddImageHelp)

  image_utils.AddImageProjectFlag(parser)

  source_group.add_argument(
      '--image-family',
      help=('The family of the image that the boot disk will be initialized '
            'with. When a family is used instead of an image, the latest '
            'non-deprecated image associated with that family is used.')
  )
  source_snapshot_arg.AddArgument(source_group)
Example #2
0
def AddImageArgs(parser):
  """Adds arguments related to images for instances and instance-templates."""

  def AddImageHelp():
    """Returns the detailed help for the `--image` flag."""
    return """
          Specifies the boot image for the instances. For each
          instance, a new boot disk will be created from the given
          image. Each boot disk will have the same name as the
          instance. To view a list of public images and projects, run
          `$ gcloud compute images list`.

          When using this option, ``--boot-disk-device-name'' and
          ``--boot-disk-size'' can be used to override the boot disk's
          device name and size, respectively.
          """

  image_group = parser.add_mutually_exclusive_group()
  image_group.add_argument(
      '--image',
      help=AddImageHelp,
      metavar='IMAGE')
  image_utils.AddImageProjectFlag(parser)

  image_group.add_argument(
      '--image-family',
      help="""\
      The family of the image that the boot disk will be initialized
      with. When a family is specified instead of an image, the latest
      non-deprecated image associated with that family is used.

      By default, ``{default_image_family}'' is assumed for this flag.
      """.format(default_image_family=constants.DEFAULT_IMAGE_FAMILY))
Example #3
0
def _SourceArgs(parser, source_instant_snapshot_enabled=False):
    """Add mutually exclusive source args."""
    source_parent_group = parser.add_group()
    source_group = source_parent_group.add_mutually_exclusive_group()

    def AddImageHelp():
        """Returns detailed help for `--image` argument."""
        template = """\
        An image to apply to the disks being created. When using
        this option, the size of the disks must be at least as large as
        the image size. Use ``--size'' to adjust the size of the disks.

        This flag is mutually exclusive with ``--source-snapshot'' and
        ``--image-family''.
        """
        return template

    source_group.add_argument('--image', help=AddImageHelp)

    image_utils.AddImageProjectFlag(source_parent_group)

    source_group.add_argument('--image-family',
                              help="""\
        The image family for the operating system that the boot disk will be
        initialized with. Compute Engine offers multiple Linux
        distributions, some of which are available as both regular and
        Shielded VM images.  When a family is specified instead of an image,
        the latest non-deprecated image associated with that family is
        used. It is best practice to use --image-family when the latest
        version of an image is needed.
        """)
    disks_flags.SOURCE_SNAPSHOT_ARG.AddArgument(source_group)
    if source_instant_snapshot_enabled:
        disks_flags.SOURCE_INSTANT_SNAPSHOT_ARG.AddArgument(source_group)
    disks_flags.SOURCE_DISK_ARG.AddArgument(source_group)
Example #4
0
  def Args(parser):
    image_group = parser.add_mutually_exclusive_group(required=True)

    image_group.add_argument(
        '--image',
        help=('The name of the disk image to export.'),
    )
    image_group.add_argument(
        '--image-family',
        help=('The family of the disk image to be exported. When a family '
              'is used instead of an image, the latest non-deprecated image '
              'associated with that family is used.'),
    )
    image_utils.AddImageProjectFlag(parser)

    parser.add_argument(
        '--destination-uri',
        required=True,
        help=('The Google Cloud Storage URI destination for '
              'the exported virtual disk file.'),
    )

    # Export format can take more values than what we list here in the help.
    # However, we don't want to suggest formats that will likely never be used,
    # so we list common ones here, but don't prevent others from being used.
    parser.add_argument(
        '--export-format',
        help=('Specify the format to export to, such as '
              '`vmdk`, `vhdx`, `vpc`, or `qcow2`.'),
    )
    daisy_utils.AddCommonDaisyArgs(parser)
    parser.display_info.AddCacheUpdater(flags.ImagesCompleter)
Example #5
0
def AddImageArgs(parser):
  """Adds arguments related to images for instances and instance-templates."""

  def AddImageHelp():
    """Returns the detailed help for the `--image` flag."""
    template = """
          Specifies the boot image for the instances. For each
          instance, a new boot disk will be created from the given
          image. Each boot disk will have the same name as the
          instance.

          {alias_table}

          When using this option, ``--boot-disk-device-name'' and
          ``--boot-disk-size'' can be used to override the boot disk's
          device name and size, respectively.

          By default, ``{default_image}'' is assumed for this flag.
          """
    # -1 for leading newline
    indent = template.find(template.lstrip()[0]) - 1
    return template.format(
        alias_table=image_utils.GetImageAliasTable(indent=indent),
        default_image=constants.DEFAULT_IMAGE)

  image_choices = ['IMAGE'] + sorted(constants.IMAGE_ALIASES.keys())
  image = parser.add_argument(
      '--image',
      help='The image that the boot disk will be initialized with.',
      metavar=' | '.join(image_choices))
  image.detailed_help = AddImageHelp
  image_utils.AddImageProjectFlag(parser)
Example #6
0
    def Args(parser):
        image_group = parser.add_mutually_exclusive_group(required=True)

        image_group.add_argument(
            '--image',
            help='The name of the disk image to export.',
        )
        image_group.add_argument(
            '--image-family',
            help=(
                'The family of the disk image to be exported. When a family '
                'is used instead of an image, the latest non-deprecated image '
                'associated with that family is used.'),
        )
        image_utils.AddImageProjectFlag(parser)

        flags.compute_flags.AddZoneFlag(
            parser,
            'image',
            'export',
            explanation='The zone to use when exporting the image.')

        parser.add_argument(
            '--destination-uri',
            required=True,
            help=('The Cloud Storage URI destination for '
                  'the exported virtual disk file.'),
        )

        # Export format can take more values than what we list here in the help.
        # However, we don't want to suggest formats that will likely never be used,
        # so we list common ones here, but don't prevent others from being used.
        parser.add_argument(
            '--export-format',
            help=('Specify the format to export to, such as '
                  '`vmdk`, `vhdx`, `vpc`, or `qcow2`.'),
        )

        parser.add_argument(
            '--network',
            help=(
                'The name of the network in your project to use for the image '
                'export. The network must have access to Cloud Storage. '
                'If not specified, the network named `default` is used.'),
        )

        parser.add_argument(
            '--subnet',
            help=(
                'Name of the subnetwork in your project to use for the image '
                'export. If the network resource is in legacy mode, do not '
                'provide this property. If the network is in auto subnet mode, '
                'providing the subnetwork is optional. If the network is in '
                'custom subnet mode, then this field should be specified.'),
        )

        daisy_utils.AddCommonDaisyArgs(parser)

        parser.display_info.AddCacheUpdater(flags.ImagesCompleter)
Example #7
0
def _SourceArgs(parser, image_family=False):
  """Add mutually exclusive source args."""

  source_group = parser.add_mutually_exclusive_group()

  def AddImageHelp():
    """Returns detailed help for `--image` argument."""
    template = """\
        An image to apply to the disks being created. When using
        this option, the size of the disks must be at least as large as
        the image size. Use ``--size'' to adjust the size of the disks.

        {alias_table}

        This flag is mutually exclusive with ``--source-snapshot''.
        """
    indent = template.find(template.lstrip()[0])
    return template.format(
        alias_table=image_utils.GetImageAliasTable(indent=indent))

  image = source_group.add_argument(
      '--image',
      help='An image to apply to the disks being created.')
  image.detailed_help = AddImageHelp

  image_utils.AddImageProjectFlag(parser)

  if image_family:
    source_group.add_argument(
        '--image-family',
        help=('The family of the image that the boot disk will be initialized '
              'with. When a family is used instead of an image, the latest '
              'non-deprecated image associated with that family is used.')
    )

  source_snapshot = source_group.add_argument(
      '--source-snapshot',
      help='A source snapshot used to create the disks.')
  source_snapshot.detailed_help = """\
Example #8
0
    def Args(parser):
        image_group = parser.add_mutually_exclusive_group(required=True)

        image_group.add_argument(
            '--image',
            help='The name of the disk image to export.',
        )
        image_group.add_argument(
            '--image-family',
            help=(
                'The family of the disk image to be exported. When a family '
                'is used instead of an image, the latest non-deprecated image '
                'associated with that family is used.'),
        )
        image_utils.AddImageProjectFlag(parser)

        flags.compute_flags.AddZoneFlag(
            parser,
            'image',
            'export',
            help_text=
            'The zone to use when exporting the image. When you export '
            'an image, the export tool creates and uses temporary VMs '
            'in your project for the export process. Use this flag to '
            'specify the zone to use for these temporary VMs.')

        parser.add_argument(
            '--destination-uri',
            required=True,
            help=('The Cloud Storage URI destination for '
                  'the exported virtual disk file.'),
        )

        # Export format can take more values than what we list here in the help.
        # However, we don't want to suggest formats that will likely never be used,
        # so we list common ones here, but don't prevent others from being used.
        parser.add_argument(
            '--export-format',
            help=('Specify the format to export to, such as '
                  '`vmdk`, `vhdx`, `vpc`, or `qcow2`.'),
        )

        parser.add_argument(
            '--network',
            help=
            ('The name of the network in your project to use for the image '
             'export. When you export an image, the export tool creates and '
             'uses temporary VMs in your project for the export process. Use '
             'this flag to specify the network to use for these temporary VMs.'
             ),
        )

        parser.add_argument('--subnet',
                            help="""\
      Name of the subnetwork in your project to use for the image export. When
      you export an image, the export tool creates and uses temporary VMs in
      your project for the export process. Use this flag to specify the
      subnetwork to use for these temporary VMs.
          * If the network resource is in legacy mode, do not provide this
            property.
          * If the network is in auto subnet mode, specifying the subnetwork is
            optional.
          * If the network is in custom subnet mode, then this field must be
            specified.
        """)

        daisy_utils.AddComputeServiceAccountArg(
            parser, 'image export',
            daisy_utils.EXPORT_ROLES_FOR_COMPUTE_SERVICE_ACCOUNT)

        daisy_utils.AddCommonDaisyArgs(parser,
                                       operation='an export',
                                       extra_timeout_help=("""

          If you are exporting a large image that takes longer than 24 hours to
          export, either use the RAW disk format to reduce the time needed for
          converting the image, or split the data into several smaller images.
          """))

        parser.display_info.AddCacheUpdater(flags.ImagesCompleter)
def _CommonArgs(parser):
    """Add arguments used for parsing in all command tracks."""
    parser.add_argument(
        '--description',
        help=('An optional, textual description for the disks being created.'))

    size = parser.add_argument('--size',
                               type=arg_parsers.BinarySize(lower_bound='1GB'),
                               help='Indicates the size of the disks.')
    size.detailed_help = """\
      Indicates the size of the disks. The value must be a whole
      number followed by a size unit of ``KB'' for kilobyte, ``MB''
      for megabyte, ``GB'' for gigabyte, or ``TB'' for terabyte. For
      example, ``10GB'' will produce 10 gigabyte disks.  Disk size
      must be a multiple of 10 GB.
      """

    parser.add_argument('names',
                        metavar='NAME',
                        nargs='+',
                        help='The names of the disks to create.')

    source_group = parser.add_mutually_exclusive_group()

    def AddImageHelp():
        """Returns detailed help for `--image` argument."""
        template = """\
        An image to apply to the disks being created. When using
        this option, the size of the disks must be at least as large as
        the image size. Use ``--size'' to adjust the size of the disks.

        {alias_table}

        This flag is mutually exclusive with ``--source-snapshot''.
        """
        indent = template.find(template.lstrip()[0])
        return template.format(alias_table=image_utils.GetImageAliasTable(
            indent=indent))

    image = source_group.add_argument(
        '--image', help='An image to apply to the disks being created.')
    image.detailed_help = AddImageHelp

    image_utils.AddImageProjectFlag(parser)

    source_snapshot = source_group.add_argument(
        '--source-snapshot',
        help='A source snapshot used to create the disks.')
    source_snapshot.detailed_help = """\
      A source snapshot used to create the disks. It is safe to
      delete a snapshot after a disk has been created from the
      snapshot. In such cases, the disks will no longer reference
      the deleted snapshot. To get a list of snapshots in your
      current project, run `gcloud compute snapshots list`. A
      snapshot from an existing disk can be created using the
      'gcloud compute disks snapshot' command. This flag is mutually
      exclusive with ``--image''.

      When using this option, the size of the disks must be at least
      as large as the snapshot size. Use ``--size'' to adjust the
      size of the disks.
      """

    disk_type = parser.add_argument(
        '--type', help='Specifies the type of disk to create.')
    disk_type.detailed_help = """\
      Specifies the type of disk to create. To get a
      list of available disk types, run 'gcloud compute
      disk-types list'. The default disk type is pd-standard.
      """

    utils.AddZoneFlag(parser, resource_type='disks', operation_type='create')