Skip to content

Commit 64419b1

Browse files
author
Sateesh Chodapuneedi
committed
CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
Introduced 2 new API command classes AddVmwareDcCmd & RemoveVmwareDcCmd. The new APIs are addVmwareDc & removeVmwareDc, these APIs will associate a Vmware datacenter to a cloudstack zone & dis-associate a Vmware datacenter from a cloudstack zone. Constraint checks are added for infrastructure change operations in zone that encompass resources like clusters. Constraint checks are added in discoverer and manager classes. Added a service 'VmwareDatacenterService' to expose methods that will have API implementation for 2 APIs addVmwareDc & removeVmwareDc Signed-off-by: Sateesh Chodapuneedi <sateesh@apache.org>
1 parent 47e355c commit 64419b1

6 files changed

Lines changed: 662 additions & 4 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package com.cloud.hypervisor.vmware;
19+
20+
import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;
21+
import org.apache.cloudstack.api.command.admin.zone.RemoveVmwareDcCmd;
22+
23+
import com.cloud.exception.DiscoveryException;
24+
import com.cloud.exception.ResourceInUseException;
25+
import com.cloud.utils.component.PluggableService;
26+
27+
public interface VmwareDatacenterService extends PluggableService {
28+
29+
public VmwareDatacenterVO addVmwareDatacenter(AddVmwareDcCmd cmd) throws IllegalArgumentException, DiscoveryException, ResourceInUseException;
30+
31+
public boolean removeVmwareDatacenter(RemoveVmwareDcCmd cmd) throws IllegalArgumentException, ResourceInUseException;
32+
}

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java‎

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import org.apache.log4j.Logger;
3232
import org.apache.cloudstack.api.ApiConstants;
33+
import org.springframework.beans.NullValueInNestedPathException;
3334

3435
import com.cloud.agent.api.StartupCommand;
3536
import com.cloud.agent.api.StartupRoutingCommand;
@@ -51,6 +52,8 @@
5152
import com.cloud.hypervisor.Hypervisor;
5253
import com.cloud.hypervisor.Hypervisor.HypervisorType;
5354
import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
55+
import com.cloud.hypervisor.vmware.dao.VmwareDatacenterDao;
56+
import com.cloud.hypervisor.vmware.dao.VmwareDatacenterZoneMapDao;
5457
import com.cloud.hypervisor.vmware.manager.VmwareManager;
5558
import com.cloud.hypervisor.vmware.mo.ClusterMO;
5659
import com.cloud.hypervisor.vmware.mo.HostMO;
@@ -107,11 +110,16 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
107110
@Inject
108111
CiscoNexusVSMDeviceDao _nexusDao;
109112
@Inject
110-
CiscoNexusVSMElementService _nexusElement;
113+
CiscoNexusVSMElement _nexusElement;
111114
@Inject
112115
NetworkModel _netmgr;
113116
@Inject
114117
HypervisorCapabilitiesDao _hvCapabilitiesDao;
118+
@Inject
119+
VmwareDatacenterZoneMapDao _vmwareDcZoneMapDao;
120+
@Inject
121+
VmwareDatacenterDao _vmwareDcDao;
122+
115123
protected Map<String, String> _urlParams;
116124
protected boolean useDVS = false;
117125
protected boolean nexusDVS = false;
@@ -140,6 +148,18 @@ public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long p
140148
return null;
141149
}
142150

151+
Map<String, String> clusterDetails = _clusterDetailsDao.findDetails(clusterId);
152+
boolean legacyZone = false;
153+
//Check if NOT a legacy zone.
154+
if (!legacyZone) {
155+
String updatedInventoryPath = validateCluster(dcId, url, username, password);
156+
if (url.getPath() != updatedInventoryPath) {
157+
// If url from API doesn't specifiy DC then update url in database with DC assocaited with this zone.
158+
clusterDetails.put("url", url.getScheme() + "://" + url.getHost() + updatedInventoryPath);
159+
_clusterDetailsDao.persist(clusterId, clusterDetails);
160+
}
161+
}
162+
143163
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId);
144164
if (hosts != null && hosts.size() > 0) {
145165
int maxHostsPerCluster = _hvCapabilitiesDao.getMaxHostsPerCluster(hosts.get(0).getHypervisorType(), hosts.get(0).getHypervisorVersion());
@@ -164,7 +184,6 @@ public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long p
164184

165185
VmwareTrafficLabel guestTrafficLabelObj = new VmwareTrafficLabel(TrafficType.Guest);
166186
VmwareTrafficLabel publicTrafficLabelObj = new VmwareTrafficLabel(TrafficType.Public);
167-
Map<String, String> clusterDetails = _clusterDetailsDao.findDetails(clusterId);
168187
DataCenterVO zone = _dcDao.findById(dcId);
169188
NetworkType zoneType = zone.getNetworkType();
170189
_readGlobalConfigParameters();
@@ -395,6 +414,63 @@ public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long p
395414
}
396415
}
397416

417+
private String validateCluster(Long dcId, URI url, String username, String password) throws DiscoveryException {
418+
String msg;
419+
long vmwareDcId;
420+
VmwareDatacenterVO vmwareDc;
421+
String vmwareDcNameFromDb;
422+
String vmwareDcNameFromApi;
423+
String vCenterHost;
424+
String updatedInventoryPath = url.getPath();
425+
String clusterName = null;
426+
427+
// Check if zone is associated with DC
428+
VmwareDatacenterZoneMapVO vmwareDcZone = _vmwareDcZoneMapDao.findByZoneId(dcId);
429+
if (vmwareDcZone == null) {
430+
msg = "Zone " + dcId + " is not associated with any VMware DC yet. "
431+
+ "Please add VMware DC to this zone first and then try to add clusters.";
432+
s_logger.error(msg);
433+
throw new DiscoveryException(msg);
434+
}
435+
436+
// Retrieve DC added to this zone from database
437+
vmwareDcId = vmwareDcZone.getVmwareDcId();
438+
vmwareDc = _vmwareDcDao.findById(vmwareDcId);
439+
vmwareDcNameFromApi = vmwareDcNameFromDb = vmwareDc.getVmwareDatacenterName();
440+
vCenterHost = vmwareDc.getVcenterHost();
441+
String inventoryPath = url.getPath();
442+
443+
assert (inventoryPath != null);
444+
445+
String[] pathTokens = inventoryPath.split("/");
446+
if (pathTokens.length == 2) {
447+
// DC name is not present in url.
448+
// Using DC name read from database.
449+
clusterName = pathTokens[1];
450+
updatedInventoryPath = "/" + vmwareDcNameFromDb + "/" + clusterName;
451+
} else if (pathTokens.length == 3) {
452+
vmwareDcNameFromApi = pathTokens[1];
453+
clusterName = pathTokens[2];
454+
}
455+
456+
if (!vCenterHost.equalsIgnoreCase(url.getHost())) {
457+
msg = "This cluster " + clusterName + " belongs to vCenter " + url.getHost()
458+
+ " .But this zone is associated with VMware DC from vCenter " + vCenterHost
459+
+ ". Make sure the cluster being added belongs to vCenter " + vCenterHost
460+
+ " and DC " + vmwareDcNameFromDb;
461+
s_logger.error(msg);
462+
throw new DiscoveryException(msg);
463+
} else if (!vmwareDcNameFromDb.equalsIgnoreCase(vmwareDcNameFromApi)) {
464+
msg = "This cluster " + clusterName + " belongs to VMware DC " + vmwareDcNameFromApi
465+
+ " .But this zone is associated with VMware DC " + vmwareDcNameFromDb
466+
+ ". Make sure the cluster being added belongs to DC " + vmwareDcNameFromDb
467+
+ " in vCenter " + vCenterHost;
468+
s_logger.error(msg);
469+
throw new DiscoveryException(msg);
470+
}
471+
return updatedInventoryPath;
472+
}
473+
398474
private boolean validateDiscoveredHosts(VmwareContext context,
399475
ManagedObjectReference morCluster,
400476
List<ManagedObjectReference> morHosts) throws Exception {

0 commit comments

Comments
 (0)