Image
Create a Custom Image
It supports to create the custom image through the instance or the snapshot. You can create a custom image by using the following codes:
// Create a custom Image with Instance
public static void createImageFromInstance(BccClient bccClient, String imageName, String instanceId) {
CreateImageRequest createImageRequest = new CreateImageRequest();
// Set a custom image name
createImageRequest.setImageName(imageName);
// Set a virtual machine id of BCC
createImageRequest.setInstanceId(instanceId);
System.out.println(bccClient.createImage(createImageRequest).getImageId());
}
Create a custom Image with snapshot
public static void createImageFromSnapshot(BccClient bccClient, String imageName, String snapshotId) {
CreateImageRequest createImageRequest = new CreateImageRequest();
// Set a custom image name
createImageRequest.setImageName(imageName);
// Set a snapshot id
createImageRequest.setSnapshotId(snapshotId);
System.out.println(bccClient.createImage(createImageRequest).getImageId());
}
Note: Create a custom image, whose quota is 20 per account number by default.
Querye a Image List
You can query the image list with privilege by using the following codes:
public static void listImage(BccClient bccClient, String imageType) {
ListImagesRequest listImagesRequest = new ListImagesRequest();
// Set a paging mark
listImagesRequest.setMarker(imageId);
// Set the pagination return data size
listImagesRequest.setMaxKeys(maxKey);
// Set filtered image types
listImagesRequest.setImageType(imageType);
ListImagesResponse listImagesResponse = bccClient.listImages();
for (ImageModel imageModel : listImagesResponse.getImages()) {
System.out.println(imageModel.getId());
}
}
For the specific image type, see BCC API Documentation Query Image List.
Query Image Details
You can query the image details by using the following codes:
public static void getImage(BccClient bccClient, String imageId) {
GetImageResponse getImageResponse = bccClient.getImage(imageId);
System.out.println(getImageResponse.getImage().getName());
}
Delete a Custom Image
You can delete a custom image by using the following codes:
public static void deleteImage(BccClient bccClient, String imageId) {
bccClient.deleteImage(imageId);
}
Cross-region Replication of Custom Image
This API is used for the cross-region replication of custom image, which is only limited to the custom image. The system image and service integration image can not be replicated.
Regions may be multiple selections, such as "bj", "gz" and "su":
public static void remoteCopyImage(BccClient bccClient, String destImageId, String imageName, ArrayList<String> regions) {
RemoteCopyImageRequest remoteCopyImageRequest = new RemoteCopyImageRequest();
// Image ID to copy
remoteCopyImageRequest.setImageId(destImageId);
// Set a image name
remoteCopyImageRequest.setname(imageName);
// destination regionId
remoteCopyImageRequest.setDestRegion(regions);
bccClient.remoteCopyImage(remoteCopyImageRequest);
}
Cancel the Cross-region Replication of Custom Image
This API is used to cancel the cross-region replication of custom image, which is only limited to the custom image. The system image and service integration image can not be replicated:
public static void cancelRemoteCopyImage(BccClient bccClient, String imageId) {
//Copied image ID to be canceled
bccClient.cancelRemoteCopyImage(destImageId);
}
Share a Custom Image
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:
public static void shareImage(BccClient bccClient, String accountId, String imageId) {
ShareImageRequest shareImageRequest = new ShareImageRequest();
// User ID to share
shareImageRequest.setAccountId(accountId);
// Image ID to share
shareImageRequest.setImageId(imageId);
bccClient.shareImage(shareImageRequest);
}
Cancel the Sharing Custom Image
It is used to cancel the shared custom image:
public static void unShareImage(BccClient bccClient, String accountId, String imageId) {
UnShareImageRequest unShareImageRequest = new UnShareImageRequest();
// User ID to cancel sharing
unShareImageRequest.setAccountId(accountId);
// Image ID to cancel sharing
unShareImageRequest.setImageId(imageId);
bccClient.unShareImage(unShareImageRequest);
}
Query the Shared User List of Images
It is used to query the share user list of images:
public static void listSharedUser(BccClient bccClient, String ImageId) {
ListSharedUserResponse listSharedUserResponse = bccClient.listSharedUser(ImageId);
}
Query OS information in batches based on instance ID (newly add)
It is used to batch query the OS information through the short instance ID:
public static void listOs(BccClient bccClient) {
ListOsRequest listOsRequest = new ListOsRequest();
List<String> ids = new ArrayList<String>();
//Set the instance ID to be queried
instanceId
listOsRequest.setInstanceIds(ids);
ListOsResponse listOsResponse = bccClient.listOs(listOsRequest);
}