Example #1
0
    def Run(self, args):
        try:
            gcs_uri = daisy_utils.MakeGcsObjectUri(args.destination_uri)
        except (storage_util.InvalidObjectNameError,
                core_resources.UnknownCollectionException):
            raise exceptions.InvalidArgumentException(
                'destination-uri',
                'must be a path to an object in Google Cloud Storage')

        tags = ['gce-daisy-image-export']
        export_args = []
        daisy_utils.AppendNetworkAndSubnetArgs(args, export_args)

        daisy_utils.AppendArg(export_args, 'zone',
                              properties.VALUES.compute.zone.Get())
        daisy_utils.AppendArg(export_args, 'scratch_bucket_gcs_path',
                              'gs://{0}/'.format(self._GetDaisyBucket(args)))
        daisy_utils.AppendArg(export_args, 'timeout',
                              '{}s'.format(daisy_utils.GetDaisyTimeout(args)))

        daisy_utils.AppendArg(export_args, 'client_id', 'gcloud')
        source_image = self._GetSourceImage(args.image, args.image_family,
                                            args.image_project)
        daisy_utils.AppendArg(export_args, 'source_image', source_image)
        daisy_utils.AppendArg(export_args, 'destination_uri', gcs_uri)
        if args.export_format:
            daisy_utils.AppendArg(export_args, 'format',
                                  args.export_format.lower())

        return self._RunImageExport(args, export_args, tags, _OUTPUT_FILTER)
Example #2
0
    def Stage(self):
        """Prepares for import args.

    It supports running new import wrapper (gce_vm_image_import).

    Returns:
      import_args - array of strings, import args.
    """
        import_args = []

        daisy_utils.AppendArg(import_args, 'zone',
                              properties.VALUES.compute.zone.Get())
        if self.args.storage_location:
            daisy_utils.AppendArg(import_args, 'storage_location',
                                  self.args.storage_location)
        daisy_utils.AppendArg(import_args, 'scratch_bucket_gcs_path',
                              'gs://{0}/'.format(self.daisy_bucket))
        daisy_utils.AppendArg(
            import_args, 'timeout',
            '{}s'.format(daisy_utils.GetDaisyTimeout(self.args)))

        daisy_utils.AppendArg(import_args, 'client_id', 'gcloud')
        daisy_utils.AppendArg(import_args, 'image_name', self.args.image_name)
        daisy_utils.AppendBoolArg(import_args, 'no_guest_environment',
                                  not self.args.guest_environment)
        daisy_utils.AppendNetworkAndSubnetArgs(self.args, import_args)
        daisy_utils.AppendArg(import_args, 'description',
                              self.args.description)
        daisy_utils.AppendArg(import_args, 'family', self.args.family)

        return import_args
    def Stage(self):
        """Prepares for import args.

    It supports running new import wrapper (gce_vm_image_import).

    Returns:
      import_args - array of strings, import args.
    """
        import_args = []
        messages = self.compute_holder.client.messages

        daisy_utils.AppendArg(import_args, 'zone',
                              properties.VALUES.compute.zone.Get())
        if self.args.storage_location:
            daisy_utils.AppendArg(import_args, 'storage_location',
                                  self.args.storage_location)
        daisy_utils.AppendArg(import_args, 'scratch_bucket_gcs_path',
                              'gs://{0}/'.format(self.daisy_bucket))
        daisy_utils.AppendArg(
            import_args, 'timeout',
            '{}s'.format(daisy_utils.GetDaisyTimeout(self.args)))

        daisy_utils.AppendArg(import_args, 'client_id', 'gcloud')
        daisy_utils.AppendArg(import_args, 'image_name', self.args.image_name)
        daisy_utils.AppendBoolArg(import_args, 'no_guest_environment',
                                  not self.args.guest_environment)
        daisy_utils.AppendNetworkAndSubnetArgs(self.args, import_args)
        daisy_utils.AppendArg(import_args, 'description',
                              self.args.description)
        daisy_utils.AppendArg(import_args, 'family', self.args.family)
        if 'byol' in self.args:
            daisy_utils.AppendBoolArg(import_args, 'byol', self.args.byol)

        # The value of the attribute 'guest_os_features' can be can be a list, None,
        # or the attribute may not be present at all.
        # We treat the case when it is None or when it is not present as if the list
        # of features is empty. We need to use the trailing `or ()` rather than
        # give () as a default value to getattr() to handle the case where
        # args.guest_os_features is present, but it is None.
        guest_os_features = getattr(self.args, 'guest_os_features', None) or ()
        uefi_compatible = (
            messages.GuestOsFeature.TypeValueValuesEnum.UEFI_COMPATIBLE.name
            in guest_os_features)
        if uefi_compatible:
            daisy_utils.AppendBoolArg(import_args, 'uefi_compatible', True)

        if 'sysprep_windows' in self.args:
            daisy_utils.AppendBoolArg(import_args, 'sysprep_windows',
                                      self.args.sysprep_windows)
        if 'no_address' in self.args:
            daisy_utils.AppendBoolArg(import_args, 'no_external_ip',
                                      self.args.no_address)
        if 'compute_service_account' in self.args:
            daisy_utils.AppendArg(import_args, 'compute_service_account',
                                  self.args.compute_service_account)
        return import_args
Example #4
0
  def _BuildImportArgs(self, import_args):
    """Build args to support running new import wrapper - gce_vm_image_import.

    Args:
      import_args: array of str, args to build.
    """
    daisy_utils.AppendArg(import_args, 'zone',
                          properties.VALUES.compute.zone.Get())
    daisy_utils.AppendArg(import_args, 'scratch_bucket_gcs_path',
                          'gs://{0}/'.format(self.GetDaisyBucket()))
    daisy_utils.AppendArg(import_args, 'timeout',
                          '{}s'.format(daisy_utils.GetDaisyTimeout(self.args)))

    daisy_utils.AppendArg(import_args, 'client_id', 'gcloud')
    daisy_utils.AppendArg(import_args, 'image_name', self.args.image_name)
    daisy_utils.AppendBoolArg(import_args, 'no_guest_environment',
                              not self.args.guest_environment)
    daisy_utils.AppendNetworkAndSubnetArgs(self.args, import_args)
Example #5
0
  def Run(self, args):
    tags = ['gce-daisy-image-export']
    export_args = []
    daisy_utils.AppendNetworkAndSubnetArgs(args, export_args)

    daisy_utils.AppendArg(export_args, 'zone',
                          properties.VALUES.compute.zone.Get())
    daisy_utils.AppendArg(export_args, 'scratch_bucket_gcs_path',
                          'gs://{0}/'.format(self._GetDaisyBucket(args)))
    daisy_utils.AppendArg(export_args, 'timeout',
                          '{}s'.format(daisy_utils.GetDaisyTimeout(args)))

    daisy_utils.AppendArg(export_args, 'client_id', 'gcloud')
    source_image = self._GetSourceImage(args.image, args.image_family,
                                        args.image_project)
    daisy_utils.AppendArg(export_args, 'source_image', source_image)
    daisy_utils.AppendArg(export_args, 'destination_uri', args.destination_uri)
    if args.export_format:
      daisy_utils.AppendArg(export_args, 'format', args.export_format.lower())

    return self._RunImageExport(args, export_args, tags, _OUTPUT_FILTER)