Disk
Create a CDS disk
Support creating a blank CDS disk or creating a CDS disk from a CDS data disk snapshot. You can create a CDS disk by referring to the following code:
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.BccClient;
5import com.baidubce.services.bcc.BccClientConfiguration;
6import com.baidubce.services.bcc.model.Billing;
7import com.baidubce.services.bcc.model.StorageType;
8import com.baidubce.services.bcc.model.volume.CreateVolumeRequest;
9import com.baidubce.services.bcc.model.volume.CreateVolumeResponse;
10public class Main {
11 public static void main(String[] args) {
12 // Set your AK, SK and the endpoint to be accessed
13 String endpoint = "bcc.bj.baidubce.com";
14 String ak = "ak";
15 String sk = "sk";
16 // Set default configuration
17 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
18 .withProtocol(Protocol.HTTP)
19 .withCredentials(new DefaultBceCredentials(ak, sk))
20 .withEndpoint(endpoint);
21 // Create a BCC client
22 BccClient client = new BccClient(bccClientConfiguration);
23
24 CreateVolumeRequest request = new CreateVolumeRequest()
25
26 .withChargeType("Postpaid") // Charge type
27 .withCdsSizeInGB(5) // Disk size
28 .withStorageType(StorageType.hdd.name()) // Storage class
29 .withPurchaseCount(2) // Purchase count
30 .withZoneName("cn-bj-c"); // Availability zone
31 CreateVolumeResponse response = client.createVolume(request);
32 System.out.println(response.getVolumeIds());
33 }
34}
Create CDS disk from snapshot
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.BccClient;
5import com.baidubce.services.bcc.BccClientConfiguration;
6import com.baidubce.services.bcc.model.Billing;
7import com.baidubce.services.bcc.model.Reservation;
8import com.baidubce.services.bcc.model.StorageType;
9import com.baidubce.services.bcc.model.volume.CreateVolumeRequest;
10import com.baidubce.services.bcc.model.volume.CreateVolumeResponse;
11public class Main {
12 public static void main(String[] args) {
13 // Set your AK, SK and the endpoint to be accessed
14 String endpoint = "bcc.bj.baidubce.com";
15 String ak = "ak";
16 String sk = "sk";
17 // Set default configuration
18 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
19 .withProtocol(Protocol.HTTP)
20 .withCredentials(new DefaultBceCredentials(ak, sk))
21 .withEndpoint(endpoint);
22 // Create a BCC client
23 BccClient client = new BccClient(bccClientConfiguration);
24 CreateVolumeRequest request = new CreateVolumeRequest()
25
26 .withChargeType("Postpaid") // Charge type
27 .withReservation(new Reservation().withReservationLength(2).withReservationTimeUnit("month")))
28 .withSnapshotId("s-4CMA****") //Snapshot ID
29 .withPurchaseCount(1) // Creation count
30 .withZoneName("cn-bj-a"); // Availability zone;
31 CreateVolumeResponse response = client.createVolume(request);
32 System.out.println(response.getVolumeIds());
33 }
34}
The CDS disk creation API is asynchronous. You can query the disk status through the [Query Disk Details](#Query disk details) API. For detailed use of the API, please refer to the BCC API documentation [Query Disk Details](BCC/API Reference/Disk Related Interfaces/Query disk details.md)
Query the disk list
You can query all disk lists, excluding temporary data disks, with the following code. Support pagination queries and filtering based on the BCC instance ID to which the cloud disk server is attached:
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.BccClient;
5import com.baidubce.services.bcc.BccClientConfiguration;
6import com.baidubce.services.bcc.model.volume.ListVolumesRequest;
7import com.baidubce.services.bcc.model.volume.ListVolumesResponse;
8public class Main {
9 public static void main(String[] args) {
10 // Set your AK, SK and the endpoint to be accessed
11 String endpoint = "bcc.bj.baidubce.com";
12 String ak = "ak";
13 String sk = "sk";
14 // Set default configuration
15 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
16 .withProtocol(Protocol.HTTP)
17 .withCredentials(new DefaultBceCredentials(ak, sk))
18 .withEndpoint(endpoint);
19 // Create a BCC client
20 BccClient client = new BccClient(bccClientConfiguration);
21 ListVolumesRequest listVolumesRequest = new ListVolumesRequest()
22 .withZoneName("cn-bj-c") // Availability zone
23 .withInstanceId("i-lC39****") // Instance ID
24 .withMarker("v-ePrp****") //Starting volume ID
25 .withMaxKeys(10); //Maximum number of returned items
26 ListVolumesResponse response = client.listVolumes(listVolumesRequest);
27 System.out.println(response);
28 }
29}
Query disk details
You can retrieve detailed information about a specific disk with its disk ID, and you can query disk details with the following code:
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.BccClient;
5import com.baidubce.services.bcc.BccClientConfiguration;
6import com.baidubce.services.bcc.model.volume.GetVolumeRequest;
7import com.baidubce.services.bcc.model.volume.GetVolumeResponse;
8public class Main {
9 public static void main(String[] args) {
10 // Set your AK, SK and the endpoint to be accessed
11 String endpoint = "bcc.bj.baidubce.com";
12 String ak = "ak";
13 String sk = "sk";
14 // Set default configuration
15 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
16 .withProtocol(Protocol.HTTP)
17 .withCredentials(new DefaultBceCredentials(ak, sk))
18 .withEndpoint(endpoint);
19 // Create a BCC client
20 BccClient client = new BccClient(bccClientConfiguration);
21 GetVolumeRequest getVolumeRequest = new GetVolumeRequest()
22 .withVolumeId("v-ePrp****"); //Specify volume ID
23 GetVolumeResponse response = client.getVolume(getVolumeRequest);
24 System.out.println(response);
25 }
26}
Attach a CDS disk
You can attach an unattached cloud disk to a corresponding BCC instance. You can attach a CDS to the corresponding BCC instance with the following code:
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.BccClient;
5import com.baidubce.services.bcc.BccClientConfiguration;
6import com.baidubce.services.bcc.model.instance.StopInstanceRequest;
7import com.baidubce.services.bcc.model.volume.AttachVolumeRequest;
8public class AttachVolume {
9 public static void main(String[] args) {
10 // Set your AK, SK and the endpoint to be accessed
11 String endpoint = "http://bcc.bj.baidubce.com";
12 String ak = "ak";
13 String sk = "sk";
14 // Set default configuration
15 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
16 .withProtocol(Protocol.HTTP)
17 .withCredentials(new DefaultBceCredentials(ak, sk))
18 .withEndpoint(endpoint);
19 // Create a BCC client
20 BccClient client = new BccClient(bccClientConfiguration);
21 AttachVolumeRequest attachVolumeRequest = new AttachVolumeRequest();
22 // Set disk ID to be attached
23 attachVolumeRequest.setVolumeId("v-***");
24 // Set BCC virtual machine ID
25 attachVolumeRequest.setInstanceId("i-***");
26 // Print attaching path
27 System.out.println(client.attachVolume(attachVolumeRequest).getVolumeAttachment().getDevice());
28 }
29}
- The CDS disk must be attached to a BCC instance located in the same zone; otherwise, a 403 error will occur.
- Mounting is only permitted when the disk status is "Available" and the instance status is either "Running" or "Stopped." Otherwise, calling this API will result in a 409 error.
Detach a CDS disk
You can detach an already attached disk from its corresponding BCC instance. Detach a CDS disk with the following code:
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.BccClient;
5import com.baidubce.services.bcc.BccClientConfiguration;
6import com.baidubce.services.bcc.model.volume.DetachVolumeRequest;
7public class DetachVolume {
8 public static void main(String[] args) {
9 // Set your AK, SK and the endpoint to be accessed
10 String endpoint = "http://bcc.bj.baidubce.com";
11 String ak = "ak";
12 String sk = "sk";
13 // Set default configuration
14 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
15 .withProtocol(Protocol.HTTP)
16 .withCredentials(new DefaultBceCredentials(ak, sk)).withEndpoint(endpoint);
17 // Create a BCC client
18 BccClient client = new BccClient(bccClientConfiguration);
19 DetachVolumeRequest detachVolumeRequest = new DetachVolumeRequest();
20 // Set ID of the disk to be detached
21 detachVolumeRequest.setVolumeId("v-***");
22 // Set instance ID to which the disk will be attached
23 detachVolumeRequest.setInstanceId("i-***");
24 // Execute detaching operation
25 client.detachVolume(detachVolumeRequest);
26 }
27}
- This operation can only be performed when the instance is in the Running or Stopped state; otherwise, a 409 error will occur.
- If the disk with the given volumeId is not attached to the instance with the given instanceId, the operation will fail, and a 404 error will occur.
Release a CDS disk
You can release detached CDS disks with the following code:
- Users can decide whether to delete snapshots associated with the disk. By default, all snapshots will be retained, although they will no longer be linked to the disk.
- You can choose whether to move the disk to the recycle bin; by default, it will be placed in the recycle bin.
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.BccClient;
5import com.baidubce.services.bcc.BccClientConfiguration;
6import com.baidubce.services.bcc.model.volume.ReleaseVolumeRequest;
7import java.util.ArrayList;
8import java.util.List;
9public class Main {
10 public static void main(String[] args) {
11 // Set your AK, SK and the endpoint to be accessed
12 String endpoint = "bcc.bj.baidubce.com";
13 String ak = "ak";
14 String sk = "sk";
15 // Set default configuration
16 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
17 .withProtocol(Protocol.HTTP)
18 .withCredentials(new DefaultBceCredentials(ak, sk))
19 .withEndpoint(endpoint);
20 // Create a BCC client
21 BccClient client = new BccClient(bccClientConfiguration);
22
23 // Release disk
24 // Request parameters
25 ReleaseVolumeRequest request = new ReleaseVolumeRequest();
26 // Disk ID
27 request.setVolumeId("v-***");
28 // Whether to delete automatic snapshots associated with the disk
29 request.setAutoSnapshot("on");
30 // Whether to delete manual snapshots associated with the disk
31 request.setManualSnapshot("on");
32 // Whether to move the disk to the recycle bin; if set to off, the disk will be released directly without entering the recycle bin
33 request.setRecycle("off");
34 client.releaseVolume(request);
35 }
36}
- An attached CDS disk cannot be released, and system disks cannot be released either.
- After a disk is released, it cannot be recovered. By default, all disk snapshots will be kept, but their association with the disk will be removed.
- This operation can only be executed when the disk status is "Available," "Expired," or "Error." Otherwise, a 409 error will be returned.
Modify disk properties
You can modify the name and description of a specified disk with the following code:
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.BccClient;
5import com.baidubce.services.bcc.BccClientConfiguration;
6import com.baidubce.services.bcc.model.volume.ModifyCdsAttrRequest;
7public class Main {
8 public static void main(String[] args) {
9 // Set your AK, SK and the endpoint to be accessed
10 String endpoint = "bcc.bj.baidubce.com";
11 String ak = "ak";
12 String sk = "sk";
13 // Set default configuration
14 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
15 .withProtocol(Protocol.HTTP)
16 .withCredentials(new DefaultBceCredentials(ak, sk))
17 .withEndpoint(endpoint);
18 // Create a BCC client
19 BccClient client = new BccClient(bccClientConfiguration);
20 ModifyCdsAttrRequest modifyCdsAttributeRequest = new ModifyCdsAttrRequest;
21 // Set disk ID
22 modifyCdsAttributeRequest.setCdsId("v-dj5Q****");
23 // Set new disk name
24 modifyCdsAttributeRequest.setCdsName("volumeName");
25 // Set new disk description
26 modifyCdsAttributeRequest.setDesc("volumeDesc");
27 client.modifyCdsAttribute(modifyCdsAttributeRequest);
28 }
29}
Shift charge for disks
You can change the disk charge type using the code provided below. Two conversions are supported: from pay-as-you-go (postpay) to subscription (prepay) and vice versa. When switching to subscription (prepay), you must specify the purchase period.
You can change the charge type of a subscribed (prepaid) disk to a pay-as-you-go (postpaid) disk with the following code:
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.BccClient;
5import com.baidubce.services.bcc.BccClientConfiguration;
6import java.util.ArrayList;
7import java.util.List;
8public class Main {
9 public static void main(String[] args) {
10 // Set your AK, SK and the endpoint to be accessed
11 String endpoint = "bcc.bj.baidubce.com";
12 String ak = "ak";
13 String sk = "sk";
14 // Set default configuration
15 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
16 .withProtocol(Protocol.HTTP)
17 .withCredentials(new DefaultBceCredentials(ak, sk))
18 .withEndpoint(endpoint);
19 // Create a BCC client
20 BccClient client = new BccClient(bccClientConfiguration);
21
22 // Change a prepaid disk to postpaid
23 // Request parameters
24 ModifyVolumeChargeRequest request = new ModifyVolumeChargeRequest();
25 // Disk ID
26 request.setVolumeId("v-***");
27 // Charge type, current value: postpay, which can be omitted
28 request.setBillingMethod("postpay");
29 client.modifyVolumeChargeType(request);
30 }
31}
You can change a pay-as-you-go (postpaid) disk to a subscribed (prepaid) disk with the following code:
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.BccClient;
5import com.baidubce.services.bcc.BccClientConfiguration;
6import java.util.ArrayList;
7import java.util.List;
8public class Main {
9 public static void main(String[] args) {
10 // Set your AK, SK and the endpoint to be accessed
11 String endpoint = "bcc.bj.baidubce.com";
12 String ak = "ak";
13 String sk = "sk";
14 // Set default configuration
15 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
16 .withProtocol(Protocol.HTTP)
17 .withCredentials(new DefaultBceCredentials(ak, sk))
18 .withEndpoint(endpoint);
19 // Create a BCC client
20 BccClient client = new BccClient(bccClientConfiguration);
21
22 // Change the postpaid disk to the prepaid disk
23 // Request parameters
24 ModifyVolumeChargeRequest request = new ModifyVolumeChargeRequest();
25 // Disk ID
26 request.setVolumeId("v-***");
27 // Charge type, current value: prepay, which can be omitted
28 request.setBillingMethod("prepay");
29 // When changing to prepay, specify the prepaid duration, currently supporting months as the unit, with a range of 1 - 9
30 request.setReservationLength(1);
31 client.modifyVolumeChargeType(request);
32 }
33}
Disk expansion and resizing
You can expand disk size or change disk type with the following code:
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.BccClient;
5import com.baidubce.services.bcc.BccClientConfiguration;
6import com.baidubce.services.bcc.model.volume.ResizeVolumeRequest;
7import java.util.ArrayList;
8import java.util.List;
9public class Main {
10 public static void main(String[] args) {
11 // Set your AK, SK and the endpoint to be accessed
12 String endpoint = "bcc.bj.baidubce.com";
13 String ak = "ak";
14 String sk = "sk";
15 // Set default configuration
16 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
17 .withProtocol(Protocol.HTTP)
18 .withCredentials(new DefaultBceCredentials(ak, sk))
19 .withEndpoint(endpoint);
20 // Create a BCC client
21 BccClient client = new BccClient(bccClientConfiguration);
22 // Request to change disk type and size
23 ResizeVolumeRequest request = new ResizeVolumeRequest();
24 // Disk ID
25 request.setVolumeId("v-***");
26 // Disk size, in GB
27 request.setNewCdsSizeInGB(50);
28 // Disk type, see https://cloud.baidu.com/doc/BCC/s/6jwvyo0q2#storagetype for value range
29 request.setNewVolumeType("cloud_hp1");
30 client.resizeVolume(request);
31 }
32}
Disks can only be expanded; contraction is not supported. Only disks in the "Available" status can undergo expansion operations. Disk expansion is executed by an asynchronous API; the disk expansion status can be queried through the [Query Disk Details](#Query disk details) API.
Roll back disk data
You can use a snapshot of the specified disk itself to roll back disk data, and you can perform disk data rollback with the following code:
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.BccClient;
5import com.baidubce.services.bcc.BccClientConfiguration;
6import com.baidubce.services.bcc.model.volume.RollbackVolumeRequest;
7public class Main {
8 public static void main(String[] args) {
9 // Set your AK, SK and the endpoint to be accessed
10 String endpoint = "bcc.bj.baidubce.com";
11 String ak = "ak";
12 String sk = "sk";
13 // Set default configuration
14 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
15 .withProtocol(Protocol.HTTP)
16 .withCredentials(new DefaultBceCredentials(ak, sk))
17 .withEndpoint(endpoint);
18 // Create a BCC client
19 BccClient client = new BccClient(bccClientConfiguration);
20 RollbackVolumeRequest rollbackVolumeRequest = new RollbackVolumeRequest();
21 // Set disk ID
22 rollbackVolumeRequest.setVolumeId("v-zBms****");
23 // Set disk snapshot ID
24 rollbackVolumeRequest.setSnapshotId("s-HkbJ****");
25 // Execute rollback operation
26 client.rollbackVolume(rollbackVolumeRequest);
27 }
28}
- The disk must be in the "Available" status to initiate a rollback.
- The snapshot ID specified must originate from the same disk ID.
- When rolling back a system disk, ensure the instance status is either Running or Stopped before initiating this operation.
- When rolling back a system disk snapshot, all data generated on the system disk after the snapshot was created will be completely lost and cannot be recovered.
Renew a disk
Renewing a disk extends its expiration duration. You can renew a disk with the following code:
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.BccClient;
5import com.baidubce.services.bcc.BccClientConfiguration;
6import com.baidubce.services.bcc.model.Billing;
7import com.baidubce.services.bcc.model.Reservation;
8import com.baidubce.services.bcc.model.volume.PurchaseReservedVolumeRequest;
9public class Main {
10 public static void main(String[] args) {
11 // Set your AK, SK and the endpoint to be accessed
12 String endpoint = "bcc.bj.baidubce.com";
13 String ak = "ak";
14 String sk = "sk";
15 // Set default configuration
16 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
17 .withProtocol(Protocol.HTTP)
18 .withCredentials(new DefaultBceCredentials(ak, sk))
19 .withEndpoint(endpoint);
20 // Create a BCC client
21 BccClient client = new BccClient(bccClientConfiguration);
22 PurchaseReservedVolumeRequest purchaseReservedVolumeRequest = new PurchaseReservedVolumeRequest();
23 // Set disk ID
24 purchaseReservedVolumeRequest.setVolumeId("v-dj5Q****");
25 // Set billing information
26 Billing billing = new Billing();
27 // Set renewal period, currently only supporting 'month' as the unit
28 billing.setReservation(new Reservation().withReservationLength(1));
29 billing.setPaymentTiming("Prepaid");
30 // Set billing information
31 purchaseReservedVolumeRequest.setBilling(billing);
32 // Execute disk renewal operation
33 client.purchaseReservedVolume(purchaseReservedVolumeRequest);
34 }
35}
Enable automatic renewal for disks
You can enable automatic renewal for a specified disk with the following code:
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.BccClient;
5import com.baidubce.services.bcc.BccClientConfiguration;
6import com.baidubce.services.bcc.model.volume.AutoRenewVolumeRequest;
7import java.util.ArrayList;
8import java.util.List;
9public class Main {
10 public static void main(String[] args) {
11 // Set your AK, SK and the endpoint to be accessed
12 String endpoint = "bcc.bj.baidubce.com";
13 String ak = "ak";
14 String sk = "sk";
15 // Set default configuration
16 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
17 .withProtocol(Protocol.HTTP)
18 .withCredentials(new DefaultBceCredentials(ak, sk))
19 .withEndpoint(endpoint);
20 // Create a BCC client
21 BccClient client = new BccClient(bccClientConfiguration);
22
23 AutoRenewVolumeRequest req = new AutoRenewVolumeRequest();
24 // Disk ID
25 req.setVolumeId("v-***");
26 // Unit of renewal time, current value: month
27 req.setRenewTimeUnit("month");
28 // Renewal time, in month. Value range: 1-9
29 req.setRenewTime(3);
30 client.autoRenewVolume(req);
31 }
32}
33}
- Note: Auto-renewal operation is allowed for data disks only
- Note: Auto-renewal operation is not allowed for disks in an expired status
- Asynchronous API; the disk expiration time can be queried through the [Query Disk Details](#Query disk details) API
Disable automatic renewal for disks
You can disable auto-renewal for a specified disk with the following code
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.BccClient;
5import com.baidubce.services.bcc.BccClientConfiguration;
6import com.baidubce.services.bcc.model.volume.CancelAutoRenewVolumeRequest;
7import java.util.ArrayList;
8import java.util.List;
9public class Main {
10 public static void main(String[] args) {
11 // Set your AK, SK and the endpoint to be accessed
12 String endpoint = "bcc.bj.baidubce.com";
13 String ak = "ak";
14 String sk = "sk";
15 // Set default configuration
16 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
17 .withProtocol(Protocol.HTTP)
18 .withCredentials(new DefaultBceCredentials(ak, sk))
19 .withEndpoint(endpoint);
20 // Create a BCC client
21 BccClient client = new BccClient(bccClientConfiguration);
22
23 CancelAutoRenewVolumeRequest req = new CancelAutoRenewVolumeRequest();
24 req.setVolumeId("v-***"); // Disk ID
25 client.cancelAutoRenewVolume(req);
26 }
27}
- Note: Auto-renewal disabling is allowed for data disks only
- Asynchronous API; the disk expiration time can be queried through the [Query Disk Details](#Query disk details) API
Rename a disk
You can modify the name of a specified disk with the following code:
1import com.baidubce.BceClientConfiguration;
2import com.baidubce.Protocol;
3import com.baidubce.auth.DefaultBceCredentials;
4import com.baidubce.services.bcc.BccClient;
5import com.baidubce.services.bcc.BccClientConfiguration;
6import com.baidubce.services.bcc.model.volume.RenameVolumeRequest;
7public class Main {
8 public static void main(String[] args) {
9 // Set your AK, SK and the endpoint to be accessed
10 String endpoint = "bcc.bj.baidubce.com";
11 String ak = "ak";
12 String sk = "sk";
13 // Set default configuration
14 BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
15 .withProtocol(Protocol.HTTP)
16 .withCredentials(new DefaultBceCredentials(ak, sk))
17 .withEndpoint(endpoint);
18 // Create a BCC client
19 BccClient client = new BccClient(bccClientConfiguration);
20 RenameVolumeRequest renameVolumeRequest = new RenameVolumeRequest();
21 // ID of disk to be renamed
22 renameVolumeRequest.setVolumeId("v-1YgO****");
23 // New disk name, custom image name, which supports uppercase and lowercase letters, numbers, Chinese characters, and -_/special characters, starting with a letter and a length of 1-65.
24 renameVolumeRequest.setName("newName");
25 client.renameVolume(renameVolumeRequest);
26 }
27}
