mirror of https://github.com/apache/cloudstack.git
add delete nsx controller operation
This commit is contained in:
parent
96d17bade3
commit
bc8504952b
|
|
@ -810,6 +810,7 @@ public class ApiConstants {
|
|||
public static final String NICIRA_NVP_L2_GATEWAYSERVICE_UUID = "l2gatewayserviceuuid";
|
||||
public static final String NSX_LOGICAL_SWITCH = "nsxlogicalswitch";
|
||||
public static final String NSX_LOGICAL_SWITCH_PORT = "nsxlogicalswitchport";
|
||||
public static final String NSX_CONTROLLER_ID = "nsxcontrollerid";
|
||||
public static final String S3_ACCESS_KEY = "accesskey";
|
||||
public static final String S3_SECRET_KEY = "secretkey";
|
||||
public static final String S3_END_POINT = "endpoint";
|
||||
|
|
|
|||
|
|
@ -18,11 +18,34 @@ package com.cloud.network.dao;
|
|||
|
||||
import com.cloud.network.element.NsxProviderVO;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NsxProviderDaoImpl extends GenericDaoBase<NsxProviderVO, Long>
|
||||
implements NsxProviderDao {
|
||||
|
||||
final SearchBuilder<NsxProviderVO> allFieldsSearch;
|
||||
public NsxProviderDaoImpl() {
|
||||
super();
|
||||
allFieldsSearch = createSearchBuilder();
|
||||
allFieldsSearch.and("id", allFieldsSearch.entity().getId(),
|
||||
SearchCriteria.Op.EQ);
|
||||
allFieldsSearch.and("uuid", allFieldsSearch.entity().getUuid(),
|
||||
SearchCriteria.Op.EQ);
|
||||
allFieldsSearch.and("hostname", allFieldsSearch.entity().getHostname(),
|
||||
SearchCriteria.Op.EQ);
|
||||
allFieldsSearch.and("provider_name", allFieldsSearch.entity().getProviderName(),
|
||||
SearchCriteria.Op.EQ);
|
||||
allFieldsSearch.and("tier0_gateway", allFieldsSearch.entity().getTier0Gateway(),
|
||||
SearchCriteria.Op.EQ);
|
||||
allFieldsSearch.and("zone_id", allFieldsSearch.entity().getZoneId(),
|
||||
SearchCriteria.Op.EQ);
|
||||
allFieldsSearch.and("edge_cluster", allFieldsSearch.entity().getEdgeCluster(),
|
||||
SearchCriteria.Op.EQ);
|
||||
allFieldsSearch.done();
|
||||
}
|
||||
@Override
|
||||
public NsxProviderVO findByZoneId(long zoneId) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -136,6 +136,7 @@
|
|||
<bean id="nicIpAliasDaoImpl" class="com.cloud.vm.dao.NicIpAliasDaoImpl" />
|
||||
<bean id="objectInDataStoreDaoImpl" class="org.apache.cloudstack.storage.db.ObjectInDataStoreDaoImpl" />
|
||||
<bean id="ovsProviderDaoImpl" class="com.cloud.network.dao.OvsProviderDaoImpl" />
|
||||
<bean id="nsxProviderDao" class="com.cloud.network.dao.NsxProviderDaoImpl" />
|
||||
<bean id="tungstenControllerDaoImpl" class="com.cloud.network.dao.TungstenProviderDaoImpl"/>
|
||||
<bean id="physicalNetworkDaoImpl" class="com.cloud.network.dao.PhysicalNetworkDaoImpl" />
|
||||
<bean id="physicalNetworkIsolationMethodDaoImpl" class="com.cloud.network.dao.PhysicalNetworkIsolationMethodDaoImpl" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,87 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command;
|
||||
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
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.SuccessResponse;
|
||||
import org.apache.cloudstack.service.NsxProviderService;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.apache.cloudstack.api.command.DeleteNsxControllerCmd.APINAME;
|
||||
|
||||
@APICommand(name = APINAME, description = "Add NSX Controller to CloudStack",
|
||||
responseObject = NsxControllerResponse.class, requestHasSensitiveInfo = false,
|
||||
responseHasSensitiveInfo = false, since = "4.19.0.0")
|
||||
public class DeleteNsxControllerCmd extends BaseCmd {
|
||||
public static final String APINAME = "deleteNsxController";
|
||||
|
||||
@Inject
|
||||
protected NsxProviderService nsxProviderService;
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name = ApiConstants.NSX_CONTROLLER_ID, type = CommandType.UUID, entityType = NsxControllerResponse.class,
|
||||
required = true, description = "NSX Controller ID")
|
||||
private Long nsxControllerId;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public Long getNsxControllerId() {
|
||||
return nsxControllerId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@Override
|
||||
public void execute() throws ServerApiException, ConcurrentOperationException {
|
||||
try {
|
||||
boolean deleted = nsxProviderService.deleteNsxController(getNsxControllerId());
|
||||
if (deleted) {
|
||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove NSX Controller from Zone");
|
||||
}
|
||||
} catch (InvalidParameterValueException e) {
|
||||
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
|
||||
} catch (CloudRuntimeException e) {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -27,7 +27,9 @@ import java.util.List;
|
|||
public interface NsxProviderService extends PluggableService {
|
||||
NsxProvider addProvider(AddNsxControllerCmd cmd);
|
||||
|
||||
NsxControllerResponse createNsxControllerResponse(NsxProvider tungstenProvider);
|
||||
NsxControllerResponse createNsxControllerResponse(NsxProvider nsxProvider);
|
||||
|
||||
List<BaseResponse> listNsxProviders(Long zoneId);
|
||||
|
||||
boolean deleteNsxController(Long nsxControllerId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,10 +16,18 @@
|
|||
// under the License.
|
||||
package org.apache.cloudstack.service;
|
||||
|
||||
import com.amazonaws.util.CollectionUtils;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Networks;
|
||||
import com.cloud.network.NsxProvider;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.dao.NsxProviderDao;
|
||||
import com.cloud.network.dao.PhysicalNetworkDao;
|
||||
import com.cloud.network.dao.PhysicalNetworkVO;
|
||||
import com.cloud.network.dao.NetworkVO;
|
||||
import com.cloud.network.element.NsxProviderVO;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.TransactionCallback;
|
||||
|
|
@ -40,6 +48,10 @@ public class NsxProviderServiceImpl implements NsxProviderService {
|
|||
NsxProviderDao nsxProviderDao;
|
||||
@Inject
|
||||
DataCenterDao dataCenterDao;
|
||||
@Inject
|
||||
PhysicalNetworkDao physicalNetworkDao;
|
||||
@Inject
|
||||
NetworkDao networkDao;
|
||||
|
||||
@Override
|
||||
public NsxProvider addProvider(AddNsxControllerCmd cmd) {
|
||||
|
|
@ -85,6 +97,32 @@ public class NsxProviderServiceImpl implements NsxProviderService {
|
|||
return nsxControllersResponseList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteNsxController(Long nsxControllerId) {
|
||||
NsxProviderVO nsxProvider = nsxProviderDao.findById(nsxControllerId);
|
||||
if (Objects.isNull(nsxProvider)) {
|
||||
throw new InvalidParameterValueException(String.format("Failed to find NSX controller with id: %s", nsxControllerId));
|
||||
}
|
||||
Long zoneId = nsxProvider.getZoneId();
|
||||
// Find the physical network we work for
|
||||
List<PhysicalNetworkVO> physicalNetworks = physicalNetworkDao.listByZone(zoneId);
|
||||
for (PhysicalNetworkVO physicalNetwork : physicalNetworks) {
|
||||
List<NetworkVO> networkList = networkDao.listByPhysicalNetwork(physicalNetwork.getId());
|
||||
if (!CollectionUtils.isNullOrEmpty(networkList)) {
|
||||
// Networks with broadcast type vcs are ours
|
||||
for (NetworkVO network : networkList) {
|
||||
if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.NSX) {
|
||||
if ((network.getState() != Network.State.Shutdown) && (network.getState() != Network.State.Destroy)) {
|
||||
throw new CloudRuntimeException("This NSX Controller cannot be deleted as there are one or more logical networks provisioned by CloudStack on it.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nsxProviderDao.remove(nsxControllerId);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<?>> getCommands() {
|
||||
List<Class<?>> cmdList = new ArrayList<Class<?>>();
|
||||
|
|
|
|||
|
|
@ -31,5 +31,6 @@
|
|||
<bean id="NsxGuestNetworkGuru" class="org.apache.cloudstack.service.NsxGuestNetworkGuru">
|
||||
<property name="name" value="NsxGuestNetworkGuru" />
|
||||
</bean>
|
||||
<bean id="nsxProviderService" class="org.apache.cloudstack.service.NsxProviderServiceImpl"/>
|
||||
|
||||
</beans>
|
||||
|
|
|
|||
|
|
@ -135,6 +135,7 @@ known_categories = {
|
|||
'listTungstenFabricLBHealthMonitor': 'Tungsten',
|
||||
'listNsxControllers': 'NSX',
|
||||
'addNsxController': 'NSX',
|
||||
'deleteNsxController': 'NSX',
|
||||
'Vpn': 'VPN',
|
||||
'Limit': 'Limit',
|
||||
'ResourceCount': 'Limit',
|
||||
|
|
|
|||
Loading…
Reference in New Issue