From 4e935617777bc78997a517d229d66ea0be600f62 Mon Sep 17 00:00:00 2001 From: Marcela Bonell Date: Fri, 8 Jul 2016 12:23:24 -0500 Subject: [PATCH] MyFirstApp: Introduction section with shade Improve and complete the code in this section. Change-Id: I6b214c9560a537d4dd8db5b3a15d91deeef00aaa --- firstapp/samples/shade/introduction.py | 38 ++++++++++++++++---------- firstapp/source/introduction.rst | 25 ++++++++++++++++- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/firstapp/samples/shade/introduction.py b/firstapp/samples/shade/introduction.py index edc1cd6dd..7eb211746 100644 --- a/firstapp/samples/shade/introduction.py +++ b/firstapp/samples/shade/introduction.py @@ -8,7 +8,9 @@ curl -L -s https://git.openstack.org/cgit/openstack/faafo/plain/contrib/install. instance_name = 'all-in-one' testing_instance = conn.create_server(wait=True, auto_ip=False, name=instance_name, - image=image_id, flavor=flavor_id, key_name=keypair_name, + image=image_id, + flavor=flavor_id, + key_name=keypair_name, security_groups=[sec_group_name], userdata=userdata) @@ -25,13 +27,13 @@ conn.create_security_group(sec_group_name, 'network access for all-in-one applic conn.create_security_group_rule(sec_group_name, 80, 80, 'TCP') conn.create_security_group_rule(sec_group_name, 22, 22, 'TCP') -conn.search_security_groups(sec_group_name) - # step-4 -conn.list_security_groups() +sec_groups = conn.list_security_groups() +for sec_group in sec_groups: + print(sec_group) # step-5 -conn.delete_security_group_rule(rule['id']) +conn.delete_security_group_rule(rule_id) conn.delete_security_group(sec_group_name) # step-6 @@ -47,13 +49,21 @@ unused_floating_ip = conn.available_floating_ip() conn.add_ip_list(testing_instance, [unused_floating_ip['floating_ip_address']]) # step-11 -worker_group = conn.create_security_group('worker', 'for services that run on a worker node') -conn.create_security_group_rule(worker_group['name'], 22, 22, 'TCP') +worker_group_name = 'worker' +if conn.search_security_groups(worker_group_name): + print('Security group \'%s\' already exists. Skipping creation.' % worker_group_name) +else: + worker_group = conn.create_security_group(worker_group_name, 'for services that run on a worker node') + conn.create_security_group_rule(worker_group['name'], 22, 22, 'TCP') -controller_group = conn.create_security_group('control', 'for services that run on a control node') -conn.create_security_group_rule(controller_group['name'], 22, 22, 'TCP') -conn.create_security_group_rule(controller_group['name'], 80, 80, 'TCP') -conn.create_security_group_rule(controller_group['name'], 5672, 5672, 'TCP', remote_group_id=worker_group['id']) +controller_group_name = 'control' +if conn.search_security_groups(controller_group_name): + print('Security group \'%s\' already exists. Skipping creation.' % controller_group_name) +else: + controller_group = conn.create_security_group(controller_group_name, 'for services that run on a control node') + conn.create_security_group_rule(controller_group['name'], 22, 22, 'TCP') + conn.create_security_group_rule(controller_group['name'], 80, 80, 'TCP') + conn.create_security_group_rule(controller_group['name'], 5672, 5672, 'TCP', remote_group_id=worker_group['id']) userdata = '''#!/usr/bin/env bash curl -L -s http://git.openstack.org/cgit/openstack/faafo/plain/contrib/install.sh | bash -s -- \ @@ -65,7 +75,7 @@ instance_controller_1 = conn.create_server(wait=True, auto_ip=False, image=image_id, flavor=flavor_id, key_name=keypair_name, - security_groups=[controller_group['name']], + security_groups=[controller_group_name], userdata=userdata) unused_floating_ip = conn.available_floating_ip() @@ -91,7 +101,7 @@ instance_worker_1 = conn.create_server(wait=True, auto_ip=False, image=image_id, flavor=flavor_id, key_name=keypair_name, - security_groups=[worker_group['name']], + security_groups=[worker_group_name], userdata=userdata) unused_floating_ip = conn.available_floating_ip() @@ -104,5 +114,3 @@ print('The worker will be available for SSH at %s' % unused_floating_ip['floatin instance_worker_1 = conn.get_server(instance_worker_1['name']) ip_instance_worker_1 = conn.get_server_public_ip(instance_worker_1) print(ip_instance_worker_1) - -# step-14 diff --git a/firstapp/source/introduction.rst b/firstapp/source/introduction.rst index d459b35a3..7b3096d28 100644 --- a/firstapp/source/introduction.rst +++ b/firstapp/source/introduction.rst @@ -403,6 +403,30 @@ To see which security groups apply to an instance, you can: :start-after: step-6 :end-before: step-7 + .. code-block:: none + + name: 'all-in-one', + description: 'network access for all-in-one application.', + security_group_rules: + - direction: 'ingress', + protocol': 'tcp', + remote_ip_prefix: '0.0.0.0/0', + port_range_max: 22, + security_group_id: '83aa1bf9-564a-47da-bb46-60cd1c63cc84', + port_range_min: 22, + ethertype: 'IPv4', + id: '5ff0008f-a02d-4b40-9719-f52c77dfdab0', + - direction: 'ingress', + protocol: 'tcp', + remote_ip_prefix: '0.0.0.0/0', + port_range_max: 80, + security_group_id: '83aa1bf9-564a-47da-bb46-60cd1c63cc84', + port_range_min: 80, + ethertype: 'IPv4', + id: 'c2539e49-b110-4657-bf0a-7a221f5e9e6f', + id: '83aa1bf9-564a-47da-bb46-60cd1c63cc84' + + .. only:: fog .. literalinclude:: ../samples/fog/introduction.rb @@ -676,7 +700,6 @@ address of the worker: .. literalinclude:: ../samples/shade/introduction.py :language: python :start-after: step-13 - :end-before: step-14 .. only:: fog