summaryrefslogtreecommitdiff
path: root/openstack_dashboard/dashboards/project/stacks/mappings.py
diff options
context:
space:
mode:
Diffstat (limited to 'openstack_dashboard/dashboards/project/stacks/mappings.py')
-rw-r--r--openstack_dashboard/dashboards/project/stacks/mappings.py350
1 files changed, 0 insertions, 350 deletions
diff --git a/openstack_dashboard/dashboards/project/stacks/mappings.py b/openstack_dashboard/dashboards/project/stacks/mappings.py
deleted file mode 100644
index eeab18c..0000000
--- a/openstack_dashboard/dashboards/project/stacks/mappings.py
+++ /dev/null
@@ -1,350 +0,0 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13import json
14import logging
15
16from django.conf import settings
17from django.core.urlresolvers import reverse
18from django.template.defaultfilters import register
19from django.utils import html
20from django.utils import safestring
21import six
22import six.moves.urllib.parse as urlparse
23
24from openstack_dashboard.api import swift
25
26LOG = logging.getLogger(__name__)
27
28
29resource_urls = {
30 "AWS::AutoScaling::AutoScalingGroup": {
31 'link': 'horizon:project:stacks:detail'},
32 "AWS::CloudFormation::Stack": {
33 'link': 'horizon:project:stacks:detail'},
34 "AWS::EC2::Instance": {
35 'link': 'horizon:project:instances:detail'},
36 "AWS::EC2::InternetGateway": {
37 'link': 'horizon:project:networks:ports:detail'},
38 "AWS::EC2::NetworkInterface": {
39 'link': 'horizon:project:networks:ports:detail'},
40 "AWS::EC2::RouteTable": {
41 'link': 'horizon:project:routers:detail'},
42 "AWS::EC2::SecurityGroup": {
43 'link': 'horizon:project:security_groups:index'},
44 "AWS::EC2::Subnet": {
45 'link': 'horizon:project:networks:subnets:detail'},
46 "AWS::EC2::Volume": {
47 'link': 'horizon:project:volumes:detail'},
48 "AWS::EC2::VPC": {
49 'link': 'horizon:project:networks:detail'},
50 "AWS::S3::Bucket": {
51 'link': 'horizon:project:containers:index'},
52 "OS::Cinder::Volume": {
53 'link': 'horizon:project:volumes:detail'},
54 "OS::Heat::AccessPolicy": {
55 'link': 'horizon:project:stacks:detail'},
56 "OS::Heat::AutoScalingGroup": {
57 'link': 'horizon:project:stacks:detail'},
58 "OS::Heat::CloudConfig": {
59 'link': 'horizon:project:stacks:detail'},
60 "OS::Neutron::Firewall": {
61 'link': 'horizon:project:firewalls:firewalldetails'},
62 "OS::Neutron::FirewallPolicy": {
63 'link': 'horizon:project:firewalls:policydetails'},
64 "OS::Neutron::FirewallRule": {
65 'link': 'horizon:project:firewalls:ruledetails'},
66 "OS::Heat::HARestarter": {
67 'link': 'horizon:project:stacks:detail'},
68 "OS::Heat::InstanceGroup": {
69 'link': 'horizon:project:stacks:detail'},
70 "OS::Heat::MultipartMime": {
71 'link': 'horizon:project:stacks:detail'},
72 "OS::Heat::ResourceGroup": {
73 'link': 'horizon:project:stacks:detail'},
74 "OS::Heat::SoftwareConfig": {
75 'link': 'horizon:project:stacks:detail'},
76 "OS::Heat::StructuredConfig": {
77 'link': 'horizon:project:stacks:detail'},
78 "OS::Heat::StructuredDeployment": {
79 'link': 'horizon:project:stacks:detail'},
80 "OS::Heat::Stack": {
81 'link': 'horizon:project:stacks:detail'},
82 "OS::Heat::WaitCondition": {
83 'link': 'horizon:project:stacks:detail'},
84 "OS::Heat::WaitConditionHandle": {
85 'link': 'horizon:project:stacks:detail'},
86 "OS::Neutron::IKEPolicy": {
87 'link': 'horizon:project:vpn:ikepolicydetails'},
88 "OS::Neutron::IPsecPolicy": {
89 'link': 'horizon:project:vpn:ipsecpolicydetails'},
90 "OS::Neutron::IPsecSiteConnection": {
91 'link': 'horizon:project:vpn:ipsecsiteconnectiondetails'},
92 "OS::Neutron::Net": {
93 'link': 'horizon:project:networks:detail'},
94 "OS::Neutron::Port": {
95 'link': 'horizon:project:networks:ports:detail'},
96 "OS::Neutron::Router": {
97 'link': 'horizon:project:routers:detail'},
98 "OS::Neutron::Subnet": {
99 'link': 'horizon:project:networks:subnets:detail'},
100 "OS::Neutron::VPNService": {
101 'link': 'horizon:project:vpn:vpnservicedetails'},
102 "OS::Nova::KeyPair": {
103 'link': 'horizon:project:key_pairs:index'},
104 "OS::Nova::Server": {
105 'link': 'horizon:project:instances:detail'},
106 "OS::Swift::Container": {
107 'link': 'horizon:project:containers:index',
108 'format_pattern': '%s' + swift.FOLDER_DELIMITER},
109}
110
111
112def resource_to_url(resource):
113 if (not resource or
114 not resource.physical_resource_id or
115 not hasattr(resource, 'resource_type')):
116 return None
117
118 mapping = resource_urls.get(resource.resource_type, {})
119 try:
120 if 'link' not in mapping:
121 return None
122 format_pattern = mapping.get('format_pattern') or '%s'
123 rid = format_pattern % resource.physical_resource_id
124 url = reverse(mapping['link'], args=(rid,))
125 except Exception as e:
126 LOG.exception(e)
127 return None
128 return url
129
130
131@register.filter
132def stack_output(output):
133 if not output:
134 return u''
135 if isinstance(output, six.string_types):
136 parts = urlparse.urlsplit(output)
137 if parts.netloc and parts.scheme in ('http', 'https'):
138 url = html.escape(output)
139 safe_link = u'<a href="%s" target="_blank">%s</a>' % (url, url)
140 return safestring.mark_safe(safe_link)
141 if isinstance(output, dict) or isinstance(output, list):
142 output = json.dumps(output, indent=2)
143 return safestring.mark_safe(u'<pre>%s</pre>' % html.escape(output))
144
145static_url = getattr(settings, "STATIC_URL", "/static/")
146resource_images = {
147 'LB_FAILED': static_url + 'dashboard/img/lb-red.svg',
148 'LB_DELETE': static_url + 'dashboard/img/lb-red.svg',
149 'LB_IN_PROGRESS': static_url + 'dashboard/img/lb-gray.gif',
150 'LB_INIT': static_url + 'dashboard/img/lb-gray.svg',
151 'LB_COMPLETE': static_url + 'dashboard/img/lb-green.svg',
152 'DB_FAILED': static_url + 'dashboard/img/db-red.svg',
153 'DB_DELETE': static_url + 'dashboard/img/db-red.svg',
154 'DB_IN_PROGRESS': static_url + 'dashboard/img/db-gray.gif',
155 'DB_INIT': static_url + 'dashboard/img/db-gray.svg',
156 'DB_COMPLETE': static_url + 'dashboard/img/db-green.svg',
157 'STACK_FAILED': static_url + 'dashboard/img/stack-red.svg',
158 'STACK_DELETE': static_url + 'dashboard/img/stack-red.svg',
159 'STACK_IN_PROGRESS': static_url + 'dashboard/img/stack-gray.gif',
160 'STACK_INIT': static_url + 'dashboard/img/stack-gray.svg',
161 'STACK_COMPLETE': static_url + 'dashboard/img/stack-green.svg',
162 'SERVER_FAILED': static_url + 'dashboard/img/server-red.svg',
163 'SERVER_DELETE': static_url + 'dashboard/img/server-red.svg',
164 'SERVER_IN_PROGRESS': static_url + 'dashboard/img/server-gray.gif',
165 'SERVER_INIT': static_url + 'dashboard/img/server-gray.svg',
166 'SERVER_COMPLETE': static_url + 'dashboard/img/server-green.svg',
167 'ALARM_FAILED': static_url + 'dashboard/img/alarm-red.svg',
168 'ALARM_DELETE': static_url + 'dashboard/img/alarm-red.svg',
169 'ALARM_IN_PROGRESS': static_url + 'dashboard/img/alarm-gray.gif',
170 'ALARM_INIT': static_url + 'dashboard/img/alarm-gray.svg',
171 'ALARM_COMPLETE': static_url + 'dashboard/img/alarm-green.svg',
172 'VOLUME_FAILED': static_url + 'dashboard/img/volume-red.svg',
173 'VOLUME_DELETE': static_url + 'dashboard/img/volume-red.svg',
174 'VOLUME_IN_PROGRESS': static_url + 'dashboard/img/volume-gray.gif',
175 'VOLUME_INIT': static_url + 'dashboard/img/volume-gray.svg',
176 'VOLUME_COMPLETE': static_url + 'dashboard/img/volume-green.svg',
177 'IMAGE_FAILED': static_url + 'dashboard/img/image-red.svg',
178 'IMAGE_DELETE': static_url + 'dashboard/img/image-red.svg',
179 'IMAGE_IN_PROGRESS': static_url + 'dashboard/img/image-gray.gif',
180 'IMAGE_INIT': static_url + 'dashboard/img/image-gray.svg',
181 'IMAGE_COMPLETE': static_url + 'dashboard/img/image-green.svg',
182 'WAIT_FAILED': static_url + 'dashboard/img/wait-red.svg',
183 'WAIT_DELETE': static_url + 'dashboard/img/wait-red.svg',
184 'WAIT_IN_PROGRESS': static_url + 'dashboard/img/wait-gray.gif',
185 'WAIT_INIT': static_url + 'dashboard/img/wait-gray.svg',
186 'WAIT_COMPLETE': static_url + 'dashboard/img/wait-green.svg',
187 'FIREWALL_FAILED': static_url + 'dashboard/img/firewall-red.svg',
188 'FIREWALL_DELETE': static_url + 'dashboard/img/firewall-red.svg',
189 'FIREWALL_IN_PROGRESS': static_url + 'dashboard/img/firewall-gray.gif',
190 'FIREWALL_INIT': static_url + 'dashboard/img/firewall-gray.svg',
191 'FIREWALL_COMPLETE': static_url + 'dashboard/img/firewall-green.svg',
192 'FLOATINGIP_FAILED': static_url + 'dashboard/img/floatingip-red.svg',
193 'FLOATINGIP_DELETE': static_url + 'dashboard/img/floatingip-red.svg',
194 'FLOATINGIP_IN_PROGRESS': static_url + 'dashboard/img/floatingip-gray.gif',
195 'FLOATINGIP_INIT': static_url + 'dashboard/img/floatingip-gray.svg',
196 'FLOATINGIP_COMPLETE': static_url + 'dashboard/img/floatingip-green.svg',
197 'ROUTER_FAILED': static_url + 'dashboard/img/router-red.svg',
198 'ROUTER_DELETE': static_url + 'dashboard/img/router-red.svg',
199 'ROUTER_IN_PROGRESS': static_url + 'dashboard/img/router-gray.gif',
200 'ROUTER_INIT': static_url + 'dashboard/img/router-gray.svg',
201 'ROUTER_COMPLETE': static_url + 'dashboard/img/router-green.svg',
202 'POLICY_FAILED': static_url + 'dashboard/img/policy-red.svg',
203 'POLICY_DELETE': static_url + 'dashboard/img/policy-red.svg',
204 'POLICY_IN_PROGRESS': static_url + 'dashboard/img/policy-gray.gif',
205 'POLICY_INIT': static_url + 'dashboard/img/policy-gray.svg',
206 'POLICY_COMPLETE': static_url + 'dashboard/img/policy-green.svg',
207 'CONFIG_FAILED': static_url + 'dashboard/img/config-red.svg',
208 'CONFIG_DELETE': static_url + 'dashboard/img/config-red.svg',
209 'CONFIG_IN_PROGRESS': static_url + 'dashboard/img/config-gray.gif',
210 'CONFIG_INIT': static_url + 'dashboard/img/config-gray.svg',
211 'CONFIG_COMPLETE': static_url + 'dashboard/img/config-green.svg',
212 'NETWORK_FAILED': static_url + 'dashboard/img/network-red.svg',
213 'NETWORK_DELETE': static_url + 'dashboard/img/network-red.svg',
214 'NETWORK_IN_PROGRESS': static_url + 'dashboard/img/network-gray.gif',
215 'NETWORK_INIT': static_url + 'dashboard/img/network-gray.svg',
216 'NETWORK_COMPLETE': static_url + 'dashboard/img/network-green.svg',
217 'PORT_FAILED': static_url + 'dashboard/img/port-red.svg',
218 'PORT_DELETE': static_url + 'dashboard/img/port-red.svg',
219 'PORT_IN_PROGRESS': static_url + 'dashboard/img/port-gray.gif',
220 'PORT_INIT': static_url + 'dashboard/img/port-gray.svg',
221 'PORT_COMPLETE': static_url + 'dashboard/img/port-green.svg',
222 'SECURITYGROUP_FAILED': static_url + 'dashboard/img/securitygroup-red.svg',
223 'SECURITYGROUP_DELETE': static_url + 'dashboard/img/securitygroup-red.svg',
224 'SECURITYGROUP_IN_PROGRESS':
225 static_url + 'dashboard/img/securitygroup-gray.gif',
226 'SECURITYGROUP_INIT': static_url + 'dashboard/img/securitygroup-gray.svg',
227 'SECURITYGROUP_COMPLETE':
228 static_url + 'dashboard/img/securitygroup-green.svg',
229 'VPN_FAILED': static_url + 'dashboard/img/vpn-red.svg',
230 'VPN_DELETE': static_url + 'dashboard/img/vpn-red.svg',
231 'VPN_IN_PROGRESS': static_url + 'dashboard/img/vpn-gray.gif',
232 'VPN_INIT': static_url + 'dashboard/img/vpn-gray.svg',
233 'VPN_COMPLETE': static_url + 'dashboard/img/vpn-green.svg',
234 'FLAVOR_FAILED': static_url + 'dashboard/img/flavor-red.svg',
235 'FLAVOR_DELETE': static_url + 'dashboard/img/flavor-red.svg',
236 'FLAVOR_IN_PROGRESS': static_url + 'dashboard/img/flavor-gray.gif',
237 'FLAVOR_INIT': static_url + 'dashboard/img/flavor-gray.svg',
238 'FLAVOR_COMPLETE': static_url + 'dashboard/img/flavor-green.svg',
239 'KEYPAIR_FAILED': static_url + 'dashboard/img/keypair-red.svg',
240 'KEYPAIR_DELETE': static_url + 'dashboard/img/keypair-red.svg',
241 'KEYPAIR_IN_PROGRESS': static_url + 'dashboard/img/keypair-gray.gif',
242 'KEYPAIR_INIT': static_url + 'dashboard/img/keypair-gray.svg',
243 'KEYPAIR_COMPLETE': static_url + 'dashboard/img/keypair-green.svg',
244 'UNKNOWN_FAILED': static_url + 'dashboard/img/unknown-red.svg',
245 'UNKNOWN_DELETE': static_url + 'dashboard/img/unknown-red.svg',
246 'UNKNOWN_IN_PROGRESS': static_url + 'dashboard/img/unknown-gray.gif',
247 'UNKNOWN_INIT': static_url + 'dashboard/img/unknown-gray.svg',
248 'UNKNOWN_COMPLETE': static_url + 'dashboard/img/unknown-green.svg',
249}
250
251
252resource_types = {
253 # LB
254 'LoadBalance': 'LB',
255 'HealthMonitor': 'LB',
256 'PoolMember': 'LB',
257 'Pool': 'LB',
258 # DB
259 'DBInstance': 'DB',
260 'Database': 'DB',
261 # SERVER
262 'Instance': 'SERVER',
263 'Server': 'SERVER',
264 # ALARM
265 'Alarm': 'ALARM',
266 'CombinationAlarm': 'ALARM',
267 'CWLiteAlarm': 'ALARM',
268 # VOLUME
269 'Volume': 'VOLUME',
270 'VolumeAttachment': 'VOLUME',
271 # STACK
272 'stack': 'STACK',
273 'AutoScalingGroup': 'STACK',
274 'InstanceGroup': 'STACK',
275 'ServerGroup': 'STACK',
276 'ResourceGroup': 'STACK',
277 # IMAGE
278 'Image': 'IMAGE',
279 # WAIT
280 'WaitCondition': 'WAIT',
281 'WaitConditionHandle': 'WAIT',
282 'UpdateWaitConditionHandle': 'WAIT',
283 # FIREWALL
284 'Firewall': 'FIREWALL',
285 'FirewallPolicy': 'FIREWALL',
286 'FirewallRule': 'FIREWALL',
287 # FLOATINGIP
288 'FloatingIP': 'FLOATINGIP',
289 'FloatingIPAssociation': 'FLOATINGIP',
290 # ROUTER
291 'Router': 'ROUTER',
292 'RouterGateway': 'ROUTER',
293 'RouterInterface': 'ROUTER',
294 # POLICY
295 'ScalingPolicy': 'POLICY',
296 # CONFIG
297 'CloudConfig': 'CONFIG',
298 'MultipartMime': 'CONFIG',
299 'SoftwareConfig': 'CONFIG',
300 'SoftwareDeployment': 'CONFIG',
301 'StructuredConfig': 'CONFIG',
302 'StructuredDeployment': 'CONFIG',
303 # NETWORK
304 'Net': 'NETWORK',
305 'Subnet': 'NETWORK',
306 'NetworkGateway': 'NETWORK',
307 'ProviderNet': 'NETWORK',
308 # PORT
309 'Port': 'PORT',
310 # SECURITYGROUP
311 'SecurityGroup': 'SECURITYGROUP',
312 # VPN
313 'VPNService': 'VPN',
314 # FLAVOR
315 'Flavor': 'FLAVOR',
316 # KEYPAIR
317 'KeyPair': 'KEYPAIR',
318}
319
320
321def get_resource_type(type):
322 for key, value in resource_types.items():
323 if key in type:
324 return value
325
326 return 'UNKNOWN'
327
328
329def get_resource_status(status):
330 if ('IN_PROGRESS' in status):
331 return 'IN_PROGRESS'
332 elif ('FAILED' in status):
333 return 'FAILED'
334 elif ('DELETE' in status):
335 return 'DELETE'
336 elif ('INIT' in status):
337 return 'INIT'
338 else:
339 return 'COMPLETE'
340
341
342def get_resource_image(status, type):
343 """Sets the image url and in_progress action sw based on status."""
344 resource_type = get_resource_type(type)
345 resource_status = get_resource_status(status)
346 resource_state = resource_type + "_" + resource_status
347
348 for key in resource_images:
349 if key == resource_state:
350 return resource_images.get(key)