コード例 #1
0
ファイル: update.py プロジェクト: PrateekKhatri/gcloud_cli
    def _Run(self, args, version):
        index_ref = args.CONCEPTS.index.Parse()
        region = index_ref.AsDict()['locationsId']
        with endpoint_util.AiplatformEndpointOverrides(version, region=region):
            operation = client.IndexesClient().PatchBeta(index_ref, args)
            if args.metadata_file is not None:
                # Update index content.
                op_ref = indexes_util.ParseIndexOperation(operation.name)
                log.status.Print(
                    constants.OPERATION_CREATION_DISPLAY_MESSAGE.format(
                        name=operation.name,
                        verb='update index',
                        id=op_ref.Name(),
                        sub_commands='--index={}'.format(index_ref.Name())))
                # We will not wait for the operation since it can take up to hours.
                return operation

            # Update index meta data.
            response_msg = operations_util.WaitForOpMaybe(
                operations_client=operations.OperationsClient(),
                op=operation,
                op_ref=indexes_util.ParseIndexOperation(operation.name),
                log_method='update')
            if response_msg is not None:
                response = encoding.MessageToPyValue(response_msg)
                if 'name' in response:
                    log.UpdatedResource(response['name'],
                                        kind='AI Platform index')
            return response_msg
コード例 #2
0
 def Run(self, args):
   region_ref = args.CONCEPTS.region.Parse()
   region = region_ref.AsDict()['locationsId']
   with endpoint_util.AiplatformEndpointOverrides(
       version=constants.GA_VERSION, region=region):
     client_instance = apis.GetClientInstance(
         constants.AI_PLATFORM_API_NAME,
         constants.AI_PLATFORM_API_VERSION[constants.GA_VERSION])
     operation = client.ModelsClient(
         client=client_instance,
         messages=client_instance.MESSAGES_MODULE).UploadV1(
             region_ref,
             args.display_name,
             args.description,
             args.artifact_uri,
             args.container_image_uri,
             args.container_command,
             args.container_args,
             args.container_env_vars,
             args.container_ports,
             args.container_predict_route,
             args.container_health_route,
             explanation_spec=self._BuildExplanationSpec(args))
     return operations_util.WaitForOpMaybe(
         operations_client=operations.OperationsClient(
             client=client_instance, messages=client_instance.MESSAGES_MODULE),
         op=operation,
         op_ref=models_util.ParseModelOperation(operation.name))
コード例 #3
0
def _Run(args, version):
    """Create a new Vertex AI endpoint."""
    validation.ValidateDisplayName(args.display_name)

    region_ref = args.CONCEPTS.region.Parse()
    args.region = region_ref.AsDict()['locationsId']
    with endpoint_util.AiplatformEndpointOverrides(version,
                                                   region=args.region):
        endpoints_client = client.EndpointsClient(version=version)
        operation_client = operations.OperationsClient()
        if version == constants.GA_VERSION:
            op = endpoints_client.Create(
                region_ref, args.display_name,
                labels_util.ParseCreateArgs(
                    args, endpoints_client.messages.
                    GoogleCloudAiplatformV1Endpoint.LabelsValue),
                args.description, args.network, args.endpoint_id)
        else:
            op = endpoints_client.CreateBeta(
                region_ref, args.display_name,
                labels_util.ParseCreateArgs(
                    args, endpoints_client.messages.
                    GoogleCloudAiplatformV1beta1Endpoint.LabelsValue),
                args.description, args.network, args.endpoint_id)
        response_msg = operations_util.WaitForOpMaybe(
            operation_client, op, endpoints_util.ParseOperation(op.name))
        if response_msg is not None:
            response = encoding.MessageToPyValue(response_msg)
            if 'name' in response:
                log.status.Print(('Created Vertex AI endpoint: {}.').format(
                    response['name']))
        return response_msg
コード例 #4
0
 def _Run(self, args, model_ref, region):
     with endpoint_util.AiplatformEndpointOverrides(
             version=constants.BETA_VERSION, region=region):
         operation = client.ModelsClient().Delete(model_ref)
         return operations_util.WaitForOpMaybe(
             operations_client=operations.OperationsClient(),
             op=operation,
             op_ref=models_util.ParseModelOperation(operation.name))
コード例 #5
0
 def _Run(self, args):
     model_ref = args.CONCEPTS.model.Parse()
     region = model_ref.AsDict()['locationsId']
     with endpoint_util.AiplatformEndpointOverrides(
             version=constants.BETA_VERSION, region=region):
         operation = client.ModelsClient().Delete(model_ref)
         return operations_util.WaitForOpMaybe(
             operations_client=operations.OperationsClient(),
             op=operation,
             op_ref=models_util.ParseModelOperation(operation.name))
