百度智能云

All Product Document

          Cloud Compute Service

          Image

          Create a Custom Image Through Instance

          • It is used to create a custom image. The quota is 20 custom images for each account by default. The created image can be used to create an instance.
          • This operation can be performed only when the instance is in the Running or Stopped status.
          • It is only limited to create a custom mirror through the system disk snapshot:

            def create_image_from_instance_id(self):
            
                client_token = generate_client_token()
            
                # Set a created image name
                image_name = 'your-image-name' + client_token
            
                # Instance ID for creating image
                instance_id='your-choose-instance-id'
            
                self.assertEqual(
                      type(self.client.create_image_from_instance_id(image_name,instance_id=instance_id,client_token=client_token)), 
            
                      baidubce.bce_response.BceResponse)

          Create a Custom Image Through Snapshot

          When you create a custom image through the snapshot, this operation can be performed only when the snapshot is in the Available status:

          def create_image_from_snapshot_id(self):
          
                client_token = generate_client_token()
          
                # Set a created image name
                image_name = 'your-image-name' + client_token
          
                # Snapshot ID for creating image
                snapshot_id='your-choose-snapshot-id'
          
                self.assertEqual(
                      type(self.client.create_image_from_snapshot_id(image_name,snapshot_id=snapshot_id,client_token=client_token)), 
          
                      baidubce.bce_response.BceResponse)

          Querye a Image List

          It is used to query all image information of users.

          The queried image information includes system image, custom image and service integration image.

          It supports to filter the query results by imageType. This parameter is not required. If it is not set, it is All by default, i.e., query all types of images:

          def list_images(self):
          
                #Specify what type of image to query
                #All (All)
                #System (System Image/Public image)
                # Custom (Custom Image)
                #Integration(Service integration image)
                #Sharing (shared image)
                # GpuBccSystem (GPU dedicated public image)
                #GpuBccCustom(GPU dedicated custom Image)
                #FpgaBccSystem(FPGA dedicated public image)
                #FpgaBccCustom(FPGA dedicated custom Image) 
          
                image_type = 'All'
          
                # Start position of the query for getting list by batch 
                marker = 'your-marker'
          
                # Maximum number of master instances per page
                max_keys = 100
          
                self.assertEqual(
          
                      type(self.client.list_images(image_type=image_type,marker=marker,max_keys=max_keys)), 
          
                      baidubce.bce_response.BceResponse)

          Query Image Details

          It is used to query the single image details through the specified image ID:

          def get_image(self): 
          
                #Image ID to be queried
                image_id='your-choose-image-id'
          
                self.assertEqual(
          
                      type(self.client.get_image(image_id)), 
          
                      baidubce.bce_response.BceResponse)

          Delete a Custom Image

          It is used to delete the custom image, which is only limited to the custom image. The system image and service integration image can not be deleted.

          The deleted image can not be recovered or used to create or reset the instance:

          def delete_image(self): 
          
                #Image ID to be deleted
                image_id='your-choose-image-id'
          
                self.assertEqual(
          
                      type(self.client.delete_image(image_id)), 
          
                      baidubce.bce_response.BceResponse)

          Cross-region Replication of Images (New)

          It is used for users to replicate the custom images across regions, which is only limited to the custom image. The system image and service integration image can not be replicated:

          def remote_copy_image(self): 
          
                # Set the image ID to be copied
                image_id = 'your-choose-image-id'
          
                # Set destination region id, you can set multiple regions.
                destRegions = ['bd', 'su']
          
                # Set a replication image name
                remote_image_name = 'new-remote-image'
          
                self.assertEqual(
                      type(self.client.remote_copy_image(image_id=image_id,
                                                         name=remote_image_name,
                                                         destRegions=destRegions)), 
          
                      baidubce.bce_response.BceResponse)

          Cancel the Cross-region Replication of Images (New)

          It is used to cancel the cross-region replication of custom image:

          def cancle_remote_copy_image(self): 
          
                # Set a image id
                image_id = 'your-choose-image-id'
          
                self.assertEqual(
                      type(self.client.cancle_remote_copy_image(image_id=image_id)), 
          
                      baidubce.bce_response.BceResponse)

          Share a Custom Image (New)

          It is used to share the custom image, which is only limited to the custom image. The system image and service integration image can not be shared:

          def share_image(self): 
          
                #Image id to be shared
                image_id = 'your-choose-image-id'
          
                #User’s id to be shared
                account_id = 'your-choose-account-id'
          
                self.assertEqual(
          
                      type(self.client.share_image(image_id=image_id,account_id=account_id)), 
          
                      baidubce.bce_response.BceResponse)

          Cancel a Shared Custom Image (New)

          It is used to cancel the shared custom image:

          def unshare_image(self): 
          
                # The Shared Image id to be canceled
                image_id = 'your-choose-image-id'
          
                # User’s shared id to be shared
                account_id = 'your-choose-account-id'
          
                self.assertEqual(
          
                      type(self.client.unshare_image(image_id=image_id,account_id=account_id)), 
          
                      baidubce.bce_response.BceResponse)

          Query the Shared User List (New)

          It is used to query the share user list of images:

          def list_shared_user(self): 
          
                #Image id to be queried
                image_id = 'your-choose-image-id'
          
                self.assertEqual(
                      type(self.client.list_shared_user(image_id=image_id)), 
          
                      baidubce.bce_response.BceResponse)

          Batch Query the OS Information by Short Instance ID (New)

          It is used to batch query the OS information through the short instance ID:

          def list_os(self): 
          
                # Instance id to be queried
                instance_id1 = 'your-choose-instance-id1'
                instance_id2 = 'your-choose-instance-id2'
          
                instance_ids = []
          
                instance_ids.append(instance_id1, instance_id2)
          
                self.assertEqual(
          
                      type(self.client.list_os(instance_ids=instance_ids)), 
          
                      baidubce.bce_response.BceResponse)
          Previous
          Disk
          Next
          Snapshot