Skip to content

Commit 1ba362d

Browse files
committed
Merge pull request #806 from sureshanaparti/CLOUDSTACK-8820
CLOUDSTACK-8820: Support for VMware vCenter 6 data centerCLOUDSTACK-8820: Showing error when try to add advance zone using VMware ESXi 6.0 host Summary: In vCenter 6.0, response headers need to be fetched after service login for server cookie unlike previous versions of vCenter. * pr/806: CLOUDSTACK-8820: Updated the code for vCenter6 data center support. CLOUDSTACK-8820: Showing error when try to add advance zone using VMWare ESXi 6.0 host Summary: In vCenter 6.0, response headers need to be fetched after service login for server cookie unlike previous versions of vCenter. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2 parents 8f11b45 + 1d73418 commit 1ba362d

File tree

1 file changed

+56
-32
lines changed

1 file changed

+56
-32
lines changed

vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareClient.java

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,27 @@ public void connect(String url, String userName, String password) throws Excepti
152152
@SuppressWarnings("unchecked")
153153
Map<String, List<String>> headers = (Map<String, List<String>>)((BindingProvider)vimPort).getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
154154
List<String> cookies = headers.get("Set-cookie");
155+
156+
vimPort.login(serviceContent.getSessionManager(), userName, password, null);
157+
158+
if (cookies == null) {
159+
// Get the cookie from the response header. See vmware sample program com.vmware.httpfileaccess.GetVMFiles
160+
@SuppressWarnings("unchecked")
161+
Map<String, List<String>> responseHeaders = (Map<String, List<String>>)((BindingProvider)vimPort).getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
162+
cookies = responseHeaders.get("Set-cookie");
163+
if (cookies == null) {
164+
String msg = "Login successful, but failed to get server cookies from url :[" + url + "]";
165+
s_logger.error(msg);
166+
throw new Exception(msg);
167+
}
168+
}
169+
155170
String cookieValue = cookies.get(0);
156171
StringTokenizer tokenizer = new StringTokenizer(cookieValue, ";");
157172
cookieValue = tokenizer.nextToken();
158173
String pathData = "$" + tokenizer.nextToken();
159174
serviceCookie = "$Version=\"1\"; " + cookieValue + "; " + pathData;
160175

161-
vimPort.login(serviceContent.getSessionManager(), userName, password, null);
162176
isConnected = true;
163177
}
164178

@@ -577,41 +591,51 @@ public ManagedObjectReference getDecendentMoRef(ManagedObjectReference root, Str
577591
return null;
578592
}
579593

580-
// Create PropertySpecs
581-
PropertySpec pSpec = new PropertySpec();
582-
pSpec.setType(type);
583-
pSpec.setAll(false);
584-
pSpec.getPathSet().add("name");
585-
586-
ObjectSpec oSpec = new ObjectSpec();
587-
oSpec.setObj(root);
588-
oSpec.setSkip(false);
589-
oSpec.getSelectSet().addAll(constructCompleteTraversalSpec());
590-
591-
PropertyFilterSpec spec = new PropertyFilterSpec();
592-
spec.getPropSet().add(pSpec);
593-
spec.getObjectSet().add(oSpec);
594-
List<PropertyFilterSpec> specArr = new ArrayList<PropertyFilterSpec>();
595-
specArr.add(spec);
596-
597-
List<ObjectContent> ocary = vimPort.retrieveProperties(getPropCol(), specArr);
598-
599-
if (ocary == null || ocary.size() == 0) {
600-
return null;
601-
}
594+
try {
595+
// Create PropertySpecs
596+
PropertySpec pSpec = new PropertySpec();
597+
pSpec.setType(type);
598+
pSpec.setAll(false);
599+
pSpec.getPathSet().add("name");
600+
601+
ObjectSpec oSpec = new ObjectSpec();
602+
oSpec.setObj(root);
603+
oSpec.setSkip(false);
604+
oSpec.getSelectSet().addAll(constructCompleteTraversalSpec());
605+
606+
PropertyFilterSpec spec = new PropertyFilterSpec();
607+
spec.getPropSet().add(pSpec);
608+
spec.getObjectSet().add(oSpec);
609+
List<PropertyFilterSpec> specArr = new ArrayList<PropertyFilterSpec>();
610+
specArr.add(spec);
611+
612+
ManagedObjectReference propCollector = getPropCol();
613+
List<ObjectContent> ocary = vimPort.retrieveProperties(propCollector, specArr);
614+
615+
if (ocary == null || ocary.size() == 0) {
616+
return null;
617+
}
602618

603-
// filter through retrieved objects to get the first match.
604-
for (ObjectContent oc : ocary) {
605-
ManagedObjectReference mor = oc.getObj();
606-
List<DynamicProperty> propary = oc.getPropSet();
607-
if (type == null || type.equals(mor.getType())) {
608-
if (propary.size() > 0) {
609-
String propval = (String)propary.get(0).getVal();
610-
if (propval != null && name.equalsIgnoreCase(propval))
611-
return mor;
619+
// filter through retrieved objects to get the first match.
620+
for (ObjectContent oc : ocary) {
621+
ManagedObjectReference mor = oc.getObj();
622+
List<DynamicProperty> propary = oc.getPropSet();
623+
if (type == null || type.equals(mor.getType())) {
624+
if (propary.size() > 0) {
625+
String propval = (String)propary.get(0).getVal();
626+
if (propval != null && name.equalsIgnoreCase(propval))
627+
return mor;
628+
}
612629
}
613630
}
631+
} catch (InvalidPropertyFaultMsg invalidPropertyException) {
632+
s_logger.debug("Failed to get Vmware ManagedObjectReference for name: " + name + " and type: " + type + " due to " + invalidPropertyException.getMessage());
633+
throw invalidPropertyException;
634+
} catch (RuntimeFaultFaultMsg runtimeFaultException) {
635+
s_logger.debug("Failed to get Vmware ManagedObjectReference for name: " + name + " and type: " + type + " due to " + runtimeFaultException.getMessage());
636+
throw runtimeFaultException;
614637
}
638+
615639
return null;
616640
}
617641

0 commit comments

Comments
 (0)