Просмотр исходного кода

Fixed some bugs in documentation

Nuwan Goonasekera 8 лет назад
Родитель
Сommit
497a2f0dd9
3 измененных файлов с 59 добавлено и 15 удалено
  1. 33 8
      docs/getting_started.rst
  2. 24 7
      docs/topics/launch.rst
  3. 2 0
      docs/topics/networking.rst

+ 33 - 8
docs/getting_started.rst

@@ -91,16 +91,31 @@ on disk as a read-only file.
     import os
     import os
     os.chmod('cloudbridge_intro.pem', 0400)
     os.chmod('cloudbridge_intro.pem', 0400)
 
 
+Create a network
+----------------
+A cloudbridge instance should be launched into a private subnet. We'll create
+a private network and subnet, and make sure it has internet connectivity, by
+attaching an internet gateway to the subnet via a router.
+
+.. code-block:: python
+
+    net = self.provider.networking.networks.create(
+        name='my-network', cidr_block='10.0.0.0/16')
+    sn = net.create_subnet(name='my-subnet', cidr_block='10.0.0.0/28')
+    router = self.provider.networking.routers.create(network=net, name='my-router')
+    router.attach_subnet(sn)
+    gateway = self.provider.networking.gateways.get_or_create_inet_gateway(name)
+    router.attach_gateway(gateway)
+
+
 Create a security group
 Create a security group
 -----------------------
 -----------------------
 Next, we need to create a security group and add a rule to allow ssh access.
 Next, we need to create a security group and add a rule to allow ssh access.
-A security group needs to be associated with a private network, so we'll also
-need to fetch it.
+A security group needs to be associated with a private network.
 
 
 .. code-block:: python
 .. code-block:: python
 
 
-    provider.network.list()  # Find a desired network ID
-    net = provider.network.get('desired network ID')
+    net = provider.networking.networks.get('desired network ID')
     sg = provider.security.security_groups.create(
     sg = provider.security.security_groups.create(
         'cloudbridge_intro', 'A security group used by CloudBridge', net.id)
         'cloudbridge_intro', 'A security group used by CloudBridge', net.id)
     sg.add_rule('tcp', 22, 22, '0.0.0.0/0')
     sg.add_rule('tcp', 22, 22, '0.0.0.0/0')
@@ -114,18 +129,27 @@ also add the network interface as a launch argument.
 .. code-block:: python
 .. code-block:: python
 
 
     img = provider.compute.images.get(image_id)
     img = provider.compute.images.get(image_id)
-    inst_type = sorted([t for t in provider.compute.instance_types.list()
+    inst_type = sorted([t for t in provider.compute.instance_types
                         if t.vcpus >= 2 and t.ram >= 4],
                         if t.vcpus >= 2 and t.ram >= 4],
                        key=lambda x: x.vcpus*x.ram)[0]
                        key=lambda x: x.vcpus*x.ram)[0]
     inst = provider.compute.instances.create(
     inst = provider.compute.instances.create(
         name='CloudBridge-intro', image=img, instance_type=inst_type,
         name='CloudBridge-intro', image=img, instance_type=inst_type,
-        network=net, key_pair=kp, security_groups=[sg])
+        subnet=subnet, key_pair=kp, security_groups=[sg])
     # Wait until ready
     # Wait until ready
     inst.wait_till_ready()  # This is a blocking call
     inst.wait_till_ready()  # This is a blocking call
     # Show instance state
     # Show instance state
     inst.state
     inst.state
     # 'running'
     # 'running'
 
 
+.. note ::
+
+   Note that we iterated through provider.compute.instance_types directly
+   instead of calling provider.compute.instance_types.list(). This is
+   because we need to iterate through all records in this case. The list()
+   method may not always return all records, depending on the global limit
+   for records, necessitating that additional records be paged in. See
+   :doc:`topics/paging_and_iteration`.
+
 Assign a public IP address
 Assign a public IP address
 --------------------------
 --------------------------
 To access the instance, let's assign a public IP address to the instance. For
 To access the instance, let's assign a public IP address to the instance. For
@@ -157,8 +181,9 @@ To wrap things up, let's clean up all the resources we have created
     sg.delete()
     sg.delete()
     kp.delete()
     kp.delete()
     os.remove('cloudbridge_intro.pem')
     os.remove('cloudbridge_intro.pem')
-    router.remove_route(sn.id)
-    router.detach_network()
+    router.detach_gateway(gateway)
+    router.detach_subnet(subnet)
+    gateway.delete()
     router.delete()
     router.delete()
     sn.delete()
     sn.delete()
     net.delete()
     net.delete()

+ 24 - 7
docs/topics/launch.rst

@@ -15,10 +15,20 @@ and 4 GB RAM.
 .. code-block:: python
 .. code-block:: python
 
 
     img = provider.compute.images.get('ami-f4cc1de2')  # Ubuntu 16.04 on AWS
     img = provider.compute.images.get('ami-f4cc1de2')  # Ubuntu 16.04 on AWS
-    inst_type = sorted([t for t in provider.compute.instance_types.list()
+    inst_type = sorted([t for t in provider.compute.instance_types
                         if t.vcpus >= 2 and t.ram >= 4],
                         if t.vcpus >= 2 and t.ram >= 4],
                        key=lambda x: x.vcpus*x.ram)[0]
                        key=lambda x: x.vcpus*x.ram)[0]
 
 
+In addition, CloudBridge instances must be launched into a private subnet.
+While it is possible to create complex network configurations as shown in the
+`Private networking`_ section, if you don't particularly care where the
+instance is launched, CloudBridge provides a convenience function to quickly
+obtain a default subnet for use.
+
+.. code-block:: python
+
+    subnet = provider.networking.subnets.get_or_create_default()
+
 When launching an instance, you can also specify several optional arguments
 When launching an instance, you can also specify several optional arguments
 such as the security group, a key pair, or instance user data. To allow you to
 such as the security group, a key pair, or instance user data. To allow you to
 connect to the launched instances, we will also supply those parameters (note
 connect to the launched instances, we will also supply those parameters (note
@@ -39,20 +49,27 @@ Once we have all the desired pieces, we'll use them to launch an instance:
 
 
     inst = provider.compute.instances.create(
     inst = provider.compute.instances.create(
         name='CloudBridge-VPC', image=img, instance_type=inst_type,
         name='CloudBridge-VPC', image=img, instance_type=inst_type,
-        key_pair=kp, security_groups=[sg])
+        subnet=subnet, key_pair=kp, security_groups=[sg])
 
 
 Private networking
 Private networking
 ~~~~~~~~~~~~~~~~~~
 ~~~~~~~~~~~~~~~~~~
 Private networking gives you control over the networking setup for your
 Private networking gives you control over the networking setup for your
 instance(s) and is considered the preferred method for launching instances. To
 instance(s) and is considered the preferred method for launching instances. To
-launch an instance with an explicit private network, supply a subnet within
-a network as an additional argument to the ``create`` method:
+launch an instance with an explicit private network, you can create a custom
+network and make sure it has internet connectivity. You can then launch into
+that subnet.
 
 
 .. code-block:: python
 .. code-block:: python
 
 
-    provider.network.list()  # Find a desired network ID
-    net = provider.network.get('desired network ID')
-    sn = net.subnets()[0]  # Get a handle on the desired subnet to launch with
+    net = self.provider.networking.networks.create(
+        name='my-network', cidr_block='10.0.0.0/16')
+    sn = net.create_subnet(name='my-subnet', cidr_block='10.0.0.0/28')
+    # make sure subnet has internet access
+    router = self.provider.networking.routers.create(network=net, name='my-router')
+    router.attach_subnet(sn)
+    gateway = self.provider.networking.gateways.get_or_create_inet_gateway(name)
+    router.attach_gateway(gateway)
+
     inst = provider.compute.instances.create(
     inst = provider.compute.instances.create(
         name='CloudBridge-VPC', image=img, instance_type=inst_type,
         name='CloudBridge-VPC', image=img, instance_type=inst_type,
         subnet=sn, key_pair=kp, security_groups=[sg])
         subnet=sn, key_pair=kp, security_groups=[sg])

+ 2 - 0
docs/topics/networking.rst

@@ -20,6 +20,7 @@ several common scenarios.
    In the simplest scenario, a user may simply want to launch an instance and
    In the simplest scenario, a user may simply want to launch an instance and
    allow the instance to access the internet.
    allow the instance to access the internet.
 
 
+
 2. Allowing internet access to a launched VM
 2. Allowing internet access to a launched VM
 
 
    Alternatively, the user may want to allow the instance to be contactable
    Alternatively, the user may want to allow the instance to be contactable
@@ -29,6 +30,7 @@ several common scenarios.
    the latter scenario, the gateway/jump host/bastion host will need to be
    the latter scenario, the gateway/jump host/bastion host will need to be
    contactable over the internet.
    contactable over the internet.
 
 
+
 3. Secure access between subnets for n-tier applications
 3. Secure access between subnets for n-tier applications
 
 
    In this third scenario, a multi-tier app may be deployed into several
    In this third scenario, a multi-tier app may be deployed into several