百度智能云

All Product Document

          Cloud Compute Service

          BCC Instance

          The BCC instance is the BCC operation instance on Baidu AI Cloud and the management entity of advanced features, such as billing and access control.

          Create an Instance

          With the following code, You can create BCC instances, including an dedicated instance, a general-purpose instance, a general-purpose II instance, a memory-optimized BCC and a compute-optimized BCC:

          public static void createInstance(BccClient bccClient) {
              CreateInstanceRequest createInstanceRequest = new CreateInstanceRequest();
          
              // Set the image used to create the BCC virtual machine
              createInstanceRequest.setImageId(imageId);
              // Set the password for creating BCC
              createInstanceRequest.setAdminPass(adminPass);
              // Set the number of cores to create BCC
              createInstanceRequest.setCpuCount(newCpuCount);
              // Set the memory size for creating BCC GB
              createInstanceRequest.setMemoryCapacityInGB(newMemoryInGb);
              // Set the network bandwidth used to create BCC
              createInstanceRequest.setNetworkCapacityInMbps(networkCapacityInMbps);
              // Set the name for creating BCC
              createInstanceRequest.setName(newName);
              // Set the zone where the BCC is created
              createInstanceRequest.setZoneName(zoneName);
          
              // To create a specified subnet and security group, you must specify or  must not  specify the subnet and security group at the same time. 
              //Furthermore, the specified subnet and security group must be of the same VPC. If you do not specify them, use the default subnet and security group.
              // Set the subnet used to create the BCC,
              createInstanceRequest.setSubnetId(subnetId);
              // Set the security group used to create the BCC
              createInstanceRequest.setSecurityGroupId(securityGroupId);
          
              List<CreateCdsModel> createCdsModelList = new ArrayList<CreateCdsModel>();
              // New blank CDS data disk with high performance type
              createCdsModelList.add(new CreateCdsModel().withCdsSizeInGB(cdsSizeInGb).withStorageType("hp1"));
              // Create a CDS data disk based on the CDS data disk snapshot snapshotId. A CDS disk is created using the snapshot size by default, .
              createCdsModelList.add(new CreateCdsModel().withSnapshotId(snapshotId));
              // Create a list of CDS disks that need to be created
              createInstanceRequest.setCreateCdsList(createCdsModelList);
          
              // Set a billing method for creating BCC as a prepayment for annual and monthly billing
              createInstanceRequest.setBilling(new Billing().withPaymentTiming("Prepaid"));
              // Set a billing method for creating BCC as post-paid
              createInstanceRequest.setBilling(new Billing().withPaymentTiming("Postpaid"));
          
              List<EphemeralDisk> ephemeralDiskList = new ArrayList<EphemeralDisk>();
              // The DCC instance can create multiple local disks. The disk type and size need to be specified.
              // Other BCC types can only use one local disk at most. The default disk type is used, and the disk size needs to be specified.
              ephemeralDiskList.add(new EphemeralDisk().withSizeInGB(sizeInGb));
          
              // The following BCC models can be created
              
              // Set the DCC server id for creating BCC
              createInstanceRequest.setDedicatedHostId(dedicatedHostId);
              // Set the BCC instance type to be created to the common BCC I 
              createInstanceRequest.setInstanceType(InstanceType.N1.name());
              // Set the BCC instance type to be created to the common BCCⅡ
              createInstanceRequest.setInstanceType(InstanceType.N2.name());
              // Set the BCC instance type to be created to the computing optimized
              createInstanceRequest.setInstanceType(InstanceType.C1.name());
              // Set the BCC instance type to be created to the storage optimized
              createInstanceRequest.setInstanceType(InstanceType.S1.name());
              // Carry out a request for creating BCC
              CreateInstanceResponse createInstanceResponse = bccClient.createInstance(createInstanceRequest);
              for (String instanceId : createInstanceResponse.getInstanceIds()) {
                  System.out.println(instanceId);
              }
          }
           
              // Create the CPU BCC virtual machine
              public static void createGpuInstance(BccClient bccClient) {
                  CreateInstanceRequest createInstanceRequest = new CreateInstanceRequest();
          
                  // Set the image used to create the BCC virtual machine
                  createInstanceRequest.setImageId(imageId);
                  // Set the password for creating BCC
                  createInstanceRequest.setAdminPass(adminPass);
                  // Set the number of cores to create BCC
                  createInstanceRequest.setCpuCount(12);
                  // Set the memory size for creating BCC GB
                  createInstanceRequest.setMemoryCapacityInGB(40);
                  // Set the network bandwidth used to create BCC
                  createInstanceRequest.setNetworkCapacityInMbps(networkCapacityInMbps);
                  // Set the name for creating BCC
                  createInstanceRequest.setName(newName);
          
                  List<CreateCdsModel> createCdsModelList = new ArrayList<CreateCdsModel>();
                  // New blank CDS data disk with high performance type
                  createCdsModelList.add(new CreateCdsModel().withCdsSizeInGB(cdsSizeInGb).withStorageType("hp1"));
                  // Create a CDS data disk based on the CDS data disk snapshot snapshotId. A CDS disk is created using the snapshot size by default, .
          //        createCdsModelList.add(new CreateCdsModel().withSnapshotId(snapshotId));
                  // Create a list of CDS disks that need to be created
                  createInstanceRequest.setCreateCdsList(createCdsModelList);
          
                  // Set a billing method for creating BCC as a prepayment for annual and monthly billing
          //        createInstanceRequest.setBilling(new Billing().withPaymentTiming("Prepaid"));
                  // Set a billing method for creating BCC as post-paid
                  createInstanceRequest.setBilling(new Billing().withPaymentTiming("Postpaid"));
          
                  List<EphemeralDisk> ephemeralDiskList = new ArrayList<EphemeralDisk>();
                  // The DCC instance can create multiple local disks. The disk type and size need to be specified.
                  // Other BCC types can only use one local disk at most. The default disk type is used, and the disk size needs to be specified.
                  ephemeralDiskList.add(new EphemeralDisk().withSizeInGB(450));
          
                  // Set the BCC instance type to be created to the GPU type
                  createInstanceRequest.setInstanceType(InstanceType.G1.name());
                  createInstanceRequest.setGpuCard(GpuCardType.P4);
                  createInstanceRequest.setCardCount(1);
                  // Carry out a request for creating BCC
                  CreateInstanceResponse createInstanceResponse = bccClient.createInstance(createInstanceRequest);
                  for (String instanceId : createInstanceResponse.getInstanceIds()) {
                      System.out.println(instanceId);
                  }
              }
          
              // Create the FPGA BCC virtual machine
              public static void createFpgaInstance(BccClient bccClient) {
                  CreateInstanceRequest createInstanceRequest = new CreateInstanceRequest();
          
                  // Set the image used to create the BCC virtual machine
                  createInstanceRequest.setImageId("m-r3BBe7Ep");
                  // Set the password for creating BCC
                  createInstanceRequest.setAdminPass(adminPass);
                  // Set the number of cores to create BCC
                  createInstanceRequest.setCpuCount(16);
                  // Set the memory size for creating BCC GB
                  createInstanceRequest.setMemoryCapacityInGB(64);
                  // Set the network bandwidth used to create BCC
                  createInstanceRequest.setNetworkCapacityInMbps(networkCapacityInMbps);
                  // Set the name for creating BCC
                  createInstanceRequest.setName(newName);
          
                  List<CreateCdsModel> createCdsModelList = new ArrayList<CreateCdsModel>();
                  // New blank CDS data disk with high performance type
                  createCdsModelList.add(new CreateCdsModel().withCdsSizeInGB(cdsSizeInGb).withStorageType("hp1"));
                  // Create a CDS data disk based on the CDS data disk snapshot snapshotId. A CDS disk is created using the snapshot size by default, .
          //        createCdsModelList.add(new CreateCdsModel().withSnapshotId(snapshotId));
                  // Create a list of CDS disks that need to be created
                  createInstanceRequest.setCreateCdsList(createCdsModelList);
          
                  // Set a billing method for creating BCC as a prepayment for annual and monthly billing
          //        createInstanceRequest.setBilling(new Billing().withPaymentTiming("Prepaid"));
                  // Set a billing method for creating BCC as post-paid
                  createInstanceRequest.setBilling(new Billing().withPaymentTiming("Postpaid"));
          
                  List<EphemeralDisk> ephemeralDiskList = new ArrayList<EphemeralDisk>();
                  // The DCC instance can create multiple local disks. The disk type and size need to be specified.
                  // Other BCC types can only use one local disk at most. The default disk type is used, and the disk size needs to be specified.
                  ephemeralDiskList.add(new EphemeralDisk().withSizeInGB(450));
          
                  // Set the BCC instance type to be created to the FPGA type
                  createInstanceRequest.setInstanceType(InstanceType.F1.name());
                  // Set the FPGA card information to be created
                  createInstanceRequest.setFpgaCard(FpgaCardType.KU115);
                  createInstanceRequest.setCardCount(1);
                  // Carry out a request for creating BCC
                  CreateInstanceResponse createInstanceResponse = bccClient.createInstance(createInstanceRequest);
                  for (String instanceId : createInstanceResponse.getInstanceIds()) {
                      System.out.println(instanceId);
                  }
              }
           
          1. The BCC creation request is an asynchronous request, and it indicates to generate an order when it returns 200. You can understand the creation progress of BCC virtual machines by querying the returned instance ID subsequently.
          2. This API is used to create one or more virtual machine instances of same configuration.
          3. Creating an instance requires the Identity Verification. Otherwise, you can access the Identity Verification under the security certification on the Baidu Open Cloud official website console for the Identity Verification.
          4. To create a postpaid instance, the account cash balance and the general voucher must be greater than 100 CNY. To create a prepaid instance, the account cash balance must be greater than or equal to the instance cost.
          5. Batch creation is supported, and if one instance fails to be created in the creation, all instances are rolled back and all creations fail. If a CDS is included when it is created, the CDS will also be rolled back.
          6. An instance can mount up to 5 CDS disks by default.
          7. When you create the CDS disk and the temporary data disk, the disk capacity is limited to a multiple of 5.
          8. Creating an instance supports to create and add the temporary data disk, but does not support to create or add the temporary data disk separately.
          9. The temporary data disk does not support the mount, uninstall or delete.
          10. The temporary data disk of general purpose instance can not exceed 500 GB at most.
          11. To create a specified subnet and security group, you must specify the subnet and security group at the same time. Furthermore, the specified subnet and security group must be of the same VPC. If you do not specify them, use the default subnet and security group.
          12. When you create the public IP with specified bandwidth, the billing mode is bill-by-bandwidth.
          13. This API is an asynchronous interface. You can query the instances status through the Query Instance Details interface.
          14. You can specify DCC to create an instance by this interface, and the dedicated instance is not billed. Dedicated instances can only create temporary disks and specify disk types by ephemeralDisks.
          15. Each instance can purchase up to one temporary data disk.
          16. The temporary data disk of instances is of hp1 type by default.
          17. You can specify the virtual machine type to create through the instanceType field. For the virtual machine type supported by API currently, see InstanceType below. The parameters (instanceType, cpuCount and memoryCapacityInGB) can be used to determine the required model and configuration.
          18. To create a memory optimized instance, you must purchase the temporary data disk, and specify the storage capacity of the temporary data disk through ephemeralDisks. The temporary data disk is of nvme type by default, which does not need to specify.
          19. For the creation request details, see the Create Instance in the BCC API document for details.
          20. To create an FPGA BCC virtual machine, you need to use the specified CPU, memory, local data disk, FPGA type and exclusive image. See the BCC Optional Specification Configuration of FPGA Type in the BCC API document for details.
          21. Creating a GPU BCC virtual machine requires the use of specified CPU, memory, local data disk and GPU card type. See the BCC Optional Configuration of GPU type in the BCC API document for details.

          Query the Instance List

          You can query the BCC virtual machine instance list by the following codes, which supports the filter through the private IP, DCC ID and availability zone name:

          public static void listInstance(BccClient bccClient) {
              ListInstancesRequest listInstancesRequest = new ListInstancesRequest();
              // Set a paging mark
              listInstancesRequest.setMarker(instanceId);
              // Set the pagination return data size
              listInstancesRequest.setMaxKeys(maxKey);
              # Filter virtual machine BCC list by internalIp
              listInstancesRequest.setInternalIp(internalIp);
              //Filter BCC list by dedicated cloud compute dccId
              listInstancesRequest.setDedicatedHostId(dedicatedHostId);
              //Filter BCC virtual machine list by zoneName
              listInstancesRequest.setZoneName(zoneName);
              // carry out a query action of the virtual machine list
              ListInstancesResponse listInstancesResponse = bccClient.listInstances(listInstancesRequest);
          
              for (InstanceModel instanceModel : listInstancesResponse.getInstances()) {
                  System.out.println(instanceModel.getId());
              }
          }

          Query Instance Details

          You can query the specified BCC virtual machine details by the following codes:

          public static void getInstanceDetail(BccClient bccClient) {
              // Query detailed information of a specified BCC virtual machine
              InstanceModel instanceModel = bccClient.getInstance(instanceId).getInstance();
              System.out.println(instanceModel.getName());
          }

          Start an Instance

          You can start a specified BCC virtual machine instance by the following codes:

          public static void startInstance(BccClient bccClient) {
              bccClient.startInstance(instanceId);
          }

          After the API is called successfully, the instance is in the Starting status. The instance must be in the Stopped status, so that it returns successfully when this API is called. Otherwise, it prompts an error 409.

          Stop an Instance

          You can stop a specified BCC virtual machine instance by the following codes:

          public static void stopInstance(BccClient bccClient) {
              StopInstanceRequest stopInstanceRequest = new StopInstanceRequest();
              // Set the BCC virtual machine id
              stopInstanceRequest.setInstanceId(instanceId);
              // The setting is forcibly stopped, which is equivalent to the power failure and may lose the data that is not written to the disk in the instance operating system.
              stopInstanceRequest.setForceStop(Boolean.TRUE);
             // Set if to shut down without charging, TRUE means no charging with shutting down, FALSE means charging without shutting down. Notice: Only whitelisted users are entitled to shutdown without charge
              stopInstanceRequest.setStopWithNoCharge(Boolean.TRUE);
              // Carry out a stop action of BCC virtual machine
              bccClient.stopInstance(stopInstanceRequest);
          }
          • The system backend is in the Stopped status after the instance is stopped successfully.
          • This operation can be performed only when the instance is in the Running status. Otherwise, it prompts an error 409.
          • You can forcibly stop an instance, which is equivalent to the power failure and may lose the data that is not written to the disk in the instance operating system.

          Restart an Instance

          You can restart a specified BCC virtual machine instance by the following codes:

          public static void rebootInstance(BccClient bccClient) {
              RebootInstanceRequest rebootInstanceRequest = new RebootInstanceRequest();
              // Set BCC virtual machine id
              rebootInstanceRequest.setInstanceId(instanceId);
              // The setting is forcibly stopped, which is equivalent to the power failure and may lose the data that is not written to the disk in the instance operating system.
              rebootInstanceRequest.setForceStop(Boolean.TRUE);
              //  Carry out a restart action of BCC virtual machine
              bccClient.rebootInstance(rebootInstanceRequest);
          }
          • This operation can be performed only when the instance is in the Running status. Otherwise, it prompts an error 409.
          • After the API is called successfully, the instance is in the Starting status.
          • You can forcibly restart an instance, which is equivalent to the power failure restart of the traditional compute and may lose the data that is not written to the disk in the instance operating system.

          Modify an instance password

          You can change the Admin password of specified virtual machine by the following codes:

          public static void modifyInstancePassword(BccClient bccClient) {
              ModifyInstancePasswordRequest modifyInstancePasswordRequest = new ModifyInstancePasswordRequest();
              // Set BCC virtual machine id
              modifyInstancePasswordRequest.setInstanceId(instanceId);
              // Set a password of BCC virtual machine 
              modifyInstancePasswordRequest.setAdminPass(adminPass);
              // Carry out a password action for modifying BCC instance
              bccClient.modifyInstancePassword(modifyInstancePasswordRequest);
          }

          This API can be called only when the instance is in the Running or Stopped status. Otherwise, it prompts an error 409.

          Modify an instance attribute

          Modify an instance name

          You can modify the name of specified virtual machine by the following code. At present, you can only modify the name attribute of BCC virtual machine:

          public static void modifyAttributeInstance(BccClient bccClient) {
               ModifyInstanceAttributesRequest modifyInstanceAttributesRequest = new ModifyInstanceAttributesRequest();
               // Set BCC virtual machine id 
               modifyInstanceAttributesRequest.setInstanceId(instanceId);
               // Set a name of BCC virtual machine 
               modifyInstanceAttributesRequest.setName(newName);
               // Carry out a attribute action for modifying BCC instance 
               bccClient.modifyInstanceAttributes(modifyInstanceAttributesRequest);
           }

          Modify description information of instances

          You can modify the description  information of specified instance by the following codes:
          
          public static void modifyDescInstance(BccClient bccClient) {
          
              ModifyInstanceDescRequest modifyInstanceDescRequest = new ModifyInstanceDescRequest();
          
              // Set the BCC virtual machine id
          
              modifyInstanceDescRequest.setInstanceId(instanceId);
          
              // Set the description of this virtual machine
          
              modifyInstanceDescRequest.setDesc(newDesc);
          
              // Carry out a modifying BCC action
          
              bccClient.modifyInstanceDesc(modifyInstanceDescRequest);
          
          }

          This API can be called only when the instance is in the Running or Stopped status. Otherwise, it prompts an error 409.

          Reinstall an Instance

          You can reinstall a specified BCC virtual machine instance by the following codes:

          public static void rebuildInstance(BccClient bccClient) {
              RebuildInstanceRequest rebuildInstanceRequest = new RebuildInstanceRequest();
              // Set the BCC virtual machine id
              rebuildInstanceRequest.setInstanceId(instanceId);
              // Set a image id for reinstalling BCC virtual machine.
              rebuildInstanceRequest.setImageId(imageId);
              // Set a password of BCC virtual machine
              rebuildInstanceRequest.setAdminPass(adminPass);
              //  Carry out a reinstalling action for BCC virtual machine
              bccClient.rebuildInstance(rebuildInstanceRequest);
          }

          After the reinstallation of instance, the snapshot based on the original system disk is deleted automatically, while the custom image based on the original system disk is retained.

          Release an Instance

          You can release a postpaid or prepaid BCC virtual machine instance expired by the following codes:

          public static void releaseInstance(BccClient bccClient) {
              bccClient.releaseInstance(instanceId);
          }
          • It releases an individual BCC instance. After the release, all physical resources the instance uses are recovered, and all relevant data is lost and can not be recovered.
          • You can only release the postpaid or prepaid instance expired.
          • After the release of instance, the mounted CDS disk is uninstalled automatically, while the snapshot based on this CDS disk is retained.
          • After the release of instance, the snapshot based on the original system disk is deleted automatically, while the custom image based on the original system disk is retained.

          Scale an Instance

          You can scale the CPU and memory of BCC virtual machine by the following codes:

          public static void resizeInstance(BccClient bccClient) {
              ResizeInstanceRequest resizeInstanceRequest = new ResizeInstanceRequest();
              // Set the BCC virtual machine id
              resizeInstanceRequest.setInstanceId(instanceId);
              // Set the number of new CPUs
              resizeInstanceRequest.setCpuCount(newCpuCount);
              // Set the memory of new BCC virtual machine, and the memory unit is GB.
              resizeInstanceRequest.setMemoryCapacityInGB(newMemoryInGb);
              //  Carry out the scalability of BCC instance
              bccClient.resizeInstance(resizeInstanceRequest);
          }
          • The scale-down operation can not be performed for the prepaid instance.
          • The auto scaling operation can be performed for the postpaid instance.
          • The scaling operation can be performed only when the instance in the Running or Stopped status.
          • The instance is restarted once after scaling.
          • It is an asynchronous interface, and you can view whether the scaling status is completed through the Query Instance Details interface.
          • The dedicated instance can be created by the specified CPU, memory and temporary disk size. The temporary disk of dedicated instance can be scaled up only, but can not be scaled down. See [Instance Scaling](BCC/API Reference/Instance Related Port/实例扩缩容.md) in the API Documentation for details.

          Add an Instance to Security Group

          You can add a specified BCC virtual machine instance to the specified security group by the following codes:

          public static void bindInstanceToSecurityGroup(BccClient bccClient) {
              BindSecurityGroupRequest bindSecurityGroupRequest = new BindSecurityGroupRequest();
              // Set a security group id
              bindSecurityGroupRequest.setSecurityGroupId(securityGroupId);
              // Set the BCC virtual machine Instance id
              bindSecurityGroupRequest.setInstanceId(instanceId);
              // Carry out an action of adding instances into the security group
              bccClient.bindInstanceToSecurityGroup(bindSecurityGroupRequest);
          }

          Each instance is associated with up to 10 security groups.

          Remove an Instance from Security Group

          You can remove a specified instance from the specified security group by the following codes:

          public static void unbindInstanceFromSecurityGroup(BccClient bccClient) {
              UnbindSecurityGroupRequest unbindSecurityGroupRequest = new UnbindSecurityGroupRequest();
              // Set a security group id
              unbindSecurityGroupRequest.setSecurityGroupId(securityGroupId);
              // Set the BCC virtual machine Instance id
              unbindSecurityGroupRequest.setInstanceId(instanceId);
              // Carry out an action of moving instances into the security group
              bccClient.unbindInstanceFromSecurityGroup(unbindSecurityGroupRequest);
          }
          • Each instance associates with one security group at least, and it associates with the default security group by default.
          • If the instance belongs to one security group only, it prompts an error 403 for the request when you try to remove the instance.

          Query the VNC Address of Instance

          You can query the VNC URL of specified BCC virtual machine instance by the following codes:

          public static void getInstanceVnc(BccClient bccClient) {
              System.out.println(bccClient.getInstanceVnc(instanceId).getVncUrl());
          }
          • The VNC address is invalid after the use for one time.
          • The validity period of URL address is 10 minutes.

          Renew an Instance

          Renewing a BCC virtual machine instance can extend the expiration date. You can renew the disk by the following codes:

          public static void purchaseReservedInstance(BccClient bccClient) {
              PurchaseReservedInstanceRequeset purchaseReservedInstanceRequeset = new PurchaseReservedInstanceRequeset();
              // Set the BCC virtual machine id
              purchaseReservedInstanceRequeset.setInstanceId(instanceId);
              // 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
              purchaseReservedInstanceRequeset.setBilling(billing);
              // Carry out BCC virtual machine renewal
              bccClient.purchaseReservedInstance(purchaseReservedInstanceRequeset);
          }
          • The renew operation can not be performed during the scaling of BCC virtual machine instance.
          • If the instance is stopped due to arrears during the renew, there is a start process of BCC virtual machine instance after renewal.
          • This API is an asynchronous interface.
          • The dedicated instance can not be renewed.
          Previous
          Getting Started
          Next
          Disk