networking.rst 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. All CloudBridge deployed VMs must be deployed into a particular subnet.
  7. If you do not explicitly specify a private network to use when launching an
  8. instance, CloudBridge will attempt to use a default one. A 'default' network is
  9. one tagged as such by the native API. If such tag or functionality does not
  10. exist, CloudBridge will look for one with a predefined label (by default,
  11. called 'cloudbridge-net', which can be overridden with environment variable
  12. ``CB_DEFAULT_NETWORK_LABEL``).
  13. Once a VM is deployed, CloudBridge's networking capabilities must address
  14. several common scenarios.
  15. 1. Allowing internet access from a launched VM
  16. In the simplest scenario, a user may simply want to launch an instance and
  17. allow the instance to access the internet.
  18. 2. Allowing internet access to a launched VM
  19. Alternatively, the user may want to allow the instance to be contactable
  20. from the internet. In a more complex scenario, a user may want to deploy
  21. VMs into several subnets, and deploy a gateway, jump host, or bastion host
  22. to access other VMs which are not directly connected to the internet. In
  23. the latter scenario, the gateway/jump host/bastion host will need to be
  24. contactable over the internet.
  25. 3. Secure access between subnets for n-tier applications
  26. In this third scenario, a multi-tier app may be deployed into several
  27. subnets depending on their tier. For example, consider the following
  28. scenario:
  29. - Tier 1/Subnet 1 - Web Server needs to be externally accessible over the
  30. internet. However, in this particular scenario, the web server itself does
  31. not need access to the internet.
  32. - Tier 2/Subnet 2 - Application Server must only be able to communicate with
  33. the database server in Subnet 3, and receive communication from the Web
  34. Server in Subnet 1. However, we assume a special case here where the
  35. application server needs to access the internet.
  36. - Tier 3/Subnet 3 - Database Server must only be able to receive incoming
  37. traffic from Tier 2, but must not be able to make outgoing traffic outside
  38. of its subnet.
  39. At present, CloudBridge does not provide support for this scenario,
  40. primarily because OpenStack's FwaaS (Firewall-as-a-Service) is not widely
  41. available.
  42. 1. Allowing internet access from a launched VM
  43. ----------------------------------------------
  44. Creating a private network is a simple, one-line command but appropriately
  45. connecting it so that it has uniform internet access across all providers
  46. is a multi-step process:
  47. (1) create a network; (2) create a subnet within this network; (3) create a
  48. router; (4) attach the router to the subnet; and (5) attach the router to the
  49. internet gateway.
  50. When creating a network, we need to set an address pool. Any subsequent
  51. subnets you create must have a CIDR block that falls within the parent
  52. network's CIDR block. CloudBridge also defines a default IPv4 network range in
  53. ``BaseNetwork.CB_DEFAULT_IPV4RANGE``. Below, we'll create a subnet starting
  54. from the beginning of the block and allow up to 16 IP addresses within a
  55. subnet (``/28``).
  56. .. code-block:: python
  57. net = provider.networking.networks.create(
  58. label='my-network', cidr_block='10.0.0.0/16')
  59. sn = net.subnets.create(label='my-subnet',
  60. cidr_block='10.0.0.0/28',
  61. zone=zone)
  62. router = provider.networking.routers.create(label='my-router', network=net)
  63. router.attach_subnet(sn)
  64. gateway = net.gateways.get_or_create()
  65. router.attach_gateway(gateway)
  66. 2. Allowing internet access to a launched VM
  67. --------------------------------------------
  68. The additional step that's required here is to assign a floating IP to the VM:
  69. .. code-block:: python
  70. net = provider.networking.networks.create(
  71. label='my-network', cidr_block='10.0.0.0/16')
  72. sn = net.subnets.create(label='my-subnet', cidr_block='10.0.0.0/28', zone=zone)
  73. vm = provider.compute.instances.create(label='my-inst', subnet=sn, zone=zone, ...)
  74. router = provider.networking.routers.create(label='my-router', network=net)
  75. router.attach_subnet(sn)
  76. gateway = net.gateways.get_or_create()
  77. router.attach_gateway(gateway)
  78. fip = provider.networking.floating_ips.create()
  79. vm.add_floating_ip(fip)
  80. Retrieve an existing private network
  81. ------------------------------------
  82. If you already have existing networks, we can query for it:
  83. .. code-block:: python
  84. provider.networking.networks.list() # Find a desired network ID
  85. net = provider.networking.networks.get('desired network ID')