コード例 #6
0
def _Run(args, version):
    """Deploy a model to an existing Vertex AI endpoint."""
    validation.ValidateDisplayName(args.display_name)
    if version != constants.GA_VERSION:
        validation.ValidateAutoscalingMetricSpecs(
            args.autoscaling_metric_specs)

    endpoint_ref = args.CONCEPTS.endpoint.Parse()
    args.region = endpoint_ref.AsDict()['locationsId']
    with endpoint_util.AiplatformEndpointOverrides(version,
                                                   region=args.region):
        endpoints_client = client.EndpointsClient(version=version)
        operation_client = operations.OperationsClient()
        if version == constants.GA_VERSION:
            op = endpoints_client.DeployModel(
                endpoint_ref,
                args.model,
                args.region,
                args.display_name,
                machine_type=args.machine_type,
                accelerator_dict=args.accelerator,
                min_replica_count=args.min_replica_count,
                max_replica_count=args.max_replica_count,
                enable_access_logging=args.enable_access_logging,
                disable_container_logging=args.disable_container_logging,
                service_account=args.service_account,
                traffic_split=args.traffic_split,
                deployed_model_id=args.deployed_model_id)
        else:
            op = endpoints_client.DeployModelBeta(
                endpoint_ref,
                args.model,
                args.region,
                args.display_name,
                machine_type=args.machine_type,
                accelerator_dict=args.accelerator,
                min_replica_count=args.min_replica_count,
                max_replica_count=args.max_replica_count,
                autoscaling_metric_specs=args.autoscaling_metric_specs,
                enable_access_logging=args.enable_access_logging,
                enable_container_logging=args.enable_container_logging,
                service_account=args.service_account,
                traffic_split=args.traffic_split,
                deployed_model_id=args.deployed_model_id)
        response_msg = operations_util.WaitForOpMaybe(
            operation_client, op, endpoints_util.ParseOperation(op.name))
        if response_msg is not None:
            response = encoding.MessageToPyValue(response_msg)
            if 'deployedModel' in response and 'id' in response[
                    'deployedModel']:
                log.status.Print(('Deployed a model to the endpoint {}. '
                                  'Id of the deployed model: {}.').format(
                                      endpoint_ref.AsDict()['endpointsId'],
                                      response['deployedModel']['id']))
        return response_msg
コード例 #7
0
 def _Run(self, args):
     tensorboard_ref = args.CONCEPTS.tensorboard.Parse()
     region = tensorboard_ref.AsDict()['locationsId']
     with endpoint_util.AiplatformEndpointOverrides(
             version=constants.ALPHA_VERSION, region=region):
         operation = client.TensorboardsClient().Delete(tensorboard_ref)
         return operations_util.WaitForOpMaybe(
             operations_client=operations.OperationsClient(),
             op=operation,
             op_ref=tensorboards_util.ParseTensorboardOperation(
                 operation.name))
コード例 #8
0
def _Run(args, version):
    """Undeploy a model fro man existing AI Platform endpoint."""
    endpoint_ref = args.CONCEPTS.endpoint.Parse()
    args.region = endpoint_ref.AsDict()['locationsId']
    with endpoint_util.AiplatformEndpointOverrides(version,
                                                   region=args.region):
        endpoints_client = client.EndpointsClient(version=version)
        operation_client = operations.OperationsClient()
        op = endpoints_client.UndeployModelBeta(endpoint_ref, args)
        return operations_util.WaitForOpMaybe(
            operation_client, op, endpoints_util.ParseOperation(op.name))
コード例 #9
0
def _Run(args, version):
    tensorboard_run_ref = args.CONCEPTS.tensorboard_run.Parse()
    region = tensorboard_run_ref.AsDict()['locationsId']
    with endpoint_util.AiplatformEndpointOverrides(version=version,
                                                   region=region):
        operation = client.TensorboardRunsClient(
            version=version).Delete(tensorboard_run_ref)
        return operations_util.WaitForOpMaybe(
            operations_client=operations.OperationsClient(),
            op=operation,
            op_ref=tensorboards_util.ParseTensorboardOperation(operation.name))
