コード例 #1
0
ファイル: export.py プロジェクト: piotradamczyk5/gcloud_cli
    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)
コード例 #2
0
    def _CreateImportStager(self, args):
        if args.source_image:
            return ImportFromImageStager(self.storage_client, args)

        if _IsLocalFile(args.source_file):
            return ImportFromLocalFileStager(self.storage_client, args)

        try:
            gcs_uri = daisy_utils.MakeGcsObjectUri(args.source_file)
        except storage_util.InvalidObjectNameError:
            raise exceptions.InvalidArgumentException(
                'source-file',
                'must be a path to an object in Google Cloud Storage')
        else:
            return ImportFromGSFileStager(self.storage_client, args, gcs_uri)
コード例 #3
0
    def _CreateImportStager(self, args, compute_holder):
        if (self.ReleaseTrack() != base.ReleaseTrack.GA
                and _HasExternalCloudProvider(args)):
            return ImportFromExternalCloudProviderStager(
                self.storage_client, compute_holder, args)

        if args.source_image:
            return ImportFromImageStager(self.storage_client, compute_holder,
                                         args)

        if daisy_utils.IsLocalFile(args.source_file):
            return ImportFromLocalFileStager(self.storage_client,
                                             compute_holder, args)

        try:
            gcs_uri = daisy_utils.MakeGcsObjectUri(args.source_file)
        except storage_util.InvalidObjectNameError:
            raise exceptions.InvalidArgumentException(
                'source-file',
                'must be a path to an object in Google Cloud Storage')
        else:
            return ImportFromGSFileStager(self.storage_client, compute_holder,
                                          args, gcs_uri)
コード例 #4
0
 def testMakeGcsObjectUriErrorOnBucketOnly(self):
     with self.AssertRaisesExceptionMatches(
             storage_util.InvalidObjectNameError, r'Missing object name'):
         daisy_utils.MakeGcsObjectUri('gs://bucket')
コード例 #5
0
 def testMakeGcsObjectUri(self):
     uri = 'gs://bucket/file/a'
     result = daisy_utils.MakeGcsObjectUri(uri)
     self.assertEqual(uri, result)