networking.rst 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. Private networking
  2. ==================
  3. Private networking gives you control over the networking setup for your
  4. instance(s) and is considered the preferred method for launching instances.
  5. Also, providers these days are increasingly requiring use of private networks.
  6. If you do not explicitly specify a private network to use when launching an
  7. instance, CloudBridge will attempt to use a default one. A 'default' network is
  8. one tagged as such by the native API. If such tag or functionality does not
  9. exist, CloudBridge will look for one with a predefined name (by default, called
  10. 'CloudBridgeNet', which can be overridden with environment variable
  11. ``CB_DEFAULT_NETWORK_NAME``).
  12. Create a new private network
  13. ----------------------------
  14. Creating a private network is a simple, one-line command but appropriately
  15. connecting it so it has Internet access is a multi-step process:
  16. (1) create a network; (2) create a subnet within this network; (3) create a
  17. router; (4) attach the router to an external network; and (5) add a route to
  18. the router that links with a subnet. For some providers, any network can
  19. be external (ie, connected to the Internet) while for others it's a specific,
  20. pre-defined one that exists in the an account by default. In order to properly
  21. connect the router, we need to ensure we're using an external network.
  22. When creating the subnet, we need to set an address pool. We can obtain the
  23. private network address space via network object's ``cidr_block`` field (e.g.,
  24. ``10.0.0.0/16``). Below, we'll create a subnet starting from the beginning of
  25. the block and allow up to 16 IP addresses into the subnet (``/28``).
  26. .. code-block:: python
  27. net = provider.network.create('cloudbridge_intro')
  28. sn = net.create_subnet('10.0.0.0/28', 'cloudbridge-intro')
  29. router = provider.network.create_router('cloudbridge-intro')
  30. if not net.external:
  31. for n in self.provider.network.list():
  32. if n.external:
  33. net = n
  34. break
  35. router.attach_network(net.id)
  36. router.add_route(sn.id)
  37. Retrieve an existing private network
  38. ------------------------------------
  39. If you already have existing networks, we can query for those:
  40. .. code-block:: python
  41. provider.network.list() # Find a desired network ID
  42. net = provider.network.get('desired network ID')