コード例 #1
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())
        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)

        return import_args
コード例 #2
0
 def GetImportStepForNonGSFile(self):
     import_vars = []
     daisy_utils.AppendArg(import_vars, 'source_file',
                           self.GetCopiedSource(regionalized=False))
     daisy_utils.AppendBoolArg(import_vars, 'data_disk')
     daisy_utils.AppendArg(
         import_vars, 'scratch_bucket_gcs_path',
         'gs://{0}/'.format(self.GetScratchBucketNameWithoutRegion()))
     daisy_utils.AppendArg(import_vars, 'timeout', _DEFAULT_TIMEOUT)
     daisy_utils.AppendArg(import_vars, 'client_id', 'gcloud')
     daisy_utils.AppendArg(import_vars, 'image_name', self.image_name)
     return self.cloudbuild_v1_messages.BuildStep(args=import_vars,
                                                  name=self.builder)
コード例 #3
0
 def GetImportStepForTimeoutTest(self, timeout):
     import_vars = []
     daisy_utils.AppendArg(import_vars, 'source_file',
                           self.GetCopiedSource())
     daisy_utils.AppendBoolArg(import_vars, 'data_disk')
     daisy_utils.AppendArg(
         import_vars, 'scratch_bucket_gcs_path',
         'gs://{0}/'.format(self.GetScratchBucketNameWithRegion()))
     daisy_utils.AppendArg(import_vars, 'timeout', '{}s'.format(timeout))
     daisy_utils.AppendArg(import_vars, 'client_id', 'gcloud')
     daisy_utils.AppendArg(import_vars, 'image_name', self.image_name)
     return self.cloudbuild_v1_messages.BuildStep(args=import_vars,
                                                  name=self.builder)
コード例 #4
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 = []
        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
コード例 #5
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.support_storage_location and 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)
        # TODO(b/122357922): Remove 'description' and 'family' guards once in GA.
        if 'description' in self.args:
            daisy_utils.AppendArg(import_args, 'description',
                                  self.args.description)
        if 'family' in self.args:
            daisy_utils.AppendArg(import_args, 'family', self.args.family)
        return import_args
コード例 #6
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())
        if 'compute_service_account' in args:
            daisy_utils.AppendArg(export_args, 'compute_service_account',
                                  args.compute_service_account)
        return self._RunImageExport(args, export_args, tags, _OUTPUT_FILTER)
コード例 #7
0
  def Stage(self):
    import_args = []

    daisy_utils.AppendArg(import_args, 'source_image', self.args.source_image)
    _AppendTranslateWorkflowArg(self.args, import_args)

    import_args.extend(super(ImportFromImageStager, self).Stage())
    return import_args
コード例 #8
0
  def _BuildImportArgs(self, import_args):
    # Import and (maybe) translate from the scratch bucket.
    daisy_utils.AppendArg(import_args, 'source_file', self.gcs_uri)
    if self.args.data_disk:
      daisy_utils.AppendBoolArg(import_args, 'data_disk', self.args.data_disk)
    else:
      _AppendTranslateWorkflowArg(self.args, import_args)

    super(BaseImportFromFileStager, self)._BuildImportArgs(import_args)
コード例 #9
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)
コード例 #10
0
    def GetNetworkStepForExport(
            self,
            network=None,
            subnet=None,
            zone='my-region-c',
            include_empty_network=False,
            image_project='my-project',
            workflow='../workflows/export/image_export.wf.json',
            image_format='',
            daisy_bucket_name=None):
        export_vars = []

        if subnet:
            daisy_utils.AppendArg(export_vars, 'subnet', subnet)

        if network:
            daisy_utils.AppendArg(export_vars, 'network', network)

        if zone:
            daisy_utils.AppendArg(export_vars, 'zone', zone)

        daisy_utils.AppendArg(
            export_vars, 'scratch_bucket_gcs_path',
            'gs://{0}/'.format(daisy_bucket_name
                               or self.GetScratchBucketNameWithRegion()))

        daisy_utils.AppendArg(export_vars, 'timeout',
                              daisy_test_base._DEFAULT_TIMEOUT)
        daisy_utils.AppendArg(export_vars, 'client_id', 'gcloud')
        daisy_utils.AppendArg(
            export_vars, 'source_image',
            'projects/{0}/global/images/{1}'.format(image_project,
                                                    self.image_name))
        daisy_utils.AppendArg(export_vars, 'destination_uri',
                              self.destination_uri)
        daisy_utils.AppendArg(export_vars, 'format', image_format)
        daisy_utils.AppendArg(export_vars, 'client_version',
                              config.CLOUD_SDK_VERSION)

        return self.cloudbuild_v1_messages.BuildStep(args=export_vars,
                                                     name=self.GetBuilder(
                                                         zone='',
                                                         region='my-region'))
