百度智能云

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

          Use the following codes to create a physical machine instance:

          createInstanceArgs := &CreateInstanceArgs{ 
              // Enter ID of your selected flavor (package). Please refer to the package section for the method of obtaining the available flavor ID through SDK 
              FlavorId:         "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 
              ImageId:          "your-choose-image-id", 
              // Enter the raid ID you want to use to create the instance. For the method to obtain the available raid ID through SDK, see the package section. 
              RaidId:           "your-choose-raid-id", 
              // Enter the size of the physical disk to create, the unit is GB, and the default is 20 
              RootDiskSizeInGb: 20, 
              // The number of virtual machine instances created (purchased) in batches, must be an integer greater than 0, optional parameter, 1 by default 
              PurchaseCount:    1, 
              // Availability zone, the format is: Country-Region-Availability Zone, for instance, 'China-Beijing-Availability Zone A'is'cn-bj-a' 
              ZoneName:         "cn-bj-a", 
              // Specify subnet ID, required parameter 
              SubnetId:         "your-choose-subnet-id", 
              // Specify the security group id, optional parameter 
              SecurityGroupId:  "your-choose-security-group-id" 
              // Use uuid to generate an ASCII string no longer than 64 bits in length 
              ClientToken:      "random-uuid", 
              // Choose the payment method 
              Billing: Billing{ 
                  PaymentTiming: PaymentTimingPostPaid, 
                  Reservation: Reservation{ 
                      Length: 1, 
                      TimeUnit: "Month", 
                  }, 
              }, 
              // Specify the deployment set id to be used, optional parameters; for the method to obtain the available deployment set id through SDK, please refer to the deployment set chapter 
              DeploySetId: "your-choose-raid-id", 
              // Set the instance administrator password (8-16 characters, English, numbers and symbols must exist at the same time, and symbols are limited to! @#$%^*()) 
              AdminPass:   "your-admin-pass", 
              // Instance name 
              Name:        "your-choose-instance-name", 
          } 
          if res, err := bbcClient.CreateInstance(createInstanceArgs); err != nil { 
              fmt.Println("create instance failed: ", err) 
          } else { 
              fmt.Println("create instance success, instanceId: ", res.InstanceIds[0]) 
          } 

          Note:

          Payment method (PaymentTiming) optional:

          • Post-payment: PaymentTimingPostPaid
          • Prepayment: PaymentTimingPrePaid

          Query Instance List

          Use the following codes to query the list and details of all BBC instances:

          listArgs := &ListInstancesArgs{ 
              // The starting position of the query to obtain the list in batches is a string generated by the system 
              Marker: "your-marker", 
              // Set the size of the returned data, the default is 1000 
              MaxKeys: 100, 
              // Filter BBC list by internal Ip 
              InternalIp: "your-choose-internal-ip", 
          } 
          if res, err := bbcClient.ListInstances(listArgs); err != nil { 
              fmt.Println("list instances failed: ", err) 
          } else { 
              fmt.Println("list instances success, result: ", res) 
          } 

          Query Instance Details

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

          // Set the instanceId you want to operate 
          instanceId := "your-choose-instance-id" 
          if res, err := bbcClient.GetInstanceDetail(instanceId); err != nil { 
              fmt.Println("get instance detail failed: ", err) 
          } else { 
              fmt.Println("get instance detail success, result: ", res) 
          } 

          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:

          // Set the instanceId you want to operate 
          instanceId := "your-choose-instance-id" 
          if err := bbcClient.StartInstance(instanceId); err != nil { 
              fmt.Println("start instance failed: ", err) 
          } else { 
              fmt.Println("start instance success.") 
          } 

          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:

          // Set the instanceId you want to operate 
          instanceId := "your-choose-instance-id" 
          // Whether to stop the instance forcefully, True means force stop 
          forceStop := true 
          if err := bbcClient.StopInstance(instanceId, forceStop); err != nil { 
              fmt.Println("stop instance failed: ", err) 
          } else { 
              fmt.Println("stop instance success.") 
          } 

          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:

          // Set the instanceId you want to operate 
          instanceId := "your-choose-instance-id" 
          // Whether to stop the instance forcefully, True means force stop 
          forceStop := true 
          if err := bbcClient.RebootInstance(instanceId, forceStop); err != nil { 
              fmt.Println("reboot instance failed: ", err) 
          } else { 
              fmt.Println("reboot instance success.") 
          } 

          Modify the Name of Instance

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

          modifyInstanceNameArgs := &ModifyInstanceNameArgs{ 
              Name: "new_bbc_name", 
          } 
          // Set the instanceId you want to operate 
          instanceId := "your-choose-instance-id" 
          if err := bbcClient.ModifyInstanceName(instanceId, modifyInstanceNameArgs); err != nil { 
              fmt.Println("modify instance name failed: ", err) 
          } else { 
              fmt.Println("modify instance name success.") 
          } 

          Modify the Description of Instance

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

          modifyInstanceDescArgs := &ModifyInstanceDescArgs{ 
              Description: "new_bbc_description", 
          } 
          // Set the instanceId you want to operate 
          instanceId := "your-choose-instance-id" 
          if err := bbcClient.ModifyInstanceDesc(instanceId, modifyInstanceDescArgs); err != nil { 
              fmt.Println("modify instance desc failed: ", err) 
          } else { 
              fmt.Println("modify instance desc success.") 
          } 

          Rebuild Instance

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

          rebuildArgs := &RebuildInstanceArgs{ 
              // Set the image id used 
              ImageId:        "your-choose-image-id", 
              // Set administrator password 
              AdminPass:      "your-new-admin-pass", 
              // Whether to keep the data. When the value is true, the raidId and sysRootSize fields do not take effect 
              IsPreserveData: false, 
              // This parameter is required when isPreserveData is false, and does not take effect when isPreserveData is true 
              RaidId:         "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 
              SysRootSize: 20, 
          } 
          // Set the instanceId you want to operate 
          instanceId := "your-choose-instance-id" 
          // Set whether to keep data 
          isPreserveData = false 
          if err := bbcClient.RebuildInstance(instanceId, isPreserveData, rebuildArgs); err != nil { 
              fmt.Println("rebuild instance failed: ", err) 
          } else { 
              fmt.Println("rebuild instance success.") 
          } 

          Note:

          IsPreserveData indicates whether to retain data:

          • When IsPreserveData is set to false, RaidId and SysRootSize are required parameters.
          • When IsPreserveData is set to true, the RaidId and SysRootSize parameters do not take effect.

          Release the Instance

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

          // Set the instanceId you want to operate 
          instanceId := "your-choose-instance-id" 
          if err := bbcClient.ReleaseInstance(instanceId); err != nil { 
              fmt.Println("release instance failed: ", err) 
          } else { 
              fmt.Println("release instance success.") 
          } 

          Modify Instance Password

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

          modifyInstancePasswordArgs := &ModifyInstancePasswordArgs{ 
              AdminPass: "your_new_password", 
          } 
          // Set the instanceId you want to operate 
          instanceId := "your-choose-instance-id" 
          if err := bbcClient.ModifyInstancePassword(instanceId, modifyInstancePasswordArgs); err != nil { 
              fmt.Println("modify instance password failed: ", err) 
          } else { 
              fmt.Println("modify instance password success.") 
          } 

          Note:

          BBC Example password requirements:

          • A password contains 8-16 characters among which English, numbers and symbols must coexist, and the symbols are only limited to!. @#$%^*()

          Query Instance VPC/Subnet Information

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

          // Set the instanceId you want to operate 
          instanceId := "your-choose-instance-id" 
          getVpcSubnetArgs := &GetVpcSubnetArgs{ 
              BbcIds: []string{instanceId}, 
          } 
          if res, err := bbcClient.GetVpcSubnet(getVpcSubnetArgs); err != nil { 
              fmt.Println("get vpc subnet failed: ", err) 
          } else { 
              fmt.Println("get vpc subnet success. res: ", res) 
          } 
          Previous
          Initialization
          Next
          Image