コード例 #10
0
 def _Run(self, args, version):
     index_endpoint_ref = args.CONCEPTS.index_endpoint.Parse()
     region = index_endpoint_ref.AsDict()['locationsId']
     with endpoint_util.AiplatformEndpointOverrides(version, region=region):
         operation = client.IndexEndpointsClient().UndeployIndexBeta(
             index_endpoint_ref, args)
         return operations_util.WaitForOpMaybe(
             operations_client=operations.OperationsClient(),
             op=operation,
             op_ref=index_endpoints_util.ParseIndexEndpointOperation(
                 operation.name))
コード例 #11
0
ファイル: delete.py プロジェクト: PrateekKhatri/gcloud_cli
 def _Run(self, args, version):
     index_ref = args.CONCEPTS.index.Parse()
     region = index_ref.AsDict()['locationsId']
     index_id = index_ref.AsDict()['indexesId']
     with endpoint_util.AiplatformEndpointOverrides(version, region=region):
         console_io.PromptContinue(
             'This will delete index [{}]...'.format(index_id),
             cancel_on_no=True)
         operation = client.IndexesClient().Delete(index_ref)
         return operations_util.WaitForOpMaybe(
             operations_client=operations.OperationsClient(),
             op=operation,
             op_ref=indexes_util.ParseIndexOperation(operation.name))
コード例 #12
0
    def _Run(self, args, version):
        # This is the default operation name in the format of
        # `projects/123/locations/us-central1/operations/456`.
        operation_ref = args.CONCEPTS.operation.Parse()
        project_id = operation_ref.AsDict()['projectsId']
        region = operation_ref.AsDict()['locationsId']
        operation_id = operation_ref.AsDict()['operationsId']

        if args.index is not None:
            # Override the operation name using the multi-parent format.
            operation_ref = indexes_util.BuildIndexParentOperation(
                project_id, region, args.index, operation_id)
        with endpoint_util.AiplatformEndpointOverrides(version, region=region):
            return operations.OperationsClient().Get(operation_ref)
コード例 #13
0
ファイル: upload.py プロジェクト: piotradamczyk5/gcloud_cli
 def Run(self, args):
     region_ref = args.CONCEPTS.region.Parse()
     region = region_ref.AsDict()['locationsId']
     with endpoint_util.AiplatformEndpointOverrides(
             version=constants.BETA_VERSION, region=region):
         operation = client.ModelsClient().UploadV1Beta1(
             region_ref, args.display_name, args.description,
             args.artifact_uri, args.container_image_uri,
             args.container_command, args.container_args,
             args.container_env_vars, args.container_ports,
             args.container_predict_route, args.container_health_route)
         return operations_util.WaitForOpMaybe(
             operations_client=operations.OperationsClient(),
             op=operation,
             op_ref=models_util.ParseModelOperation(operation.name))
コード例 #14
0
def _Run(args, version):
    """Delete an existing Vertex AI endpoint."""
    endpoint_ref = args.CONCEPTS.endpoint.Parse()
    args.region = endpoint_ref.AsDict()['locationsId']
    endpoint_id = endpoint_ref.AsDict()['endpointsId']
    with endpoint_util.AiplatformEndpointOverrides(version,
                                                   region=args.region):
        endpoints_client = client.EndpointsClient(version=version)
        operation_client = operations.OperationsClient()
        console_io.PromptContinue(
            'This will delete endpoint [{}]...'.format(endpoint_id),
            cancel_on_no=True)
        op = endpoints_client.Delete(endpoint_ref)
        return operations_util.WaitForOpMaybe(
            operation_client, op, endpoints_util.ParseOperation(op.name))
コード例 #15
0
def _Run(args, version):
    """Run method for delete command."""
    model_monitoring_job_ref = args.CONCEPTS.monitoring_job.Parse()
    region = model_monitoring_job_ref.AsDict()['locationsId']
    model_monitoring_job_id = model_monitoring_job_ref.AsDict(
    )['modelDeploymentMonitoringJobsId']
    with endpoint_util.AiplatformEndpointOverrides(version, region=region):
        console_io.PromptContinue(
            'This will delete model deployment monitoring job [{}]...'.format(
                model_monitoring_job_id),
            cancel_on_no=True)
        operation = client.ModelMonitoringJobsClient(
            version=version).Delete(model_monitoring_job_ref)
        return operations_util.WaitForOpMaybe(
            operations_client=operations.OperationsClient(),
            op=operation,
            op_ref=model_monitoring_jobs_util.ParseMonitoringJobOperation(
                operation.name))
