百度智能云

All Product Document

          Cloud Compute Service

          Disk

          Create a Disk Directly

          You can create the disk by using the following codes:

          def create_volume_with_cds_size(self):
                client_token = generate_client_token()
                #Set the CDS disk capacity must be an integer greater than 0GB, and the size is 0-5120GB.
                cds_size_in_gb = 5
                # Set the billing mode
                billing = pre_paid_billing
                #The CDS disks created in batch must be an integer greater than 0, and no more than 5 CDS disks can be created at a time. Optional parameters, the default value is 1.
                purchase_cpunt = 1
                # Set cds disk storage types
                #std1: General purpose
                #hp1: High Performance
                #cloud_hp1:SSD type
                #local: Local disk
                #sata: Sata disk, which is dedicated to create the DCC sub-instance.
                #ssd: ssd disk, which is dedicated to create the DCC sub-instance.
                storage_type = 'hp1'
                #Specify the domain informations, the default is null and automatically selected by the system.
                zone_name = 'cn-bj-a'
                self.assertEqual(
                     type(self.client.create_volume_with_cds_size(cds_size_in_gb,
                                                                   billing=billing,
                                                                   purchase_count=purchase_count,
                                                                   storage_type=storage_type,
                                                                   zone_name=zone_name,
                                                                   client_token=client_token),
          
                      baidubce.bce_response.BceResponse)

          Create a CDS Disk Through Snapshot

          You can create the disk through the snapshot by using the following codes:

          def create_volume_with_snapshot_id(self):
                client_token = generate_client_token()
                #Set the CDS disk capacity must be an integer greater than 0GB, and the size is 0-5120GB.
                snapshot_id = 'your-choose-snap-shot-id'
                # Set the billing mode
                billing = pre_paid_billing
                #The CDS disks created in batch must be an integer greater than 0, and no more than 5 CDS disks can be created at a time. Optional parameters, the default value is 1.
                purchase_cpunt = 1
                #Set cds disk storage types
                #std1: General purpose
                #hp1: High Performance
                #cloud_hp1:SSD type
                #local: Local disk
                #sata: Sata disk, which is dedicated to create the DCC sub-instance.
                #ssd: ssd disk, which is dedicated to create the DCC sub-instance.
                storage_type = 'hp1'
                #Specify the domain informations, the default is null and automatically selected by the system.
                zone_name = 'cn-bj-a'
                self.assertEqual(
                      type(self.client.create_volume_with_snapshot_id(snapshot_id,
                                                                      billing=billing,
                                                                      purchase_count=purchase_count,
                                                                      storage_type=storage_type,
                                                                      zone_name=zone_name,
                                                                      client_token=client_token),
          
                      baidubce.bce_response.BceResponse)

          Query Disk List

          You can query all CDS disk lists by using the following codes:

          def list_volumes(self):
                # Query the list of disks mounted on an instance
                self.client.list_volumes(instance_id = 'your-choose-instance-id')
                #Query the list of disks in a certain domain
                self.client.list_volumes(zone_name = 'your-choose-zone-name')
                # The start position of the query for getting list by batch is a character string generated by the system.
                self.client.list_volumes(marker = 'your-marker')
                # Set the maximum number of pages per page, the default value is 1000
                self.client.list_volumes(max_keys = 100)
                print self.client.list_instances()

          Query Disk Details

          You can query the single disk details through the disk ID by using the following codes:

          def get_volume(self):
                volume_id = 'your-choose-volume-id'
                self.assertEqual(
                      type(self.client.get_volume(volume_id)), 
                      baidubce.bce_response.BceResponse)

          Mount CDS Disks

          You can mount the disk to the specified virtual machine instance by using the following code. Note: The CDS disk needs to be mounted on the virtual machine instance of the same zone.

          The mount is allowed only when the disk is in the Available status and the instance is in the Running or Stopped status.

          def attach_volume(self):
                # Set the disk ID to be mounted
                volume_id = 'your-choose-volume-id'
                # Set the disk ID to be mounted
                instance_id = 'your-choose-instance-id'  
                self.assertEqual(
                      type(self.client.attach_volume(volume_id, 
                                                     instance_id)), 
                      baidubce.bce_response.BceResponse)

          Uninstall a CDS Disk

          Uninstall a Specified Disk from Instance

          This operation can be performed for the disk only when the instance is in the Running or Stopped status:

          def detach_volume(self):
                #Set the ID of the disk to be uninstalled
                volume_id = 'your-choose-volume-id'
                #Set the mounted instance ID
                instance_id = 'your-choose-instance-id'  
                self.assertEqual(
                      type(self.client.detach_volume(volume_id, 
                                                     instance_id)), 
                      baidubce.bce_response.BceResponse)

          Rlease a CDS Disk

          It is used to release the unmounted CDS disk, while the system disk can not be released.

          The disk can not be recovered after release. All snapshots of this disk are retained by default, but the association with this disk is deleted.

          This operation can be performed only when the disk is in the Available, Expired or Error status:

          def release_volume(self):
                #Set the disk ID to be released
                volume_id = 'your-choose-volume-id'
                self.assertEqual(
                      type(self.client.release_volume(volume_id)), 
                      baidubce.bce_response.BceResponse)

          Disk Scale-up

          The disk can be scaled up only, but can not be scaled down.

          The scale-up operation can be performed only when the disk is in the Available status.

          This operation can be performed only when the disk is in the Available, Expired or Error status:

          def resize_volume(self):
                #Set the expansion disk ID
                volume_id = 'your-choose-volume-id'
                #Set the CDS disk capacity must be an integer greater than 0GB, and the size is 0-5120GB.
                resize_cds_size_in_gb = 10
                client_token = generate_client_token()   
                self.assertEqual(
                      type(self.client.resize_volume(volume_id,
                                                     resize_cds_size_in_gb,
                                                     client_token)), 
                      baidubce.bce_response.BceResponse)

          Roll Back a CDS Disk

          You can roll back the disk content by using the snapshot of specified disk itself

          This operation can be performed only when the disk is in the Available status

          The specified snapshotId must be the snapshot created by volumeId

          If the system disk is rolled back, this operation can be performed only when the instance is in the Running or Stopped status

          If the system disk snapshot is rolled back, the data of system disk since this snapshot is lost completely and can not be recovered:

          def rollback_volume(self): 
                # Disk ID to be rolled back
                # the system disk is the instance ID
                volume_id = 'your-choose-volume-id'
                #The snapshot ID used to roll back the specified disk must be the snapshot created by volumeId.
                snapshot_id = 'your-choose-snapshot-id'
                self.assertEqual(
                      type(self.client.rollback_volume(volume_id,
                                                       snapshot_id)), 
                      baidubce.bce_response.BceResponse)

          Renew Disk

          You can renew the disk by using the following codes:

          The renew operation can not be performed during the disk scaling:

          def purchase_reserved_volume(self):
                #The disk ID to be renewed
                volume_id = 'your-choose-volume-id'
                #Set the billing mode
                billing = pre_paid_billing
                client_token = generate_client_token()   
                self.assertEqual(
                      type(self.client.purchase_reserved_volume(volume_id,
                                                                billing,
                                                                client_token)), 
                      baidubce.bce_response.BceResponse)
          Previous
          image
          Next
          Version Change Records