You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by sa...@apache.org on 2013/07/10 17:59:01 UTC
git commit: updated refs/heads/master-6-17-stable to 3e378ac
Updated Branches:
refs/heads/master-6-17-stable 527080e8e -> 3e378acf1
CLOUDSTACK-3450 To implement toggle action of add/remove VMware DC, listVmwareDcs API call is required.
listVmwareDcs API is added. Takes 1 parameter (mandatory) which is zoneId.
Returns list of VMware DCs associated with specified zone.
Signed-off-by: Sateesh Chodapuneedi <sa...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3e378acf
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3e378acf
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3e378acf
Branch: refs/heads/master-6-17-stable
Commit: 3e378acf11cbd923f1e7a8271c582e5f0aa10b6e
Parents: 527080e
Author: Sateesh Chodapuneedi <sa...@apache.org>
Authored: Wed Jul 10 21:27:23 2013 +0530
Committer: Sateesh Chodapuneedi <sa...@apache.org>
Committed: Wed Jul 10 21:27:23 2013 +0530
----------------------------------------------------------------------
.../vmware/VmwareDatacenterService.java | 6 +
.../vmware/manager/VmwareManagerImpl.java | 51 ++++++--
.../command/admin/zone/ListVmwareDcsCmd.java | 118 +++++++++++++++++++
.../api/response/VmwareDatacenterResponse.java | 27 ++++-
4 files changed, 191 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3e378acf/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java
index 5e80e18..d74c123 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java
@@ -17,16 +17,22 @@
package com.cloud.hypervisor.vmware;
+import java.util.List;
+
import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;
+import org.apache.cloudstack.api.command.admin.zone.ListVmwareDcsCmd;
import org.apache.cloudstack.api.command.admin.zone.RemoveVmwareDcCmd;
import com.cloud.exception.DiscoveryException;
import com.cloud.exception.ResourceInUseException;
import com.cloud.utils.component.PluggableService;
+import com.cloud.utils.exception.CloudRuntimeException;
public interface VmwareDatacenterService extends PluggableService {
public VmwareDatacenterVO addVmwareDatacenter(AddVmwareDcCmd cmd) throws IllegalArgumentException, DiscoveryException, ResourceInUseException;
public boolean removeVmwareDatacenter(RemoveVmwareDcCmd cmd) throws IllegalArgumentException, ResourceInUseException;
+
+ public List<? extends VmwareDatacenter> listVmwareDatacenters(ListVmwareDcsCmd cmd) throws IllegalArgumentException, CloudRuntimeException;
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3e378acf/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
index 17fad32..4c57a6c 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
@@ -36,9 +36,16 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
+import org.apache.log4j.Logger;
+
+import com.google.gson.Gson;
+import com.vmware.vim25.AboutInfo;
+import com.vmware.vim25.HostConnectSpec;
+import com.vmware.vim25.ManagedObjectReference;
+
import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;
+import org.apache.cloudstack.api.command.admin.zone.ListVmwareDcsCmd;
import org.apache.cloudstack.api.command.admin.zone.RemoveVmwareDcCmd;
-import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
import com.cloud.agent.Listener;
@@ -69,6 +76,7 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
import com.cloud.hypervisor.vmware.LegacyZoneVO;
import com.cloud.hypervisor.vmware.VmwareCleanupMaid;
+import com.cloud.hypervisor.vmware.VmwareDatacenter;
import com.cloud.hypervisor.vmware.VmwareDatacenterService;
import com.cloud.hypervisor.vmware.VmwareDatacenterVO;
import com.cloud.hypervisor.vmware.VmwareDatacenterZoneMapVO;
@@ -110,10 +118,6 @@ import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
import com.cloud.utils.ssh.SshHelper;
import com.cloud.vm.DomainRouterVO;
-import com.google.gson.Gson;
-import com.vmware.vim25.AboutInfo;
-import com.vmware.vim25.HostConnectSpec;
-import com.vmware.vim25.ManagedObjectReference;
@Local(value = {VmwareManager.class, VmwareDatacenterService.class})
@@ -470,8 +474,8 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
@Override
public String getManagementPortGroupByHost(HostMO hostMo) throws Exception {
if(hostMo.getHostType() == VmwareHostType.ESXi)
- return this._managemetPortGroupName;
- return this._serviceConsoleName;
+ return _managemetPortGroupName;
+ return _serviceConsoleName;
}
@Override
@@ -553,7 +557,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
@Override
public String getSystemVMDefaultNicAdapterType() {
- return this._defaultSystemVmNicAdapterType;
+ return _defaultSystemVmNicAdapterType;
}
private File getSystemVMPatchIsoFile() {
@@ -856,7 +860,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
@Override
public int getRouterExtraPublicNics() {
- return this._routerExtraPublicNics;
+ return _routerExtraPublicNics;
}
@Override
@@ -897,6 +901,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
List<Class<?>> cmdList = new ArrayList<Class<?>>();
cmdList.add(AddVmwareDcCmd.class);
cmdList.add(RemoveVmwareDcCmd.class);
+ cmdList.add(ListVmwareDcsCmd.class);
return cmdList;
}
@@ -1126,7 +1131,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
return true;
}
- private void validateZone(Long zoneId) throws ResourceInUseException {
+ private void validateZone(Long zoneId) throws InvalidParameterValueException {
// Check if zone with specified id exists
DataCenterVO zone = _dcDao.findById(zoneId);
if (zone == null) {
@@ -1159,4 +1164,30 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
}
return isLegacyZone;
}
+
+ @Override
+ public List<? extends VmwareDatacenter> listVmwareDatacenters(ListVmwareDcsCmd cmd) throws CloudRuntimeException, InvalidParameterValueException {
+ Long zoneId = cmd.getZoneId();
+ List<VmwareDatacenterVO> vmwareDcList = new ArrayList<VmwareDatacenterVO>();
+ VmwareDatacenterZoneMapVO vmwareDcZoneMap;
+ VmwareDatacenterVO vmwareDatacenter;
+ long vmwareDcId;
+
+ // Validate if zone id parameter passed to API is valid
+ validateZone(zoneId);
+
+ // Check if zone is associated with VMware DC
+ vmwareDcZoneMap = _vmwareDcZoneMapDao.findByZoneId(zoneId);
+ if (vmwareDcZoneMap == null) {
+ return null;
+ }
+ // Retrieve details of VMware DC associated with zone.
+ vmwareDcId = vmwareDcZoneMap.getVmwareDcId();
+ vmwareDatacenter = _vmwareDcDao.findById(vmwareDcId);
+ vmwareDcList.add(vmwareDatacenter);
+
+ // Currently a zone can have only 1 VMware DC associated with.
+ // Returning list of VmwareDatacenterVO objects, in-line with future requirements, if any, like participation of multiple VMware DCs in a zone.
+ return vmwareDcList;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3e378acf/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcsCmd.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcsCmd.java b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcsCmd.java
new file mode 100644
index 0000000..6096233
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcsCmd.java
@@ -0,0 +1,118 @@
+// 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.admin.zone;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.VmwareDatacenterResponse;
+import org.apache.cloudstack.api.response.ZoneResponse;
+
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.hypervisor.vmware.VmwareDatacenter;
+import com.cloud.hypervisor.vmware.VmwareDatacenterService;
+import com.cloud.user.Account;
+
+@APICommand(name = "listVmwareDcs", responseObject = VmwareDatacenterResponse.class, description = "Retrieves VMware DC(s) associated with a zone.")
+public class ListVmwareDcsCmd extends BaseListCmd {
+
+ @Inject public VmwareDatacenterService _vmwareDatacenterService;
+
+ public static final Logger s_logger = Logger.getLogger(AddVmwareDcCmd.class.getName());
+
+ private static final String s_name = "listvmwaredcsresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class,
+ required = true, description="Id of the CloudStack zone.")
+ private Long zoneId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getZoneId() {
+ return zoneId;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
+ List<? extends VmwareDatacenter> vmwareDcList = null;
+
+ try {
+ vmwareDcList = _vmwareDatacenterService.listVmwareDatacenters(this);
+ } catch (InvalidParameterValueException ie) {
+ throw new InvalidParameterValueException("Invalid zone id " + getZoneId());
+ } catch (Exception e) {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to find associated VMware DCs associated with zone " + getZoneId());
+ }
+
+ ListResponse<VmwareDatacenterResponse> response = new ListResponse<VmwareDatacenterResponse>();
+ List<VmwareDatacenterResponse> vmwareDcResponses = new ArrayList<VmwareDatacenterResponse>();
+
+ if (vmwareDcList != null && vmwareDcList.size() > 0) {
+ for (VmwareDatacenter vmwareDc : vmwareDcList) {
+ VmwareDatacenterResponse vmwareDcResponse = new VmwareDatacenterResponse();
+
+ vmwareDcResponse.setId(vmwareDc.getUuid());
+ vmwareDcResponse.setVcenter(vmwareDc.getVcenterHost());
+ vmwareDcResponse.setName(vmwareDc.getVmwareDatacenterName());
+ vmwareDcResponse.setZoneId(getZoneId());
+ vmwareDcResponse.setObjectName("VMwareDC");
+
+ vmwareDcResponses.add(vmwareDcResponse);
+ }
+ }
+ response.setResponses(vmwareDcResponses);
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+ }
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3e378acf/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/response/VmwareDatacenterResponse.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/response/VmwareDatacenterResponse.java b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/response/VmwareDatacenterResponse.java
index 420320b..3c1ed99 100644
--- a/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/response/VmwareDatacenterResponse.java
+++ b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/response/VmwareDatacenterResponse.java
@@ -17,34 +17,59 @@
package org.apache.cloudstack.api.response;
+import com.google.gson.annotations.SerializedName;
+
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.EntityReference;
import com.cloud.hypervisor.vmware.VmwareDatacenter;
import com.cloud.serializer.Param;
-import com.google.gson.annotations.SerializedName;
@EntityReference(value = VmwareDatacenter.class)
public class VmwareDatacenterResponse extends BaseResponse {
@SerializedName(ApiConstants.ID) @Param(description="The VMware Datacenter ID")
private String id;
+ @SerializedName(ApiConstants.ZONE_ID)
+ @Param(description = "the Zone ID associated with this VMware Datacenter")
+ private Long zoneId;
+
@SerializedName(ApiConstants.NAME) @Param(description="The VMware Datacenter name")
private String name;
+ @SerializedName(ApiConstants.VCENTER)
+ @Param(description = "The VMware vCenter name/ip")
+ private String vCenter;
+
public String getName() {
return name;
}
+ public String getVcenter() {
+ return vCenter;
+ }
+
public String getId() {
return id;
}
+ public Long getZoneId() {
+ return zoneId;
+ }
+
+ public void setZoneId(Long zoneId) {
+ this.zoneId = zoneId;
+ }
+
public void setName(String name) {
this.name = name;
}
+ public void setVcenter(String vCenter) {
+ this.vCenter = vCenter;
+ }
+
public void setId(String id) {
this.id = id;
}