summaryrefslogtreecommitdiffstats
path: root/vio/vio/pub/vim/drivers/vimsdk/heat.py
blob: 0dad830e1746141ba7ded3382c0977ca24a25e2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Copyright (c) 2018 VMware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

import logging

from vio.pub.vim.drivers import base
from vio.pub.vim.drivers.vimsdk import sdk

LOG = logging.getLogger(__name__)


class HeatClient(base.DriverBase):
    '''Heat driver.'''

    def __init__(self, params):
        super(HeatClient, self).__init__(params)
        self.conn = sdk.create_connection(params)
        self.session = self.conn.session

    @sdk.translate_exception
    def stack_create(self, **params):
        return self.conn.orchestration.create_stack(**params)

    @sdk.translate_exception
    def stack_get(self, stack_id):
        return self.conn.orchestration.get_stack(stack_id)

    @sdk.translate_exception
    def stack_find(self, name_or_id):
        return self.conn.orchestration.find_stack(name_or_id)

    @sdk.translate_exception
    def stack_list(self):
        return self.conn.orchestration.stacks()

    @sdk.translate_exception
    def stack_delete(self, stack_id, ignore_missing=True):
        return self.conn.orchestration.delete_stack(stack_id,
                                                    ignore_missing)

    @sdk.translate_exception
    def wait_for_stack(self, stack_id, status, failures=None, interval=2,
                       timeout=None):
        if failures is None:
            failures = []

        if timeout is None:
            timeout = 600

        stack_obj = self.conn.orchestration.find_stack(stack_id, False)
        if stack_obj:
            self.conn.orchestration.wait_for_status(
                stack_obj, status, failures, interval, timeout)

    @sdk.translate_exception
    def wait_for_stack_delete(self, stack_id, timeout=None):
        """Wait for stack deleting complete"""
        if timeout is None:
            timeout = 600

        server_obj = self.conn.orchestration.find_stack(stack_id, True)
        if server_obj:
            self.conn.orchestration.wait_for_delete(server_obj, wait=timeout)

        return