3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 import AccountActions
from './accountActions.js';
19 import AccountSource
from './accountSource.js';
21 var Utils
= require('utils/utils.js');
22 var rw
= require('utils/rw.js');
23 var altImage
= rw
.getSearchParams(window
.location
).alt_image
;
58 "account-type": "juju",
77 "account-type": "odl",
81 defaultType
: 'openstack',
90 label
: "Availability Zone",
91 ref
: 'availability-zone'
93 label
: "Default Subnet ID",
94 ref
: 'default-subnet-id'
116 label
: "Authentication URL",
122 label
: 'Management Network',
125 label
: 'Floating IP Pool',
126 ref
: 'floating-ip-pool',
133 label
: "Tenant Name",
136 label
: 'Management Network',
146 "container-name": "image-management",
147 "label": "Image Management",
155 label
: 'Image Directory Path',
156 ref
: 'image-directory-path',
163 "account-type": "openstack"
166 "account-type": "cloudsim_proxy"
169 "account-type": "aws"
172 "account-type": "openvim"
178 "aws": require("../../images/aws.png"),
179 "openvim": require("../../images/openmano.png"),
180 "openstack": require("../../images/openstack.png"),
181 "cloudsim_proxy": require("../../images/riftio.png"),
182 "odl": require("../../images/OpenDaylight_logo.png"),
183 "juju": require("../../images/juju.svg")
188 "openvim": "Open VIM",
189 "openstack": "OpenStack",
190 "cloudsim_proxy": "Cloudsim"
194 export default class AccountStore
{
197 this['config-agent'] = [];
201 this.refreshingAll
= false;
202 this.sdnOptions
= [];
203 this.AccountMeta
= AccountMeta
;
205 this.bindActions(AccountActions(this.alt
));
206 this.registerAsync(AccountSource
);
207 this.exportPublicMethods({
208 closeSocket
:this.closeSocket
,
209 setAccountTemplate
: this.setAccountTemplate
,
210 handleParamChange
: this.handleParamChange
,
211 handleNameChange
: this.handleNameChange
,
212 handleAccountTypeChange
: this.handleAccountTypeChange
,
213 updateAccount
: this.updateAccount
,
214 viewAccount
: this.viewAccount
,
215 handleNestedParamChange
: this.handleNestedParamChange
,
216 getImage
: this.getImage
219 refreshAllAccountsSuccess
= () => {
224 refreshAllAccountsLoading
= () => {
229 refreshAllAccountsError
= () => {
232 refreshCloudAccountFail
= () => {
235 refreshCloudAccountSuccess
= () => {
238 getResourceOrchestratorSuccess
= (data
) => {
239 this.alt
.actions
.global
.hideScreenLoader
.defer();
240 if(data
['account-type'] == 'openmano') {
246 deleteAccountSuccess
= (response
) => {
248 currentAccount
: false,
252 openAccountSocketSuccess
= (connection
) => {
254 let ws
= window
.multiplexer
.channel(connection
);
255 if (!connection
) return;
258 channelId
: connection
260 ws
.onmessage
= (socket
) => {
262 var data
= JSON
.parse(socket
.data
);
263 Utils
.checkAuthentication(data
.statusCode
, function() {
267 label
: 'Select an SDN Account',
270 SdnOptions
= SdnOptions
.concat(this.generateOptionsByName(data
.sdn
.data
))
272 cloud
: data
.cloud
.data
,
273 'config-agent': data
['config-agent'].data
,
275 sdnOptions
: SdnOptions
278 //If account is selected, updated connection status only
279 if(self
.currentAccount
) {
280 let Account
= self
.getAccountFromStream(data
[self
.currentAccount
.type
].data
, self
.currentAccount
.name
);
281 newState
.account
= self
.account
;
282 newState
.account
['connection-status'] = Account
['connection-status']
284 self
.setState(newState
)
286 console
.log('Hit at exception in openAccountSocketSuccess', error
)
294 closeSocket
= () => {
296 window
.multiplexer
.channel(this.channelId
).close();
302 setAccountTemplate
= (AccountType
, type
) => {
305 'account-type': type
|| AccountMeta
[AccountType
].defaultType
,
306 params
: AccountMeta
[AccountType
].params
[AccountMeta
[AccountType
].defaultType
],
307 nestedParams
: AccountMeta
[AccountType
].nestedParams
? AccountMeta
[AccountType
].nestedParams
[AccountMeta
[AccountType
].defaultType
]:null,
308 'connection-status': {
313 account
[type
|| AccountMeta
[AccountType
].defaultType
] = {}
316 accountType
: AccountType
,
317 types
: AccountMeta
[AccountType
].types
,
321 getAccountFromStream(data
, name
) {
323 data
.map(function(a
) {
330 viewAccount
= ({type
, name
}) => {
333 if(this && this[type
].length
) {
334 accounts
= this[type
];
335 data
= this.getAccountFromStream(accounts
, name
);
337 let accountParams
= {
338 params
: AccountMeta
[type
].params
[data
['account-type']]
341 let accountNestedParams
= {
342 nestedParams
: AccountMeta
[type
].nestedParams
?AccountMeta
[type
].nestedParams
[data
['account-type']]:null
346 currentAccount
: {type
, name
},
347 account
: Object
.assign(data
, accountParams
, accountNestedParams
),
353 generateOptionsByName(data
) {
355 if (data
&& data
.constructor.name
== "Array") {
356 data
.map(function(d
) {
365 updateAccount
= (account
) => {
366 this.setState({account
:account
})
368 handleNameChange
= (event
) => {
369 var account
= this.account
;
370 account
.name
= event
.target
.value
;
377 handleAccountTypeChange
= (node
, event
) => {
379 temp
.name
= this.account
.name
;
380 temp
['account-type'] = event
.target
.value
;
381 temp
.params
= AccountMeta
[this.accountType
].params
[event
.target
.value
];
382 temp
.nestedParams
= AccountMeta
[this.accountType
]?AccountMeta
[this.accountType
].nestedParams
[event
.target
.value
]:null;
383 temp
[event
.target
.value
] = {};
388 handleParamChange(node
, event
) {
389 return function(event
) {
390 var account
= this.state
.account
;
391 account
[account
['account-type']][node
.ref
] = event
.target
.value
;
392 account
.params
[node
.ref
] = event
.target
.value
;
393 this.updateAccount(account
);
396 handleNestedParamChange(containerName
, node
, event
) {
397 return function(event
) {
398 var account
= this.state
.account
;
399 account
[account
['account-type']][containerName
] = account
[account
['account-type']][containerName
] || {};
400 account
[account
['account-type']][containerName
][node
.ref
] = event
.target
.value
;
401 account
[containerName
] = account
[containerName
] || {};
402 account
[containerName
].params
= account
[containerName
].params
|| {};
403 account
[containerName
].params
[node
.ref
] = event
.target
.value
;
404 this.updateAccount(account
);
407 getImage
= (type
) => {
408 return AccountMeta
.image
[type
];