百度智能云

All Product Document

          Cloud Compute Service

          Disk

          Create a CDS Disk

          It supports to create a blank CDS disk or create a CDS disk through the CDS data disk snapshot. You can create a CDS disk by using the following codes:

          // Create a CDS Disk
          public static void createVolume(BccClient bccClient) {
              CreateVolumeRequest createVolumeRequest = new CreateVolumeRequest();
              // Set the size of the Creating CDS disk
              createVolumeRequest.setCdsSizeInGB(cdsSizeInGb);
              // Set the number of Creating CDS disks 
              createVolumeRequest.setPurchaseCount(purchaseCount);
          
              CreateVolumeResponse createVolumeResponse = bccClient.createVolume(createVolumeRequest);
          
              System.out.println(createVolumeResponse.getVolumeIds());
          }
          
          Create a CDS disk from a snapshot
          public static void createVolumeFromSnapshot(BccClient bccClient, String snapshotId) {
              CreateVolumeRequest createVolumeRequest = new CreateVolumeRequest();
              // Set the snapshot source for creating a CDS disk
              createVolumeRequest.setSnapshotId(snapshotId);
              // Set the number for Creating CDS disks
              createVolumeRequest.setPurchaseCount(purchaseCount);
          
              CreateVolumeResponse createVolumeResponse = bccClient.createVolume(createVolumeRequest);
          
              System.out.println(createVolumeResponse.getVolumeIds());
          }

          The Create CDS Disk interface is an asynchronous interface. You can query the disk status through the Query Disk Details interface. For the interface details, see BCC API Documentation Query Disk Details.

          Query Disk List

          You can query all disk lists by using the following codes, excluding temporary data disks. It supports the paging query and filtering by the BCC instance ID mounted to this disk:

          public static void listVolumes(BccClient bccClient) {
              ListVolumesRequest listVolumesRequest = new ListVolumesRequest();
              // Set a paging flag
              listVolumesRequest.setMarker(volumeId);
              // Set the pagination return data size
              listVolumesRequest.setMaxKeys(maxKey);
              // Set the instance Bcc instance id mounted on the filtered disk
              listVolumesRequest.setInstanceId(instanceId);
          
              ListVolumesResponse listVolumesResponse = bccClient.listVolumes(listVolumesRequest);
          
              for (VolumeModel volumeModel : listVolumesResponse.getVolumes()) {
                  System.out.println(volumeModel.getId());
              }
          }

          Query Disk Details

          Use the disk ID to obtain the detailed information of the corresponding disk. You can query the disk details using the following code:

          public static void getVolumeDetail(BccClient bccClient) {
              // Set a disk id.
              GetVolumeResponse volumeResponse = bccClient.getVolume(volumeId);
              System.out.println(volumeResponse.getVolume().getId());
          }

          Mount CDS Disks

          You can mount the unmounted disk to the corresponding BCC virtual machine. You can mount a CDS disk to the corresponding BCC virtual machine by using the following codes:

          public static void attachVolume(BccClient bccClient) {
              AttachVolumeRequest attachVolumeRequest = new AttachVolumeRequest();
              // Set the disk id to be mounted
              attachVolumeRequest.setVolumeId(volumeId);
              // Set BCC virtual machine id
              attachVolumeRequest.setInstanceId(instanceId);
              // Print mount paths
              System.out.println(bccClient.attachVolume(attachVolumeRequest).getVolumeAttachment().getDevice());
          }
          • The CDS disk needs to be mounted on the virtual machine instance of the same zone. Otherwise, it prompts an error 403.
          • The mount is allowed only when the disk is in the Available status and the instance is in the Running or Stopped status. Otherwise, it prompts an error 409 when you call this interface.

          Uninstall a CDS Disk

          You can uninstall the mounted disk from the corresponding BCC virtual machine. You can uninstall the CDS disk by using the following codes:

          public static void detachVolume(BccClient bccClient) {
              DetachVolumeRequest detachVolumeRequest = new DetachVolumeRequest();
              // Set corresponding ID of disk to uninstall
              detachVolumeRequest.setVolumeId(volumeId);
              // Set the mounted instance ID
              detachVolumeRequest.setInstanceId(instanceId);
              // Carry out uninstall operation
              bccClient.detachVolume(detachVolumeRequest);
          }
          • This operation can be performed for the disk only when the instance is in the Running or Stopped status. Otherwise, it prompts an error 409.
          • If the disk with volumeid is not mounted to the instance with instanceId, this operation fails and it prompts an error 404.

          Rlease a CDS Disk

          It is used to release the unmounted CDS disk, and specify whether the snapshot associated with the disk is deleted. All snapshots of this disk are retained by default, but the association with this disk is deleted:

          public static void releaseVolume(BccClient bccClient) {
          
              ReleaseVolumeRequest releaseVolumeRequest = new ReleaseVolumeRequest();
          
              // Set a disk id.
          
              releaseVolumeRequest.setVolumeId(volumeId);
          
              // To release the disk-associated snapshot, add the following codes the parameters are "on" and "off"
          
              // To delete the disk-associated automatic snapshot, set the parameter to "on", otherwise default to "off"
          
               releaseVolumeRequest.setAutoSnapshot("on");
          
              // To delete the disk-associated manual snapshot, set the parameter to "on", otherwise default to "off"
          
               releaseVolumeRequest.setManualSnapshot("on");
          
               bccClient.releaseVolume(releaseVolumeRequest);
          
          }
          • The mounted CDS disk can not be released, and 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 or Expired or Error status. Otherwise, it prompts an error 409.

          Modify the Disk Attribute

          You can modify the specified disk name and the description information by using the following codes:

          public static void modifyCdsAttribute(BccClient bccClient) {
          
              ModifyCdsAttributeRequest modifyCdsAttributeRequest = new ModifyCdsAttributeRequest();
          
              // Set a disk id.
          
              modifyCdsAttributeRequest.setCdsId(volumeId);
          
              // Set a disk name
          
               modifyCdsAttributeRequest.setCdsName(volumeName);
          
              // Set new description information of disk
          
                modifyCdsAttributeRequest.setDesc(volumeDesc);
          
                bccClient.modifyCdsAttribute(modifyCdsAttributeRequest);
          
          }

          Change the Disk Billing Mode

          You can change the disk Billing Mode by using the following code. It supports to change the postpaid mode to prepaid mode and the prepaid mode to postpaid mode only. To change to the prepaid mode, you need to specify the duration of purchase.

          public static void modifyVolumeChargeType(BccClient bccClient) {
          
              ModifyVolumeChargeRequest modifyVolumeChargeRequest = new ModifyVolumeChargeRequest();
          
              // Set a disk id.
          
              modifyVolumeChargeRequest.setVolumeId(volumeId);
          
              // Set a new billing method to prepaid
          
               modifyVolumeChargeRequest.setBillingMethod("prepay");
          
              // Set a new billing method as postpaid
          
               modifyVolumeChargeRequest.setBillingMethod("postpay");
          
              // Set purchase duration (month)
          
               modifyVolumeChargeRequest.setReservationLength(reservationLength);
          
               bccClient.modifyVolumeChargeType(modifyVolumeChargeRequest);
          
          }

          Disk Scale-up

          You can scale up the disk by using the following codes:

          public static void resizeVolume(BccClient bccClient) {
              ResizeVolumeRequest resizeVolumeRequest = new ResizeVolumeRequest();
              // Set a disk id.
              resizeVolumeRequest.setVolumeId(volumeId);
              // Set total disk after scale up
              resizeVolumeRequest.setNewCdsSizeInGB(cdsResizeInGb);
              // Carry out the disk scale-up
              bccClient.resizeVolume(resizeVolumeRequest);
          }

          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. The disk scale-up is an asynchronous interface, and you can query the disk scale-up status through the Query Disk Details nterface.

          Roll Back a CDS Disk

          You can roll back the disk content by using the snapshot of specified disk itself. You can roll back the disk by using the following codes:

          public static void rollbackVolume(BccClient bccClient) {
              RollbackVolumeRequest rollbackVolumeRequest = new RollbackVolumeRequest();
              // Set a disk id.
              rollbackVolumeRequest.setVolumeId(volumeId);
              // Set the snapshot id of the disk
              rollbackVolumeRequest.setSnapshotId(snapshotId);
              // Carru out a rollback operation
              bccClient.rollbackVolume(rollbackVolumeRequest);
          }
          • This disk rollback operation can be performed only when the disk is in the Available status.
          • The specified snapshot ID must be a snapshot created by this disk ID.
          • 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.

          Renew Disk

          The renew operation of the disk can extend the expiration date. You can renew the disk by using the following codes:

          public static void purchaseReservedVolume(BccClient bccClient) {
              PurchaseReservedVolumeRequest purchaseReservedVolumeRequest = new PurchaseReservedVolumeRequest();
              // Set a disk id.
              purchaseReservedVolumeRequest.setVolumeId(volumeId);
              // Set billing informations
              Billing billing = new Billing();
              // Set the renewal duration, the unit currently only supports 'month' as the unit
              billing.setReservation(new Reservation().withReservationLength(reservationLength));
              // Set billing informations
              purchaseReservedVolumeRequest.setBilling(billing);
              // Carry out a renewal disk operation
              bccClient.purchaseReservedVolume(purchaseReservedVolumeRequest);
          }
          Previous
          BCC Instance
          Next
          Image