launch.rst 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. Launching instances
  2. ===================
  3. Depending on the cloud provider, instances can be launched using
  4. software-managed networking (e.g., VPC on AWS, Neutron on OpenStack) or the
  5. classic networking approach. Before being able to run below command, you will
  6. need a ``provider`` object (see `this page <setup.html>`_).
  7. Common launch data
  8. ------------------
  9. Before launching an instane, you need to decide on what image to launch
  10. as well as what type of instance. We will create those objects here are use
  11. them in both options below. The specified image ID is a base Ubuntu image on
  12. AWS so feel free to change it as desired.
  13. .. code-block:: python
  14. img = provider.compute.images.get('ami-d85e75b0')
  15. inst_type = provider.compute.instance_types.find(name='m1.small')[0]
  16. When launching an instance, you can also specify several optional arguments
  17. such as the security group, a key pair, or instance user data. To allow you to
  18. connect to the launched instances, we will also supply those parameters (note
  19. that we're making an assumption here these resources exist; if you don't have
  20. those resources, take a look at the `Getting Started <../getting_started.html>`_
  21. guide).
  22. .. code-block:: python
  23. kp = provider.security.key_pairs.find(name='cloudbridge_intro')[0]
  24. sg = provider.security.security_groups.list()[0]
  25. Launch with classic networking
  26. ------------------------------
  27. Launching an instance with the traditional networking model is straighforward,
  28. only needing to specify the basic parameters:
  29. .. code-block:: python
  30. inst = provider.compute.instances.create(
  31. name='Cloudbridge-basic', image=img, instance_type=inst_type,
  32. keypair=kp, security_groups=[sg])
  33. Launch with private networking
  34. ------------------------------
  35. Before we can launch an instance into a private network, we need to supply a
  36. network into which the instance will get launched. To aggregate multiple such
  37. launch configuration options, we create a launch config object and supply it
  38. when launching an instance. Note that for the time being (Cloudbridge v0.1)
  39. there is no support for exploring the networking resources so it is necessary
  40. to get the network IDs via other means (e.g., native API, web dashboard).
  41. .. code-block:: python
  42. lc = provider.compute.instances.create_launch_config()
  43. lc.add_network_interface('subnet-c24aeaff')
  44. inst = provider.compute.instances.create(
  45. name='Cloudbridge-VPC', image=img, instance_type=inst_type,
  46. launch_config=lc, keypair=kp, security_groups=[sg])
  47. For OpenStack, the process is the same and you only need to specify the
  48. appropriate network interface ID (e.g.,
  49. ``lc.add_network_interface('5820c766-75fe-4fc6-96ef-798f67623238')``).
  50. Block device mapping
  51. --------------------
  52. Optionally, you may want to provide a block device mapping at launch,
  53. specifying volume or ephemeral storage mappings for the instance. While volumes
  54. can also be attached and mapped after instance boot using the volume service,
  55. specifying block device mappings at launch time is especially useful when it is
  56. necessary to resize the root volume.
  57. The code below demonstrates how to resize the root volume. For more information,
  58. refer to :class:`.LaunchConfig`.
  59. .. code-block:: python
  60. lc = provider.compute.instances.create_launch_config()
  61. lc.add_volume_device(source=img, size=11, is_root=True)
  62. inst = provider.compute.instances.create(
  63. name='Cloudbridge-BDM', image=img, instance_type=inst_type,
  64. launch_config=lc, keypair=kp, security_groups=[sg])
  65. where img is the :class:`.Image` object to use for the root volume.
  66. After an instance has launched, you can access its properties:
  67. .. code-block:: python
  68. # Wait until ready
  69. inst.wait_till_ready()
  70. inst.state
  71. # 'running'
  72. inst.public_ips
  73. # [u'54.166.125.219']