Add Nicira configuration to the UI

This commit is contained in:
Hugo Trippaers 2012-09-30 23:33:37 -07:00
parent c5634b9687
commit c9b0b0b1a9
8 changed files with 486 additions and 11 deletions

View File

@ -291,4 +291,9 @@ public class EventTypes {
public static final String EVENT_TAGS_CREATE = "CREATE_TAGS";
public static final String EVENT_TAGS_DELETE = "DELETE_TAGS";
// external network device events
public static final String EVENT_EXTERNAL_NVP_CONTROLLER_ADD = "PHYSICAL.NVPCONTROLLER.ADD";
public static final String EVENT_EXTERNAL_NVP_CONTROLLER_DELETE = "PHYSICAL.NVPCONTROLLER.DELETE";
public static final String EVENT_EXTERNAL_NVP_CONTROLLER_CONFIGURE = "PHYSICAL.NVPCONTROLLER.CONFIGURE";
}

View File

@ -42,7 +42,7 @@ import com.cloud.user.UserContext;
import com.cloud.utils.exception.CloudRuntimeException;
@Implementation(responseObject=NiciraNvpDeviceResponse.class, description="Adds a Nicira NVP device")
public class AddNiciraNvpDeviceCmd extends BaseCmd {
public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
private static final Logger s_logger = Logger.getLogger(AddNiciraNvpDeviceCmd.class.getName());
private static final String s_name = "addniciranvpdevice";
@PlugService NiciraNvpElementService _niciraNvpElementService;
@ -130,4 +130,14 @@ public class AddNiciraNvpDeviceCmd extends BaseCmd {
public long getEntityOwnerId() {
return UserContext.current().getCaller().getId();
}
@Override
public String getEventType() {
return EventTypes.EVENT_EXTERNAL_NVP_CONTROLLER_ADD;
}
@Override
public String getEventDescription() {
return "Adding a Nicira Nvp Controller";
}
}

View File

@ -19,6 +19,7 @@ package com.cloud.api.commands;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseAsyncCmd;
import com.cloud.api.BaseCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
@ -26,6 +27,7 @@ import com.cloud.api.Parameter;
import com.cloud.api.PlugService;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
@ -36,9 +38,9 @@ import com.cloud.user.UserContext;
import com.cloud.utils.exception.CloudRuntimeException;
@Implementation(responseObject=SuccessResponse.class, description=" delete a nicira nvp device")
public class DeleteNiciraNvpDeviceCmd extends BaseCmd {
public class DeleteNiciraNvpDeviceCmd extends BaseAsyncCmd {
private static final Logger s_logger = Logger.getLogger(DeleteNiciraNvpDeviceCmd.class.getName());
private static final String s_name = "addniciranvpdevice";
private static final String s_name = "deleteniciranvpdeviceresponse";
@PlugService NiciraNvpElementService _niciraNvpElementService;
/////////////////////////////////////////////////////
@ -89,4 +91,14 @@ public class DeleteNiciraNvpDeviceCmd extends BaseCmd {
return UserContext.current().getCaller().getId();
}
@Override
public String getEventType() {
return EventTypes.EVENT_EXTERNAL_LB_DEVICE_DELETE;
}
@Override
public String getEventDescription() {
return "Deleting Nicira Nvp Controller";
}
}

View File

@ -43,7 +43,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
@Implementation(responseObject=NiciraNvpDeviceResponse.class, description="Lists Nicira NVP devices")
public class ListNiciraNvpDevicesCmd extends BaseListCmd {
private static final Logger s_logger = Logger.getLogger(ListNiciraNvpDevicesCmd.class.getName());
private static final String s_name = "listniciranvpdevices";
private static final String s_name = "listniciranvpdeviceresponse";
@PlugService NiciraNvpElementService _niciraNvpElementService;
/////////////////////////////////////////////////////

View File

@ -33,7 +33,16 @@ public class NiciraNvpDeviceResponse extends BaseResponse {
@SerializedName(ApiConstants.NICIRA_NVP_DEVICE_NAME) @Param(description="device name")
private String deviceName;
@SerializedName(ApiConstants.HOST_NAME) @Param(description="the controller Ip address")
private String hostName;
@SerializedName(ApiConstants.NICIRA_NVP_TRANSPORT_ZONE_UUID) @Param(description="the transport zone Uuid")
private String transportZoneUuid;
@SerializedName(ApiConstants.NICIRA_NVP_GATEWAYSERVICE_UUID) @Param(description="this L3 gateway service Uuid")
private String l3GatewayServiceUuid;
public void setId(long nvpDeviceId) {
this.id.setValue(nvpDeviceId);
}
@ -48,6 +57,26 @@ public class NiciraNvpDeviceResponse extends BaseResponse {
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
}
public void setId(IdentityProxy id) {
this.id = id;
}
public void setPhysicalNetworkId(IdentityProxy physicalNetworkId) {
this.physicalNetworkId = physicalNetworkId;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
public void setTransportZoneUuid(String transportZoneUuid) {
this.transportZoneUuid = transportZoneUuid;
}
public void setL3GatewayServiceUuid(String l3GatewayServiceUuid) {
this.l3GatewayServiceUuid = l3GatewayServiceUuid;
}
}

View File

@ -657,11 +657,18 @@ public class NiciraNvpElement extends AdapterBase implements
@Override
public NiciraNvpDeviceResponse createNiciraNvpDeviceResponse(
NiciraNvpDeviceVO niciraNvpDeviceVO) {
HostVO niciraNvpHost = _hostDao.findById(niciraNvpDeviceVO.getHostId());
_hostDao.loadDetails(niciraNvpHost);
NiciraNvpDeviceResponse response = new NiciraNvpDeviceResponse();
response.setDeviceName(niciraNvpDeviceVO.getDeviceName());
response.setPhysicalNetworkId(niciraNvpDeviceVO.getPhysicalNetworkId());
response.setId(niciraNvpDeviceVO.getId());
response.setProviderName(niciraNvpDeviceVO.getProviderName());
response.setHostName(niciraNvpHost.getDetail("ip"));
response.setTransportZoneUuid(niciraNvpHost.getDetail("transportzoneuuid"));
response.setL3GatewayServiceUuid(niciraNvpHost.getDetail("l3gatewayserviceuuid"));
response.setObjectName("niciranvpdevice");
return response;
}
@ -705,7 +712,6 @@ public class NiciraNvpElement extends AdapterBase implements
_resourceMgr.deleteHost(hostId, false, false);
_niciraNvpDao.remove(niciraDeviceId);
return true;
}

View File

@ -229,7 +229,8 @@ public class NiciraNvpResource implements ServerResource {
}
else if (cmd instanceof ConfigurePortForwardingRulesOnLogicalRouterCommand) {
return executeRequest((ConfigurePortForwardingRulesOnLogicalRouterCommand) cmd, numRetries);
} s_logger.debug("Received unsupported command " + cmd.toString());
}
s_logger.debug("Received unsupported command " + cmd.toString());
return Answer.createUnsupportedCommandAnswer(cmd);
}

View File

@ -3761,7 +3761,213 @@
name: { label: 'label.name' }//,
//state: { label: 'label.status' } //comment it for now, since dataProvider below doesn't get called by widget code after action is done
}
}
},
// Nicira Nvp provider detail view
niciraNvp: {
type: 'detailView',
id: 'niciraNvpProvider',
label: 'label.niciraNvp',
viewAll: { label: 'label.devices', path: '_zone.niciraNvpDevices' },
tabs: {
details: {
title: 'label.details',
fields: [
{
name: { label: 'label.name' }
},
{
state: { label: 'label.state' }
}
],
dataProvider: function(args) {
refreshNspData("NiciraNvp");
var providerObj;
$(nspHardcodingArray).each(function(){
if(this.id == "niciraNvp") {
providerObj = this;
return false; //break each loop
}
});
args.response.success({
data: providerObj,
actionFilter: networkProviderActionFilter('niciraNvp')
});
}
}
},
actions: {
add: {
label: 'label.add.NiciraNvp.device',
createForm: {
title: 'label.add.NiciraNvp.device',
preFilter: function(args) { }, // TODO What is this?
fields: {
host: {
label: 'label.ip.address'
},
username: {
label: 'label.username'
},
password: {
label: 'label.password',
isPassword: true
},
numretries: {
label: 'label.numretries',
defaultValue: '2'
},
transportzoneuuid: {
label: 'label.nicira.transportzoneuuid'
},
l3gatewayserviceuuid: {
label: 'label.nicira.l3gatewayserviceuuid'
}
}
},
action: function(args) {
if(nspMap["niciraNvp"] == null) {
$.ajax({
url: createURL("addNetworkServiceProvider&name=NiciraNvp&physicalnetworkid=" + selectedPhysicalNetworkObj.id),
dataType: "json",
async: true,
success: function(json) {
var jobId = json.addnetworkserviceproviderresponse.jobid;
var addNiciraNvpProviderIntervalID = setInterval(function() {
$.ajax({
url: createURL("queryAsyncJobResult&jobId="+jobId),
dataType: "json",
success: function(json) {
var result = json.queryasyncjobresultresponse;
if (result.jobstatus == 0) {
return; //Job has not completed
}
else {
clearInterval(addNiciraNvpProviderIntervalID);
if (result.jobstatus == 1) {
nspMap["niciraNvp"] = json.queryasyncjobresultresponse.jobresult.networkserviceprovider;
addNiciraNvpDevice(args, selectedPhysicalNetworkObj, "addNiciraNvpDevice", "addniciranvpdeviceresponse", "niciranvpdevice")
}
else if (result.jobstatus == 2) {
alert("addNetworkServiceProvider&name=NiciraNvp failed. Error: " + _s(result.jobresult.errortext));
}
}
},
error: function(XMLHttpResponse) {
var errorMsg = parseXMLHttpResponse(XMLHttpResponse);
alert("addNetworkServiceProvider&name=NiciraNvp failed. Error: " + errorMsg);
}
});
}, 3000);
}
});
}
else {
addNiciraNvpDevice(args, selectedPhysicalNetworkObj, "addNiciraNvpDevice", "addniciranvpdeviceresponse", "niciranvpdevice")
}
},
messages: {
notification: function(args) {
return 'label.add.NiciraNvp.device';
}
},
notification: {
poll: pollAsyncJobResult
}
},
enable: {
label: 'label.enable.provider',
action: function(args) {
$.ajax({
url: createURL("updateNetworkServiceProvider&id=" + nspMap["niciraNvp"].id + "&state=Enabled"),
dataType: "json",
success: function(json) {
var jid = json.updatenetworkserviceproviderresponse.jobid;
args.response.success(
{_custom:
{
jobId: jid,
getUpdatedItem: function(json) {
$(window).trigger('cloudStack.fullRefresh');
}
}
}
);
}
});
},
messages: {
confirm: function(args) {
return 'message.confirm.enable.provider';
},
notification: function() {
return 'label.enable.provider';
}
},
notification: { poll: pollAsyncJobResult }
},
disable: {
label: 'label.disable.provider',
action: function(args) {
$.ajax({
url: createURL("updateNetworkServiceProvider&id=" + nspMap["niciraNvp"].id + "&state=Disabled"),
dataType: "json",
success: function(json) {
var jid = json.updatenetworkserviceproviderresponse.jobid;
args.response.success(
{_custom:
{
jobId: jid,
getUpdatedItem: function(json) {
$(window).trigger('cloudStack.fullRefresh');
}
}
}
);
}
});
},
messages: {
confirm: function(args) {
return 'message.confirm.disable.provider';
},
notification: function() {
return 'label.disable.provider';
}
},
notification: { poll: pollAsyncJobResult }
},
destroy: {
label: 'label.shutdown.provider',
action: function(args) {
$.ajax({
url: createURL("deleteNetworkServiceProvider&id=" + nspMap["niciraNvp"].id),
dataType: "json",
success: function(json) {
var jid = json.deletenetworkserviceproviderresponse.jobid;
args.response.success(
{_custom:
{
jobId: jid
}
}
);
$(window).trigger('cloudStack.fullRefresh');
}
});
},
messages: {
confirm: function(args) {
return 'message.confirm.shutdown.provider';
},
notification: function(args) {
return 'label.shutdown.provider';
}
},
notification: { poll: pollAsyncJobResult }
}
}
}
}
}
},
@ -6312,7 +6518,171 @@
}
}
},
// FIXME convert to nicira detailview
// NiciraNvp devices listView
niciraNvpDevices: {
id: 'niciraNvpDevices',
title: 'label.devices',
listView: {
id: 'niciraNvpDevices',
fields: {
hostname: { label: 'label.nicira.controller.address' },
transportzoneuuid: { label: 'label.nicira.transportzoneuuid'},
l3gatewayserviceuuid: { label: 'label.nicira.l3gatewayserviceuuid' }
},
actions: {
add: {
label: 'label.add.NiciraNvp.device',
createForm: {
title: 'label.add.NiciraNvp.device',
preFilter: function(args) { }, // TODO What is this?
fields: {
host: {
label: 'label.ip.address'
},
username: {
label: 'label.username'
},
password: {
label: 'label.password',
isPassword: true
},
numretries: {
label: 'label.numretries',
defaultValue: '2'
},
transportzoneuuid: {
label: 'label.nicira.transportzoneuuid'
},
l3gatewayserviceuuid: {
label: 'label.nicira.l3gatewayserviceuuid'
}
}
},
action: function(args) {
if(nspMap["niciraNvp"] == null) {
$.ajax({
url: createURL("addNetworkServiceProvider&name=NiciraNvp&physicalnetworkid=" + selectedPhysicalNetworkObj.id),
dataType: "json",
async: true,
success: function(json) {
var jobId = json.addnetworkserviceproviderresponse.jobid;
var addNiciraNvpProviderIntervalID = setInterval(function() {
$.ajax({
url: createURL("queryAsyncJobResult&jobId="+jobId),
dataType: "json",
success: function(json) {
var result = json.queryasyncjobresultresponse;
if (result.jobstatus == 0) {
return; // Job has not completed
}
else {
clearInterval(addNiciraNvpProviderIntervalID);
if (result.jobstatus == 1) {
nspMap["niciraNvp"] = json.queryasyncjobresultresponse.jobresult.networkserviceprovider;
addNiciraNvpDevice(args, selectedPhysicalNetworkObj, "addNiciraNvpDevice", "addniciranvpdeviceresponse", "niciranvpdevice")
}
else if (result.jobstatus == 2) {
alert("addNetworkServiceProvider&name=NiciraNvp failed. Error: " + _s(result.jobresult.errortext));
}
}
},
error: function(XMLHttpResponse) {
var errorMsg = parseXMLHttpResponse(XMLHttpResponse);
alert("addNetworkServiceProvider&name=NiciraNvp failed. Error: " + errorMsg);
}
});
}, 3000);
}
});
}
else {
addNiciraNvpDevice(args, selectedPhysicalNetworkObj, "addNiciraNvpDevice", "addniciranvpdeviceresponse", "niciranvpdevice")
}
},
messages: {
notification: function(args) {
return 'Added new Nicira Nvp Controller';
}
},
notification: {
poll: pollAsyncJobResult
}
}
},
dataProvider: function(args) {
$.ajax({
url: createURL("listNiciraNvpDevices&physicalnetworkid=" + selectedPhysicalNetworkObj.id),
data: { page: args.page, pageSize: pageSize },
dataType: "json",
async: false,
success: function(json) {
var items = json.listniciranvpdeviceresponse.niciranvpdevice;
args.response.success({data: items});
}
});
},
detailView: {
name: 'Nicira Nvp details',
actions: {
'remove': {
label: 'label.delete.NiciaNvp',
messages: {
confirm: function(args) {
return 'message.confirm.delete.NiciraNvp';
},
notification: function(args) {
return 'label.delete.NiciraNvp';
}
},
action: function(args) {
$.ajax({
url: createURL("deleteNiciraNvpDevice&nvpdeviceid=" + args.context.niciraNvpDevices[0].nvpdeviceid),
dataType: "json",
async: true,
success: function(json) {
var jid = json.deleteniciranvpdeviceresponse.jobid;
args.response.success(
{_custom:
{jobId: jid}
}
);
}
});
},
notification: {
poll: pollAsyncJobResult
}
}
},
tabs: {
details: {
title: 'label.details',
fields: [
{
nvpdeviceid: { label: 'label.id' },
hostname: { label: 'label.ip.address' },
transportzoneuuid: { label: 'label.nicira.transportzoneuuid' },
l3gatewayserviceuuid: { label: 'label.nicira.l3gatewayserviceuuid' }
}
],
dataProvider: function(args) {
$.ajax({
url: createURL("listNiciraNvpDevices&nvpdeviceid=" + args.context.niciraNvpDevices[0].nvpdeviceid),
dataType: "json",
async: true,
success: function(json) {
var item = json.listniciranvpdeviceresponse.niciranvpdevice[0];
args.response.success({data: item});
}
});
}
}
}
}
}
},
pods: {
title: 'label.pods',
listView: {
@ -9327,6 +9697,40 @@
});
}
function addNiciraNvpDevice(args, physicalNetworkObj, apiCmd, apiCmdRes, apiCmdObj) {
var array1 = [];
array1.push("&physicalnetworkid=" + physicalNetworkObj.id);
array1.push("&username=" + todb(args.data.username));
array1.push("&password=" + todb(args.data.password));
array1.push("&hostname=" + todb(args.data.host));
array1.push("&transportzoneuuid=" + todb(args.data.transportzoneuuid));
var l3GatewayServiceUuid = args.data.l3gatewayserviceuuid;
if(l3GatewayServiceUuid != null && l3GatewayServiceUuid.length > 0) {
array1.push("&l3gatewayserviceuuid=" + todb(args.data.l3gatewayserviceuuid));
}
$.ajax({
url: createURL(apiCmd + array1.join("")),
dataType: "json",
success: function(json) {
var jid = json[apiCmdRes].jobid;
args.response.success(
{_custom:
{jobId: jid,
getUpdatedItem: function(json) {
var item = json.queryasyncjobresultresponse.jobresult[apiCmdObj];
return item;
}
}
}
);
}
});
}
var afterCreateZonePhysicalNetworkTrafficTypes = function(args, newZoneObj, newPhysicalnetwork) {
$.ajax({
url: createURL("updatePhysicalNetwork&state=Enabled&id=" + newPhysicalnetwork.id),
@ -9924,6 +10328,9 @@
case "SecurityGroupProvider":
nspMap["securityGroups"] = items[i];
break;
case "NiciraNvp":
nspMap["niciraNvp"] = items[i];
break;
}
}
}
@ -9940,7 +10347,12 @@
id: 'virtualRouter',
name: 'Virtual Router',
state: nspMap.virtualRouter ? nspMap.virtualRouter.state : 'Disabled'
}
},
{
id: 'niciraNvp',
name: 'Nicira Nvp',
state: nspMap.niciraNvp ? nspMap.niciraNvp.state : 'Disabled'
}
];
if(selectedZoneObj.networktype == "Basic") {