summaryrefslogtreecommitdiff
path: root/openstack_dashboard/dashboards/project/stacks/api.py
blob: 9f01e847773414886d432e378bcafd98db15cba7 (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
75
76
77
78
79
import json
import logging

from openstack_dashboard.api.heat import resources_list
from openstack_dashboard.api.heat import stack_get

from openstack_dashboard.dashboards.project.stacks.mappings \
    import get_resource_image
from openstack_dashboard.dashboards.project.stacks.mappings \
    import get_resource_status
from openstack_dashboard.dashboards.project.stacks.sro import resource_info
from openstack_dashboard.dashboards.project.stacks.sro import stack_info


LOG = logging.getLogger(__name__)


class Stack(object):
    pass


def d3_data(request, stack_id=''):
    try:
        stack = stack_get(request, stack_id)
    except:
        stack = Stack()
        stack.id = stack_id
        stack.stack_name = request.session.get('stack_name', '')
        stack.stack_status = 'DELETE_COMPLETE'
        stack.stack_status_reason = 'DELETE_COMPLETE'

    try:
        resources = resources_list(request, stack.stack_name)
    except:
        resources = []

    d3_data = {"nodes": [], "stack": {}}
    if stack:
        stack_image = get_resource_image(stack.stack_status, 'stack')
        stack_node = {
            'stack_id': stack.id,
            'name': stack.stack_name,
            'status': stack.stack_status,
            'image': stack_image,
            'image_size': 60,
            'image_x': -30,
            'image_y': -30,
            'text_x': 40,
            'text_y': ".35em",
            'in_progress': True if (get_resource_status(stack.stack_status) ==
                                   'IN_PROGRESS') else False,
            'info_box': stack_info(stack, stack_image)
        }
        d3_data['stack'] = stack_node

    if resources:
        for resource in resources:
            resource_image = get_resource_image(resource.resource_status,
                                            resource.resource_type)
            resource_status = get_resource_status(resource.resource_status)
            if resource_status in ('IN_PROGRESS', 'INIT'):
                in_progress = True
            else:
                in_progress = False
            resource_node = {
                'name': resource.logical_resource_id,
                'status': resource.resource_status,
                'image': resource_image,
                'required_by': resource.required_by,
                'image_size': 50,
                'image_x': -25,
                'image_y': -25,
                'text_x': 35,
                'text_y': ".35em",
                'in_progress': in_progress,
                'info_box': resource_info(resource)
            }
            d3_data['nodes'].append(resource_node)
    return json.dumps(d3_data)