mirror of https://github.com/apache/cloudstack.git
Instance wizard: clean up JS formatting
This commit is contained in:
parent
e0692b39d9
commit
9d5c375678
|
|
@ -68,475 +68,475 @@
|
|||
|
||||
// Data providers for each wizard step
|
||||
steps: [
|
||||
|
||||
// Step 1: Setup
|
||||
function(args) {
|
||||
if(args.initArgs.pluginForm != null && args.initArgs.pluginForm.name == "vpcTierInstanceWizard") { //from VPC Tier chart
|
||||
//populate only one zone to the dropdown, the zone which the VPC is under.
|
||||
zoneObjs = [{
|
||||
id: args.context.vpc[0].zoneid,
|
||||
name: args.context.vpc[0].zonename,
|
||||
networktype: 'Advanced'
|
||||
}];
|
||||
args.response.success({ data: {zones: zoneObjs}});
|
||||
}
|
||||
else { //from Instance page
|
||||
$.ajax({
|
||||
url: createURL("listZones&available=true"),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
zoneObjs = json.listzonesresponse.zone;
|
||||
args.response.success({ data: {zones: zoneObjs}});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// Step 1: Setup
|
||||
function(args) {
|
||||
if(args.initArgs.pluginForm != null && args.initArgs.pluginForm.name == "vpcTierInstanceWizard") { //from VPC Tier chart
|
||||
//populate only one zone to the dropdown, the zone which the VPC is under.
|
||||
zoneObjs = [{
|
||||
id: args.context.vpc[0].zoneid,
|
||||
name: args.context.vpc[0].zonename,
|
||||
networktype: 'Advanced'
|
||||
}];
|
||||
args.response.success({ data: {zones: zoneObjs}});
|
||||
}
|
||||
else { //from Instance page
|
||||
$.ajax({
|
||||
url: createURL("listZones&available=true"),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
zoneObjs = json.listzonesresponse.zone;
|
||||
args.response.success({ data: {zones: zoneObjs}});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// Step 2: Select template
|
||||
function(args) {
|
||||
$(zoneObjs).each(function(){
|
||||
if(this.id == args.currentData.zoneid) {
|
||||
selectedZoneObj = this;
|
||||
return false; //break the $.each() loop
|
||||
}
|
||||
});
|
||||
if(selectedZoneObj == null) {
|
||||
alert("error: can't find matched zone object");
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: createURL("listHypervisors&zoneid="+args.currentData.zoneid),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
hypervisorObjs = json.listhypervisorsresponse.hypervisor;
|
||||
}
|
||||
});
|
||||
|
||||
//***** get templates/ISOs (begin) *****
|
||||
var selectedTemplate = args.currentData['select-template'];
|
||||
if (selectedTemplate == 'select-template') {
|
||||
var hypervisorArray = [];
|
||||
$(hypervisorObjs).each(function(index, item) {
|
||||
hypervisorArray.push(item.name);
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: createURL("listTemplates&templatefilter=featured&zoneid="+args.currentData.zoneid),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
if(json.listtemplatesresponse.template == null) {
|
||||
featuredTemplateObjs = null;
|
||||
}
|
||||
else {
|
||||
featuredTemplateObjs = $.grep(json.listtemplatesresponse.template, function(item, index) {
|
||||
if($.inArray(item.hypervisor, hypervisorArray) > -1)
|
||||
return true;
|
||||
});
|
||||
}
|
||||
// Step 2: Select template
|
||||
function(args) {
|
||||
$(zoneObjs).each(function(){
|
||||
if(this.id == args.currentData.zoneid) {
|
||||
selectedZoneObj = this;
|
||||
return false; //break the $.each() loop
|
||||
}
|
||||
});
|
||||
if(selectedZoneObj == null) {
|
||||
alert("error: can't find matched zone object");
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: createURL("listTemplates&templatefilter=community&zoneid="+args.currentData.zoneid),
|
||||
url: createURL("listHypervisors&zoneid="+args.currentData.zoneid),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
if(json.listtemplatesresponse.template == null) {
|
||||
communityTemplateObjs = null;
|
||||
}
|
||||
else {
|
||||
communityTemplateObjs = $.grep(json.listtemplatesresponse.template, function(item, index) {
|
||||
if($.inArray(item.hypervisor, hypervisorArray) > -1)
|
||||
return true;
|
||||
});
|
||||
}
|
||||
hypervisorObjs = json.listhypervisorsresponse.hypervisor;
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
url: createURL("listTemplates&templatefilter=selfexecutable&zoneid="+args.currentData.zoneid),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
if(json.listtemplatesresponse.template == null) {
|
||||
myTemplateObjs = null;
|
||||
}
|
||||
else {
|
||||
myTemplateObjs = $.grep(json.listtemplatesresponse.template, function(item, index) {
|
||||
if($.inArray(item.hypervisor, hypervisorArray) > -1)
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (selectedTemplate == 'select-iso') {
|
||||
$.ajax({
|
||||
url: createURL("listIsos&isofilter=featured&zoneid=" + args.currentData.zoneid + "&bootable=true"),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
if(json.listisosresponse.iso == null) {
|
||||
featuredIsoObjs = null;
|
||||
}
|
||||
else {
|
||||
featuredIsoObjs = json.listisosresponse.iso;
|
||||
}
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
url: createURL("listIsos&isofilter=community&zoneid=" + args.currentData.zoneid + "&bootable=true"),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
if(json.listisosresponse.iso == null) {
|
||||
communityIsoObjs = null;
|
||||
}
|
||||
else {
|
||||
communityIsoObjs = json.listisosresponse.iso;
|
||||
}
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
url: createURL("listIsos&isofilter=selfexecutable&zoneid=" + args.currentData.zoneid + "&bootable=true"),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
if(json.listisosresponse.iso == null) {
|
||||
myIsoObjs = null;
|
||||
}
|
||||
else {
|
||||
myIsoObjs = json.listisosresponse.iso;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
//***** get templates/ISOs (end) *****
|
||||
|
||||
//***** get templates/ISOs (begin) *****
|
||||
var selectedTemplate = args.currentData['select-template'];
|
||||
if (selectedTemplate == 'select-template') {
|
||||
var hypervisorArray = [];
|
||||
$(hypervisorObjs).each(function(index, item) {
|
||||
hypervisorArray.push(item.name);
|
||||
});
|
||||
|
||||
var templatesObj = {};
|
||||
if (selectedTemplate == 'select-template') {
|
||||
templatesObj = {
|
||||
featuredtemplates: featuredTemplateObjs,
|
||||
communitytemplates: communityTemplateObjs,
|
||||
mytemplates: myTemplateObjs
|
||||
}
|
||||
} else if (selectedTemplate == 'select-iso') {
|
||||
templatesObj = {
|
||||
featuredisos: featuredIsoObjs,
|
||||
communityisos: communityIsoObjs,
|
||||
myisos: myIsoObjs
|
||||
}
|
||||
}
|
||||
args.response.success({
|
||||
hypervisor: {
|
||||
idField: 'name',
|
||||
nameField: 'name'
|
||||
},
|
||||
data: {
|
||||
templates: templatesObj,
|
||||
hypervisors: hypervisorObjs
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Step 3: Service offering
|
||||
function(args) {
|
||||
if(args.currentData["select-template"] == "select-template") {
|
||||
if(featuredTemplateObjs != null && featuredTemplateObjs.length > 0) {
|
||||
for(var i=0; i < featuredTemplateObjs.length; i++) {
|
||||
if(featuredTemplateObjs[i].id == args.currentData.templateid) {
|
||||
selectedTemplateObj = featuredTemplateObjs[i];
|
||||
break;
|
||||
$.ajax({
|
||||
url: createURL("listTemplates&templatefilter=featured&zoneid="+args.currentData.zoneid),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
if(json.listtemplatesresponse.template == null) {
|
||||
featuredTemplateObjs = null;
|
||||
}
|
||||
else {
|
||||
featuredTemplateObjs = $.grep(json.listtemplatesresponse.template, function(item, index) {
|
||||
if($.inArray(item.hypervisor, hypervisorArray) > -1)
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
url: createURL("listTemplates&templatefilter=community&zoneid="+args.currentData.zoneid),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
if(json.listtemplatesresponse.template == null) {
|
||||
communityTemplateObjs = null;
|
||||
}
|
||||
else {
|
||||
communityTemplateObjs = $.grep(json.listtemplatesresponse.template, function(item, index) {
|
||||
if($.inArray(item.hypervisor, hypervisorArray) > -1)
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
url: createURL("listTemplates&templatefilter=selfexecutable&zoneid="+args.currentData.zoneid),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
if(json.listtemplatesresponse.template == null) {
|
||||
myTemplateObjs = null;
|
||||
}
|
||||
else {
|
||||
myTemplateObjs = $.grep(json.listtemplatesresponse.template, function(item, index) {
|
||||
if($.inArray(item.hypervisor, hypervisorArray) > -1)
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (selectedTemplate == 'select-iso') {
|
||||
$.ajax({
|
||||
url: createURL("listIsos&isofilter=featured&zoneid=" + args.currentData.zoneid + "&bootable=true"),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
if(json.listisosresponse.iso == null) {
|
||||
featuredIsoObjs = null;
|
||||
}
|
||||
else {
|
||||
featuredIsoObjs = json.listisosresponse.iso;
|
||||
}
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
url: createURL("listIsos&isofilter=community&zoneid=" + args.currentData.zoneid + "&bootable=true"),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
if(json.listisosresponse.iso == null) {
|
||||
communityIsoObjs = null;
|
||||
}
|
||||
else {
|
||||
communityIsoObjs = json.listisosresponse.iso;
|
||||
}
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
url: createURL("listIsos&isofilter=selfexecutable&zoneid=" + args.currentData.zoneid + "&bootable=true"),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
if(json.listisosresponse.iso == null) {
|
||||
myIsoObjs = null;
|
||||
}
|
||||
else {
|
||||
myIsoObjs = json.listisosresponse.iso;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
//***** get templates/ISOs (end) *****
|
||||
|
||||
|
||||
var templatesObj = {};
|
||||
if (selectedTemplate == 'select-template') {
|
||||
templatesObj = {
|
||||
featuredtemplates: featuredTemplateObjs,
|
||||
communitytemplates: communityTemplateObjs,
|
||||
mytemplates: myTemplateObjs
|
||||
}
|
||||
} else if (selectedTemplate == 'select-iso') {
|
||||
templatesObj = {
|
||||
featuredisos: featuredIsoObjs,
|
||||
communityisos: communityIsoObjs,
|
||||
myisos: myIsoObjs
|
||||
}
|
||||
}
|
||||
if(selectedTemplateObj == null) {
|
||||
if(communityTemplateObjs != null && communityTemplateObjs.length > 0) {
|
||||
for(var i=0; i < communityTemplateObjs.length; i++) {
|
||||
if(communityTemplateObjs[i].id == args.currentData.templateid) {
|
||||
selectedTemplateObj = communityTemplateObjs[i];
|
||||
args.response.success({
|
||||
hypervisor: {
|
||||
idField: 'name',
|
||||
nameField: 'name'
|
||||
},
|
||||
data: {
|
||||
templates: templatesObj,
|
||||
hypervisors: hypervisorObjs
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Step 3: Service offering
|
||||
function(args) {
|
||||
if(args.currentData["select-template"] == "select-template") {
|
||||
if(featuredTemplateObjs != null && featuredTemplateObjs.length > 0) {
|
||||
for(var i=0; i < featuredTemplateObjs.length; i++) {
|
||||
if(featuredTemplateObjs[i].id == args.currentData.templateid) {
|
||||
selectedTemplateObj = featuredTemplateObjs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(selectedTemplateObj == null) {
|
||||
if(myTemplateObjs != null && myTemplateObjs.length > 0) {
|
||||
for(var i=0; i < myTemplateObjs.length; i++) {
|
||||
if(myTemplateObjs[i].id == args.currentData.templateid) {
|
||||
selectedTemplateObj = myTemplateObjs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(selectedTemplateObj == null)
|
||||
alert("unable to find matched template object");
|
||||
else
|
||||
selectedHypervisor = selectedTemplateObj.hypervisor;
|
||||
}
|
||||
else { //(args.currentData["select-template"] == "select-iso"
|
||||
selectedHypervisor = args.currentData.hypervisorid;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: createURL("listServiceOfferings&issystem=false"),
|
||||
dataType: "json",
|
||||
async: true,
|
||||
success: function(json) {
|
||||
serviceOfferingObjs = json.listserviceofferingsresponse.serviceoffering;
|
||||
args.response.success({
|
||||
data: {serviceOfferings: serviceOfferingObjs}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Step 4: Data disk offering
|
||||
function(args) {
|
||||
var isRequred = (args.currentData["select-template"] == "select-iso"? true: false);
|
||||
$.ajax({
|
||||
url: createURL("listDiskOfferings"),
|
||||
dataType: "json",
|
||||
async: true,
|
||||
success: function(json) {
|
||||
diskOfferingObjs = json.listdiskofferingsresponse.diskoffering;
|
||||
args.response.success({
|
||||
required: isRequred,
|
||||
customFlag: 'iscustomized', // Field determines if custom slider is shown
|
||||
data: {diskOfferings: diskOfferingObjs}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Step 5: Network
|
||||
function(args) {
|
||||
if(diskOfferingObjs != null && diskOfferingObjs.length > 0) {
|
||||
for(var i=0; i < diskOfferingObjs.length; i++) {
|
||||
if(diskOfferingObjs[i].id == args.currentData.diskofferingid) {
|
||||
selectedDiskOfferingObj = diskOfferingObjs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedZoneObj.networktype == "Advanced") { //Advanced zone. Show network list.
|
||||
var $networkStep = $(".step.network:visible .nothing-to-select");
|
||||
var $networkStepContainer = $('.step.network:visible');
|
||||
|
||||
if(args.initArgs.pluginForm != null && args.initArgs.pluginForm.name == "vpcTierInstanceWizard") { //from VPC Tier chart
|
||||
step5ContainerType = 'nothing-to-select';
|
||||
$networkStep.find("#from_instance_page_1").hide();
|
||||
$networkStep.find("#from_instance_page_2").hide();
|
||||
$networkStep.find("#from_vpc_tier").text("tier " + args.context.networks[0].name);
|
||||
$networkStep.find("#from_vpc_tier").show();
|
||||
} else { //from Instance page
|
||||
if(selectedZoneObj.securitygroupsenabled != true) { // Advanced SG-disabled zone
|
||||
step5ContainerType = 'select-network';
|
||||
$networkStep.find("#from_instance_page_1").show();
|
||||
$networkStep.find("#from_instance_page_2").show();
|
||||
$networkStep.find("#from_vpc_tier").text("");
|
||||
$networkStep.find("#from_vpc_tier").hide();
|
||||
$networkStepContainer.removeClass('next-use-security-groups');
|
||||
} else { // Advanced SG-enabled zone
|
||||
step5ContainerType = 'select-advanced-sg';
|
||||
}
|
||||
|
||||
if ($networkStepContainer.hasClass('next-use-security-groups')) {
|
||||
$networkStepContainer.removeClass('repeat next-use-security-groups loaded');
|
||||
step5ContainerType = 'select-security-group';
|
||||
}
|
||||
}
|
||||
}
|
||||
else { //Basic zone. Show securigy group list or nothing(when no SecurityGroup service in guest network)
|
||||
var includingSecurityGroupService = false;
|
||||
$.ajax({
|
||||
url: createURL("listNetworks&trafficType=Guest&zoneId=" + selectedZoneObj.id),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
//basic zone should have only one guest network returned in this API call
|
||||
var items = json.listnetworksresponse.network;
|
||||
if(items != null && items.length > 0) {
|
||||
var networkObj = items[0]; //basic zone has only one guest network
|
||||
var serviceObjArray = networkObj.service;
|
||||
for(var k = 0; k < serviceObjArray.length; k++) {
|
||||
if(serviceObjArray[k].name == "SecurityGroup") {
|
||||
includingSecurityGroupService = true;
|
||||
if(selectedTemplateObj == null) {
|
||||
if(communityTemplateObjs != null && communityTemplateObjs.length > 0) {
|
||||
for(var i=0; i < communityTemplateObjs.length; i++) {
|
||||
if(communityTemplateObjs[i].id == args.currentData.templateid) {
|
||||
selectedTemplateObj = communityTemplateObjs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(includingSecurityGroupService == false || selectedHypervisor == "VMware") {
|
||||
step5ContainerType = 'nothing-to-select';
|
||||
}
|
||||
else {
|
||||
step5ContainerType = 'select-security-group';
|
||||
}
|
||||
}
|
||||
|
||||
//step5ContainerType = 'nothing-to-select'; //for testing only, comment it out before checking in
|
||||
if(step5ContainerType == 'select-network' || step5ContainerType == 'select-advanced-sg') {
|
||||
var defaultNetworkArray = [], optionalNetworkArray = [];
|
||||
var networkData = {
|
||||
zoneId: args.currentData.zoneid,
|
||||
canusefordeploy: true
|
||||
};
|
||||
|
||||
if(selectedZoneObj.networktype == 'Advanced' && selectedZoneObj.securitygroupsenabled == true) {
|
||||
$.extend(networkData, {
|
||||
type: 'Shared'
|
||||
});
|
||||
}
|
||||
|
||||
if (!(cloudStack.context.projects && cloudStack.context.projects[0])) {
|
||||
networkData.domainid = g_domainid;
|
||||
networkData.account = g_account;
|
||||
}
|
||||
|
||||
var vpcObjs;
|
||||
|
||||
//listVPCs without account/domainid/listAll parameter will return only VPCs belonging to the current login. That's what should happen in Instances page's VM Wizard.
|
||||
//i.e. If the current login is root-admin, do not show VPCs belonging to regular-user/domain-admin in Instances page's VM Wizard.
|
||||
$.ajax({
|
||||
url: createURL('listVPCs'),
|
||||
async: false,
|
||||
success: function(json) {
|
||||
vpcObjs = json.listvpcsresponse.vpc ? json.listvpcsresponse.vpc : [];
|
||||
}
|
||||
});
|
||||
|
||||
var networkObjsToPopulate = [];
|
||||
$.ajax({
|
||||
url: createURL('listNetworks'),
|
||||
data: networkData,
|
||||
async: false,
|
||||
success: function(json) {
|
||||
networkObjs = json.listnetworksresponse.network ? json.listnetworksresponse.network : [];
|
||||
if(networkObjs.length > 0) {
|
||||
for(var i = 0; i < networkObjs.length; i++) {
|
||||
var networkObj = networkObjs[i];
|
||||
var includingSecurityGroup = false;
|
||||
var serviceObjArray = networkObj.service;
|
||||
for(var k = 0; k < serviceObjArray.length; k++) {
|
||||
if(serviceObjArray[k].name == "SecurityGroup") {
|
||||
networkObjs[i].type = networkObjs[i].type + ' (sg)';
|
||||
includingSecurityGroup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (networkObj.vpcid) {
|
||||
networkObj._singleSelect = true;
|
||||
if(selectedTemplateObj == null) {
|
||||
if(myTemplateObjs != null && myTemplateObjs.length > 0) {
|
||||
for(var i=0; i < myTemplateObjs.length; i++) {
|
||||
if(myTemplateObjs[i].id == args.currentData.templateid) {
|
||||
selectedTemplateObj = myTemplateObjs[i];
|
||||
break;
|
||||
}
|
||||
|
||||
//for Advanced SG-enabled zone, list only SG network offerings
|
||||
if(selectedZoneObj.networktype == 'Advanced' && selectedZoneObj.securitygroupsenabled == true) {
|
||||
if(includingSecurityGroup == false)
|
||||
continue; //skip to next network offering
|
||||
}
|
||||
networkObjsToPopulate.push(networkObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: createURL("listNetworkOfferings"),
|
||||
dataType: "json",
|
||||
data: {
|
||||
forvpc: false,
|
||||
zoneid: args.currentData.zoneid,
|
||||
guestiptype: 'Isolated',
|
||||
supportedServices: 'SourceNat',
|
||||
specifyvlan: false,
|
||||
state: 'Enabled'
|
||||
},
|
||||
async: false,
|
||||
success: function(json) {
|
||||
networkOfferingObjs = json.listnetworkofferingsresponse.networkoffering;
|
||||
}
|
||||
});
|
||||
//get network offerings (end) ***
|
||||
|
||||
$networkStepContainer.removeClass('repeat next-use-security-groups');
|
||||
|
||||
if (step5ContainerType == 'select-advanced-sg') {
|
||||
$networkStepContainer.addClass('repeat next-use-security-groups');
|
||||
|
||||
// Add guest network is disabled
|
||||
$networkStepContainer.find('.select-network').addClass('no-add-network');
|
||||
} else {
|
||||
$networkStepContainer.find('.select-network').removeClass('no-add-network');
|
||||
}
|
||||
|
||||
args.response.success({
|
||||
type: 'select-network',
|
||||
data: {
|
||||
networkObjs: networkObjsToPopulate,
|
||||
securityGroups: [],
|
||||
networkOfferings: networkOfferingObjs,
|
||||
vpcs: vpcObjs
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else if(step5ContainerType == 'select-security-group') {
|
||||
var securityGroupArray = [];
|
||||
var data = {
|
||||
domainid: g_domainid,
|
||||
account: g_account
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: createURL("listSecurityGroups"),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data: cloudStack.context.projects ? {} : data,
|
||||
success: function(json) {
|
||||
var items = json.listsecuritygroupsresponse.securitygroup;
|
||||
if (items != null && items.length > 0) {
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
securityGroupArray.push(items[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
args.response.success({
|
||||
type: 'select-security-group',
|
||||
data: {
|
||||
networkObjs: [],
|
||||
securityGroups: securityGroupArray,
|
||||
networkOfferings: [],
|
||||
vpcs: []
|
||||
if(selectedTemplateObj == null)
|
||||
alert("unable to find matched template object");
|
||||
else
|
||||
selectedHypervisor = selectedTemplateObj.hypervisor;
|
||||
}
|
||||
else { //(args.currentData["select-template"] == "select-iso"
|
||||
selectedHypervisor = args.currentData.hypervisorid;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: createURL("listServiceOfferings&issystem=false"),
|
||||
dataType: "json",
|
||||
async: true,
|
||||
success: function(json) {
|
||||
serviceOfferingObjs = json.listserviceofferingsresponse.serviceoffering;
|
||||
args.response.success({
|
||||
data: {serviceOfferings: serviceOfferingObjs}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
else if(step5ContainerType == 'nothing-to-select') {
|
||||
args.response.success({
|
||||
type: 'nothing-to-select',
|
||||
data: {
|
||||
networkObjs: [],
|
||||
securityGroups: [],
|
||||
networkOfferings: [],
|
||||
vpcs: []
|
||||
// Step 4: Data disk offering
|
||||
function(args) {
|
||||
var isRequred = (args.currentData["select-template"] == "select-iso"? true: false);
|
||||
$.ajax({
|
||||
url: createURL("listDiskOfferings"),
|
||||
dataType: "json",
|
||||
async: true,
|
||||
success: function(json) {
|
||||
diskOfferingObjs = json.listdiskofferingsresponse.diskoffering;
|
||||
args.response.success({
|
||||
required: isRequred,
|
||||
customFlag: 'iscustomized', // Field determines if custom slider is shown
|
||||
data: {diskOfferings: diskOfferingObjs}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Step 6: Network
|
||||
function(args) {
|
||||
if(diskOfferingObjs != null && diskOfferingObjs.length > 0) {
|
||||
for(var i=0; i < diskOfferingObjs.length; i++) {
|
||||
if(diskOfferingObjs[i].id == args.currentData.diskofferingid) {
|
||||
selectedDiskOfferingObj = diskOfferingObjs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedZoneObj.networktype == "Advanced") { //Advanced zone. Show network list.
|
||||
var $networkStep = $(".step.network:visible .nothing-to-select");
|
||||
var $networkStepContainer = $('.step.network:visible');
|
||||
|
||||
if(args.initArgs.pluginForm != null && args.initArgs.pluginForm.name == "vpcTierInstanceWizard") { //from VPC Tier chart
|
||||
step5ContainerType = 'nothing-to-select';
|
||||
$networkStep.find("#from_instance_page_1").hide();
|
||||
$networkStep.find("#from_instance_page_2").hide();
|
||||
$networkStep.find("#from_vpc_tier").text("tier " + args.context.networks[0].name);
|
||||
$networkStep.find("#from_vpc_tier").show();
|
||||
} else { //from Instance page
|
||||
if(selectedZoneObj.securitygroupsenabled != true) { // Advanced SG-disabled zone
|
||||
step5ContainerType = 'select-network';
|
||||
$networkStep.find("#from_instance_page_1").show();
|
||||
$networkStep.find("#from_instance_page_2").show();
|
||||
$networkStep.find("#from_vpc_tier").text("");
|
||||
$networkStep.find("#from_vpc_tier").hide();
|
||||
$networkStepContainer.removeClass('next-use-security-groups');
|
||||
} else { // Advanced SG-enabled zone
|
||||
step5ContainerType = 'select-advanced-sg';
|
||||
}
|
||||
|
||||
if ($networkStepContainer.hasClass('next-use-security-groups')) {
|
||||
$networkStepContainer.removeClass('repeat next-use-security-groups loaded');
|
||||
step5ContainerType = 'select-security-group';
|
||||
}
|
||||
}
|
||||
}
|
||||
else { //Basic zone. Show securigy group list or nothing(when no SecurityGroup service in guest network)
|
||||
var includingSecurityGroupService = false;
|
||||
$.ajax({
|
||||
url: createURL("listNetworks&trafficType=Guest&zoneId=" + selectedZoneObj.id),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
//basic zone should have only one guest network returned in this API call
|
||||
var items = json.listnetworksresponse.network;
|
||||
if(items != null && items.length > 0) {
|
||||
var networkObj = items[0]; //basic zone has only one guest network
|
||||
var serviceObjArray = networkObj.service;
|
||||
for(var k = 0; k < serviceObjArray.length; k++) {
|
||||
if(serviceObjArray[k].name == "SecurityGroup") {
|
||||
includingSecurityGroupService = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(includingSecurityGroupService == false || selectedHypervisor == "VMware") {
|
||||
step5ContainerType = 'nothing-to-select';
|
||||
}
|
||||
else {
|
||||
step5ContainerType = 'select-security-group';
|
||||
}
|
||||
}
|
||||
|
||||
//step5ContainerType = 'nothing-to-select'; //for testing only, comment it out before checking in
|
||||
if(step5ContainerType == 'select-network' || step5ContainerType == 'select-advanced-sg') {
|
||||
var defaultNetworkArray = [], optionalNetworkArray = [];
|
||||
var networkData = {
|
||||
zoneId: args.currentData.zoneid,
|
||||
canusefordeploy: true
|
||||
};
|
||||
|
||||
if(selectedZoneObj.networktype == 'Advanced' && selectedZoneObj.securitygroupsenabled == true) {
|
||||
$.extend(networkData, {
|
||||
type: 'Shared'
|
||||
});
|
||||
}
|
||||
|
||||
if (!(cloudStack.context.projects && cloudStack.context.projects[0])) {
|
||||
networkData.domainid = g_domainid;
|
||||
networkData.account = g_account;
|
||||
}
|
||||
|
||||
var vpcObjs;
|
||||
|
||||
//listVPCs without account/domainid/listAll parameter will return only VPCs belonging to the current login. That's what should happen in Instances page's VM Wizard.
|
||||
//i.e. If the current login is root-admin, do not show VPCs belonging to regular-user/domain-admin in Instances page's VM Wizard.
|
||||
$.ajax({
|
||||
url: createURL('listVPCs'),
|
||||
async: false,
|
||||
success: function(json) {
|
||||
vpcObjs = json.listvpcsresponse.vpc ? json.listvpcsresponse.vpc : [];
|
||||
}
|
||||
});
|
||||
|
||||
var networkObjsToPopulate = [];
|
||||
$.ajax({
|
||||
url: createURL('listNetworks'),
|
||||
data: networkData,
|
||||
async: false,
|
||||
success: function(json) {
|
||||
networkObjs = json.listnetworksresponse.network ? json.listnetworksresponse.network : [];
|
||||
if(networkObjs.length > 0) {
|
||||
for(var i = 0; i < networkObjs.length; i++) {
|
||||
var networkObj = networkObjs[i];
|
||||
var includingSecurityGroup = false;
|
||||
var serviceObjArray = networkObj.service;
|
||||
for(var k = 0; k < serviceObjArray.length; k++) {
|
||||
if(serviceObjArray[k].name == "SecurityGroup") {
|
||||
networkObjs[i].type = networkObjs[i].type + ' (sg)';
|
||||
includingSecurityGroup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (networkObj.vpcid) {
|
||||
networkObj._singleSelect = true;
|
||||
}
|
||||
|
||||
//for Advanced SG-enabled zone, list only SG network offerings
|
||||
if(selectedZoneObj.networktype == 'Advanced' && selectedZoneObj.securitygroupsenabled == true) {
|
||||
if(includingSecurityGroup == false)
|
||||
continue; //skip to next network offering
|
||||
}
|
||||
networkObjsToPopulate.push(networkObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: createURL("listNetworkOfferings"),
|
||||
dataType: "json",
|
||||
data: {
|
||||
forvpc: false,
|
||||
zoneid: args.currentData.zoneid,
|
||||
guestiptype: 'Isolated',
|
||||
supportedServices: 'SourceNat',
|
||||
specifyvlan: false,
|
||||
state: 'Enabled'
|
||||
},
|
||||
async: false,
|
||||
success: function(json) {
|
||||
networkOfferingObjs = json.listnetworkofferingsresponse.networkoffering;
|
||||
}
|
||||
});
|
||||
//get network offerings (end) ***
|
||||
|
||||
$networkStepContainer.removeClass('repeat next-use-security-groups');
|
||||
|
||||
if (step5ContainerType == 'select-advanced-sg') {
|
||||
$networkStepContainer.addClass('repeat next-use-security-groups');
|
||||
|
||||
// Add guest network is disabled
|
||||
$networkStepContainer.find('.select-network').addClass('no-add-network');
|
||||
} else {
|
||||
$networkStepContainer.find('.select-network').removeClass('no-add-network');
|
||||
}
|
||||
|
||||
args.response.success({
|
||||
type: 'select-network',
|
||||
data: {
|
||||
networkObjs: networkObjsToPopulate,
|
||||
securityGroups: [],
|
||||
networkOfferings: networkOfferingObjs,
|
||||
vpcs: vpcObjs
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else if(step5ContainerType == 'select-security-group') {
|
||||
var securityGroupArray = [];
|
||||
var data = {
|
||||
domainid: g_domainid,
|
||||
account: g_account
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: createURL("listSecurityGroups"),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data: cloudStack.context.projects ? {} : data,
|
||||
success: function(json) {
|
||||
var items = json.listsecuritygroupsresponse.securitygroup;
|
||||
if (items != null && items.length > 0) {
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
securityGroupArray.push(items[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
args.response.success({
|
||||
type: 'select-security-group',
|
||||
data: {
|
||||
networkObjs: [],
|
||||
securityGroups: securityGroupArray,
|
||||
networkOfferings: [],
|
||||
vpcs: []
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else if(step5ContainerType == 'nothing-to-select') {
|
||||
args.response.success({
|
||||
type: 'nothing-to-select',
|
||||
data: {
|
||||
networkObjs: [],
|
||||
securityGroups: [],
|
||||
networkOfferings: [],
|
||||
vpcs: []
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
// Step 6: Review
|
||||
function(args) {
|
||||
return false;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
// Step 6: Review
|
||||
function(args) {
|
||||
return false;
|
||||
}
|
||||
],
|
||||
action: function(args) {
|
||||
// Create a new VM!!!!
|
||||
|
|
@ -638,12 +638,12 @@
|
|||
|
||||
if(checkedSecurityGroupIdArray.length > 0)
|
||||
array1.push("&securitygroupids=" + checkedSecurityGroupIdArray.join(","));
|
||||
|
||||
|
||||
if(selectedZoneObj.networktype == "Advanced" && selectedZoneObj.securitygroupsenabled == true) { // Advanced SG-enabled zone
|
||||
var array2 = [];
|
||||
var myNetworks = $('.multi-wizard:visible form').data('my-networks'); //widget limitation: If using an advanced security group zone, get the guest networks like this
|
||||
var defaultNetworkId = $('.multi-wizard:visible form').find('input[name=defaultNetwork]:checked').val();
|
||||
|
||||
|
||||
var checkedNetworkIdArray;
|
||||
if(typeof(myNetworks) == "object" && myNetworks.length != null) { //myNetworks is an array of string, e.g. ["203", "202"],
|
||||
checkedNetworkIdArray = myNetworks;
|
||||
|
|
@ -703,30 +703,30 @@
|
|||
var vmid = json.deployvirtualmachineresponse.id;
|
||||
args.response.success(
|
||||
{_custom:
|
||||
{jobId: jid,
|
||||
getUpdatedItem: function(json) {
|
||||
var item = json.queryasyncjobresultresponse.jobresult.virtualmachine;
|
||||
if (item.password != null)
|
||||
alert("Password of new VM " + item.displayname + " is " + item.password);
|
||||
return item;
|
||||
},
|
||||
getActionFilter: function() {
|
||||
return cloudStack.actionFilter.vmActionFilter;
|
||||
},
|
||||
getUpdatedItemWhenAsyncJobFails: function() {
|
||||
var item;
|
||||
$.ajax({
|
||||
url: createURL("listVirtualMachines&id="+vmid),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
item = json.listvirtualmachinesresponse.virtualmachine[0];
|
||||
}
|
||||
});
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
{jobId: jid,
|
||||
getUpdatedItem: function(json) {
|
||||
var item = json.queryasyncjobresultresponse.jobresult.virtualmachine;
|
||||
if (item.password != null)
|
||||
alert("Password of new VM " + item.displayname + " is " + item.password);
|
||||
return item;
|
||||
},
|
||||
getActionFilter: function() {
|
||||
return cloudStack.actionFilter.vmActionFilter;
|
||||
},
|
||||
getUpdatedItemWhenAsyncJobFails: function() {
|
||||
var item;
|
||||
$.ajax({
|
||||
url: createURL("listVirtualMachines&id="+vmid),
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
item = json.listvirtualmachinesresponse.virtualmachine[0];
|
||||
}
|
||||
});
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
error: function(XMLHttpResponse) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue