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';
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
);
256 if (!connection
) return;
259 channelId
: connection
261 ws
.onmessage
= (socket
) => {
263 var data
= JSON
.parse(socket
.data
);
265 label
: 'Select an SDN Account',
268 SdnOptions
= SdnOptions
.concat(this.generateOptionsByName(data
.sdn
.data
))
270 cloud
: data
.cloud
.data
,
271 'config-agent': data
['config-agent'].data
,
273 sdnOptions
: SdnOptions
276 //If account is selected, updated connection status only
277 if(self
.currentAccount
) {
278 let Account
= self
.getAccountFromStream(data
[self
.currentAccount
.type
].data
, self
.currentAccount
.name
);
279 newState
.account
= self
.account
;
280 newState
.account
['connection-status'] = Account
['connection-status']
282 self
.setState(newState
)
284 console
.log('Hit at exception in openAccountSocketSuccess', error
)
292 closeSocket
= () => {
294 window
.multiplexer
.channel(this.channelId
).close();
300 setAccountTemplate
= (AccountType
, type
) => {
303 'account-type': type
|| AccountMeta
[AccountType
].defaultType
,
304 params
: AccountMeta
[AccountType
].params
[AccountMeta
[AccountType
].defaultType
],
305 nestedParams
: AccountMeta
[AccountType
].nestedParams
? AccountMeta
[AccountType
].nestedParams
[AccountMeta
[AccountType
].defaultType
]:null,
306 'connection-status': {
311 account
[type
|| AccountMeta
[AccountType
].defaultType
] = {}
314 accountType
: AccountType
,
315 types
: AccountMeta
[AccountType
].types
,
319 getAccountFromStream(data
, name
) {
321 data
.map(function(a
) {
328 viewAccount
= ({type
, name
}) => {
331 if(this && this[type
].length
) {
332 accounts
= this[type
];
333 data
= this.getAccountFromStream(accounts
, name
);
335 let accountParams
= {
336 params
: AccountMeta
[type
].params
[data
['account-type']]
339 let accountNestedParams
= {
340 nestedParams
: AccountMeta
[type
].nestedParams
?AccountMeta
[type
].nestedParams
[data
['account-type']]:null
344 currentAccount
: {type
, name
},
345 account
: Object
.assign(data
, accountParams
, accountNestedParams
),
351 generateOptionsByName(data
) {
353 if (data
.constructor.name
== "Array") {
354 data
.map(function(d
) {
363 updateAccount
= (account
) => {
364 this.setState({account
:account
})
366 handleNameChange
= (event
) => {
367 var account
= this.account
;
368 account
.name
= event
.target
.value
;
375 handleAccountTypeChange
= (node
, event
) => {
377 temp
.name
= this.account
.name
;
378 temp
['account-type'] = event
.target
.value
;
379 temp
.params
= AccountMeta
[this.accountType
].params
[event
.target
.value
];
380 temp
.nestedParams
= AccountMeta
[this.accountType
]?AccountMeta
[this.accountType
].nestedParams
[event
.target
.value
]:null;
381 temp
[event
.target
.value
] = {};
386 handleParamChange(node
, event
) {
387 return function(event
) {
388 var account
= this.state
.account
;
389 account
[account
['account-type']][node
.ref
] = event
.target
.value
;
390 account
.params
[node
.ref
] = event
.target
.value
;
391 this.updateAccount(account
);
394 handleNestedParamChange(containerName
, node
, event
) {
395 return function(event
) {
396 var account
= this.state
.account
;
397 account
[account
['account-type']][containerName
] = account
[account
['account-type']][containerName
] || {};
398 account
[account
['account-type']][containerName
][node
.ref
] = event
.target
.value
;
399 account
[containerName
] = account
[containerName
] || {};
400 account
[containerName
].params
= account
[containerName
].params
|| {};
401 account
[containerName
].params
[node
.ref
] = event
.target
.value
;
402 this.updateAccount(account
);
405 getImage
= (type
) => {
406 return AccountMeta
.image
[type
];
414 * {"name":"eng2","account-type":"openstack","openstack":{"key":"lmaultsb","secret":"mypasswd","auth_url":"http://engstack.eng.riftio.com:5000/v3/","tenant":"lmaultsb","mgmt-network":"private"}}