百度智能云

All Product Document

          Baremetal Compute Sevice

          Instance

          The BBC instance is a physical server operation instance on Baidu Cloud, and is also a management entity for advanced functions such as billing and privilege control.

          Create Instance

          Create one or more physical machine instances by the following codes.

          def create_instance(self): 
              # If the user does not specify the client_token parameter, use uuid4 to generate a random string to the client_token 
              generate_client_token = str(uuid.uuid4()) 
              client_token = generate_client_token() 
              # Enter ID of your selected flavor (package). Please refer to the package section for the method of obtaining the available flavor ID through SDK 
              flavor_id = 'your-choose-flavor-id' 
              # Enter the image ID you want to create the instance to use. For the method of obtaining the available image ID through SDK, please refer to the Image chapter 
              image_id = 'your-choose-image-id' 
              # Enter the raid ID you want to use to create the instance, and see the package section for the method to obtain the available flavor ID through SDK 
              image_id = 'your-choose-raid-id' 
              # Enter the size of the physical disk to create, the unit is GB, and the default is 20 
              root_disk_size_in_gb = 20
              # The number of virtual machine instances created (purchased) in batches, must be an integer greater than 0, optional parameter, 1 by default 
              purchase_count = 1
              # Availability zone, the format is: Country-Region-Availability Zone, for instance, 'China-Beijing-Availability Zone A'is'cn-bj-a' 
              zone_name = 'cn-bj-a' 
              # Specify the subnet information. If it is empty, the default subnet will be used. 
              subnet_id = '604cebcd-740d-49d1-a1ac-72a91f5e34aa' 
              # Choose the payment method: 
              # The payment method is postpaid. 
              post_paid_billing = bcc_model.Billing('Postpaid', 1) 
              # The payment method is prepaid with annual and monthly billing 
              pre_paid_billing = bcc_model.Billing('Prepaid', 1) 
              # Instance name 
              instance_name = 'your-choose-instance-name' + client_token 
              # Specify the deployment set id used, optional parameters 
              deploy_set_id = 'your-choose-deploy-set-id' 
              # Set the instance administrator password (8-16 characters, English, numbers and symbols must exist at the same time, and symbols are limited to! @#$%^*()) 
              admin_pass = 'your-admin-pass' 
              self.client.create_instance(client_token = client_token, 
                                          flavor_id = flavor_id,
                                          image_id = image_id,
                                          raid_id = raid_id,
                                          root_disk_size_in_gb = root_disk_size_in_gb, 
                                          purchase_count = purchase_count, 
                                          zone_name = zone_name, 
                                          subnet_id = subnet_id, 
                                          billing = post_paid_billing, 
                                          name = instance_name, 
                                          deploy_set_id = deploy_set_id,
                                          admin_pass = admin_pass) 

          Query Instance List

          Query the list and detailed information of all BBC instances by the following codes:

          def list_instances(self): 
              # The starting position of the query to obtain the list in batches is a string generated by the system 
              self.client.list_instances(marker='your-marker') 
              # Set the returned data size 
              self.client.list_instances(max_keys=100) 
              # Filter BBC list by internal Ip 
              self.client.list_instances(internal_ip='your-choose-internal-ip') 
              # Perform the operation to query BBC instance list 
              self.client.list_instances() 

          Query Instance Details

          Use the following codes to query the detailed information of a specified BBC instance:

          def get_instance(self): 
              # Set the instance_id you want to operate 
              instance_id = 'your-choose-instance-id' 
              self.client.get_instance(instance_id = instance_id) 

          Start Instance

          Use the following codes to start the specified BBC instance, the instance status must be Stopped, and the interface can be called to return successfully, otherwise a 409 error is displayed:

          def start_instance(self): 
              # Set the instance_id you want to operate 
              instance_id = 'your-choose-instance-id' 
              self.client.start_instance(instance_id = instance_id) 

          Stop Instance

          Use the following codes to stop the specified BBC instance, only the instance with the status Running can perform this operation, otherwise a 409 error will be displayed:

          def stop_instance(self): 
              # Set the instance_id you want to operate 
              instance_id = 'your-choose-instance-id' 
              # Whether to stop the instance forcefully, True means force stop. The default is False 
              force_stop = False 
              self.client.stop_instance(instance_id = instance_id, force_stop = force_stop)) 

          Reboot Instance

          Use the following codes to reboot the specified BBC instance, only the instance with the status Running can perform this operation, otherwise a 409 error will be displayed:

          def reboot_instance(self): 
              # Set the instance_id you want to operate 
              instance_id = 'your-choose-instance-id' 
              # Whether to reboot the instance forcefully, True means forced reboot. The default is False 
              force_stop = False 
              self.client.reboot_instance(instance_id = instance_id,  force_stop = force_stop)) 

          Modify the Name of Instance

          Use the following codes to modify the name of the specified BBC instance:

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

          Modify the Description of Instance

          Use the following codes to modify the description of the specified BBC instance:

          def modify_instance_desc(self): 
              # Set the instance_id you want to operate 
              instance_id = 'your-choose-instance-id' 
              desc = 'your_desc'   
              self.client.modify_instance_attributes(instance_id = instance_id, desc = desc)), 

          Rebuild Instance

          Use the following codes to reconstruct the specified BBC instance by imaging:

          def rebuild_instance(self): 
              # Set the instance_id you want to operate 
              instance_id = 'your-choose-instance-id' 
              # Set the image id used 
              image_id = 'your-choose-image-id' 
              # Set administrator password 
              admin_pass = 'your-new-admin-pass' 
              # Whether to keep the data, the default is true. When the value is true, the raidId and sysRootSize fields do not take effect 
              is_preserve_data = False 
              # The raid configuration Id can be obtained by calling the get_flavor_raid interface of SDK. This parameter is required when isPreserveData is false, and does not take effect when isPreserveData is true 
              raid_id = 'your_raid_id' 
              # The size of the system disk root partition, the default is 20G, and the value range is 20-100. This parameter does not take effect when isPreserveData is true 
              sys_root_size = 20
              self.client.rebuild_instance(instance_id = instance_id, 
                                           image_id = image_id, 
                                           admin_pass = admin_pass,
                                           is_preserve_data = is_preserve_data, 
                                           raid_id = raid_id, 
                                           sys_root_size = sys_root_size) 

          Release the Instance

          For BBC instances with Postpaid and expired Prepaid, you can Use the following codes to release them:

          def release_instance(self): 
              # Set the instance_id you want to operate 
              instance_id = 'your-choose-instance-id' 
              self.client.release_instance(instance_id = instance_id) 

          Modify Instance Password

          Use the following codes to modify the administrator password of the specified BBC instance:

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

          Query Instance VPC/Subnet Information

          Use the following codes to query VPC/Subnet information through the BBC instance id:

          def get_vpc_subnet(self): 
              # Set the instance_id you want to operate 
              instance_ids = ['your-choose-instance-id'] 
              self.client.get_vpc_subnet(bbc_ids = instance_ids) 
          Previous
          BbcClient
          Next
          Image