Example #1
0
 def _MakeGcsUri(self, uri):
     try:
         return daisy_utils.MakeGcsObjectOrPathUri(uri)
     except storage_util.InvalidObjectNameError:
         raise exceptions.InvalidArgumentException(
             'source-file',
             'must be a path to an object in Google Cloud Storage')
Example #2
0
    def Run(self, args):
        compute_holder = base_classes.ComputeApiHolder(self.ReleaseTrack())

        self._ValidateInstanceName(args)
        self._CheckForExistingInstances(args.instance_name,
                                        compute_holder.client)

        instances_flags.ValidateNicFlags(args)
        instances_flags.ValidateNetworkTierArgs(args)

        log.warning('Importing OVF. This may take 40 minutes for smaller OVFs '
                    'and up to a couple of hours for larger OVFs.')

        machine_type = None
        if args.machine_type or args.custom_cpu or args.custom_memory:
            machine_type = instance_utils.InterpretMachineType(
                machine_type=args.machine_type,
                custom_cpu=args.custom_cpu,
                custom_memory=args.custom_memory,
                ext=getattr(args, 'custom_extensions', None),
                vm_type=getattr(args, 'custom_vm_type', None))

        try:
            source_uri = daisy_utils.MakeGcsObjectOrPathUri(args.source_uri)
        except storage_util.InvalidObjectNameError:
            raise exceptions.InvalidArgumentException(
                'source-uri',
                'must be a path to an object or a directory in Google Cloud Storage'
            )

        return daisy_utils.RunOVFImportBuild(
            args=args,
            compute_client=compute_holder.client,
            instance_name=args.instance_name,
            source_uri=source_uri,
            no_guest_environment=not args.guest_environment,
            can_ip_forward=args.can_ip_forward,
            deletion_protection=args.deletion_protection,
            description=args.description,
            labels=args.labels,
            machine_type=machine_type,
            network=args.network,
            network_tier=args.network_tier,
            subnet=args.subnet,
            private_network_ip=args.private_network_ip,
            no_restart_on_failure=not args.restart_on_failure,
            os=args.os,
            tags=args.tags,
            zone=properties.VALUES.compute.zone.Get(),
            project=args.project,
            output_filter=_OUTPUT_FILTER,
            compute_release_track=self.ReleaseTrack().id.lower()
            if self.ReleaseTrack() else None)
Example #3
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.MakeGcsObjectOrPathUri(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)