1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 from heatclient import client as heat_client
11 from keystoneclient.v2_0 import client as keystone_client
12 from heatclient.common import template_utils
14 import heat.common as common
18 def __init__(self, credentials):
19 self.user = credentials['user']
20 self.password = credentials['password']
21 self.controller_ip = credentials['controller_ip']
22 self.heat_url = credentials['heat_url']
23 self.auth_uri = credentials['auth_uri']
24 self.project_id = credentials['project']
28 keystone = keystone_client.Client(username=self.user,
29 password=self.password,
30 tenant_name=self.project_id,
31 auth_url=self.auth_uri)
32 auth_token = keystone.auth_token
33 self.heat_url = keystone.service_catalog.url_for(
34 service_type='orchestration')
35 self.heat = heat_client.Client('1', endpoint=self.heat_url,
38 def stacks_list(self, name=None):
39 for stack in self.heat.stacks.list():
40 if (name and stack.stack_name == name) or not name:
41 common.LOG.info("stack name " + stack.stack_name)
42 common.LOG.info("stack status " + stack.stack_status)
44 def stack_generate(self, template_file, stack_name, parameters):
47 tpl_files, template = template_utils.get_template_contents(template_file)
51 'files': dict(list(tpl_files.items()))
53 self.heat.stacks.create(stack_name=stack_name, files=fields['files'],
54 template=template, parameters=parameters)
55 self.stacks_list(stack_name)
57 def stack_is_deployed(self, stack_name):
59 if stack_name in self.heat.stacks.list():
63 def stack_check_status(self, stack_name):
64 for stack in self.heat.stacks.list():
65 if stack.stack_name == stack_name:
66 return stack.stack_status
69 def heat_validate_template(self, heat_template_file):
71 if not self.heat.stacks.validate(template=open(heat_template_file,
73 raise ValueError('The provided heat template "' +
75 '" is in the wrong format')
77 def stack_delete(self, stack_name):
80 for stack in self.heat.stacks.list():
81 if stack.stack_name == stack_name:
82 self.heat.stacks.delete(stack.id)