百度智能云

All Product Document

          Cloud Compute Service

          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 exclusive instance, general-purpose I instance, general-purpose II instance, general-purpose III instance, GPU instance, compute-optimized I instance, compute-optimized II instance and memory-optimized I instance:

          def create_instance(self):
                #If the user does not specify the parameters of client_token, a random string is generated for client_token by uuid4.
                generate_client_token = str(uuid.uuid4())
                client_token = generate_client_token()
          
                #Input a image ID which is used for creating instance.
                image_id = 'your-choose-image-id'
          
                #Set the type of instance you want to create.
          
                #The corresponding code of each type is shown in the "Instance Type Definition List" below.
                instance_type = 'your-choose-instance-type'
               
                #Select the payment mode:
          
                #The payment mode is the postpaid mode.
                post_paid_billing = bcc_model.Billing('Postpaid', 1)
          
                #The billing method is a preppaid mode for annual and monthly billing.
                pre_paid_billing = bcc_model.Billing('Prepaid', 1)
          
                #Create cds_list required parameters:
          
                #Cloud disk size (common cloud disk range: 5 - 32765, high-performance cloud disk range: 5 - 32765, SSD cloud disk range: 50 - 32765
                cds_size_in_gb = 5
          
                #Set the cloud disk type
               
                #The specific type corresponding encoding see BccOpenAPI
                storage_type = 'hp1'
          
                #If creating CDS disk data based on CDS data disk snapshots, input the snapshot policy id selected by the user
                snap_shot_id = 'your-choose-snap-shot-id'
          
                #Instance Name
                instance_name = 'your-choose-instance-name' + client_token
          
                #set the instance administrator password (its password is 8-16 characters, English, numbers and symbols must exist at the same time, the using symbols are limited to only! @ # $% ^ * ()).
                admin_pass = 'your-admin-pass'
          
                #Specify the zone information, which is null by default and selected by the system automatically. You can query the list of availability zones through the Query Availability Zone List interface.
                
                #The format is: Country- Region-Available region, such as 'China-Beijing-Available Zone A' is 'cn-bj-a'.
                zone_name = 'country-region-zone'
          
                #The specified subnet information. If it is null, the default subnet is used.
                subnet_id = 'your-choose-subnet-id'
                
                #The specified security_group_id information. If it is null, the default security group is used.
                security_group_id = 'your-choose-security-group-id'
          
                #Input the gpu_card you select.
                
                #Each gpu_card type code refer to Gpu Type List below.
                gpuCard='your-choose-Gpu-Type-id'
               
                #Input the fpga_card you select.
          
                #Currently fpga_card type is only KU115
                fpgaCard='KU115'
                self.assertEqual(
                      type(self.client.create_instance(1,# Set the number of cores to create BCC
                                                       1,# Set the memory size for creating BCC GB
                                                       image_id,# Set the image used to create the BCC virtual machine
                                                       Instance_type=instance_type,# Set the type of BCC instance to be created
                                                       billing=post_paid_billing,# Set the payment method for creating BCC as post-paid 
                                                       Root_disk_size_in_gb=40,# Set the BCC system disk size, the range is [40, 500] GB
                                                       root_disk_storage_type='hp1',# Set the BCC system disk system disk medium. The default is hp1 cloud disk. For the system disk disk type, see StorageType.
                                                       create_cds_list=bcc_model.CreateCdsModel,(cds_size_in_gb, storage_type, snap_shot_id)# Create a CDS disks that need to be created
                                                       Network_capacity_in_mbps=1,# Set the network bandwidth used to create the BCC (must be between 1 and 200)
                                                       Purchase_count=1,# When used to create BCC instances in batches, the value must be an integer greater than 0
                                                       cardCount=1,# The number of GPU card or FPGA card is for creating instance, it is valid when the gpuCard or fpgaCard field is not null only.
                                                       Name=instance_name,#  Set and create a BCC name
                                                       admin_pass=admin_pass,# set the instance administrator password
                                                       zone_name=zone_name,# Set a Zone where the BCC is created.
                                                       Subnet_id=subnet_id,#  the specified subnet information. If it is null, the default subnet is used.
                                                       Security_group_id=security_group_id,# the specified security_group_id information. If it is null, the default security group is used.
                                                       gpuCard=gpuCard,# Specify GPU type when creating GPU instance
                                                       fpgaCard=fpgaCard,#Specify FPGA type when creating FPGA instance                                           client_token=client_token)),
                      baidubce.bce_response.BceResponse)

          For the instance type and GPU type definition list, see List.

          Create an Instance on DCC

          You can create a BCC instance on DCC by using the following codes:

          def create_instance_from_dedicated_host(self):
                #If the user does not specify the parameters of client_token, a random random string is generated for client_token by uuid4.
                generate_client_token = str(uuid.uuid4())
                client_token = generate_client_token()
          
                #Set a image id
                image_id = 'your-choose-image-id'
                
                #Set a dedicated cloud compute (DCC)  ID
                dedicated_host_id = 'your-choose-dedicated-host-id'
          
                #Set a instance name
                instance_name = 'your-choose-instance-name' + client_token
          
                #set the instance administrator password (its password is 8-16 characters, English, numbers and symbols must exist at the same time, the using symbols are limited to only! @ # $% ^ * ()).
                admin_pass = 'your-admin-pass'
          
                #The specified subnet information. If it is null, the default subnet is used.
                subnet_id = 'your-choose-subnet-id'
          
                #The specified security_group_id information. If it is null, the default security group is used.
                security_group_id = 'your-choose-security-group-id'
          
                #The DCC dedicated cloud compute instance can create multiple local disks. The disk type and size need to be specified.
          
                #Other BCC types can only use one local disk. The default disk type is used, and the disk size needs to be specified.
          
                #Set the size of creating local disk
                ephemeral_disk = EphemeralDisk(6144)
          
                #Set the local disk type as the default type
                ephemeral_disks = [ephemeral_disk.__dict__, ephemeral_disk.__dict__]
                self.assertEqual(
                      type(self.client.create_instance_from_dedicated_host(1, # Set the number of cores to create BCC
                                                                           2, # Set the memory size for creating BCC GB
                                                                           image_id, #Set the image used to create the BCC
                                                                           dedicated_host_id, #Set a dedicated cloud compute for creating BCC
                                                                         Purchase_count=1,# When used to create BCC instances in batches, the value must be an integer greater than 0
                                                                           Name=instance_name,#  Set and create a BCC name
                                                                           admin_pass=admin_pass,# set the instance administrator password
                                                                         Subnet_id=subnet_id,#  the specified subnet information. If it is null, the default subnet is used.
                                                                           Security_group_id=security_group_id,# the specified security_group_id information. If it is null, the default security group is used.
                                                                           client_token=client_token
                                                                           ephemeral_disks) #Set a local disk for creating BCC
                      baidubce.bce_response.BceResponse)

          Query the Instance List

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

          def list_instances(self):
                #The start position of the query for getting list by batch is a character string generated by the system.
                self.client.list_instances(marker='your-marker')
                
                #Set the return data size
                self.client.list_instances(max_keys=100)
          
                #filter virtual machine BCC list by internal IP
                self.client.list_instances(internal_ip='your-choose-internal-ip')
          
                #Filter virtual machine BCC list by dedicated cloud compute DCC id
                self.client.list_instances(dedicated_host_id='your-choose-dedicated-host-id')
          
                #Filter virtual machine BCC list by zone name
                self.client.list_instances(zone_name='country-region-zone')
          
                #Carry out a query action of the virtual machine list
                print self.client.list_instances()

          Query Instance Details

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

          def get_instance(self): 
          
                #Set the instance_id you want to operate
                instance_id = 'your-choose-instance-id'
                self.assertEqual(
                      type(self.client.get_instance(instance_id)), 
                      baidubce.bce_response.BceResponse)

          Start an Instance

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

          def start_instance(self):
          
                #Set the instance_id you want to operate
                instance_id = 'your-choose-instance-id'
                self.assertEqual(
                      type(self.client.start_instance(instance_id)), 
                      baidubce.bce_response.BceResponse)

          Stop an Instance

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

          def stop_instance(self):
          
                #Set the instance_id you want to operate
                instance_id = 'your-choose-instance-id'
            
                #Set the billing mode of shutdown, no billing command for shutdown is True,the billing command is False,the default command is False. Notice: Only whitelisted users are entitled to shutdown without charge
                stop_with_no_charge = 'True'
                self.assertEqual(
                  type(self.client.stop_instance(instance_id=instance_id,
                                                 stopWithNoCharge=stop_with_no_charge,
                                                 force_stop=force_stop)), 
                      baidubce.bce_response.BceResponse)

          Restart an Instance

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

          def reboot_instance(self):
          
                #Set the instance_id you want to operate
                instance_id = 'your-choose-instance-id'
                self.assertEqual(
                      type(self.client.reboot_instance(instance_id,
                                                       force_stop)),
                      baidubce.bce_response.BceResponse)

          Modify an instance password

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

          def modify_instance_password(self):
          
                #Set the instance_id you want to operate
                instance_id = 'your-choose-instance-id'
          
                #Set a password
                admin_pass = 'your-new-admin-pass'
                self.assertEqual(
                      type(self.client.modify_instance_password(instance_id,
                                                                admin_pass)), 
                      baidubce.bce_response.BceResponse)

          Modify an instance name

          You can modify the name of specified BCC virtual machine instance by using the following codes:

          def modify_instance_attributes(self):
          
                #Set the instance_id you want to operate
                instance_id = 'your-choose-instance-id'
                name = 'name_modify'    
                self.assertEqual(
                      type(self.client.modify_instance_attributes(instance_id,
                                                                   name)), 
                      baidubce.bce_response.BceResponse)

          Reinstall an Instance

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

          def rebuild_instance(self):
          
                #Set the instance_id you want to operate
                instance_id = 'your-choose-instance-id'
                # Set a using image id.
                image_id = 'your-choose-image-id'
                # Set a admin password
                admin_pass = 'your-new-admin-pass'
                self.assertEqual(
                      type(self.client.rebuild_instance(instance_id,
                                                        image_id,
                                                        admin_pass)), 
                      baidubce.bce_response.BceResponse)

          Release an Instance

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

          def release_instance(self):
          
                #Set the instance_id you want to operate
                instance_id = 'your-choose-instance-id'
                self.assertEqual(
                      type(self.client.release_instance(instance_id)), 
                      baidubce.bce_response.BceResponse)

          Scale an Instance

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

          def resize_instance(self):
          
                #Set the instance_id you want to operate
                instance_id = 'your-choose-instance-id'
                client_token = generate_client_token()
                self.assertEqual(
                      type(self.client.resize_instance(instance_id,
                                                       1,# New CPU cores
                                                       2,# New memory size
                                                       client_token)), 
                      baidubce.bce_response.BceResponse)

          Add an Instance to Security Group

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

          def bind_instance_to_security_group(self):
          
                #Specify security_group_id information
                security_group_id = 'your-choose-security-group-id'
          
                #Set the instance_id you want to operate
                instance_id = 'your-choose-instance-id'
                self.assertEqual(                type(self.client.bind_instance_to_security_group(instance_id,                             security_group_id)), 
                      baidubce.bce_response.BceResponse)

          Remove an Instance from Security Group

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

          def unbind_instance_from_security_group(self):
          
                #Specify security_group_id information
                security_group_id = 'your-choose-security-group-id'
          
                #Set the instance_id you want to operate
                instance_id = 'your-choose-instance-id'
                self.assertEqual(
                      type(self.client.unbind_instance_from_security_group(instance_id,                                                                                                     security_group_id)), 
                      baidubce.bce_response.BceResponse)

          Query an Instance Address

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

          def get_instance_vnc(self):
          
                #Set the instance_id you want to operate
                instance_id = 'your-choose-instance-id'
                self.assertEqual(
                      type(self.client.get_instance_vnc(instance_id)), 
                      baidubce.bce_response.BceResponse)

          Renew an Instance

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

          def purchase_reserved_instance(self):
          
                #Set the instance_id you want to operate
          
                instance_id = 'your-choose-instance-id'
                billing = pre_paid_billing
                client_token = generate_client_token()
                self.assertEqual(
                      type(self.client.purchase_reserved_instance(instance_id,
                                                                  billing,
                                                                 client_token)), 
                     baidubce.bce_response.BceResponse)
          Previous
          BccClient
          Next
          Security Group