Skip to content

Commit a94cd0b

Browse files
author
Jessica Wang
committed
cloudStack 3.0 new UI - deployVM - select networks step - list all networks in the same container with checkbox and radio button. Provide another container to create new network with network offering dropdodwn.
1 parent c05b4db commit a94cd0b

1 file changed

Lines changed: 86 additions & 45 deletions

File tree

‎ui/scripts/instances.js‎

Lines changed: 86 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function($, cloudStack, testData) {
22

3-
var zoneObjs, hypervisorObjs, featuredTemplateObjs, communityTemplateObjs, myTemplateObjs, isoObjs, serviceOfferingObjs, diskOfferingObjs;
4-
var selectedZoneObj, selectedTemplateObj, selectedHypervisor, selectedDiskOfferingObj;
3+
var zoneObjs, hypervisorObjs, featuredTemplateObjs, communityTemplateObjs, myTemplateObjs, isoObjs, serviceOfferingObjs, diskOfferingObjs, networkOfferingObjs;
4+
var selectedZoneObj, selectedTemplateObj, selectedHypervisor, selectedDiskOfferingObj;
55
var step5ContainerType = 'nothing-to-select'; //'nothing-to-select', 'select-network', 'select-security-group'
66

77
cloudStack.sections.instances = {
@@ -130,25 +130,31 @@
130130
// Step 3: Service offering
131131
function(args) {
132132
if(args.currentData["select-template"] == "select-template") {
133-
for(var i=0; i < featuredTemplateObjs.length; i++) {
134-
if(featuredTemplateObjs[i].id == args.currentData.templateid) {
135-
selectedTemplateObj = featuredTemplateObjs[i];
136-
break;
133+
if(featuredTemplateObjs != null && featuredTemplateObjs.length > 0) {
134+
for(var i=0; i < featuredTemplateObjs.length; i++) {
135+
if(featuredTemplateObjs[i].id == args.currentData.templateid) {
136+
selectedTemplateObj = featuredTemplateObjs[i];
137+
break;
138+
}
137139
}
138140
}
139141
if(selectedTemplateObj == null) {
140-
for(var i=0; i < communityTemplateObjs.length; i++) {
141-
if(communityTemplateObjs[i].id == args.currentData.templateid) {
142-
selectedTemplateObj = communityTemplateObjs[i];
143-
break;
142+
if(communityTemplateObjs != null && communityTemplateObjs.length > 0) {
143+
for(var i=0; i < communityTemplateObjs.length; i++) {
144+
if(communityTemplateObjs[i].id == args.currentData.templateid) {
145+
selectedTemplateObj = communityTemplateObjs[i];
146+
break;
147+
}
144148
}
145149
}
146150
}
147151
if(selectedTemplateObj == null) {
148-
for(var i=0; i < myTemplateObjs.length; i++) {
149-
if(myTemplateObjs[i].id == args.currentData.templateid) {
150-
selectedTemplateObj = myTemplateObjs[i];
151-
break;
152+
if(myTemplateObjs != null && myTemplateObjs.length > 0) {
153+
for(var i=0; i < myTemplateObjs.length; i++) {
154+
if(myTemplateObjs[i].id == args.currentData.templateid) {
155+
selectedTemplateObj = myTemplateObjs[i];
156+
break;
157+
}
152158
}
153159
}
154160
}
@@ -228,7 +234,7 @@
228234
}
229235
});
230236

231-
if(includingSecurityGroupService == false || selectedHypervisor == "VMware" || g_directAttachSecurityGroupsEnabled != "true") { //???
237+
if(includingSecurityGroupService == false || selectedHypervisor == "VMware" || g_directAttachSecurityGroupsEnabled != "true") {
232238
step5ContainerType = 'nothing-to-select';
233239
}
234240
else {
@@ -257,6 +263,7 @@
257263
var networks = json.listnetworksresponse.network;
258264

259265
//***** check if there is an isolated network with sourceNAT (begin) *****
266+
/*
260267
var isolatedSourcenatNetwork = null;
261268
if(selectedZoneObj.securitygroupsenabled == false) {
262269
if (networks != null && networks.length > 0) {
@@ -302,31 +309,24 @@
302309
});
303310
}
304311
}
312+
*/
305313
//***** check if there is an isolated network with sourceNAT (end) *****
306314

307315

308316
//***** populate all networks (begin) **********************************
309317
//isolatedSourcenatNetwork is first radio button in default network section. Show isolatedSourcenatNetwork when its networkofferingavailability is 'Required' or'Optional'
318+
/*
310319
if (isolatedSourcenatNetwork.networkofferingavailability == 'Required' || isolatedSourcenatNetwork.networkofferingavailability == 'Optional') {
311320
defaultNetworkArray.push(isolatedSourcenatNetwork);
312321
}
322+
*/
313323

314324
//default networks are in default network section
315325
//non-default networks are in additional network section
316326
if (networks != null && networks.length > 0) {
317-
for (var i = 0; i < networks.length; i++) {
318-
//if selectedZoneObj.securitygroupsenabled is true and users still choose to select network instead of security group (from dialog), then UI won't show networks whose securitygroupenabled is true.
319-
//if(selectedZoneObj.securitygroupsenabled == true && networks[i].securitygroupenabled == true) {
320-
// continue;
321-
//}
322-
323-
if (networks[i].isdefault) {
324-
if (isolatedSourcenatNetwork.networkofferingavailability == 'Required') {
325-
continue; //don't display 2nd~Nth radio buttons in default network section when isolatedSourcenatNetwork.networkofferingavailability == 'Required'
326-
}
327-
if(networks[i].id != isolatedSourcenatNetwork.id) {
328-
defaultNetworkArray.push(networks[i]);
329-
}
327+
for (var i = 0; i < networks.length; i++) {
328+
if (networks[i].isdefault) {
329+
defaultNetworkArray.push(networks[i]);
330330
}
331331
else {
332332
optionalNetworkArray.push(networks[i]);
@@ -335,13 +335,25 @@
335335
}
336336
//***** populate all networks (end) ************************************
337337
}
338+
});
339+
340+
$.ajax({
341+
url: createURL("listNetworkOfferings"),
342+
dataType: "json",
343+
async: false,
344+
success: function(json) {
345+
networkOfferingObjs = json.listnetworkofferingsresponse.networkoffering;
346+
}
338347
});
348+
349+
339350
args.response.success({
340351
type: 'select-network',
341352
data: {
342353
myNetworks: defaultNetworkArray,
343354
sharedNetworks: optionalNetworkArray,
344-
securityGroups: []
355+
securityGroups: [],
356+
networkOfferings: networkOfferingObjs
345357
}
346358
});
347359
}
@@ -378,7 +390,7 @@
378390
data: {
379391
defaultNetworks: [],
380392
optionalNetworks: [],
381-
securityGroups: []
393+
securityGroups: []
382394
}
383395
});
384396
}
@@ -419,26 +431,55 @@
419431
array1.push("&size=" + args.data.size);
420432
}
421433

422-
//step 5: select network
423-
if (step5ContainerType == 'select-network') {
424-
var array2 = [];
425-
var defaultNetwork = args.data["default-network"];
434+
//step 5: select network ???
435+
if (step5ContainerType == 'select-network') {
436+
var array2 = [];
437+
var defaultNetwork = args.data.defaultNetwork; //args.data.defaultNetwork might be equal to "new-network"
438+
var checkedNetworks = args.data["my-networks"];
439+
440+
//create new network starts here
441+
if(args.data["new-network"] == "create-new-network") {
442+
var selectedNetworkOfferingId;
443+
if(networkOfferingObjs != null && networkOfferingObjs.length > 0) {
444+
for(var k=0; k < networkOfferingObjs.length; k++) {
445+
if(networkOfferingObjs[k].name == args.data["new-network-serviceofferingid"])
446+
selectedNetworkOfferingId = networkOfferingObjs[k].id;
447+
}
448+
}
449+
450+
var networkName = "new Network";
451+
$.ajax({
452+
url: createURL("createNetwork&networkOfferingId="+selectedNetworkOfferingId+"&name="+todb(networkName)+"&displayText="+todb(networkName)+"&zoneId="+selectedZoneObj.id),
453+
dataType: "json",
454+
async: false,
455+
success: function(json) {
456+
newNetwork = json.createnetworkresponse.network;
457+
checkedNetworks.push(newNetwork.id);
458+
if(defaultNetwork == "new-network")
459+
defaultNetwork = newNetwork.id;
460+
}
461+
});
462+
}
463+
//create new network ends here
464+
465+
//add default network first
426466
if(defaultNetwork != null && defaultNetwork.length > 0)
427467
array2.push(defaultNetwork);
428-
429-
var optionalNetworks = args.data["optional-networks"];
430-
//optionalNetworks might be: (1) an array of string, e.g. ["203", "202"],
431-
if(typeof(optionalNetworks) == "object" && optionalNetworks.length != null) {
432-
if(optionalNetworks != null && optionalNetworks.length > 0) {
433-
for(var i=0; i < optionalNetworks.length; i++) {
434-
array2.push(optionalNetworks[i]);
468+
469+
//then, add other checked networks
470+
if(typeof(checkedNetworks) == "object" && checkedNetworks.length != null) { //checkedNetworks might be: (1) an array of string, e.g. ["203", "202"],
471+
if(checkedNetworks != null && checkedNetworks.length > 0) {
472+
for(var i=0; i < checkedNetworks.length; i++) {
473+
if(checkedNetworks[i] != defaultNetwork) //exclude defaultNetwork that has been added to array2
474+
array2.push(checkedNetworks[i]);
435475
}
436476
}
477+
}
478+
else if(typeof(checkedNetworks) == "string" && checkedNetworks.length > 0) { //checkedNetworks might be: (2) just an string, e.g. "202"
479+
if(checkedNetworks != defaultNetwork) //exclude defaultNetwork that has been added to array2
480+
array2.push(checkedNetworks);
437481
}
438-
//optionalNetworks might be: (2) just an string, e.g. "202"
439-
else if(typeof(optionalNetworks) == "string" && optionalNetworks.length > 0) {
440-
array2.push(optionalNetworks);
441-
}
482+
442483
array1.push("&networkIds=" + array2.join(","));
443484
}
444485
else if (step5ContainerType == 'select-security-group') {

0 commit comments

Comments
 (0)