mirror of https://github.com/apache/cloudstack.git
add support for adding and listing nsx provider to a zone
This commit is contained in:
parent
2c0f51e071
commit
2b0ddc6f76
|
|
@ -8,4 +8,7 @@ public interface NsxProvider extends InternalIdentity, Identity {
|
|||
String getProviderName();
|
||||
String getUsername();
|
||||
long getZoneId();
|
||||
|
||||
String getTier0Gateway();
|
||||
String getEdgeCluster();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import org.apache.cloudstack.api.ServerApiException;
|
|||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.response.NsxControllerResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.service.NsxProviderService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -17,7 +18,8 @@ import javax.inject.Inject;
|
|||
|
||||
|
||||
@APICommand(name = AddNsxControllerCmd.APINAME, description = "Add NSX Controller to CloudStack",
|
||||
responseObject = NsxControllerResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||
responseObject = NsxControllerResponse.class, requestHasSensitiveInfo = false,
|
||||
responseHasSensitiveInfo = false, since = "4.19.0.0")
|
||||
public class AddNsxControllerCmd extends BaseCmd {
|
||||
public static final String APINAME = "addNsxController";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(AddNsxControllerCmd.class.getName());
|
||||
|
|
@ -94,6 +96,6 @@ public class AddNsxControllerCmd extends BaseCmd {
|
|||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return 0;
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package org.apache.cloudstack.api.command;
|
||||
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.utils.StringUtils;
|
||||
import org.apache.cloudstack.api.*;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.NsxControllerResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.service.NsxProviderService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.cloudstack.api.command.ListNsxControllersCmd.APINAME;
|
||||
|
||||
@APICommand(name = APINAME, description = "list all NSX controllers added to CloudStack",
|
||||
responseObject = NsxControllerResponse.class, requestHasSensitiveInfo = false,
|
||||
responseHasSensitiveInfo = false, since = "4.19.0.0")
|
||||
public class ListNsxControllersCmd extends BaseListCmd {
|
||||
public static final String APINAME = "listNsxControllers";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(ListNsxControllersCmd.class.getName());
|
||||
|
||||
@Inject
|
||||
private NsxProviderService nsxProviderService;
|
||||
|
||||
@Parameter(name = ApiConstants.ZONE_ID, description = "NSX controller added to the specific zone",
|
||||
type = CommandType.UUID, entityType = ZoneResponse.class)
|
||||
Long zoneId;
|
||||
|
||||
@Override
|
||||
public void execute() throws ServerApiException, ConcurrentOperationException {
|
||||
List<BaseResponse> baseResponseList = nsxProviderService.listNsxProviders(zoneId);
|
||||
List<BaseResponse> pagingList = StringUtils.applyPagination(baseResponseList, this.getStartIndex(), this.getPageSizeVal());
|
||||
ListResponse<BaseResponse> listResponse = new ListResponse<>();
|
||||
listResponse.setResponses(pagingList);
|
||||
listResponse.setResponseName(getCommandName());
|
||||
setResponseObject(listResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,87 @@
|
|||
package org.apache.cloudstack.api.response;
|
||||
|
||||
import com.cloud.network.NsxProvider;
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseResponse;
|
||||
import org.apache.cloudstack.api.EntityReference;
|
||||
|
||||
@EntityReference(value = {NsxProvider.class})
|
||||
public class NsxControllerResponse extends BaseResponse {
|
||||
@SerializedName(ApiConstants.NAME)
|
||||
@Param(description = "NSX controller name")
|
||||
private String name;
|
||||
|
||||
@SerializedName(ApiConstants.ZONE_ID)
|
||||
@Param(description = "Zone ID to which the NSX controller is associated with")
|
||||
private long zoneId;
|
||||
|
||||
@SerializedName(ApiConstants.ZONE_NAME)
|
||||
@Param(description = "Zone name to which the NSX controller is associated with")
|
||||
private String zoneName;
|
||||
|
||||
@SerializedName(ApiConstants.HOST_NAME)
|
||||
@Param(description = "NSX controller hostname or IP address")
|
||||
private String hostname;
|
||||
|
||||
// TODO: Should Password be returned?
|
||||
|
||||
@SerializedName(ApiConstants.TIER0_GATEWAY)
|
||||
@Param(description = "The tier-0 gateway network. Tier-0 gateway is responsible for handling" +
|
||||
" traffic between logical and physical networks"
|
||||
)
|
||||
private String tier0Gateway;
|
||||
|
||||
@SerializedName(ApiConstants.EDGE_CLUSTER)
|
||||
@Param(description = "The name of the edge cluster. An edge cluster is a logical grouping of edge nodes in NSX")
|
||||
private String edgeCluster;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
public void setZoneId(long zoneId) {
|
||||
this.zoneId = zoneId;
|
||||
}
|
||||
|
||||
public String getZoneName() {
|
||||
return zoneName;
|
||||
}
|
||||
|
||||
public void setZoneName(String zoneName) {
|
||||
this.zoneName = zoneName;
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public void setHostname(String hostname) {
|
||||
this.hostname = hostname;
|
||||
}
|
||||
|
||||
public String getTier0Gateway() {
|
||||
return tier0Gateway;
|
||||
}
|
||||
|
||||
public void setTier0Gateway(String tier0Gateway) {
|
||||
this.tier0Gateway = tier0Gateway;
|
||||
}
|
||||
|
||||
public String getEdgeCluster() {
|
||||
return edgeCluster;
|
||||
}
|
||||
|
||||
public void setEdgeCluster(String edgeCluster) {
|
||||
this.edgeCluster = edgeCluster;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,5 +13,5 @@ public interface NsxProviderService extends PluggableService {
|
|||
|
||||
NsxControllerResponse createNsxControllerResponse(NsxProvider tungstenProvider);
|
||||
|
||||
List<BaseResponse> listTungstenProvider(Long zoneId);
|
||||
List<BaseResponse> listNsxProviders(Long zoneId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,29 @@
|
|||
package org.apache.cloudstack.service;
|
||||
|
||||
import com.cloud.host.DetailVO;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.network.NsxProvider;
|
||||
import com.cloud.network.dao.NsxProviderDao;
|
||||
import com.cloud.network.element.NsxProviderVO;
|
||||
import com.cloud.network.element.TungstenProviderVO;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.TransactionCallback;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import org.apache.cloudstack.api.command.ListNsxControllersCmd;
|
||||
import org.apache.cloudstack.api.BaseResponse;
|
||||
import org.apache.cloudstack.api.command.AddNsxControllerCmd;
|
||||
import org.apache.cloudstack.api.response.NsxControllerResponse;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class NsxProviderServiceImpl implements NsxProviderService {
|
||||
|
||||
@Inject
|
||||
NsxProviderDao nsxProviderDao;
|
||||
@Inject
|
||||
DataCenterDao dataCenterDao;
|
||||
|
||||
@Override
|
||||
public NsxProvider addProvider(AddNsxControllerCmd cmd) {
|
||||
|
|
@ -28,24 +32,48 @@ public class NsxProviderServiceImpl implements NsxProviderService {
|
|||
cmd.getUsername(), cmd.getPassword(),
|
||||
cmd.getTier0Gateway(), cmd.getEdgeCluster());
|
||||
nsxProviderDao.persist(nsxProviderVO);
|
||||
|
||||
return nsxProviderVO;
|
||||
});
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NsxControllerResponse createNsxControllerResponse(NsxProvider tungstenProvider) {
|
||||
return null;
|
||||
public NsxControllerResponse createNsxControllerResponse(NsxProvider nsxProvider) {
|
||||
DataCenterVO zone = dataCenterDao.findById(nsxProvider.getZoneId());
|
||||
if (Objects.isNull(zone)) {
|
||||
throw new CloudRuntimeException(String.format("Failed to find zone with id %s", nsxProvider.getZoneId()));
|
||||
}
|
||||
NsxControllerResponse response = new NsxControllerResponse();
|
||||
response.setName(nsxProvider.getProviderName());
|
||||
response.setHostname(nsxProvider.getHostname());
|
||||
response.setZoneId(nsxProvider.getZoneId());
|
||||
response.setZoneName(zone.getName());
|
||||
response.setTier0Gateway(nsxProvider.getTier0Gateway());
|
||||
response.setTier0Gateway(nsxProvider.getEdgeCluster());
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BaseResponse> listTungstenProvider(Long zoneId) {
|
||||
return null;
|
||||
public List<BaseResponse> listNsxProviders(Long zoneId) {
|
||||
List<BaseResponse> nsxControllersResponseList = new ArrayList<>();
|
||||
if (zoneId != null) {
|
||||
NsxProviderVO nsxProviderVO = nsxProviderDao.findByZoneId(zoneId);
|
||||
nsxControllersResponseList.add(createNsxControllerResponse(nsxProviderVO));
|
||||
} else {
|
||||
List<NsxProviderVO> nsxProviderVOList = nsxProviderDao.listAll();
|
||||
for (NsxProviderVO nsxProviderVO : nsxProviderVOList) {
|
||||
nsxControllersResponseList.add(createNsxControllerResponse(nsxProviderVO));
|
||||
}
|
||||
}
|
||||
|
||||
return nsxControllersResponseList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<?>> getCommands() {
|
||||
return null;
|
||||
List<Class<?>> cmdList = new ArrayList<Class<?>>();
|
||||
cmdList.add(AddNsxControllerCmd.class);
|
||||
cmdList.add(ListNsxControllersCmd.class);
|
||||
return cmdList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue