cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sate...@apache.org
Subject git commit: updated refs/heads/4.2 to 50b8d64
Date Wed, 10 Jul 2013 17:41:20 GMT
Updated Branches:
  refs/heads/4.2 ea04729fd -> 50b8d6429


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 <sateesh@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/50b8d642
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/50b8d642
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/50b8d642

Branch: refs/heads/4.2
Commit: 50b8d6429939972e3f00229831880b466acaf4bd
Parents: ea04729
Author: Sateesh Chodapuneedi <sateesh@apache.org>
Authored: Wed Jul 10 23:04:32 2013 +0530
Committer: Sateesh Chodapuneedi <sateesh@apache.org>
Committed: Wed Jul 10 23:07:47 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/50b8d642/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/50b8d642/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 7b8697d..c872e93 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
@@ -38,9 +38,16 @@ import javax.naming.ConfigurationException;
 
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
+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;
@@ -71,6 +78,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;
@@ -113,10 +121,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})
@@ -475,8 +479,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
@@ -558,7 +562,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager,
Vmw
 
     @Override
     public String getSystemVMDefaultNicAdapterType() {
-        return this._defaultSystemVmNicAdapterType;
+        return _defaultSystemVmNicAdapterType;
     }
 
     private File getSystemVMPatchIsoFile() {
@@ -861,7 +865,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager,
Vmw
 
     @Override
     public int getRouterExtraPublicNics() {
-        return this._routerExtraPublicNics;
+        return _routerExtraPublicNics;
     }
 
     @Override
@@ -902,6 +906,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;
     }
 
@@ -1131,7 +1136,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) {
@@ -1164,4 +1169,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/50b8d642/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..15c23fa
--- /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/50b8d642/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;
     }


Mime
View raw message