networking.rst 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 name (by default, called
  11. 'CloudBridgeNet', which can be overridden with environment variable
  12. ``CB_DEFAULT_NETWORK_NAME``).
  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 The Application server must only be
  33. able to communicate with the database server in Subnet 3, and receive
  34. communication from the Web Server in Subnet 1. However, we assume a
  35. special case here where the application server needs to access the
  36. internet.
  37. - Tier 3/Subnet 3 - Database Server The database server must only be able to
  38. receive incoming traffic from Tier 2, but must not be able to make
  39. outgoing traffic outside of its subnet.
  40. At present, CloudBridge does not provide support for this scenario,
  41. primarily because OpenStack's FwaaS (Firewall-as-a-Service) is not widely
  42. available.
  43. 1. Allowing internet access from a launched VM
  44. ----------------------------------------------
  45. Creating a private network is a simple, one-line command but appropriately
  46. connecting it so that it has uniform Internet access across all providers
  47. is a multi-step process:
  48. (1) create a network; (2) create a subnet within this network; (3) create a
  49. router; (4) attach the router to the subnet and (5) attach the router to the
  50. internet gateway.
  51. When creating a network, we need to set an address pool. Any subsequent
  52. subnets you create must have a CIDR block that falls within the parent
  53. network's CIDR block. Below, we'll create a subnet starting from the beginning
  54. of the block and allow up to 16 IP addresses within a subnet (``/28``).
  55. .. code-block:: python
  56. net = provider.networking.networks.create(
  57. name='my-network', cidr_block='10.0.0.0/16')
  58. sn = net.create_subnet(name='my-subnet', cidr_block='10.0.0.0/28', zone=zone)
  59. router = provider.networking.routers.create(network=net, name='my-router')
  60. router.attach_subnet(sn)
  61. gateway = net.gateways.get_or_create_inet_gateway()
  62. router.attach_gateway(gateway)
  63. 2. Allowing internet access to a launched VM
  64. --------------------------------------------
  65. The additional step that's required here is to assign a floating IP to the VM:
  66. .. code-block:: python
  67. net = provider.networking.networks.create(
  68. name='my-network', cidr_block='10.0.0.0/16')
  69. sn = net.create_subnet(name='my-subnet', cidr_block='10.0.0.0/28', zone=zone)
  70. vm = provider.compute.instances.create('my-inst', subnet=sn, zone=zone, ...)
  71. router = provider.networking.routers.create(network=net, name='my-router')
  72. router.attach_subnet(sn)
  73. gateway = net.gateways.get_or_create_inet_gateway()
  74. router.attach_gateway(gateway)
  75. fip = provider.networking.floating_ips.create()
  76. vm.add_floating_ip(fip)
  77. Retrieve an existing private network
  78. ------------------------------------
  79. If you already have existing networks, we can query for it:
  80. .. code-block:: python
  81. provider.networking.networks.list() # Find a desired network ID
  82. net = provider.networking.networks.get('desired network ID')