forked from ManageIQ/manageiq-ui-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree_builder_utilization.rb
120 lines (106 loc) · 4.59 KB
/
tree_builder_utilization.rb
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
class TreeBuilderUtilization < TreeBuilderRegion
has_kids_for ExtManagementSystem, [:x_get_tree_ems_kids]
has_kids_for Datacenter, [:x_get_tree_datacenter_kids, :type]
has_kids_for EmsFolder, [:x_get_tree_folder_kids, :type]
has_kids_for EmsCluster, [:x_get_tree_cluster_kids]
def initialize(name, type, sandbox, build = true, **params)
@selected_node = params[:selected_node]
super(name, type, sandbox, build)
end
private
def override(node, _object, _pid, _options)
node[:selectable] = node[:key].split('-')[1].split('_')[0] != 'folder'
end
def set_locals_for_render
locals = super
locals.merge!(:select_node => @selected_node.to_s)
end
def root_options
if MiqEnterprise.my_enterprise.is_enterprise?
text = _("Enterprise")
icon = 'pficon pficon-enterprise'
else
text = _("%{product} Region: %{region_description} [%{region}]") % {:region_description => MiqRegion.my_region.description,
:region => MiqRegion.my_region.region,
:product => Vmdb::Appliance.PRODUCT_NAME}
icon = 'pficon pficon-regions'
end
{
:text => text,
:tooltip => text,
:icon => icon
}
end
def x_get_tree_ems_kids(object, count_only)
ems_clusters = Rbac.filtered(object.ems_clusters)
non_clustered_hosts = Rbac.filtered(object.non_clustered_hosts)
total = ems_clusters.count + non_clustered_hosts.count
return total if count_only
return [] if total == 0
[
{
:id => "folder_c_xx-#{object.id}",
:text => _("Cluster / Deployment Role"),
:icon => "pficon pficon-folder-close",
:tip => _("Cluster / Deployment Role (Click to open)")
}
]
end
def x_get_tree_datacenter_kids(object, count_only, type)
objects =
case type
when :vandt then x_get_tree_vandt_datacenter_kids(object)
when :handc then x_get_tree_handc_datacenter_kids(object)
end
count_only_or_objects(count_only, objects)
end
def x_get_tree_vandt_datacenter_kids(object)
# Count clusters directly in this folder
objects = rbac_filtered_sorted_objects(object.clusters, "name", :match_via_descendants => VmOrTemplate)
object.folders.each do |f|
if f.name == "vm" # Count vm folder children
objects += rbac_filtered_sorted_objects(f.folders, "name", :match_via_descendants => VmOrTemplate)
objects += rbac_filtered_sorted_objects(f.vms_and_templates, "name")
elsif f.name == "host" # Don't count host folder children
else # add in other folders
f = Rbac.filtered_object(f, :match_via_descendants => VmOrTemplate)
objects << f if f
end
end
end
def x_get_tree_handc_datacenter_kids(object)
objects = rbac_filtered_sorted_objects(object.clusters, "name")
object.folders.each do |f|
if f.name == "vm" # Don't add vm folder children
elsif f.name == "host" # Add host folder children
objects += rbac_filtered_sorted_objects(f.folders, "name")
objects += rbac_filtered_sorted_objects(f.clusters, "name")
objects += rbac_filtered_sorted_objects(f.hosts, "name")
else # add in other folders
f = Rbac.filtered_object(f)
objects << f if f
end
end
end
def x_get_tree_folder_kids(object, count_only, type)
objects = []
case type
when :vandt, :handc, :storage_pod
objects = rbac_filtered_sorted_objects(object.folders_only, "name", :match_via_descendants => VmOrTemplate)
objects += rbac_filtered_sorted_objects(object.datacenters_only, "name", :match_via_descendants => VmOrTemplate)
objects += rbac_filtered_sorted_objects(object.clusters, "name", :match_via_descendants => VmOrTemplate)
objects += rbac_filtered_sorted_objects(object.hosts, "name", :match_via_descendants => VmOrTemplate)
objects += rbac_filtered_sorted_objects(object.vms_and_templates, "name")
end
count_only_or_objects(count_only, objects)
end
def x_get_tree_cluster_kids(object, count_only)
objects = rbac_filtered_sorted_objects(object.hosts, "name")
# FIXME: is the condition below ever false?
unless [:bottlenecks, :utilization].include?(@type)
objects += rbac_filtered_sorted_objects(object.resource_pools, "name")
objects += rbac_filtered_sorted_objects(object.vms, "name")
end
count_only_or_objects(count_only, objects)
end
end