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
19 def __init__(self, credentials):
20 self.user = credentials['user']
21 self.password = credentials['password']
22 self.controller_ip = credentials['controller_ip']
23 self.heat_url = credentials['heat_url']
24 self.auth_uri = credentials['auth_uri']
25 self.project_id = credentials['project']
29 keystone = keystone_client.Client(username=self.user,
30 password=self.password,
31 tenant_name=self.project_id,
32 auth_url=self.auth_uri)
33 auth_token = keystone.auth_token
34 self.heat_url = keystone.service_catalog.url_for(
35 service_type='orchestration')
36 self.heat = heat_client.Client('1', endpoint=self.heat_url,
39 def stacks_list(self, name=None):
40 for stack in self.heat.stacks.list():
41 if (name and stack.stack_name == name) or not name:
42 common.LOG.info("stack name " + stack.stack_name)
43 common.LOG.info("stack status " + stack.stack_status)
45 def stack_generate(self, template_file, stack_name, parameters):
48 tpl_files, template = template_utils.get_template_contents(
53 'files': dict(list(tpl_files.items()))
55 self.heat.stacks.create(stack_name=stack_name, files=fields['files'],
56 template=template, parameters=parameters)
57 self.stacks_list(stack_name)
59 def stack_is_deployed(self, stack_name):
61 if stack_name in self.heat.stacks.list():
65 def stack_check_status(self, stack_name):
66 for stack in self.heat.stacks.list():
67 if stack.stack_name == stack_name:
68 return stack.stack_status
71 def heat_validate_template(self, heat_template_file):
73 if not self.heat.stacks.validate(template=open(heat_template_file,
75 raise ValueError('The provided heat template "' +
77 '" is in the wrong format')
79 def stack_delete(self, stack_name):
82 for stack in self.heat.stacks.list():
83 if stack.stack_name == stack_name:
84 self.heat.stacks.delete(stack.id)