summaryrefslogtreecommitdiffstats
path: root/utils/infra_setup/runner/stack.py
diff options
context:
space:
mode:
authorliyin <liyin11@huawei.com>2017-01-24 17:26:21 +0800
committerAce Lee <liyin11@huawei.com>2017-02-07 02:00:00 +0000
commitc6755e612b322facefc4edc32e948ab2b00bb3b0 (patch)
treef3796ea159c10c9e9690c8b9072f37ebc0ea1f9c /utils/infra_setup/runner/stack.py
parentca641fcdaa919afb072a9625eb9ba3848b9e3805 (diff)
Bottlenecks POSCA testing code reconstruction
JIRA:BOTTLENECK-103 This is the foundation of adding stack samples. This code change a lot code. but it's a basic. Those code will be changed in the furture. Change-Id: I8d5bbb9cc401b1aaac54ec4dffc4c005a42d17ac Signed-off-by: liyin <liyin11@huawei.com>
Diffstat (limited to 'utils/infra_setup/runner/stack.py')
-rw-r--r--utils/infra_setup/runner/stack.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/utils/infra_setup/runner/stack.py b/utils/infra_setup/runner/stack.py
new file mode 100644
index 00000000..fb78c360
--- /dev/null
+++ b/utils/infra_setup/runner/stack.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+##############################################################################
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+'''This file realize the function of use config to be born with a template
+a template is use to create a stack in openstack.
+This file will be amended in the furture.'''
+
+import utils.infra_setup.heat.template as Heat
+
+class stack_api():
+
+ def from_config_template(stack_info):
+ stack_name = stack_info['name']
+ ext_gw_net = os.environ.get("EXTERNAL_NETWORK")
+ heat_parser = HeatTemplate_Parser()
+ heat_parser.add_security_group(stack_name)
+ heat_parser.add_keypair(stack_name)
+ for network in stack_info['networks']:
+ heat_parser.add_network(stack_name)
+ heat_parser.add_subnet(stack_name,
+ stack_info['networks'][network]['cidr'])
+
+ heat_parser.add_router(stack_name, ext_gw_net)
+ heat_parser.add_router_interface(stack_name)
+
+ for server in stack_info['servers']:
+ heat_parser.add_port(server, stack_name)
+ heat_parser.add_floating_ip(server, stack_name, ext_gw_net)
+ heat_parser.add_floating_ip_ass(server)
+ heat_parser.add_server(server,
+ stack_info['servers'][server]['image'],
+ stack_info['servers'][server]['flavor'],
+ stack_info['servers'][server]['user'])
+
+ template = heat_parser.get_template_date()
+ stack = Heat.HeatTemplate(name=stack_name, heat_template=template)
+ try:
+ self.stack = stack.create()
+ except KeyboardInterrupt:
+ sys.exit("\nStack create interrupted")
+ except RuntimeError as err:
+ sys.exit("error: failed to deploy stack: '%s'" % err.args)
+ except Exception as err:
+ sys.exit("error: failed to deploy stack: '%s'" % err)
+
+ for server in stack_info['servers']:
+ if len(server.ports) > 0:
+ # TODO(hafe) can only handle one internal network for now
+ port = list(server.ports.values())[0]
+ server.private_ip = self.stack.outputs[port["stack_name"]]
+
+ if server.floating_ip:
+ server.public_ip = \
+ self.stack.outputs[server.floating_ip["stack_name"]]
+