mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
CLOUDSTACK-7795
Fix multiple baremetal rct configuraitons
This commit is contained in:
parent
95b9be0cb6
commit
2ae40237a4
@ -454,6 +454,7 @@ public class EventTypes {
|
||||
public static final String EVENT_BAREMETAL_PXE_SERVER_ADD = "PHYSICAL.PXE.ADD";
|
||||
public static final String EVENT_BAREMETAL_PXE_SERVER_DELETE = "PHYSICAL.PXE.DELETE";
|
||||
public static final String EVENT_BAREMETAL_RCT_ADD = "BAREMETAL.RCT.ADD";
|
||||
public static final String EVENT_BAREMETAL_RCT_DELETE = "BAREMETAL.RCT.DELETE";
|
||||
public static final String EVENT_BAREMETAL_PROVISION_DONE = "BAREMETAL.PROVISION.DONE";
|
||||
|
||||
public static final String EVENT_AFFINITY_GROUP_CREATE = "AG.CREATE";
|
||||
|
||||
@ -17,6 +17,9 @@
|
||||
//
|
||||
package com.cloud.baremetal.database;
|
||||
|
||||
import org.apache.cloudstack.api.Identity;
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
@ -30,7 +33,7 @@ import java.util.UUID;
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "baremetal_rct")
|
||||
public class BaremetalRctVO {
|
||||
public class BaremetalRctVO implements InternalIdentity, Identity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
|
||||
@ -18,13 +18,14 @@
|
||||
package com.cloud.baremetal.manager;
|
||||
|
||||
import com.cloud.baremetal.networkservice.BaremetalRctResponse;
|
||||
import com.cloud.baremetal.networkservice.BaremetalSwitchBackend;
|
||||
import com.cloud.baremetal.networkservice.BaremetalSwitchBackend;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.utils.component.PluggableService;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import org.apache.cloudstack.api.AddBaremetalRctCmd;
|
||||
import org.apache.cloudstack.api.DeleteBaremetalRctCmd;
|
||||
|
||||
/**
|
||||
* Created by frank on 4/30/14.
|
||||
@ -40,5 +41,7 @@ public interface BaremetalVlanManager extends Manager, PluggableService {
|
||||
|
||||
void registerSwitchBackend(BaremetalSwitchBackend backend);
|
||||
|
||||
void deleteRct(DeleteBaremetalRctCmd cmd);
|
||||
|
||||
BaremetalRctResponse listRct();
|
||||
}
|
||||
|
||||
@ -40,6 +40,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.cloudstack.api.AddBaremetalRctCmd;
|
||||
import org.apache.cloudstack.api.DeleteBaremetalRctCmd;
|
||||
import org.apache.cloudstack.api.ListBaremetalRctCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
@ -69,20 +70,24 @@ public class BaremetalVlanManagerImpl extends ManagerBase implements BaremetalVl
|
||||
@Inject
|
||||
private AccountManager acntMgr;
|
||||
|
||||
private Map<String, BaremetalSwitchBackend> backends;
|
||||
private Map<String, BaremetalSwitchBackend> backends;
|
||||
|
||||
private class RackPair {
|
||||
BaremetalRct.Rack rack;
|
||||
BaremetalRct.HostEntry host;
|
||||
}
|
||||
|
||||
public void setBackends(Map<String, BaremetalSwitchBackend> backends) {
|
||||
this.backends = backends;
|
||||
}
|
||||
|
||||
public void setBackends(Map<String, BaremetalSwitchBackend> backends) {
|
||||
this.backends = backends;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaremetalRctResponse addRct(AddBaremetalRctCmd cmd) {
|
||||
try {
|
||||
List<BaremetalRctVO> existings = rctDao.listAll();
|
||||
if (!existings.isEmpty()) {
|
||||
throw new CloudRuntimeException(String.format("there is some RCT existing. A CloudStack deployment accepts only one RCT"));
|
||||
}
|
||||
URL url = new URL(cmd.getRctUrl());
|
||||
RestTemplate rest = new RestTemplate();
|
||||
String rctStr = rest.getForObject(url.toString(), String.class);
|
||||
@ -171,6 +176,11 @@ public class BaremetalVlanManagerImpl extends ManagerBase implements BaremetalVl
|
||||
backends.put(backend.getSwitchBackendType(), backend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRct(DeleteBaremetalRctCmd cmd) {
|
||||
rctDao.remove(cmd.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaremetalRctResponse listRct() {
|
||||
List<BaremetalRctVO> vos = rctDao.listAll();
|
||||
@ -218,6 +228,7 @@ public class BaremetalVlanManagerImpl extends ManagerBase implements BaremetalVl
|
||||
List<Class<?>> cmds = new ArrayList<Class<?>>();
|
||||
cmds.add(AddBaremetalRctCmd.class);
|
||||
cmds.add(ListBaremetalRctCmd.class);
|
||||
cmds.add(DeleteBaremetalRctCmd.class);
|
||||
return cmds;
|
||||
}
|
||||
|
||||
|
||||
@ -17,14 +17,17 @@
|
||||
//
|
||||
package com.cloud.baremetal.networkservice;
|
||||
|
||||
import com.cloud.baremetal.database.BaremetalRctVO;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Created by frank on 5/8/14.
|
||||
*/
|
||||
@EntityReference(value = BaremetalRctVO.class)
|
||||
public class BaremetalRctResponse extends BaseResponse {
|
||||
@SerializedName(ApiConstants.ID)
|
||||
@Param(description = "id of rct")
|
||||
|
||||
@ -0,0 +1,85 @@
|
||||
// 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;
|
||||
|
||||
import com.cloud.baremetal.manager.BaremetalVlanManager;
|
||||
import com.cloud.baremetal.networkservice.BaremetalRctResponse;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.NetworkRuleConflictException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.api.response.SuccessResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Created by frank on 10/27/14.
|
||||
*/
|
||||
@APICommand(name = "deleteBaremetalRct", description = "deletes baremetal rack configuration text", responseObject = SuccessResponse.class,
|
||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin})
|
||||
public class DeleteBaremetalRctCmd extends BaseAsyncCmd {
|
||||
private static final String s_name = "deletebaremetalrctresponse";
|
||||
public static final Logger s_logger = Logger.getLogger(DeleteBaremetalRctCmd.class);
|
||||
|
||||
@Parameter(name = ApiConstants.ID, type = BaseCmd.CommandType.UUID, description = "RCT id", required = true, entityType = BaremetalRctResponse.class)
|
||||
private Long id;
|
||||
|
||||
@Inject
|
||||
private BaremetalVlanManager vlanMgr;
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_BAREMETAL_RCT_DELETE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "Deleting baremetal rct configuration";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
|
||||
try {
|
||||
vlanMgr.deleteRct(this);
|
||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||
setResponseObject(response);
|
||||
} catch (Exception e) {
|
||||
s_logger.warn(String.format("unable to add baremetal RCT[%s]", getId()), e);
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user