Initial commit adding few required managed object classes and added pbm sdk

This commit is contained in:
Harikrishna Patnala 2020-05-22 11:01:46 +05:30
parent db3fdf4142
commit 0701dc9d9c
8 changed files with 170 additions and 1 deletions

View File

@ -39,3 +39,5 @@ mvn install:install-file -Dfile=vim25_65.jar -DgroupId=com.cloud.com.vmwa
# From https://my.vmware.com/group/vmware/details?downloadGroup=WEBCLIENTSDK67U2&productId=742
mvn install:install-file -Dfile=vim25_67.jar -DgroupId=com.cloud.com.vmware -DartifactId=vmware-vim25 -Dversion=6.7 -Dpackaging=jar
mvn install:install-file -Dfile=pbm_65.jar -DgroupId=com.cloud.com.vmware -DartifactId=pbm -Dversion=6.5 -Dpackaging=jar

View File

@ -72,5 +72,11 @@
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
<dependency>
<groupId>com.cloud.com.vmware</groupId>
<artifactId>pbm</artifactId>
<version>${cs.vmware.api.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -75,5 +75,11 @@
<version>${cs.jaxws.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.cloud.com.vmware</groupId>
<artifactId>pbm</artifactId>
<version>${cs.vmware.api.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,53 @@
package com.cloud.hypervisor.vmware.mo;
import com.cloud.hypervisor.vmware.util.VmwareContext;
import com.vmware.pbm.PbmProfile;
import com.vmware.pbm.PbmProfileId;
import com.vmware.pbm.PbmProfileResourceType;
import com.vmware.pbm.PbmProfileResourceTypeEnum;
import com.vmware.vim25.ManagedObjectReference;
import org.apache.log4j.Logger;
import java.util.List;
public class PbmProfileManagerMO extends BaseMO {
private static final Logger s_logger = Logger.getLogger(PbmProfileManagerMO.class);
public PbmProfileManagerMO (VmwareContext context) {
super(context, context.getPbmServiceContent().getProfileManager());
}
public PbmProfileManagerMO (VmwareContext context, ManagedObjectReference morProfileMgr) {
super(context, morProfileMgr);
}
public PbmProfileManagerMO (VmwareContext context, String morType, String morValue) {
super(context, morType, morValue);
}
public List<PbmProfileId> getProfileIds() throws Exception {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Querying vCenter " + _context.getServerAddress() + " for profiles");
}
List<PbmProfileId> profileIds = _context.getPbmService().pbmQueryProfile(_mor, getStorageResourceType(), null);
return profileIds;
}
public List<PbmProfile> getProfiles(PbmProfileResourceType pbmResourceType) throws Exception {
List<PbmProfileId> profileIds = getProfileIds();
List<PbmProfile> profiles = _context.getPbmService().pbmRetrieveContent(_mor, profileIds);
return profiles;
}
private PbmProfileResourceType getStorageResourceType() {
PbmProfileResourceType resourceType = new PbmProfileResourceType();
resourceType.setResourceType(PbmProfileResourceTypeEnum.STORAGE.value());
return resourceType;
}
}

View File

@ -34,6 +34,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import com.vmware.vim25.VStorageObject;
import com.vmware.vim25.VStorageObjectConfigInfo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.log4j.Logger;
@ -2485,7 +2487,13 @@ public class VirtualMachineMO extends BaseMO {
String deviceNumbering = getDeviceBusName(devices, device);
s_logger.info("Disk backing : " + diskBackingInfo.getFileName() + " matches ==> " + deviceNumbering);
if (((VirtualDisk) device).getVDiskId() == null) {
s_logger.debug("vDiskid does not exist for volume " + vmdkDatastorePath + " registering the disk now");
VirtualStorageObjectManager vStorageObjectManagerMO = new VirtualStorageObjectManager(getOwnerDatacenter().first().getContext());
VStorageObject vStorageObject = vStorageObjectManagerMO.registerVirtualDisk(dsBackingFile, null, getOwnerDatacenter().first().getName());
VStorageObjectConfigInfo diskConfigInfo = vStorageObject.getConfig();
((VirtualDisk) device).setVDiskId(diskConfigInfo.getId());
}
return new Pair<>((VirtualDisk)device, deviceNumbering);
}

View File

@ -0,0 +1,58 @@
// 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 com.cloud.hypervisor.vmware.mo;
import com.vmware.vim25.ID;
import com.vmware.vim25.VStorageObject;
import org.apache.log4j.Logger;
import com.vmware.vim25.ManagedObjectReference;
import com.cloud.hypervisor.vmware.util.VmwareContext;
public class VirtualStorageObjectManager extends BaseMO {
@SuppressWarnings("unused")
private static final Logger s_logger = Logger.getLogger(VirtualStorageObjectManager.class);
public VirtualStorageObjectManager(VmwareContext context) {
super(context, context.getServiceContent().getVStorageObjectManager());
}
public VirtualStorageObjectManager(VmwareContext context, ManagedObjectReference morDiskMgr) {
super(context, morDiskMgr);
}
public VirtualStorageObjectManager(VmwareContext context, String morType, String morValue) {
super(context, morType, morValue);
}
public VStorageObject registerVirtualDisk(DatastoreFile datastoreFile, String name, String dcName) throws Exception {
StringBuilder sb = new StringBuilder();
//https://10.2.2.254/folder/i-2-4-VM/89e3756d9b7444dc92388eb36ddd026b.vmdk?dcPath=datacenter-21&dsName=c84e4af9b6ac33e887a25d9242650091
sb.append("https://").append(_context.getServerAddress()).append("/folder/");
sb.append(datastoreFile.getRelativePath());
sb.append("?dcPath=");
sb.append(dcName);
sb.append("&dsName=");
sb.append(datastoreFile.getDatastoreName());
return _context.getService().registerDisk(_mor, sb.toString(), name);
}
public VStorageObject retrieveVirtualDisk (ID id, ManagedObjectReference morDS) throws Exception {
return _context.getService().retrieveVStorageObject(_mor, id, morDS);
}
}

View File

@ -32,6 +32,8 @@ import javax.xml.ws.handler.MessageContext;
import org.apache.cloudstack.utils.security.SSLUtils;
import org.apache.cloudstack.utils.security.SecureSSLSocketFactory;
import com.vmware.pbm.PbmPortType;
import com.vmware.pbm.PbmServiceInstanceContent;
import org.apache.log4j.Logger;
import org.w3c.dom.Element;
@ -120,8 +122,14 @@ public class VmwareClient {
}
private final ManagedObjectReference svcInstRef = new ManagedObjectReference();
private final ManagedObjectReference pbmSvcInstRef = new ManagedObjectReference();
private static VimService vimService;
private VimPortType vimPort;
private PbmPortType pbmPort;
private static final String PBM_SERVICE_INSTANCE_TYPE = "PbmServiceInstance";
private static final String PBM_SERVICE_INSTANCE_VALUE = "ServiceInstance";
private String serviceCookie;
private final static String SVC_INST_NAME = "ServiceInstance";
private int vCenterSessionTimeout = 1200000; // Timeout in milliseconds
@ -211,6 +219,24 @@ public class VmwareClient {
return null;
}
/**
* @return PBM service instance
*/
public PbmPortType getPbmService() {
return pbmPort;
}
/**
* @return Service instance content
*/
public PbmServiceInstanceContent getPbmServiceContent() {
try {
return pbmPort.pbmRetrieveServiceContent(pbmSvcInstRef);
} catch (com.vmware.pbm.RuntimeFaultFaultMsg e) {
}
return null;
}
/**
* @return cookie used in service connection
*/

View File

@ -20,6 +20,8 @@ import com.cloud.hypervisor.vmware.mo.DatacenterMO;
import com.cloud.hypervisor.vmware.mo.DatastoreFile;
import com.cloud.utils.ActionDelegate;
import com.cloud.utils.StringUtils;
import com.vmware.pbm.PbmPortType;
import com.vmware.pbm.PbmServiceInstanceContent;
import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.ObjectContent;
import com.vmware.vim25.ObjectSpec;
@ -148,6 +150,14 @@ public class VmwareContext {
return _vimClient.getServiceContent();
}
public PbmPortType getPbmService() {
return _vimClient.getPbmService();
}
public PbmServiceInstanceContent getPbmServiceContent() {
return _vimClient.getPbmServiceContent();
}
public ManagedObjectReference getPropertyCollector() {
return _vimClient.getPropCol();
}