diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java index 3a1d58a66a6..2e8c8ae0234 100755 --- a/api/src/com/cloud/event/EventTypes.java +++ b/api/src/com/cloud/event/EventTypes.java @@ -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"; diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/database/BaremetalRctVO.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/database/BaremetalRctVO.java index 91cbc9fe12b..3a24cf4554d 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/database/BaremetalRctVO.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/database/BaremetalRctVO.java @@ -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") diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManager.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManager.java index b2a1be950a5..76f10526cbc 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManager.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManager.java @@ -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(); } diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java index c8473b691f6..a77cf35c60e 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java @@ -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 backends; + private Map backends; private class RackPair { BaremetalRct.Rack rack; BaremetalRct.HostEntry host; } - public void setBackends(Map backends) { - this.backends = backends; - } - + public void setBackends(Map backends) { + this.backends = backends; + } + @Override public BaremetalRctResponse addRct(AddBaremetalRctCmd cmd) { try { + List 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 vos = rctDao.listAll(); @@ -218,6 +228,7 @@ public class BaremetalVlanManagerImpl extends ManagerBase implements BaremetalVl List> cmds = new ArrayList>(); cmds.add(AddBaremetalRctCmd.class); cmds.add(ListBaremetalRctCmd.class); + cmds.add(DeleteBaremetalRctCmd.class); return cmds; } diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalRctResponse.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalRctResponse.java index cf85f1943de..d1577aa257c 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalRctResponse.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalRctResponse.java @@ -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") diff --git a/plugins/hypervisors/baremetal/src/org/apache/cloudstack/api/DeleteBaremetalRctCmd.java b/plugins/hypervisors/baremetal/src/org/apache/cloudstack/api/DeleteBaremetalRctCmd.java new file mode 100755 index 00000000000..f1c84231e76 --- /dev/null +++ b/plugins/hypervisors/baremetal/src/org/apache/cloudstack/api/DeleteBaremetalRctCmd.java @@ -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; + } +}