コード例 #16
0
 def _Run(self, args, version):
     validation.ValidateDisplayName(args.display_name)
     index_endpoint_ref = args.CONCEPTS.index_endpoint.Parse()
     region = index_endpoint_ref.AsDict()['locationsId']
     with endpoint_util.AiplatformEndpointOverrides(version, region=region):
         operation = client.IndexEndpointsClient().DeployIndexBeta(
             index_endpoint_ref, args)
         response_msg = operations_util.WaitForOpMaybe(
             operations_client=operations.OperationsClient(),
             op=operation,
             op_ref=index_endpoints_util.ParseIndexEndpointOperation(
                 operation.name))
     if response_msg is not None:
         response = encoding.MessageToPyValue(response_msg)
         if 'deployedIndex' in response and 'id' in response[
                 'deployedIndex']:
             log.status.Print(('Id of the deployed index: {}.').format(
                 response['deployedIndex']['id']))
     return response_msg
コード例 #17
0
def _Run(args, version):
    """Create a new AI Platform endpoint."""
    validation.ValidateDisplayName(args.display_name)

    region_ref = args.CONCEPTS.region.Parse()
    args.region = region_ref.AsDict()['locationsId']
    with endpoint_util.AiplatformEndpointOverrides(version,
                                                   region=args.region):
        endpoints_client = client.EndpointsClient(version=version)
        operation_client = operations.OperationsClient()
        op = endpoints_client.CreateBeta(region_ref, args)
        response_msg = operations_util.WaitForOpMaybe(
            operation_client, op, endpoints_util.ParseOperation(op.name))
        if response_msg is not None:
            response = encoding.MessageToPyValue(response_msg)
            if 'name' in response:
                log.status.Print(('Created AI Platform endpoint: {}.').format(
                    response['name']))
        return response_msg
コード例 #18
0
 def _Run(self, args, version):
     validation.ValidateDisplayName(args.display_name)
     region_ref = args.CONCEPTS.region.Parse()
     region = region_ref.AsDict()['locationsId']
     with endpoint_util.AiplatformEndpointOverrides(version, region=region):
         operation = client.IndexEndpointsClient().CreateBeta(
             region_ref, args)
         response_msg = operations_util.WaitForOpMaybe(
             operations_client=operations.OperationsClient(),
             op=operation,
             op_ref=index_endpoints_util.ParseIndexEndpointOperation(
                 operation.name))
         if response_msg is not None:
             response = encoding.MessageToPyValue(response_msg)
             if 'name' in response:
                 log.status.Print(
                     ('Created AI Platform index endpoint: {}.').format(
                         response['name']))
         return response_msg
コード例 #19
0
def _Run(args, version):
  """Undeploy a model fro man existing Vertex AI endpoint."""
  endpoint_ref = args.CONCEPTS.endpoint.Parse()
  args.region = endpoint_ref.AsDict()['locationsId']
  with endpoint_util.AiplatformEndpointOverrides(version, region=args.region):
    endpoints_client = client.EndpointsClient(version=version)
    operation_client = operations.OperationsClient()
    if version == constants.GA_VERSION:
      op = endpoints_client.UndeployModel(
          endpoint_ref,
          args.deployed_model_id,
          traffic_split=args.traffic_split)
    else:
      op = endpoints_client.UndeployModelBeta(
          endpoint_ref,
          args.deployed_model_id,
          traffic_split=args.traffic_split)
    return operations_util.WaitForOpMaybe(
        operation_client, op, endpoints_util.ParseOperation(op.name))
コード例 #20
0
def _Run(args, version):
    """Deploy a model to an existing AI Platform endpoint."""
    validation.ValidateDisplayName(args.display_name)

    endpoint_ref = args.CONCEPTS.endpoint.Parse()
    args.region = endpoint_ref.AsDict()['locationsId']
    with endpoint_util.AiplatformEndpointOverrides(version,
                                                   region=args.region):
        endpoints_client = client.EndpointsClient(version=version)
        operation_client = operations.OperationsClient()
        op = endpoints_client.DeployModelBeta(endpoint_ref, args)
        response_msg = operations_util.WaitForOpMaybe(
            operation_client, op, endpoints_util.ParseOperation(op.name))
        if response_msg is not None:
            response = encoding.MessageToPyValue(response_msg)
            if 'deployedModel' in response and 'id' in response[
                    'deployedModel']:
                log.status.Print(('Deployed a model to the endpoint {}. '
                                  'Id of the deployed model: {}.').format(
                                      endpoint_ref.AsDict()['endpointsId'],
                                      response['deployedModel']['id']))
        return response_msg