2
0

launch.rst 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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')
  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.
  19. .. code-block:: python
  20. kp = provider.security.key_pairs.find(name='cloudbridge_intro')
  21. sg = provider.security.security_groups.list()[0]
  22. Launch with classic networking
  23. ------------------------------
  24. Launching an instance with the traditional networking model is straighforward,
  25. only needing to specify the basic parameters:
  26. .. code-block:: python
  27. inst = provider.compute.instances.create(
  28. name='Cloudbridge-basic', image=img, instance_type=inst_type,
  29. keypair=kp, security_groups=[sg])
  30. Launch with private networking
  31. ------------------------------
  32. Before we can launch an instance into a private newtork, we need to supply a
  33. network into which the instance will get launched. To aggregate multiple such
  34. launch configuration options, we create a launch config object and supply it
  35. when launching an instance. Note that for the time being (Cloudbridge v0.1)
  36. there is no support for exploring the networking resources so it is necessary
  37. to get the network IDs via other means (e.g., native API, web dashboard).
  38. .. code-block:: python
  39. lc = provider.compute.instances.create_launch_config()
  40. lc.add_network_interface('subnet-c24aeaff')
  41. inst = provider.compute.instances.create(
  42. name='Cloudbridge-VPC', image=img, instance_type=inst_type,
  43. launch_config=lc, keypair=kp, security_groups=[sg])
  44. For OpenStack, the process is the same and you only need to specify the
  45. appropriate network interface ID (e.g.,
  46. ``lc.add_network_interface('5820c766-75fe-4fc6-96ef-798f67623238')``).
  47. ------------
  48. After an instance has launched, you can access it's properties:
  49. .. code-block:: python
  50. # Refresh the state
  51. inst.refresh()
  52. inst.state
  53. # 'running'
  54. inst.public_ips
  55. # [u'54.166.125.219']