mirror of https://github.com/apache/cloudstack.git
Update netris VPC and tier name
This commit is contained in:
parent
af27e88c82
commit
8572d6a776
|
|
@ -55,4 +55,6 @@ public interface VpcProvider extends NetworkElement {
|
|||
boolean applyACLItemsToPrivateGw(PrivateGateway gateway, List<? extends NetworkACLItem> rules) throws ResourceUnavailableException;
|
||||
|
||||
boolean updateVpcSourceNatIp(Vpc vpc, IpAddress address);
|
||||
|
||||
boolean updateVpc(Vpc vpc, String previousVpcName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ public interface NetrisService {
|
|||
|
||||
boolean createVpcResource(long zoneId, long accountId, long domainId, Long vpcId, String vpcName, boolean sourceNatEnabled, String cidr, boolean isVpcNetwork);
|
||||
|
||||
boolean updateVpcResource(long zoneId, long accountId, long domainId, Long vpcId, String vpcName, String previousVpcName);
|
||||
|
||||
boolean deleteVpcResource(long zoneId, long accountId, long domainId, Vpc vpc);
|
||||
|
||||
boolean createVnetResource(Long zoneId, long accountId, long domainId, String vpcName, Long vpcId, String networkName, Long networkId, String cidr, Boolean globalRouting);
|
||||
|
|
|
|||
|
|
@ -201,4 +201,9 @@ public class ContrailVpcElementImpl extends ContrailElementImpl implements Netwo
|
|||
public boolean updateVpcSourceNatIp(Vpc vpc, IpAddress address) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateVpc(Vpc vpc, String previousVpcName) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package org.apache.cloudstack.agent.api;
|
||||
|
||||
public class UpdateNetrisVnetCommand extends NetrisCommand{
|
||||
private String prevNetworkName;
|
||||
|
||||
public UpdateNetrisVnetCommand(long zoneId, Long accountId, Long domainId, String name, Long id, boolean isVpc) {
|
||||
super(zoneId, accountId, domainId, name, id, isVpc);
|
||||
}
|
||||
|
||||
public String getPrevNetworkName() {
|
||||
return prevNetworkName;
|
||||
}
|
||||
|
||||
public void setPrevNetworkName(String prevNetworkName) {
|
||||
this.prevNetworkName = prevNetworkName;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
// 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.agent.api;
|
||||
|
||||
public class UpdateNetrisVpcCommand extends NetrisCommand {
|
||||
private String previousVpcName;
|
||||
public UpdateNetrisVpcCommand(long zoneId, Long accountId, Long domainId, String name, Long id, boolean isVpc) {
|
||||
super(zoneId, accountId, domainId, name, id, isVpc);
|
||||
}
|
||||
|
||||
public String getPreviousVpcName() {
|
||||
return previousVpcName;
|
||||
}
|
||||
|
||||
public void setPreviousVpcName(String previousVpcName) {
|
||||
this.previousVpcName = previousVpcName;
|
||||
}
|
||||
}
|
||||
|
|
@ -44,6 +44,7 @@ import org.apache.cloudstack.agent.api.NetrisAnswer;
|
|||
import org.apache.cloudstack.StartupNetrisCommand;
|
||||
import org.apache.cloudstack.agent.api.ReleaseNatIpCommand;
|
||||
import org.apache.cloudstack.agent.api.SetupNetrisPublicRangeCommand;
|
||||
import org.apache.cloudstack.agent.api.UpdateNetrisVpcCommand;
|
||||
import org.apache.cloudstack.service.NetrisApiClient;
|
||||
import org.apache.cloudstack.service.NetrisApiClientImpl;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
|
@ -98,6 +99,8 @@ public class NetrisResource implements ServerResource {
|
|||
return executeRequest((CheckHealthCommand) cmd);
|
||||
} else if (cmd instanceof CreateNetrisVpcCommand) {
|
||||
return executeRequest((CreateNetrisVpcCommand) cmd);
|
||||
} else if (cmd instanceof UpdateNetrisVpcCommand) {
|
||||
return executeRequest((UpdateNetrisVpcCommand) cmd);
|
||||
} else if (cmd instanceof DeleteNetrisVpcCommand) {
|
||||
return executeRequest((DeleteNetrisVpcCommand) cmd);
|
||||
} else if (cmd instanceof CreateNetrisVnetCommand) {
|
||||
|
|
@ -242,6 +245,20 @@ public class NetrisResource implements ServerResource {
|
|||
}
|
||||
}
|
||||
|
||||
private Answer executeRequest(UpdateNetrisVpcCommand cmd) {
|
||||
try {
|
||||
boolean result = netrisApiClient.updateVpc(cmd);
|
||||
if (!result) {
|
||||
return new NetrisAnswer(cmd, false, String.format("Netris VPC %s creation failed", cmd.getName()));
|
||||
}
|
||||
return new NetrisAnswer(cmd, true, "OK");
|
||||
} catch (CloudRuntimeException e) {
|
||||
String msg = String.format("Error creating Netris VPC: %s", e.getMessage());
|
||||
logger.error(msg, e);
|
||||
return new NetrisAnswer(cmd, new CloudRuntimeException(msg));
|
||||
}
|
||||
}
|
||||
|
||||
private Answer executeRequest(CreateNetrisVnetCommand cmd) {
|
||||
try {
|
||||
String vpcName = cmd.getVpcName();
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import org.apache.cloudstack.agent.api.DeleteNetrisVnetCommand;
|
|||
import org.apache.cloudstack.agent.api.DeleteNetrisVpcCommand;
|
||||
import org.apache.cloudstack.agent.api.ReleaseNatIpCommand;
|
||||
import org.apache.cloudstack.agent.api.SetupNetrisPublicRangeCommand;
|
||||
import org.apache.cloudstack.agent.api.UpdateNetrisVpcCommand;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -50,6 +51,8 @@ public interface NetrisApiClient {
|
|||
*/
|
||||
boolean createVpc(CreateNetrisVpcCommand cmd);
|
||||
|
||||
boolean updateVpc(UpdateNetrisVpcCommand cmd);
|
||||
|
||||
/**
|
||||
* Delete a VPC on CloudStack removes the following Netris resources:
|
||||
* - Delete the IPAM Allocation for the VPC using the Prefix = VPC CIDR
|
||||
|
|
|
|||
|
|
@ -98,6 +98,8 @@ import io.netris.model.VnetResAddBody;
|
|||
import io.netris.model.VnetResDeleteBody;
|
||||
import io.netris.model.VnetResListBody;
|
||||
import io.netris.model.VnetsBody;
|
||||
import io.netris.model.VpcEditResponseOK;
|
||||
import io.netris.model.VpcVpcIdBody;
|
||||
import io.netris.model.response.AuthResponse;
|
||||
import io.netris.model.response.L4LbEditResponse;
|
||||
import io.netris.model.response.TenantResponse;
|
||||
|
|
@ -117,6 +119,7 @@ import org.apache.cloudstack.agent.api.DeleteNetrisVpcCommand;
|
|||
import org.apache.cloudstack.agent.api.NetrisCommand;
|
||||
import org.apache.cloudstack.agent.api.ReleaseNatIpCommand;
|
||||
import org.apache.cloudstack.agent.api.SetupNetrisPublicRangeCommand;
|
||||
import org.apache.cloudstack.agent.api.UpdateNetrisVpcCommand;
|
||||
import org.apache.cloudstack.resource.NetrisResourceObjectUtils;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
|
@ -257,6 +260,30 @@ public class NetrisApiClientImpl implements NetrisApiClient {
|
|||
return response;
|
||||
}
|
||||
|
||||
private VpcEditResponseOK updateVpcInternal(String vpcName, String prevVpcName, int adminTenantId, String adminTenantName) {
|
||||
VpcEditResponseOK response;
|
||||
logger.debug(String.format("Updating Netris VPC name from %s to %s", prevVpcName, vpcName));
|
||||
try {
|
||||
VPCListing vpcResource = getVpcByNameAndTenant(prevVpcName);
|
||||
if (vpcResource == null) {
|
||||
logger.error("Could not find the Netris VPC resource with name {} and tenant ID {}", prevVpcName, tenantId);
|
||||
return null;
|
||||
}
|
||||
VpcApi vpcApi = apiClient.getApiStubForMethod(VpcApi.class);
|
||||
VpcVpcIdBody body = new VpcVpcIdBody();
|
||||
body.setName(vpcName);
|
||||
VPCAdminTenant vpcAdminTenant = new VPCAdminTenant();
|
||||
vpcAdminTenant.setId(adminTenantId);
|
||||
vpcAdminTenant.name(adminTenantName);
|
||||
body.setAdminTenant(vpcAdminTenant);
|
||||
response = vpcApi.apiV2VpcVpcIdPut(body, vpcResource.getId());
|
||||
} catch (ApiException e) {
|
||||
logAndThrowException("Error updating Netris VPC", e);
|
||||
return null;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
private InlineResponse2004Data createIpamAllocationInternal(String ipamName, String ipamPrefix, VPCListing vpc) {
|
||||
logger.debug(String.format("Creating Netris IPAM Allocation %s for VPC %s", ipamPrefix, vpc.getName()));
|
||||
try {
|
||||
|
|
@ -302,6 +329,24 @@ public class NetrisApiClientImpl implements NetrisApiClient {
|
|||
return createdIpamAllocation != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateVpc(UpdateNetrisVpcCommand cmd) {
|
||||
Long domainId = cmd.getDomainId();
|
||||
Long zoneId = cmd.getZoneId();
|
||||
Long accountId = cmd.getAccountId();
|
||||
Long vpcId = cmd.getId();
|
||||
String prevVpcName = cmd.getPreviousVpcName();
|
||||
String netrisVpcName = NetrisResourceObjectUtils.retrieveNetrisResourceObjectName(cmd, NetrisResourceObjectUtils.NetrisObjectType.VPC);
|
||||
String netrisPrevVpcName = String.format("D%s-A%s-Z%s-V%s-%s", domainId, accountId, zoneId, vpcId, prevVpcName);
|
||||
VpcEditResponseOK updatedVpc = updateVpcInternal(netrisVpcName, netrisPrevVpcName, tenantId, tenantName);
|
||||
if (updatedVpc == null || !updatedVpc.isIsSuccess()) {
|
||||
String reason = updatedVpc == null ? "Empty response" : "Operation failed on Netris";
|
||||
logger.debug("The update of Netris VPC {} failed: {}", cmd.getPreviousVpcName(), reason);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteNatRule(DeleteNetrisNatRuleCommand cmd) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -466,6 +466,11 @@ public class NetrisElement extends AdapterBase implements DhcpServiceProvider, D
|
|||
return netrisService.updateVpcSourceNatIp(vpc, address);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateVpc(Vpc vpc, String previousVpcName) {
|
||||
return netrisService.updateVpcResource(vpc.getZoneId(), vpc.getAccountId(), vpc.getDomainId(), vpc.getId(), vpc.getName(), previousVpcName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyNetworkACLs(Network network, List<? extends NetworkACLItem> rules) throws ResourceUnavailableException {
|
||||
if (!canHandle(network, Network.Service.NetworkACL)) {
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ import org.apache.cloudstack.agent.api.NetrisAnswer;
|
|||
import org.apache.cloudstack.agent.api.NetrisCommand;
|
||||
import org.apache.cloudstack.agent.api.ReleaseNatIpCommand;
|
||||
import org.apache.cloudstack.agent.api.SetupNetrisPublicRangeCommand;
|
||||
import org.apache.cloudstack.agent.api.UpdateNetrisVpcCommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
import org.apache.cloudstack.framework.config.Configurable;
|
||||
|
|
@ -198,6 +199,14 @@ public class NetrisServiceImpl implements NetrisService, Configurable {
|
|||
return answer.getResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateVpcResource(long zoneId, long accountId, long domainId, Long vpcId, String vpcName, String previousVpcName) {
|
||||
UpdateNetrisVpcCommand cmd = new UpdateNetrisVpcCommand(zoneId, accountId, domainId, vpcName, vpcId, true);
|
||||
cmd.setPreviousVpcName(previousVpcName);
|
||||
NetrisAnswer answer = sendNetrisCommand(cmd, zoneId);
|
||||
return answer.getResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteVpcResource(long zoneId, long accountId, long domainId, Vpc vpc) {
|
||||
DeleteNetrisVpcCommand cmd = new DeleteNetrisVpcCommand(zoneId, accountId, domainId, vpc.getName(), vpc.getCidr(), vpc.getId(), true);
|
||||
|
|
|
|||
|
|
@ -945,4 +945,9 @@ public class NsxElement extends AdapterBase implements DhcpServiceProvider, Dns
|
|||
public boolean updateVpcSourceNatIp(Vpc vpc, IpAddress address) {
|
||||
return nsxService.updateVpcSourceNatIp(vpc, address);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateVpc(Vpc vpc, String previousVpcName) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -732,4 +732,9 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
|
|||
public boolean updateVpcSourceNatIp(Vpc vpc, IpAddress address) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateVpc(Vpc vpc, String previousVpcName) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1582,6 +1582,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
|||
_accountMgr.checkAccess(caller, null, false, vpcToUpdate);
|
||||
|
||||
final VpcVO vpc = vpcDao.createForUpdate(vpcId);
|
||||
String previousVpcName = vpcToUpdate.getName();
|
||||
|
||||
if (vpcName != null) {
|
||||
vpc.setName(vpcName);
|
||||
|
|
@ -1617,6 +1618,16 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
|||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("no restart needed.");
|
||||
if (isVpcForProvider(Provider.Netris, vpcToUpdate)) {
|
||||
final String sourceNatProvider = _vpcSrvcDao.getProviderForServiceInVpc(vpc.getId(), Service.SourceNat);
|
||||
for (final VpcProvider provider : getVpcElements()) {
|
||||
if ((provider instanceof StaticNatServiceProvider && provider.getName().equalsIgnoreCase(sourceNatProvider))) {
|
||||
vpcToUpdate.setName(vpcName);
|
||||
provider.updateVpc(vpcToUpdate, previousVpcName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vpcDao.findById(vpcId);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,11 @@ public class NetrisServiceMockTest implements NetrisService {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateVpcResource(long zoneId, long accountId, long domainId, Long vpcId, String vpcName, String previousVpcName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteVpcResource(long zoneId, long accountId, long domainId, Vpc vpc) {
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue