Support for private IP addresses

The getting started sample will now run successfully on clouds that
use the private IP addresses as the public IP address.

Change-Id: I64680e96d7c05ea5e12bed4127eb0a48b6a66975
This commit is contained in:
Martin Paulo 2015-11-10 13:50:49 +11:00
parent 1b00f131dd
commit fceaa341af
2 changed files with 64 additions and 23 deletions

View File

@ -116,6 +116,18 @@ for instance in conn.list_nodes():
print(instance)
# step-13
private_ip = None
if len(testing_instance.private_ips):
private_ip = testing_instance.private_ips[0]
print('Private IP found: {}'.format(private_ip))
# step-14
public_ip = None
if len(testing_instance.public_ips):
public_ip = testing_instance.public_ips[0]
print('Public IP found: {}'.format(private_ip))
# step-15
print('Checking for unused Floating IP...')
unused_floating_ip = None
for floating_ip in conn.ex_list_floating_ips():
@ -123,16 +135,24 @@ for floating_ip in conn.ex_list_floating_ips():
unused_floating_ip = floating_ip
break
if not unused_floating_ip:
if not unused_floating_ip and len(conn.ex_list_floating_ip_pools()):
pool = conn.ex_list_floating_ip_pools()[0]
print('Allocating new Floating IP from pool: {}'.format(pool))
unused_floating_ip = pool.create_floating_ip()
# step-14
if len(testing_instance.public_ips) > 0:
# step-16
if public_ip:
print('Instance ' + testing_instance.name + ' already has a public ip. Skipping attachment.')
else:
elif unused_floating_ip:
conn.ex_attach_floating_ip_to_node(testing_instance, unused_floating_ip)
# step-15
print('The Fractals app will be deployed to http://%s' % unused_floating_ip.ip_address)
# step-17
actual_ip_address = None
if public_ip:
actual_ip_address = public_ip
elif unused_floating_ip:
actual_ip_address = unused_floating_ip.ip_address
elif private_ip:
actual_ip_address = private_ip
print('The Fractals app will be deployed to http://{}'.format(actual_ip_address))

View File

@ -210,8 +210,8 @@ to run code snippets in your language of choice.
.. only:: pkgcloud
To try it, add the following code to a script (or use an
interactive nodejs shell) by calling :code:`node`.
To try it, use an interactive Node.js shell by calling :code:`node` or add
the following code to a script.
.. literalinclude:: ../samples/pkgcloud/getting_started.js
:start-after: step-1
@ -526,7 +526,7 @@ this guide, you must change the image and flavor IDs to correspond to
the image and flavor that you choose.
If the image that you want is not available in your cloud, you can usually
upload one depending on your cloud's policy settings. For information about
upload one depending on the policy settings of your cloud. For information about
how to upload images, see
`obtaining images <http://docs.openstack.org/image-guide/content/ch_obtaining_images.html>`_.
@ -1219,31 +1219,51 @@ address to your instance.
.. only:: libcloud
Use :code:`ex_list_floating_ip_pools()` and select the first floating IP
address pool. Allocate this pool to your project and attach it to your
instance.
To see if there is a private IP address assigned to your instance:
.. literalinclude:: ../samples/libcloud/getting_started.py
:start-after: step-13
:end-before: step-14
If one is assigned, users can use this address to access the instance on
some OpenStack clouds.
To determine whether a public IP address is assigned to your instance:
.. literalinclude:: ../samples/libcloud/getting_started.py
:start-after: step-14
:end-before: step-15
If one is assigned, users can use this address to access the instance.
To create a floating IP address to use with your instance:
Use :code:`ex_list_floating_ip_pools()` and select the first floating IP
address pool. Allocate this pool to your project and use it to get a
floating IP address.
.. literalinclude:: ../samples/libcloud/getting_started.py
:start-after: step-15
:end-before: step-16
This code returns the floating IP address:
::
<OpenStack_1_1_FloatingIpAddress: id=4536ed1e-4374-4d7f-b02c-c3be2cb09b67, ip_addr=203.0.113.101, pool=<OpenStack_1_1_FloatingIpPool: name=floating001>, driver=<libcloud.compute.drivers.openstack.OpenStack_1_1_NodeDriver object at 0x1310b50>>
You can then attach it to the instance:
Attach the floating IP address to the instance:
.. literalinclude:: ../samples/libcloud/getting_started.py
:start-after: step-14
:end-before: step-15
:start-after: step-16
:end-before: step-17
.. only:: pkgcloud
Use :code:`getFloatingIps` to check for unused addresses, selecting the
first one if available, otherwise use :code:`allocateNewFloatingIp` to
allocate a new Floating IP to your project from the default address pool.
Use :code:`getFloatingIps` to check for unused addresses. Select the first
available address. Otherwise, use :code:`allocateNewFloatingIp` to
allocate a new floating IP to your project from the default address pool.
.. literalinclude:: ../samples/pkgcloud/getting_started.js
:start-after: step-13
@ -1255,7 +1275,7 @@ address to your instance.
203.0.113.101
You can then attach it to the instance:
Attach the floating IP address to the instance:
.. literalinclude:: ../samples/pkgcloud/getting_started.js
:start-after: step-14
@ -1300,8 +1320,8 @@ Access the application
Deploying application data and configuration to the instance can take some
time. Consider enjoying a cup of coffee while you wait. After the application
deploys, you can visit the awesome graphic interface at the following link
by using your preferred browser.
deploys, you can use your preferred browser to visit the awesome graphic
interface at the following link.
.. only:: fog
@ -1312,7 +1332,7 @@ by using your preferred browser.
.. only:: libcloud
.. literalinclude:: ../samples/libcloud/getting_started.py
:start-after: step-15
:start-after: step-17
.. only:: pkgcloud
@ -1329,7 +1349,8 @@ by using your preferred browser.
.. literalinclude:: ../samples/openstacksdk/getting_started.py
:start-after: step-15
.. note:: If you do not use floating IPs, substitute another IP address as appropriate
.. note:: If you do not use floating IP addresses, substitute another IP
address, as appropriate.
.. figure:: images/screenshot_webinterface.png
:width: 800px