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

     1  /*
     2  Package bootfromvolume extends a server create request with the ability to
     3  specify block device options. This can be used to boot a server from a block
     4  storage volume as well as specify multiple ephemeral disks upon creation.
     5  
     6  It is recommended to refer to the Block Device Mapping documentation to see
     7  all possible ways to configure a server's block devices at creation time:
     8  
     9  https://docs.openstack.org/nova/latest/user/block-device-mapping.html
    10  
    11  Note that this package implements `block_device_mapping_v2`.
    12  
    13  Example of Creating a Server From an Image
    14  
    15  This example will boot a server from an image and use a standard ephemeral
    16  disk as the server's root disk. This is virtually no different than creating
    17  a server without using block device mappings.
    18  
    19  	blockDevices := []bootfromvolume.BlockDevice{
    20  		bootfromvolume.BlockDevice{
    21  			BootIndex:           0,
    22  			DeleteOnTermination: true,
    23  			DestinationType:     bootfromvolume.DestinationLocal,
    24  			SourceType:          bootfromvolume.SourceImage,
    25  			UUID:                "image-uuid",
    26  		},
    27  	}
    28  
    29  	serverCreateOpts := servers.CreateOpts{
    30  		Name:      "server_name",
    31  		FlavorRef: "flavor-uuid",
    32  		ImageRef:  "image-uuid",
    33  	}
    34  
    35  	createOpts := bootfromvolume.CreateOptsExt{
    36  		CreateOptsBuilder: serverCreateOpts,
    37  		BlockDevice:       blockDevices,
    38  	}
    39  
    40  	server, err := bootfromvolume.Create(client, createOpts).Extract()
    41  	if err != nil {
    42  		panic(err)
    43  	}
    44  
    45  Example of Creating a Server From a New Volume
    46  
    47  This example will create a block storage volume based on the given Image. The
    48  server will use this volume as its root disk.
    49  
    50  	blockDevices := []bootfromvolume.BlockDevice{
    51  		bootfromvolume.BlockDevice{
    52  			DeleteOnTermination: true,
    53  			DestinationType:     bootfromvolume.DestinationVolume,
    54  			SourceType:          bootfromvolume.SourceImage,
    55  			UUID:                "image-uuid",
    56  			VolumeSize:          2,
    57  		},
    58  	}
    59  
    60  	serverCreateOpts := servers.CreateOpts{
    61  		Name:      "server_name",
    62  		FlavorRef: "flavor-uuid",
    63  	}
    64  
    65  	createOpts := bootfromvolume.CreateOptsExt{
    66  		CreateOptsBuilder: serverCreateOpts,
    67  		BlockDevice:       blockDevices,
    68  	}
    69  
    70  	server, err := bootfromvolume.Create(client, createOpts).Extract()
    71  	if err != nil {
    72  		panic(err)
    73  	}
    74  
    75  Example of Creating a Server From an Existing Volume
    76  
    77  This example will create a server with an existing volume as its root disk.
    78  
    79  	blockDevices := []bootfromvolume.BlockDevice{
    80  		bootfromvolume.BlockDevice{
    81  			DeleteOnTermination: true,
    82  			DestinationType:     bootfromvolume.DestinationVolume,
    83  			SourceType:          bootfromvolume.SourceVolume,
    84  			UUID:                "volume-uuid",
    85  		},
    86  	}
    87  
    88  	serverCreateOpts := servers.CreateOpts{
    89  		Name:      "server_name",
    90  		FlavorRef: "flavor-uuid",
    91  	}
    92  
    93  	createOpts := bootfromvolume.CreateOptsExt{
    94  		CreateOptsBuilder: serverCreateOpts,
    95  		BlockDevice:       blockDevices,
    96  	}
    97  
    98  	server, err := bootfromvolume.Create(client, createOpts).Extract()
    99  	if err != nil {
   100  		panic(err)
   101  	}
   102  
   103  Example of Creating a Server with Multiple Ephemeral Disks
   104  
   105  This example will create a server with multiple ephemeral disks. The first
   106  block device will be based off of an existing Image. Each additional
   107  ephemeral disks must have an index of -1.
   108  
   109  	blockDevices := []bootfromvolume.BlockDevice{
   110  		bootfromvolume.BlockDevice{
   111  			BootIndex:           0,
   112  			DestinationType:     bootfromvolume.DestinationLocal,
   113  			DeleteOnTermination: true,
   114  			SourceType:          bootfromvolume.SourceImage,
   115  			UUID:                "image-uuid",
   116  			VolumeSize:          5,
   117  		},
   118  		bootfromvolume.BlockDevice{
   119  			BootIndex:           -1,
   120  			DestinationType:     bootfromvolume.DestinationLocal,
   121  			DeleteOnTermination: true,
   122  			GuestFormat:         "ext4",
   123  			SourceType:          bootfromvolume.SourceBlank,
   124  			VolumeSize:          1,
   125  		},
   126  		bootfromvolume.BlockDevice{
   127  			BootIndex:           -1,
   128  			DestinationType:     bootfromvolume.DestinationLocal,
   129  			DeleteOnTermination: true,
   130  			GuestFormat:         "ext4",
   131  			SourceType:          bootfromvolume.SourceBlank,
   132  			VolumeSize:          1,
   133  		},
   134  	}
   135  
   136  	serverCreateOpts := servers.CreateOpts{
   137  		Name:      "server_name",
   138  		FlavorRef: "flavor-uuid",
   139  		ImageRef:  "image-uuid",
   140  	}
   141  
   142  	createOpts := bootfromvolume.CreateOptsExt{
   143  		CreateOptsBuilder: serverCreateOpts,
   144  		BlockDevice:       blockDevices,
   145  	}
   146  
   147  	server, err := bootfromvolume.Create(client, createOpts).Extract()
   148  	if err != nil {
   149  		panic(err)
   150  	}
   151  */
   152  package bootfromvolume