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',
143 label
: "Tenant Name",
146 label
: 'Management Network',
156 "container-name": "image-management",
157 "label": "Image Management",
165 label
: 'Image Directory Path',
166 ref
: 'image-directory-path',
173 "account-type": "openstack"
176 "account-type": "cloudsim_proxy"
179 "account-type": "openmano"
182 "account-type": "aws"
185 "account-type": "openvim"
191 "aws": require("../../images/aws.png"),
192 "openmano": altImage
|| require("../../images/openmano.png"),
193 "openvim": require("../../images/openmano.png"),
194 "openstack": require("../../images/openstack.png"),
195 "cloudsim_proxy": require("../../images/riftio.png"),
196 "odl": require("../../images/OpenDaylight_logo.png"),
197 "juju": require("../../images/juju.svg")
202 "openmano": "OpenStack",
203 "openvim": "Open VIM",
204 "openstack": "OpenStack",
205 "cloudsim_proxy": "Cloudsim"
209 export default class AccountStore
{
212 this['config-agent'] = [];
216 this.refreshingAll
= false;
217 this.sdnOptions
= [];
218 this.AccountMeta
= AccountMeta
;
219 this.bindActions(AccountActions(this.alt
));
220 this.registerAsync(AccountSource
);
221 this.exportPublicMethods({
222 closeSocket
:this.closeSocket
,
223 setAccountTemplate
: this.setAccountTemplate
,
224 handleParamChange
: this.handleParamChange
,
225 handleNameChange
: this.handleNameChange
,
226 handleAccountTypeChange
: this.handleAccountTypeChange
,
227 updateAccount
: this.updateAccount
,
228 viewAccount
: this.viewAccount
,
229 handleNestedParamChange
: this.handleNestedParamChange
,
230 getImage
: this.getImage
233 refreshAllAccountsSuccess
= () => {
238 refreshAllAccountsLoading
= () => {
243 refreshAllAccountsError
= () => {
246 refreshCloudAccountFail
= () => {
249 refreshCloudAccountSuccess
= () => {
252 deleteAccountSuccess
= (response
) => {
254 currentAccount
: false,
258 openAccountSocketSuccess
= (connection
) => {
260 let ws
= window
.multiplexer
.channel(connection
);
262 if (!connection
) return;
265 channelId
: connection
267 ws
.onmessage
= (socket
) => {
269 var data
= JSON
.parse(socket
.data
);
271 label
: 'Select an SDN Account',
274 SdnOptions
= SdnOptions
.concat(this.generateOptionsByName(data
.sdn
.data
))
276 cloud
: data
.cloud
.data
,
277 'config-agent': data
['config-agent'].data
,
279 sdnOptions
: SdnOptions
282 //If account is selected, updated connection status only
283 if(self
.currentAccount
) {
284 let Account
= self
.getAccountFromStream(data
[self
.currentAccount
.type
].data
, self
.currentAccount
.name
);
285 newState
.account
= self
.account
;
286 newState
.account
['connection-status'] = Account
['connection-status']
288 self
.setState(newState
)
290 console
.log('Hit at exception in openAccountSocketSuccess', error
)
298 closeSocket
= () => {
300 window
.multiplexer
.channel(this.channelId
).close();
306 setAccountTemplate
= (AccountType
, type
) => {
309 'account-type': type
|| AccountMeta
[AccountType
].defaultType
,
310 params
: AccountMeta
[AccountType
].params
[AccountMeta
[AccountType
].defaultType
],
311 nestedParams
: AccountMeta
[AccountType
].nestedParams
? AccountMeta
[AccountType
].nestedParams
[AccountMeta
[AccountType
].defaultType
]:null,
312 'connection-status': {
317 account
[type
|| AccountMeta
[AccountType
].defaultType
] = {}
320 accountType
: AccountType
,
321 types
: AccountMeta
[AccountType
].types
,
325 getAccountFromStream(data
, name
) {
327 data
.map(function(a
) {
334 viewAccount
= ({type
, name
}) => {
337 if(this && this[type
].length
) {
338 accounts
= this[type
];
339 data
= this.getAccountFromStream(accounts
, name
);
341 let accountParams
= {
342 params
: AccountMeta
[type
].params
[data
['account-type']]
345 let accountNestedParams
= {
346 nestedParams
: AccountMeta
[type
].nestedParams
?AccountMeta
[type
].nestedParams
[data
['account-type']]:null
350 currentAccount
: {type
, name
},
351 account
: Object
.assign(data
, accountParams
, accountNestedParams
),
357 generateOptionsByName(data
) {
359 if (data
.constructor.name
== "Array") {
360 data
.map(function(d
) {
369 updateAccount
= (account
) => {
370 this.setState({account
:account
})
372 handleNameChange
= (event
) => {
373 var account
= this.account
;
374 account
.name
= event
.target
.value
;
381 handleAccountTypeChange
= (node
, event
) => {
383 temp
.name
= this.account
.name
;
384 temp
['account-type'] = event
.target
.value
;
385 temp
.params
= AccountMeta
[this.accountType
].params
[event
.target
.value
];
386 temp
.nestedParams
= AccountMeta
[this.accountType
]?AccountMeta
[this.accountType
].nestedParams
[event
.target
.value
]:null;
387 temp
[event
.target
.value
] = {};
392 handleParamChange(node
, event
) {
393 return function(event
) {
394 var account
= this.state
.account
;
395 account
[account
['account-type']][node
.ref
] = event
.target
.value
;
396 account
.params
[node
.ref
] = event
.target
.value
;
397 this.updateAccount(account
);
400 handleNestedParamChange(containerName
, node
, event
) {
401 return function(event
) {
402 var account
= this.state
.account
;
403 account
[account
['account-type']][containerName
] = account
[account
['account-type']][containerName
] || {};
404 account
[account
['account-type']][containerName
][node
.ref
] = event
.target
.value
;
405 account
[containerName
] = account
[containerName
] || {};
406 account
[containerName
].params
= account
[containerName
].params
|| {};
407 account
[containerName
].params
[node
.ref
] = event
.target
.value
;
408 this.updateAccount(account
);
411 getImage
= (type
) => {
412 return AccountMeta
.image
[type
];
420 * {"name":"eng2","account-type":"openstack","openstack":{"key":"lmaultsb","secret":"mypasswd","auth_url":"http://engstack.eng.riftio.com:5000/v3/","tenant":"lmaultsb","mgmt-network":"private"}}