コード例 #11
0
  def Stage(self):
    self._FileStage()

    import_args = []

    # Import and (maybe) translate from the scratch bucket.
    daisy_utils.AppendArg(import_args, 'source_file', self.gcs_uri)
    if self.args.data_disk:
      daisy_utils.AppendBoolArg(import_args, 'data_disk', self.args.data_disk)
    else:
      _AppendTranslateWorkflowArg(self.args, import_args)

    import_args.extend(super(BaseImportFromFileStager, self).Stage())
    return import_args
コード例 #12
0
 def GetImportStepForZoneFlagTest(self):
     import_vars = []
     daisy_utils.AppendArg(import_vars, 'source_file',
                           self.GetCopiedSource())
     daisy_utils.AppendArg(import_vars, 'os', 'ubuntu-1604')
     daisy_utils.AppendArg(import_vars, 'zone', 'us-west1-c')
     daisy_utils.AppendArg(
         import_vars, 'scratch_bucket_gcs_path',
         'gs://{0}/'.format(self.GetScratchBucketNameWithRegion()))
     daisy_utils.AppendArg(import_vars, 'timeout', _DEFAULT_TIMEOUT)
     daisy_utils.AppendArg(import_vars, 'client_id', 'gcloud')
     daisy_utils.AppendArg(import_vars, 'image_name', self.image_name)
     return self.cloudbuild_v1_messages.BuildStep(args=import_vars,
                                                  name=self.builder)
コード例 #13
0
 def GetImportStepForWarnOnOva(self, copied_source, daisy_bucket_name):
     import_vars = []
     daisy_utils.AppendArg(import_vars, 'source_file', copied_source)
     daisy_utils.AppendArg(import_vars, 'os', 'ubuntu-1604')
     daisy_utils.AppendArg(import_vars, 'scratch_bucket_gcs_path',
                           'gs://{0}/'.format(daisy_bucket_name))
     daisy_utils.AppendArg(import_vars, 'timeout', _DEFAULT_TIMEOUT)
     daisy_utils.AppendArg(import_vars, 'client_id', 'gcloud')
     daisy_utils.AppendArg(import_vars, 'image_name', self.image_name)
     return self.cloudbuild_v1_messages.BuildStep(args=import_vars,
                                                  name=self.builder)
コード例 #14
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)
        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
コード例 #15
0
    def Stage(self):
        _CheckForExistingImage(self.args.source_image,
                               self.compute_holder,
                               arg_name='source-image',
                               expect_to_exist=True)
        import_args = []

        daisy_utils.AppendArg(import_args, 'source_image',
                              self.args.source_image)
        if self.args.data_disk:
            daisy_utils.AppendBoolArg(import_args, 'data_disk',
                                      self.args.data_disk)
        else:
            _AppendTranslateWorkflowArg(self.args, import_args)

        import_args.extend(super(ImportFromImageStager, self).Stage())
        return import_args
コード例 #16
0
 def GetImportStepForWindowsByolMapping(self, target_workflow,
                                        translate_workflow):
     import_vars = []
     daisy_utils.AppendArg(import_vars, 'source_image', self.source_image)
     daisy_utils.AppendArg(import_vars, 'os', 'windows-7-x64-byol')
     daisy_utils.AppendArg(
         import_vars, 'scratch_bucket_gcs_path',
         'gs://{0}/'.format(self.GetScratchBucketNameWithoutRegion()))
     daisy_utils.AppendArg(import_vars, 'timeout', _DEFAULT_TIMEOUT)
     daisy_utils.AppendArg(import_vars, 'client_id', 'gcloud')
     daisy_utils.AppendArg(import_vars, 'image_name',
                           self.destination_image)
     return self.cloudbuild_v1_messages.BuildStep(args=import_vars,
                                                  name=self.builder)
コード例 #17
0
 def GetImportStepForNoGooglePackageInstall(self):
     import_vars = []
     daisy_utils.AppendArg(import_vars, 'source_file',
                           self.GetCopiedSource())
     daisy_utils.AppendArg(import_vars, 'os', 'ubuntu-1604')
     daisy_utils.AppendArg(
         import_vars, 'scratch_bucket_gcs_path',
         'gs://{0}/'.format(self.GetScratchBucketNameWithRegion()))
     daisy_utils.AppendArg(import_vars, 'timeout', _DEFAULT_TIMEOUT)
     daisy_utils.AppendArg(import_vars, 'client_id', 'gcloud')
     daisy_utils.AppendArg(import_vars, 'image_name', self.image_name)
     daisy_utils.AppendBoolArg(import_vars, 'no_guest_environment')
     return self.cloudbuild_v1_messages.BuildStep(args=import_vars,
                                                  name=self.builder)
