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",
119 label
: "User Domain",
123 label
: "Project Domain",
124 ref
: 'project-domain',
130 label
: 'Management Network',
133 label
: 'Floating IP Pool',
134 ref
: 'floating-ip-pool',
141 label
: "Tenant Name",
144 label
: 'Management Network',
154 "container-name": "image-management",
155 "label": "Image Management",
163 label
: 'Image Directory Path',
164 ref
: 'image-directory-path',
171 "account-type": "openstack"
174 "account-type": "cloudsim_proxy"
177 "account-type": "aws"
180 "account-type": "openvim"
186 "aws": require("../../images/aws.png"),
187 "openvim": require("../../images/openmano.png"),
188 "openstack": require("../../images/openstack.png"),
189 "cloudsim_proxy": require("../../images/riftio.png"),
190 "odl": require("../../images/OpenDaylight_logo.png"),
191 "juju": require("../../images/juju.svg")
196 "openvim": "Open VIM",
197 "openstack": "OpenStack",
198 "cloudsim_proxy": "Cloudsim"
202 export default class AccountStore
{
205 this['config-agent'] = [];
209 this.refreshingAll
= false;
210 this.sdnOptions
= [];
211 this.AccountMeta
= AccountMeta
;
213 this.bindActions(AccountActions(this.alt
));
214 this.registerAsync(AccountSource
);
215 this.exportPublicMethods({
216 closeSocket
:this.closeSocket
,
217 setAccountTemplate
: this.setAccountTemplate
,
218 handleParamChange
: this.handleParamChange
,
219 handleNameChange
: this.handleNameChange
,
220 handleAccountTypeChange
: this.handleAccountTypeChange
,
221 updateAccount
: this.updateAccount
,
222 viewAccount
: this.viewAccount
,
223 handleNestedParamChange
: this.handleNestedParamChange
,
224 getImage
: this.getImage
227 refreshAllAccountsSuccess
= () => {
232 refreshAllAccountsLoading
= () => {
237 refreshAllAccountsError
= () => {
240 refreshCloudAccountFail
= () => {
243 refreshCloudAccountSuccess
= () => {
246 getResourceOrchestratorSuccess
= (data
) => {
247 this.alt
.actions
.global
.hideScreenLoader
.defer();
248 if(data
['account-type'] == 'openmano') {
254 deleteAccountSuccess
= (response
) => {
256 currentAccount
: false,
260 openAccountSocketSuccess
= (connection
) => {
262 let ws
= window
.multiplexer
.channel(connection
);
263 if (!connection
) return;
266 channelId
: connection
268 ws
.onmessage
= (socket
) => {
270 var data
= JSON
.parse(socket
.data
);
271 Utils
.checkAuthentication(data
.statusCode
, function() {
275 label
: 'Select an SDN Account',
278 SdnOptions
= SdnOptions
.concat(this.generateOptionsByName(data
.sdn
.data
))
280 cloud
: data
.cloud
.data
,
281 'config-agent': data
['config-agent'].data
,
283 sdnOptions
: SdnOptions
286 //If account is selected, updated connection status only
287 if(self
.currentAccount
) {
288 let Account
= self
.getAccountFromStream(data
[self
.currentAccount
.type
].data
, self
.currentAccount
.name
);
289 newState
.account
= self
.account
;
290 newState
.account
['connection-status'] = Account
['connection-status']
292 self
.setState(newState
)
294 console
.log('Hit at exception in openAccountSocketSuccess', error
)
302 closeSocket
= () => {
304 window
.multiplexer
.channel(this.channelId
).close();
310 setAccountTemplate
= (AccountType
, type
) => {
313 'account-type': type
|| AccountMeta
[AccountType
].defaultType
,
314 params
: AccountMeta
[AccountType
].params
[AccountMeta
[AccountType
].defaultType
],
315 nestedParams
: AccountMeta
[AccountType
].nestedParams
? AccountMeta
[AccountType
].nestedParams
[AccountMeta
[AccountType
].defaultType
]:null,
316 'connection-status': {
321 account
[type
|| AccountMeta
[AccountType
].defaultType
] = {}
324 accountType
: AccountType
,
325 types
: AccountMeta
[AccountType
].types
,
329 getAccountFromStream(data
, name
) {
331 data
.map(function(a
) {
338 viewAccount
= ({type
, name
}) => {
341 if(this && this[type
].length
) {
342 accounts
= this[type
];
343 data
= this.getAccountFromStream(accounts
, name
);
345 let accountParams
= {
346 params
: AccountMeta
[type
].params
[data
['account-type']]
349 let accountNestedParams
= {
350 nestedParams
: AccountMeta
[type
].nestedParams
?AccountMeta
[type
].nestedParams
[data
['account-type']]:null
354 currentAccount
: {type
, name
},
355 account
: Object
.assign(data
, accountParams
, accountNestedParams
),
361 generateOptionsByName(data
) {
363 if (data
&& data
.constructor.name
== "Array") {
364 data
.map(function(d
) {
373 updateAccount
= (account
) => {
374 this.setState({account
:account
})
376 handleNameChange
= (event
) => {
377 var account
= this.account
;
378 account
.name
= event
.target
.value
;
385 handleAccountTypeChange
= (node
, event
) => {
387 temp
.name
= this.account
.name
;
388 temp
['account-type'] = event
.target
.value
;
389 temp
.params
= AccountMeta
[this.accountType
].params
[event
.target
.value
];
390 temp
.nestedParams
= AccountMeta
[this.accountType
]?AccountMeta
[this.accountType
].nestedParams
[event
.target
.value
]:null;
391 temp
[event
.target
.value
] = {};
396 handleParamChange(node
, event
) {
397 return function(event
) {
398 var account
= this.state
.account
;
399 account
[account
['account-type']][node
.ref
] = event
.target
.value
;
400 account
.params
[node
.ref
] = event
.target
.value
;
401 this.updateAccount(account
);
404 handleNestedParamChange(containerName
, node
, event
) {
405 return function(event
) {
406 var account
= this.state
.account
;
407 account
[account
['account-type']][containerName
] = account
[account
['account-type']][containerName
] || {};
408 account
[account
['account-type']][containerName
][node
.ref
] = event
.target
.value
;
409 account
[containerName
] = account
[containerName
] || {};
410 account
[containerName
].params
= account
[containerName
].params
|| {};
411 account
[containerName
].params
[node
.ref
] = event
.target
.value
;
412 this.updateAccount(account
);
415 getImage
= (type
) => {
416 return AccountMeta
.image
[type
];