Datacenter display fix on instnatiate
[osm/UI.git] / skyquake / plugins / launchpad / src / cloud-account.js
1
2 /*
3 *
4 * Copyright 2016 RIFT.IO Inc
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19 var CloudAccountCreateController = function($timeout, $state, $stateParams) {
20 var self = this;
21 var CloudAccountStore = require('../missioncontrol/cloud_account/cloudAccountStore')
22 var CloudAccountActions = require('../missioncontrol/cloud_account/cloudAccountActions')
23 self.CloudAccountStore = CloudAccountStore;
24 self.accountType = [
25 // {
26 // "name":"AWS",
27 // "account-type":"aws",
28 // },
29 {
30 "name":"OpenStack",
31 "account-type":"openstack",
32 },{
33 "name":"Cloudsim",
34 "account-type":"cloudsim"
35 },{
36 "name":"OpenMano",
37 "account-type":"openmano"
38 }
39 ];
40 self.params = {
41 "aws": [
42 {
43 label: "Key",
44 ref: 'key'
45 },
46 {
47 label: "Secret",
48 ref: 'secret'
49 },
50 {
51 label: "Availability Zone",
52 ref: 'availability-zone'
53 },
54 {
55 label: "Default Subnet ID",
56 ref: 'default-subnet-id'
57 },
58 {
59 label: "Region",
60 ref: 'region'
61 },
62 {
63 label: "VPC ID",
64 ref: 'vpcid'
65 },
66 {
67 label: "SSH Key",
68 ref: 'ssh-key'
69 }
70 ],
71 "openstack": [
72 {
73 label: "Key",
74 ref: 'key'
75 },
76 {
77 label: "Secret",
78 ref: 'secret'
79 },
80 {
81 label: "Authentication URL",
82 ref: 'auth_url'
83 },
84 {
85 label: "Tenant",
86 ref: 'tenant'
87 },
88 {
89 label: 'Management Network',
90 ref: 'mgmt-network'
91 }
92 ],
93 "openmano": [
94 {
95 label: "Host",
96 ref: 'host'
97 },
98 {
99 label: "Port",
100 ref: 'port'
101 },
102 {
103 label: "Tenant ID",
104 ref: 'tenant-id'
105 }
106 ]
107 }
108 self.cloud = {
109 name: '',
110 'account-type': 'openstack'
111 };
112 self.loadDashboard = function() {
113 $state.go('/launchpad', {management_domain: $stateParams.management_domain});
114 }
115 self.openAbout = function() {
116 $state.go('lp-about', {management_domain: $stateParams.management_domain});
117 }
118 self.openDebug = function() {
119 $state.go('lp-debug', {management_domain: $stateParams.management_domain});
120 }
121 self.create = function() {
122 if (self.cloud.name == "") {
123 CloudAccountActions.validateError("Please give the cloud account a name");
124 return;
125 } else {
126 var type = self.cloud['account-type'];
127 if (typeof(self.params[type]) != 'undefined') {
128 var params = self.params[type];
129 for (var i = 0; i < params.length; i++) {
130 var param = params[i].ref;
131 if (typeof(self.cloud[type]) == 'undefined' || typeof(self.cloud[type][param]) == 'undefined' || self.cloud[type][param] == "") {
132
133 CloudAccountActions.validateError("Please fill all account details");
134 return;
135 }
136 }
137 }
138 }
139 CloudAccountActions.validateReset();
140 CloudAccountStore.create(self.cloud).then(function() {
141 $state.go('/launchpad',{management_domain: $stateParams.management_domain});
142 });
143 }
144 self.cancel = function() {
145 $state.go('/launchpad',{management_domain: $stateParams.management_domain});
146 }
147 self.store = CloudAccountStore;
148 require('../utils/utils.js').isNotAuthenticated(window.location, function() {
149 $state.go('login');
150 });
151 };
152
153 var CloudAccountEditController = function($timeout, $state, $stateParams) {
154 var self = this;
155 var CloudAccountStore = require('../missioncontrol/cloud_account/cloudAccountStore');
156 self.CloudAccountStore = CloudAccountStore;
157 var cloud_account_name = $stateParams.cloud_account;
158
159 // Mark this is edit
160 self.edit = true;
161
162 self.accountType = [
163 // {
164 // "name":"AWS",
165 // "account-type":"aws",
166 // },
167 {
168 "name":"OpenStack",
169 "account-type":"openstack",
170 },{
171 "name":"Cloudsim",
172 "account-type":"cloudsim"
173 },{
174 "name":"OpenMano",
175 "account-type":"openmano"
176 }
177 ];
178 self.params = {
179 "aws": [
180 {
181 label: "Key",
182 ref: 'key'
183 },
184 {
185 label: "Secret",
186 ref: 'secret'
187 },
188 {
189 label: "Availability Zone",
190 ref: 'availability-zone'
191 },
192 {
193 label: "Default Subnet ID",
194 ref: 'default-subnet-id'
195 },
196 {
197 label: "Region",
198 ref: 'region'
199 },
200 {
201 label: "VPC ID",
202 ref: 'vpcid'
203 },
204 {
205 label: "SSH Key",
206 ref: 'ssh-key'
207 }
208 ],
209 "openstack": [
210 {
211 label: "Key",
212 ref: 'key'
213 },
214 {
215 label: "Secret",
216 ref: 'secret'
217 },
218 {
219 label: "Authentication URL",
220 ref: 'auth_url'
221 },
222 {
223 label: "Tenant",
224 ref: 'tenant'
225 },
226 {
227 label: 'Management Network',
228 ref: 'mgmt-network'
229 }
230 ],
231 "openmano": [
232 {
233 label: "Host",
234 ref: 'host'
235 },
236 {
237 label: "Port",
238 ref: 'port'
239 },
240 {
241 label: "Tenant ID",
242 ref: 'tenant'
243 },
244 {
245 label: "Data Center ID",
246 ref: 'datacenter'
247 }
248 ]
249 };
250 self.cloud = {
251 name: ''
252 };
253
254 // Setup listener
255 var listener = function(data) {
256 $timeout(function() {
257 console.log('updating', data);
258 self.cloud.name = data.cloudAccount.name;
259 var accountType = self.cloud['account-type'] = data.cloudAccount['account-type'];
260 if (data.cloudAccount[accountType]) {
261 // There are extra params.
262 // Initialize object
263 self.cloud[accountType] = {};
264 // Iterate over them and assign to proper keys
265 for (var k in data.cloudAccount[accountType]) {
266 self.cloud[accountType][k] = data.cloudAccount[accountType][k];
267 }
268 }
269 });
270 };
271
272 CloudAccountStore.listen(listener);
273 require('../utils/utils.js').isNotAuthenticated(window.location, function() {
274 CloudAccountStore.unlisten(listener);
275 $state.go('login')
276 });
277 // Get the cloud account
278 CloudAccountStore.getCloudAccount($stateParams.cloud_account);
279 self.store = CloudAccountStore;
280 self.update = function() {
281 if (self.cloud.name == "") {
282 console.log('pop')
283 return;
284 }
285 CloudAccountStore.update(self.cloud).then(function() {
286 CloudAccountStore.unlisten(listener);
287 $state.go('/launchpad',{management_domain: $stateParams.management_domain});
288 });
289 };
290 self.loadDashboard = function() {
291 $state.go('/launchpad', {management_domain: $stateParams.management_domain});
292 }
293 self.openAbout = function() {
294 $state.go('lp-about', {management_domain: $stateParams.management_domain});
295 }
296 self.openDebug = function() {
297 $state.go('lp-debug', {management_domain: $stateParams.management_domain});
298 }
299 self.delete = function() {
300 console.log('Deleting cloud account', cloud_account_name);
301 CloudAccountStore.delete(cloud_account_name).then(function() {
302 CloudAccountStore.unlisten(listener);
303 $state.go('/launchpad',{management_domain: $stateParams.management_domain});
304 });
305 };
306 self.cancel = function() {
307 CloudAccountStore.unlisten(listener);
308 $state.go('/launchpad',{management_domain: $stateParams.management_domain});
309 }
310 };
311
312 module.exports = {
313 CloudAccountCreateController: CloudAccountCreateController,
314 CloudAccountEditController: CloudAccountEditController
315 };