コード例 #18
0
 def GetImportStepForTranslateFromImage(self, translate_workflow):
     default_translate_workflow = 'ubuntu/translate_ubuntu_1604.wf.json'
     import_vars = []
     daisy_utils.AppendArg(import_vars, 'source_image', self.source_image)
     if default_translate_workflow != translate_workflow:
         daisy_utils.AppendArg(import_vars, 'custom_translate_workflow',
                               translate_workflow)
     else:
         daisy_utils.AppendArg(import_vars, 'os', 'ubuntu-1604')
     daisy_utils.AppendArg(
         import_vars, 'scratch_bucket_gcs_path',
         'gs://{0}/'.format(self.GetScratchBucketNameWithoutRegion()))
     daisy_utils.AppendArg(import_vars, 'timeout', _DEFAULT_TIMEOUT)
     daisy_utils.AppendArg(import_vars, 'client_id', 'gcloud')
     daisy_utils.AppendArg(import_vars, 'image_name',
                           self.destination_image)
     return self.cloudbuild_v1_messages.BuildStep(args=import_vars,
                                                  name=self.builder)
コード例 #19
0
def _AppendAwsArgs(args, import_args):
    """Appends args related to AWS image import."""

    daisy_utils.AppendArg(import_args, 'aws_access_key_id',
                          args.aws_access_key_id)
    daisy_utils.AppendArg(import_args, 'aws_secret_access_key',
                          args.aws_secret_access_key)
    daisy_utils.AppendArg(import_args, 'aws_session_token',
                          args.aws_session_token)
    daisy_utils.AppendArg(import_args, 'aws_region', args.aws_region)

    if args.aws_ami_id:
        daisy_utils.AppendArg(import_args, 'aws_ami_id', args.aws_ami_id)
    if args.aws_ami_export_location:
        daisy_utils.AppendArg(import_args, 'aws_ami_export_location',
                              args.aws_ami_export_location)
    if args.aws_source_ami_file_path:
        daisy_utils.AppendArg(import_args, 'aws_source_ami_file_path',
                              args.aws_source_ami_file_path)
コード例 #20
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)
コード例 #21
0
ファイル: import.py プロジェクト: twinDev/order-api
def _AppendTranslateWorkflowArg(args, import_args):
    if args.os:
        daisy_utils.AppendArg(import_args, 'os', args.os)
    daisy_utils.AppendArg(import_args, 'custom_translate_workflow',
                          args.custom_workflow)
コード例 #22
0
ファイル: import.py プロジェクト: lrxcy/google-cloud-sdk
 def _BuildImportArgs(self, import_args):
     source_image_name = self._GetSourceImage()
     daisy_utils.AppendArg(import_args, 'source_image', source_image_name)
     _AppendTranslateWorkflowArg(self.args, import_args)
     super(ImportFromImageStager, self)._BuildImportArgs(import_args)
コード例 #23
0
    def GetNetworkStepForImport(self,
                                network=None,
                                subnet=None,
                                include_zone=True,
                                from_image=False,
                                include_storage_location=False,
                                family=None,
                                description=None,
                                sysprep_windows=False):

        import_vars = []

        if from_image:
            daisy_utils.AppendArg(import_vars, 'source_image',
                                  self.source_image)
        else:
            daisy_utils.AppendArg(import_vars, 'source_file',
                                  self.GetCopiedSource(regionalized=True))

        daisy_utils.AppendArg(import_vars, 'os', 'ubuntu-1604')

        if include_zone:
            daisy_utils.AppendArg(import_vars, 'zone', 'my-region-c')

        if include_storage_location:
            daisy_utils.AppendArg(import_vars, 'storage_location', 'my-region')

        daisy_utils.AppendArg(
            import_vars, 'scratch_bucket_gcs_path', 'gs://{0}/'.format(
                self.GetScratchBucketName(not from_image
                                          or include_storage_location)))

        daisy_utils.AppendArg(import_vars, 'timeout', _DEFAULT_TIMEOUT)
        daisy_utils.AppendArg(import_vars, 'client_id', 'gcloud')
        daisy_utils.AppendArg(import_vars, 'image_name', self.image_name)

        if subnet:
            daisy_utils.AppendArg(import_vars, 'subnet', subnet)

        if network:
            daisy_utils.AppendArg(import_vars, 'network', network)

        if description:
            daisy_utils.AppendArg(import_vars, 'description', description)

        if family:
            daisy_utils.AppendArg(import_vars, 'family', family)

        if sysprep_windows:
            daisy_utils.AppendBoolArg(import_vars, 'sysprep_windows')

        return self.cloudbuild_v1_messages.BuildStep(args=import_vars,
                                                     name=self.builder)