github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/servers/doc.go (about)

     1  /*
     2  Package servers provides information and interaction with the server API
     3  resource in the OpenStack Compute service.
     4  
     5  A server is a virtual machine instance in the compute system. In order for
     6  one to be provisioned, a valid flavor and image are required.
     7  
     8  Example to List Servers
     9  
    10  	listOpts := servers.ListOpts{
    11  		AllTenants: true,
    12  	}
    13  
    14  	allPages, err := servers.List(computeClient, listOpts).AllPages()
    15  	if err != nil {
    16  		panic(err)
    17  	}
    18  
    19  	allServers, err := servers.ExtractServers(allPages)
    20  	if err != nil {
    21  		panic(err)
    22  	}
    23  
    24  	for _, server := range allServers {
    25  		fmt.Printf("%+v\n", server)
    26  	}
    27  
    28  Example to Create a Server
    29  
    30  	createOpts := servers.CreateOpts{
    31  		Name:      "server_name",
    32  		ImageRef:  "image-uuid",
    33  		FlavorRef: "flavor-uuid",
    34  	}
    35  
    36  	server, err := servers.Create(computeClient, createOpts).Extract()
    37  	if err != nil {
    38  		panic(err)
    39  	}
    40  
    41  Example to Delete a Server
    42  
    43  	serverID := "d9072956-1560-487c-97f2-18bdf65ec749"
    44  	err := servers.Delete(computeClient, serverID).ExtractErr()
    45  	if err != nil {
    46  		panic(err)
    47  	}
    48  
    49  Example to Force Delete a Server
    50  
    51  	serverID := "d9072956-1560-487c-97f2-18bdf65ec749"
    52  	err := servers.ForceDelete(computeClient, serverID).ExtractErr()
    53  	if err != nil {
    54  		panic(err)
    55  	}
    56  
    57  Example to Reboot a Server
    58  
    59  	rebootOpts := servers.RebootOpts{
    60  		Type: servers.SoftReboot,
    61  	}
    62  
    63  	serverID := "d9072956-1560-487c-97f2-18bdf65ec749"
    64  
    65  	err := servers.Reboot(computeClient, serverID, rebootOpts).ExtractErr()
    66  	if err != nil {
    67  		panic(err)
    68  	}
    69  
    70  Example to Rebuild a Server
    71  
    72  	rebuildOpts := servers.RebuildOpts{
    73  		Name:    "new_name",
    74  		ImageID: "image-uuid",
    75  	}
    76  
    77  	serverID := "d9072956-1560-487c-97f2-18bdf65ec749"
    78  
    79  	server, err := servers.Rebuilt(computeClient, serverID, rebuildOpts).Extract()
    80  	if err != nil {
    81  		panic(err)
    82  	}
    83  
    84  Example to Resize a Server
    85  
    86  	resizeOpts := servers.ResizeOpts{
    87  		FlavorRef: "flavor-uuid",
    88  	}
    89  
    90  	serverID := "d9072956-1560-487c-97f2-18bdf65ec749"
    91  
    92  	err := servers.Resize(computeClient, serverID, resizeOpts).ExtractErr()
    93  	if err != nil {
    94  		panic(err)
    95  	}
    96  
    97  	err = servers.ConfirmResize(computeClient, serverID).ExtractErr()
    98  	if err != nil {
    99  		panic(err)
   100  	}
   101  
   102  Example to Snapshot a Server
   103  
   104  	snapshotOpts := servers.CreateImageOpts{
   105  		Name: "snapshot_name",
   106  	}
   107  
   108  	serverID := "d9072956-1560-487c-97f2-18bdf65ec749"
   109  
   110  	image, err := servers.CreateImage(computeClient, serverID, snapshotOpts).ExtractImageID()
   111  	if err != nil {
   112  		panic(err)
   113  	}
   114  */
   115  package servers