-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathcloud.account_view.sql
More file actions
212 lines (210 loc) · 9.84 KB
/
cloud.account_view.sql
File metadata and controls
212 lines (210 loc) · 9.84 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you 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. See the License for the
-- specific language governing permissions and limitations
-- under the License.
-- VIEW `cloud`.`account_view`;
DROP VIEW IF EXISTS `cloud`.`account_view`;
CREATE VIEW `cloud`.`account_view` AS
select
`account`.`id` AS `id`,
`account`.`uuid` AS `uuid`,
`account`.`account_name` AS `account_name`,
`account`.`type` AS `type`,
`account`.`role_id` AS `role_id`,
`account`.`state` AS `state`,
`account`.`created` AS `created`,
`account`.`removed` AS `removed`,
`account`.`cleanup_needed` AS `cleanup_needed`,
`account`.`network_domain` AS `network_domain` ,
`account`.`default` AS `default`,
`account`.`api_key_access` AS `api_key_access`,
`domain`.`id` AS `domain_id`,
`domain`.`uuid` AS `domain_uuid`,
`domain`.`name` AS `domain_name`,
`domain`.`path` AS `domain_path`,
`data_center`.`id` AS `data_center_id`,
`data_center`.`uuid` AS `data_center_uuid`,
`data_center`.`name` AS `data_center_name`,
`account_netstats`.`bytesReceived` AS `bytesReceived`,
`account_netstats`.`bytesSent` AS `bytesSent`,
`vmlimit`.`max` AS `vmLimit`,
`vmcount`.`count` AS `vmTotal`,
`runningvm`.`vmcount` AS `runningVms`,
`stoppedvm`.`vmcount` AS `stoppedVms`,
`iplimit`.`max` AS `ipLimit`,
`ipcount`.`count` AS `ipTotal`,
`free_ip_view`.`free_ip` AS `ipFree`,
`volumelimit`.`max` AS `volumeLimit`,
`volumecount`.`count` AS `volumeTotal`,
`snapshotlimit`.`max` AS `snapshotLimit`,
`snapshotcount`.`count` AS `snapshotTotal`,
`templatelimit`.`max` AS `templateLimit`,
`templatecount`.`count` AS `templateTotal`,
`vpclimit`.`max` AS `vpcLimit`,
`vpccount`.`count` AS `vpcTotal`,
`projectlimit`.`max` AS `projectLimit`,
`projectcount`.`count` AS `projectTotal`,
`networklimit`.`max` AS `networkLimit`,
`networkcount`.`count` AS `networkTotal`,
`cpulimit`.`max` AS `cpuLimit`,
`cpucount`.`count` AS `cpuTotal`,
`memorylimit`.`max` AS `memoryLimit`,
`memorycount`.`count` AS `memoryTotal`,
`gpulimit`.`max` AS `gpuLimit`,
`gpucount`.`count` AS `gpuTotal`,
`primary_storage_limit`.`max` AS `primaryStorageLimit`,
`primary_storage_count`.`count` AS `primaryStorageTotal`,
`secondary_storage_limit`.`max` AS `secondaryStorageLimit`,
`secondary_storage_count`.`count` AS `secondaryStorageTotal`,
`backup_limit`.`max` AS `backupLimit`,
`backup_count`.`count` AS `backupTotal`,
`backup_storage_limit`.`max` AS `backupStorageLimit`,
`backup_storage_count`.`count` AS `backupStorageTotal`,
`bucket_limit`.`max` AS `bucketLimit`,
`bucket_count`.`count` AS `bucketTotal`,
`object_storage_limit`.`max` AS `objectStorageLimit`,
`object_storage_count`.`count` AS `objectStorageTotal`,
`async_job`.`id` AS `job_id`,
`async_job`.`uuid` AS `job_uuid`,
`async_job`.`job_status` AS `job_status`,
`async_job`.`account_id` AS `job_account_id`
from
`cloud`.`free_ip_view`,
`cloud`.`account`
inner join
`cloud`.`domain` ON account.domain_id = domain.id
left join
`cloud`.`data_center` ON account.default_zone_id = data_center.id
left join lateral (
select
coalesce(sum(`user_statistics`.`net_bytes_received` + `user_statistics`.`current_bytes_received`), 0) AS `bytesReceived`,
coalesce(sum(`user_statistics`.`net_bytes_sent` + `user_statistics`.`current_bytes_sent`), 0) AS `bytesSent`
from
`cloud`.`user_statistics`
where
`user_statistics`.`account_id` = `account`.`id`
) AS `account_netstats` ON TRUE
left join
`cloud`.`resource_limit` vmlimit ON account.id = vmlimit.account_id
and vmlimit.type = 'user_vm' and vmlimit.tag IS NULL
left join
`cloud`.`resource_count` vmcount ON account.id = vmcount.account_id
and vmcount.type = 'user_vm' and vmcount.tag IS NULL
left join
`cloud`.`account_vmstats_view` runningvm ON account.id = runningvm.account_id
and runningvm.state = 'Running'
left join
`cloud`.`account_vmstats_view` stoppedvm ON account.id = stoppedvm.account_id
and stoppedvm.state = 'Stopped'
left join
`cloud`.`resource_limit` iplimit ON account.id = iplimit.account_id
and iplimit.type = 'public_ip'
left join
`cloud`.`resource_count` ipcount ON account.id = ipcount.account_id
and ipcount.type = 'public_ip'
left join
`cloud`.`resource_limit` volumelimit ON account.id = volumelimit.account_id
and volumelimit.type = 'volume' and volumelimit.tag IS NULL
left join
`cloud`.`resource_count` volumecount ON account.id = volumecount.account_id
and volumecount.type = 'volume' and volumecount.tag IS NULL
left join
`cloud`.`resource_limit` snapshotlimit ON account.id = snapshotlimit.account_id
and snapshotlimit.type = 'snapshot'
left join
`cloud`.`resource_count` snapshotcount ON account.id = snapshotcount.account_id
and snapshotcount.type = 'snapshot'
left join
`cloud`.`resource_limit` templatelimit ON account.id = templatelimit.account_id
and templatelimit.type = 'template'
left join
`cloud`.`resource_count` templatecount ON account.id = templatecount.account_id
and templatecount.type = 'template'
left join
`cloud`.`resource_limit` vpclimit ON account.id = vpclimit.account_id
and vpclimit.type = 'vpc'
left join
`cloud`.`resource_count` vpccount ON account.id = vpccount.account_id
and vpccount.type = 'vpc'
left join
`cloud`.`resource_limit` projectlimit ON account.id = projectlimit.account_id
and projectlimit.type = 'project'
left join
`cloud`.`resource_count` projectcount ON account.id = projectcount.account_id
and projectcount.type = 'project'
left join
`cloud`.`resource_limit` networklimit ON account.id = networklimit.account_id
and networklimit.type = 'network'
left join
`cloud`.`resource_count` networkcount ON account.id = networkcount.account_id
and networkcount.type = 'network'
left join
`cloud`.`resource_limit` cpulimit ON account.id = cpulimit.account_id
and cpulimit.type = 'cpu' and cpulimit.tag IS NULL
left join
`cloud`.`resource_count` cpucount ON account.id = cpucount.account_id
and cpucount.type = 'cpu' and cpucount.tag IS NULL
left join
`cloud`.`resource_limit` memorylimit ON account.id = memorylimit.account_id
and memorylimit.type = 'memory' and memorylimit.tag IS NULL
left join
`cloud`.`resource_count` memorycount ON account.id = memorycount.account_id
and memorycount.type = 'memory' and memorycount.tag IS NULL
left join
`cloud`.`resource_limit` gpulimit ON account.id = gpulimit.account_id
and gpulimit.type = 'gpu' and gpulimit.tag IS NULL
left join
`cloud`.`resource_count` gpucount ON account.id = gpucount.account_id
and gpucount.type = 'gpu' and gpucount.tag IS NULL
left join
`cloud`.`resource_limit` primary_storage_limit ON account.id = primary_storage_limit.account_id
and primary_storage_limit.type = 'primary_storage' and primary_storage_limit.tag IS NULL
left join
`cloud`.`resource_count` primary_storage_count ON account.id = primary_storage_count.account_id
and primary_storage_count.type = 'primary_storage' and primary_storage_count.tag IS NULL
left join
`cloud`.`resource_limit` secondary_storage_limit ON account.id = secondary_storage_limit.account_id
and secondary_storage_limit.type = 'secondary_storage'
left join
`cloud`.`resource_count` secondary_storage_count ON account.id = secondary_storage_count.account_id
and secondary_storage_count.type = 'secondary_storage'
left join
`cloud`.`resource_limit` backup_limit ON account.id = backup_limit.account_id
and backup_limit.type = 'backup'
left join
`cloud`.`resource_count` backup_count ON account.id = backup_count.account_id
and backup_count.type = 'backup'
left join
`cloud`.`resource_limit` backup_storage_limit ON account.id = backup_storage_limit.account_id
and backup_storage_limit.type = 'backup_storage'
left join
`cloud`.`resource_count` backup_storage_count ON account.id = backup_storage_count.account_id
and backup_storage_count.type = 'backup_storage'
left join
`cloud`.`resource_limit` bucket_limit ON account.id = bucket_limit.account_id
and bucket_limit.type = 'bucket'
left join
`cloud`.`resource_count` bucket_count ON account.id = bucket_count.account_id
and bucket_count.type = 'bucket'
left join
`cloud`.`resource_limit` object_storage_limit ON account.id = object_storage_limit.account_id
and object_storage_limit.type = 'object_storage'
left join
`cloud`.`resource_count` object_storage_count ON account.id = object_storage_count.account_id
and object_storage_count.type = 'object_storage'
left join
`cloud`.`async_job` ON async_job.instance_id = account.id
and async_job.instance_type = 'Account'
and async_job.job_status = 0;