mirror of https://github.com/apache/cloudstack.git
Merge branch 'vim51_win8'
This commit is contained in:
commit
88355b9457
|
|
@ -612,8 +612,8 @@ public class AgentShell implements IAgentShell {
|
|||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
LogUtils.initLog4j("log4j-cloud.xml");
|
||||
|
||||
LogUtils.initLog4j("log4j-cloud.xml");
|
||||
|
||||
AgentShell shell = new AgentShell();
|
||||
shell.init(args);
|
||||
shell.start();
|
||||
|
|
|
|||
|
|
@ -104,7 +104,14 @@
|
|||
<bean id="FirstFitRouting" class="com.cloud.agent.manager.allocator.impl.FirstFitRoutingAllocator">
|
||||
<property name="name" value="FirstFitRouting"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="hypervisorTemplateAdapter" class="com.cloud.template.HypervisorTemplateAdapter">
|
||||
<property name="name" value="HypervisorAdapter"/>
|
||||
</bean>
|
||||
|
||||
<bean id="bareMetalTemplateAdapter" class="com.cloud.baremetal.BareMetalTemplateAdapter">
|
||||
<property name="name" value="BareMetalAdapter"/>
|
||||
</bean>
|
||||
|
||||
<!--
|
||||
Storage pool allocators
|
||||
|
|
@ -230,7 +237,7 @@
|
|||
<bean id="BareMetalPlanner" class="com.cloud.baremetal.manager.BareMetalPlanner">
|
||||
<property name="name" value="BareMetal Fit"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="BaremetalPlannerSelector" class="com.cloud.baremetal.manager.BaremetalPlannerSelector">
|
||||
<property name="name" value="BaremetalPlannerSelector"/>
|
||||
</bean>
|
||||
|
|
@ -298,7 +305,7 @@
|
|||
<bean id="OvmGuru" class="com.cloud.ovm.hypervisor.OvmGuru">
|
||||
<property name="name" value="OvmGuru"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<!--
|
||||
<bean id="SimulatorGuru" class="com.cloud.simulator.SimulatorGuru">
|
||||
<property name="name" value="SimulatorGuru"/>
|
||||
|
|
|
|||
|
|
@ -111,6 +111,14 @@
|
|||
<property name="name" value="FirstFitRouting"/>
|
||||
</bean>
|
||||
|
||||
<bean id="hypervisorTemplateAdapter" class="com.cloud.template.HypervisorTemplateAdapter">
|
||||
<property name="name" value="HypervisorAdapter"/>
|
||||
</bean>
|
||||
|
||||
<bean id="bareMetalTemplateAdapter" class="com.cloud.baremetal.BareMetalTemplateAdapter">
|
||||
<property name="name" value="BareMetalAdapter"/>
|
||||
</bean>
|
||||
|
||||
<!--
|
||||
Storage pool allocators
|
||||
-->
|
||||
|
|
@ -240,7 +248,7 @@
|
|||
<bean id="BareMetalPlanner" class="com.cloud.baremetal.manager.BareMetalPlanner">
|
||||
<property name="name" value="BareMetal Fit"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<!--
|
||||
Network Gurus
|
||||
-->
|
||||
|
|
@ -285,7 +293,7 @@
|
|||
<bean id="KVMGuru" class="com.cloud.hypervisor.KVMGuru">
|
||||
<property name="name" value="KVMGuru"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="OvmGuru" class="com.cloud.ovm.hypervisor.OvmGuru">
|
||||
<property name="name" value="OvmGuru"/>
|
||||
</bean>
|
||||
|
|
@ -293,7 +301,7 @@
|
|||
<bean id="VMwareGuru" class="com.cloud.hypervisor.guru.VMwareGuru">
|
||||
<property name="name" value="VMwareGuru"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="BaremetalGuru" class="com.cloud.baremetal.manager.BareMetalGuru">
|
||||
<property name="name" value="BaremetalGuru"/>
|
||||
</bean>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
# 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
|
||||
|
|
@ -26,10 +26,17 @@ if [ -e cloud-manageontap.jar ]; then mv cloud-manageontap.jar manageontap.jar;
|
|||
mvn install:install-file -Dfile=manageontap.jar -DgroupId=com.cloud.com.netapp -DartifactId=manageontap -Dversion=4.0 -Dpackaging=jar
|
||||
|
||||
# From https://my.vmware.com/group/vmware/get-download?downloadGroup=VSDK41
|
||||
# Version: 4.1, Release-date: 2010-07-13, Build: 257238
|
||||
# Version: 4.1, Release-date: 2010-07-13, Build: 257238
|
||||
if [ -e vmware-apputils.jar ]; then mv vmware-apputils.jar apputils.jar; fi
|
||||
if [ -e vmware-vim.jar ]; then mv vmware-vim.jar vim.jar; fi
|
||||
if [ -e vmware-vim25.jar ]; then mv vmware-vim25.jar vim25.jar; fi
|
||||
mvn install:install-file -Dfile=vim25.jar -DgroupId=com.cloud.com.vmware -DartifactId=vmware-vim25 -Dversion=4.1 -Dpackaging=jar
|
||||
mvn install:install-file -Dfile=apputils.jar -DgroupId=com.cloud.com.vmware -DartifactId=vmware-apputils -Dversion=4.1 -Dpackaging=jar
|
||||
mvn install:install-file -Dfile=vim.jar -DgroupId=com.cloud.com.vmware -DartifactId=vmware-vim -Dversion=4.1 -Dpackaging=jar
|
||||
|
||||
#
|
||||
# From https://my.vmware.com/group/vmware/get-download?downloadGroup=VSP510-WEBSDK-510
|
||||
# Version: 5.1, Release-date: 2012-09-10, Build: 774886
|
||||
mvn install:install-file -Dfile=vim25_51.jar -DgroupId=com.cloud.com.vmware -DartifactId=vmware-vim25 -Dversion=5.1 -Dpackaging=jar
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -38,18 +38,6 @@
|
|||
<version>${cs.vmware.api.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cloud.com.vmware</groupId>
|
||||
<artifactId>vmware-vim</artifactId>
|
||||
<version>${cs.vmware.api.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cloud.com.vmware</groupId>
|
||||
<artifactId>vmware-apputils</artifactId>
|
||||
<version>${cs.vmware.api.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.axis</groupId>
|
||||
<artifactId>axis</artifactId>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
// 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
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.hypervisor.vmware;
|
||||
|
|
@ -78,6 +78,7 @@ import com.cloud.utils.UriUtils;
|
|||
import com.vmware.vim25.ClusterDasConfigInfo;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
|
||||
|
||||
@Local(value = Discoverer.class)
|
||||
public class VmwareServerDiscoverer extends DiscovererBase implements
|
||||
Discoverer, ResourceStateAdapter {
|
||||
|
|
@ -113,41 +114,41 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
|
|||
public VmwareServerDiscoverer() {
|
||||
s_logger.info("VmwareServerDiscoverer is constructed");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url,
|
||||
String username, String password, List<String> hostTags) throws DiscoveryException {
|
||||
|
||||
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("Discover host. dc: " + dcId + ", pod: " + podId + ", cluster: " + clusterId + ", uri host: " + url.getHost());
|
||||
|
||||
|
||||
if(podId == null) {
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("No pod is assigned, assuming that it is not for vmware and skip it to next discoverer");
|
||||
return null;
|
||||
}
|
||||
|
||||
ClusterVO cluster = _clusterDao.findById(clusterId);
|
||||
s_logger.info("No pod is assigned, assuming that it is not for vmware and skip it to next discoverer");
|
||||
return null;
|
||||
}
|
||||
|
||||
ClusterVO cluster = _clusterDao.findById(clusterId);
|
||||
if(cluster == null || cluster.getHypervisorType() != HypervisorType.VMware) {
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("invalid cluster id or cluster is not for VMware hypervisors");
|
||||
return null;
|
||||
}
|
||||
|
||||
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId);
|
||||
s_logger.info("invalid cluster id or cluster is not for VMware hypervisors");
|
||||
return null;
|
||||
}
|
||||
|
||||
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId);
|
||||
if (hosts != null && hosts.size() > 0) {
|
||||
int maxHostsPerCluster = _hvCapabilitiesDao.getMaxHostsPerCluster(hosts.get(0).getHypervisorType(), hosts.get(0).getHypervisorVersion());
|
||||
if (hosts.size() > maxHostsPerCluster) {
|
||||
String msg = "VMware cluster " + cluster.getName() + " is too big to add new host now. (current configured cluster size: " + maxHostsPerCluster + ")";
|
||||
s_logger.error(msg);
|
||||
throw new DiscoveredWithErrorException(msg);
|
||||
}
|
||||
s_logger.error(msg);
|
||||
throw new DiscoveredWithErrorException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
String privateTrafficLabel = null;
|
||||
String publicTrafficLabel = null;
|
||||
String guestTrafficLabel = null;
|
||||
Map<String, String> vsmCredentials = null;
|
||||
String privateTrafficLabel = null;
|
||||
String publicTrafficLabel = null;
|
||||
String guestTrafficLabel = null;
|
||||
Map<String, String> vsmCredentials = null;
|
||||
|
||||
VirtualSwitchType defaultVirtualSwitchType = VirtualSwitchType.StandardVirtualSwitch;
|
||||
|
||||
|
|
@ -204,30 +205,30 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
|
|||
// Process traffic label information provided at zone level and cluster level
|
||||
publicTrafficLabelObj = getTrafficInfo(TrafficType.Public, publicTrafficLabel, defaultVirtualSwitchType, paramPublicVswitchType, paramPublicVswitchName, clusterId);
|
||||
|
||||
// Configuration Check: A physical network cannot be shared by different types of virtual switches.
|
||||
//
|
||||
// Check if different vswitch types are chosen for same physical network
|
||||
// 1. Get physical network for guest traffic - multiple networks
|
||||
// 2. Get physical network for public traffic - single network
|
||||
// See if 2 is in 1
|
||||
// if no - pass
|
||||
// if yes - compare publicTrafficLabelObj.getVirtualSwitchType() == guestTrafficLabelObj.getVirtualSwitchType()
|
||||
// true - pass
|
||||
// false - throw exception - fail cluster add operation
|
||||
// Configuration Check: A physical network cannot be shared by different types of virtual switches.
|
||||
//
|
||||
// Check if different vswitch types are chosen for same physical network
|
||||
// 1. Get physical network for guest traffic - multiple networks
|
||||
// 2. Get physical network for public traffic - single network
|
||||
// See if 2 is in 1
|
||||
// if no - pass
|
||||
// if yes - compare publicTrafficLabelObj.getVirtualSwitchType() == guestTrafficLabelObj.getVirtualSwitchType()
|
||||
// true - pass
|
||||
// false - throw exception - fail cluster add operation
|
||||
|
||||
List<? extends PhysicalNetwork> pNetworkListGuestTraffic = _netmgr.getPhysicalNtwksSupportingTrafficType(dcId, TrafficType.Guest);
|
||||
List<? extends PhysicalNetwork> pNetworkListPublicTraffic = _netmgr.getPhysicalNtwksSupportingTrafficType(dcId, TrafficType.Public);
|
||||
// Public network would be on single physical network hence getting first object of the list would suffice.
|
||||
PhysicalNetwork pNetworkPublic = pNetworkListPublicTraffic.get(0);
|
||||
if (pNetworkListGuestTraffic.contains(pNetworkPublic)) {
|
||||
if (publicTrafficLabelObj.getVirtualSwitchType() != guestTrafficLabelObj.getVirtualSwitchType()) {
|
||||
String msg = "Both public traffic and guest traffic is over same physical network " + pNetworkPublic +
|
||||
". And virtual switch type chosen for each traffic is different" +
|
||||
". A physical network cannot be shared by different types of virtual switches.";
|
||||
s_logger.error(msg);
|
||||
throw new InvalidParameterValueException(msg);
|
||||
}
|
||||
List<? extends PhysicalNetwork> pNetworkListGuestTraffic = _netmgr.getPhysicalNtwksSupportingTrafficType(dcId, TrafficType.Guest);
|
||||
List<? extends PhysicalNetwork> pNetworkListPublicTraffic = _netmgr.getPhysicalNtwksSupportingTrafficType(dcId, TrafficType.Public);
|
||||
// Public network would be on single physical network hence getting first object of the list would suffice.
|
||||
PhysicalNetwork pNetworkPublic = pNetworkListPublicTraffic.get(0);
|
||||
if (pNetworkListGuestTraffic.contains(pNetworkPublic)) {
|
||||
if (publicTrafficLabelObj.getVirtualSwitchType() != guestTrafficLabelObj.getVirtualSwitchType()) {
|
||||
String msg = "Both public traffic and guest traffic is over same physical network " + pNetworkPublic +
|
||||
". And virtual switch type chosen for each traffic is different" +
|
||||
". A physical network cannot be shared by different types of virtual switches.";
|
||||
s_logger.error(msg);
|
||||
throw new InvalidParameterValueException(msg);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Distributed virtual switch is not supported in Basic zone for now.
|
||||
// Private / Management network traffic is not yet supported over distributed virtual switch.
|
||||
|
|
@ -239,24 +240,24 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
|
|||
}
|
||||
|
||||
privateTrafficLabel = _netmgr.getDefaultManagementTrafficLabel(dcId, HypervisorType.VMware);
|
||||
if (privateTrafficLabel != null) {
|
||||
if (privateTrafficLabel != null) {
|
||||
s_logger.info("Detected private network label : " + privateTrafficLabel);
|
||||
}
|
||||
}
|
||||
|
||||
if (nexusDVS) {
|
||||
if (zoneType != NetworkType.Basic) {
|
||||
if (zoneType != NetworkType.Basic) {
|
||||
publicTrafficLabel = _netmgr.getDefaultPublicTrafficLabel(dcId, HypervisorType.VMware);
|
||||
if (publicTrafficLabel != null) {
|
||||
if (publicTrafficLabel != null) {
|
||||
s_logger.info("Detected public network label : " + publicTrafficLabel);
|
||||
}
|
||||
}
|
||||
// Get physical network label
|
||||
}
|
||||
}
|
||||
// Get physical network label
|
||||
guestTrafficLabel = _netmgr.getDefaultGuestTrafficLabel(dcId, HypervisorType.VMware);
|
||||
if (guestTrafficLabel != null) {
|
||||
if (guestTrafficLabel != null) {
|
||||
s_logger.info("Detected guest network label : " + guestTrafficLabel);
|
||||
}
|
||||
}
|
||||
vsmCredentials = _vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId);
|
||||
}
|
||||
}
|
||||
|
||||
VmwareContext context = null;
|
||||
try {
|
||||
|
|
@ -304,8 +305,8 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
|
|||
} else {
|
||||
ClusterMO clusterMo = new ClusterMO(context, morCluster);
|
||||
ClusterDasConfigInfo dasConfig = clusterMo.getDasConfig();
|
||||
if (dasConfig != null && dasConfig.getEnabled() != null
|
||||
&& dasConfig.getEnabled().booleanValue()) {
|
||||
if (dasConfig != null && dasConfig.isEnabled() != null
|
||||
&& dasConfig.isEnabled().booleanValue()) {
|
||||
clusterDetails.put("NativeHA", "true");
|
||||
_clusterDetailsDao.persist(clusterId, clusterDetails);
|
||||
}
|
||||
|
|
@ -329,7 +330,7 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
|
|||
details.put("url", hostMo.getHostName());
|
||||
details.put("username", username);
|
||||
details.put("password", password);
|
||||
String guid = morHost.getType() + ":" + morHost.get_value()
|
||||
String guid = morHost.getType() + ":" + morHost.getValue()
|
||||
+ "@" + url.getHost();
|
||||
details.put("guid", guid);
|
||||
|
||||
|
|
@ -385,7 +386,7 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
|
|||
if (morCluster == null) {
|
||||
for (ManagedObjectReference morHost : morHosts) {
|
||||
ManagedObjectReference morParent = (ManagedObjectReference) context
|
||||
.getServiceUtil().getDynamicProperty(morHost, "parent");
|
||||
.getVimClient().getDynamicProperty(morHost, "parent");
|
||||
if (morParent.getType().equalsIgnoreCase(
|
||||
"ClusterComputeResource"))
|
||||
return false;
|
||||
|
|
@ -393,12 +394,12 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
|
|||
} else {
|
||||
for (ManagedObjectReference morHost : morHosts) {
|
||||
ManagedObjectReference morParent = (ManagedObjectReference) context
|
||||
.getServiceUtil().getDynamicProperty(morHost, "parent");
|
||||
.getVimClient().getDynamicProperty(morHost, "parent");
|
||||
if (!morParent.getType().equalsIgnoreCase(
|
||||
"ClusterComputeResource"))
|
||||
return false;
|
||||
|
||||
if (!morParent.get_value().equals(morCluster.get_value()))
|
||||
if (!morParent.getValue().equals(morCluster.getValue()))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -464,6 +465,7 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public HostVO createHostVOForConnectedAgent(HostVO host,
|
||||
StartupCommand[] cmd) {
|
||||
|
|
@ -499,6 +501,7 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
|
|||
|
||||
_resourceMgr.deleteRoutingHost(host, isForced, isForceDeleteStorage);
|
||||
return new DeleteHostAnswer(true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
// 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
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.hypervisor.vmware.manager;
|
||||
|
|
@ -67,6 +67,8 @@ import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper;
|
|||
import com.cloud.hypervisor.vmware.mo.TaskMO;
|
||||
import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType;
|
||||
import com.cloud.hypervisor.vmware.mo.VmwareHostType;
|
||||
import com.cloud.utils.ssh.SshHelper;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareClient;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.cloud.network.CiscoNexusVSMDeviceVO;
|
||||
import com.cloud.network.NetworkModel;
|
||||
|
|
@ -91,7 +93,6 @@ 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.apputils.vim25.ServiceUtil;
|
||||
import com.vmware.vim25.AboutInfo;
|
||||
import com.vmware.vim25.HostConnectSpec;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
|
|
@ -316,10 +317,10 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
|
|||
}
|
||||
|
||||
s_logger.info("Preparing network on host " + hostMo.getContext().toString() + " for " + privateTrafficLabel);
|
||||
HypervisorHostHelper.prepareNetwork(vSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
||||
HypervisorHostHelper.prepareNetwork(vSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceContext, long dcId, Long podId, Long clusterId,
|
||||
String hostInventoryPath) throws Exception {
|
||||
|
|
@ -336,27 +337,28 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
|
|||
List<ManagedObjectReference> returnedHostList = new ArrayList<ManagedObjectReference>();
|
||||
|
||||
if(mor.getType().equals("ComputeResource")) {
|
||||
ManagedObjectReference[] hosts = (ManagedObjectReference[])serviceContext.getServiceUtil().getDynamicProperty(mor, "host");
|
||||
assert(hosts != null);
|
||||
List<ManagedObjectReference> hosts = (List<ManagedObjectReference>)serviceContext.getVimClient().getDynamicProperty(mor, "host");
|
||||
assert(hosts != null && hosts.size() > 0);
|
||||
|
||||
// For ESX host, we need to enable host firewall to allow VNC access
|
||||
HostMO hostMo = new HostMO(serviceContext, hosts[0]);
|
||||
HostMO hostMo = new HostMO(serviceContext, hosts.get(0));
|
||||
|
||||
prepareHost(hostMo, privateTrafficLabel);
|
||||
returnedHostList.add(hosts[0]);
|
||||
returnedHostList.add(hosts.get(0));
|
||||
return returnedHostList;
|
||||
} else if(mor.getType().equals("ClusterComputeResource")) {
|
||||
ManagedObjectReference[] hosts = (ManagedObjectReference[])serviceContext.getServiceUtil().getDynamicProperty(mor, "host");
|
||||
List<ManagedObjectReference> hosts = (List<ManagedObjectReference>)serviceContext.getVimClient().getDynamicProperty(mor, "host");
|
||||
assert(hosts != null);
|
||||
|
||||
if (hosts.length > 0) {
|
||||
AboutInfo about = (AboutInfo)(serviceContext.getServiceUtil().getDynamicProperty(hosts[0], "config.product"));
|
||||
if (hosts.size() > 0) {
|
||||
AboutInfo about = (AboutInfo)(serviceContext.getVimClient().getDynamicProperty(hosts.get(0), "config.product"));
|
||||
String version = about.getApiVersion();
|
||||
int maxHostsPerCluster = _hvCapabilitiesDao.getMaxHostsPerCluster(HypervisorType.VMware, version);
|
||||
if (hosts.length > maxHostsPerCluster) {
|
||||
if (hosts.size() > maxHostsPerCluster) {
|
||||
String msg = "vCenter cluster size is too big (current configured cluster size: " + maxHostsPerCluster + ")";
|
||||
s_logger.error(msg);
|
||||
throw new DiscoveredWithErrorException(msg);
|
||||
}
|
||||
s_logger.error(msg);
|
||||
throw new DiscoveredWithErrorException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
for(ManagedObjectReference morHost: hosts) {
|
||||
|
|
@ -373,7 +375,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
|
|||
returnedHostList.add(mor);
|
||||
return returnedHostList;
|
||||
} else {
|
||||
s_logger.error("Unsupport host type " + mor.getType() + ":" + mor.get_value() + " from inventory path: " + hostInventoryPath);
|
||||
s_logger.error("Unsupport host type " + mor.getType() + ":" + mor.getValue() + " from inventory path: " + hostInventoryPath);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -386,8 +388,8 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
|
|||
private ManagedObjectReference addHostToVCenterCluster(VmwareContext serviceContext, ManagedObjectReference morCluster,
|
||||
String host, String userName, String password) throws Exception {
|
||||
|
||||
ServiceUtil serviceUtil = serviceContext.getServiceUtil();
|
||||
ManagedObjectReference morHost = serviceUtil.getDecendentMoRef(morCluster, "HostSystem", host);
|
||||
VmwareClient vclient = serviceContext.getVimClient();
|
||||
ManagedObjectReference morHost = vclient.getDecendentMoRef(morCluster, "HostSystem", host);
|
||||
if(morHost == null) {
|
||||
HostConnectSpec hostSpec = new HostConnectSpec();
|
||||
hostSpec.setUserName(userName);
|
||||
|
|
@ -395,16 +397,16 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
|
|||
hostSpec.setHostName(host);
|
||||
hostSpec.setForce(true); // forcely take over the host
|
||||
|
||||
ManagedObjectReference morTask = serviceContext.getService().addHost_Task(morCluster, hostSpec, true, null, null);
|
||||
String taskResult = serviceUtil.waitForTask(morTask);
|
||||
if(!taskResult.equals("sucess")) {
|
||||
ManagedObjectReference morTask = serviceContext.getService().addHostTask(morCluster, hostSpec, true, null, null);
|
||||
boolean taskResult = vclient.waitForTask(morTask);
|
||||
if(!taskResult) {
|
||||
s_logger.error("Unable to add host " + host + " to vSphere cluster due to " + TaskMO.getTaskFailureInfo(serviceContext, morTask));
|
||||
throw new CloudRuntimeException("Unable to add host " + host + " to vSphere cluster due to " + taskResult);
|
||||
}
|
||||
serviceContext.waitForTaskProgressDone(morTask);
|
||||
|
||||
// init morHost after it has been created
|
||||
morHost = serviceUtil.getDecendentMoRef(morCluster, "HostSystem", host);
|
||||
morHost = vclient.getDecendentMoRef(morCluster, "HostSystem", host);
|
||||
if(morHost == null) {
|
||||
throw new CloudRuntimeException("Successfully added host into vSphere but unable to find it later on?!. Please make sure you are either using IP address or full qualified domain name for host");
|
||||
}
|
||||
|
|
@ -422,6 +424,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
|
|||
|
||||
@Override
|
||||
public String getSecondaryStorageStoreUrl(long dcId) {
|
||||
|
||||
List<HostVO> secStorageHosts = _ssvmMgr.listSecondaryStorageHostsInOneZone(dcId);
|
||||
if(secStorageHosts.size() > 0)
|
||||
return secStorageHosts.get(0).getStorageUrl();
|
||||
|
|
@ -492,6 +495,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
|
|||
s_logger.info("Inject SSH key pairs before copying systemvm.iso into secondary storage");
|
||||
_configServer.updateKeyPairs();
|
||||
|
||||
|
||||
try {
|
||||
FileUtil.copyfile(srcIso, destIso);
|
||||
} catch(IOException e) {
|
||||
|
|
@ -533,11 +537,11 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
|
|||
if (url != null) {
|
||||
isoFile = new File(url.getPath());
|
||||
}
|
||||
|
||||
|
||||
if(isoFile == null || !isoFile.exists()) {
|
||||
isoFile = new File("/usr/share/cloudstack-common/vms/systemvm.iso");
|
||||
}
|
||||
|
||||
|
||||
assert(isoFile != null);
|
||||
if(!isoFile.exists()) {
|
||||
s_logger.error("Unable to locate systemvm.iso in your setup at " + isoFile.toString());
|
||||
|
|
@ -552,7 +556,6 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
|
|||
if ( url != null ){
|
||||
keyFile = new File(url.getPath());
|
||||
}
|
||||
|
||||
if (keyFile == null || !keyFile.exists()) {
|
||||
keyFile = new File("/usr/share/cloudstack-common/scripts/vm/systemvm/id_rsa.cloud");
|
||||
}
|
||||
|
|
@ -838,7 +841,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
|
|||
vsmMapVO = _vsmMapDao.findByClusterId(clusterId);
|
||||
long vsmId = 0;
|
||||
if (vsmMapVO != null) {
|
||||
vsmId = vsmMapVO.getVsmId();
|
||||
vsmId = vsmMapVO.getVsmId();
|
||||
s_logger.info("vsmId is " + vsmId);
|
||||
nexusVSM = _nexusDao.findById(vsmId);
|
||||
s_logger.info("Fetching nexus vsm credentials from database.");
|
||||
|
|
@ -846,7 +849,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
|
|||
else {
|
||||
s_logger.info("Found empty vsmMapVO.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> nexusVSMCredentials = new HashMap<String, String>();
|
||||
if (nexusVSM != null) {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
// 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
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.hypervisor.vmware.manager;
|
||||
|
|
@ -83,24 +83,24 @@ import com.vmware.vim25.VirtualSCSISharing;
|
|||
|
||||
public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
||||
private static final Logger s_logger = Logger.getLogger(VmwareStorageManagerImpl.class);
|
||||
|
||||
|
||||
private final VmwareStorageMount _mountService;
|
||||
private final StorageLayer _storage = new JavaStorageLayer();
|
||||
|
||||
|
||||
private int _timeout;
|
||||
|
||||
|
||||
public VmwareStorageManagerImpl(VmwareStorageMount mountService) {
|
||||
assert(mountService != null);
|
||||
_mountService = mountService;
|
||||
}
|
||||
|
||||
|
||||
public void configure(Map<String, Object> params) {
|
||||
s_logger.info("Configure VmwareStorageManagerImpl");
|
||||
|
||||
|
||||
String value = (String)params.get("scripts.timeout");
|
||||
_timeout = NumbersUtil.parseInt(value, 1440) * 1000;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Answer execute(VmwareHostService hostService, PrimaryStorageDownloadCommand cmd) {
|
||||
String secondaryStorageUrl = cmd.getSecondaryStorageUrl();
|
||||
|
|
@ -130,18 +130,18 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
}
|
||||
templateName = cmd.getName();
|
||||
}
|
||||
|
||||
|
||||
VmwareContext context = hostService.getServiceContext(cmd);
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
|
||||
|
||||
String templateUuidName = UUID.nameUUIDFromBytes((templateName + "@" + cmd.getPoolUuid() + "-" + hyperHost.getMor().get_value()).getBytes()).toString();
|
||||
|
||||
String templateUuidName = UUID.nameUUIDFromBytes((templateName + "@" + cmd.getPoolUuid() + "-" + hyperHost.getMor().getValue()).getBytes()).toString();
|
||||
// truncate template name to 32 chars to ensure they work well with vSphere API's.
|
||||
templateUuidName = templateUuidName.replace("-", "");
|
||||
|
||||
templateUuidName = templateUuidName.replace("-", "");
|
||||
|
||||
DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter());
|
||||
VirtualMachineMO templateMo = VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(templateUuidName), true);
|
||||
|
||||
|
||||
if (templateMo == null) {
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("Template " + templateName + " is not setup yet, setup template from secondary storage with uuid name: " + templateUuidName);
|
||||
|
|
@ -167,7 +167,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
return new PrimaryStorageDownloadAnswer(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Answer execute(VmwareHostService hostService, BackupSnapshotCommand cmd) {
|
||||
Long accountId = cmd.getAccountId();
|
||||
|
|
@ -198,15 +198,15 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
if (vmMo == null) {
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("Unable to find owner VM for BackupSnapshotCommand on host " + hyperHost.getHyperHostName() + ", will try within datacenter");
|
||||
|
||||
|
||||
vmMo = hyperHost.findVmOnPeerHyperHost(cmd.getVmName());
|
||||
if(vmMo == null) {
|
||||
dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
|
||||
|
||||
|
||||
workerVMName = hostService.getWorkerName(context, cmd, 0);
|
||||
|
||||
|
||||
// attach a volume to dummay wrapper VM for taking snapshot and exporting the VM for backup
|
||||
if (!hyperHost.createBlankVm(workerVMName, 1, 512, 0, false, 4, 0, VirtualMachineGuestOsIdentifier._otherGuest.toString(), morDs, false)) {
|
||||
if (!hyperHost.createBlankVm(workerVMName, 1, 512, 0, false, 4, 0, VirtualMachineGuestOsIdentifier.OTHER_GUEST.value(), morDs, false)) {
|
||||
String msg = "Unable to create worker VM to execute BackupSnapshotCommand";
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
|
|
@ -216,17 +216,17 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
throw new Exception("Failed to find the newly create or relocated VM. vmName: " + workerVMName);
|
||||
}
|
||||
workerVm = vmMo;
|
||||
|
||||
|
||||
// attach volume to worker VM
|
||||
String datastoreVolumePath = String.format("[%s] %s.vmdk", dsMo.getName(), volumePath);
|
||||
vmMo.attachDisk(new String[] { datastoreVolumePath }, morDs);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!vmMo.createSnapshot(snapshotUuid, "Snapshot taken for " + cmd.getSnapshotName(), false, false)) {
|
||||
throw new Exception("Failed to take snapshot " + cmd.getSnapshotName() + " on vm: " + cmd.getVmName());
|
||||
}
|
||||
|
||||
|
||||
snapshotBackupUuid = backupSnapshotToSecondaryStorage(vmMo, accountId, volumeId, cmd.getVolumePath(), snapshotUuid, secondaryStorageUrl, prevSnapshotUuid, prevBackupUuid,
|
||||
hostService.getWorkerName(context, cmd, 1));
|
||||
|
||||
|
|
@ -234,7 +234,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
if (success) {
|
||||
details = "Successfully backedUp the snapshotUuid: " + snapshotUuid + " to secondary storage.";
|
||||
}
|
||||
|
||||
|
||||
} finally {
|
||||
if(vmMo != null){
|
||||
ManagedObjectReference snapshotMor = vmMo.getSnapshotMor(snapshotUuid);
|
||||
|
|
@ -242,7 +242,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
vmMo.removeSnapshot(snapshotUuid, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if (workerVm != null) {
|
||||
// detach volume and destroy worker vm
|
||||
|
|
@ -251,7 +251,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
}
|
||||
} catch (Throwable e) {
|
||||
s_logger.warn("Failed to destroy worker VM: " + workerVMName);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
|
|
@ -278,7 +278,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
VmwareContext context = hostService.getServiceContext(cmd);
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
|
||||
|
||||
|
||||
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
|
||||
if (vmMo == null) {
|
||||
if(s_logger.isDebugEnabled())
|
||||
|
|
@ -294,7 +294,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
|
||||
Ternary<String, Long, Long> result = createTemplateFromVolume(vmMo,
|
||||
accountId, templateId, cmd.getUniqueName(),
|
||||
secondaryStoragePoolURL, volumePath,
|
||||
secondaryStoragePoolURL, volumePath,
|
||||
hostService.getWorkerName(context, cmd, 0));
|
||||
|
||||
return new CreatePrivateTemplateAnswer(cmd, true, null,
|
||||
|
|
@ -344,7 +344,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
return new CreatePrivateTemplateAnswer(cmd, false, details);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Answer execute(VmwareHostService hostService, CopyVolumeCommand cmd) {
|
||||
Long volumeId = cmd.getVolumeId();
|
||||
|
|
@ -393,64 +393,64 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
return new CopyVolumeAnswer(cmd, false, "CopyVolumeCommand failed due to exception: " + StringUtils.getExceptionStackInfo(e), null, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Answer execute(VmwareHostService hostService, CreateVolumeFromSnapshotCommand cmd) {
|
||||
public Answer execute(VmwareHostService hostService, CreateVolumeFromSnapshotCommand cmd) {
|
||||
|
||||
String primaryStorageNameLabel = cmd.getPrimaryStoragePoolNameLabel();
|
||||
Long accountId = cmd.getAccountId();
|
||||
Long volumeId = cmd.getVolumeId();
|
||||
String secondaryStorageUrl = cmd.getSecondaryStorageUrl();
|
||||
String backedUpSnapshotUuid = cmd.getSnapshotUuid();
|
||||
String primaryStorageNameLabel = cmd.getPrimaryStoragePoolNameLabel();
|
||||
Long accountId = cmd.getAccountId();
|
||||
Long volumeId = cmd.getVolumeId();
|
||||
String secondaryStorageUrl = cmd.getSecondaryStorageUrl();
|
||||
String backedUpSnapshotUuid = cmd.getSnapshotUuid();
|
||||
|
||||
String details = null;
|
||||
boolean success = false;
|
||||
String newVolumeName = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
String details = null;
|
||||
boolean success = false;
|
||||
String newVolumeName = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
|
||||
VmwareContext context = hostService.getServiceContext(cmd);
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
|
||||
VmwareContext context = hostService.getServiceContext(cmd);
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
|
||||
ManagedObjectReference morPrimaryDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost,
|
||||
primaryStorageNameLabel);
|
||||
if (morPrimaryDs == null) {
|
||||
String msg = "Unable to find datastore: " + primaryStorageNameLabel;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
if (morPrimaryDs == null) {
|
||||
String msg = "Unable to find datastore: " + primaryStorageNameLabel;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs);
|
||||
details = createVolumeFromSnapshot(hyperHost, primaryDsMo,
|
||||
newVolumeName, accountId, volumeId, secondaryStorageUrl, backedUpSnapshotUuid);
|
||||
if (details == null) {
|
||||
success = true;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
hostService.invalidateServiceContext(context);
|
||||
}
|
||||
|
||||
s_logger.error("Unexpecpted exception ", e);
|
||||
details = "CreateVolumeFromSnapshotCommand exception: " + StringUtils.getExceptionStackInfo(e);
|
||||
}
|
||||
DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs);
|
||||
details = createVolumeFromSnapshot(hyperHost, primaryDsMo,
|
||||
newVolumeName, accountId, volumeId, secondaryStorageUrl, backedUpSnapshotUuid);
|
||||
if (details == null) {
|
||||
success = true;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
hostService.invalidateServiceContext(context);
|
||||
}
|
||||
|
||||
return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName);
|
||||
}
|
||||
s_logger.error("Unexpecpted exception ", e);
|
||||
details = "CreateVolumeFromSnapshotCommand exception: " + StringUtils.getExceptionStackInfo(e);
|
||||
}
|
||||
|
||||
return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName);
|
||||
}
|
||||
|
||||
// templateName: name in secondary storage
|
||||
// templateUuid: will be used at hypervisor layer
|
||||
private void copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost hyperHost, DatastoreMO datastoreMo, String secondaryStorageUrl,
|
||||
String templatePathAtSecondaryStorage, String templateName, String templateUuid) throws Exception {
|
||||
|
||||
s_logger.info("Executing copyTemplateFromSecondaryToPrimary. secondaryStorage: "
|
||||
|
||||
s_logger.info("Executing copyTemplateFromSecondaryToPrimary. secondaryStorage: "
|
||||
+ secondaryStorageUrl + ", templatePathAtSecondaryStorage: " + templatePathAtSecondaryStorage
|
||||
+ ", templateName: " + templateName);
|
||||
|
||||
|
||||
String secondaryMountPoint = _mountService.getMountPoint(secondaryStorageUrl);
|
||||
s_logger.info("Secondary storage mount point: " + secondaryMountPoint);
|
||||
|
||||
String srcOVAFileName = secondaryMountPoint + "/" + templatePathAtSecondaryStorage +
|
||||
|
||||
String srcOVAFileName = secondaryMountPoint + "/" + templatePathAtSecondaryStorage +
|
||||
templateName + "." + ImageFormat.OVA.getFileExtension();
|
||||
|
||||
|
||||
String srcFileName = getOVFFilePath(srcOVAFileName);
|
||||
if(srcFileName == null) {
|
||||
Script command = new Script("tar", 0, s_logger);
|
||||
|
|
@ -465,40 +465,40 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
throw new Exception(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
srcFileName = getOVFFilePath(srcOVAFileName);
|
||||
if(srcFileName == null) {
|
||||
String msg = "Unable to locate OVF file in template package directory: " + srcOVAFileName;
|
||||
if(srcFileName == null) {
|
||||
String msg = "Unable to locate OVF file in template package directory: " + srcOVAFileName;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
|
||||
String vmName = templateUuid;
|
||||
hyperHost.importVmFromOVF(srcFileName, vmName, datastoreMo, "thin");
|
||||
|
||||
|
||||
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
|
||||
if(vmMo == null) {
|
||||
String msg = "Failed to import OVA template. secondaryStorage: "
|
||||
String msg = "Failed to import OVA template. secondaryStorage: "
|
||||
+ secondaryStorageUrl + ", templatePathAtSecondaryStorage: " + templatePathAtSecondaryStorage
|
||||
+ ", templateName: " + templateName + ", templateUuid: " + templateUuid;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
|
||||
if(vmMo.createSnapshot("cloud.template.base", "Base snapshot", false, false)) {
|
||||
vmMo.setCustomFieldValue(CustomFieldConstants.CLOUD_UUID, templateUuid);
|
||||
vmMo.markAsTemplate();
|
||||
} else {
|
||||
vmMo.destroy();
|
||||
String msg = "Unable to create base snapshot for template, templateName: " + templateName + ", templateUuid: " + templateUuid;
|
||||
String msg = "Unable to create base snapshot for template, templateName: " + templateName + ", templateUuid: " + templateUuid;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
}
|
||||
|
||||
private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vmMo, long accountId, long templateId, String templateUniqueName,
|
||||
|
||||
private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vmMo, long accountId, long templateId, String templateUniqueName,
|
||||
String secStorageUrl, String volumePath, String workerVmName) throws Exception {
|
||||
|
||||
|
||||
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl);
|
||||
String installPath = getTemplateRelativeDirInSecStorage(accountId, templateId);
|
||||
String installFullPath = secondaryMountPoint + "/" + installPath;
|
||||
|
|
@ -506,16 +506,16 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
Script command = new Script(false, "mkdir", _timeout, s_logger);
|
||||
command.add("-p");
|
||||
command.add(installFullPath);
|
||||
|
||||
|
||||
String result = command.execute();
|
||||
if(result != null) {
|
||||
String msg = "unable to prepare template directory: "
|
||||
String msg = "unable to prepare template directory: "
|
||||
+ installPath + ", storage: " + secStorageUrl + ", error msg: " + result;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VirtualMachineMO clonedVm = null;
|
||||
try {
|
||||
Pair<VirtualDisk, String> volumeDeviceInfo = vmMo.getDiskDevice(volumePath, false);
|
||||
|
|
@ -524,15 +524,15 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
|
||||
if(!vmMo.createSnapshot(templateUniqueName, "Temporary snapshot for template creation", false, false)) {
|
||||
String msg = "Unable to take snapshot for creating template from volume. volume path: " + volumePath;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
|
||||
// 4 MB is the minimum requirement for VM memory in VMware
|
||||
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(),
|
||||
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(),
|
||||
VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
|
||||
clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName);
|
||||
if(clonedVm == null) {
|
||||
|
|
@ -540,9 +540,9 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
|
||||
clonedVm.exportVm(secondaryMountPoint + "/" + installPath, templateUniqueName, true, false);
|
||||
|
||||
|
||||
long physicalSize = new File(installFullPath + "/" + templateUniqueName + ".ova").length();
|
||||
VmdkProcessor processor = new VmdkProcessor();
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
|
|
@ -552,54 +552,54 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
|
||||
postCreatePrivateTemplate(installFullPath, templateId, templateUniqueName, physicalSize, virtualSize);
|
||||
return new Ternary<String, Long, Long>(installPath + "/" + templateUniqueName + ".ova", physicalSize, virtualSize);
|
||||
|
||||
|
||||
} finally {
|
||||
if(clonedVm != null) {
|
||||
clonedVm.detachAllDisks();
|
||||
clonedVm.destroy();
|
||||
}
|
||||
|
||||
|
||||
vmMo.removeSnapshot(templateUniqueName, false);
|
||||
}
|
||||
}
|
||||
|
||||
private Ternary<String, Long, Long> createTemplateFromSnapshot(long accountId, long templateId, String templateUniqueName,
|
||||
|
||||
private Ternary<String, Long, Long> createTemplateFromSnapshot(long accountId, long templateId, String templateUniqueName,
|
||||
String secStorageUrl, long volumeId, String backedUpSnapshotUuid) throws Exception {
|
||||
|
||||
|
||||
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl);
|
||||
String installPath = getTemplateRelativeDirInSecStorage(accountId, templateId);
|
||||
String installFullPath = secondaryMountPoint + "/" + installPath;
|
||||
String installFullName = installFullPath + "/" + templateUniqueName + ".ova";
|
||||
String snapshotFullName = secondaryMountPoint + "/" + getSnapshotRelativeDirInSecStorage(accountId, volumeId)
|
||||
String snapshotFullName = secondaryMountPoint + "/" + getSnapshotRelativeDirInSecStorage(accountId, volumeId)
|
||||
+ "/" + backedUpSnapshotUuid + ".ova";
|
||||
String result;
|
||||
Script command;
|
||||
|
||||
|
||||
synchronized(installPath.intern()) {
|
||||
command = new Script(false, "mkdir", _timeout, s_logger);
|
||||
command.add("-p");
|
||||
command.add(installFullPath);
|
||||
|
||||
|
||||
result = command.execute();
|
||||
if(result != null) {
|
||||
String msg = "unable to prepare template directory: "
|
||||
String msg = "unable to prepare template directory: "
|
||||
+ installPath + ", storage: " + secStorageUrl + ", error msg: " + result;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
command = new Script(false, "cp", _timeout, s_logger);
|
||||
command.add(snapshotFullName);
|
||||
command.add(installFullName);
|
||||
result = command.execute();
|
||||
if(result != null) {
|
||||
String msg = "unable to copy snapshot " + snapshotFullName + " to " + installFullPath;
|
||||
String msg = "unable to copy snapshot " + snapshotFullName + " to " + installFullPath;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
|
||||
// untar OVA file at template directory
|
||||
command = new Script("tar", 0, s_logger);
|
||||
command.add("--no-same-owner");
|
||||
|
|
@ -608,12 +608,12 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
s_logger.info("Executing command: " + command.toString());
|
||||
result = command.execute();
|
||||
if(result != null) {
|
||||
String msg = "unable to untar snapshot " + snapshotFullName + " to "
|
||||
+ installFullPath;
|
||||
String msg = "unable to untar snapshot " + snapshotFullName + " to "
|
||||
+ installFullPath;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
|
||||
long physicalSize = new File(installFullPath + "/" + templateUniqueName + ".ova").length();
|
||||
VmdkProcessor processor = new VmdkProcessor();
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
|
|
@ -623,45 +623,45 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
|
||||
postCreatePrivateTemplate(installFullPath, templateId, templateUniqueName, physicalSize, virtualSize);
|
||||
return new Ternary<String, Long, Long>(installPath + "/" + templateUniqueName + ".ova", physicalSize, virtualSize);
|
||||
|
||||
|
||||
} catch(Exception e) {
|
||||
// TODO, clean up left over files
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private void postCreatePrivateTemplate(String installFullPath, long templateId,
|
||||
|
||||
private void postCreatePrivateTemplate(String installFullPath, long templateId,
|
||||
String templateName, long size, long virtualSize) throws Exception {
|
||||
|
||||
// TODO a bit ugly here
|
||||
BufferedWriter out = null;
|
||||
try {
|
||||
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(installFullPath + "/template.properties")));
|
||||
out.write("filename=" + templateName + ".ova");
|
||||
out.write("filename=" + templateName + ".ova");
|
||||
out.newLine();
|
||||
out.write("description=");
|
||||
out.write("description=");
|
||||
out.newLine();
|
||||
out.write("checksum=");
|
||||
out.write("checksum=");
|
||||
out.newLine();
|
||||
out.write("hvm=false");
|
||||
out.write("hvm=false");
|
||||
out.newLine();
|
||||
out.write("size=" + size);
|
||||
out.write("size=" + size);
|
||||
out.newLine();
|
||||
out.write("ova=true");
|
||||
out.write("ova=true");
|
||||
out.newLine();
|
||||
out.write("id=" + templateId);
|
||||
out.write("id=" + templateId);
|
||||
out.newLine();
|
||||
out.write("public=false");
|
||||
out.write("public=false");
|
||||
out.newLine();
|
||||
out.write("ova.filename=" + templateName + ".ova");
|
||||
out.write("ova.filename=" + templateName + ".ova");
|
||||
out.newLine();
|
||||
out.write("uniquename=" + templateName);
|
||||
out.newLine();
|
||||
out.write("ova.virtualsize=" + virtualSize);
|
||||
out.write("ova.virtualsize=" + virtualSize);
|
||||
out.newLine();
|
||||
out.write("virtualsize=" + virtualSize);
|
||||
out.write("virtualsize=" + virtualSize);
|
||||
out.newLine();
|
||||
out.write("ova.size=" + size);
|
||||
out.write("ova.size=" + size);
|
||||
out.newLine();
|
||||
} finally {
|
||||
if(out != null)
|
||||
|
|
@ -669,21 +669,21 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
}
|
||||
}
|
||||
|
||||
private String createVolumeFromSnapshot(VmwareHypervisorHost hyperHost, DatastoreMO primaryDsMo, String newVolumeName,
|
||||
private String createVolumeFromSnapshot(VmwareHypervisorHost hyperHost, DatastoreMO primaryDsMo, String newVolumeName,
|
||||
long accountId, long volumeId, String secStorageUrl, String snapshotBackupUuid) throws Exception {
|
||||
|
||||
restoreVolumeFromSecStorage(hyperHost, primaryDsMo, newVolumeName,
|
||||
|
||||
restoreVolumeFromSecStorage(hyperHost, primaryDsMo, newVolumeName,
|
||||
secStorageUrl, getSnapshotRelativeDirInSecStorage(accountId, volumeId), snapshotBackupUuid);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void restoreVolumeFromSecStorage(VmwareHypervisorHost hyperHost, DatastoreMO primaryDsMo, String newVolumeName,
|
||||
|
||||
private void restoreVolumeFromSecStorage(VmwareHypervisorHost hyperHost, DatastoreMO primaryDsMo, String newVolumeName,
|
||||
String secStorageUrl, String secStorageDir, String backupName) throws Exception {
|
||||
|
||||
|
||||
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl);
|
||||
String srcOVAFileName = secondaryMountPoint + "/" + secStorageDir + "/"
|
||||
String srcOVAFileName = secondaryMountPoint + "/" + secStorageDir + "/"
|
||||
+ backupName + "." + ImageFormat.OVA.getFileExtension();
|
||||
|
||||
|
||||
String srcFileName = getOVFFilePath(srcOVAFileName);
|
||||
if(srcFileName == null) {
|
||||
Script command = new Script("tar", 0, s_logger);
|
||||
|
|
@ -698,21 +698,21 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
throw new Exception(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
srcFileName = getOVFFilePath(srcOVAFileName);
|
||||
if(srcFileName == null) {
|
||||
String msg = "Unable to locate OVF file in template package directory: " + srcOVAFileName;
|
||||
String msg = "Unable to locate OVF file in template package directory: " + srcOVAFileName;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
|
||||
VirtualMachineMO clonedVm = null;
|
||||
try {
|
||||
hyperHost.importVmFromOVF(srcFileName, newVolumeName, primaryDsMo, "thin");
|
||||
clonedVm = hyperHost.findVmOnHyperHost(newVolumeName);
|
||||
if(clonedVm == null)
|
||||
throw new Exception("Unable to create container VM for volume creation");
|
||||
|
||||
|
||||
clonedVm.moveAllVmDiskFiles(primaryDsMo, "", false);
|
||||
clonedVm.detachAllDisks();
|
||||
} finally {
|
||||
|
|
@ -722,24 +722,24 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String backupSnapshotToSecondaryStorage(VirtualMachineMO vmMo, long accountId, long volumeId,
|
||||
String volumePath, String snapshotUuid, String secStorageUrl,
|
||||
|
||||
private String backupSnapshotToSecondaryStorage(VirtualMachineMO vmMo, long accountId, long volumeId,
|
||||
String volumePath, String snapshotUuid, String secStorageUrl,
|
||||
String prevSnapshotUuid, String prevBackupUuid, String workerVmName) throws Exception {
|
||||
|
||||
|
||||
String backupUuid = UUID.randomUUID().toString();
|
||||
exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl,
|
||||
exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl,
|
||||
getSnapshotRelativeDirInSecStorage(accountId, volumeId), backupUuid, workerVmName);
|
||||
return backupUuid;
|
||||
}
|
||||
|
||||
private void exportVolumeToSecondaryStroage(VirtualMachineMO vmMo, String volumePath,
|
||||
|
||||
private void exportVolumeToSecondaryStroage(VirtualMachineMO vmMo, String volumePath,
|
||||
String secStorageUrl, String secStorageDir, String exportName,
|
||||
String workerVmName) throws Exception {
|
||||
|
||||
|
||||
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl);
|
||||
String exportPath = secondaryMountPoint + "/" + secStorageDir;
|
||||
|
||||
|
||||
synchronized(exportPath.intern()) {
|
||||
if(!new File(exportPath).exists()) {
|
||||
Script command = new Script(false, "mkdir", _timeout, s_logger);
|
||||
|
|
@ -752,16 +752,16 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
|
||||
VirtualMachineMO clonedVm = null;
|
||||
try {
|
||||
|
||||
|
||||
Pair<VirtualDisk, String> volumeDeviceInfo = vmMo.getDiskDevice(volumePath, false);
|
||||
if(volumeDeviceInfo == null) {
|
||||
String msg = "Unable to find related disk device for volume. volume path: " + volumePath;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
|
||||
// 4 MB is the minimum requirement for VM memory in VMware
|
||||
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(),
|
||||
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(),
|
||||
VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
|
||||
clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName);
|
||||
if(clonedVm == null) {
|
||||
|
|
@ -769,7 +769,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
|
||||
clonedVm.exportVm(exportPath, exportName, true, true);
|
||||
} finally {
|
||||
if(clonedVm != null) {
|
||||
|
|
@ -778,7 +778,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String deleteSnapshotOnSecondaryStorge(long accountId, long volumeId, String secStorageUrl, String backupUuid) throws Exception {
|
||||
|
||||
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl);
|
||||
|
|
@ -787,18 +787,18 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
if(file.exists()) {
|
||||
if(file.delete())
|
||||
return null;
|
||||
|
||||
|
||||
} else {
|
||||
return "Backup file does not exist. backupUuid: " + backupUuid;
|
||||
}
|
||||
|
||||
|
||||
return "Failed to delete snapshot backup file, backupUuid: " + backupUuid;
|
||||
}
|
||||
|
||||
private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostService, VmwareHypervisorHost hyperHost, CopyVolumeCommand cmd,
|
||||
String vmName, long volumeId, String poolId, String volumePath,
|
||||
|
||||
private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostService, VmwareHypervisorHost hyperHost, CopyVolumeCommand cmd,
|
||||
String vmName, long volumeId, String poolId, String volumePath,
|
||||
String secStorageUrl, String workerVmName) throws Exception {
|
||||
|
||||
|
||||
String volumeFolder = String.valueOf(volumeId) + "/";
|
||||
VirtualMachineMO workerVm=null;
|
||||
VirtualMachineMO vmMo=null;
|
||||
|
|
@ -822,21 +822,21 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
vmConfig.setName(workerVmName);
|
||||
vmConfig.setMemoryMB((long) 4);
|
||||
vmConfig.setNumCPUs(1);
|
||||
vmConfig.setGuestId(VirtualMachineGuestOsIdentifier._otherGuest.toString());
|
||||
vmConfig.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST.value());
|
||||
VirtualMachineFileInfo fileInfo = new VirtualMachineFileInfo();
|
||||
fileInfo.setVmPathName(String.format("[%s]", dsMo.getName()));
|
||||
vmConfig.setFiles(fileInfo);
|
||||
|
||||
// Scsi controller
|
||||
VirtualLsiLogicController scsiController = new VirtualLsiLogicController();
|
||||
scsiController.setSharedBus(VirtualSCSISharing.noSharing);
|
||||
scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
|
||||
scsiController.setBusNumber(0);
|
||||
scsiController.setKey(1);
|
||||
VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec();
|
||||
scsiControllerSpec.setDevice(scsiController);
|
||||
scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
|
||||
vmConfig.setDeviceChange(new VirtualDeviceConfigSpec[] { scsiControllerSpec });
|
||||
|
||||
scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
|
||||
vmConfig.getDeviceChange().add(scsiControllerSpec);
|
||||
|
||||
hyperHost.createVm(vmConfig);
|
||||
workerVm = hyperHost.findVmOnHyperHost(workerVmName);
|
||||
if (workerVm == null) {
|
||||
|
|
@ -844,7 +844,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
|
||||
//attach volume to worker VM
|
||||
String datastoreVolumePath = String.format("[%s] %s.vmdk", dsMo.getName(), volumePath);
|
||||
workerVm.attachDisk(new String[] { datastoreVolumePath }, morDs);
|
||||
|
|
@ -853,7 +853,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
|
||||
vmMo.createSnapshot(exportName, "Temporary snapshot for copy-volume command", false, false);
|
||||
|
||||
exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl, "volumes/" + volumeFolder, exportName,
|
||||
exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl, "volumes/" + volumeFolder, exportName,
|
||||
hostService.getWorkerName(hyperHost.getContext(), cmd, 1));
|
||||
return new Pair<String, String>(volumeFolder, exportName);
|
||||
|
||||
|
|
@ -867,16 +867,16 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
}
|
||||
}
|
||||
|
||||
private Pair<String, String> copyVolumeFromSecStorage(VmwareHypervisorHost hyperHost, long volumeId,
|
||||
private Pair<String, String> copyVolumeFromSecStorage(VmwareHypervisorHost hyperHost, long volumeId,
|
||||
DatastoreMO dsMo, String secStorageUrl, String exportName) throws Exception {
|
||||
|
||||
String volumeFolder = String.valueOf(volumeId) + "/";
|
||||
String newVolume = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
restoreVolumeFromSecStorage(hyperHost, dsMo, newVolume, secStorageUrl, "volumes/" + volumeFolder, exportName);
|
||||
|
||||
|
||||
return new Pair<String, String>(volumeFolder, newVolume);
|
||||
}
|
||||
|
||||
|
||||
private String getOVFFilePath(String srcOVAFileName) {
|
||||
File file = new File(srcOVAFileName);
|
||||
assert(_storage != null);
|
||||
|
|
@ -891,11 +891,11 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static String getTemplateRelativeDirInSecStorage(long accountId, long templateId) {
|
||||
return "template/tmpl/" + accountId + "/" + templateId;
|
||||
}
|
||||
|
||||
|
||||
private static String getSnapshotRelativeDirInSecStorage(long accountId, long volumeId) {
|
||||
return "snapshots/" + accountId + "/" + volumeId;
|
||||
}
|
||||
|
|
@ -912,18 +912,18 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
Map<String, String> mapNewDisk = new HashMap<String, String>();
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
|
||||
|
||||
|
||||
// wait if there are already VM snapshot task running
|
||||
ManagedObjectReference taskmgr = context.getServiceContent().getTaskManager();
|
||||
ManagedObjectReference[] tasks = (ManagedObjectReference[]) context.getServiceUtil().getDynamicProperty(taskmgr, "recentTask");
|
||||
ManagedObjectReference[] tasks = (ManagedObjectReference[]) context.getVimClient().getDynamicProperty(taskmgr, "recentTask");
|
||||
for (ManagedObjectReference taskMor : tasks) {
|
||||
TaskInfo info = (TaskInfo) (context.getServiceUtil().getDynamicProperty(taskMor, "info"));
|
||||
TaskInfo info = (TaskInfo) (context.getVimClient().getDynamicProperty(taskMor, "info"));
|
||||
if(info.getEntityName().equals(cmd.getVmName()) && info.getName().equalsIgnoreCase("CreateSnapshot_Task")){
|
||||
s_logger.debug("There is already a VM snapshot task running, wait for it");
|
||||
context.getServiceUtil().waitForTask(taskMor);
|
||||
context.getVimClient().waitForTask(taskMor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
vmMo = hyperHost.findVmOnHyperHost(vmName);
|
||||
if(vmMo == null)
|
||||
vmMo = hyperHost.findVmOnPeerHyperHost(vmName);
|
||||
|
|
@ -952,7 +952,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
mapNewDisk.put(s[0], vmdkName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// update volume path using maps
|
||||
for (VolumeTO volumeTO : volumeTOs) {
|
||||
String parentUUID = volumeTO.getPath();
|
||||
|
|
@ -1003,7 +1003,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
}
|
||||
}
|
||||
s_logger.debug("snapshot: " + vmSnapshotName + " is removed");
|
||||
// after removed snapshot, the volumes' paths have been changed for the VM, needs to report new paths to manager
|
||||
// after removed snapshot, the volumes' paths have been changed for the VM, needs to report new paths to manager
|
||||
VirtualDisk[] vdisks = vmMo.getAllDiskDevice();
|
||||
for (int i = 0; i < vdisks.length; i++) {
|
||||
@SuppressWarnings("deprecation")
|
||||
|
|
@ -1045,18 +1045,18 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
Map<String, String> mapNewDisk = new HashMap<String, String>();
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
|
||||
|
||||
|
||||
// wait if there are already VM revert task running
|
||||
ManagedObjectReference taskmgr = context.getServiceContent().getTaskManager();
|
||||
ManagedObjectReference[] tasks = (ManagedObjectReference[]) context.getServiceUtil().getDynamicProperty(taskmgr, "recentTask");
|
||||
ManagedObjectReference[] tasks = (ManagedObjectReference[]) context.getVimClient().getDynamicProperty(taskmgr, "recentTask");
|
||||
for (ManagedObjectReference taskMor : tasks) {
|
||||
TaskInfo info = (TaskInfo) (context.getServiceUtil().getDynamicProperty(taskMor, "info"));
|
||||
TaskInfo info = (TaskInfo) (context.getVimClient().getDynamicProperty(taskMor, "info"));
|
||||
if(info.getEntityName().equals(cmd.getVmName()) && info.getName().equalsIgnoreCase("RevertToSnapshot_Task")){
|
||||
s_logger.debug("There is already a VM snapshot task running, wait for it");
|
||||
context.getServiceUtil().waitForTask(taskMor);
|
||||
context.getVimClient().waitForTask(taskMor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HostMO hostMo = (HostMO) hyperHost;
|
||||
vmMo = hyperHost.findVmOnHyperHost(vmName);
|
||||
if(vmMo == null)
|
||||
|
|
@ -1113,7 +1113,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private VirtualMachineMO createWorkingVM(DatastoreMO dsMo, VmwareHypervisorHost hyperHost) throws Exception {
|
||||
String uniqueName = UUID.randomUUID().toString();
|
||||
VirtualMachineMO workingVM = null;
|
||||
|
|
@ -1121,20 +1121,20 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
vmConfig.setName(uniqueName);
|
||||
vmConfig.setMemoryMB((long) 4);
|
||||
vmConfig.setNumCPUs(1);
|
||||
vmConfig.setGuestId(VirtualMachineGuestOsIdentifier._otherGuest.toString());
|
||||
vmConfig.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST.toString());
|
||||
VirtualMachineFileInfo fileInfo = new VirtualMachineFileInfo();
|
||||
fileInfo.setVmPathName(String.format("[%s]", dsMo.getName()));
|
||||
vmConfig.setFiles(fileInfo);
|
||||
|
||||
VirtualLsiLogicController scsiController = new VirtualLsiLogicController();
|
||||
scsiController.setSharedBus(VirtualSCSISharing.noSharing);
|
||||
scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
|
||||
scsiController.setBusNumber(0);
|
||||
scsiController.setKey(1);
|
||||
VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec();
|
||||
scsiControllerSpec.setDevice(scsiController);
|
||||
scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
|
||||
scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
|
||||
|
||||
vmConfig.setDeviceChange(new VirtualDeviceConfigSpec[] { scsiControllerSpec });
|
||||
vmConfig.getDeviceChange().add(scsiControllerSpec);
|
||||
hyperHost.createVm(vmConfig);
|
||||
workingVM = hyperHost.findVmOnHyperHost(uniqueName);
|
||||
return workingVM;
|
||||
|
|
|
|||
|
|
@ -23,12 +23,10 @@ import org.apache.log4j.Logger;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.hypervisor.vmware.manager.VmwareManager;
|
||||
import com.cloud.hypervisor.vmware.manager.VmwareManagerImpl;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareClient;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.cloud.utils.StringUtils;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
|
||||
import com.vmware.apputils.version.ExtendedAppUtil;
|
||||
@Component
|
||||
public class VmwareContextFactory {
|
||||
|
||||
|
|
@ -56,15 +54,15 @@ public class VmwareContextFactory {
|
|||
assert(vCenterPassword != null);
|
||||
|
||||
String serviceUrl = "https://" + vCenterAddress + "/sdk/vimService";
|
||||
String[] params = new String[] {"--url", serviceUrl, "--username", vCenterUserName, "--password", vCenterPassword };
|
||||
//String[] params = new String[] {"--url", serviceUrl, "--username", vCenterUserName, "--password", vCenterPassword };
|
||||
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("initialize VmwareContext. url: " + serviceUrl + ", username: " + vCenterUserName + ", password: " + StringUtils.getMaskedPasswordForDisplay(vCenterPassword));
|
||||
|
||||
ExtendedAppUtil appUtil = ExtendedAppUtil.initialize(vCenterAddress + "-" + s_seq++, params);
|
||||
VmwareClient vimClient = new VmwareClient(vCenterAddress + "-" + s_seq++);
|
||||
vimClient.connect(serviceUrl, vCenterUserName, vCenterPassword);
|
||||
|
||||
appUtil.connect();
|
||||
VmwareContext context = new VmwareContext(appUtil, vCenterAddress);
|
||||
VmwareContext context = new VmwareContext(vimClient, vCenterAddress);
|
||||
context.registerStockObject(VmwareManager.CONTEXT_STOCK_NAME, s_vmwareMgr);
|
||||
|
||||
context.registerStockObject("serviceconsole", s_vmwareMgr.getServiceConsolePortGroupName());
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
// 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
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.hypervisor.vmware.resource;
|
||||
|
|
@ -24,6 +24,7 @@ import java.net.URI;
|
|||
import java.nio.channels.SocketChannel;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
|
@ -247,7 +248,9 @@ import com.vmware.vim25.PerfMetricSeries;
|
|||
import com.vmware.vim25.PerfQuerySpec;
|
||||
import com.vmware.vim25.PerfSampleInfo;
|
||||
import com.vmware.vim25.RuntimeFault;
|
||||
import com.vmware.vim25.RuntimeFaultFaultMsg;
|
||||
import com.vmware.vim25.ToolsUnavailable;
|
||||
import com.vmware.vim25.ToolsUnavailableFaultMsg;
|
||||
import com.vmware.vim25.VimPortType;
|
||||
import com.vmware.vim25.VirtualDevice;
|
||||
import com.vmware.vim25.VirtualDeviceConfigSpec;
|
||||
|
|
@ -270,7 +273,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
protected String _name;
|
||||
|
||||
protected final long _ops_timeout = 900000; // 15 minutes time out to time
|
||||
protected final int _shutdown_waitMs = 300000; // wait up to 5 minutes for shutdown
|
||||
|
||||
protected final int _shutdown_waitMs = 300000; // wait up to 5 minutes for shutdown
|
||||
|
||||
// out an operation
|
||||
protected final int _retry = 24;
|
||||
|
|
@ -297,7 +301,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
protected boolean _reserveMem = false;
|
||||
protected boolean _recycleHungWorker = false;
|
||||
protected DiskControllerType _rootDiskController = DiskControllerType.ide;
|
||||
protected DiskControllerType _rootDiskController = DiskControllerType.ide;
|
||||
|
||||
protected ManagedObjectReference _morHyperHost;
|
||||
protected VmwareContext _serviceContext;
|
||||
|
|
@ -313,9 +317,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
protected static HashMap<VirtualMachinePowerState, State> s_statesTable;
|
||||
static {
|
||||
s_statesTable = new HashMap<VirtualMachinePowerState, State>();
|
||||
s_statesTable.put(VirtualMachinePowerState.poweredOn, State.Running);
|
||||
s_statesTable.put(VirtualMachinePowerState.poweredOff, State.Stopped);
|
||||
s_statesTable.put(VirtualMachinePowerState.suspended, State.Stopped);
|
||||
s_statesTable.put(VirtualMachinePowerState.POWERED_ON, State.Running);
|
||||
s_statesTable.put(VirtualMachinePowerState.POWERED_OFF, State.Stopped);
|
||||
s_statesTable.put(VirtualMachinePowerState.SUSPENDED, State.Stopped);
|
||||
}
|
||||
|
||||
public VmwareResource() {
|
||||
|
|
@ -324,6 +328,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
@Override
|
||||
public Answer executeRequest(Command cmd) {
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("Begin executeRequest(), cmd: " + cmd.getClass().getSimpleName());
|
||||
|
||||
|
|
@ -481,14 +486,14 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
synchronized (this) {
|
||||
try {
|
||||
JmxUtil.registerMBean("VMware " + _morHyperHost.get_value(), "Command " + cmdSequence + "-" + cmd.getClass().getSimpleName(), mbean);
|
||||
JmxUtil.registerMBean("VMware " + _morHyperHost.getValue(), "Command " + cmdSequence + "-" + cmd.getClass().getSimpleName(), mbean);
|
||||
_cmdMBeans.add(mbean);
|
||||
|
||||
if (_cmdMBeans.size() >= MAX_CMD_MBEAN) {
|
||||
PropertyMapDynamicBean mbeanToRemove = _cmdMBeans.get(0);
|
||||
_cmdMBeans.remove(0);
|
||||
|
||||
JmxUtil.unregisterMBean("VMware " + _morHyperHost.get_value(), "Command " + mbeanToRemove.getProp("Sequence") + "-" + mbeanToRemove.getProp("Name"));
|
||||
JmxUtil.unregisterMBean("VMware " + _morHyperHost.getValue(), "Command " + mbeanToRemove.getProp("Sequence") + "-" + mbeanToRemove.getProp("Name"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if(s_logger.isTraceEnabled())
|
||||
|
|
@ -500,12 +505,13 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
NDC.pop();
|
||||
}
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("End executeRequest(), cmd: " + cmd.getClass().getSimpleName());
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
|
||||
private Answer execute(ResizeVolumeCommand cmd) {
|
||||
String path = cmd.getPath();
|
||||
String vmName = cmd.getInstanceName();
|
||||
|
|
@ -533,15 +539,15 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
if (newSize < oldSize){
|
||||
throw new Exception("VMware doesn't support shrinking volume from larger size: " + oldSize+ " MB to a smaller size: " + newSize + " MB");
|
||||
} else if(newSize == oldSize){
|
||||
return new ResizeVolumeAnswer(cmd, true, "success", newSize*1024);
|
||||
return new ResizeVolumeAnswer(cmd, true, "success", newSize*1024);
|
||||
}
|
||||
disk.setCapacityInKB(newSize);
|
||||
|
||||
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
|
||||
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
|
||||
deviceConfigSpec.setDevice(disk);
|
||||
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.edit);
|
||||
vmConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec[] { deviceConfigSpec });
|
||||
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
|
||||
vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
|
||||
if (!vmMo.configureVm(vmConfigSpec)) {
|
||||
throw new Exception("Failed to configure VM to resize disk. vmName: " + vmName);
|
||||
}
|
||||
|
|
@ -613,6 +619,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
if (!resultPair.first()) {
|
||||
throw new Exception(" vpc network usage plugin call failed ");
|
||||
|
||||
}
|
||||
|
||||
if (option.equals("get") || option.equals("vpn")) {
|
||||
|
|
@ -633,7 +640,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
return new NetworkUsageAnswer(cmd, "success", 0L, 0L);
|
||||
} catch (Throwable e) {
|
||||
s_logger.error("Unable to execute NetworkUsage command on DomR (" + privateIp + "), domR may not be ready yet. failure due to "
|
||||
|
||||
s_logger.error("Unable to execute NetworkUsage command on DomR (" + privateIp + "), domR may not be ready yet. failure due to "
|
||||
+ VmwareHelper.getExceptionMessage(e), e);
|
||||
}
|
||||
return new NetworkUsageAnswer(cmd, "success", 0L, 0L);
|
||||
|
|
@ -730,6 +738,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (!result.first()) {
|
||||
s_logger.error("SetFirewallRulesCommand failure on setting one rule. args: "
|
||||
+ args);
|
||||
|
|
@ -739,7 +748,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
|
||||
return new SetFirewallRulesAnswer(cmd, false, results);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
s_logger.error("SetFirewallRulesCommand(args: " + args
|
||||
+ ") failed on setting one rule due to "
|
||||
|
|
@ -749,10 +758,10 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
results[i] = "Failed";
|
||||
}
|
||||
return new SetFirewallRulesAnswer(cmd, false, results);
|
||||
}
|
||||
}
|
||||
|
||||
return new SetFirewallRulesAnswer(cmd, true, results);
|
||||
}
|
||||
}
|
||||
|
||||
protected Answer execute(SetStaticNatRulesCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
|
|
@ -1336,12 +1345,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
|
||||
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
|
||||
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
|
||||
deviceConfigSpecArray[0] = new VirtualDeviceConfigSpec();
|
||||
deviceConfigSpecArray[0].setDevice(nic);
|
||||
deviceConfigSpecArray[0].setOperation(VirtualDeviceConfigSpecOperation.add);
|
||||
//VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
|
||||
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
|
||||
deviceConfigSpec.setDevice(nic);
|
||||
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
|
||||
|
||||
vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
|
||||
vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
|
||||
if(!vmMo.configureVm(vmConfigSpec)) {
|
||||
throw new Exception("Failed to configure devices when running PlugNicCommand");
|
||||
}
|
||||
|
|
@ -1384,12 +1393,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
return new UnPlugNicAnswer(cmd, true, "success");
|
||||
}
|
||||
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
|
||||
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
|
||||
deviceConfigSpecArray[0] = new VirtualDeviceConfigSpec();
|
||||
deviceConfigSpecArray[0].setDevice(nic);
|
||||
deviceConfigSpecArray[0].setOperation(VirtualDeviceConfigSpecOperation.remove);
|
||||
//VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
|
||||
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
|
||||
deviceConfigSpec.setDevice(nic);
|
||||
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
|
||||
|
||||
vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
|
||||
vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
|
||||
if(!vmMo.configureVm(vmConfigSpec)) {
|
||||
throw new Exception("Failed to configure devices when running unplugNicCommand");
|
||||
}
|
||||
|
|
@ -1527,6 +1536,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
if (removeVif) {
|
||||
|
||||
|
||||
String nicMasksStr = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_NIC_MASK);
|
||||
int nicMasks = Integer.parseInt(nicMasksStr);
|
||||
nicMasks &= ~(1 << publicNicInfo.first().intValue());
|
||||
|
|
@ -1582,12 +1592,13 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
|
||||
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
|
||||
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
|
||||
deviceConfigSpecArray[0] = new VirtualDeviceConfigSpec();
|
||||
deviceConfigSpecArray[0].setDevice(device);
|
||||
deviceConfigSpecArray[0].setOperation(VirtualDeviceConfigSpecOperation.edit);
|
||||
|
||||
vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
|
||||
//VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
|
||||
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
|
||||
deviceConfigSpec.setDevice(device);
|
||||
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
|
||||
|
||||
vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
|
||||
if(!vmMo.configureVm(vmConfigSpec)) {
|
||||
throw new Exception("Failed to configure devices when plugPublicNic");
|
||||
}
|
||||
|
|
@ -1674,7 +1685,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
protected Answer execute(SavePasswordCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource SavePasswordCommand. vmName: " + cmd.getVmName() + ", vmIp: " + cmd.getVmIpAddress() + ", password: "
|
||||
|
||||
s_logger.info("Executing resource SavePasswordCommand. vmName: " + cmd.getVmName() + ", vmIp: " + cmd.getVmIpAddress() + ", password: "
|
||||
+ StringUtils.getMaskedPasswordForDisplay(cmd.getPassword()));
|
||||
}
|
||||
|
||||
|
|
@ -1720,6 +1732,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
|
||||
// ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/root/edithosts.sh $mac $ip $vm $dfltrt $ns $staticrt" >/dev/null
|
||||
|
||||
String args = " -m " + cmd.getVmMac();
|
||||
if (cmd.getVmIpAddress() != null) {
|
||||
args += " -4 " + cmd.getVmIpAddress();
|
||||
|
|
@ -1737,7 +1750,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
if (cmd.getStaticRoutes() != null) {
|
||||
args += " -s " + cmd.getStaticRoutes();
|
||||
}
|
||||
|
||||
|
||||
if (cmd.getVmIp6Address() != null) {
|
||||
args += " -6 " + cmd.getVmIp6Address();
|
||||
args += " -u " + cmd.getDuid();
|
||||
|
|
@ -2097,7 +2110,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
assert (vmSpec.getMinSpeed() != null) && (rootDiskDataStoreDetails != null);
|
||||
if (!hyperHost.createBlankVm(vmName, vmSpec.getCpus(), vmSpec.getMaxSpeed().intValue(),
|
||||
vmSpec.getMinSpeed(), vmSpec.getLimitCpuUse(),(int)(vmSpec.getMaxRam()/(1024*1024)), ramMb,
|
||||
translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).toString(), rootDiskDataStoreDetails.first(), false)) {
|
||||
translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(), rootDiskDataStoreDetails.first(), false)) {
|
||||
throw new Exception("Failed to create VM. vmName: " + vmName);
|
||||
}
|
||||
}
|
||||
|
|
@ -2129,8 +2142,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
int ramMb = (int) (vmSpec.getMinRam() / (1024 * 1024));
|
||||
VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(),
|
||||
vmSpec.getMinSpeed(),(int) (vmSpec.getMaxRam()/(1024*1024)), ramMb,
|
||||
translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).toString(), vmSpec.getLimitCpuUse());
|
||||
|
||||
translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(), vmSpec.getLimitCpuUse());
|
||||
|
||||
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[totalChangeDevices];
|
||||
int i = 0;
|
||||
int ideControllerKey = vmMo.getIDEDeviceControllerKey();
|
||||
|
|
@ -2156,17 +2169,17 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
DatastoreMO secDsMo = new DatastoreMO(hyperHost.getContext(), morSecDs);
|
||||
|
||||
deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
|
||||
Pair<VirtualDevice, Boolean> isoInfo = VmwareHelper.prepareIsoDevice(vmMo, String.format("[%s] systemvm/%s", secDsMo.getName(), mgr.getSystemVMIsoFileNameOnDatastore()),
|
||||
Pair<VirtualDevice, Boolean> isoInfo = VmwareHelper.prepareIsoDevice(vmMo, String.format("[%s] systemvm/%s", secDsMo.getName(), mgr.getSystemVMIsoFileNameOnDatastore()),
|
||||
secDsMo.getMor(), true, true, i, i + 1);
|
||||
deviceConfigSpecArray[i].setDevice(isoInfo.first());
|
||||
if (isoInfo.second()) {
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("Prepare ISO volume at new device " + _gson.toJson(isoInfo.first()));
|
||||
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.add);
|
||||
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD);
|
||||
} else {
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("Prepare ISO volume at existing device " + _gson.toJson(isoInfo.first()));
|
||||
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.edit);
|
||||
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.EDIT);
|
||||
}
|
||||
i++;
|
||||
} else {
|
||||
|
|
@ -2182,11 +2195,11 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
if (isoInfo.second()) {
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("Prepare ISO volume at new device " + _gson.toJson(isoInfo.first()));
|
||||
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.add);
|
||||
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD);
|
||||
} else {
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("Prepare ISO volume at existing device " + _gson.toJson(isoInfo.first()));
|
||||
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.edit);
|
||||
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.EDIT);
|
||||
}
|
||||
} else {
|
||||
deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
|
||||
|
|
@ -2196,12 +2209,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("Prepare ISO volume at existing device " + _gson.toJson(isoInfo.first()));
|
||||
|
||||
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.add);
|
||||
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD);
|
||||
} else {
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("Prepare ISO volume at existing device " + _gson.toJson(isoInfo.first()));
|
||||
|
||||
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.edit);
|
||||
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.EDIT);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
|
|
@ -2253,7 +2266,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
device = VmwareHelper.prepareDiskDevice(vmMo, controllerKey, new String[] { datastoreDiskPath }, volumeDsDetails.first(), i, i + 1);
|
||||
}
|
||||
deviceConfigSpecArray[i].setDevice(device);
|
||||
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.add);
|
||||
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD);
|
||||
|
||||
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("Prepare volume at new device " + _gson.toJson(device));
|
||||
|
|
@ -2284,7 +2298,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
|
||||
deviceConfigSpecArray[i].setDevice(nic);
|
||||
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.add);
|
||||
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD);
|
||||
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("Prepare NIC at new device " + _gson.toJson(deviceConfigSpecArray[i]));
|
||||
|
|
@ -2297,7 +2311,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
nicCount++;
|
||||
}
|
||||
|
||||
vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
|
||||
vmConfigSpec.getDeviceChange().addAll(Arrays.asList(deviceConfigSpecArray));
|
||||
|
||||
// pass boot arguments through machine.id & perform customized options to VMX
|
||||
|
||||
|
|
@ -2322,7 +2336,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
String keyboardLayout = null;
|
||||
if(vmSpec.getDetails() != null)
|
||||
keyboardLayout = vmSpec.getDetails().get(VmDetailConstants.KEYBOARD);
|
||||
vmConfigSpec.setExtraConfig(configureVnc(extraOptions, hyperHost, vmName, vmSpec.getVncPassword(), keyboardLayout));
|
||||
vmConfigSpec.getExtraConfig().addAll(Arrays.asList(configureVnc(extraOptions, hyperHost, vmName, vmSpec.getVncPassword(), keyboardLayout)));
|
||||
|
||||
if (!vmMo.configureVm(vmConfigSpec)) {
|
||||
throw new Exception("Failed to configure VM before start. vmName: " + vmName);
|
||||
|
|
@ -2357,6 +2371,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
|
||||
private Map<String, String> validateVmDetails(Map<String, String> vmDetails) {
|
||||
|
||||
Map<String, String> validatedDetails = new HashMap<String, String>();
|
||||
|
||||
if(vmDetails != null && vmDetails.size() > 0) {
|
||||
|
|
@ -2381,7 +2396,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private NicTO[] sortNicsByDeviceId(NicTO[] nics) {
|
||||
|
||||
List<NicTO> listForSort = new ArrayList<NicTO>();
|
||||
|
|
@ -2496,7 +2511,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
!namePrefix.startsWith("cloud.private"));
|
||||
}
|
||||
else {
|
||||
networkInfo = HypervisorHostHelper.prepareNetwork(switchName.first(), namePrefix, hostMo, getVlanInfo(nicTo, switchName.second()),
|
||||
networkInfo = HypervisorHostHelper.prepareNetwork(switchName.first(), namePrefix, hostMo, getVlanInfo(nicTo, switchName.second()),
|
||||
nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), _ops_timeout, switchType, _portsPerDvPortGroup);
|
||||
}
|
||||
|
||||
|
|
@ -2892,7 +2907,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
try {
|
||||
vmMo.rebootGuest();
|
||||
return new RebootAnswer(cmd, "reboot succeeded", true);
|
||||
} catch(ToolsUnavailable e) {
|
||||
} catch(ToolsUnavailableFaultMsg e) {
|
||||
s_logger.warn("VMware tools is not installed at guest OS, we will perform hard reset for reboot");
|
||||
} catch(Exception e) {
|
||||
s_logger.warn("We are not able to perform gracefull guest reboot due to " + VmwareHelper.getExceptionMessage(e));
|
||||
|
|
@ -3077,8 +3092,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
VmwareManager mgr = dcMo.getContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
|
||||
ObjectContent[] ocs = dcMo.getHostPropertiesOnDatacenterHostFolder(new String[] { "name", "parent" });
|
||||
if (ocs != null && ocs.length > 0) {
|
||||
List<ObjectContent> ocs = dcMo.getHostPropertiesOnDatacenterHostFolder(new String[] { "name", "parent" });
|
||||
if (ocs != null && ocs.size() > 0) {
|
||||
for (ObjectContent oc : ocs) {
|
||||
HostMO hostMo = new HostMO(dcMo.getContext(), oc.getObj());
|
||||
VmwareHypervisorHostNetworkSummary netSummary = hostMo.getHyperHostNetworkSummary(mgr.getManagementPortGroupByHost(hostMo));
|
||||
|
|
@ -3111,7 +3126,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
ManagedObjectReference morDatastore = null;
|
||||
morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, pool.getUuid());
|
||||
if(morDatastore == null)
|
||||
morDatastore = hyperHost.mountDatastore(pool.getType() == StoragePoolType.VMFS, pool.getHost(),
|
||||
morDatastore = hyperHost.mountDatastore(pool.getType() == StoragePoolType.VMFS, pool.getHost(),
|
||||
pool.getPort(), pool.getPath(), pool.getUuid().replace("-", ""));
|
||||
|
||||
assert (morDatastore != null);
|
||||
|
|
@ -3382,7 +3397,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
return new CreateVMSnapshotAnswer(cmd, false, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected Answer execute(DeleteVMSnapshotCommand cmd) {
|
||||
try {
|
||||
VmwareContext context = getServiceContext();
|
||||
|
|
@ -3395,7 +3410,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
return new DeleteVMSnapshotAnswer(cmd, false, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected Answer execute(RevertToVMSnapshotCommand cmd){
|
||||
try{
|
||||
VmwareContext context = getServiceContext();
|
||||
|
|
@ -3598,7 +3613,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
if(result.first())
|
||||
return new Answer(cmd);
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Unable to execute ping command on DomR (" + controlIp + "), domR may not be ready yet. failure due to "
|
||||
s_logger.error("Unable to execute ping command on DomR (" + controlIp + "), domR may not be ready yet. failure due to "
|
||||
+ VmwareHelper.getExceptionMessage(e), e);
|
||||
}
|
||||
return new Answer(cmd,false,"PingTestCommand failed");
|
||||
|
|
@ -3659,11 +3674,11 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
/*
|
||||
* DestroyCommand content example
|
||||
*
|
||||
*
|
||||
* {"volume": {"id":5,"name":"Volume1", "mountPoint":"/export/home/kelven/vmware-test/primary",
|
||||
* "path":"6bb8762f-c34c-453c-8e03-26cc246ceec4", "size":0,"type":"DATADISK","resourceType":
|
||||
* "STORAGE_POOL","storagePoolType":"NetworkFilesystem", "poolId":0,"deviceId":0 } }
|
||||
*
|
||||
*
|
||||
* {"volume": {"id":1, "name":"i-2-1-KY-ROOT", "mountPoint":"/export/home/kelven/vmware-test/primary",
|
||||
* "path":"i-2-1-KY-ROOT","size":0,"type":"ROOT", "resourceType":"STORAGE_POOL", "storagePoolType":"NetworkFilesystem",
|
||||
* "poolId":0,"deviceId":0 } }
|
||||
|
|
@ -3712,7 +3727,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s_logger.isInfoEnabled())
|
||||
s_logger.info("Destroy volume by original name: " + cmd.getVolume().getPath() + ".vmdk");
|
||||
|
|
@ -3803,7 +3818,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
* NetworkMO(hostMo.getContext(), netDetails.getNetworkMor()); ManagedObjectReference[] vms =
|
||||
* networkMo.getVMsOnNetwork(); if(vms == null || vms.length == 0) { if(s_logger.isInfoEnabled()) {
|
||||
* s_logger.info("Cleanup network as it is currently not in use: " + netDetails.getName()); }
|
||||
*
|
||||
*
|
||||
* hostMo.deletePortGroup(netDetails.getName()); } } } catch(Throwable e) {
|
||||
* s_logger.warn("Unable to cleanup network due to exception, skip for next time"); }
|
||||
*/
|
||||
|
|
@ -4024,21 +4039,21 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
vmConfig.setName(vmName);
|
||||
vmConfig.setMemoryMB((long) 4); // vmware request minimum of 4 MB
|
||||
vmConfig.setNumCPUs(1);
|
||||
vmConfig.setGuestId(VirtualMachineGuestOsIdentifier._otherGuest.toString());
|
||||
vmConfig.setGuestId(VirtualMachineGuestOsIdentifier.OTHER_GUEST.value());
|
||||
VirtualMachineFileInfo fileInfo = new VirtualMachineFileInfo();
|
||||
fileInfo.setVmPathName(String.format("[%s]", dsMo.getName()));
|
||||
vmConfig.setFiles(fileInfo);
|
||||
|
||||
// Scsi controller
|
||||
VirtualLsiLogicController scsiController = new VirtualLsiLogicController();
|
||||
scsiController.setSharedBus(VirtualSCSISharing.noSharing);
|
||||
scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
|
||||
scsiController.setBusNumber(0);
|
||||
scsiController.setKey(1);
|
||||
VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec();
|
||||
scsiControllerSpec.setDevice(scsiController);
|
||||
scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
|
||||
scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
|
||||
|
||||
vmConfig.setDeviceChange(new VirtualDeviceConfigSpec[] { scsiControllerSpec });
|
||||
vmConfig.getDeviceChange().add(scsiControllerSpec );
|
||||
hyperHost.createVm(vmConfig);
|
||||
vmMo = hyperHost.findVmOnHyperHost(vmName);
|
||||
return vmMo;
|
||||
|
|
@ -4077,11 +4092,11 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
new String[] {"name", "config.template", "runtime.powerState", "runtime.bootTime"});
|
||||
if(ocs != null) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
DynamicProperty[] props = oc.getPropSet();
|
||||
List<DynamicProperty> props = oc.getPropSet();
|
||||
if(props != null) {
|
||||
String name = null;
|
||||
boolean template = false;
|
||||
VirtualMachinePowerState powerState = VirtualMachinePowerState.poweredOff;
|
||||
VirtualMachinePowerState powerState = VirtualMachinePowerState.POWERED_OFF;
|
||||
GregorianCalendar bootTime = null;
|
||||
|
||||
for(DynamicProperty prop : props) {
|
||||
|
|
@ -4091,7 +4106,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
template = (Boolean)prop.getVal();
|
||||
else if(prop.getName().equals("runtime.powerState"))
|
||||
powerState = (VirtualMachinePowerState)prop.getVal();
|
||||
else if(prop.getName().equals("runtime.bootTime"))
|
||||
else if(prop.getName().equals("runtime.bootTime"))
|
||||
bootTime = (GregorianCalendar)prop.getVal();
|
||||
}
|
||||
|
||||
|
|
@ -4099,7 +4114,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
boolean recycle = false;
|
||||
|
||||
// recycle stopped worker VM and VM that has been running for too long (hard-coded 10 hours for now)
|
||||
if(powerState == VirtualMachinePowerState.poweredOff)
|
||||
if(powerState == VirtualMachinePowerState.POWERED_OFF)
|
||||
recycle = true;
|
||||
else if(bootTime != null && (new Date().getTime() - bootTime.getTimeInMillis() > 10*3600*1000))
|
||||
recycle = true;
|
||||
|
|
@ -4203,7 +4218,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
DatastoreSummary dsSummary = dsMo.getSummary();
|
||||
String address = hostMo.getHostName();
|
||||
StoragePoolInfo pInfo = new StoragePoolInfo(poolUuid, address, dsMo.getMor().get_value(), "", StoragePoolType.LVM, dsSummary.getCapacity(), dsSummary.getFreeSpace());
|
||||
StoragePoolInfo pInfo = new StoragePoolInfo(poolUuid, address, dsMo.getMor().getValue(), "", StoragePoolType.LVM, dsSummary.getCapacity(), dsSummary.getFreeSpace());
|
||||
StartupStorageCommand cmd = new StartupStorageCommand();
|
||||
cmd.setName(poolUuid);
|
||||
cmd.setPoolInfo(pInfo);
|
||||
|
|
@ -4241,7 +4256,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
fillHostHardwareInfo(serviceContext, cmd);
|
||||
fillHostNetworkInfo(serviceContext, cmd);
|
||||
fillHostDetailsInfo(serviceContext, details);
|
||||
} catch (RuntimeFault e) {
|
||||
} catch (RuntimeFaultFaultMsg e) {
|
||||
s_logger.error("RuntimeFault while retrieving host info: " + e.toString(), e);
|
||||
throw new CloudRuntimeException("RuntimeFault while retrieving host info");
|
||||
} catch (RemoteException e) {
|
||||
|
|
@ -4263,7 +4278,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
cmd.setVersion(VmwareResource.class.getPackage().getImplementationVersion());
|
||||
}
|
||||
|
||||
private void fillHostHardwareInfo(VmwareContext serviceContext, StartupRoutingCommand cmd) throws RuntimeFault, RemoteException, Exception {
|
||||
private void fillHostHardwareInfo(VmwareContext serviceContext, StartupRoutingCommand cmd) throws RuntimeFaultFaultMsg, RemoteException, Exception {
|
||||
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
VmwareHypervisorHostResourceSummary summary = hyperHost.getHyperHostResourceSummary();
|
||||
|
|
@ -4279,7 +4294,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
cmd.setMemory(summary.getMemoryBytes());
|
||||
}
|
||||
|
||||
private void fillHostNetworkInfo(VmwareContext serviceContext, StartupRoutingCommand cmd) throws RuntimeFault, RemoteException {
|
||||
private void fillHostNetworkInfo(VmwareContext serviceContext, StartupRoutingCommand cmd) throws RuntimeFaultFaultMsg, RemoteException {
|
||||
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
|
|
@ -4315,7 +4330,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
|
||||
ClusterDasConfigInfo dasConfig = hyperHost.getDasConfig();
|
||||
if (dasConfig != null && dasConfig.getEnabled() != null && dasConfig.getEnabled().booleanValue()) {
|
||||
if (dasConfig != null && dasConfig.isEnabled() != null && dasConfig.isEnabled().booleanValue()) {
|
||||
details.put("NativeHA", "true");
|
||||
}
|
||||
}
|
||||
|
|
@ -4433,7 +4448,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
return hyperHost.findVmOnPeerHyperHost(vmName) != null;
|
||||
}
|
||||
|
||||
protected OptionValue[] configureVnc(OptionValue[] optionsToMerge, VmwareHypervisorHost hyperHost, String vmName,
|
||||
protected OptionValue[] configureVnc(OptionValue[] optionsToMerge, VmwareHypervisorHost hyperHost, String vmName,
|
||||
String vncPassword, String keyboardLayout) throws Exception {
|
||||
|
||||
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
|
||||
|
|
@ -4519,9 +4534,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
|
||||
if (cpuArchitecture.equalsIgnoreCase("x86_64")) {
|
||||
return VirtualMachineGuestOsIdentifier.otherGuest64;
|
||||
return VirtualMachineGuestOsIdentifier.OTHER_GUEST_64;
|
||||
}
|
||||
return VirtualMachineGuestOsIdentifier.otherGuest;
|
||||
return VirtualMachineGuestOsIdentifier.OTHER_GUEST;
|
||||
}
|
||||
|
||||
private void prepareNetworkForVmTargetHost(HostMO hostMo, VirtualMachineMO vmMo) throws Exception {
|
||||
|
|
@ -4540,7 +4555,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
String[] tokens = networkName.split("\\.");
|
||||
if (tokens.length == 3) {
|
||||
Integer networkRateMbps = null;
|
||||
if (shapingPolicy != null && shapingPolicy.getEnabled() != null && shapingPolicy.getEnabled().booleanValue()) {
|
||||
if (shapingPolicy != null && shapingPolicy.isEnabled() != null && shapingPolicy.isEnabled().booleanValue()) {
|
||||
networkRateMbps = (int) (shapingPolicy.getPeakBandwidth().longValue() / (1024 * 1024));
|
||||
}
|
||||
String vlanId = null;
|
||||
|
|
@ -4556,7 +4571,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
String[] tokens = networkName.split("\\.");
|
||||
if (tokens.length == 3) {
|
||||
Integer networkRateMbps = null;
|
||||
if (shapingPolicy != null && shapingPolicy.getEnabled() != null && shapingPolicy.getEnabled().booleanValue()) {
|
||||
if (shapingPolicy != null && shapingPolicy.isEnabled() != null && shapingPolicy.isEnabled().booleanValue()) {
|
||||
networkRateMbps = (int) (shapingPolicy.getPeakBandwidth().longValue() / (1024 * 1024));
|
||||
}
|
||||
String vlanId = null;
|
||||
|
|
@ -4572,7 +4587,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
String[] tokens = networkName.split("\\.");
|
||||
if (tokens.length >= 3) {
|
||||
Integer networkRateMbps = null;
|
||||
if (shapingPolicy != null && shapingPolicy.getEnabled() != null && shapingPolicy.getEnabled().booleanValue()) {
|
||||
if (shapingPolicy != null && shapingPolicy.isEnabled() != null && shapingPolicy.isEnabled().booleanValue()) {
|
||||
networkRateMbps = (int) (shapingPolicy.getPeakBandwidth().longValue() / (1024 * 1024));
|
||||
}
|
||||
|
||||
|
|
@ -4598,12 +4613,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
HashMap<String, State> newStates = new HashMap<String, State>();
|
||||
if (ocs != null && ocs.length > 0) {
|
||||
for (ObjectContent oc : ocs) {
|
||||
DynamicProperty[] objProps = oc.getPropSet();
|
||||
List<DynamicProperty> objProps = oc.getPropSet();
|
||||
if (objProps != null) {
|
||||
|
||||
boolean isTemplate = false;
|
||||
String name = null;
|
||||
VirtualMachinePowerState powerState = VirtualMachinePowerState.poweredOff;
|
||||
VirtualMachinePowerState powerState = VirtualMachinePowerState.POWERED_OFF;
|
||||
for (DynamicProperty objProp : objProps) {
|
||||
if (objProp.getName().equals("config.template")) {
|
||||
if (objProp.getVal().toString().equalsIgnoreCase("true")) {
|
||||
|
|
@ -4630,19 +4645,19 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
private HashMap<String, VmStatsEntry> getVmStats(List<String> vmNames) throws Exception {
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
HashMap<String, VmStatsEntry> vmResponseMap = new HashMap<String, VmStatsEntry>();
|
||||
ManagedObjectReference perfMgr = getServiceContext().getServiceConnection().getServiceContent().getPerfManager();
|
||||
VimPortType service = getServiceContext().getServiceConnection().getService();
|
||||
ManagedObjectReference perfMgr = getServiceContext().getServiceContent().getPerfManager();
|
||||
VimPortType service = getServiceContext().getService();
|
||||
PerfCounterInfo rxPerfCounterInfo = null;
|
||||
PerfCounterInfo txPerfCounterInfo = null;
|
||||
|
||||
PerfCounterInfo[] cInfo = (PerfCounterInfo[]) getServiceContext().getServiceUtil().getDynamicProperty(perfMgr, "perfCounter");
|
||||
for(int i=0; i<cInfo.length; ++i) {
|
||||
if ("net".equalsIgnoreCase(cInfo[i].getGroupInfo().getKey())) {
|
||||
if ("transmitted".equalsIgnoreCase(cInfo[i].getNameInfo().getKey())) {
|
||||
txPerfCounterInfo = cInfo[i];
|
||||
List<PerfCounterInfo> cInfo = (List<PerfCounterInfo>) getServiceContext().getVimClient().getDynamicProperty(perfMgr, "perfCounter");
|
||||
for(PerfCounterInfo info : cInfo) {
|
||||
if ("net".equalsIgnoreCase(info.getGroupInfo().getKey())) {
|
||||
if ("transmitted".equalsIgnoreCase(info.getNameInfo().getKey())) {
|
||||
txPerfCounterInfo = info;
|
||||
}
|
||||
if ("received".equalsIgnoreCase(cInfo[i].getNameInfo().getKey())) {
|
||||
rxPerfCounterInfo = cInfo[i];
|
||||
if ("received".equalsIgnoreCase(info.getNameInfo().getKey())) {
|
||||
rxPerfCounterInfo = info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4650,7 +4665,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new String[] {"name", "summary.config.numCpu", "summary.quickStats.overallCpuUsage"});
|
||||
if (ocs != null && ocs.length > 0) {
|
||||
for (ObjectContent oc : ocs) {
|
||||
DynamicProperty[] objProps = oc.getPropSet();
|
||||
List<DynamicProperty> objProps = oc.getPropSet();
|
||||
if (objProps != null) {
|
||||
String name = null;
|
||||
String numberCPUs = null;
|
||||
|
|
@ -4674,13 +4689,13 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
assert(vmMor!=null);
|
||||
|
||||
ArrayList vmNetworkMetrics = new ArrayList();
|
||||
// get all the metrics from the available sample period
|
||||
PerfMetricId[] perfMetrics = service.queryAvailablePerfMetric(perfMgr, vmMor, null, null, null);
|
||||
// get all the metrics from the available sample period
|
||||
List<PerfMetricId> perfMetrics = service.queryAvailablePerfMetric(perfMgr, vmMor, null, null, null);
|
||||
if(perfMetrics != null) {
|
||||
for(int index=0; index < perfMetrics.length; ++index) {
|
||||
if ( ((rxPerfCounterInfo != null) && (perfMetrics[index].getCounterId() == rxPerfCounterInfo.getKey())) ||
|
||||
((txPerfCounterInfo != null) && (perfMetrics[index].getCounterId() == txPerfCounterInfo.getKey())) ) {
|
||||
vmNetworkMetrics.add(perfMetrics[index]);
|
||||
for(int index=0; index < perfMetrics.size(); ++index) {
|
||||
if ( ((rxPerfCounterInfo != null) && (perfMetrics.get(index).getCounterId() == rxPerfCounterInfo.getKey())) ||
|
||||
((txPerfCounterInfo != null) && (perfMetrics.get(index).getCounterId() == txPerfCounterInfo.getKey())) ) {
|
||||
vmNetworkMetrics.add(perfMetrics.get(index));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4693,23 +4708,26 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
PerfQuerySpec qSpec = new PerfQuerySpec();
|
||||
qSpec.setEntity(vmMor);
|
||||
PerfMetricId[] availableMetricIds = (PerfMetricId[]) vmNetworkMetrics.toArray(new PerfMetricId[0]);
|
||||
qSpec.setMetricId(availableMetricIds);
|
||||
PerfQuerySpec[] qSpecs = new PerfQuerySpec[] {qSpec};
|
||||
PerfEntityMetricBase[] values = service.queryPerf(perfMgr, qSpecs);
|
||||
qSpec.getMetricId().addAll(Arrays.asList(availableMetricIds));
|
||||
List<PerfQuerySpec> qSpecs = new ArrayList<PerfQuerySpec>();
|
||||
qSpecs.add(qSpec);
|
||||
List<PerfEntityMetricBase> values = service.queryPerf(perfMgr, qSpecs);
|
||||
|
||||
for(int i=0; i<values.length; ++i) {
|
||||
PerfSampleInfo[] infos = ((PerfEntityMetric)values[i]).getSampleInfo();
|
||||
sampleDuration = (infos[infos.length-1].getTimestamp().getTimeInMillis() - infos[0].getTimestamp().getTimeInMillis()) /1000;
|
||||
PerfMetricSeries[] vals = ((PerfEntityMetric)values[i]).getValue();
|
||||
for(int vi = 0; ((vals!= null) && (vi < vals.length)); ++vi){
|
||||
if(vals[vi] instanceof PerfMetricIntSeries) {
|
||||
PerfMetricIntSeries val = (PerfMetricIntSeries)vals[vi];
|
||||
long[] perfValues = val.getValue();
|
||||
if (vals[vi].getId().getCounterId() == rxPerfCounterInfo.getKey()) {
|
||||
networkReadKBs = sampleDuration * perfValues[3]; //get the average RX rate multiplied by sampled duration
|
||||
for(int i=0; i<values.size(); ++i) {
|
||||
List<PerfSampleInfo> infos = ((PerfEntityMetric)values.get(i)).getSampleInfo();
|
||||
int endMs = infos.get(infos.size()-1).getTimestamp().getSecond() * 1000 + infos.get(infos.size()-1).getTimestamp().getMillisecond();
|
||||
int beginMs = infos.get(0).getTimestamp().getSecond() * 1000 + infos.get(0).getTimestamp().getMillisecond();
|
||||
sampleDuration = (endMs - beginMs) /1000;
|
||||
List<PerfMetricSeries> vals = ((PerfEntityMetric)values.get(i)).getValue();
|
||||
for(int vi = 0; ((vals!= null) && (vi < vals.size())); ++vi){
|
||||
if(vals.get(vi) instanceof PerfMetricIntSeries) {
|
||||
PerfMetricIntSeries val = (PerfMetricIntSeries)vals.get(vi);
|
||||
List<Long> perfValues = val.getValue();
|
||||
if (vals.get(vi).getId().getCounterId() == rxPerfCounterInfo.getKey()) {
|
||||
networkReadKBs = sampleDuration * perfValues.get(3); //get the average RX rate multiplied by sampled duration
|
||||
}
|
||||
if (vals[vi].getId().getCounterId() == txPerfCounterInfo.getKey()) {
|
||||
networkWriteKBs = sampleDuration * perfValues[3];//get the average TX rate multiplied by sampled duration
|
||||
if (vals.get(vi).getId().getCounterId() == txPerfCounterInfo.getKey()) {
|
||||
networkWriteKBs = sampleDuration * perfValues.get(3);//get the average TX rate multiplied by sampled duration
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4719,8 +4737,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
}
|
||||
}
|
||||
return vmResponseMap;
|
||||
}
|
||||
return vmResponseMap;
|
||||
}
|
||||
|
||||
protected String networkUsage(final String privateIpAddress, final String option, final String ethName) {
|
||||
String args = null;
|
||||
|
|
@ -4753,7 +4771,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
return result.second();
|
||||
} catch (Throwable e) {
|
||||
s_logger.error("Unable to execute NetworkUsage command on DomR (" + privateIpAddress + "), domR may not be ready yet. failure due to "
|
||||
s_logger.error("Unable to execute NetworkUsage command on DomR (" + privateIpAddress + "), domR may not be ready yet. failure due to "
|
||||
+ VmwareHelper.getExceptionMessage(e), e);
|
||||
}
|
||||
|
||||
|
|
@ -4894,7 +4912,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
_morHyperHost = new ManagedObjectReference();
|
||||
String[] hostTokens = tokens[0].split(":");
|
||||
_morHyperHost.setType(hostTokens[0]);
|
||||
_morHyperHost.set_value(hostTokens[1]);
|
||||
_morHyperHost.setValue(hostTokens[1]);
|
||||
|
||||
_guestTrafficInfo = (VmwareTrafficLabel) params.get("guestTrafficInfo");
|
||||
_publicTrafficInfo = (VmwareTrafficLabel) params.get("publicTrafficInfo");
|
||||
|
|
@ -5067,13 +5085,13 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
@Override
|
||||
public void setName(String name) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfigParams(Map<String, Object> params) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -5091,6 +5109,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
@Override
|
||||
public void setRunLevel(int level) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
// 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
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.storage.resource;
|
||||
|
|
@ -20,45 +20,44 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareClient;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.vmware.apputils.version.ExtendedAppUtil;
|
||||
|
||||
public class VmwareSecondaryStorageContextFactory {
|
||||
private static volatile int s_seq = 1;
|
||||
|
||||
|
||||
private static Map<String, VmwareContext> s_contextMap = new HashMap<String, VmwareContext>();
|
||||
|
||||
|
||||
public static void initFactoryEnvironment() {
|
||||
System.setProperty("axis.socketSecureFactory", "org.apache.axis.components.net.SunFakeTrustSocketFactory");
|
||||
}
|
||||
|
||||
|
||||
public static VmwareContext create(String vCenterAddress, String vCenterUserName, String vCenterPassword) throws Exception {
|
||||
assert(vCenterAddress != null);
|
||||
assert(vCenterUserName != null);
|
||||
assert(vCenterPassword != null);
|
||||
|
||||
|
||||
VmwareContext context = null;
|
||||
|
||||
|
||||
synchronized(s_contextMap) {
|
||||
context = s_contextMap.get(vCenterAddress);
|
||||
if(context == null) {
|
||||
String serviceUrl = "https://" + vCenterAddress + "/sdk/vimService";
|
||||
String[] params = new String[] {"--url", serviceUrl, "--username", vCenterUserName, "--password", vCenterPassword };
|
||||
ExtendedAppUtil appUtil = ExtendedAppUtil.initialize(vCenterAddress + "-" + s_seq++, params);
|
||||
|
||||
appUtil.connect();
|
||||
context = new VmwareContext(appUtil, vCenterAddress);
|
||||
//String[] params = new String[] {"--url", serviceUrl, "--username", vCenterUserName, "--password", vCenterPassword };
|
||||
VmwareClient vimClient = new VmwareClient(vCenterAddress + "-" + s_seq++);
|
||||
vimClient.connect(serviceUrl, vCenterUserName, vCenterPassword);
|
||||
context = new VmwareContext(vimClient, vCenterAddress);
|
||||
context.registerStockObject("username", vCenterUserName);
|
||||
context.registerStockObject("password", vCenterPassword);
|
||||
|
||||
|
||||
s_contextMap.put(vCenterAddress, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
assert(context != null);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
public static void invalidate(VmwareContext context) {
|
||||
synchronized(s_contextMap) {
|
||||
for(Iterator<Map.Entry<String, VmwareContext>> entryIter = s_contextMap.entrySet().iterator(); entryIter.hasNext();) {
|
||||
|
|
@ -68,7 +67,7 @@ public class VmwareSecondaryStorageContextFactory {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
// 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
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.storage.resource;
|
||||
|
|
@ -85,11 +85,11 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe
|
|||
if(cmd.getContextParam("execid") != null) {
|
||||
answer.setContextParam("execid", cmd.getContextParam("execid"));
|
||||
}
|
||||
|
||||
|
||||
if(cmd.getContextParam("checkpoint") != null) {
|
||||
answer.setContextParam("checkpoint", cmd.getContextParam("checkpoint"));
|
||||
}
|
||||
|
||||
|
||||
if(cmd.getContextParam("checkpoint2") != null) {
|
||||
answer.setContextParam("checkpoint2", cmd.getContextParam("checkpoint2"));
|
||||
}
|
||||
|
|
@ -219,23 +219,23 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe
|
|||
}
|
||||
|
||||
morHyperHost.setType(hostTokens[0]);
|
||||
morHyperHost.set_value(hostTokens[1]);
|
||||
morHyperHost.setValue(hostTokens[1]);
|
||||
|
||||
if(morHyperHost.getType().equalsIgnoreCase("HostSystem")) {
|
||||
HostMO hostMo = new HostMO(context, morHyperHost);
|
||||
|
||||
try {
|
||||
|
||||
|
||||
ManagedObjectReference mor = hostMo.getHyperHostCluster();
|
||||
ClusterMO clusterMo = new ClusterMO(hostMo.getContext(), mor);
|
||||
List<Pair<ManagedObjectReference, String>> hostsInCluster = clusterMo.getClusterHosts();
|
||||
for(Pair<ManagedObjectReference, String> hostPair : hostsInCluster) {
|
||||
HostMO hostIteratorMo = new HostMO(hostMo.getContext(), hostPair.first());
|
||||
|
||||
|
||||
VmwareHypervisorHostNetworkSummary netSummary = hostIteratorMo.getHyperHostNetworkSummary(
|
||||
hostIteratorMo.getHostType() == VmwareHostType.ESXi ? cmd.getContextParam("manageportgroup") : cmd.getContextParam("serviceconsole"));
|
||||
_resource.ensureOutgoingRuleForAddress(netSummary.getHostIp());
|
||||
|
||||
|
||||
s_logger.info("Setup firewall rule for host: " + netSummary.getHostIp());
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
|
|
@ -253,7 +253,7 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe
|
|||
public String getWorkerName(VmwareContext context, Command cmd, int workerSequence) {
|
||||
assert(cmd.getContextParam("worker") != null);
|
||||
assert(workerSequence < 2);
|
||||
|
||||
|
||||
if(workerSequence == 0)
|
||||
return cmd.getContextParam("worker");
|
||||
return cmd.getContextParam("worker2");
|
||||
|
|
@ -276,7 +276,7 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe
|
|||
assert(hostTokens.length == 2);
|
||||
|
||||
morHyperHost.setType(hostTokens[0]);
|
||||
morHyperHost.set_value(hostTokens[1]);
|
||||
morHyperHost.setValue(hostTokens[1]);
|
||||
|
||||
if(morHyperHost.getType().equalsIgnoreCase("HostSystem")) {
|
||||
HostMO hostMo = new HostMO(context, morHyperHost);
|
||||
|
|
|
|||
5
pom.xml
5
pom.xml
|
|
@ -82,8 +82,8 @@
|
|||
<cs.servlet.version>2.4</cs.servlet.version>
|
||||
<cs.jstl.version>1.2</cs.jstl.version>
|
||||
<cs.selenium.server.version>1.0-20081010.060147</cs.selenium.server.version>
|
||||
<cs.vmware.api.version>5.1</cs.vmware.api.version>
|
||||
<org.springframework.version>3.1.2.RELEASE</org.springframework.version>
|
||||
<cs.vmware.api.version>4.1</cs.vmware.api.version>
|
||||
<cs.mockito.version>1.9.5</cs.mockito.version>
|
||||
<cs.aws.sdk.version>1.3.21.1</cs.aws.sdk.version>
|
||||
<cs.lang.version>2.6</cs.lang.version>
|
||||
|
|
@ -452,7 +452,8 @@
|
|||
<target>${cs.jdk.version}</target>
|
||||
<fork>true</fork>
|
||||
<meminitial>128m</meminitial>
|
||||
<maxmem>512m</maxmem>
|
||||
<maxmem>512m</maxmem>
|
||||
<compilerArgument>-XDignore.symbol.file=true</compilerArgument>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
|||
|
|
@ -48,14 +48,13 @@ import com.cloud.user.Account;
|
|||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@Component
|
||||
@Local(value=TemplateAdapter.class)
|
||||
public class BareMetalTemplateAdapter extends TemplateAdapterBase implements TemplateAdapter {
|
||||
private final static Logger s_logger = Logger.getLogger(BareMetalTemplateAdapter.class);
|
||||
@Inject HostDao _hostDao;
|
||||
@Inject ResourceManager _resourceMgr;
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public String getName() {
|
||||
return TemplateAdapterType.BareMetal.getName();
|
||||
}
|
||||
|
|
@ -63,7 +62,7 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
@Override
|
||||
public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException {
|
||||
TemplateProfile profile = super.prepare(cmd);
|
||||
|
||||
|
||||
if (profile.getZoneId() == null || profile.getZoneId() == -1) {
|
||||
List<DataCenterVO> dcs = _dcDao.listAllIncludingRemoved();
|
||||
for (DataCenterVO dc : dcs) {
|
||||
|
|
@ -78,15 +77,15 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
throw new CloudRuntimeException("Please add PXE server before adding baremetal template in zone " + profile.getZoneId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationException {
|
||||
throw new CloudRuntimeException("Baremetal doesn't support ISO template");
|
||||
}
|
||||
|
||||
|
||||
private void templateCreateUsage(VMTemplateVO template, HostVO host) {
|
||||
if (template.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_TEMPLATE_CREATE, template.getAccountId(), host.getDataCenterId(),
|
||||
|
|
@ -94,12 +93,12 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
template.getClass().getName(), template.getUuid());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VMTemplateVO create(TemplateProfile profile) {
|
||||
VMTemplateVO template = persistTemplate(profile);
|
||||
Long zoneId = profile.getZoneId();
|
||||
|
||||
|
||||
/* There is no secondary storage vm for baremetal, we use pxe server id.
|
||||
* Tempalte is not bound to pxeserver right now, and we assume the pxeserver
|
||||
* cannot be removed once it was added. so we use host id of first found pxe
|
||||
|
|
@ -127,7 +126,7 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
_tmpltHostDao.persist(vmTemplateHost);
|
||||
templateCreateUsage(template, pxe);
|
||||
}
|
||||
|
||||
|
||||
_resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template);
|
||||
return template;
|
||||
}
|
||||
|
|
@ -135,7 +134,7 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
public TemplateProfile prepareDelete(DeleteIsoCmd cmd) {
|
||||
throw new CloudRuntimeException("Baremetal doesn't support ISO, how the delete get here???");
|
||||
}
|
||||
|
||||
|
||||
@Override @DB
|
||||
public boolean delete(TemplateProfile profile) {
|
||||
VMTemplateVO template = (VMTemplateVO)profile.getTemplate();
|
||||
|
|
@ -143,7 +142,7 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
boolean success = true;
|
||||
String zoneName;
|
||||
boolean isAllZone;
|
||||
|
||||
|
||||
if (!template.isCrossZones() && profile.getZoneId() != null) {
|
||||
isAllZone = false;
|
||||
zoneName = profile.getZoneId().toString();
|
||||
|
|
@ -151,12 +150,12 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
zoneName = "all zones";
|
||||
isAllZone = true;
|
||||
}
|
||||
|
||||
|
||||
s_logger.debug("Attempting to mark template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName);
|
||||
Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId());
|
||||
String eventType = EventTypes.EVENT_TEMPLATE_DELETE;
|
||||
List<VMTemplateHostVO> templateHostVOs = _tmpltHostDao.listByTemplateId(templateId);
|
||||
|
||||
|
||||
for (VMTemplateHostVO vo : templateHostVOs) {
|
||||
VMTemplateHostVO lock = null;
|
||||
try {
|
||||
|
|
@ -187,13 +186,13 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
s_logger.debug("Successfully marked template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName);
|
||||
|
||||
|
||||
// If there are no more non-destroyed template host entries for this template, delete it
|
||||
if (success && (_tmpltHostDao.listByTemplateId(templateId).size() == 0)) {
|
||||
long accountId = template.getAccountId();
|
||||
|
||||
|
||||
VMTemplateVO lock = _tmpltDao.acquireInLockTable(templateId);
|
||||
|
||||
try {
|
||||
|
|
@ -212,7 +211,7 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
}
|
||||
s_logger.debug("Removed template: " + template.getName() + " because all of its template host refs were marked as destroyed.");
|
||||
}
|
||||
|
||||
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,10 +75,9 @@ import javax.ejb.Local;
|
|||
import java.net.*;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Local(value=TemplateAdapter.class)
|
||||
public class HyervisorTemplateAdapter extends TemplateAdapterBase implements TemplateAdapter {
|
||||
private final static Logger s_logger = Logger.getLogger(HyervisorTemplateAdapter.class);
|
||||
public class HypervisorTemplateAdapter extends TemplateAdapterBase implements TemplateAdapter {
|
||||
private final static Logger s_logger = Logger.getLogger(HypervisorTemplateAdapter.class);
|
||||
@Inject DownloadMonitor _downloadMonitor;
|
||||
@Inject SecondaryStorageVmManager _ssvmMgr;
|
||||
@Inject AgentManager _agentMgr;
|
||||
|
|
@ -96,7 +95,7 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
private String validateUrl(String url) {
|
||||
try {
|
||||
URI uri = new URI(url);
|
||||
if ((uri.getScheme() == null) || (!uri.getScheme().equalsIgnoreCase("http")
|
||||
if ((uri.getScheme() == null) || (!uri.getScheme().equalsIgnoreCase("http")
|
||||
&& !uri.getScheme().equalsIgnoreCase("https") && !uri.getScheme().equalsIgnoreCase("file"))) {
|
||||
throw new IllegalArgumentException("Unsupported scheme for url: " + url);
|
||||
}
|
||||
|
|
@ -117,34 +116,34 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
} catch (UnknownHostException uhe) {
|
||||
throw new IllegalArgumentException("Unable to resolve " + host);
|
||||
}
|
||||
|
||||
|
||||
return uri.toString();
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException("Invalid URL " + url);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationException {
|
||||
TemplateProfile profile = super.prepare(cmd);
|
||||
String url = profile.getUrl();
|
||||
|
||||
|
||||
if((!url.toLowerCase().endsWith("iso"))&&(!url.toLowerCase().endsWith("iso.zip"))&&(!url.toLowerCase().endsWith("iso.bz2"))
|
||||
&&(!url.toLowerCase().endsWith("iso.gz"))){
|
||||
throw new InvalidParameterValueException("Please specify a valid iso");
|
||||
}
|
||||
|
||||
|
||||
profile.setUrl(validateUrl(url));
|
||||
return profile;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException {
|
||||
TemplateProfile profile = super.prepare(cmd);
|
||||
String url = profile.getUrl();
|
||||
|
||||
|
||||
if((!url.toLowerCase().endsWith("vhd"))&&(!url.toLowerCase().endsWith("vhd.zip"))
|
||||
&&(!url.toLowerCase().endsWith("vhd.bz2"))&&(!url.toLowerCase().endsWith("vhd.gz"))
|
||||
&&(!url.toLowerCase().endsWith("vhd.bz2"))&&(!url.toLowerCase().endsWith("vhd.gz"))
|
||||
&&(!url.toLowerCase().endsWith("qcow2"))&&(!url.toLowerCase().endsWith("qcow2.zip"))
|
||||
&&(!url.toLowerCase().endsWith("qcow2.bz2"))&&(!url.toLowerCase().endsWith("qcow2.gz"))
|
||||
&&(!url.toLowerCase().endsWith("ova"))&&(!url.toLowerCase().endsWith("ova.zip"))
|
||||
|
|
@ -152,26 +151,26 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
&&(!url.toLowerCase().endsWith("img"))&&(!url.toLowerCase().endsWith("raw"))){
|
||||
throw new InvalidParameterValueException("Please specify a valid "+ cmd.getFormat().toLowerCase());
|
||||
}
|
||||
|
||||
|
||||
if ((cmd.getFormat().equalsIgnoreCase("vhd") && (!url.toLowerCase().endsWith("vhd") && !url.toLowerCase().endsWith("vhd.zip") && !url.toLowerCase().endsWith("vhd.bz2") && !url.toLowerCase().endsWith("vhd.gz") ))
|
||||
|| (cmd.getFormat().equalsIgnoreCase("qcow2") && (!url.toLowerCase().endsWith("qcow2") && !url.toLowerCase().endsWith("qcow2.zip") && !url.toLowerCase().endsWith("qcow2.bz2") && !url.toLowerCase().endsWith("qcow2.gz") ))
|
||||
|| (cmd.getFormat().equalsIgnoreCase("ova") && (!url.toLowerCase().endsWith("ova") && !url.toLowerCase().endsWith("ova.zip") && !url.toLowerCase().endsWith("ova.bz2") && !url.toLowerCase().endsWith("ova.gz")))
|
||||
|| (cmd.getFormat().equalsIgnoreCase("raw") && (!url.toLowerCase().endsWith("img") && !url.toLowerCase().endsWith("raw")))) {
|
||||
throw new InvalidParameterValueException("Please specify a valid URL. URL:" + url + " is an invalid for the format " + cmd.getFormat().toLowerCase());
|
||||
}
|
||||
|
||||
|
||||
profile.setUrl(validateUrl(url));
|
||||
return profile;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VMTemplateVO create(TemplateProfile profile) {
|
||||
VMTemplateVO template = persistTemplate(profile);
|
||||
|
||||
|
||||
if (template == null) {
|
||||
throw new CloudRuntimeException("Unable to persist the template " + profile.getTemplate());
|
||||
}
|
||||
|
||||
|
||||
DataStore imageStore = this.storeMgr.getDataStore(profile.getImageStoreId(), DataStoreRole.Image);
|
||||
|
||||
AsyncCallFuture<CommandResult> future = this.imageService.createTemplateAsync(this.imageFactory.getTemplate(template.getId()), imageStore);
|
||||
|
|
@ -185,18 +184,18 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
throw new CloudRuntimeException("create template Failed", e);
|
||||
}
|
||||
_resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template);
|
||||
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
public boolean delete(TemplateProfile profile) {
|
||||
boolean success = true;
|
||||
|
||||
|
||||
VMTemplateVO template = (VMTemplateVO)profile.getTemplate();
|
||||
Long zoneId = profile.getZoneId();
|
||||
Long templateId = template.getId();
|
||||
|
||||
|
||||
String zoneName;
|
||||
List<HostVO> secondaryStorageHosts;
|
||||
if (!template.isCrossZones() && zoneId != null) {
|
||||
|
|
@ -207,9 +206,9 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
zoneName = "(all zones)";
|
||||
secondaryStorageHosts = _ssvmMgr.listSecondaryStorageHostsInAllZones();
|
||||
}
|
||||
|
||||
|
||||
s_logger.debug("Attempting to mark template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName);
|
||||
|
||||
|
||||
// Make sure the template is downloaded to all the necessary secondary storage hosts
|
||||
for (HostVO secondaryStorageHost : secondaryStorageHosts) {
|
||||
long hostId = secondaryStorageHost.getId();
|
||||
|
|
@ -222,16 +221,16 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId());
|
||||
String eventType = "";
|
||||
|
||||
|
||||
if (template.getFormat().equals(ImageFormat.ISO)){
|
||||
eventType = EventTypes.EVENT_ISO_DELETE;
|
||||
} else {
|
||||
eventType = EventTypes.EVENT_TEMPLATE_DELETE;
|
||||
}
|
||||
|
||||
|
||||
// Iterate through all necessary secondary storage hosts and mark the template on each host as destroyed
|
||||
for (HostVO secondaryStorageHost : secondaryStorageHosts) {
|
||||
long hostId = secondaryStorageHost.getId();
|
||||
|
|
@ -252,21 +251,21 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
List<UserVmVO> userVmUsingIso = _userVmDao.listByIsoId(templateId);
|
||||
//check if there is any VM using this ISO.
|
||||
if (userVmUsingIso == null || userVmUsingIso.isEmpty()) {
|
||||
if (installPath != null) {
|
||||
Answer answer = _agentMgr.sendToSecStorage(secondaryStorageHost, new DeleteTemplateCommand(secondaryStorageHost.getStorageUrl(), installPath));
|
||||
if (installPath != null) {
|
||||
Answer answer = _agentMgr.sendToSecStorage(secondaryStorageHost, new DeleteTemplateCommand(secondaryStorageHost.getStorageUrl(), installPath));
|
||||
|
||||
if (answer == null || !answer.getResult()) {
|
||||
s_logger.debug("Failed to delete " + templateHostVO + " due to " + ((answer == null) ? "answer is null" : answer.getDetails()));
|
||||
} else {
|
||||
_tmpltHostDao.remove(templateHostVO.getId());
|
||||
s_logger.debug("Deleted template at: " + installPath);
|
||||
}
|
||||
if (answer == null || !answer.getResult()) {
|
||||
s_logger.debug("Failed to delete " + templateHostVO + " due to " + ((answer == null) ? "answer is null" : answer.getDetails()));
|
||||
} else {
|
||||
_tmpltHostDao.remove(templateHostVO.getId());
|
||||
s_logger.debug("Deleted template at: " + installPath);
|
||||
}
|
||||
} else {
|
||||
_tmpltHostDao.remove(templateHostVO.getId());
|
||||
}
|
||||
}
|
||||
VMTemplateZoneVO templateZone = _tmpltZoneDao.findByZoneTemplate(sZoneId, templateId);
|
||||
|
||||
|
||||
if (templateZone != null) {
|
||||
_tmpltZoneDao.remove(templateZone.getId());
|
||||
}
|
||||
|
|
@ -276,18 +275,18 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!success) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
s_logger.debug("Successfully marked template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName);
|
||||
|
||||
|
||||
// If there are no more non-destroyed template host entries for this template, delete it
|
||||
if (success && (_tmpltHostDao.listByTemplateId(templateId).size() == 0)) {
|
||||
long accountId = template.getAccountId();
|
||||
|
||||
|
||||
VMTemplateVO lock = _tmpltDao.acquireInLockTable(templateId);
|
||||
|
||||
try {
|
||||
|
|
@ -304,18 +303,18 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
_tmpltDao.releaseFromLockTable(lock.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
s_logger.debug("Removed template: " + template.getName() + " because all of its template host refs were marked as destroyed.");
|
||||
}
|
||||
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
public TemplateProfile prepareDelete(DeleteTemplateCmd cmd) {
|
||||
TemplateProfile profile = super.prepareDelete(cmd);
|
||||
VMTemplateVO template = (VMTemplateVO)profile.getTemplate();
|
||||
Long zoneId = profile.getZoneId();
|
||||
|
||||
|
||||
if (template.getTemplateType() == TemplateType.SYSTEM) {
|
||||
throw new InvalidParameterValueException("The DomR template cannot be deleted.");
|
||||
}
|
||||
|
|
@ -323,18 +322,18 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||
if (zoneId != null && (_ssvmMgr.findSecondaryStorageHost(zoneId) == null)) {
|
||||
throw new InvalidParameterValueException("Failed to find a secondary storage host in the specified zone.");
|
||||
}
|
||||
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
|
||||
public TemplateProfile prepareDelete(DeleteIsoCmd cmd) {
|
||||
TemplateProfile profile = super.prepareDelete(cmd);
|
||||
Long zoneId = profile.getZoneId();
|
||||
|
||||
|
||||
if (zoneId != null && (_ssvmMgr.findSecondaryStorageHost(zoneId) == null)) {
|
||||
throw new InvalidParameterValueException("Failed to find a secondary storage host in the specified zone.");
|
||||
}
|
||||
|
||||
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package com.cloud.storage.dao;
|
||||
package com.cloud.vm.dao;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
|
|||
|
|
@ -489,7 +489,7 @@ ALTER TABLE `cloud`.`data_center` ADD COLUMN `ip6_dns2` varchar(255);
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`user_vm_view`;
|
||||
CREATE VIEW `cloud`.`user_vm_view` AS
|
||||
select
|
||||
select
|
||||
vm_instance.id id,
|
||||
vm_instance.name name,
|
||||
user_vm.display_name display_name,
|
||||
|
|
@ -657,7 +657,7 @@ CREATE VIEW `cloud`.`user_vm_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`domain_router_view`;
|
||||
CREATE VIEW `cloud`.`domain_router_view` AS
|
||||
select
|
||||
select
|
||||
vm_instance.id id,
|
||||
vm_instance.name name,
|
||||
account.id account_id,
|
||||
|
|
@ -761,7 +761,7 @@ CREATE VIEW `cloud`.`domain_router_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`security_group_view`;
|
||||
CREATE VIEW `cloud`.`security_group_view` AS
|
||||
select
|
||||
select
|
||||
security_group.id id,
|
||||
security_group.name name,
|
||||
security_group.description description,
|
||||
|
|
@ -820,7 +820,7 @@ CREATE VIEW `cloud`.`security_group_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`resource_tag_view`;
|
||||
CREATE VIEW `cloud`.`resource_tag_view` AS
|
||||
select
|
||||
select
|
||||
resource_tags.id,
|
||||
resource_tags.uuid,
|
||||
resource_tags.key,
|
||||
|
|
@ -852,7 +852,7 @@ CREATE VIEW `cloud`.`resource_tag_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`event_view`;
|
||||
CREATE VIEW `cloud`.`event_view` AS
|
||||
select
|
||||
select
|
||||
event.id,
|
||||
event.uuid,
|
||||
event.type,
|
||||
|
|
@ -891,7 +891,7 @@ CREATE VIEW `cloud`.`event_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`instance_group_view`;
|
||||
CREATE VIEW `cloud`.`instance_group_view` AS
|
||||
select
|
||||
select
|
||||
instance_group.id,
|
||||
instance_group.uuid,
|
||||
instance_group.name,
|
||||
|
|
@ -919,7 +919,7 @@ CREATE VIEW `cloud`.`instance_group_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`user_view`;
|
||||
CREATE VIEW `cloud`.`user_view` AS
|
||||
select
|
||||
select
|
||||
user.id,
|
||||
user.uuid,
|
||||
user.username,
|
||||
|
|
@ -962,7 +962,7 @@ CREATE VIEW `cloud`.`user_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`project_view`;
|
||||
CREATE VIEW `cloud`.`project_view` AS
|
||||
select
|
||||
select
|
||||
projects.id,
|
||||
projects.uuid,
|
||||
projects.name,
|
||||
|
|
@ -1003,7 +1003,7 @@ CREATE VIEW `cloud`.`project_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`project_account_view`;
|
||||
CREATE VIEW `cloud`.`project_account_view` AS
|
||||
select
|
||||
select
|
||||
project_account.id,
|
||||
account.id account_id,
|
||||
account.uuid account_uuid,
|
||||
|
|
@ -1028,7 +1028,7 @@ CREATE VIEW `cloud`.`project_account_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`project_invitation_view`;
|
||||
CREATE VIEW `cloud`.`project_invitation_view` AS
|
||||
select
|
||||
select
|
||||
project_invitations.id,
|
||||
project_invitations.uuid,
|
||||
project_invitations.email,
|
||||
|
|
@ -1056,7 +1056,7 @@ CREATE VIEW `cloud`.`project_invitation_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`host_view`;
|
||||
CREATE VIEW `cloud`.`host_view` AS
|
||||
select
|
||||
select
|
||||
host.id,
|
||||
host.uuid,
|
||||
host.name,
|
||||
|
|
@ -1126,7 +1126,7 @@ CREATE VIEW `cloud`.`host_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`volume_view`;
|
||||
CREATE VIEW `cloud`.`volume_view` AS
|
||||
select
|
||||
select
|
||||
volumes.id,
|
||||
volumes.uuid,
|
||||
volumes.name,
|
||||
|
|
@ -1227,7 +1227,7 @@ CREATE VIEW `cloud`.`volume_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`account_netstats_view`;
|
||||
CREATE VIEW `cloud`.`account_netstats_view` AS
|
||||
SELECT
|
||||
SELECT
|
||||
account_id,
|
||||
sum(net_bytes_received) + sum(current_bytes_received) as bytesReceived,
|
||||
sum(net_bytes_sent) + sum(current_bytes_sent) as bytesSent
|
||||
|
|
@ -1238,7 +1238,7 @@ CREATE VIEW `cloud`.`account_netstats_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`account_vmstats_view`;
|
||||
CREATE VIEW `cloud`.`account_vmstats_view` AS
|
||||
SELECT
|
||||
SELECT
|
||||
account_id, state, count(*) as vmcount
|
||||
from
|
||||
`cloud`.`vm_instance`
|
||||
|
|
@ -1246,7 +1246,7 @@ CREATE VIEW `cloud`.`account_vmstats_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`free_ip_view`;
|
||||
CREATE VIEW `cloud`.`free_ip_view` AS
|
||||
select
|
||||
select
|
||||
count(user_ip_address.id) free_ip
|
||||
from
|
||||
`cloud`.`user_ip_address`
|
||||
|
|
@ -1258,7 +1258,7 @@ CREATE VIEW `cloud`.`free_ip_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`account_view`;
|
||||
CREATE VIEW `cloud`.`account_view` AS
|
||||
select
|
||||
select
|
||||
account.id,
|
||||
account.uuid,
|
||||
account.account_name,
|
||||
|
|
@ -1385,7 +1385,7 @@ CREATE VIEW `cloud`.`account_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`async_job_view`;
|
||||
CREATE VIEW `cloud`.`async_job_view` AS
|
||||
select
|
||||
select
|
||||
account.id account_id,
|
||||
account.uuid account_uuid,
|
||||
account.account_name account_name,
|
||||
|
|
@ -1494,7 +1494,7 @@ CREATE VIEW `cloud`.`async_job_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`storage_pool_view`;
|
||||
CREATE VIEW `cloud`.`storage_pool_view` AS
|
||||
select
|
||||
select
|
||||
storage_pool.id,
|
||||
storage_pool.uuid,
|
||||
storage_pool.name,
|
||||
|
|
@ -1543,7 +1543,7 @@ CREATE VIEW `cloud`.`storage_pool_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`disk_offering_view`;
|
||||
CREATE VIEW `cloud`.`disk_offering_view` AS
|
||||
select
|
||||
select
|
||||
disk_offering.id,
|
||||
disk_offering.uuid,
|
||||
disk_offering.name,
|
||||
|
|
@ -1568,7 +1568,7 @@ CREATE VIEW `cloud`.`disk_offering_view` AS
|
|||
|
||||
DROP VIEW IF EXISTS `cloud`.`service_offering_view`;
|
||||
CREATE VIEW `cloud`.`service_offering_view` AS
|
||||
select
|
||||
select
|
||||
service_offering.id,
|
||||
disk_offering.uuid,
|
||||
disk_offering.name,
|
||||
|
|
@ -1599,10 +1599,10 @@ CREATE VIEW `cloud`.`service_offering_view` AS
|
|||
`cloud`.`disk_offering` ON service_offering.id = disk_offering.id
|
||||
left join
|
||||
`cloud`.`domain` ON disk_offering.domain_id = domain.id;
|
||||
|
||||
|
||||
DROP VIEW IF EXISTS `cloud`.`data_center_view`;
|
||||
CREATE VIEW `cloud`.`data_center_view` AS
|
||||
select
|
||||
select
|
||||
data_center.id,
|
||||
data_center.uuid,
|
||||
data_center.name,
|
||||
|
|
@ -1629,8 +1629,8 @@ CREATE VIEW `cloud`.`data_center_view` AS
|
|||
from
|
||||
`cloud`.`data_center`
|
||||
left join
|
||||
`cloud`.`domain` ON data_center.domain_id = domain.id;
|
||||
|
||||
`cloud`.`domain` ON data_center.domain_id = domain.id;
|
||||
|
||||
|
||||
CREATE TABLE `cloud`.`baremetal_dhcp_devices` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
|
||||
|
|
@ -1640,7 +1640,7 @@ CREATE TABLE `cloud`.`baremetal_dhcp_devices` (
|
|||
`device_type` varchar(255) DEFAULT NULL COMMENT 'type of the external device',
|
||||
`physical_network_id` bigint unsigned DEFAULT NULL COMMENT 'id of the physical network in to which external dhcp device is added',
|
||||
`host_id` bigint unsigned DEFAULT NULL COMMENT 'host id coresponding to the external dhcp device',
|
||||
PRIMARY KEY (`id`)
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `cloud`.`baremetal_pxe_devices` (
|
||||
|
|
@ -1651,9 +1651,10 @@ CREATE TABLE `cloud`.`baremetal_pxe_devices` (
|
|||
`device_type` varchar(255) DEFAULT NULL COMMENT 'type of the pxe device',
|
||||
`physical_network_id` bigint unsigned DEFAULT NULL COMMENT 'id of the physical network in to which external pxe device is added',
|
||||
`host_id` bigint unsigned DEFAULT NULL COMMENT 'host id coresponding to the external pxe device',
|
||||
PRIMARY KEY (`id`)
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
CREATE TABLE `cloud`.`ucs_blade` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
|
||||
`uuid` varchar(40) UNIQUE,
|
||||
|
|
|
|||
|
|
@ -101,6 +101,13 @@ CREATE TABLE `vpc_service_map` (
|
|||
|
||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'vm.instancename.flag', 'false', 'Append guest VM display Name (if set) to the internal name of the VM');
|
||||
|
||||
INSERT INTO `cloud`.`guest_os` (id, uuid, category_id, display_name) VALUES (208, UUID(), 6, 'Windows 8');
|
||||
INSERT INTO `cloud`.`guest_os` (id, uuid, category_id, display_name) VALUES (209, UUID(), 6, 'Windows 8 (64 bit)');
|
||||
INSERT INTO `cloud`.`guest_os` (id, uuid, category_id, display_name) VALUES (210, UUID(), 6, 'Windows 8 Server (64 bit)');
|
||||
INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Windows 8', 208);
|
||||
INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Windows 8 (64 bit)', 209);
|
||||
INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Windows 8 Server (64 bit)', 210);
|
||||
|
||||
CREATE TABLE `cloud`.`user_vm_clone_setting` (
|
||||
`vm_id` bigint unsigned NOT NULL COMMENT 'guest VM id',
|
||||
`clone_type` varchar(10) NOT NULL COMMENT 'Full or Linked Clone (applicable to VMs on ESX)',
|
||||
|
|
|
|||
|
|
@ -43,18 +43,6 @@
|
|||
<version>${cs.vmware.api.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cloud.com.vmware</groupId>
|
||||
<artifactId>vmware-vim</artifactId>
|
||||
<version>${cs.vmware.api.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cloud.com.vmware</groupId>
|
||||
<artifactId>vmware-apputils</artifactId>
|
||||
<version>${cs.vmware.api.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.axis</groupId>
|
||||
<artifactId>axis</artifactId>
|
||||
|
|
|
|||
|
|
@ -25,55 +25,55 @@ import com.vmware.vim25.ManagedObjectReference;
|
|||
|
||||
public class BaseMO {
|
||||
private static final Logger s_logger = Logger.getLogger(BaseMO.class);
|
||||
|
||||
|
||||
protected VmwareContext _context;
|
||||
protected ManagedObjectReference _mor;
|
||||
|
||||
private String _name;
|
||||
|
||||
|
||||
public BaseMO(VmwareContext context, ManagedObjectReference mor) {
|
||||
assert(context != null);
|
||||
|
||||
|
||||
_context = context;
|
||||
_mor = mor;
|
||||
}
|
||||
|
||||
|
||||
public BaseMO(VmwareContext context, String morType, String morValue) {
|
||||
assert(context != null);
|
||||
assert(morType != null);
|
||||
assert(morValue != null);
|
||||
|
||||
|
||||
_context = context;
|
||||
_mor = new ManagedObjectReference();
|
||||
_mor.setType(morType);
|
||||
_mor.set_value(morValue);
|
||||
_mor.setValue(morValue);
|
||||
}
|
||||
|
||||
|
||||
public VmwareContext getContext() {
|
||||
return _context;
|
||||
}
|
||||
|
||||
|
||||
public ManagedObjectReference getMor() {
|
||||
assert(_mor != null);
|
||||
return _mor;
|
||||
}
|
||||
|
||||
|
||||
public ManagedObjectReference getParentMor() throws Exception {
|
||||
return (ManagedObjectReference)_context.getServiceUtil().getDynamicProperty(_mor, "parent");
|
||||
return (ManagedObjectReference)_context.getVimClient().getDynamicProperty(_mor, "parent");
|
||||
}
|
||||
|
||||
public String getName() throws Exception {
|
||||
if(_name == null)
|
||||
_name = (String)_context.getServiceUtil().getDynamicProperty(_mor, "name");
|
||||
|
||||
_name = (String)_context.getVimClient().getDynamicProperty(_mor, "name");
|
||||
|
||||
return _name;
|
||||
}
|
||||
|
||||
|
||||
public boolean destroy() throws Exception {
|
||||
ManagedObjectReference morTask = _context.getService().destroy_Task(_mor);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(result.equals("sucess")) {
|
||||
ManagedObjectReference morTask = _context.getService().destroyTask(_mor);
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(result) {
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
return true;
|
||||
} else {
|
||||
|
|
@ -81,16 +81,16 @@ public class BaseMO {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void reload() throws Exception {
|
||||
_context.getService().reload(_mor);
|
||||
}
|
||||
|
||||
|
||||
public boolean rename(String newName) throws Exception {
|
||||
ManagedObjectReference morTask = _context.getService().rename_Task(_mor, newName);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(result.equals("sucess")) {
|
||||
ManagedObjectReference morTask = _context.getService().renameTask(_mor, newName);
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(result) {
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
return true;
|
||||
} else {
|
||||
|
|
@ -98,11 +98,11 @@ public class BaseMO {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void setCustomFieldValue(String fieldName, String value) throws Exception {
|
||||
CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context,
|
||||
CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context,
|
||||
_context.getServiceContent().getCustomFieldsManager());
|
||||
|
||||
|
||||
int key = getCustomFieldKey(fieldName);
|
||||
if(key == 0) {
|
||||
try {
|
||||
|
|
@ -114,36 +114,36 @@ public class BaseMO {
|
|||
key = getCustomFieldKey(fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(key == 0)
|
||||
throw new Exception("Unable to setup custom field facility");
|
||||
|
||||
|
||||
cfmMo.setField(getMor(), key, value);
|
||||
}
|
||||
|
||||
|
||||
public String getCustomFieldValue(String fieldName) throws Exception {
|
||||
int key = getCustomFieldKey(fieldName);
|
||||
if(key == 0)
|
||||
return null;
|
||||
|
||||
CustomFieldStringValue cfValue = (CustomFieldStringValue)_context.getServiceUtil().getDynamicProperty(getMor(),
|
||||
|
||||
CustomFieldStringValue cfValue = (CustomFieldStringValue)_context.getVimClient().getDynamicProperty(getMor(),
|
||||
String.format("value[%d]", key));
|
||||
if(cfValue != null)
|
||||
return cfValue.getValue();
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public int getCustomFieldKey(String fieldName) throws Exception {
|
||||
return getCustomFieldKey(getMor().getType(), fieldName);
|
||||
}
|
||||
|
||||
|
||||
public int getCustomFieldKey(String morType, String fieldName) throws Exception {
|
||||
assert(morType != null);
|
||||
|
||||
CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context,
|
||||
|
||||
CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context,
|
||||
_context.getServiceContent().getCustomFieldsManager());
|
||||
|
||||
|
||||
return cfmMo.getCustomFieldKey(morType, fieldName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import org.apache.log4j.Logger;
|
|||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.google.gson.Gson;
|
||||
import com.vmware.apputils.vim25.ServiceUtil;
|
||||
import com.vmware.vim25.ArrayOfHostIpRouteEntry;
|
||||
import com.vmware.vim25.ClusterComputeResourceSummary;
|
||||
import com.vmware.vim25.ClusterConfigInfoEx;
|
||||
|
|
@ -47,24 +46,25 @@ import com.vmware.vim25.ObjectSpec;
|
|||
import com.vmware.vim25.OptionValue;
|
||||
import com.vmware.vim25.PropertyFilterSpec;
|
||||
import com.vmware.vim25.PropertySpec;
|
||||
import com.vmware.vim25.SelectionSpec;
|
||||
import com.vmware.vim25.TraversalSpec;
|
||||
import com.vmware.vim25.VirtualMachineConfigSpec;
|
||||
|
||||
import edu.emory.mathcs.backport.java.util.Arrays;
|
||||
|
||||
//
|
||||
// interface. This has changed as ClusterMO no longer works as a special host anymore. Need to refactor accordingly
|
||||
//
|
||||
public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
|
||||
private static final Logger s_logger = Logger.getLogger(ClusterMO.class);
|
||||
|
||||
|
||||
public ClusterMO(VmwareContext context, ManagedObjectReference morCluster) {
|
||||
super(context, morCluster);
|
||||
}
|
||||
|
||||
|
||||
public ClusterMO(VmwareContext context, String morType, String morValue) {
|
||||
super(context, morType, morValue);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getHyperHostName() throws Exception {
|
||||
return getName();
|
||||
|
|
@ -73,40 +73,39 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
|
|||
@Override
|
||||
public ClusterDasConfigInfo getDasConfig() throws Exception {
|
||||
// Note getDynamicProperty() with "configurationEx.dasConfig" does not work here because of that dasConfig is a property in subclass
|
||||
ClusterConfigInfoEx configInfo = (ClusterConfigInfoEx)_context.getServiceUtil().getDynamicProperty(_mor, "configurationEx");
|
||||
ClusterConfigInfoEx configInfo = (ClusterConfigInfoEx)_context.getVimClient().getDynamicProperty(_mor, "configurationEx");
|
||||
return configInfo.getDasConfig();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ManagedObjectReference getHyperHostDatacenter() throws Exception {
|
||||
Pair<DatacenterMO, String> dcPair = DatacenterMO.getOwnerDatacenter(getContext(), getMor());
|
||||
assert(dcPair != null);
|
||||
return dcPair.first().getMor();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ManagedObjectReference getHyperHostOwnerResourcePool() throws Exception {
|
||||
ServiceUtil serviceUtil = _context.getServiceUtil();
|
||||
return (ManagedObjectReference)serviceUtil.getDynamicProperty(getMor(), "resourcePool");
|
||||
return (ManagedObjectReference)_context.getVimClient().getDynamicProperty(getMor(), "resourcePool");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ManagedObjectReference getHyperHostCluster() throws Exception {
|
||||
return _mor;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VirtualMachineMO findVmOnHyperHost(String name) throws Exception {
|
||||
ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { "name" });
|
||||
return HypervisorHostHelper.findVmFromObjectContent(_context, ocs, name);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VirtualMachineMO findVmOnPeerHyperHost(String name) throws Exception {
|
||||
ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { "name" });
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
DynamicProperty[] props = oc.getPropSet();
|
||||
List<DynamicProperty> props = oc.getPropSet();
|
||||
if(props != null) {
|
||||
for(DynamicProperty prop : props) {
|
||||
if(prop.getVal().toString().equals(name))
|
||||
|
|
@ -117,54 +116,54 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ObjectContent[] getVmPropertiesOnHyperHost(String[] propertyPaths) throws Exception {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - retrieveProperties() for VM properties. target MOR: " + _mor.get_value() + ", properties: " + new Gson().toJson(propertyPaths));
|
||||
|
||||
s_logger.trace("vCenter API trace - retrieveProperties() for VM properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths));
|
||||
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec.setType("VirtualMachine");
|
||||
pSpec.setPathSet(propertyPaths);
|
||||
pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
|
||||
|
||||
TraversalSpec host2VmFolderTraversal = new TraversalSpec();
|
||||
host2VmFolderTraversal.setType("HostSystem");
|
||||
host2VmFolderTraversal.setPath("vm");
|
||||
host2VmFolderTraversal.setName("host2VmFolderTraversal");
|
||||
|
||||
|
||||
TraversalSpec cluster2HostFolderTraversal = new TraversalSpec();
|
||||
cluster2HostFolderTraversal.setType("ClusterComputeResource");
|
||||
cluster2HostFolderTraversal.setPath("host");
|
||||
cluster2HostFolderTraversal.setName("cluster2HostFolderTraversal");
|
||||
cluster2HostFolderTraversal.setSelectSet(new SelectionSpec[] { host2VmFolderTraversal });
|
||||
|
||||
cluster2HostFolderTraversal.getSelectSet().add(host2VmFolderTraversal);
|
||||
|
||||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec.setObj(getMor());
|
||||
oSpec.setSkip(Boolean.TRUE);
|
||||
oSpec.setSelectSet(new SelectionSpec[] { cluster2HostFolderTraversal });
|
||||
|
||||
oSpec.getSelectSet().add(cluster2HostFolderTraversal);
|
||||
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||
|
||||
ObjectContent[] properties = _context.getService().retrieveProperties(
|
||||
_context.getServiceContent().getPropertyCollector(),
|
||||
new PropertyFilterSpec[] { pfSpec });
|
||||
|
||||
pfSpec.getPropSet().add(pSpec);
|
||||
pfSpec.getObjectSet().add(oSpec);
|
||||
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
|
||||
pfSpecArr.add(pfSpec);
|
||||
|
||||
List<ObjectContent> properties = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - retrieveProperties() done");
|
||||
return properties;
|
||||
return properties.toArray(new ObjectContent[properties.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectContent[] getDatastorePropertiesOnHyperHost(String[] propertyPaths) throws Exception {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - retrieveProperties() on Datastore properties. target MOR: " + _mor.get_value() + ", properties: " + new Gson().toJson(propertyPaths));
|
||||
|
||||
s_logger.trace("vCenter API trace - retrieveProperties() on Datastore properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths));
|
||||
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec.setType("Datastore");
|
||||
pSpec.setPathSet(propertyPaths);
|
||||
|
||||
pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
|
||||
|
||||
TraversalSpec cluster2DatastoreTraversal = new TraversalSpec();
|
||||
cluster2DatastoreTraversal.setType("ClusterComputeResource");
|
||||
cluster2DatastoreTraversal.setPath("datastore");
|
||||
|
|
@ -173,29 +172,30 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
|
|||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec.setObj(_mor);
|
||||
oSpec.setSkip(Boolean.TRUE);
|
||||
oSpec.setSelectSet(new SelectionSpec[] { cluster2DatastoreTraversal });
|
||||
oSpec.getSelectSet().add(cluster2DatastoreTraversal);
|
||||
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||
|
||||
ObjectContent[] properties = _context.getService().retrieveProperties(
|
||||
_context.getServiceContent().getPropertyCollector(),
|
||||
new PropertyFilterSpec[] { pfSpec });
|
||||
|
||||
pfSpec.getPropSet().add(pSpec);
|
||||
pfSpec.getObjectSet().add(oSpec);
|
||||
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
|
||||
pfSpecArr.add(pfSpec);
|
||||
|
||||
List<ObjectContent> properties = _context.getService().retrieveProperties(
|
||||
_context.getPropertyCollector(), pfSpecArr);
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - retrieveProperties() done");
|
||||
return properties;
|
||||
return properties.toArray(new ObjectContent[properties.size()]);
|
||||
}
|
||||
|
||||
|
||||
private ObjectContent[] getHostPropertiesOnCluster(String[] propertyPaths) throws Exception {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - retrieveProperties() on Host properties. target MOR: " + _mor.get_value() + ", properties: " + new Gson().toJson(propertyPaths));
|
||||
s_logger.trace("vCenter API trace - retrieveProperties() on Host properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths));
|
||||
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec.setType("HostSystem");
|
||||
pSpec.setPathSet(propertyPaths);
|
||||
|
||||
pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
|
||||
|
||||
TraversalSpec cluster2HostTraversal = new TraversalSpec();
|
||||
cluster2HostTraversal.setType("ClusterComputeResource");
|
||||
cluster2HostTraversal.setPath("host");
|
||||
|
|
@ -204,63 +204,65 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
|
|||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec.setObj(_mor);
|
||||
oSpec.setSkip(Boolean.TRUE);
|
||||
oSpec.setSelectSet(new SelectionSpec[] { cluster2HostTraversal });
|
||||
oSpec.getSelectSet().add(cluster2HostTraversal);
|
||||
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||
|
||||
ObjectContent[] properties = _context.getService().retrieveProperties(
|
||||
_context.getServiceContent().getPropertyCollector(),
|
||||
new PropertyFilterSpec[] { pfSpec });
|
||||
pfSpec.getPropSet().add(pSpec);
|
||||
pfSpec.getObjectSet().add(oSpec);
|
||||
|
||||
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
|
||||
pfSpecArr.add(pfSpec);
|
||||
|
||||
List<ObjectContent> properties = _context.getService().retrieveProperties(
|
||||
_context.getPropertyCollector(), pfSpecArr);
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - retrieveProperties() done");
|
||||
return properties;
|
||||
return properties.toArray(new ObjectContent[properties.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createVm(VirtualMachineConfigSpec vmSpec) throws Exception {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - createVM_Task(). target MOR: " + _mor.get_value() + ", VirtualMachineConfigSpec: " + new Gson().toJson(vmSpec));
|
||||
|
||||
s_logger.trace("vCenter API trace - createVM_Task(). target MOR: " + _mor.getValue() + ", VirtualMachineConfigSpec: " + new Gson().toJson(vmSpec));
|
||||
|
||||
assert(vmSpec != null);
|
||||
DatacenterMO dcMo = new DatacenterMO(_context, getHyperHostDatacenter());
|
||||
ManagedObjectReference morPool = getHyperHostOwnerResourcePool();
|
||||
|
||||
ManagedObjectReference morTask = _context.getService().createVM_Task(
|
||||
|
||||
ManagedObjectReference morTask = _context.getService().createVMTask(
|
||||
dcMo.getVmFolder(), vmSpec, morPool, null);
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
|
||||
if(result.equals("sucess")) {
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
|
||||
if(result) {
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - createVM_Task() done(successfully)");
|
||||
return true;
|
||||
} else {
|
||||
s_logger.error("VMware createVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
}
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - createVM_Task() done(failed)");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void importVmFromOVF(String ovfFilePath, String vmName, DatastoreMO dsMo, String diskOption) throws Exception {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - importVmFromOVF(). target MOR: " + _mor.get_value() + ", ovfFilePath: " + ovfFilePath + ", vmName: " + vmName
|
||||
+ ", datastore: " + dsMo.getMor().get_value() + ", diskOption: " + diskOption);
|
||||
s_logger.trace("vCenter API trace - importVmFromOVF(). target MOR: " + _mor.getValue() + ", ovfFilePath: " + ovfFilePath + ", vmName: " + vmName
|
||||
+ ", datastore: " + dsMo.getMor().getValue() + ", diskOption: " + diskOption);
|
||||
|
||||
ManagedObjectReference morRp = getHyperHostOwnerResourcePool();
|
||||
assert(morRp != null);
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - importVmFromOVF(). resource pool: " + morRp.get_value());
|
||||
|
||||
s_logger.trace("vCenter API trace - importVmFromOVF(). resource pool: " + morRp.getValue());
|
||||
|
||||
HypervisorHostHelper.importVmFromOVF(this, ovfFilePath, vmName, dsMo, diskOption, morRp, null);
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - importVmFromOVF() done");
|
||||
}
|
||||
|
|
@ -268,83 +270,83 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
|
|||
@Override
|
||||
public boolean createBlankVm(String vmName, int cpuCount, int cpuSpeedMHz, int cpuReservedMHz, boolean limitCpuUse, int memoryMB, int memoryReserveMB,
|
||||
String guestOsIdentifier, ManagedObjectReference morDs, boolean snapshotDirToParent) throws Exception {
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - createBlankVm(). target MOR: " + _mor.get_value() + ", vmName: " + vmName + ", cpuCount: " + cpuCount
|
||||
+ ", cpuSpeedMhz: " + cpuSpeedMHz + ", cpuReservedMHz: " + cpuReservedMHz + ", limitCpu: " + limitCpuUse + ", memoryMB: " + memoryMB
|
||||
+ ", guestOS: " + guestOsIdentifier + ", datastore: " + morDs.get_value() + ", snapshotDirToParent: " + snapshotDirToParent);
|
||||
|
||||
s_logger.trace("vCenter API trace - createBlankVm(). target MOR: " + _mor.getValue() + ", vmName: " + vmName + ", cpuCount: " + cpuCount
|
||||
+ ", cpuSpeedMhz: " + cpuSpeedMHz + ", cpuReservedMHz: " + cpuReservedMHz + ", limitCpu: " + limitCpuUse + ", memoryMB: " + memoryMB
|
||||
+ ", guestOS: " + guestOsIdentifier + ", datastore: " + morDs.getValue() + ", snapshotDirToParent: " + snapshotDirToParent);
|
||||
|
||||
boolean result = HypervisorHostHelper.createBlankVm(this, vmName, cpuCount, cpuSpeedMHz, cpuReservedMHz, limitCpuUse,
|
||||
memoryMB, memoryReserveMB, guestOsIdentifier, morDs, snapshotDirToParent);
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - createBlankVm() done");
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ManagedObjectReference mountDatastore(boolean vmfsDatastore, String poolHostAddress,
|
||||
public ManagedObjectReference mountDatastore(boolean vmfsDatastore, String poolHostAddress,
|
||||
int poolHostPort, String poolPath, String poolUuid) throws Exception {
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - mountDatastore(). target MOR: " + _mor.get_value() + ", vmfs: " + vmfsDatastore + ", poolHost: " + poolHostAddress
|
||||
s_logger.trace("vCenter API trace - mountDatastore(). target MOR: " + _mor.getValue() + ", vmfs: " + vmfsDatastore + ", poolHost: " + poolHostAddress
|
||||
+ ", poolHostPort: " + poolHostPort + ", poolPath: " + poolPath + ", poolUuid: " + poolUuid);
|
||||
|
||||
|
||||
ManagedObjectReference morDs = null;
|
||||
ManagedObjectReference morDsFirst = null;
|
||||
ManagedObjectReference[] hosts = (ManagedObjectReference[])_context.getServiceUtil().getDynamicProperty(_mor, "host");
|
||||
if(hosts != null && hosts.length > 0) {
|
||||
List<ManagedObjectReference> hosts = (List<ManagedObjectReference>)_context.getVimClient().getDynamicProperty(_mor, "host");
|
||||
if(hosts != null && hosts.size() > 0) {
|
||||
for(ManagedObjectReference morHost : hosts) {
|
||||
HostMO hostMo = new HostMO(_context, morHost);
|
||||
morDs = hostMo.mountDatastore(vmfsDatastore, poolHostAddress, poolHostPort, poolPath, poolUuid);
|
||||
if(morDsFirst == null)
|
||||
morDsFirst = morDs;
|
||||
|
||||
|
||||
// assume datastore is in scope of datacenter
|
||||
assert(morDsFirst.get_value().equals(morDs.get_value()));
|
||||
assert(morDsFirst.getValue().equals(morDs.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(morDs == null) {
|
||||
String msg = "Failed to mount datastore in all hosts within the cluster";
|
||||
s_logger.error(msg);
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - mountDatastore() done(failed)");
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - mountDatastore() done(successfully)");
|
||||
|
||||
|
||||
return morDs;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void unmountDatastore(String poolUuid) throws Exception {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - unmountDatastore(). target MOR: " + _mor.get_value() + ", poolUuid: " + poolUuid);
|
||||
|
||||
ManagedObjectReference[] hosts = (ManagedObjectReference[])_context.getServiceUtil().getDynamicProperty(_mor, "host");
|
||||
if(hosts != null && hosts.length > 0) {
|
||||
s_logger.trace("vCenter API trace - unmountDatastore(). target MOR: " + _mor.getValue() + ", poolUuid: " + poolUuid);
|
||||
|
||||
List<ManagedObjectReference> hosts = (List<ManagedObjectReference>)_context.getVimClient().getDynamicProperty(_mor, "host");
|
||||
if(hosts != null && hosts.size() > 0) {
|
||||
for(ManagedObjectReference morHost : hosts) {
|
||||
HostMO hostMo = new HostMO(_context, morHost);
|
||||
hostMo.unmountDatastore(poolUuid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - unmountDatastore() done");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ManagedObjectReference findDatastore(String poolUuid) throws Exception {
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - findDatastore(). target MOR: " + _mor.get_value() + ", poolUuid: " + poolUuid);
|
||||
|
||||
CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context,
|
||||
s_logger.trace("vCenter API trace - findDatastore(). target MOR: " + _mor.getValue() + ", poolUuid: " + poolUuid);
|
||||
|
||||
CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context,
|
||||
_context.getServiceContent().getCustomFieldsManager());
|
||||
int key = cfmMo.getCustomFieldKey("Datastore", CustomFieldConstants.CLOUD_UUID);
|
||||
assert(key != 0);
|
||||
|
|
@ -352,16 +354,16 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
|
|||
ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] {"name", String.format("value[%d]", key)});
|
||||
if(ocs != null) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
if(oc.getPropSet(0).getVal().equals(poolUuid))
|
||||
if(oc.getPropSet().get(0).getVal().equals(poolUuid))
|
||||
return oc.getObj();
|
||||
|
||||
if(oc.getPropSet().length > 1) {
|
||||
DynamicProperty prop = oc.getPropSet(1);
|
||||
|
||||
if(oc.getPropSet().size() > 1) {
|
||||
DynamicProperty prop = oc.getPropSet().get(1);
|
||||
if(prop != null && prop.getVal() != null) {
|
||||
if(prop.getVal() instanceof CustomFieldStringValue) {
|
||||
String val = ((CustomFieldStringValue)prop.getVal()).getValue();
|
||||
if(val.equalsIgnoreCase(poolUuid)) {
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - findDatastore() done(successfully)");
|
||||
return oc.getObj();
|
||||
|
|
@ -371,31 +373,31 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - findDatastore() done(failed)");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ManagedObjectReference findDatastoreByExportPath(String exportPath) throws Exception {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - findDatastoreByExportPath(). target MOR: " + _mor.get_value() + ", exportPath: " + exportPath);
|
||||
|
||||
s_logger.trace("vCenter API trace - findDatastoreByExportPath(). target MOR: " + _mor.getValue() + ", exportPath: " + exportPath);
|
||||
|
||||
ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] {"info"});
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
DatastoreInfo dsInfo = (DatastoreInfo)oc.getPropSet(0).getVal();
|
||||
DatastoreInfo dsInfo = (DatastoreInfo)oc.getPropSet().get(0).getVal();
|
||||
if(dsInfo != null && dsInfo instanceof NasDatastoreInfo) {
|
||||
NasDatastoreInfo info = (NasDatastoreInfo)dsInfo;
|
||||
if(info != null) {
|
||||
String vmwareUrl = info.getUrl();
|
||||
if(vmwareUrl.charAt(vmwareUrl.length() - 1) == '/')
|
||||
vmwareUrl = vmwareUrl.substring(0, vmwareUrl.length() - 1);
|
||||
|
||||
|
||||
URI uri = new URI(vmwareUrl);
|
||||
if(uri.getPath().equals("/" + exportPath)) {
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(successfully)");
|
||||
return oc.getObj();
|
||||
|
|
@ -404,49 +406,49 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(failed)");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ManagedObjectReference findMigrationTarget(VirtualMachineMO vmMo) throws Exception {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - findMigrationTarget(). target MOR: " + _mor.get_value() + ", vm: " + vmMo.getName());
|
||||
s_logger.trace("vCenter API trace - findMigrationTarget(). target MOR: " + _mor.getValue() + ", vm: " + vmMo.getName());
|
||||
|
||||
ClusterHostRecommendation[] candidates = recommendHostsForVm(vmMo);
|
||||
if(candidates != null && candidates.length > 0) {
|
||||
List<ClusterHostRecommendation> candidates = recommendHostsForVm(vmMo);
|
||||
if(candidates != null && candidates.size() > 0) {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - findMigrationTarget() done(successfully)");
|
||||
return candidates[0].getHost();
|
||||
return candidates.get(0).getHost();
|
||||
}
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - findMigrationTarget() done(failed)");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isHyperHostConnected() throws Exception {
|
||||
ObjectContent[] ocs = getHostPropertiesOnCluster(new String[] {"runtime"});
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
HostRuntimeInfo runtimeInfo = (HostRuntimeInfo)oc.getPropSet(0).getVal();
|
||||
// as long as we have one host connected, we assume the cluster is up
|
||||
if(runtimeInfo.getConnectionState() == HostSystemConnectionState.connected)
|
||||
HostRuntimeInfo runtimeInfo = (HostRuntimeInfo)oc.getPropSet().get(0).getVal();
|
||||
// as long as we have one host connected, we assume the cluster is up
|
||||
if(runtimeInfo.getConnectionState() == HostSystemConnectionState.CONNECTED)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getHyperHostDefaultGateway() throws Exception {
|
||||
ObjectContent[] ocs = getHostPropertiesOnCluster(new String[] {"config.network.routeTableInfo.ipRoute"});
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
ArrayOfHostIpRouteEntry entries = (ArrayOfHostIpRouteEntry)oc.getPropSet(0).getVal();
|
||||
ArrayOfHostIpRouteEntry entries = (ArrayOfHostIpRouteEntry)oc.getPropSet().get(0).getVal();
|
||||
if(entries != null) {
|
||||
for(HostIpRouteEntry entry : entries.getHostIpRouteEntry()) {
|
||||
if(entry.getNetwork().equalsIgnoreCase("0.0.0.0"))
|
||||
|
|
@ -455,28 +457,28 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
throw new Exception("Could not find host default gateway, host is not properly configured?");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VmwareHypervisorHostResourceSummary getHyperHostResourceSummary() throws Exception {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - getHyperHostResourceSummary(). target MOR: " + _mor.get_value());
|
||||
s_logger.trace("vCenter API trace - getHyperHostResourceSummary(). target MOR: " + _mor.getValue());
|
||||
|
||||
VmwareHypervisorHostResourceSummary summary = new VmwareHypervisorHostResourceSummary();
|
||||
|
||||
ComputeResourceSummary vmwareSummary = (ComputeResourceSummary)_context.getServiceUtil().getDynamicProperty(
|
||||
|
||||
ComputeResourceSummary vmwareSummary = (ComputeResourceSummary)_context.getVimClient().getDynamicProperty(
|
||||
_mor, "summary");
|
||||
|
||||
// TODO, need to use traversal to optimize retrieve of
|
||||
|
||||
// TODO, need to use traversal to optimize retrieve of
|
||||
int cpuNumInCpuThreads = 1;
|
||||
ManagedObjectReference[] hosts = (ManagedObjectReference[])_context.getServiceUtil().getDynamicProperty(_mor, "host");
|
||||
if(hosts != null && hosts.length > 0) {
|
||||
List<ManagedObjectReference> hosts = (List<ManagedObjectReference>)_context.getVimClient().getDynamicProperty(_mor, "host");
|
||||
if(hosts != null && hosts.size() > 0) {
|
||||
for(ManagedObjectReference morHost : hosts) {
|
||||
HostMO hostMo = new HostMO(_context, morHost);
|
||||
HostHardwareSummary hardwareSummary = hostMo.getHostHardwareSummary();
|
||||
|
||||
|
||||
if(hardwareSummary.getNumCpuCores()*hardwareSummary.getNumCpuThreads() > cpuNumInCpuThreads)
|
||||
cpuNumInCpuThreads = hardwareSummary.getNumCpuCores()*hardwareSummary.getNumCpuThreads();
|
||||
}
|
||||
|
|
@ -484,74 +486,74 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
|
|||
summary.setCpuCount(cpuNumInCpuThreads);
|
||||
summary.setCpuSpeed(vmwareSummary.getTotalCpu());
|
||||
summary.setMemoryBytes(vmwareSummary.getTotalMemory());
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - getHyperHostResourceSummary() done");
|
||||
return summary;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VmwareHypervisorHostNetworkSummary getHyperHostNetworkSummary(String esxServiceConsolePort) throws Exception {
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - getHyperHostNetworkSummary(). target MOR: " + _mor.get_value() + ", mgmtPortgroup: " + esxServiceConsolePort);
|
||||
|
||||
ManagedObjectReference[] hosts = (ManagedObjectReference[])_context.getServiceUtil().getDynamicProperty(_mor, "host");
|
||||
if(hosts != null && hosts.length > 0) {
|
||||
VmwareHypervisorHostNetworkSummary summary = new HostMO(_context, hosts[0]).getHyperHostNetworkSummary(esxServiceConsolePort);
|
||||
|
||||
s_logger.trace("vCenter API trace - getHyperHostNetworkSummary(). target MOR: " + _mor.getValue() + ", mgmtPortgroup: " + esxServiceConsolePort);
|
||||
|
||||
List<ManagedObjectReference> hosts = (List<ManagedObjectReference>)_context.getVimClient().getDynamicProperty(_mor, "host");
|
||||
if(hosts != null && hosts.size() > 0) {
|
||||
VmwareHypervisorHostNetworkSummary summary = new HostMO(_context, hosts.get(0)).getHyperHostNetworkSummary(esxServiceConsolePort);
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - getHyperHostResourceSummary() done(successfully)");
|
||||
return summary;
|
||||
}
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - getHyperHostResourceSummary() done(failed)");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ComputeResourceSummary getHyperHostHardwareSummary() throws Exception {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - getHyperHostHardwareSummary(). target MOR: " + _mor.get_value());
|
||||
s_logger.trace("vCenter API trace - getHyperHostHardwareSummary(). target MOR: " + _mor.getValue());
|
||||
|
||||
ClusterComputeResourceSummary hardwareSummary = (ClusterComputeResourceSummary)
|
||||
_context.getServiceUtil().getDynamicProperty(_mor, "summary");
|
||||
_context.getVimClient().getDynamicProperty(_mor, "summary");
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - getHyperHostHardwareSummary() done");
|
||||
return hardwareSummary;
|
||||
}
|
||||
|
||||
public ClusterHostRecommendation[] recommendHostsForVm(VirtualMachineMO vmMo) throws Exception {
|
||||
return _context.getService().recommendHostsForVm(_mor, vmMo.getMor(),
|
||||
public List<ClusterHostRecommendation> recommendHostsForVm(VirtualMachineMO vmMo) throws Exception {
|
||||
return _context.getService().recommendHostsForVm(_mor, vmMo.getMor(),
|
||||
getHyperHostOwnerResourcePool());
|
||||
}
|
||||
|
||||
|
||||
public List<Pair<ManagedObjectReference, String>> getClusterHosts() throws Exception {
|
||||
List<Pair<ManagedObjectReference, String>> hosts = new ArrayList<Pair<ManagedObjectReference, String>>();
|
||||
|
||||
|
||||
ObjectContent[] ocs = getHostPropertiesOnCluster(new String[] {"name"});
|
||||
if(ocs != null) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
ManagedObjectReference morHost = oc.getObj();
|
||||
String name = (String)oc.getPropSet(0).getVal();
|
||||
|
||||
String name = (String)oc.getPropSet().get(0).getVal();
|
||||
|
||||
hosts.add(new Pair<ManagedObjectReference, String>(morHost, name));
|
||||
}
|
||||
}
|
||||
return hosts;
|
||||
}
|
||||
|
||||
|
||||
public HashMap<String, Integer> getVmVncPortsOnCluster() throws Exception {
|
||||
ObjectContent[] ocs = getVmPropertiesOnHyperHost(
|
||||
new String[] { "name", "config.extraConfig[\"RemoteDisplay.vnc.port\"]" }
|
||||
);
|
||||
|
||||
|
||||
HashMap<String, Integer> portInfo = new HashMap<String, Integer>();
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
DynamicProperty[] objProps = oc.getPropSet();
|
||||
List<DynamicProperty> objProps = oc.getPropSet();
|
||||
if(objProps != null) {
|
||||
String name = null;
|
||||
String value = null;
|
||||
|
|
@ -561,16 +563,16 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
|
|||
} else {
|
||||
OptionValue optValue = (OptionValue)objProp.getVal();
|
||||
value = (String)optValue.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(name != null && value != null) {
|
||||
portInfo.put(name, Integer.parseInt(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return portInfo;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
// under the License.
|
||||
package com.cloud.hypervisor.vmware.mo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.vmware.vim25.CustomFieldDef;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
|
|
@ -26,34 +28,34 @@ public class CustomFieldsManagerMO extends BaseMO {
|
|||
public CustomFieldsManagerMO(VmwareContext context, ManagedObjectReference mor) {
|
||||
super(context, mor);
|
||||
}
|
||||
|
||||
|
||||
public CustomFieldsManagerMO(VmwareContext context, String morType, String morValue) {
|
||||
super(context, morType, morValue);
|
||||
}
|
||||
|
||||
public CustomFieldDef addCustomerFieldDef(String fieldName, String morType,
|
||||
|
||||
public CustomFieldDef addCustomerFieldDef(String fieldName, String morType,
|
||||
PrivilegePolicyDef fieldDefPolicy, PrivilegePolicyDef fieldPolicy) throws Exception {
|
||||
return _context.getService().addCustomFieldDef(getMor(), fieldName, morType, fieldDefPolicy, fieldPolicy);
|
||||
}
|
||||
|
||||
|
||||
public void removeCustomFieldDef(int key) throws Exception {
|
||||
_context.getService().removeCustomFieldDef(getMor(), key);
|
||||
}
|
||||
|
||||
|
||||
public void renameCustomFieldDef(int key, String name) throws Exception {
|
||||
_context.getService().renameCustomFieldDef(getMor(), key, name);
|
||||
}
|
||||
|
||||
|
||||
public void setField(ManagedObjectReference morEntity, int key, String value) throws Exception {
|
||||
_context.getService().setField(getMor(), morEntity, key, value);
|
||||
}
|
||||
|
||||
public CustomFieldDef[] getFields() throws Exception {
|
||||
return (CustomFieldDef[])_context.getServiceUtil().getDynamicProperty(getMor(), "field");
|
||||
|
||||
public List<CustomFieldDef> getFields() throws Exception {
|
||||
return (List<CustomFieldDef>)_context.getVimClient().getDynamicProperty(getMor(), "field");
|
||||
}
|
||||
|
||||
|
||||
public int getCustomFieldKey(String morType, String fieldName) throws Exception {
|
||||
CustomFieldDef[] fields = getFields();
|
||||
List<CustomFieldDef> fields = getFields();
|
||||
if(fields != null) {
|
||||
for(CustomFieldDef field : fields) {
|
||||
if(field.getName().equals(fieldName) && field.getManagedObjectType().equals(morType))
|
||||
|
|
@ -62,12 +64,12 @@ public class CustomFieldsManagerMO extends BaseMO {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public int ensureCustomFieldDef(String morType, String fieldName) throws Exception {
|
||||
int key = getCustomFieldKey(morType, fieldName);
|
||||
if(key > 0)
|
||||
return key;
|
||||
|
||||
|
||||
try {
|
||||
CustomFieldDef field = addCustomerFieldDef(fieldName, morType, null, null);
|
||||
return field.getKey();
|
||||
|
|
@ -75,10 +77,10 @@ public class CustomFieldsManagerMO extends BaseMO {
|
|||
// assuming that someone is adding it
|
||||
key = getCustomFieldKey(morType, fieldName);
|
||||
}
|
||||
|
||||
|
||||
if(key == 0)
|
||||
throw new Exception("Unable to setup custom field facility for " + morType + ":" + fieldName);
|
||||
|
||||
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import java.util.List;
|
|||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.vmware.apputils.vim25.ServiceUtil;
|
||||
import com.vmware.vim25.CustomFieldStringValue;
|
||||
import com.vmware.vim25.DVPortgroupConfigInfo;
|
||||
import com.vmware.vim25.DistributedVirtualSwitchPortConnection;
|
||||
|
|
@ -34,59 +33,58 @@ import com.vmware.vim25.PropertyFilterSpec;
|
|||
import com.vmware.vim25.PropertySpec;
|
||||
import com.vmware.vim25.SelectionSpec;
|
||||
import com.vmware.vim25.TraversalSpec;
|
||||
import com.vmware.vim25.VirtualDeviceBackingInfo;
|
||||
import com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo;
|
||||
import com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo;
|
||||
import edu.emory.mathcs.backport.java.util.Arrays;
|
||||
|
||||
public class DatacenterMO extends BaseMO {
|
||||
|
||||
|
||||
public DatacenterMO(VmwareContext context, ManagedObjectReference morDc) {
|
||||
super(context, morDc);
|
||||
}
|
||||
|
||||
|
||||
public DatacenterMO(VmwareContext context, String morType, String morValue) {
|
||||
super(context, morType, morValue);
|
||||
}
|
||||
|
||||
|
||||
public DatacenterMO(VmwareContext context, String dcName) throws Exception {
|
||||
super(context, null);
|
||||
|
||||
_mor = _context.getServiceUtil().getDecendentMoRef(_context.getRootFolder(), "Datacenter", dcName);
|
||||
|
||||
_mor = _context.getVimClient().getDecendentMoRef(_context.getRootFolder(), "Datacenter", dcName);
|
||||
assert(_mor != null);
|
||||
}
|
||||
|
||||
public String getName() throws Exception {
|
||||
return (String)_context.getServiceUtil().getDynamicProperty(_mor, "name");
|
||||
|
||||
@Override
|
||||
public String getName() throws Exception {
|
||||
return (String)_context.getVimClient().getDynamicProperty(_mor, "name");
|
||||
}
|
||||
|
||||
public void registerTemplate(ManagedObjectReference morHost, String datastoreName,
|
||||
|
||||
public void registerTemplate(ManagedObjectReference morHost, String datastoreName,
|
||||
String templateName, String templateFileName) throws Exception {
|
||||
|
||||
ServiceUtil serviceUtil = _context.getServiceUtil();
|
||||
|
||||
ManagedObjectReference morFolder = (ManagedObjectReference)serviceUtil.getDynamicProperty(
|
||||
|
||||
|
||||
ManagedObjectReference morFolder = (ManagedObjectReference)_context.getVimClient().getDynamicProperty(
|
||||
_mor, "vmFolder");
|
||||
assert(morFolder != null);
|
||||
|
||||
ManagedObjectReference morTask = _context.getService().registerVM_Task(
|
||||
morFolder,
|
||||
|
||||
ManagedObjectReference morTask = _context.getService().registerVMTask(
|
||||
morFolder,
|
||||
String.format("[%s] %s/%s", datastoreName, templateName, templateFileName),
|
||||
templateName, true,
|
||||
templateName, true,
|
||||
null, morHost);
|
||||
|
||||
String result = serviceUtil.waitForTask(morTask);
|
||||
if (!result.equalsIgnoreCase("Sucess")) {
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if (!result) {
|
||||
throw new Exception("Unable to register template due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
} else {
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public VirtualMachineMO findVm(String vmName) throws Exception {
|
||||
ObjectContent[] ocs = getVmPropertiesOnDatacenterVmFolder(new String[] { "name" });
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
List<ObjectContent> ocs = getVmPropertiesOnDatacenterVmFolder(new String[] { "name" });
|
||||
if(ocs != null && ocs.size() > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
DynamicProperty[] props = oc.getPropSet();
|
||||
List<DynamicProperty> props = oc.getPropSet();
|
||||
if(props != null) {
|
||||
for(DynamicProperty prop : props) {
|
||||
if(prop.getVal().toString().equals(vmName))
|
||||
|
|
@ -97,19 +95,19 @@ public class DatacenterMO extends BaseMO {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public List<VirtualMachineMO> findVmByNameAndLabel(String vmLabel) throws Exception {
|
||||
CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context,
|
||||
CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context,
|
||||
_context.getServiceContent().getCustomFieldsManager());
|
||||
int key = cfmMo.getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_UUID);
|
||||
assert(key != 0);
|
||||
|
||||
|
||||
List<VirtualMachineMO> list = new ArrayList<VirtualMachineMO>();
|
||||
|
||||
ObjectContent[] ocs = getVmPropertiesOnDatacenterVmFolder(new String[] { "name", String.format("value[%d]", key)});
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
|
||||
List<ObjectContent> ocs = getVmPropertiesOnDatacenterVmFolder(new String[] { "name", String.format("value[%d]", key)});
|
||||
if(ocs != null && ocs.size() > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
DynamicProperty[] props = oc.getPropSet();
|
||||
List<DynamicProperty> props = oc.getPropSet();
|
||||
if(props != null) {
|
||||
for(DynamicProperty prop : props) {
|
||||
if(prop.getVal() != null) {
|
||||
|
|
@ -135,209 +133,217 @@ public class DatacenterMO extends BaseMO {
|
|||
|
||||
public List<Pair<ManagedObjectReference, String>> getAllVmsOnDatacenter() throws Exception {
|
||||
List<Pair<ManagedObjectReference, String>> vms = new ArrayList<Pair<ManagedObjectReference, String>>();
|
||||
|
||||
ObjectContent[] ocs = getVmPropertiesOnDatacenterVmFolder(new String[] { "name" });
|
||||
|
||||
List<ObjectContent> ocs = getVmPropertiesOnDatacenterVmFolder(new String[] { "name" });
|
||||
if(ocs != null) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
String vmName = oc.getPropSet(0).getVal().toString();
|
||||
String vmName = oc.getPropSet().get(0).getVal().toString();
|
||||
vms.add(new Pair<ManagedObjectReference, String>(oc.getObj(), vmName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return vms;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ManagedObjectReference findDatastore(String name) throws Exception {
|
||||
assert(name != null);
|
||||
|
||||
ObjectContent[] ocs = getDatastorePropertiesOnDatacenter(new String[] { "name" });
|
||||
|
||||
List<ObjectContent> ocs = getDatastorePropertiesOnDatacenter(new String[] { "name" });
|
||||
if(ocs != null) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
if(oc.getPropSet(0).getVal().toString().equals(name)) {
|
||||
if(oc.getPropSet().get(0).getVal().toString().equals(name)) {
|
||||
return oc.getObj();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public ManagedObjectReference findHost(String name) throws Exception {
|
||||
ObjectContent[] ocs= getHostPropertiesOnDatacenterHostFolder(new String[] { "name" });
|
||||
|
||||
List<ObjectContent> ocs= getHostPropertiesOnDatacenterHostFolder(new String[] { "name" });
|
||||
|
||||
if(ocs != null) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
if(oc.getPropSet(0).getVal().toString().equals(name)) {
|
||||
if(oc.getPropSet().get(0).getVal().toString().equals(name)) {
|
||||
return oc.getObj();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public ManagedObjectReference getVmFolder() throws Exception {
|
||||
return (ManagedObjectReference)_context.getServiceUtil().getDynamicProperty(_mor, "vmFolder");
|
||||
return (ManagedObjectReference)_context.getVimClient().getDynamicProperty(_mor, "vmFolder");
|
||||
}
|
||||
|
||||
public ObjectContent[] getHostPropertiesOnDatacenterHostFolder(String[] propertyPaths) throws Exception {
|
||||
|
||||
public List<ObjectContent> getHostPropertiesOnDatacenterHostFolder(String[] propertyPaths) throws Exception {
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec.setType("HostSystem");
|
||||
pSpec.setPathSet(propertyPaths);
|
||||
|
||||
pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
|
||||
|
||||
TraversalSpec computeResource2HostTraversal = new TraversalSpec();
|
||||
computeResource2HostTraversal.setType("ComputeResource");
|
||||
computeResource2HostTraversal.setPath("host");
|
||||
computeResource2HostTraversal.setName("computeResource2HostTraversal");
|
||||
|
||||
|
||||
SelectionSpec recurseFolders = new SelectionSpec();
|
||||
recurseFolders.setName("folder2childEntity");
|
||||
|
||||
|
||||
TraversalSpec folder2childEntity = new TraversalSpec();
|
||||
folder2childEntity.setType("Folder");
|
||||
folder2childEntity.setPath("childEntity");
|
||||
folder2childEntity.setName(recurseFolders.getName());
|
||||
folder2childEntity.setSelectSet(new SelectionSpec[] { recurseFolders, computeResource2HostTraversal });
|
||||
|
||||
folder2childEntity.getSelectSet().add(recurseFolders);
|
||||
folder2childEntity.getSelectSet().add(computeResource2HostTraversal);
|
||||
|
||||
TraversalSpec dc2HostFolderTraversal = new TraversalSpec();
|
||||
dc2HostFolderTraversal.setType("Datacenter");
|
||||
dc2HostFolderTraversal.setPath("hostFolder");
|
||||
dc2HostFolderTraversal.setName("dc2HostFolderTraversal");
|
||||
dc2HostFolderTraversal.setSelectSet(new SelectionSpec[] { folder2childEntity } );
|
||||
|
||||
dc2HostFolderTraversal.getSelectSet().add(folder2childEntity);
|
||||
|
||||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec.setObj(_mor);
|
||||
oSpec.setSkip(Boolean.TRUE);
|
||||
oSpec.setSelectSet(new SelectionSpec[] { dc2HostFolderTraversal });
|
||||
oSpec.getSelectSet().add(dc2HostFolderTraversal);
|
||||
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||
|
||||
return _context.getService().retrieveProperties(
|
||||
_context.getServiceContent().getPropertyCollector(),
|
||||
new PropertyFilterSpec[] { pfSpec });
|
||||
pfSpec.getPropSet().add(pSpec);
|
||||
pfSpec.getObjectSet().add(oSpec);
|
||||
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
|
||||
pfSpecArr.add(pfSpec);
|
||||
|
||||
return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
|
||||
|
||||
}
|
||||
|
||||
public ObjectContent[] getDatastorePropertiesOnDatacenter(String[] propertyPaths) throws Exception {
|
||||
|
||||
|
||||
public List<ObjectContent> getDatastorePropertiesOnDatacenter(String[] propertyPaths) throws Exception {
|
||||
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec.setType("Datastore");
|
||||
pSpec.setPathSet(propertyPaths);
|
||||
|
||||
pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
|
||||
|
||||
TraversalSpec dc2DatastoreTraversal = new TraversalSpec();
|
||||
dc2DatastoreTraversal.setType("Datacenter");
|
||||
dc2DatastoreTraversal.setPath("datastore");
|
||||
dc2DatastoreTraversal.setName("dc2DatastoreTraversal");
|
||||
|
||||
|
||||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec.setObj(_mor);
|
||||
oSpec.setSkip(Boolean.TRUE);
|
||||
oSpec.setSelectSet(new SelectionSpec[] { dc2DatastoreTraversal });
|
||||
oSpec.getSelectSet().add(dc2DatastoreTraversal);
|
||||
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||
|
||||
return _context.getService().retrieveProperties(
|
||||
_context.getServiceContent().getPropertyCollector(),
|
||||
new PropertyFilterSpec[] { pfSpec });
|
||||
pfSpec.getPropSet().add(pSpec);
|
||||
pfSpec.getObjectSet().add(oSpec);
|
||||
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
|
||||
pfSpecArr.add(pfSpec);
|
||||
|
||||
return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
|
||||
|
||||
}
|
||||
|
||||
public ObjectContent[] getVmPropertiesOnDatacenterVmFolder(String[] propertyPaths) throws Exception {
|
||||
|
||||
public List<ObjectContent> getVmPropertiesOnDatacenterVmFolder(String[] propertyPaths) throws Exception {
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec.setType("VirtualMachine");
|
||||
pSpec.setPathSet(propertyPaths);
|
||||
|
||||
pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
|
||||
|
||||
TraversalSpec dc2VmFolderTraversal = new TraversalSpec();
|
||||
dc2VmFolderTraversal.setType("Datacenter");
|
||||
dc2VmFolderTraversal.setPath("vmFolder");
|
||||
dc2VmFolderTraversal.setName("dc2VmFolderTraversal");
|
||||
|
||||
|
||||
|
||||
SelectionSpec recurseFolders = new SelectionSpec();
|
||||
recurseFolders.setName("folder2childEntity");
|
||||
|
||||
|
||||
TraversalSpec folder2childEntity = new TraversalSpec();
|
||||
folder2childEntity.setType("Folder");
|
||||
folder2childEntity.setPath("childEntity");
|
||||
folder2childEntity.setName(recurseFolders.getName());
|
||||
folder2childEntity.setSelectSet(new SelectionSpec[] { recurseFolders });
|
||||
dc2VmFolderTraversal.setSelectSet(new SelectionSpec[] { folder2childEntity } );
|
||||
folder2childEntity.getSelectSet().add(recurseFolders);
|
||||
dc2VmFolderTraversal.getSelectSet().add(folder2childEntity);
|
||||
|
||||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec.setObj(_mor);
|
||||
oSpec.setSkip(Boolean.TRUE);
|
||||
oSpec.setSelectSet(new SelectionSpec[] { dc2VmFolderTraversal });
|
||||
oSpec.getSelectSet().add(dc2VmFolderTraversal);
|
||||
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||
|
||||
return _context.getService().retrieveProperties(
|
||||
_context.getServiceContent().getPropertyCollector(),
|
||||
new PropertyFilterSpec[] { pfSpec });
|
||||
pfSpec.getPropSet().add(pSpec);
|
||||
pfSpec.getObjectSet().add(oSpec);
|
||||
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
|
||||
pfSpecArr.add(pfSpec);
|
||||
|
||||
return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
|
||||
}
|
||||
|
||||
public static Pair<DatacenterMO, String> getOwnerDatacenter(VmwareContext context,
|
||||
|
||||
public static Pair<DatacenterMO, String> getOwnerDatacenter(VmwareContext context,
|
||||
ManagedObjectReference morEntity) throws Exception {
|
||||
|
||||
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec.setType("Datacenter");
|
||||
pSpec.setPathSet(new String[] { "name" });
|
||||
|
||||
pSpec.getPathSet().add("name");
|
||||
|
||||
TraversalSpec entityParentTraversal = new TraversalSpec();
|
||||
entityParentTraversal.setType("ManagedEntity");
|
||||
entityParentTraversal.setPath("parent");
|
||||
entityParentTraversal.setName("entityParentTraversal");
|
||||
entityParentTraversal.setSelectSet(new SelectionSpec[] { new SelectionSpec(null, null, "entityParentTraversal") });
|
||||
SelectionSpec selSpec = new SelectionSpec();
|
||||
selSpec.setName("entityParentTraversal");
|
||||
entityParentTraversal.getSelectSet().add(selSpec);
|
||||
|
||||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec.setObj(morEntity);
|
||||
oSpec.setSkip(Boolean.TRUE);
|
||||
oSpec.setSelectSet(new SelectionSpec[] { entityParentTraversal });
|
||||
oSpec.getSelectSet().add(entityParentTraversal);
|
||||
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||
|
||||
ObjectContent[] ocs = context.getService().retrieveProperties(
|
||||
context.getServiceContent().getPropertyCollector(),
|
||||
new PropertyFilterSpec[] { pfSpec });
|
||||
|
||||
assert(ocs != null);
|
||||
assert(ocs[0].getObj() != null);
|
||||
assert(ocs[0].getPropSet(0) != null);
|
||||
assert(ocs[0].getPropSet(0).getVal() != null);
|
||||
|
||||
String dcName = ocs[0].getPropSet(0).getVal().toString();
|
||||
return new Pair<DatacenterMO, String>(new DatacenterMO(context, ocs[0].getObj()), dcName);
|
||||
pfSpec.getPropSet().add(pSpec);
|
||||
pfSpec.getObjectSet().add(oSpec);
|
||||
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
|
||||
pfSpecArr.add(pfSpec);
|
||||
|
||||
List<ObjectContent> ocs = context.getService().retrieveProperties(
|
||||
context.getPropertyCollector(), pfSpecArr);
|
||||
|
||||
assert(ocs != null && ocs.size() > 0);
|
||||
assert(ocs.get(0).getObj() != null);
|
||||
assert(ocs.get(0).getPropSet().get(0) != null);
|
||||
assert(ocs.get(0).getPropSet().get(0).getVal() != null);
|
||||
|
||||
String dcName = ocs.get(0).getPropSet().get(0).getVal().toString();
|
||||
return new Pair<DatacenterMO, String>(new DatacenterMO(context, ocs.get(0).getObj()), dcName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ManagedObjectReference getDvPortGroupMor(String dvPortGroupName) throws Exception {
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec.setType("DistributedVirtualPortgroup");
|
||||
pSpec.setPathSet(new String[] {"name"});
|
||||
|
||||
pSpec.getPathSet().add("name");
|
||||
|
||||
TraversalSpec datacenter2DvPortGroupTraversal = new TraversalSpec();
|
||||
datacenter2DvPortGroupTraversal.setType("Datacenter");
|
||||
datacenter2DvPortGroupTraversal.setPath("network");
|
||||
datacenter2DvPortGroupTraversal.setName("datacenter2DvPortgroupTraversal");
|
||||
|
||||
|
||||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec.setObj(_mor);
|
||||
oSpec.setSkip(Boolean.TRUE);
|
||||
oSpec.setSelectSet(new SelectionSpec[] { datacenter2DvPortGroupTraversal });
|
||||
oSpec.getSelectSet().add(datacenter2DvPortGroupTraversal);
|
||||
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||
|
||||
ObjectContent[] ocs = _context.getService().retrieveProperties(
|
||||
_context.getServiceContent().getPropertyCollector(),
|
||||
new PropertyFilterSpec[] { pfSpec });
|
||||
|
||||
pfSpec.getPropSet().add(pSpec);
|
||||
pfSpec.getObjectSet().add(oSpec);
|
||||
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
|
||||
pfSpecArr.add(pfSpec);
|
||||
|
||||
List<ObjectContent> ocs = _context.getService().retrieveProperties(
|
||||
_context.getPropertyCollector(), pfSpecArr);
|
||||
|
||||
if(ocs != null) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
DynamicProperty[] props = oc.getPropSet();
|
||||
List<DynamicProperty> props = oc.getPropSet();
|
||||
if(props != null) {
|
||||
for(DynamicProperty prop : props) {
|
||||
if(prop.getVal().equals(dvPortGroupName))
|
||||
|
|
@ -347,22 +353,23 @@ public class DatacenterMO extends BaseMO {
|
|||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasDvPortGroup(String dvPortGroupName) throws Exception {
|
||||
ManagedObjectReference morNetwork = getDvPortGroupMor(dvPortGroupName);
|
||||
if(morNetwork != null)
|
||||
return true;
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public DVPortgroupConfigInfo getDvPortGroupSpec(String dvPortGroupName) throws Exception {
|
||||
DVPortgroupConfigInfo configSpec = null;
|
||||
String nameProperty = null;
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec.setType("DistributedVirtualPortgroup");
|
||||
pSpec.setPathSet(new String[] {"name", "config"});
|
||||
|
||||
pSpec.getPathSet().add("name");
|
||||
pSpec.getPathSet().add("config");
|
||||
|
||||
TraversalSpec datacenter2DvPortGroupTraversal = new TraversalSpec();
|
||||
datacenter2DvPortGroupTraversal.setType("Datacenter");
|
||||
datacenter2DvPortGroupTraversal.setPath("network");
|
||||
|
|
@ -371,21 +378,22 @@ public class DatacenterMO extends BaseMO {
|
|||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec.setObj(_mor);
|
||||
oSpec.setSkip(Boolean.TRUE);
|
||||
oSpec.setSelectSet(new SelectionSpec[] { datacenter2DvPortGroupTraversal });
|
||||
oSpec.getSelectSet().add(datacenter2DvPortGroupTraversal);
|
||||
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||
|
||||
ObjectContent[] ocs = _context.getService().retrieveProperties(
|
||||
_context.getServiceContent().getPropertyCollector(),
|
||||
new PropertyFilterSpec[] { pfSpec });
|
||||
|
||||
pfSpec.getPropSet().add(pSpec);
|
||||
pfSpec.getObjectSet().add(oSpec);
|
||||
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
|
||||
pfSpecArr.add(pfSpec);
|
||||
|
||||
List<ObjectContent> ocs = _context.getService().retrieveProperties(
|
||||
_context.getPropertyCollector(), pfSpecArr);
|
||||
|
||||
if(ocs != null) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
DynamicProperty[] props = oc.getPropSet();
|
||||
List<DynamicProperty> props = oc.getPropSet();
|
||||
if(props != null) {
|
||||
assert(props.length == 2);
|
||||
assert(props.size() == 2);
|
||||
for(DynamicProperty prop : props) {
|
||||
if(prop.getName().equals("config")) {
|
||||
configSpec = (DVPortgroupConfigInfo) prop.getVal();
|
||||
|
|
@ -395,7 +403,7 @@ public class DatacenterMO extends BaseMO {
|
|||
}
|
||||
}
|
||||
if(nameProperty.equalsIgnoreCase(dvPortGroupName)) {
|
||||
return configSpec;
|
||||
return configSpec;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -408,7 +416,8 @@ public class DatacenterMO extends BaseMO {
|
|||
ManagedObjectReference dvSwitchMor = null;
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec.setType("DistributedVirtualPortgroup");
|
||||
pSpec.setPathSet(new String[] { "key", "config.distributedVirtualSwitch" });
|
||||
pSpec.getPathSet().add("key");
|
||||
pSpec.getPathSet().add("config.distributedVirtualSwitch");
|
||||
|
||||
TraversalSpec datacenter2DvPortGroupTraversal = new TraversalSpec();
|
||||
datacenter2DvPortGroupTraversal.setType("Datacenter");
|
||||
|
|
@ -418,21 +427,22 @@ public class DatacenterMO extends BaseMO {
|
|||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec.setObj(_mor);
|
||||
oSpec.setSkip(Boolean.TRUE);
|
||||
oSpec.setSelectSet(new SelectionSpec[] { datacenter2DvPortGroupTraversal });
|
||||
oSpec.getSelectSet().add(datacenter2DvPortGroupTraversal);
|
||||
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||
pfSpec.getPropSet().add(pSpec);
|
||||
pfSpec.getObjectSet().add(oSpec);
|
||||
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
|
||||
pfSpecArr.add(pfSpec);
|
||||
|
||||
ObjectContent[] ocs = _context.getService().retrieveProperties(
|
||||
_context.getServiceContent().getPropertyCollector(),
|
||||
new PropertyFilterSpec[] { pfSpec });
|
||||
List<ObjectContent> ocs = _context.getService().retrieveProperties(
|
||||
_context.getPropertyCollector(), pfSpecArr);
|
||||
|
||||
if (ocs != null) {
|
||||
for (ObjectContent oc : ocs) {
|
||||
DynamicProperty[] props = oc.getPropSet();
|
||||
List<DynamicProperty> props = oc.getPropSet();
|
||||
if (props != null) {
|
||||
assert (props.length == 2);
|
||||
assert (props.size() == 2);
|
||||
for (DynamicProperty prop : props) {
|
||||
if (prop.getName().equals("key")) {
|
||||
dvPortGroupKey = (String) prop.getVal();
|
||||
|
|
@ -441,7 +451,7 @@ public class DatacenterMO extends BaseMO {
|
|||
dvSwitchMor = (ManagedObjectReference) prop.getVal();
|
||||
}
|
||||
}
|
||||
if ((dvPortGroupKey != null) && dvPortGroupKey.equals(dvPortGroupMor.get_value())) {
|
||||
if ((dvPortGroupKey != null) && dvPortGroupKey.equals(dvPortGroupMor.getValue())) {
|
||||
return dvSwitchMor;
|
||||
}
|
||||
}
|
||||
|
|
@ -452,7 +462,7 @@ public class DatacenterMO extends BaseMO {
|
|||
|
||||
public String getDvSwitchUuid(ManagedObjectReference dvSwitchMor) throws Exception {
|
||||
assert (dvSwitchMor != null);
|
||||
return (String) _context.getServiceUtil().getDynamicProperty(dvSwitchMor, "uuid");
|
||||
return (String) _context.getVimClient().getDynamicProperty(dvSwitchMor, "uuid");
|
||||
}
|
||||
|
||||
public VirtualEthernetCardDistributedVirtualPortBackingInfo getDvPortBackingInfo(Pair<ManagedObjectReference, String> networkInfo)
|
||||
|
|
@ -464,7 +474,7 @@ public class DatacenterMO extends BaseMO {
|
|||
ManagedObjectReference dvsMor = getDvSwitchMor(networkInfo.first());
|
||||
String dvSwitchUuid = getDvSwitchUuid(dvsMor);
|
||||
dvPortConnection.setSwitchUuid(dvSwitchUuid);
|
||||
dvPortConnection.setPortgroupKey(networkInfo.first().get_value());
|
||||
dvPortConnection.setPortgroupKey(networkInfo.first().getValue());
|
||||
dvPortBacking.setPort(dvPortConnection);
|
||||
System.out.println("Plugging NIC device into network " + networkInfo.second() + " backed by dvSwitch: "
|
||||
+ dvSwitchUuid);
|
||||
|
|
@ -474,8 +484,8 @@ public class DatacenterMO extends BaseMO {
|
|||
public ManagedObjectReference getDvSwitchMor(String dvSwitchName) throws Exception {
|
||||
ManagedObjectReference dvSwitchMor = null;
|
||||
ManagedObjectReference networkFolderMor = null;
|
||||
networkFolderMor = _context.getServiceUtil().getMoRefProp(_mor, "networkFolder");
|
||||
dvSwitchMor = _context.getServiceUtil().getDecendentMoRef(networkFolderMor, "VmwareDistributedVirtualSwitch", dvSwitchName);
|
||||
networkFolderMor = _context.getVimClient().getMoRefProp(_mor, "networkFolder");
|
||||
dvSwitchMor = _context.getVimClient().getDecendentMoRef(networkFolderMor, "VmwareDistributedVirtualSwitch", dvSwitchName);
|
||||
return dvSwitchMor;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,95 +36,98 @@ import com.vmware.vim25.TraversalSpec;
|
|||
|
||||
public class DatastoreMO extends BaseMO {
|
||||
private static final Logger s_logger = Logger.getLogger(DatastoreMO.class);
|
||||
|
||||
private String _name;
|
||||
private Pair<DatacenterMO, String> _ownerDc;
|
||||
|
||||
|
||||
private String _name;
|
||||
private Pair<DatacenterMO, String> _ownerDc;
|
||||
|
||||
public DatastoreMO(VmwareContext context, ManagedObjectReference morDatastore) {
|
||||
super(context, morDatastore);
|
||||
}
|
||||
|
||||
|
||||
public DatastoreMO(VmwareContext context, String morType, String morValue) {
|
||||
super(context, morType, morValue);
|
||||
}
|
||||
|
||||
public String getName() throws Exception {
|
||||
if(_name == null)
|
||||
_name = (String)_context.getServiceUtil().getDynamicProperty(_mor, "name");
|
||||
|
||||
if(_name == null)
|
||||
_name = (String)_context.getVimClient().getDynamicProperty(_mor, "name");
|
||||
|
||||
return _name;
|
||||
}
|
||||
|
||||
|
||||
public DatastoreSummary getSummary() throws Exception {
|
||||
return (DatastoreSummary)_context.getServiceUtil().getDynamicProperty(_mor, "summary");
|
||||
return (DatastoreSummary)_context.getVimClient().getDynamicProperty(_mor, "summary");
|
||||
}
|
||||
|
||||
|
||||
public HostDatastoreBrowserMO getHostDatastoreBrowserMO() throws Exception {
|
||||
return new HostDatastoreBrowserMO(_context,
|
||||
(ManagedObjectReference)_context.getServiceUtil().getDynamicProperty(_mor, "browser"));
|
||||
return new HostDatastoreBrowserMO(_context,
|
||||
(ManagedObjectReference)_context.getVimClient().getDynamicProperty(_mor, "browser"));
|
||||
}
|
||||
|
||||
|
||||
public String getInventoryPath() throws Exception {
|
||||
Pair<DatacenterMO, String> dcInfo = getOwnerDatacenter();
|
||||
return dcInfo.second() + "/" + getName();
|
||||
}
|
||||
|
||||
|
||||
public Pair<DatacenterMO, String> getOwnerDatacenter() throws Exception {
|
||||
if(_ownerDc != null)
|
||||
return _ownerDc;
|
||||
|
||||
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec.setType("Datacenter");
|
||||
pSpec.setPathSet(new String[] { "name" });
|
||||
|
||||
pSpec.getPathSet().add("name");
|
||||
|
||||
TraversalSpec folderParentTraversal = new TraversalSpec();
|
||||
folderParentTraversal.setType("Folder");
|
||||
folderParentTraversal.setPath("parent");
|
||||
folderParentTraversal.setName("folderParentTraversal");
|
||||
folderParentTraversal.setSelectSet(new SelectionSpec[] { new SelectionSpec(null, null, "folderParentTraversal") });
|
||||
|
||||
SelectionSpec sSpec = new SelectionSpec();
|
||||
sSpec.setName("folderParentTraversal");
|
||||
folderParentTraversal.getSelectSet().add(sSpec);
|
||||
|
||||
TraversalSpec dsParentTraversal = new TraversalSpec();
|
||||
dsParentTraversal.setType("Datastore");
|
||||
dsParentTraversal.setPath("parent");
|
||||
dsParentTraversal.setName("dsParentTraversal");
|
||||
dsParentTraversal.setSelectSet(new SelectionSpec[] { folderParentTraversal });
|
||||
dsParentTraversal.getSelectSet().add(folderParentTraversal);
|
||||
|
||||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec.setObj(getMor());
|
||||
oSpec.setSkip(Boolean.TRUE);
|
||||
oSpec.setSelectSet(new SelectionSpec[] { dsParentTraversal });
|
||||
oSpec.getSelectSet().add(dsParentTraversal);
|
||||
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||
|
||||
ObjectContent[] ocs = _context.getService().retrieveProperties(
|
||||
_context.getServiceContent().getPropertyCollector(),
|
||||
new PropertyFilterSpec[] { pfSpec });
|
||||
|
||||
assert(ocs != null);
|
||||
assert(ocs[0].getObj() != null);
|
||||
assert(ocs[0].getPropSet() != null);
|
||||
String dcName = ocs[0].getPropSet()[0].getVal().toString();
|
||||
_ownerDc = new Pair<DatacenterMO, String>(new DatacenterMO(_context, ocs[0].getObj()), dcName);
|
||||
pfSpec.getPropSet().add(pSpec);
|
||||
pfSpec.getObjectSet().add(oSpec);
|
||||
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
|
||||
pfSpecArr.add(pfSpec);
|
||||
|
||||
List<ObjectContent> ocs = _context.getService().retrieveProperties(
|
||||
_context.getPropertyCollector(), pfSpecArr);
|
||||
|
||||
assert(ocs != null && ocs.size() > 0);
|
||||
assert(ocs.get(0).getObj() != null);
|
||||
assert(ocs.get(0).getPropSet() != null);
|
||||
String dcName = ocs.get(0).getPropSet().get(0).getVal().toString();
|
||||
_ownerDc = new Pair<DatacenterMO, String>(new DatacenterMO(_context, ocs.get(0).getObj()), dcName);
|
||||
return _ownerDc;
|
||||
}
|
||||
|
||||
|
||||
public void makeDirectory(String path, ManagedObjectReference morDc) throws Exception {
|
||||
String datastoreName = getName();
|
||||
ManagedObjectReference morFileManager = _context.getServiceContent().getFileManager();
|
||||
|
||||
|
||||
String fullPath = path;
|
||||
if(!DatastoreFile.isFullDatastorePath(fullPath))
|
||||
if(!DatastoreFile.isFullDatastorePath(fullPath))
|
||||
fullPath = String.format("[%s] %s", datastoreName, path);
|
||||
|
||||
|
||||
_context.getService().makeDirectory(morFileManager, fullPath, morDc, true);
|
||||
}
|
||||
|
||||
|
||||
public boolean deleteFile(String path, ManagedObjectReference morDc, boolean testExistence) throws Exception {
|
||||
String datastoreName = getName();
|
||||
ManagedObjectReference morFileManager = _context.getServiceContent().getFileManager();
|
||||
|
||||
|
||||
String fullPath = path;
|
||||
if(!DatastoreFile.isFullDatastorePath(fullPath))
|
||||
fullPath = String.format("[%s] %s", datastoreName, path);
|
||||
|
|
@ -136,12 +139,11 @@ public class DatastoreMO extends BaseMO {
|
|||
s_logger.info("Unable to test file existence due to exception " + e.getClass().getName() + ", skip deleting of it");
|
||||
return true;
|
||||
}
|
||||
|
||||
ManagedObjectReference morTask = _context.getService().deleteDatastoreFile_Task(morFileManager,
|
||||
fullPath, morDc);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(result.equals("sucess")) {
|
||||
|
||||
ManagedObjectReference morTask = _context.getService().deleteDatastoreFileTask(morFileManager, fullPath, morDc);
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(result) {
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
return true;
|
||||
} else {
|
||||
|
|
@ -149,29 +151,29 @@ public class DatastoreMO extends BaseMO {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean copyDatastoreFile(String srcFilePath, ManagedObjectReference morSrcDc,
|
||||
ManagedObjectReference morDestDs, String destFilePath, ManagedObjectReference morDestDc,
|
||||
ManagedObjectReference morDestDs, String destFilePath, ManagedObjectReference morDestDc,
|
||||
boolean forceOverwrite) throws Exception {
|
||||
|
||||
|
||||
String srcDsName = getName();
|
||||
DatastoreMO destDsMo = new DatastoreMO(_context, morDestDs);
|
||||
String destDsName = destDsMo.getName();
|
||||
|
||||
|
||||
ManagedObjectReference morFileManager = _context.getServiceContent().getFileManager();
|
||||
String srcFullPath = srcFilePath;
|
||||
if(!DatastoreFile.isFullDatastorePath(srcFullPath))
|
||||
srcFullPath = String.format("[%s] %s", srcDsName, srcFilePath);
|
||||
|
||||
|
||||
String destFullPath = destFilePath;
|
||||
if(!DatastoreFile.isFullDatastorePath(destFullPath))
|
||||
destFullPath = String.format("[%s] %s", destDsName, destFilePath);
|
||||
|
||||
ManagedObjectReference morTask = _context.getService().copyDatastoreFile_Task(morFileManager,
|
||||
|
||||
ManagedObjectReference morTask = _context.getService().copyDatastoreFileTask(morFileManager,
|
||||
srcFullPath, morSrcDc, destFullPath, morDestDc, forceOverwrite);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(result.equals("sucess")) {
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(result) {
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
return true;
|
||||
} else {
|
||||
|
|
@ -179,29 +181,29 @@ public class DatastoreMO extends BaseMO {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean moveDatastoreFile(String srcFilePath, ManagedObjectReference morSrcDc,
|
||||
ManagedObjectReference morDestDs, String destFilePath, ManagedObjectReference morDestDc,
|
||||
ManagedObjectReference morDestDs, String destFilePath, ManagedObjectReference morDestDc,
|
||||
boolean forceOverwrite) throws Exception {
|
||||
|
||||
|
||||
String srcDsName = getName();
|
||||
DatastoreMO destDsMo = new DatastoreMO(_context, morDestDs);
|
||||
String destDsName = destDsMo.getName();
|
||||
|
||||
|
||||
ManagedObjectReference morFileManager = _context.getServiceContent().getFileManager();
|
||||
String srcFullPath = srcFilePath;
|
||||
if(!DatastoreFile.isFullDatastorePath(srcFullPath))
|
||||
srcFullPath = String.format("[%s] %s", srcDsName, srcFilePath);
|
||||
|
||||
|
||||
String destFullPath = destFilePath;
|
||||
if(!DatastoreFile.isFullDatastorePath(destFullPath))
|
||||
destFullPath = String.format("[%s] %s", destDsName, destFilePath);
|
||||
|
||||
ManagedObjectReference morTask = _context.getService().moveDatastoreFile_Task(morFileManager,
|
||||
|
||||
ManagedObjectReference morTask = _context.getService().moveDatastoreFileTask(morFileManager,
|
||||
srcFullPath, morSrcDc, destFullPath, morDestDc, forceOverwrite);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(result.equals("sucess")) {
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(result) {
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
return true;
|
||||
} else {
|
||||
|
|
@ -209,23 +211,23 @@ public class DatastoreMO extends BaseMO {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public String[] getVmdkFileChain(String rootVmdkDatastoreFullPath) throws Exception {
|
||||
Pair<DatacenterMO, String> dcPair = getOwnerDatacenter();
|
||||
|
||||
|
||||
List<String> files = new ArrayList<String>();
|
||||
files.add(rootVmdkDatastoreFullPath);
|
||||
|
||||
|
||||
String currentVmdkFullPath = rootVmdkDatastoreFullPath;
|
||||
while(true) {
|
||||
String url = getContext().composeDatastoreBrowseUrl(dcPair.second(), currentVmdkFullPath);
|
||||
byte[] content = getContext().getResourceContent(url);
|
||||
if(content == null || content.length == 0)
|
||||
break;
|
||||
|
||||
|
||||
VmdkFileDescriptor descriptor = new VmdkFileDescriptor();
|
||||
descriptor.parse(content);
|
||||
|
||||
|
||||
String parentFileName = descriptor.getParentFileName();
|
||||
if(parentFileName == null)
|
||||
break;
|
||||
|
|
@ -239,8 +241,8 @@ public class DatastoreMO extends BaseMO {
|
|||
dir = dir.substring(0, dir.lastIndexOf('/'));
|
||||
else
|
||||
dir = "";
|
||||
|
||||
currentVmdkFullPath = new DatastoreFile(dsFile.getDatastoreName(), dir,
|
||||
|
||||
currentVmdkFullPath = new DatastoreFile(dsFile.getDatastoreName(), dir,
|
||||
parentFileName.substring(parentFileName.lastIndexOf('/') + 1)).getPath();
|
||||
files.add(currentVmdkFullPath);
|
||||
} else {
|
||||
|
|
@ -248,7 +250,7 @@ public class DatastoreMO extends BaseMO {
|
|||
files.add(currentVmdkFullPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return files.toArray(new String[0]);
|
||||
}
|
||||
|
||||
|
|
@ -257,59 +259,59 @@ public class DatastoreMO extends BaseMO {
|
|||
String fullPath = path;
|
||||
if(!DatastoreFile.isFullDatastorePath(fullPath))
|
||||
fullPath = String.format("[%s] %s", getName(), fullPath);
|
||||
|
||||
|
||||
Pair<DatacenterMO, String> dcPair = getOwnerDatacenter();
|
||||
String url = getContext().composeDatastoreBrowseUrl(dcPair.second(), fullPath);
|
||||
|
||||
|
||||
// TODO, VMware currently does not have a formal API to list Datastore directory content,
|
||||
// folloing hacking may have performance hit if datastore has a large number of files
|
||||
return _context.listDatastoreDirContent(url);
|
||||
}
|
||||
|
||||
|
||||
public boolean fileExists(String fileFullPath) throws Exception {
|
||||
DatastoreFile file = new DatastoreFile(fileFullPath);
|
||||
DatastoreFile dirFile = new DatastoreFile(file.getDatastoreName(), file.getDir());
|
||||
|
||||
|
||||
HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
|
||||
|
||||
|
||||
s_logger.info("Search file " + file.getFileName() + " on " + dirFile.getPath());
|
||||
HostDatastoreBrowserSearchResults results = browserMo.searchDatastore(dirFile.getPath(), file.getFileName(), true);
|
||||
if(results != null) {
|
||||
FileInfo[] info = results.getFile();
|
||||
if(info != null && info.length > 0) {
|
||||
List<FileInfo> info = results.getFile();
|
||||
if(info != null && info.size() > 0) {
|
||||
s_logger.info("File " + fileFullPath + " exists on datastore");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
s_logger.info("File " + fileFullPath + " does not exist on datastore");
|
||||
return false;
|
||||
|
||||
/*
|
||||
/*
|
||||
String[] fileNames = listDirContent(dirFile.getPath());
|
||||
|
||||
|
||||
String fileName = file.getFileName();
|
||||
for(String name : fileNames) {
|
||||
if(name.equalsIgnoreCase(fileName))
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
public boolean folderExists(String folderParentDatastorePath, String folderName) throws Exception {
|
||||
HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
|
||||
|
||||
|
||||
HostDatastoreBrowserSearchResults results = browserMo.searchDatastore(folderParentDatastorePath, folderName, true);
|
||||
if(results != null) {
|
||||
FileInfo[] info = results.getFile();
|
||||
if(info != null && info.length > 0) {
|
||||
List<FileInfo> info = results.getFile();
|
||||
if(info != null && info.size() > 0) {
|
||||
s_logger.info("Folder " + folderName + " exists on datastore");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
s_logger.info("Folder " + folderName + " does not exist on datastore");
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,13 @@
|
|||
// under the License.
|
||||
package com.cloud.hypervisor.vmware.mo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.vmware.vim25.DVPortgroupConfigSpec;
|
||||
import com.vmware.vim25.HostPortGroupSpec;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
|
||||
public class DistributedVirtualSwitchMO extends BaseMO {
|
||||
|
|
@ -35,13 +37,13 @@ public class DistributedVirtualSwitchMO extends BaseMO {
|
|||
}
|
||||
|
||||
public void createDVPortGroup(DVPortgroupConfigSpec dvPortGroupSpec) throws Exception {
|
||||
DVPortgroupConfigSpec[] dvPortGroupSpecArray = new DVPortgroupConfigSpec[1];
|
||||
dvPortGroupSpecArray[0] = dvPortGroupSpec;
|
||||
_context.getService().addDVPortgroup_Task(_mor, dvPortGroupSpecArray);
|
||||
List<DVPortgroupConfigSpec> dvPortGroupSpecArray = new ArrayList<DVPortgroupConfigSpec>();
|
||||
dvPortGroupSpecArray.add(dvPortGroupSpec);
|
||||
_context.getService().addDVPortgroupTask(_mor, dvPortGroupSpecArray);
|
||||
}
|
||||
|
||||
public void updateDvPortGroup(ManagedObjectReference dvPortGroupMor, DVPortgroupConfigSpec dvPortGroupSpec) throws Exception {
|
||||
// TODO(sateesh): Update numPorts
|
||||
_context.getService().reconfigureDVPortgroup_Task(dvPortGroupMor, dvPortGroupSpec);
|
||||
_context.getService().reconfigureDVPortgroupTask(dvPortGroupMor, dvPortGroupSpec);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,39 +24,39 @@ import com.vmware.vim25.HostDatastoreBrowserSearchSpec;
|
|||
import com.vmware.vim25.ManagedObjectReference;
|
||||
|
||||
public class HostDatastoreBrowserMO extends BaseMO {
|
||||
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(HostDatastoreBrowserMO.class);
|
||||
|
||||
|
||||
public HostDatastoreBrowserMO(VmwareContext context, ManagedObjectReference morHostDatastoreBrowser) {
|
||||
super(context, morHostDatastoreBrowser);
|
||||
}
|
||||
|
||||
|
||||
public HostDatastoreBrowserMO(VmwareContext context, String morType, String morValue) {
|
||||
super(context, morType, morValue);
|
||||
}
|
||||
|
||||
|
||||
public void DeleteFile(String datastoreFullPath) throws Exception {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - deleteFile(). target mor: " + _mor.get_value() + ", file datastore path: " + datastoreFullPath);
|
||||
|
||||
s_logger.trace("vCenter API trace - deleteFile(). target mor: " + _mor.getValue() + ", file datastore path: " + datastoreFullPath);
|
||||
|
||||
_context.getService().deleteFile(_mor, datastoreFullPath);
|
||||
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - deleteFile() done");
|
||||
}
|
||||
|
||||
|
||||
public HostDatastoreBrowserSearchResults searchDatastore(String datastorePath, HostDatastoreBrowserSearchSpec searchSpec) throws Exception {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - searchDatastore(). target mor: " + _mor.get_value() + ", file datastore path: " + datastorePath);
|
||||
s_logger.trace("vCenter API trace - searchDatastore(). target mor: " + _mor.getValue() + ", file datastore path: " + datastorePath);
|
||||
|
||||
try {
|
||||
ManagedObjectReference morTask = _context.getService().searchDatastore_Task(_mor, datastorePath, searchSpec);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(result.equals("sucess")) {
|
||||
ManagedObjectReference morTask = _context.getService().searchDatastoreTask(_mor, datastorePath, searchSpec);
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(result) {
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
|
||||
return (HostDatastoreBrowserSearchResults)_context.getServiceUtil().getDynamicProperty(morTask, "info.result");
|
||||
|
||||
return (HostDatastoreBrowserSearchResults)_context.getVimClient().getDynamicProperty(morTask, "info.result");
|
||||
} else {
|
||||
s_logger.error("VMware searchDaastore_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
}
|
||||
|
|
@ -64,30 +64,30 @@ public class HostDatastoreBrowserMO extends BaseMO {
|
|||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - searchDatastore() done");
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public HostDatastoreBrowserSearchResults searchDatastore(String datastorePath, String fileName, boolean caseInsensitive) throws Exception {
|
||||
HostDatastoreBrowserSearchSpec spec = new HostDatastoreBrowserSearchSpec();
|
||||
spec.setSearchCaseInsensitive(caseInsensitive);
|
||||
spec.setMatchPattern(new String[] { fileName });
|
||||
spec.getMatchPattern().add(fileName);
|
||||
|
||||
return searchDatastore(datastorePath, spec);
|
||||
}
|
||||
|
||||
|
||||
public HostDatastoreBrowserSearchResults searchDatastoreSubFolders(String datastorePath, HostDatastoreBrowserSearchSpec searchSpec) throws Exception {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - searchDatastoreSubFolders(). target mor: " + _mor.get_value() + ", file datastore path: " + datastorePath);
|
||||
s_logger.trace("vCenter API trace - searchDatastoreSubFolders(). target mor: " + _mor.getValue() + ", file datastore path: " + datastorePath);
|
||||
|
||||
try {
|
||||
ManagedObjectReference morTask = _context.getService().searchDatastoreSubFolders_Task(_mor, datastorePath, searchSpec);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(result.equals("sucess")) {
|
||||
ManagedObjectReference morTask = _context.getService().searchDatastoreSubFoldersTask(_mor, datastorePath, searchSpec);
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(result) {
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
|
||||
return (HostDatastoreBrowserSearchResults)_context.getServiceUtil().getDynamicProperty(morTask, "info.result");
|
||||
|
||||
return (HostDatastoreBrowserSearchResults)_context.getVimClient().getDynamicProperty(morTask, "info.result");
|
||||
} else {
|
||||
s_logger.error("VMware searchDaastoreSubFolders_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
}
|
||||
|
|
@ -95,14 +95,14 @@ public class HostDatastoreBrowserMO extends BaseMO {
|
|||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - searchDatastore() done");
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public HostDatastoreBrowserSearchResults searchDatastoreSubFolders(String datastorePath, String folderName, boolean caseInsensitive) throws Exception {
|
||||
HostDatastoreBrowserSearchSpec spec = new HostDatastoreBrowserSearchSpec();
|
||||
spec.setSearchCaseInsensitive(caseInsensitive);
|
||||
spec.setMatchPattern(new String[] { folderName });
|
||||
spec.getMatchPattern().add(folderName);
|
||||
|
||||
return searchDatastore(datastorePath, spec);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@
|
|||
package com.cloud.hypervisor.vmware.mo;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.vmware.vim25.CustomFieldStringValue;
|
||||
|
|
@ -37,27 +40,27 @@ public class HostDatastoreSystemMO extends BaseMO {
|
|||
public HostDatastoreSystemMO(VmwareContext context, ManagedObjectReference morHostDatastore) {
|
||||
super(context, morHostDatastore);
|
||||
}
|
||||
|
||||
|
||||
public HostDatastoreSystemMO(VmwareContext context, String morType, String morValue) {
|
||||
super(context, morType, morValue);
|
||||
}
|
||||
|
||||
|
||||
public ManagedObjectReference findDatastore(String name) throws Exception {
|
||||
// added cloud.com specific name convention, we will use custom field "cloud.uuid" as datastore name as well
|
||||
CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context,
|
||||
CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context,
|
||||
_context.getServiceContent().getCustomFieldsManager());
|
||||
int key = cfmMo.getCustomFieldKey("Datastore", CustomFieldConstants.CLOUD_UUID);
|
||||
assert(key != 0);
|
||||
|
||||
ObjectContent[] ocs = getDatastorePropertiesOnHostDatastoreSystem(
|
||||
List<ObjectContent> ocs = getDatastorePropertiesOnHostDatastoreSystem(
|
||||
new String[] { "name", String.format("value[%d]", key) });
|
||||
if(ocs != null) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
if(oc.getPropSet(0).getVal().equals(name))
|
||||
if(oc.getPropSet().get(0).getVal().equals(name))
|
||||
return oc.getObj();
|
||||
|
||||
if(oc.getPropSet().length > 1) {
|
||||
DynamicProperty prop = oc.getPropSet(1);
|
||||
|
||||
if(oc.getPropSet().size() > 1) {
|
||||
DynamicProperty prop = oc.getPropSet().get(1);
|
||||
if(prop != null && prop.getVal() != null) {
|
||||
if(prop.getVal() instanceof CustomFieldStringValue) {
|
||||
String val = ((CustomFieldStringValue)prop.getVal()).getValue();
|
||||
|
|
@ -70,13 +73,13 @@ public class HostDatastoreSystemMO extends BaseMO {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// storeUrl in nfs://host/exportpath format
|
||||
public ManagedObjectReference findDatastoreByUrl(String storeUrl) throws Exception {
|
||||
assert(storeUrl != null);
|
||||
|
||||
ManagedObjectReference[] datastores = getDatastores();
|
||||
if(datastores != null && datastores.length > 0) {
|
||||
|
||||
List<ManagedObjectReference> datastores = getDatastores();
|
||||
if(datastores != null && datastores.size() > 0) {
|
||||
for(ManagedObjectReference morDatastore : datastores) {
|
||||
NasDatastoreInfo info = getNasDatastoreInfo(morDatastore);
|
||||
if(info != null) {
|
||||
|
|
@ -87,7 +90,7 @@ public class HostDatastoreSystemMO extends BaseMO {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -95,30 +98,30 @@ public class HostDatastoreSystemMO extends BaseMO {
|
|||
// we should be able to find the datastore by name
|
||||
public ManagedObjectReference findDatastoreByExportPath(String exportPath) throws Exception {
|
||||
assert(exportPath != null);
|
||||
|
||||
ManagedObjectReference[] datastores = getDatastores();
|
||||
if(datastores != null && datastores.length > 0) {
|
||||
|
||||
List<ManagedObjectReference> datastores = getDatastores();
|
||||
if(datastores != null && datastores.size() > 0) {
|
||||
for(ManagedObjectReference morDatastore : datastores) {
|
||||
DatastoreMO dsMo = new DatastoreMO(_context, morDatastore);
|
||||
if(dsMo.getInventoryPath().equals(exportPath))
|
||||
if(dsMo.getInventoryPath().equals(exportPath))
|
||||
return morDatastore;
|
||||
|
||||
|
||||
NasDatastoreInfo info = getNasDatastoreInfo(morDatastore);
|
||||
if(info != null) {
|
||||
String vmwareUrl = info.getUrl();
|
||||
if(vmwareUrl.charAt(vmwareUrl.length() - 1) == '/')
|
||||
vmwareUrl = vmwareUrl.substring(0, vmwareUrl.length() - 1);
|
||||
|
||||
|
||||
URI uri = new URI(vmwareUrl);
|
||||
if(uri.getPath().equals("/" + exportPath))
|
||||
return morDatastore;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public boolean deleteDatastore(String name) throws Exception {
|
||||
ManagedObjectReference morDatastore = findDatastore(name);
|
||||
if(morDatastore != null) {
|
||||
|
|
@ -127,59 +130,60 @@ public class HostDatastoreSystemMO extends BaseMO {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ManagedObjectReference createNfsDatastore(String host, int port,
|
||||
|
||||
public ManagedObjectReference createNfsDatastore(String host, int port,
|
||||
String exportPath, String uuid) throws Exception {
|
||||
|
||||
|
||||
HostNasVolumeSpec spec = new HostNasVolumeSpec();
|
||||
spec.setRemoteHost(host);
|
||||
spec.setRemotePath(exportPath);
|
||||
spec.setType("nfs");
|
||||
spec.setLocalPath(uuid);
|
||||
|
||||
|
||||
// readOnly/readWrite
|
||||
spec.setAccessMode("readWrite");
|
||||
return _context.getService().createNasDatastore(_mor, spec);
|
||||
}
|
||||
|
||||
public ManagedObjectReference[] getDatastores() throws Exception {
|
||||
return (ManagedObjectReference[])_context.getServiceUtil().getDynamicProperty(
|
||||
|
||||
public List<ManagedObjectReference> getDatastores() throws Exception {
|
||||
return (List<ManagedObjectReference>)_context.getVimClient().getDynamicProperty(
|
||||
_mor, "datastore");
|
||||
}
|
||||
|
||||
|
||||
public DatastoreInfo getDatastoreInfo(ManagedObjectReference morDatastore) throws Exception {
|
||||
return (DatastoreInfo)_context.getServiceUtil().getDynamicProperty(morDatastore, "info");
|
||||
return (DatastoreInfo)_context.getVimClient().getDynamicProperty(morDatastore, "info");
|
||||
}
|
||||
|
||||
|
||||
public NasDatastoreInfo getNasDatastoreInfo(ManagedObjectReference morDatastore) throws Exception {
|
||||
DatastoreInfo info = (DatastoreInfo)_context.getServiceUtil().getDynamicProperty(morDatastore, "info");
|
||||
DatastoreInfo info = (DatastoreInfo)_context.getVimClient().getDynamicProperty(morDatastore, "info");
|
||||
if(info instanceof NasDatastoreInfo)
|
||||
return (NasDatastoreInfo)info;
|
||||
return null;
|
||||
}
|
||||
|
||||
public ObjectContent[] getDatastorePropertiesOnHostDatastoreSystem(String[] propertyPaths) throws Exception {
|
||||
|
||||
|
||||
public List<ObjectContent> getDatastorePropertiesOnHostDatastoreSystem(String[] propertyPaths) throws Exception {
|
||||
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec.setType("Datastore");
|
||||
pSpec.setPathSet(propertyPaths);
|
||||
|
||||
pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
|
||||
|
||||
TraversalSpec hostDsSys2DatastoreTraversal = new TraversalSpec();
|
||||
hostDsSys2DatastoreTraversal.setType("HostDatastoreSystem");
|
||||
hostDsSys2DatastoreTraversal.setPath("datastore");
|
||||
hostDsSys2DatastoreTraversal.setName("hostDsSys2DatastoreTraversal");
|
||||
|
||||
|
||||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec.setObj(_mor);
|
||||
oSpec.setSkip(Boolean.TRUE);
|
||||
oSpec.setSelectSet(new SelectionSpec[] { hostDsSys2DatastoreTraversal });
|
||||
oSpec.getSelectSet().add(hostDsSys2DatastoreTraversal);
|
||||
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||
|
||||
pfSpec.getPropSet().add(pSpec);
|
||||
pfSpec.getObjectSet().add(oSpec);
|
||||
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
|
||||
pfSpecArr.add(pfSpec);
|
||||
|
||||
return _context.getService().retrieveProperties(
|
||||
_context.getServiceContent().getPropertyCollector(),
|
||||
new PropertyFilterSpec[] { pfSpec });
|
||||
_context.getPropertyCollector(), pfSpecArr);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,27 +29,27 @@ public class HostFirewallSystemMO extends BaseMO {
|
|||
public HostFirewallSystemMO(VmwareContext context, ManagedObjectReference morFirewallSystem) {
|
||||
super(context, morFirewallSystem);
|
||||
}
|
||||
|
||||
|
||||
public HostFirewallSystemMO(VmwareContext context, String morType, String morValue) {
|
||||
super(context, morType, morValue);
|
||||
}
|
||||
|
||||
|
||||
public HostFirewallInfo getFirewallInfo() throws Exception {
|
||||
return (HostFirewallInfo)_context.getServiceUtil().getDynamicProperty(_mor, "firewallInfo");
|
||||
return (HostFirewallInfo)_context.getVimClient().getDynamicProperty(_mor, "firewallInfo");
|
||||
}
|
||||
|
||||
|
||||
public void updateDefaultPolicy(HostFirewallDefaultPolicy policy) throws Exception {
|
||||
_context.getService().updateDefaultPolicy(_mor, policy);
|
||||
}
|
||||
|
||||
|
||||
public void enableRuleset(String rulesetName) throws Exception {
|
||||
_context.getService().enableRuleset(_mor, rulesetName);
|
||||
}
|
||||
|
||||
|
||||
public void disableRuleset(String rulesetName) throws Exception {
|
||||
_context.getService().disableRuleset(_mor, rulesetName);
|
||||
}
|
||||
|
||||
|
||||
public void refreshFirewall() throws Exception {
|
||||
_context.getService().refreshFirewall(_mor);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -20,121 +20,142 @@ import java.io.BufferedReader;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.vmware.vim25.HttpNfcLeaseInfo;
|
||||
import com.vmware.vim25.HttpNfcLeaseManifestEntry;
|
||||
import com.vmware.vim25.HttpNfcLeaseState;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
import com.vmware.vim25.ObjectSpec;
|
||||
import com.vmware.vim25.OvfCreateImportSpecResult;
|
||||
import com.vmware.vim25.OvfFileItem;
|
||||
import com.vmware.vim25.PropertyFilterSpec;
|
||||
import com.vmware.vim25.PropertySpec;
|
||||
|
||||
public class HttpNfcLeaseMO extends BaseMO {
|
||||
private static final Logger s_logger = Logger.getLogger(HttpNfcLeaseMO.class);
|
||||
|
||||
|
||||
public HttpNfcLeaseMO(VmwareContext context, ManagedObjectReference morHttpNfcLease) {
|
||||
super(context, morHttpNfcLease);
|
||||
}
|
||||
|
||||
|
||||
public HttpNfcLeaseMO(VmwareContext context, String morType, String morValue) {
|
||||
super(context, morType, morValue);
|
||||
}
|
||||
|
||||
public HttpNfcLeaseState getState() throws Exception {
|
||||
return (HttpNfcLeaseState)_context.getServiceUtil().getDynamicProperty(_mor, "state");
|
||||
Object stateProp = _context.getVimClient().getDynamicProperty(_mor, "state");
|
||||
// Due to some issue in JAX-WS De-serialization getting the information
|
||||
// from the nodes
|
||||
assert (stateProp.toString().contains("val: null"));
|
||||
String stateVal = null;
|
||||
Element stateElement = (Element) stateProp;
|
||||
if (stateElement != null && stateElement.getFirstChild() != null) {
|
||||
stateVal = stateElement.getFirstChild().getTextContent();
|
||||
}
|
||||
if (stateVal != null) {
|
||||
return HttpNfcLeaseState.fromValue(stateVal);
|
||||
}
|
||||
return HttpNfcLeaseState.ERROR;
|
||||
}
|
||||
|
||||
|
||||
public HttpNfcLeaseState waitState(HttpNfcLeaseState[] states) throws Exception {
|
||||
assert(states != null);
|
||||
assert(states.length > 0);
|
||||
|
||||
|
||||
HttpNfcLeaseState state;
|
||||
while(true) {
|
||||
state = getState();
|
||||
if(state == HttpNfcLeaseState.ready || state == HttpNfcLeaseState.error)
|
||||
if(state == HttpNfcLeaseState.READY || state == HttpNfcLeaseState.ERROR)
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public HttpNfcLeaseInfo getLeaseInfo() throws Exception {
|
||||
return (HttpNfcLeaseInfo)_context.getServiceUtil().getDynamicProperty(_mor, "info");
|
||||
return (HttpNfcLeaseInfo)_context.getVimClient().getDynamicProperty(_mor, "info");
|
||||
}
|
||||
|
||||
public HttpNfcLeaseManifestEntry[] getLeaseManifest() throws Exception {
|
||||
|
||||
public List<HttpNfcLeaseManifestEntry> getLeaseManifest() throws Exception {
|
||||
return _context.getService().httpNfcLeaseGetManifest(_mor);
|
||||
}
|
||||
|
||||
|
||||
public void completeLease() throws Exception {
|
||||
_context.getService().httpNfcLeaseComplete(_mor);
|
||||
}
|
||||
|
||||
|
||||
public void abortLease() throws Exception {
|
||||
_context.getService().httpNfcLeaseAbort(_mor, null);
|
||||
}
|
||||
|
||||
|
||||
public void updateLeaseProgress(int percent) throws Exception {
|
||||
// make sure percentage is in right range
|
||||
if(percent < 0)
|
||||
percent = 0;
|
||||
else if(percent > 100)
|
||||
percent = 100;
|
||||
|
||||
|
||||
_context.getService().httpNfcLeaseProgress(_mor, percent);
|
||||
}
|
||||
|
||||
|
||||
public ProgressReporter createProgressReporter() {
|
||||
return new ProgressReporter();
|
||||
}
|
||||
|
||||
public static long calcTotalBytes(OvfCreateImportSpecResult ovfImportResult) {
|
||||
OvfFileItem[] fileItemArr = ovfImportResult.getFileItem();
|
||||
long totalBytes = 0;
|
||||
if (fileItemArr != null) {
|
||||
for (OvfFileItem fi : fileItemArr) {
|
||||
totalBytes += fi.getSize();
|
||||
}
|
||||
}
|
||||
return totalBytes;
|
||||
}
|
||||
|
||||
public static String readOvfContent(String ovfFilePath) throws IOException {
|
||||
StringBuffer strContent = new StringBuffer();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(ovfFilePath)));
|
||||
String lineStr;
|
||||
while ((lineStr = in.readLine()) != null) {
|
||||
strContent.append(lineStr);
|
||||
}
|
||||
|
||||
in.close();
|
||||
return strContent.toString();
|
||||
public static long calcTotalBytes(OvfCreateImportSpecResult ovfImportResult) {
|
||||
List<OvfFileItem> fileItemArr = ovfImportResult.getFileItem();
|
||||
long totalBytes = 0;
|
||||
if (fileItemArr != null) {
|
||||
for (OvfFileItem fi : fileItemArr) {
|
||||
totalBytes += fi.getSize();
|
||||
}
|
||||
}
|
||||
return totalBytes;
|
||||
}
|
||||
|
||||
|
||||
public static String readOvfContent(String ovfFilePath) throws IOException {
|
||||
StringBuffer strContent = new StringBuffer();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(ovfFilePath)));
|
||||
String lineStr;
|
||||
while ((lineStr = in.readLine()) != null) {
|
||||
strContent.append(lineStr);
|
||||
}
|
||||
|
||||
in.close();
|
||||
return strContent.toString();
|
||||
}
|
||||
|
||||
public class ProgressReporter extends Thread {
|
||||
volatile int _percent;
|
||||
volatile boolean _done;
|
||||
|
||||
|
||||
public ProgressReporter() {
|
||||
_percent = 0;
|
||||
_done = false;
|
||||
|
||||
|
||||
setDaemon(true);
|
||||
start();
|
||||
}
|
||||
|
||||
|
||||
public void reportProgress(int percent) {
|
||||
_percent = percent;
|
||||
}
|
||||
|
||||
|
||||
public void close() {
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("close ProgressReporter, interrupt reporter runner to let it quit");
|
||||
|
||||
|
||||
_done = true;
|
||||
interrupt();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(!_done) {
|
||||
|
|
@ -149,7 +170,7 @@ public class HttpNfcLeaseMO extends BaseMO {
|
|||
s_logger.warn("Unexpected exception ", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("ProgressReporter stopped");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,16 +74,16 @@ public class HypervisorHostHelper {
|
|||
private static final Logger s_logger = Logger.getLogger(HypervisorHostHelper.class);
|
||||
private static final int DEFAULT_LOCK_TIMEOUT_SECONDS = 600;
|
||||
private static final String s_policyNamePrefix = "cloud.policy.";
|
||||
|
||||
|
||||
// make vmware-base loosely coupled with cloud-specific stuff, duplicate VLAN.UNTAGGED constant here
|
||||
private static final String UNTAGGED_VLAN_NAME = "untagged";
|
||||
|
||||
public static VirtualMachineMO findVmFromObjectContent(VmwareContext context,
|
||||
|
||||
public static VirtualMachineMO findVmFromObjectContent(VmwareContext context,
|
||||
ObjectContent[] ocs, String name) {
|
||||
|
||||
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
DynamicProperty prop = oc.getPropSet(0);
|
||||
DynamicProperty prop = oc.getPropSet().get(0);
|
||||
assert(prop != null);
|
||||
if(prop.getVal().toString().equals(name))
|
||||
return new VirtualMachineMO(context, oc.getObj());
|
||||
|
|
@ -91,20 +91,20 @@ public class HypervisorHostHelper {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static ManagedObjectReference findDatastoreWithBackwardsCompatibility(VmwareHypervisorHost hyperHost, String uuidName) throws Exception {
|
||||
ManagedObjectReference morDs = hyperHost.findDatastore(uuidName.replace("-", ""));
|
||||
if(morDs == null)
|
||||
morDs = hyperHost.findDatastore(uuidName);
|
||||
|
||||
|
||||
return morDs;
|
||||
}
|
||||
|
||||
|
||||
public static DatastoreMO getHyperHostDatastoreMO(VmwareHypervisorHost hyperHost, String datastoreName) throws Exception {
|
||||
ObjectContent[] ocs = hyperHost.getDatastorePropertiesOnHyperHost(new String[] { "name"} );
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
DynamicProperty[] objProps = oc.getPropSet();
|
||||
List<DynamicProperty> objProps = oc.getPropSet();
|
||||
if(objProps != null) {
|
||||
for(DynamicProperty objProp : objProps) {
|
||||
if(objProp.getVal().toString().equals(datastoreName))
|
||||
|
|
@ -115,7 +115,7 @@ public class HypervisorHostHelper {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static String getPublicNetworkNamePrefix(String vlanId) {
|
||||
if (UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId)) {
|
||||
return "cloud.public.untagged";
|
||||
|
|
@ -123,24 +123,24 @@ public class HypervisorHostHelper {
|
|||
return "cloud.public." + vlanId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String composeCloudNetworkName(String prefix, String vlanId, Integer networkRateMbps, String vSwitchName) {
|
||||
StringBuffer sb = new StringBuffer(prefix);
|
||||
if(vlanId == null || UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId))
|
||||
sb.append(".untagged");
|
||||
else
|
||||
sb.append(".").append(vlanId);
|
||||
|
||||
|
||||
if(networkRateMbps != null && networkRateMbps.intValue() > 0)
|
||||
sb.append(".").append(String.valueOf(networkRateMbps));
|
||||
else
|
||||
sb.append(".0");
|
||||
sb.append(".").append(VersioningContants.PORTGROUP_NAMING_VERSION);
|
||||
sb.append("-").append(vSwitchName);
|
||||
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, String> getValidatedVsmCredentials(VmwareContext context) throws Exception {
|
||||
Map<String, String> vsmCredentials = context.getStockObject("vsmcredentials");
|
||||
String msg;
|
||||
|
|
@ -396,9 +396,9 @@ public class HypervisorHostHelper {
|
|||
* @param timeOutMs
|
||||
* @param vSwitchType
|
||||
* @param numPorts
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
public static Pair<ManagedObjectReference, String> prepareNetwork(String physicalNetwork, String namePrefix,
|
||||
HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps, long timeOutMs,
|
||||
|
|
@ -417,7 +417,7 @@ public class HypervisorHostHelper {
|
|||
boolean createGCTag = false;
|
||||
String networkName;
|
||||
Integer vid = null;
|
||||
|
||||
|
||||
if(vlanId != null && !UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId)) {
|
||||
createGCTag = true;
|
||||
vid = Integer.parseInt(vlanId);
|
||||
|
|
@ -504,22 +504,22 @@ public class HypervisorHostHelper {
|
|||
} else {
|
||||
s_logger.info("Found Ethernet port profile " + ethPortProfileName);
|
||||
}
|
||||
long averageBandwidth = 0L;
|
||||
if (networkRateMbps != null && networkRateMbps.intValue() > 0) {
|
||||
averageBandwidth = (long) (networkRateMbps.intValue() * 1024L * 1024L);
|
||||
}
|
||||
// We chose 50% higher allocation than average bandwidth.
|
||||
long averageBandwidth = 0L;
|
||||
if (networkRateMbps != null && networkRateMbps.intValue() > 0) {
|
||||
averageBandwidth = (long) (networkRateMbps.intValue() * 1024L * 1024L);
|
||||
}
|
||||
// We chose 50% higher allocation than average bandwidth.
|
||||
// TODO(sateesh): Optionally let user specify the peak coefficient
|
||||
long peakBandwidth = (long) (averageBandwidth * 1.5);
|
||||
long peakBandwidth = (long) (averageBandwidth * 1.5);
|
||||
// TODO(sateesh): Optionally let user specify the burst coefficient
|
||||
long burstSize = 5 * averageBandwidth / 8;
|
||||
long burstSize = 5 * averageBandwidth / 8;
|
||||
|
||||
if (!dataCenterMo.hasDvPortGroup(networkName)) {
|
||||
s_logger.info("Port profile " + networkName + " not found.");
|
||||
if (!dataCenterMo.hasDvPortGroup(networkName)) {
|
||||
s_logger.info("Port profile " + networkName + " not found.");
|
||||
createPortProfile(context, physicalNetwork, networkName, vid, networkRateMbps, peakBandwidth, burstSize);
|
||||
bWaitPortGroupReady = true;
|
||||
} else {
|
||||
s_logger.info("Port profile " + networkName + " found.");
|
||||
bWaitPortGroupReady = true;
|
||||
} else {
|
||||
s_logger.info("Port profile " + networkName + " found.");
|
||||
updatePortProfile(context, physicalNetwork, networkName, vid, networkRateMbps, peakBandwidth, burstSize);
|
||||
}
|
||||
}
|
||||
|
|
@ -533,7 +533,7 @@ public class HypervisorHostHelper {
|
|||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
|
||||
if(createGCTag) {
|
||||
NetworkMO networkMo = new NetworkMO(hostMo.getContext(), morNetwork);
|
||||
networkMo.setCustomFieldValue(CustomFieldConstants.CLOUD_GC_DVP, "true");
|
||||
|
|
@ -563,39 +563,39 @@ public class HypervisorHostHelper {
|
|||
}
|
||||
|
||||
public static boolean isSpecMatch(DVPortgroupConfigInfo configInfo, Integer vid, DVSTrafficShapingPolicy shapingPolicy) {
|
||||
DVSTrafficShapingPolicy currentTrafficShapingPolicy;
|
||||
DVSTrafficShapingPolicy currentTrafficShapingPolicy;
|
||||
currentTrafficShapingPolicy = configInfo.getDefaultPortConfig().getInShapingPolicy();
|
||||
|
||||
assert(currentTrafficShapingPolicy != null);
|
||||
assert(currentTrafficShapingPolicy != null);
|
||||
|
||||
LongPolicy averageBandwidth = currentTrafficShapingPolicy.getAverageBandwidth();
|
||||
LongPolicy burstSize = currentTrafficShapingPolicy.getBurstSize();
|
||||
LongPolicy peakBandwidth = currentTrafficShapingPolicy.getPeakBandwidth();
|
||||
BoolPolicy isEnabled = currentTrafficShapingPolicy.getEnabled();
|
||||
LongPolicy averageBandwidth = currentTrafficShapingPolicy.getAverageBandwidth();
|
||||
LongPolicy burstSize = currentTrafficShapingPolicy.getBurstSize();
|
||||
LongPolicy peakBandwidth = currentTrafficShapingPolicy.getPeakBandwidth();
|
||||
BoolPolicy isEnabled = currentTrafficShapingPolicy.getEnabled();
|
||||
|
||||
if (!isEnabled.equals(shapingPolicy.getEnabled())) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(averageBandwidth != null && !averageBandwidth.equals(shapingPolicy.getAverageBandwidth())) {
|
||||
if(s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Average bandwidth setting in shaping policy doesn't match with existing setting.");
|
||||
}
|
||||
return false;
|
||||
} else if(burstSize != null && !burstSize.equals(shapingPolicy.getBurstSize())) {
|
||||
if(s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Burst size setting in shaping policy doesn't match with existing setting.");
|
||||
}
|
||||
return false;
|
||||
} else if(peakBandwidth != null && !peakBandwidth.equals(shapingPolicy.getPeakBandwidth())) {
|
||||
if(s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Peak bandwidth setting in shaping policy doesn't match with existing setting.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if(averageBandwidth != null && !averageBandwidth.equals(shapingPolicy.getAverageBandwidth())) {
|
||||
if(s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Average bandwidth setting in shaping policy doesn't match with existing setting.");
|
||||
}
|
||||
return false;
|
||||
} else if(burstSize != null && !burstSize.equals(shapingPolicy.getBurstSize())) {
|
||||
if(s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Burst size setting in shaping policy doesn't match with existing setting.");
|
||||
}
|
||||
return false;
|
||||
} else if(peakBandwidth != null && !peakBandwidth.equals(shapingPolicy.getPeakBandwidth())) {
|
||||
if(s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Peak bandwidth setting in shaping policy doesn't match with existing setting.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static DVPortgroupConfigSpec createDvPortGroupSpec(String dvPortGroupName, DVPortSetting portSetting, int numPorts) {
|
||||
DVPortgroupConfigSpec spec = new DVPortgroupConfigSpec();
|
||||
|
|
@ -670,7 +670,7 @@ public class HypervisorHostHelper {
|
|||
}
|
||||
|
||||
public static Pair<ManagedObjectReference, String> prepareNetwork(String vSwitchName, String namePrefix,
|
||||
HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps,
|
||||
HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps,
|
||||
long timeOutMs, boolean syncPeerHosts) throws Exception {
|
||||
|
||||
HostVirtualSwitch vSwitch;
|
||||
|
|
@ -689,12 +689,12 @@ public class HypervisorHostHelper {
|
|||
boolean createGCTag = false;
|
||||
String networkName;
|
||||
Integer vid = null;
|
||||
|
||||
|
||||
if(vlanId != null && !UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId)) {
|
||||
createGCTag = true;
|
||||
vid = Integer.parseInt(vlanId);
|
||||
}
|
||||
|
||||
|
||||
networkName = composeCloudNetworkName(namePrefix, vlanId, networkRateMbps, vSwitchName);
|
||||
HostNetworkSecurityPolicy secPolicy = null;
|
||||
if (namePrefix.equalsIgnoreCase("cloud.private")) {
|
||||
|
|
@ -708,11 +708,11 @@ public class HypervisorHostHelper {
|
|||
shapingPolicy = new HostNetworkTrafficShapingPolicy();
|
||||
shapingPolicy.setEnabled(true);
|
||||
shapingPolicy.setAverageBandwidth((long)networkRateMbps.intValue()*1024L*1024L);
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
// TODO : people may have different opinion on how to set the following
|
||||
//
|
||||
|
||||
|
||||
// give 50% premium to peek
|
||||
shapingPolicy.setPeakBandwidth((long)(shapingPolicy.getAverageBandwidth()*1.5));
|
||||
|
||||
|
|
@ -733,7 +733,7 @@ public class HypervisorHostHelper {
|
|||
}
|
||||
|
||||
ManagedObjectReference morNetwork;
|
||||
if(bWaitPortGroupReady)
|
||||
if(bWaitPortGroupReady)
|
||||
morNetwork = waitForNetworkReady(hostMo, networkName, timeOutMs);
|
||||
else
|
||||
morNetwork = hostMo.getNetworkMor(networkName);
|
||||
|
|
@ -742,24 +742,24 @@ public class HypervisorHostHelper {
|
|||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
|
||||
if(createGCTag) {
|
||||
NetworkMO networkMo = new NetworkMO(hostMo.getContext(), morNetwork);
|
||||
networkMo.setCustomFieldValue(CustomFieldConstants.CLOUD_GC, "true");
|
||||
}
|
||||
|
||||
|
||||
if(syncPeerHosts) {
|
||||
ManagedObjectReference morParent = hostMo.getParentMor();
|
||||
if(morParent != null && morParent.getType().equals("ClusterComputeResource")) {
|
||||
// to be conservative, lock cluster
|
||||
GlobalLock lock = GlobalLock.getInternLock("ClusterLock." + morParent.get_value());
|
||||
GlobalLock lock = GlobalLock.getInternLock("ClusterLock." + morParent.getValue());
|
||||
try {
|
||||
if(lock.lock(DEFAULT_LOCK_TIMEOUT_SECONDS)) {
|
||||
try {
|
||||
ManagedObjectReference[] hosts = (ManagedObjectReference[])hostMo.getContext().getServiceUtil().getDynamicProperty(morParent, "host");
|
||||
List<ManagedObjectReference> hosts = (List<ManagedObjectReference>)hostMo.getContext().getVimClient().getDynamicProperty(morParent, "host");
|
||||
if(hosts != null) {
|
||||
for(ManagedObjectReference otherHost: hosts) {
|
||||
if(!otherHost.get_value().equals(hostMo.getMor().get_value())) {
|
||||
if(!otherHost.getValue().equals(hostMo.getMor().getValue())) {
|
||||
HostMO otherHostMo = new HostMO(hostMo.getContext(), otherHost);
|
||||
try {
|
||||
if(s_logger.isDebugEnabled())
|
||||
|
|
@ -786,7 +786,7 @@ public class HypervisorHostHelper {
|
|||
s_logger.info("Network " + networkName + " is ready on vSwitch " + vSwitchName);
|
||||
return new Pair<ManagedObjectReference, String>(morNetwork, networkName);
|
||||
}
|
||||
|
||||
|
||||
private static boolean isSpecMatch(HostPortGroupSpec spec, Integer vlanId, HostNetworkTrafficShapingPolicy shapingPolicy) {
|
||||
// check VLAN configuration
|
||||
if(vlanId != null) {
|
||||
|
|
@ -801,17 +801,17 @@ public class HypervisorHostHelper {
|
|||
HostNetworkTrafficShapingPolicy policyInSpec = null;
|
||||
if(spec.getPolicy() != null)
|
||||
policyInSpec = spec.getPolicy().getShapingPolicy();
|
||||
|
||||
|
||||
if(policyInSpec != null && shapingPolicy == null || policyInSpec == null && shapingPolicy != null)
|
||||
return false;
|
||||
|
||||
|
||||
if(policyInSpec == null && shapingPolicy == null)
|
||||
return true;
|
||||
|
||||
|
||||
// so far policyInSpec and shapingPolicy should both not be null
|
||||
if(policyInSpec.getEnabled() == null || !policyInSpec.getEnabled().booleanValue())
|
||||
if(policyInSpec.isEnabled() == null || !policyInSpec.isEnabled().booleanValue())
|
||||
return false;
|
||||
|
||||
|
||||
if(policyInSpec.getAverageBandwidth() == null || policyInSpec.getAverageBandwidth().longValue() != shapingPolicy.getAverageBandwidth().longValue())
|
||||
return false;
|
||||
|
||||
|
|
@ -820,10 +820,10 @@ public class HypervisorHostHelper {
|
|||
|
||||
if(policyInSpec.getBurstSize() == null || policyInSpec.getBurstSize().longValue() != shapingPolicy.getBurstSize().longValue())
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static ManagedObjectReference waitForNetworkReady(HostMO hostMo,
|
||||
String networkName, long timeOutMs) throws Exception {
|
||||
|
||||
|
|
@ -844,14 +844,14 @@ public class HypervisorHostHelper {
|
|||
|
||||
return morNetwork;
|
||||
}
|
||||
|
||||
public static boolean createBlankVm(VmwareHypervisorHost host, String vmName,
|
||||
int cpuCount, int cpuSpeedMHz, int cpuReservedMHz, boolean limitCpuUse, int memoryMB, int memoryReserveMB, String guestOsIdentifier,
|
||||
|
||||
public static boolean createBlankVm(VmwareHypervisorHost host, String vmName,
|
||||
int cpuCount, int cpuSpeedMHz, int cpuReservedMHz, boolean limitCpuUse, int memoryMB, int memoryReserveMB, String guestOsIdentifier,
|
||||
ManagedObjectReference morDs, boolean snapshotDirToParent) throws Exception {
|
||||
|
||||
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("Create blank VM. cpuCount: " + cpuCount + ", cpuSpeed(MHz): " + cpuSpeedMHz + ", mem(Mb): " + memoryMB);
|
||||
|
||||
|
||||
// VM config basics
|
||||
VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();
|
||||
vmConfig.setName(vmName);
|
||||
|
|
@ -859,62 +859,63 @@ public class HypervisorHostHelper {
|
|||
|
||||
// Scsi controller
|
||||
VirtualLsiLogicController scsiController = new VirtualLsiLogicController();
|
||||
scsiController.setSharedBus(VirtualSCSISharing.noSharing);
|
||||
scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
|
||||
scsiController.setBusNumber(0);
|
||||
scsiController.setKey(1);
|
||||
VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec();
|
||||
scsiControllerSpec.setDevice(scsiController);
|
||||
scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
|
||||
scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
|
||||
|
||||
VirtualMachineFileInfo fileInfo = new VirtualMachineFileInfo();
|
||||
DatastoreMO dsMo = new DatastoreMO(host.getContext(), morDs);
|
||||
fileInfo.setVmPathName(String.format("[%s]", dsMo.getName()));
|
||||
vmConfig.setFiles(fileInfo);
|
||||
|
||||
|
||||
VirtualMachineVideoCard videoCard = new VirtualMachineVideoCard();
|
||||
videoCard.setControllerKey(100);
|
||||
videoCard.setUseAutoDetect(true);
|
||||
|
||||
|
||||
VirtualDeviceConfigSpec videoDeviceSpec = new VirtualDeviceConfigSpec();
|
||||
videoDeviceSpec.setDevice(videoCard);
|
||||
videoDeviceSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
|
||||
|
||||
vmConfig.setDeviceChange(new VirtualDeviceConfigSpec[] { scsiControllerSpec, videoDeviceSpec });
|
||||
videoDeviceSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
|
||||
|
||||
vmConfig.getDeviceChange().add(scsiControllerSpec);
|
||||
vmConfig.getDeviceChange().add(videoDeviceSpec);
|
||||
if(host.createVm(vmConfig)) {
|
||||
VirtualMachineMO vmMo = host.findVmOnHyperHost(vmName);
|
||||
assert(vmMo != null);
|
||||
|
||||
|
||||
int ideControllerKey = -1;
|
||||
while(ideControllerKey < 0) {
|
||||
ideControllerKey = vmMo.tryGetIDEDeviceControllerKey();
|
||||
if(ideControllerKey >= 0)
|
||||
break;
|
||||
|
||||
|
||||
s_logger.info("Waiting for IDE controller be ready in VM: " + vmName);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
|
||||
if(snapshotDirToParent) {
|
||||
String snapshotDir = String.format("/vmfs/volumes/%s/", dsMo.getName());
|
||||
|
||||
|
||||
s_logger.info("Switch snapshot working directory to " + snapshotDir + " for " + vmName);
|
||||
vmMo.setSnapshotDirectory(snapshotDir);
|
||||
|
||||
|
||||
// Don't have a good way to test if the VM is really ready for use through normal API after configuration file manipulation,
|
||||
// delay 3 seconds
|
||||
Thread.sleep(3000);
|
||||
}
|
||||
|
||||
|
||||
s_logger.info("Blank VM: " + vmName + " is ready for use");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static String resolveHostNameInUrl(DatacenterMO dcMo, String url) {
|
||||
|
||||
|
||||
s_logger.info("Resolving host name in url through vCenter, url: " + url);
|
||||
|
||||
|
||||
URI uri;
|
||||
try {
|
||||
uri = new URI(url);
|
||||
|
|
@ -922,13 +923,13 @@ public class HypervisorHostHelper {
|
|||
s_logger.warn("URISyntaxException on url " + url);
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
String host = uri.getHost();
|
||||
if(NetUtils.isValidIp(host)) {
|
||||
s_logger.info("host name in url is already in IP address, url: " + url);
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
ManagedObjectReference morHost = dcMo.findHost(host);
|
||||
if(morHost != null) {
|
||||
|
|
@ -938,18 +939,18 @@ public class HypervisorHostHelper {
|
|||
managementPortGroupName = (String)dcMo.getContext().getStockObject("manageportgroup");
|
||||
else
|
||||
managementPortGroupName = (String)dcMo.getContext().getStockObject("serviceconsole");
|
||||
|
||||
|
||||
VmwareHypervisorHostNetworkSummary summary = hostMo.getHyperHostNetworkSummary(managementPortGroupName);
|
||||
if(summary == null) {
|
||||
s_logger.warn("Unable to resolve host name in url through vSphere, url: " + url);
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
String hostIp = summary.getHostIp();
|
||||
|
||||
|
||||
try {
|
||||
URI resolvedUri = new URI(uri.getScheme(), uri.getUserInfo(), hostIp, uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());
|
||||
|
||||
|
||||
s_logger.info("url " + url + " is resolved to " + resolvedUri.toString() + " through vCenter");
|
||||
return resolvedUri.toString();
|
||||
} catch (URISyntaxException e) {
|
||||
|
|
@ -960,41 +961,41 @@ public class HypervisorHostHelper {
|
|||
} catch(Exception e) {
|
||||
s_logger.warn("Unexpected exception ", e);
|
||||
}
|
||||
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
public static void importVmFromOVF(VmwareHypervisorHost host, String ovfFilePath, String vmName, DatastoreMO dsMo, String diskOption,
|
||||
|
||||
public static void importVmFromOVF(VmwareHypervisorHost host, String ovfFilePath, String vmName, DatastoreMO dsMo, String diskOption,
|
||||
ManagedObjectReference morRp, ManagedObjectReference morHost) throws Exception {
|
||||
|
||||
|
||||
assert(morRp != null);
|
||||
|
||||
OvfCreateImportSpecParams importSpecParams = new OvfCreateImportSpecParams();
|
||||
importSpecParams.setHostSystem(morHost);
|
||||
importSpecParams.setLocale("US");
|
||||
importSpecParams.setEntityName(vmName);
|
||||
|
||||
OvfCreateImportSpecParams importSpecParams = new OvfCreateImportSpecParams();
|
||||
importSpecParams.setHostSystem(morHost);
|
||||
importSpecParams.setLocale("US");
|
||||
importSpecParams.setEntityName(vmName);
|
||||
importSpecParams.setDeploymentOption("");
|
||||
importSpecParams.setDiskProvisioning(diskOption); // diskOption: thin, thick, etc
|
||||
importSpecParams.setPropertyMapping(null);
|
||||
|
||||
//importSpecParams.setPropertyMapping(null);
|
||||
|
||||
String ovfDescriptor = HttpNfcLeaseMO.readOvfContent(ovfFilePath);
|
||||
VmwareContext context = host.getContext();
|
||||
OvfCreateImportSpecResult ovfImportResult = context.getService().createImportSpec(
|
||||
context.getServiceContent().getOvfManager(), ovfDescriptor, morRp,
|
||||
context.getServiceContent().getOvfManager(), ovfDescriptor, morRp,
|
||||
dsMo.getMor(), importSpecParams);
|
||||
|
||||
|
||||
if(ovfImportResult == null) {
|
||||
String msg = "createImportSpec() failed. ovfFilePath: " + ovfFilePath + ", vmName: "
|
||||
String msg = "createImportSpec() failed. ovfFilePath: " + ovfFilePath + ", vmName: "
|
||||
+ vmName + ", diskOption: " + diskOption;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
|
||||
DatacenterMO dcMo = new DatacenterMO(context, host.getHyperHostDatacenter());
|
||||
ManagedObjectReference morLease = context.getService().importVApp(morRp,
|
||||
ManagedObjectReference morLease = context.getService().importVApp(morRp,
|
||||
ovfImportResult.getImportSpec(), dcMo.getVmFolder(), morHost);
|
||||
if(morLease == null) {
|
||||
String msg = "importVApp() failed. ovfFilePath: " + ovfFilePath + ", vmName: "
|
||||
String msg = "importVApp() failed. ovfFilePath: " + ovfFilePath + ", vmName: "
|
||||
+ vmName + ", diskOption: " + diskOption;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
|
|
@ -1002,56 +1003,56 @@ public class HypervisorHostHelper {
|
|||
boolean importSuccess = true;
|
||||
final HttpNfcLeaseMO leaseMo = new HttpNfcLeaseMO(context, morLease);
|
||||
HttpNfcLeaseState state = leaseMo.waitState(
|
||||
new HttpNfcLeaseState[] { HttpNfcLeaseState.ready, HttpNfcLeaseState.error });
|
||||
new HttpNfcLeaseState[] { HttpNfcLeaseState.READY, HttpNfcLeaseState.ERROR });
|
||||
try {
|
||||
if(state == HttpNfcLeaseState.ready) {
|
||||
if(state == HttpNfcLeaseState.READY) {
|
||||
final long totalBytes = HttpNfcLeaseMO.calcTotalBytes(ovfImportResult);
|
||||
File ovfFile = new File(ovfFilePath);
|
||||
|
||||
File ovfFile = new File(ovfFilePath);
|
||||
|
||||
HttpNfcLeaseInfo httpNfcLeaseInfo = leaseMo.getLeaseInfo();
|
||||
HttpNfcLeaseDeviceUrl[] deviceUrls = httpNfcLeaseInfo.getDeviceUrl();
|
||||
List<HttpNfcLeaseDeviceUrl> deviceUrls = httpNfcLeaseInfo.getDeviceUrl();
|
||||
long bytesAlreadyWritten = 0;
|
||||
|
||||
|
||||
final HttpNfcLeaseMO.ProgressReporter progressReporter = leaseMo.createProgressReporter();
|
||||
try {
|
||||
for (HttpNfcLeaseDeviceUrl deviceUrl : deviceUrls) {
|
||||
String deviceKey = deviceUrl.getImportKey();
|
||||
String deviceKey = deviceUrl.getImportKey();
|
||||
for (OvfFileItem ovfFileItem : ovfImportResult.getFileItem()) {
|
||||
if (deviceKey.equals(ovfFileItem.getDeviceId())) {
|
||||
if (deviceKey.equals(ovfFileItem.getDeviceId())) {
|
||||
String absoluteFile = ovfFile.getParent() + File.separator + ovfFileItem.getPath();
|
||||
String urlToPost = deviceUrl.getUrl();
|
||||
urlToPost = resolveHostNameInUrl(dcMo, urlToPost);
|
||||
|
||||
context.uploadVmdkFile(ovfFileItem.isCreate() ? "PUT" : "POST", urlToPost, absoluteFile,
|
||||
|
||||
context.uploadVmdkFile(ovfFileItem.isCreate() ? "PUT" : "POST", urlToPost, absoluteFile,
|
||||
bytesAlreadyWritten, new ActionDelegate<Long> () {
|
||||
public void action(Long param) {
|
||||
progressReporter.reportProgress((int)(param * 100 / totalBytes));
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
bytesAlreadyWritten += ovfFileItem.getSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Failed to complete file upload task. " + e.getMessage());
|
||||
// Set flag to cleanup the stale template left due to failed import operation, if any
|
||||
importSuccess = false;
|
||||
throw e;
|
||||
} finally {
|
||||
progressReporter.close();
|
||||
}
|
||||
} finally {
|
||||
progressReporter.close();
|
||||
}
|
||||
if (bytesAlreadyWritten == totalBytes) {
|
||||
leaseMo.updateLeaseProgress(100);
|
||||
}
|
||||
leaseMo.updateLeaseProgress(100);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
} finally {
|
||||
if (!importSuccess) {
|
||||
s_logger.error("Aborting the lease on " + vmName + " after import operation failed.");
|
||||
leaseMo.abortLease();
|
||||
} else {
|
||||
leaseMo.completeLease();
|
||||
}
|
||||
leaseMo.completeLease();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
// under the License.
|
||||
package com.cloud.hypervisor.vmware.mo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
|
||||
|
|
@ -23,17 +25,16 @@ public class NetworkMO extends BaseMO {
|
|||
public NetworkMO(VmwareContext context, ManagedObjectReference morCluster) {
|
||||
super(context, morCluster);
|
||||
}
|
||||
|
||||
|
||||
public NetworkMO(VmwareContext context, String morType, String morValue) {
|
||||
super(context, morType, morValue);
|
||||
}
|
||||
|
||||
|
||||
public void destroyNetwork() throws Exception {
|
||||
_context.getService().destroyNetwork(_mor);
|
||||
_context.getService().destroyNetwork(_mor);
|
||||
}
|
||||
|
||||
public ManagedObjectReference[] getVMsOnNetwork() throws Exception {
|
||||
ManagedObjectReference[] vms = (ManagedObjectReference[])_context.getServiceUtil().getDynamicProperty(_mor, "vm");
|
||||
return vms;
|
||||
|
||||
public List<ManagedObjectReference> getVMsOnNetwork() throws Exception {
|
||||
return (List<ManagedObjectReference>)_context.getVimClient().getDynamicProperty(_mor, "vm");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,13 @@
|
|||
// under the License.
|
||||
package com.cloud.hypervisor.vmware.mo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.datatype.DatatypeConfigurationException;
|
||||
import javax.xml.datatype.DatatypeFactory;
|
||||
import javax.xml.datatype.XMLGregorianCalendar;
|
||||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
|
|
@ -28,58 +34,91 @@ import com.vmware.vim25.PerfMetricId;
|
|||
import com.vmware.vim25.PerfProviderSummary;
|
||||
import com.vmware.vim25.PerfQuerySpec;
|
||||
|
||||
import edu.emory.mathcs.backport.java.util.Arrays;
|
||||
|
||||
public class PerfManagerMO extends BaseMO {
|
||||
public PerfManagerMO(VmwareContext context, ManagedObjectReference mor) {
|
||||
super(context, mor);
|
||||
}
|
||||
|
||||
|
||||
public PerfManagerMO(VmwareContext context, String morType, String morValue) {
|
||||
super(context, morType, morValue);
|
||||
}
|
||||
|
||||
|
||||
public void createPerfInterval(PerfInterval interval) throws Exception {
|
||||
_context.getService().createPerfInterval(_mor, interval);
|
||||
}
|
||||
|
||||
public PerfMetricId[] queryAvailablePerfMetric(ManagedObjectReference morEntity, Calendar beginTime,
|
||||
|
||||
/**
|
||||
* Converts Calendar object into XMLGregorianCalendar
|
||||
*
|
||||
* @param calendar Object to be converted
|
||||
* @return XMLGregorianCalendar
|
||||
*/
|
||||
private XMLGregorianCalendar calendarToXMLGregorianCalendar(Calendar calendar) throws DatatypeConfigurationException {
|
||||
|
||||
DatatypeFactory dtf = DatatypeFactory.newInstance();
|
||||
XMLGregorianCalendar xgc = dtf.newXMLGregorianCalendar();
|
||||
xgc.setYear(calendar.get(Calendar.YEAR));
|
||||
xgc.setMonth(calendar.get(Calendar.MONTH) + 1);
|
||||
xgc.setDay(calendar.get(Calendar.DAY_OF_MONTH));
|
||||
xgc.setHour(calendar.get(Calendar.HOUR_OF_DAY));
|
||||
xgc.setMinute(calendar.get(Calendar.MINUTE));
|
||||
xgc.setSecond(calendar.get(Calendar.SECOND));
|
||||
xgc.setMillisecond(calendar.get(Calendar.MILLISECOND));
|
||||
|
||||
// Calendar ZONE_OFFSET and DST_OFFSET fields are in milliseconds.
|
||||
int offsetInMinutes = (calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / (60 * 1000);
|
||||
xgc.setTimezone(offsetInMinutes);
|
||||
return xgc;
|
||||
}
|
||||
|
||||
public List<PerfMetricId> queryAvailablePerfMetric(ManagedObjectReference morEntity, Calendar beginTime,
|
||||
Calendar endTime, Integer intervalId) throws Exception {
|
||||
|
||||
return _context.getService().queryAvailablePerfMetric(_mor, morEntity, beginTime, endTime, intervalId);
|
||||
|
||||
return _context.getService().queryAvailablePerfMetric(_mor, morEntity, calendarToXMLGregorianCalendar(beginTime),
|
||||
calendarToXMLGregorianCalendar(endTime), intervalId);
|
||||
}
|
||||
|
||||
public PerfCompositeMetric queryPerfComposite(PerfQuerySpec spec) throws Exception {
|
||||
return _context.getService().queryPerfComposite(_mor, spec);
|
||||
}
|
||||
|
||||
public PerfCounterInfo[] queryPerfCounter(int[] counterId) throws Exception {
|
||||
return _context.getService().queryPerfCounter(_mor, counterId);
|
||||
}
|
||||
|
||||
public PerfCounterInfo[] queryPerfCounterByLevel(int level) throws Exception {
|
||||
return _context.getService().queryPerfCounterByLevel(_mor, level);
|
||||
}
|
||||
|
||||
public PerfProviderSummary queryPerfProviderSummary(ManagedObjectReference morEntity) throws Exception {
|
||||
return _context.getService().queryPerfProviderSummary(_mor, morEntity);
|
||||
|
||||
public List<PerfCounterInfo> queryPerfCounter(int[] counterId) throws Exception {
|
||||
List<Integer> counterArr = new ArrayList<Integer>();
|
||||
if ( counterId != null){
|
||||
for (int i = 0; i < counterId.length; i++ ){
|
||||
counterArr.add(counterId[i]);
|
||||
}
|
||||
}
|
||||
return _context.getService().queryPerfCounter(_mor, counterArr);
|
||||
}
|
||||
|
||||
public PerfEntityMetricBase[] queryPerf(PerfQuerySpec[] specs) throws Exception {
|
||||
return _context.getService().queryPerf(_mor, specs);
|
||||
public List<PerfCounterInfo> queryPerfCounterByLevel(int level) throws Exception {
|
||||
return _context.getService().queryPerfCounterByLevel(_mor, level);
|
||||
}
|
||||
|
||||
|
||||
public PerfProviderSummary queryPerfProviderSummary(ManagedObjectReference morEntity) throws Exception {
|
||||
return _context.getService().queryPerfProviderSummary(_mor, morEntity);
|
||||
}
|
||||
|
||||
public List<PerfEntityMetricBase> queryPerf(PerfQuerySpec[] specs) throws Exception {
|
||||
return _context.getService().queryPerf(_mor, Arrays.asList(specs));
|
||||
}
|
||||
|
||||
public void removePerfInterval(int samplePeriod) throws Exception {
|
||||
_context.getService().removePerfInterval(_mor, samplePeriod);
|
||||
}
|
||||
|
||||
|
||||
public void updatePerfInterval(PerfInterval interval) throws Exception {
|
||||
_context.getService().updatePerfInterval(_mor, interval);
|
||||
}
|
||||
|
||||
public PerfCounterInfo[] getCounterInfo() throws Exception {
|
||||
return (PerfCounterInfo[])_context.getServiceUtil().getDynamicProperty(_mor, "perfCounter");
|
||||
|
||||
public List<PerfCounterInfo> getCounterInfo() throws Exception {
|
||||
return (List<PerfCounterInfo>)_context.getVimClient().getDynamicProperty(_mor, "perfCounter");
|
||||
}
|
||||
|
||||
public PerfInterval[] getIntervalInfo() throws Exception {
|
||||
return (PerfInterval[])_context.getServiceUtil().getDynamicProperty(_mor, "historicalInterval");
|
||||
|
||||
public List<PerfInterval> getIntervalInfo() throws Exception {
|
||||
return (List<PerfInterval>)_context.getVimClient().getDynamicProperty(_mor, "historicalInterval");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,48 +27,48 @@ public class TaskMO extends BaseMO {
|
|||
public TaskMO(VmwareContext context, ManagedObjectReference morTask) {
|
||||
super(context, morTask);
|
||||
}
|
||||
|
||||
|
||||
public TaskMO(VmwareContext context, String morType, String morValue) {
|
||||
super(context, morType, morValue);
|
||||
}
|
||||
|
||||
|
||||
public TaskInfo getTaskInfo() throws Exception {
|
||||
return (TaskInfo)getContext().getServiceUtil().getDynamicProperty(_mor, "info");
|
||||
return (TaskInfo)getContext().getVimClient().getDynamicProperty(_mor, "info");
|
||||
}
|
||||
|
||||
|
||||
public void setTaskDescription(LocalizableMessage description) throws Exception {
|
||||
_context.getService().setTaskDescription(_mor, description);
|
||||
}
|
||||
|
||||
|
||||
public void setTaskState(TaskInfoState state, Object result, LocalizedMethodFault fault) throws Exception {
|
||||
_context.getService().setTaskState(_mor, state, result, fault);
|
||||
}
|
||||
|
||||
|
||||
public void updateProgress(int percentDone) throws Exception {
|
||||
_context.getService().updateProgress(_mor, percentDone);
|
||||
}
|
||||
|
||||
|
||||
public void cancelTask() throws Exception {
|
||||
_context.getService().cancelTask(_mor);
|
||||
}
|
||||
|
||||
|
||||
public static String getTaskFailureInfo(VmwareContext context, ManagedObjectReference morTask) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
|
||||
try {
|
||||
TaskInfo info = (TaskInfo)context.getServiceUtil().getDynamicProperty(morTask, "info");
|
||||
TaskInfo info = (TaskInfo)context.getVimClient().getDynamicProperty(morTask, "info");
|
||||
if(info != null) {
|
||||
LocalizedMethodFault fault = info.getError();
|
||||
if(fault != null) {
|
||||
sb.append(fault.getLocalizedMessage()).append(" ");
|
||||
|
||||
|
||||
if(fault.getFault() != null)
|
||||
sb.append(fault.getFault().getClass().getName());
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
}
|
||||
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,132 +25,132 @@ import com.vmware.vim25.VirtualDiskSpec;
|
|||
|
||||
public class VirtualDiskManagerMO extends BaseMO {
|
||||
private static final Logger s_logger = Logger.getLogger(VirtualDiskManagerMO.class);
|
||||
|
||||
|
||||
public VirtualDiskManagerMO(VmwareContext context, ManagedObjectReference morDiskMgr) {
|
||||
super(context, morDiskMgr);
|
||||
}
|
||||
|
||||
|
||||
public VirtualDiskManagerMO(VmwareContext context, String morType, String morValue) {
|
||||
super(context, morType, morValue);
|
||||
}
|
||||
|
||||
|
||||
public void copyVirtualDisk(String srcName, ManagedObjectReference morSrcDc,
|
||||
String destName, ManagedObjectReference morDestDc, VirtualDiskSpec diskSpec,
|
||||
String destName, ManagedObjectReference morDestDc, VirtualDiskSpec diskSpec,
|
||||
boolean force) throws Exception {
|
||||
|
||||
ManagedObjectReference morTask = _context.getService().copyVirtualDisk_Task(_mor, srcName, morSrcDc, destName, morDestDc, diskSpec, force);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(!result.equals("sucess"))
|
||||
throw new Exception("Unable to copy virtual disk " + srcName + " to " + destName
|
||||
+ " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
}
|
||||
|
||||
public void createVirtualDisk(String name, ManagedObjectReference morDc, VirtualDiskSpec diskSpec) throws Exception {
|
||||
ManagedObjectReference morTask = _context.getService().createVirtualDisk_Task(_mor, name, morDc, diskSpec);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(!result.equals("sucess"))
|
||||
throw new Exception("Unable to create virtual disk " + name
|
||||
|
||||
ManagedObjectReference morTask = _context.getService().copyVirtualDiskTask(_mor, srcName, morSrcDc, destName, morDestDc, diskSpec, force);
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(!result)
|
||||
throw new Exception("Unable to copy virtual disk " + srcName + " to " + destName
|
||||
+ " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
}
|
||||
|
||||
|
||||
public void createVirtualDisk(String name, ManagedObjectReference morDc, VirtualDiskSpec diskSpec) throws Exception {
|
||||
ManagedObjectReference morTask = _context.getService().createVirtualDiskTask(_mor, name, morDc, diskSpec);
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(!result)
|
||||
throw new Exception("Unable to create virtual disk " + name
|
||||
+ " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
}
|
||||
|
||||
public void defragmentVirtualDisk(String name, ManagedObjectReference morDc) throws Exception {
|
||||
ManagedObjectReference morTask = _context.getService().defragmentVirtualDisk_Task(_mor, name, morDc);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(!result.equals("sucess"))
|
||||
ManagedObjectReference morTask = _context.getService().defragmentVirtualDiskTask(_mor, name, morDc);
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(!result)
|
||||
throw new Exception("Unable to defragment virtual disk " + name + " due to " + result);
|
||||
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
}
|
||||
|
||||
|
||||
public void deleteVirtualDisk(String name, ManagedObjectReference morDc) throws Exception {
|
||||
ManagedObjectReference morTask = _context.getService().deleteVirtualDisk_Task(_mor, name, morDc);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(!result.equals("sucess"))
|
||||
ManagedObjectReference morTask = _context.getService().deleteVirtualDiskTask(_mor, name, morDc);
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(!result)
|
||||
throw new Exception("Unable to delete virtual disk " + name + " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
}
|
||||
|
||||
|
||||
public void eagerZeroVirtualDisk(String name, ManagedObjectReference morDc) throws Exception {
|
||||
ManagedObjectReference morTask = _context.getService().eagerZeroVirtualDisk_Task(_mor, name, morDc);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(!result.equals("sucess"))
|
||||
ManagedObjectReference morTask = _context.getService().eagerZeroVirtualDiskTask(_mor, name, morDc);
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(!result)
|
||||
throw new Exception("Unable to eager zero virtual disk " + name + " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
}
|
||||
|
||||
|
||||
public void extendVirtualDisk(String name, ManagedObjectReference morDc, long newCapacityKb, boolean eagerZero) throws Exception {
|
||||
ManagedObjectReference morTask = _context.getService().extendVirtualDisk_Task(_mor, name, morDc, newCapacityKb, eagerZero);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(!result.equals("sucess"))
|
||||
ManagedObjectReference morTask = _context.getService().extendVirtualDiskTask(_mor, name, morDc, newCapacityKb, eagerZero);
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(!result)
|
||||
throw new Exception("Unable to extend virtual disk " + name + " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
}
|
||||
|
||||
|
||||
public void inflateVirtualDisk(String name, ManagedObjectReference morDc) throws Exception {
|
||||
ManagedObjectReference morTask = _context.getService().inflateVirtualDisk_Task(_mor, name, morDc);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(!result.equals("sucess"))
|
||||
ManagedObjectReference morTask = _context.getService().inflateVirtualDiskTask(_mor, name, morDc);
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(!result)
|
||||
throw new Exception("Unable to inflate virtual disk " + name + " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
}
|
||||
|
||||
|
||||
public void shrinkVirtualDisk(String name, ManagedObjectReference morDc, boolean copy) throws Exception {
|
||||
ManagedObjectReference morTask = _context.getService().shrinkVirtualDisk_Task(_mor, name, morDc, copy);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(!result.equals("sucess"))
|
||||
ManagedObjectReference morTask = _context.getService().shrinkVirtualDiskTask(_mor, name, morDc, copy);
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(!result)
|
||||
throw new Exception("Unable to shrink virtual disk " + name + " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
}
|
||||
|
||||
|
||||
public void zeroFillVirtualDisk(String name, ManagedObjectReference morDc) throws Exception {
|
||||
ManagedObjectReference morTask = _context.getService().zeroFillVirtualDisk_Task(_mor, name, morDc);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(!result.equals("sucess"))
|
||||
ManagedObjectReference morTask = _context.getService().zeroFillVirtualDiskTask(_mor, name, morDc);
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(!result)
|
||||
throw new Exception("Unable to zero fill virtual disk " + name + " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
}
|
||||
|
||||
|
||||
public void moveVirtualDisk(String srcName, ManagedObjectReference morSrcDc,
|
||||
String destName, ManagedObjectReference morDestDc, boolean force) throws Exception {
|
||||
|
||||
ManagedObjectReference morTask = _context.getService().moveVirtualDisk_Task(_mor, srcName, morSrcDc,
|
||||
|
||||
ManagedObjectReference morTask = _context.getService().moveVirtualDiskTask(_mor, srcName, morSrcDc,
|
||||
destName, morDestDc, force);
|
||||
|
||||
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||
if(!result.equals("sucess"))
|
||||
throw new Exception("Unable to move virtual disk " + srcName + " to " + destName
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
if(!result)
|
||||
throw new Exception("Unable to move virtual disk " + srcName + " to " + destName
|
||||
+ " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
}
|
||||
|
||||
|
||||
public int queryVirtualDiskFragmentation(String name, ManagedObjectReference morDc) throws Exception {
|
||||
return _context.getService().queryVirtualDiskFragmentation(_mor, name, morDc);
|
||||
}
|
||||
|
||||
|
||||
public HostDiskDimensionsChs queryVirtualDiskGeometry(String name, ManagedObjectReference morDc) throws Exception {
|
||||
return _context.getService().queryVirtualDiskGeometry(_mor, name, morDc);
|
||||
}
|
||||
|
||||
|
||||
public String queryVirtualDiskUuid(String name, ManagedObjectReference morDc) throws Exception {
|
||||
return _context.getService().queryVirtualDiskUuid(_mor, name, morDc);
|
||||
}
|
||||
|
||||
|
||||
public void setVirtualDiskUuid(String name, ManagedObjectReference morDc, String uuid) throws Exception {
|
||||
_context.getService().setVirtualDiskUuid(_mor, name, morDc, uuid);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,558 @@
|
|||
// 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.util;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.xml.ws.BindingProvider;
|
||||
|
||||
import com.vmware.vim25.DynamicProperty;
|
||||
import com.vmware.vim25.InvalidCollectorVersionFaultMsg;
|
||||
import com.vmware.vim25.InvalidPropertyFaultMsg;
|
||||
import com.vmware.vim25.LocalizedMethodFault;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
import com.vmware.vim25.ObjectSpec;
|
||||
import com.vmware.vim25.ObjectUpdate;
|
||||
import com.vmware.vim25.ObjectUpdateKind;
|
||||
import com.vmware.vim25.PropertyChange;
|
||||
import com.vmware.vim25.PropertyChangeOp;
|
||||
import com.vmware.vim25.PropertyFilterSpec;
|
||||
import com.vmware.vim25.PropertyFilterUpdate;
|
||||
import com.vmware.vim25.PropertySpec;
|
||||
import com.vmware.vim25.RuntimeFaultFaultMsg;
|
||||
import com.vmware.vim25.SelectionSpec;
|
||||
import com.vmware.vim25.ServiceContent;
|
||||
import com.vmware.vim25.TaskInfoState;
|
||||
import com.vmware.vim25.TraversalSpec;
|
||||
import com.vmware.vim25.UpdateSet;
|
||||
import com.vmware.vim25.VimPortType;
|
||||
import com.vmware.vim25.VimService;
|
||||
import com.vmware.vim25.ObjectContent;
|
||||
|
||||
/**
|
||||
* A wrapper class to handle Vmware vsphere connection and disconnection.
|
||||
*
|
||||
* DISCLAIMER: This code is partly copied from sample codes that come along with Vmware web service 5.1 SDK.
|
||||
*
|
||||
*/
|
||||
public class VmwareClient {
|
||||
|
||||
private static class TrustAllTrustManager implements javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager {
|
||||
|
||||
@Override
|
||||
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) throws java.security.cert.CertificateException {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) throws java.security.cert.CertificateException {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static void trustAllHttpsCertificates() throws Exception {
|
||||
// Create a trust manager that does not validate certificate chains:
|
||||
javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1];
|
||||
javax.net.ssl.TrustManager tm = new TrustAllTrustManager();
|
||||
trustAllCerts[0] = tm;
|
||||
javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL");
|
||||
javax.net.ssl.SSLSessionContext sslsc = sc.getServerSessionContext();
|
||||
sslsc.setSessionTimeout(0);
|
||||
sc.init(null, trustAllCerts, null);
|
||||
javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
}
|
||||
|
||||
private ManagedObjectReference SVC_INST_REF = new ManagedObjectReference();
|
||||
private ManagedObjectReference propCollectorRef;
|
||||
private ManagedObjectReference rootRef;
|
||||
private VimService vimService;
|
||||
private VimPortType vimPort;
|
||||
private ServiceContent serviceContent;
|
||||
private final String SVC_INST_NAME = "ServiceInstance";
|
||||
|
||||
private boolean isConnected = false;
|
||||
|
||||
public VmwareClient(String name) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes session with the virtual center server.
|
||||
*
|
||||
* @throws Exception
|
||||
* the exception
|
||||
*/
|
||||
public void connect(String url, String userName, String password) throws Exception {
|
||||
|
||||
HostnameVerifier hv = new HostnameVerifier() {
|
||||
@Override
|
||||
public boolean verify(String urlHostName, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
trustAllHttpsCertificates();
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(hv);
|
||||
|
||||
SVC_INST_REF.setType(SVC_INST_NAME);
|
||||
SVC_INST_REF.setValue(SVC_INST_NAME);
|
||||
|
||||
vimService = new VimService();
|
||||
vimPort = vimService.getVimPort();
|
||||
Map<String, Object> ctxt = ((BindingProvider) vimPort).getRequestContext();
|
||||
|
||||
ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
|
||||
ctxt.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
|
||||
|
||||
ctxt.put("com.sun.xml.internal.ws.request.timeout", 600000);
|
||||
ctxt.put("com.sun.xml.internal.ws.connect.timeout", 600000);
|
||||
|
||||
serviceContent = vimPort.retrieveServiceContent(SVC_INST_REF);
|
||||
vimPort.login(serviceContent.getSessionManager(), userName, password, null);
|
||||
isConnected = true;
|
||||
|
||||
propCollectorRef = serviceContent.getPropertyCollector();
|
||||
rootRef = serviceContent.getRootFolder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects the user session.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void disconnect() throws Exception {
|
||||
if (isConnected) {
|
||||
vimPort.logout(serviceContent.getSessionManager());
|
||||
}
|
||||
isConnected = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Service instance
|
||||
*/
|
||||
public VimPortType getService() {
|
||||
return vimPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Service instance content
|
||||
*/
|
||||
public ServiceContent getServiceContent() {
|
||||
return serviceContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Service property collector
|
||||
*/
|
||||
public ManagedObjectReference getPropCol() {
|
||||
return propCollectorRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Root folder
|
||||
*/
|
||||
public ManagedObjectReference getRootFolder() {
|
||||
return rootRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the property value of a managed object.
|
||||
*
|
||||
* @param mor
|
||||
* managed object reference
|
||||
* @param propertyName
|
||||
* property name.
|
||||
* @return property value.
|
||||
* @throws Exception
|
||||
* in case of error.
|
||||
*/
|
||||
public Object getDynamicProperty(ManagedObjectReference mor, String propertyName) throws Exception {
|
||||
List<String> props = new ArrayList<String>();
|
||||
props.add(propertyName);
|
||||
List<ObjectContent> objContent = this.retrieveMoRefProperties(mor, props);
|
||||
|
||||
Object propertyValue = null;
|
||||
if (objContent != null && objContent.size() > 0) {
|
||||
List<DynamicProperty> dynamicProperty = objContent.get(0).getPropSet();
|
||||
if (dynamicProperty != null && dynamicProperty.size() > 0) {
|
||||
DynamicProperty dp = dynamicProperty.get(0);
|
||||
propertyValue = dp.getVal();
|
||||
/*
|
||||
* If object is ArrayOfXXX object, then get the XXX[] by
|
||||
* invoking getXXX() on the object.
|
||||
* For Ex:
|
||||
* ArrayOfManagedObjectReference.getManagedObjectReference()
|
||||
* returns ManagedObjectReference[] array.
|
||||
*/
|
||||
Class dpCls = propertyValue.getClass();
|
||||
String dynamicPropertyName = dpCls.getName();
|
||||
if (dynamicPropertyName.indexOf("ArrayOf") != -1) {
|
||||
String methodName = "get"
|
||||
+ dynamicPropertyName
|
||||
.substring(dynamicPropertyName.indexOf("ArrayOf") + "ArrayOf".length(), dynamicPropertyName.length());
|
||||
|
||||
Method getMorMethod = dpCls.getDeclaredMethod(methodName, null);
|
||||
propertyValue = getMorMethod.invoke(propertyValue, (Object[]) null);
|
||||
}
|
||||
}
|
||||
}
|
||||
return propertyValue;
|
||||
}
|
||||
|
||||
private List<ObjectContent> retrieveMoRefProperties(ManagedObjectReference mObj, List<String> props) throws Exception {
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec.setAll(false);
|
||||
pSpec.setType(mObj.getType());
|
||||
pSpec.getPathSet().addAll(props);
|
||||
|
||||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec.setObj(mObj);
|
||||
oSpec.setSkip(false);
|
||||
PropertyFilterSpec spec = new PropertyFilterSpec();
|
||||
spec.getPropSet().add(pSpec);
|
||||
spec.getObjectSet().add(oSpec);
|
||||
List<PropertyFilterSpec> specArr = new ArrayList<PropertyFilterSpec>();
|
||||
specArr.add(spec);
|
||||
|
||||
return vimPort.retrieveProperties(propCollectorRef, specArr);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a boolean value specifying whether the Task is
|
||||
* succeeded or failed.
|
||||
*
|
||||
* @param task
|
||||
* ManagedObjectReference representing the Task.
|
||||
*
|
||||
* @return boolean value representing the Task result.
|
||||
* @throws InvalidCollectorVersionFaultMsg
|
||||
* @throws RuntimeFaultFaultMsg
|
||||
* @throws InvalidPropertyFaultMsg
|
||||
*/
|
||||
public boolean waitForTask(ManagedObjectReference task) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, InvalidCollectorVersionFaultMsg {
|
||||
|
||||
boolean retVal = false;
|
||||
|
||||
// info has a property - state for state of the task
|
||||
Object[] result = waitForValues(task, new String[] { "info.state", "info.error" }, new String[] { "state" }, new Object[][] { new Object[] {
|
||||
TaskInfoState.SUCCESS, TaskInfoState.ERROR } });
|
||||
|
||||
if (result[0].equals(TaskInfoState.SUCCESS)) {
|
||||
retVal = true;
|
||||
}
|
||||
if (result[1] instanceof LocalizedMethodFault) {
|
||||
throw new RuntimeException(((LocalizedMethodFault) result[1]).getLocalizedMessage());
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Updates for a single object. waits till expected values of
|
||||
* properties to check are reached Destroys the ObjectFilter when done.
|
||||
*
|
||||
* @param objmor
|
||||
* MOR of the Object to wait for
|
||||
* @param filterProps
|
||||
* Properties list to filter
|
||||
* @param endWaitProps
|
||||
* Properties list to check for expected values these be
|
||||
* properties of a property in the filter properties list
|
||||
* @param expectedVals
|
||||
* values for properties to end the wait
|
||||
* @return true indicating expected values were met, and false otherwise
|
||||
* @throws RuntimeFaultFaultMsg
|
||||
* @throws InvalidPropertyFaultMsg
|
||||
* @throws InvalidCollectorVersionFaultMsg
|
||||
*/
|
||||
private Object[] waitForValues(ManagedObjectReference objmor, String[] filterProps, String[] endWaitProps, Object[][] expectedVals)
|
||||
throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, InvalidCollectorVersionFaultMsg {
|
||||
// version string is initially null
|
||||
String version = "";
|
||||
Object[] endVals = new Object[endWaitProps.length];
|
||||
Object[] filterVals = new Object[filterProps.length];
|
||||
|
||||
PropertyFilterSpec spec = new PropertyFilterSpec();
|
||||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec.setObj(objmor);
|
||||
oSpec.setSkip(Boolean.FALSE);
|
||||
spec.getObjectSet().add(oSpec);
|
||||
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec.getPathSet().addAll(Arrays.asList(filterProps));
|
||||
pSpec.setType(objmor.getType());
|
||||
spec.getPropSet().add(pSpec);
|
||||
|
||||
ManagedObjectReference filterSpecRef = vimPort.createFilter(propCollectorRef, spec, true);
|
||||
|
||||
boolean reached = false;
|
||||
|
||||
UpdateSet updateset = null;
|
||||
List<PropertyFilterUpdate> filtupary = null;
|
||||
List<ObjectUpdate> objupary = null;
|
||||
List<PropertyChange> propchgary = null;
|
||||
while (!reached) {
|
||||
updateset = vimPort.waitForUpdates(propCollectorRef, version);
|
||||
if (updateset == null || updateset.getFilterSet() == null) {
|
||||
continue;
|
||||
}
|
||||
version = updateset.getVersion();
|
||||
|
||||
// Make this code more general purpose when PropCol changes later.
|
||||
filtupary = updateset.getFilterSet();
|
||||
|
||||
for (PropertyFilterUpdate filtup : filtupary) {
|
||||
objupary = filtup.getObjectSet();
|
||||
for (ObjectUpdate objup : objupary) {
|
||||
// TODO: Handle all "kind"s of updates.
|
||||
if (objup.getKind() == ObjectUpdateKind.MODIFY || objup.getKind() == ObjectUpdateKind.ENTER
|
||||
|| objup.getKind() == ObjectUpdateKind.LEAVE) {
|
||||
propchgary = objup.getChangeSet();
|
||||
for (PropertyChange propchg : propchgary) {
|
||||
updateValues(endWaitProps, endVals, propchg);
|
||||
updateValues(filterProps, filterVals, propchg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Object expctdval = null;
|
||||
// Check if the expected values have been reached and exit the loop
|
||||
// if done.
|
||||
// Also exit the WaitForUpdates loop if this is the case.
|
||||
for (int chgi = 0; chgi < endVals.length && !reached; chgi++) {
|
||||
for (int vali = 0; vali < expectedVals[chgi].length && !reached; vali++) {
|
||||
expctdval = expectedVals[chgi][vali];
|
||||
|
||||
reached = expctdval.equals(endVals[chgi]) || reached;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy the filter when we are done.
|
||||
vimPort.destroyPropertyFilter(filterSpecRef);
|
||||
return filterVals;
|
||||
}
|
||||
|
||||
private void updateValues(String[] props, Object[] vals, PropertyChange propchg) {
|
||||
for (int findi = 0; findi < props.length; findi++) {
|
||||
if (propchg.getName().lastIndexOf(props[findi]) >= 0) {
|
||||
if (propchg.getOp() == PropertyChangeOp.REMOVE) {
|
||||
vals[findi] = "";
|
||||
} else {
|
||||
vals[findi] = propchg.getVal();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SelectionSpec getSelectionSpec(String name) {
|
||||
SelectionSpec genericSpec = new SelectionSpec();
|
||||
genericSpec.setName(name);
|
||||
return genericSpec;
|
||||
}
|
||||
|
||||
/*
|
||||
* @return An array of SelectionSpec covering VM, Host, Resource pool,
|
||||
* Cluster Compute Resource and Datastore.
|
||||
*/
|
||||
private List<SelectionSpec> constructCompleteTraversalSpec() {
|
||||
// ResourcePools to VM: RP -> VM
|
||||
TraversalSpec rpToVm = new TraversalSpec();
|
||||
rpToVm.setName("rpToVm");
|
||||
rpToVm.setType("ResourcePool");
|
||||
rpToVm.setPath("vm");
|
||||
rpToVm.setSkip(Boolean.FALSE);
|
||||
|
||||
// VirtualApp to VM: vApp -> VM
|
||||
TraversalSpec vAppToVM = new TraversalSpec();
|
||||
vAppToVM.setName("vAppToVM");
|
||||
vAppToVM.setType("VirtualApp");
|
||||
vAppToVM.setPath("vm");
|
||||
|
||||
// Host to VM: HostSystem -> VM
|
||||
TraversalSpec hToVm = new TraversalSpec();
|
||||
hToVm.setType("HostSystem");
|
||||
hToVm.setPath("vm");
|
||||
hToVm.setName("hToVm");
|
||||
hToVm.getSelectSet().add(getSelectionSpec("VisitFolders"));
|
||||
hToVm.setSkip(Boolean.FALSE);
|
||||
|
||||
// DataCenter to DataStore: DC -> DS
|
||||
TraversalSpec dcToDs = new TraversalSpec();
|
||||
dcToDs.setType("Datacenter");
|
||||
dcToDs.setPath("datastore");
|
||||
dcToDs.setName("dcToDs");
|
||||
dcToDs.setSkip(Boolean.FALSE);
|
||||
|
||||
// Recurse through all ResourcePools
|
||||
TraversalSpec rpToRp = new TraversalSpec();
|
||||
rpToRp.setType("ResourcePool");
|
||||
rpToRp.setPath("resourcePool");
|
||||
rpToRp.setSkip(Boolean.FALSE);
|
||||
rpToRp.setName("rpToRp");
|
||||
rpToRp.getSelectSet().add(getSelectionSpec("rpToRp"));
|
||||
|
||||
TraversalSpec crToRp = new TraversalSpec();
|
||||
crToRp.setType("ComputeResource");
|
||||
crToRp.setPath("resourcePool");
|
||||
crToRp.setSkip(Boolean.FALSE);
|
||||
crToRp.setName("crToRp");
|
||||
crToRp.getSelectSet().add(getSelectionSpec("rpToRp"));
|
||||
|
||||
TraversalSpec crToH = new TraversalSpec();
|
||||
crToH.setSkip(Boolean.FALSE);
|
||||
crToH.setType("ComputeResource");
|
||||
crToH.setPath("host");
|
||||
crToH.setName("crToH");
|
||||
|
||||
TraversalSpec dcToHf = new TraversalSpec();
|
||||
dcToHf.setSkip(Boolean.FALSE);
|
||||
dcToHf.setType("Datacenter");
|
||||
dcToHf.setPath("hostFolder");
|
||||
dcToHf.setName("dcToHf");
|
||||
dcToHf.getSelectSet().add(getSelectionSpec("VisitFolders"));
|
||||
|
||||
TraversalSpec vAppToRp = new TraversalSpec();
|
||||
vAppToRp.setName("vAppToRp");
|
||||
vAppToRp.setType("VirtualApp");
|
||||
vAppToRp.setPath("resourcePool");
|
||||
vAppToRp.getSelectSet().add(getSelectionSpec("rpToRp"));
|
||||
|
||||
TraversalSpec dcToVmf = new TraversalSpec();
|
||||
dcToVmf.setType("Datacenter");
|
||||
dcToVmf.setSkip(Boolean.FALSE);
|
||||
dcToVmf.setPath("vmFolder");
|
||||
dcToVmf.setName("dcToVmf");
|
||||
dcToVmf.getSelectSet().add(getSelectionSpec("VisitFolders"));
|
||||
|
||||
// For Folder -> Folder recursion
|
||||
TraversalSpec visitFolders = new TraversalSpec();
|
||||
visitFolders.setType("Folder");
|
||||
visitFolders.setPath("childEntity");
|
||||
visitFolders.setSkip(Boolean.FALSE);
|
||||
visitFolders.setName("VisitFolders");
|
||||
List<SelectionSpec> sspecarrvf = new ArrayList<SelectionSpec>();
|
||||
sspecarrvf.add(getSelectionSpec("crToRp"));
|
||||
sspecarrvf.add(getSelectionSpec("crToH"));
|
||||
sspecarrvf.add(getSelectionSpec("dcToVmf"));
|
||||
sspecarrvf.add(getSelectionSpec("dcToHf"));
|
||||
sspecarrvf.add(getSelectionSpec("vAppToRp"));
|
||||
sspecarrvf.add(getSelectionSpec("vAppToVM"));
|
||||
sspecarrvf.add(getSelectionSpec("dcToDs"));
|
||||
sspecarrvf.add(getSelectionSpec("hToVm"));
|
||||
sspecarrvf.add(getSelectionSpec("rpToVm"));
|
||||
sspecarrvf.add(getSelectionSpec("VisitFolders"));
|
||||
|
||||
visitFolders.getSelectSet().addAll(sspecarrvf);
|
||||
|
||||
List<SelectionSpec> resultspec = new ArrayList<SelectionSpec>();
|
||||
resultspec.add(visitFolders);
|
||||
resultspec.add(crToRp);
|
||||
resultspec.add(crToH);
|
||||
resultspec.add(dcToVmf);
|
||||
resultspec.add(dcToHf);
|
||||
resultspec.add(vAppToRp);
|
||||
resultspec.add(vAppToVM);
|
||||
resultspec.add(dcToDs);
|
||||
resultspec.add(hToVm);
|
||||
resultspec.add(rpToVm);
|
||||
resultspec.add(rpToRp);
|
||||
|
||||
return resultspec;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the ManagedObjectReference for an item under the
|
||||
* specified root folder that has the type and name specified.
|
||||
*
|
||||
* @param root a root folder if available, or null for default
|
||||
* @param type type of the managed object
|
||||
* @param name name to match
|
||||
*
|
||||
* @return First ManagedObjectReference of the type / name pair found
|
||||
*/
|
||||
public ManagedObjectReference getDecendentMoRef(ManagedObjectReference root, String type, String name) throws Exception {
|
||||
if (name == null || name.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create PropertySpecs
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec.setType(type);
|
||||
pSpec.setAll(false);
|
||||
pSpec.getPathSet().add(name);
|
||||
|
||||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec.setObj(root);
|
||||
oSpec.setSkip(false);
|
||||
oSpec.getSelectSet().addAll(constructCompleteTraversalSpec());
|
||||
|
||||
PropertyFilterSpec spec = new PropertyFilterSpec();
|
||||
spec.getPropSet().add(pSpec);
|
||||
spec.getObjectSet().add(oSpec);
|
||||
List<PropertyFilterSpec> specArr = new ArrayList<PropertyFilterSpec>();
|
||||
specArr.add(spec);
|
||||
|
||||
List<ObjectContent> ocary = vimPort.retrieveProperties(propCollectorRef, specArr);
|
||||
|
||||
if (ocary == null || ocary.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// filter through retrieved objects to get the first match.
|
||||
for (ObjectContent oc : ocary) {
|
||||
ManagedObjectReference mor = oc.getObj();
|
||||
List<DynamicProperty> propary = oc.getPropSet();
|
||||
if (type == null || type.equals(mor.getType())) {
|
||||
if (propary.size() > 0) {
|
||||
String propval = (String) propary.get(0).getVal();
|
||||
if (propval != null && name.equals(propval))
|
||||
return mor;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a MORef from the property returned.
|
||||
*
|
||||
* @param objMor Object to get a reference property from
|
||||
* @param propName name of the property that is the MORef
|
||||
* @return the ManagedObjectReference for that property.
|
||||
*/
|
||||
public ManagedObjectReference getMoRefProp(ManagedObjectReference objMor, String propName) throws Exception {
|
||||
Object props = getDynamicProperty(objMor, propName);
|
||||
ManagedObjectReference propmor = null;
|
||||
if (!props.getClass().isArray()) {
|
||||
propmor = (ManagedObjectReference)props;
|
||||
}
|
||||
return propmor;
|
||||
}
|
||||
}
|
||||
|
|
@ -26,7 +26,6 @@ import java.io.FileOutputStream;
|
|||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.ConnectException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
|
|
@ -38,21 +37,20 @@ import java.util.Map;
|
|||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.xml.ws.BindingProvider;
|
||||
import com.sun.xml.internal.ws.transport.http.client.CookieJar;
|
||||
import com.sun.xml.internal.ws.client.BindingProviderProperties;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.hypervisor.vmware.mo.DatacenterMO;
|
||||
import com.cloud.hypervisor.vmware.mo.DatastoreFile;
|
||||
import com.cloud.utils.ActionDelegate;
|
||||
import com.vmware.apputils.version.ExtendedAppUtil;
|
||||
import com.vmware.apputils.vim25.ServiceConnection;
|
||||
import com.vmware.apputils.vim25.ServiceUtil;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
import com.vmware.vim25.ObjectContent;
|
||||
import com.vmware.vim25.ObjectSpec;
|
||||
import com.vmware.vim25.PropertyFilterSpec;
|
||||
import com.vmware.vim25.PropertySpec;
|
||||
import com.vmware.vim25.SelectionSpec;
|
||||
import com.vmware.vim25.ServiceContent;
|
||||
import com.vmware.vim25.TaskInfo;
|
||||
import com.vmware.vim25.TraversalSpec;
|
||||
|
|
@ -63,30 +61,30 @@ public class VmwareContext {
|
|||
|
||||
private static int MAX_CONNECT_RETRY = 5;
|
||||
private static int CONNECT_RETRY_INTERVAL = 1000;
|
||||
|
||||
private ExtendedAppUtil _appUtil;
|
||||
|
||||
private VmwareClient _vimClient;
|
||||
private String _serverAddress;
|
||||
|
||||
|
||||
private Map<String, Object> _stockMap = new HashMap<String, Object>();
|
||||
private int _CHUNKSIZE = 1*1024*1024; // 1M
|
||||
|
||||
|
||||
static {
|
||||
try {
|
||||
javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1];
|
||||
javax.net.ssl.TrustManager tm = new TrustAllManager();
|
||||
trustAllCerts[0] = tm;
|
||||
javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL");
|
||||
sc.init(null, trustAllCerts, null);
|
||||
javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1];
|
||||
javax.net.ssl.TrustManager tm = new TrustAllManager();
|
||||
trustAllCerts[0] = tm;
|
||||
javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL");
|
||||
sc.init(null, trustAllCerts, null);
|
||||
javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Unexpected exception ", e);
|
||||
}
|
||||
}
|
||||
|
||||
public VmwareContext(ExtendedAppUtil appUtil, String address) {
|
||||
assert(appUtil != null) : "Invalid parameter in constructing VmwareContext object";
|
||||
|
||||
_appUtil = appUtil;
|
||||
|
||||
public VmwareContext(VmwareClient client, String address) {
|
||||
assert(client != null) : "Invalid parameter in constructing VmwareContext object";
|
||||
|
||||
_vimClient = client;
|
||||
_serverAddress = address;
|
||||
}
|
||||
|
||||
|
|
@ -95,132 +93,136 @@ public class VmwareContext {
|
|||
_stockMap.put(name, obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void uregisterStockObject(String name) {
|
||||
synchronized(_stockMap) {
|
||||
_stockMap.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getStockObject(String name) {
|
||||
synchronized(_stockMap) {
|
||||
return (T)_stockMap.get(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getServerAddress() {
|
||||
return _serverAddress;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public ServiceConnection getServiceConnection() {
|
||||
return _appUtil.getServiceConnection3();
|
||||
return _vimClient.getServiceConnection3();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
public VimPortType getService() {
|
||||
return getServiceConnection().getService();
|
||||
return _vimClient.getService();
|
||||
}
|
||||
|
||||
|
||||
public ServiceContent getServiceContent() {
|
||||
return getServiceConnection().getServiceContent();
|
||||
return _vimClient.getServiceContent();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public ServiceUtil getServiceUtil() {
|
||||
return _appUtil.getServiceUtil3();
|
||||
return _vimClient.getServiceUtil3();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
public ManagedObjectReference getPropertyCollector(){
|
||||
return _vimClient.getPropCol();
|
||||
}
|
||||
|
||||
public ManagedObjectReference getRootFolder() {
|
||||
return getServiceContent().getRootFolder();
|
||||
return _vimClient.getRootFolder();
|
||||
}
|
||||
|
||||
|
||||
public VmwareClient getVimClient(){
|
||||
return _vimClient;
|
||||
}
|
||||
|
||||
|
||||
public ManagedObjectReference getHostMorByPath(String inventoryPath) throws Exception {
|
||||
assert(inventoryPath != null);
|
||||
|
||||
|
||||
String[] tokens;
|
||||
if(inventoryPath.startsWith("/"))
|
||||
tokens = inventoryPath.substring(1).split("/");
|
||||
else
|
||||
tokens = inventoryPath.split("/");
|
||||
|
||||
|
||||
ManagedObjectReference mor = getRootFolder();
|
||||
for(int i=0; i < tokens.length;i++) {
|
||||
String token = tokens[i];
|
||||
ObjectContent[] ocs;
|
||||
List<ObjectContent> ocs;
|
||||
PropertySpec pSpec = null;
|
||||
ObjectSpec oSpec = null;
|
||||
if(mor.getType().equalsIgnoreCase("Datacenter")) {
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec = new PropertySpec();
|
||||
pSpec.setAll(false);
|
||||
pSpec.setType("ManagedEntity");
|
||||
pSpec.setPathSet(new String[] { "name" });
|
||||
|
||||
pSpec.getPathSet().add("name");
|
||||
|
||||
TraversalSpec dcHostFolderTraversal = new TraversalSpec();
|
||||
dcHostFolderTraversal.setType("Datacenter");
|
||||
dcHostFolderTraversal.setPath("hostFolder");
|
||||
dcHostFolderTraversal.setName("dcHostFolderTraversal");
|
||||
|
||||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec = new ObjectSpec();
|
||||
oSpec.setObj(mor);
|
||||
oSpec.setSkip(Boolean.TRUE);
|
||||
oSpec.setSelectSet(new SelectionSpec[] { dcHostFolderTraversal });
|
||||
oSpec.getSelectSet().add(dcHostFolderTraversal);
|
||||
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||
ocs = getService().retrieveProperties(
|
||||
getServiceContent().getPropertyCollector(),
|
||||
new PropertyFilterSpec[] { pfSpec });
|
||||
|
||||
} else if(mor.getType().equalsIgnoreCase("Folder")) {
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec = new PropertySpec();
|
||||
pSpec.setAll(false);
|
||||
pSpec.setType("ManagedEntity");
|
||||
pSpec.setPathSet(new String[] { "name" });
|
||||
|
||||
pSpec.getPathSet().add("name");
|
||||
|
||||
TraversalSpec folderChildrenTraversal = new TraversalSpec();
|
||||
folderChildrenTraversal.setType("Folder");
|
||||
folderChildrenTraversal.setPath("childEntity");
|
||||
folderChildrenTraversal.setName("folderChildrenTraversal");
|
||||
|
||||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec = new ObjectSpec();
|
||||
oSpec.setObj(mor);
|
||||
oSpec.setSkip(Boolean.TRUE);
|
||||
oSpec.setSelectSet(new SelectionSpec[] { folderChildrenTraversal });
|
||||
oSpec.getSelectSet().add(folderChildrenTraversal);
|
||||
|
||||
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||
|
||||
ocs = getService().retrieveProperties(
|
||||
getServiceContent().getPropertyCollector(),
|
||||
new PropertyFilterSpec[] { pfSpec });
|
||||
} else if(mor.getType().equalsIgnoreCase("ClusterComputeResource")) {
|
||||
PropertySpec pSpec = new PropertySpec();
|
||||
pSpec = new PropertySpec();
|
||||
pSpec.setType("ManagedEntity");
|
||||
pSpec.setPathSet(new String[] { "name" });
|
||||
|
||||
pSpec.getPathSet().add("name");
|
||||
|
||||
TraversalSpec clusterHostTraversal = new TraversalSpec();
|
||||
clusterHostTraversal.setType("ClusterComputeResource");
|
||||
clusterHostTraversal.setPath("host");
|
||||
clusterHostTraversal.setName("folderChildrenTraversal");
|
||||
|
||||
ObjectSpec oSpec = new ObjectSpec();
|
||||
oSpec = new ObjectSpec();
|
||||
oSpec.setObj(mor);
|
||||
oSpec.setSkip(Boolean.TRUE);
|
||||
oSpec.setSelectSet(new SelectionSpec[] { clusterHostTraversal });
|
||||
oSpec.getSelectSet().add(clusterHostTraversal);
|
||||
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||
|
||||
ocs = getService().retrieveProperties(
|
||||
getServiceContent().getPropertyCollector(),
|
||||
new PropertyFilterSpec[] { pfSpec });
|
||||
} else {
|
||||
s_logger.error("Invalid inventory path, path element can only be datacenter and folder");
|
||||
return null;
|
||||
}
|
||||
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
|
||||
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||
pfSpec.getPropSet().add(pSpec);
|
||||
pfSpec.getObjectSet().add(oSpec);
|
||||
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
|
||||
pfSpecArr.add(pfSpec);
|
||||
ocs = getService().retrieveProperties(getPropertyCollector(), pfSpecArr);
|
||||
|
||||
if(ocs != null && ocs.size() > 0) {
|
||||
boolean found = false;
|
||||
for(ObjectContent oc : ocs) {
|
||||
String name = oc.getPropSet()[0].getVal().toString();
|
||||
String name = oc.getPropSet().get(0).getVal().toString();
|
||||
if(name.equalsIgnoreCase(token) || name.equalsIgnoreCase("host")) {
|
||||
mor = oc.getObj();
|
||||
found = true;
|
||||
|
|
@ -244,44 +246,44 @@ public class VmwareContext {
|
|||
// path in format of <datacenter name>/<datastore name>
|
||||
public ManagedObjectReference getDatastoreMorByPath(String inventoryPath) throws Exception {
|
||||
assert(inventoryPath != null);
|
||||
|
||||
|
||||
String[] tokens;
|
||||
if(inventoryPath.startsWith("/"))
|
||||
tokens = inventoryPath.substring(1).split("/");
|
||||
else
|
||||
tokens = inventoryPath.split("/");
|
||||
|
||||
|
||||
if(tokens == null || tokens.length != 2) {
|
||||
s_logger.error("Invalid datastore inventory path. path: " + inventoryPath);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
DatacenterMO dcMo = new DatacenterMO(this, tokens[0]);
|
||||
if(dcMo.getMor() == null) {
|
||||
s_logger.error("Unable to locate the datacenter specified in path: " + inventoryPath);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return dcMo.findDatastore(tokens[1]);
|
||||
}
|
||||
|
||||
|
||||
public void waitForTaskProgressDone(ManagedObjectReference morTask) throws Exception {
|
||||
while(true) {
|
||||
TaskInfo tinfo = (TaskInfo)getServiceUtil().getDynamicProperty(morTask, "info");
|
||||
TaskInfo tinfo = (TaskInfo)_vimClient.getDynamicProperty(morTask, "info");
|
||||
Integer progress = tinfo.getProgress();
|
||||
if(progress == null)
|
||||
break;
|
||||
|
||||
|
||||
if(progress.intValue() >= 100)
|
||||
break;
|
||||
|
||||
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void getFile(String urlString, String localFileFullName) throws Exception {
|
||||
HttpURLConnection conn = getHTTPConnection(urlString);
|
||||
|
||||
|
||||
InputStream in = conn.getInputStream();
|
||||
OutputStream out = new FileOutputStream(new File(localFileFullName));
|
||||
byte[] buf = new byte[_CHUNKSIZE];
|
||||
|
|
@ -290,19 +292,19 @@ public class VmwareContext {
|
|||
out.write(buf, 0, len);
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
out.close();
|
||||
}
|
||||
|
||||
|
||||
public void uploadFile(String urlString, String localFileFullName) throws Exception {
|
||||
uploadFile(urlString, new File(localFileFullName));
|
||||
}
|
||||
|
||||
|
||||
public void uploadFile(String urlString, File localFile) throws Exception {
|
||||
HttpURLConnection conn = getHTTPConnection(urlString, "PUT");
|
||||
OutputStream out = null;
|
||||
InputStream in = null;
|
||||
BufferedReader br = null;
|
||||
|
||||
|
||||
try {
|
||||
out = conn.getOutputStream();
|
||||
in = new FileInputStream(localFile);
|
||||
|
|
@ -312,7 +314,7 @@ public class VmwareContext {
|
|||
out.write(buf, 0, len);
|
||||
}
|
||||
out.flush();
|
||||
|
||||
|
||||
br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
|
|
@ -322,41 +324,41 @@ public class VmwareContext {
|
|||
} finally {
|
||||
if(in != null)
|
||||
in.close();
|
||||
|
||||
|
||||
if(out != null)
|
||||
out.close();
|
||||
|
||||
|
||||
if(br != null)
|
||||
br.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void uploadVmdkFile(String httpMethod, String urlString, String localFileName,
|
||||
|
||||
public void uploadVmdkFile(String httpMethod, String urlString, String localFileName,
|
||||
long totalBytesUpdated, ActionDelegate progressUpdater) throws Exception {
|
||||
|
||||
|
||||
HttpURLConnection conn = getRawHTTPConnection(urlString);
|
||||
|
||||
|
||||
conn.setDoOutput(true);
|
||||
conn.setUseCaches(false);
|
||||
|
||||
conn.setChunkedStreamingMode(_CHUNKSIZE);
|
||||
conn.setRequestMethod(httpMethod);
|
||||
conn.setRequestProperty("Connection", "Keep-Alive");
|
||||
conn.setRequestProperty("Content-Type", "application/x-vnd.vmware-streamVmdk");
|
||||
|
||||
conn.setChunkedStreamingMode(_CHUNKSIZE);
|
||||
conn.setRequestMethod(httpMethod);
|
||||
conn.setRequestProperty("Connection", "Keep-Alive");
|
||||
conn.setRequestProperty("Content-Type", "application/x-vnd.vmware-streamVmdk");
|
||||
conn.setRequestProperty("Content-Length", Long.toString(new File(localFileName).length()));
|
||||
connectWithRetry(conn);
|
||||
|
||||
|
||||
BufferedOutputStream bos = null;
|
||||
BufferedInputStream is = null;
|
||||
try {
|
||||
bos = new BufferedOutputStream(conn.getOutputStream());
|
||||
is = new BufferedInputStream(new FileInputStream(localFileName));
|
||||
int bufferSize = _CHUNKSIZE;
|
||||
byte[] buffer = new byte[bufferSize];
|
||||
while (true) {
|
||||
int bytesRead = is.read(buffer, 0, bufferSize);
|
||||
if (bytesRead == -1) {
|
||||
break;
|
||||
bos = new BufferedOutputStream(conn.getOutputStream());
|
||||
is = new BufferedInputStream(new FileInputStream(localFileName));
|
||||
int bufferSize = _CHUNKSIZE;
|
||||
byte[] buffer = new byte[bufferSize];
|
||||
while (true) {
|
||||
int bytesRead = is.read(buffer, 0, bufferSize);
|
||||
if (bytesRead == -1) {
|
||||
break;
|
||||
}
|
||||
bos.write(buffer, 0, bytesRead);
|
||||
totalBytesUpdated += bytesRead;
|
||||
|
|
@ -370,54 +372,58 @@ public class VmwareContext {
|
|||
is.close();
|
||||
if(bos != null)
|
||||
bos.close();
|
||||
|
||||
|
||||
conn.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
public long downloadVmdkFile(String urlString, String localFileName,
|
||||
|
||||
public long downloadVmdkFile(String urlString, String localFileName,
|
||||
long totalBytesDownloaded, ActionDelegate progressUpdater) throws Exception {
|
||||
HttpURLConnection conn = getRawHTTPConnection(urlString);
|
||||
|
||||
String cookieString = getServiceCookie();
|
||||
conn.setRequestProperty(org.apache.axis.transport.http.HTTPConstants.HEADER_COOKIE, cookieString);
|
||||
|
||||
CookieJar cookie = getServiceCookie();
|
||||
if ( cookie == null ){
|
||||
s_logger.error("No cookie is found in vwware web service request context!");
|
||||
throw new Exception("No cookie is found in vmware web service request context!");
|
||||
}
|
||||
cookie.applyRelevantCookies(conn);
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoOutput(true);
|
||||
conn.setAllowUserInteraction(true);
|
||||
connectWithRetry(conn);
|
||||
|
||||
long bytesWritten = 0;
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
long bytesWritten = 0;
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
try {
|
||||
in = conn.getInputStream();
|
||||
out = new FileOutputStream(new File(localFileName));
|
||||
|
||||
byte[] buf = new byte[_CHUNKSIZE];
|
||||
int len = 0;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
in = conn.getInputStream();
|
||||
out = new FileOutputStream(new File(localFileName));
|
||||
|
||||
byte[] buf = new byte[_CHUNKSIZE];
|
||||
int len = 0;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
bytesWritten += len;
|
||||
totalBytesDownloaded += len;
|
||||
|
||||
|
||||
if(progressUpdater != null)
|
||||
progressUpdater.action(new Long(totalBytesDownloaded));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if(in != null)
|
||||
in.close();
|
||||
if(out != null)
|
||||
out.close();
|
||||
|
||||
|
||||
conn.disconnect();
|
||||
}
|
||||
return bytesWritten;
|
||||
return bytesWritten;
|
||||
}
|
||||
|
||||
|
||||
public byte[] getResourceContent(String urlString) throws Exception {
|
||||
HttpURLConnection conn = getHTTPConnection(urlString);
|
||||
InputStream in = conn.getInputStream();
|
||||
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
byte[] buf = new byte[_CHUNKSIZE];
|
||||
int len = 0;
|
||||
|
|
@ -425,10 +431,10 @@ public class VmwareContext {
|
|||
out.write(buf, 0, len);
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
out.close();
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
public void uploadResourceContent(String urlString, byte[] content) throws Exception {
|
||||
// vSphere does not support POST
|
||||
HttpURLConnection conn = getHTTPConnection(urlString, "PUT");
|
||||
|
|
@ -436,7 +442,7 @@ public class VmwareContext {
|
|||
OutputStream out = conn.getOutputStream();
|
||||
out.write(content);
|
||||
out.flush();
|
||||
|
||||
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
|
|
@ -446,15 +452,15 @@ public class VmwareContext {
|
|||
out.close();
|
||||
in.close();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Sample content returned by query a datastore directory
|
||||
*
|
||||
*
|
||||
* Url for the query
|
||||
* https://vsphere-1.lab.vmops.com/folder/Fedora-clone-test?dcPath=cupertino&dsName=NFS+datastore
|
||||
*
|
||||
* Returned conent from vSphere
|
||||
*
|
||||
*
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
|
|
@ -485,7 +491,7 @@ public class VmwareContext {
|
|||
</table>
|
||||
</body>
|
||||
</html>
|
||||
*/
|
||||
*/
|
||||
public String[] listDatastoreDirContent(String urlString) throws Exception {
|
||||
List<String> fileList = new ArrayList<String>();
|
||||
String content = new String(getResourceContent(urlString));
|
||||
|
|
@ -497,7 +503,7 @@ public class VmwareContext {
|
|||
int beginPos = content.lastIndexOf('>', parsePos -1);
|
||||
if(beginPos < 0)
|
||||
beginPos = 0;
|
||||
|
||||
|
||||
fileList.add((content.substring(beginPos + 1, parsePos)));
|
||||
parsePos += marker.length();
|
||||
} else {
|
||||
|
|
@ -511,11 +517,11 @@ public class VmwareContext {
|
|||
DatastoreFile dsFile = new DatastoreFile(fullPath);
|
||||
return composeDatastoreBrowseUrl(dcName, dsFile.getDatastoreName(), dsFile.getRelativePath());
|
||||
}
|
||||
|
||||
|
||||
public String composeDatastoreBrowseUrl(String dcName, String datastoreName, String relativePath) {
|
||||
assert(relativePath != null);
|
||||
assert(datastoreName != null);
|
||||
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("https://");
|
||||
sb.append(_serverAddress);
|
||||
|
|
@ -525,53 +531,56 @@ public class VmwareContext {
|
|||
sb.append(URLEncoder.encode(datastoreName));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public HttpURLConnection getHTTPConnection(String urlString) throws Exception {
|
||||
return getHTTPConnection(urlString, "GET");
|
||||
}
|
||||
|
||||
|
||||
public HttpURLConnection getHTTPConnection(String urlString, String httpMethod) throws Exception {
|
||||
String cookieString = getServiceCookie();
|
||||
CookieJar cookie = getServiceCookie();
|
||||
if ( cookie == null ){
|
||||
s_logger.error("No cookie is found in vmware web service request context!");
|
||||
throw new Exception("No cookie is found in vmware web service request context!");
|
||||
}
|
||||
HostnameVerifier hv = new HostnameVerifier() {
|
||||
public boolean verify(String urlHostName, SSLSession session) {
|
||||
@Override
|
||||
public boolean verify(String urlHostName, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(hv);
|
||||
URL url = new URL(urlString);
|
||||
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(hv);
|
||||
URL url = new URL(urlString);
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
|
||||
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
conn.setAllowUserInteraction(true);
|
||||
conn.setRequestProperty(org.apache.axis.transport.http.HTTPConstants.HEADER_COOKIE, cookieString);
|
||||
cookie.applyRelevantCookies(conn);
|
||||
conn.setRequestMethod(httpMethod);
|
||||
connectWithRetry(conn);
|
||||
return conn;
|
||||
}
|
||||
|
||||
|
||||
public HttpURLConnection getRawHTTPConnection(String urlString) throws Exception {
|
||||
HostnameVerifier hv = new HostnameVerifier() {
|
||||
public boolean verify(String urlHostName, SSLSession session) {
|
||||
@Override
|
||||
public boolean verify(String urlHostName, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(hv);
|
||||
URL url = new URL(urlString);
|
||||
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(hv);
|
||||
URL url = new URL(urlString);
|
||||
return (HttpURLConnection)url.openConnection();
|
||||
}
|
||||
|
||||
private String getServiceCookie() throws Exception {
|
||||
com.vmware.vim25.VimPortType service = getService();
|
||||
org.apache.axis.client.Stub st = (org.apache.axis.client.Stub)service;
|
||||
org.apache.axis.client.Call callObj = st._getCall();
|
||||
org.apache.axis.MessageContext msgContext = callObj.getMessageContext();
|
||||
String cookieString = (String)msgContext.getProperty(org.apache.axis.transport.http.HTTPConstants.HEADER_COOKIE);
|
||||
return cookieString;
|
||||
private CookieJar getServiceCookie() throws Exception {
|
||||
VimPortType port = getService();
|
||||
Map<String, Object> ctxt = ((BindingProvider) port).getRequestContext();
|
||||
return (CookieJar)ctxt.get(BindingProviderProperties.HTTP_COOKIE_JAR);
|
||||
}
|
||||
|
||||
|
||||
private static void connectWithRetry(HttpURLConnection conn) throws Exception {
|
||||
boolean connected = false;
|
||||
for(int i = 0; i < MAX_CONNECT_RETRY && !connected; i++) {
|
||||
|
|
@ -581,45 +590,48 @@ public class VmwareContext {
|
|||
s_logger.info("Connected, conn: " + conn.toString() + ", retry: " + i);
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to connect, conn: " + conn.toString() + ", message: " + e.toString() + ", retry: " + i);
|
||||
|
||||
|
||||
try {
|
||||
Thread.sleep(CONNECT_RETRY_INTERVAL);
|
||||
} catch(InterruptedException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!connected)
|
||||
throw new Exception("Unable to connect to " + conn.toString());
|
||||
}
|
||||
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
_appUtil.disConnect();
|
||||
_vimClient.disconnect();
|
||||
} catch(Exception e) {
|
||||
s_logger.warn("Unexpected exception: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TrustAllManager implements javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager {
|
||||
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
||||
@Override
|
||||
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public boolean isServerTrusted(java.security.cert.X509Certificate[] certs) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean isClientTrusted(java.security.cert.X509Certificate[] certs) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
|
||||
throws java.security.cert.CertificateException {
|
||||
return;
|
||||
}
|
||||
|
||||
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)
|
||||
|
||||
@Override
|
||||
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)
|
||||
throws java.security.cert.CertificateException {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,146 +24,150 @@ import com.vmware.vim25.VirtualMachineGuestOsIdentifier;
|
|||
public class VmwareGuestOsMapper {
|
||||
private static Map<String, VirtualMachineGuestOsIdentifier> s_mapper = new HashMap<String, VirtualMachineGuestOsIdentifier>();
|
||||
static {
|
||||
s_mapper.put("DOS", VirtualMachineGuestOsIdentifier.dosGuest);
|
||||
s_mapper.put("OS/2", VirtualMachineGuestOsIdentifier.os2Guest);
|
||||
s_mapper.put("DOS", VirtualMachineGuestOsIdentifier.DOS_GUEST);
|
||||
s_mapper.put("OS/2", VirtualMachineGuestOsIdentifier.OS_2_GUEST);
|
||||
|
||||
s_mapper.put("Windows 3.1", VirtualMachineGuestOsIdentifier.win31Guest);
|
||||
s_mapper.put("Windows 95", VirtualMachineGuestOsIdentifier.win95Guest);
|
||||
s_mapper.put("Windows 98", VirtualMachineGuestOsIdentifier.win98Guest);
|
||||
s_mapper.put("Windows NT 4", VirtualMachineGuestOsIdentifier.winNTGuest);
|
||||
s_mapper.put("Windows XP (32-bit)", VirtualMachineGuestOsIdentifier.winXPProGuest);
|
||||
s_mapper.put("Windows XP (64-bit)", VirtualMachineGuestOsIdentifier.winXPPro64Guest);
|
||||
s_mapper.put("Windows XP SP2 (32-bit)", VirtualMachineGuestOsIdentifier.winXPProGuest);
|
||||
s_mapper.put("Windows XP SP3 (32-bit)", VirtualMachineGuestOsIdentifier.winXPProGuest);
|
||||
s_mapper.put("Windows Vista (32-bit)", VirtualMachineGuestOsIdentifier.winVistaGuest);
|
||||
s_mapper.put("Windows Vista (64-bit)", VirtualMachineGuestOsIdentifier.winVista64Guest);
|
||||
s_mapper.put("Windows 7 (32-bit)", VirtualMachineGuestOsIdentifier.windows7Guest);
|
||||
s_mapper.put("Windows 7 (64-bit)", VirtualMachineGuestOsIdentifier.windows7_64Guest);
|
||||
s_mapper.put("Windows 3.1", VirtualMachineGuestOsIdentifier.WIN_31_GUEST);
|
||||
s_mapper.put("Windows 95", VirtualMachineGuestOsIdentifier.WIN_95_GUEST);
|
||||
s_mapper.put("Windows 98", VirtualMachineGuestOsIdentifier.WIN_98_GUEST);
|
||||
s_mapper.put("Windows NT 4", VirtualMachineGuestOsIdentifier.WIN_NT_GUEST);
|
||||
s_mapper.put("Windows XP (32-bit)", VirtualMachineGuestOsIdentifier.WIN_XP_PRO_GUEST);
|
||||
s_mapper.put("Windows XP (64-bit)", VirtualMachineGuestOsIdentifier.WIN_XP_PRO_64_GUEST);
|
||||
s_mapper.put("Windows XP SP2 (32-bit)", VirtualMachineGuestOsIdentifier.WIN_XP_PRO_GUEST);
|
||||
s_mapper.put("Windows XP SP3 (32-bit)", VirtualMachineGuestOsIdentifier.WIN_XP_PRO_GUEST);
|
||||
s_mapper.put("Windows Vista (32-bit)", VirtualMachineGuestOsIdentifier.WIN_VISTA_GUEST);
|
||||
s_mapper.put("Windows Vista (64-bit)", VirtualMachineGuestOsIdentifier.WIN_VISTA_64_GUEST);
|
||||
s_mapper.put("Windows 7 (32-bit)", VirtualMachineGuestOsIdentifier.WINDOWS_7_GUEST);
|
||||
s_mapper.put("Windows 7 (64-bit)", VirtualMachineGuestOsIdentifier.WINDOWS_7_64_GUEST);
|
||||
|
||||
s_mapper.put("Windows 2000 Professional", VirtualMachineGuestOsIdentifier.win2000ProGuest);
|
||||
s_mapper.put("Windows 2000 Server", VirtualMachineGuestOsIdentifier.win2000ServGuest);
|
||||
s_mapper.put("Windows 2000 Server SP4 (32-bit)", VirtualMachineGuestOsIdentifier.win2000ServGuest);
|
||||
s_mapper.put("Windows 2000 Advanced Server", VirtualMachineGuestOsIdentifier.win2000AdvServGuest);
|
||||
|
||||
s_mapper.put("Windows Server 2003 Enterprise Edition(32-bit)", VirtualMachineGuestOsIdentifier.winNetEnterpriseGuest);
|
||||
s_mapper.put("Windows Server 2003 Enterprise Edition(64-bit)", VirtualMachineGuestOsIdentifier.winNetEnterprise64Guest);
|
||||
s_mapper.put("Windows Server 2008 R2 (64-bit)", VirtualMachineGuestOsIdentifier.winLonghorn64Guest);
|
||||
s_mapper.put("Windows Server 2003 DataCenter Edition(32-bit)", VirtualMachineGuestOsIdentifier.winNetDatacenterGuest);
|
||||
s_mapper.put("Windows Server 2003 DataCenter Edition(64-bit)", VirtualMachineGuestOsIdentifier.winNetDatacenter64Guest);
|
||||
s_mapper.put("Windows Server 2003 Standard Edition(32-bit)", VirtualMachineGuestOsIdentifier.winNetStandardGuest);
|
||||
s_mapper.put("Windows Server 2003 Standard Edition(64-bit)", VirtualMachineGuestOsIdentifier.winNetStandard64Guest);
|
||||
s_mapper.put("Windows Server 2003 Web Edition", VirtualMachineGuestOsIdentifier.winNetWebGuest);
|
||||
s_mapper.put("Microsoft Small Bussiness Server 2003", VirtualMachineGuestOsIdentifier.winNetBusinessGuest);
|
||||
|
||||
s_mapper.put("Windows Server 2008 (32-bit)", VirtualMachineGuestOsIdentifier.winLonghornGuest);
|
||||
s_mapper.put("Windows Server 2008 (64-bit)", VirtualMachineGuestOsIdentifier.winLonghorn64Guest);
|
||||
|
||||
s_mapper.put("Open Enterprise Server", VirtualMachineGuestOsIdentifier.oesGuest);
|
||||
|
||||
s_mapper.put("Asianux 3(32-bit)", VirtualMachineGuestOsIdentifier.asianux3Guest);
|
||||
s_mapper.put("Asianux 3(64-bit)", VirtualMachineGuestOsIdentifier.asianux3_64Guest);
|
||||
|
||||
s_mapper.put("Debian GNU/Linux 5(64-bit)", VirtualMachineGuestOsIdentifier.debian5_64Guest);
|
||||
s_mapper.put("Debian GNU/Linux 5.0 (32-bit)", VirtualMachineGuestOsIdentifier.debian5Guest);
|
||||
s_mapper.put("Debian GNU/Linux 4(32-bit)", VirtualMachineGuestOsIdentifier.debian4Guest);
|
||||
s_mapper.put("Debian GNU/Linux 4(64-bit)", VirtualMachineGuestOsIdentifier.debian4_64Guest);
|
||||
|
||||
s_mapper.put("Novell Netware 6.x", VirtualMachineGuestOsIdentifier.netware6Guest);
|
||||
s_mapper.put("Novell Netware 5.1", VirtualMachineGuestOsIdentifier.netware5Guest);
|
||||
|
||||
s_mapper.put("Sun Solaris 10(32-bit)", VirtualMachineGuestOsIdentifier.solaris10Guest);
|
||||
s_mapper.put("Sun Solaris 10(64-bit)", VirtualMachineGuestOsIdentifier.solaris10_64Guest);
|
||||
s_mapper.put("Sun Solaris 9(Experimental)", VirtualMachineGuestOsIdentifier.solaris9Guest);
|
||||
s_mapper.put("Sun Solaris 8(Experimental)", VirtualMachineGuestOsIdentifier.solaris8Guest);
|
||||
|
||||
s_mapper.put("FreeBSD (32-bit)", VirtualMachineGuestOsIdentifier.freebsdGuest);
|
||||
s_mapper.put("FreeBSD (64-bit)", VirtualMachineGuestOsIdentifier.freebsd64Guest);
|
||||
|
||||
s_mapper.put("SCO OpenServer 5", VirtualMachineGuestOsIdentifier.otherGuest);
|
||||
s_mapper.put("SCO UnixWare 7", VirtualMachineGuestOsIdentifier.unixWare7Guest);
|
||||
|
||||
s_mapper.put("SUSE Linux Enterprise 8(32-bit)", VirtualMachineGuestOsIdentifier.suseGuest);
|
||||
s_mapper.put("SUSE Linux Enterprise 8(64-bit)", VirtualMachineGuestOsIdentifier.suse64Guest);
|
||||
s_mapper.put("SUSE Linux Enterprise 9(32-bit)", VirtualMachineGuestOsIdentifier.suseGuest);
|
||||
s_mapper.put("SUSE Linux Enterprise 9(64-bit)", VirtualMachineGuestOsIdentifier.suse64Guest);
|
||||
s_mapper.put("SUSE Linux Enterprise 10(32-bit)", VirtualMachineGuestOsIdentifier.suseGuest);
|
||||
s_mapper.put("SUSE Linux Enterprise 10(64-bit)", VirtualMachineGuestOsIdentifier.suse64Guest);
|
||||
s_mapper.put("SUSE Linux Enterprise 10(32-bit)", VirtualMachineGuestOsIdentifier.suseGuest);
|
||||
s_mapper.put("Other SUSE Linux(32-bit)", VirtualMachineGuestOsIdentifier.suseGuest);
|
||||
s_mapper.put("Other SUSE Linux(64-bit)", VirtualMachineGuestOsIdentifier.suse64Guest);
|
||||
|
||||
s_mapper.put("CentOS 4.5 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
|
||||
s_mapper.put("CentOS 4.6 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
|
||||
s_mapper.put("CentOS 4.7 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
|
||||
s_mapper.put("CentOS 4.8 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
|
||||
s_mapper.put("CentOS 5.0 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
|
||||
s_mapper.put("CentOS 5.0 (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
|
||||
s_mapper.put("CentOS 5.1 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
|
||||
s_mapper.put("CentOS 5.1 (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
|
||||
s_mapper.put("CentOS 5.2 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
|
||||
s_mapper.put("CentOS 5.2 (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
|
||||
s_mapper.put("CentOS 5.3 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
|
||||
s_mapper.put("CentOS 5.3 (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
|
||||
s_mapper.put("CentOS 5.4 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
|
||||
s_mapper.put("CentOS 5.4 (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
|
||||
s_mapper.put("CentOS 5.5 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
|
||||
s_mapper.put("CentOS 5.5 (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
|
||||
s_mapper.put("CentOS 5.6 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
|
||||
s_mapper.put("CentOS 5.6 (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
|
||||
s_mapper.put("CentOS 6.0 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
|
||||
s_mapper.put("CentOS 6.0 (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
|
||||
s_mapper.put("Other CentOS (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
|
||||
s_mapper.put("Other CentOS (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
|
||||
|
||||
s_mapper.put("Red Hat Enterprise Linux 2", VirtualMachineGuestOsIdentifier.rhel2Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 3(32-bit)", VirtualMachineGuestOsIdentifier.rhel3Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 3(64-bit)", VirtualMachineGuestOsIdentifier.rhel3_64Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 4(32-bit)", VirtualMachineGuestOsIdentifier.rhel4Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 4(64-bit)", VirtualMachineGuestOsIdentifier.rhel4_64Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5(32-bit)", VirtualMachineGuestOsIdentifier.rhel5Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5(64-bit)", VirtualMachineGuestOsIdentifier.rhel5_64Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 6(32-bit)", VirtualMachineGuestOsIdentifier.rhel6Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 6(64-bit)", VirtualMachineGuestOsIdentifier.rhel6_64Guest);
|
||||
|
||||
s_mapper.put("Red Hat Enterprise Linux 4.5 (32-bit)", VirtualMachineGuestOsIdentifier.rhel4Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 4.6 (32-bit)", VirtualMachineGuestOsIdentifier.rhel4Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 4.7 (32-bit)", VirtualMachineGuestOsIdentifier.rhel4Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 4.8 (32-bit)", VirtualMachineGuestOsIdentifier.rhel4Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.0(32-bit)", VirtualMachineGuestOsIdentifier.rhel5Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.0(64-bit)", VirtualMachineGuestOsIdentifier.rhel5_64Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.1(32-bit)", VirtualMachineGuestOsIdentifier.rhel5Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.1(64-bit)", VirtualMachineGuestOsIdentifier.rhel5_64Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.2(32-bit)", VirtualMachineGuestOsIdentifier.rhel5Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.2(64-bit)", VirtualMachineGuestOsIdentifier.rhel5_64Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.3(32-bit)", VirtualMachineGuestOsIdentifier.rhel5Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.3(64-bit)", VirtualMachineGuestOsIdentifier.rhel5_64Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.4(32-bit)", VirtualMachineGuestOsIdentifier.rhel5Guest);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.4(64-bit)", VirtualMachineGuestOsIdentifier.rhel5_64Guest);
|
||||
|
||||
s_mapper.put("Ubuntu 8.04 (32-bit)", VirtualMachineGuestOsIdentifier.ubuntuGuest);
|
||||
s_mapper.put("Ubuntu 8.04 (64-bit)", VirtualMachineGuestOsIdentifier.ubuntu64Guest);
|
||||
s_mapper.put("Ubuntu 8.10 (32-bit)", VirtualMachineGuestOsIdentifier.ubuntuGuest);
|
||||
s_mapper.put("Ubuntu 8.10 (64-bit)", VirtualMachineGuestOsIdentifier.ubuntu64Guest);
|
||||
s_mapper.put("Ubuntu 9.04 (32-bit)", VirtualMachineGuestOsIdentifier.ubuntuGuest);
|
||||
s_mapper.put("Ubuntu 9.04 (64-bit)", VirtualMachineGuestOsIdentifier.ubuntu64Guest);
|
||||
s_mapper.put("Ubuntu 9.10 (32-bit)", VirtualMachineGuestOsIdentifier.ubuntuGuest);
|
||||
s_mapper.put("Ubuntu 9.10 (64-bit)", VirtualMachineGuestOsIdentifier.ubuntu64Guest);
|
||||
s_mapper.put("Ubuntu 10.04 (32-bit)", VirtualMachineGuestOsIdentifier.ubuntuGuest);
|
||||
s_mapper.put("Ubuntu 10.04 (64-bit)", VirtualMachineGuestOsIdentifier.ubuntu64Guest);
|
||||
s_mapper.put("Ubuntu 10.10 (32-bit)", VirtualMachineGuestOsIdentifier.ubuntuGuest);
|
||||
s_mapper.put("Ubuntu 10.10 (64-bit)", VirtualMachineGuestOsIdentifier.ubuntu64Guest);
|
||||
s_mapper.put("Other Ubuntu (32-bit)", VirtualMachineGuestOsIdentifier.ubuntuGuest);
|
||||
s_mapper.put("Other Ubuntu (64-bit)", VirtualMachineGuestOsIdentifier.ubuntu64Guest);
|
||||
s_mapper.put("Windows 2000 Professional", VirtualMachineGuestOsIdentifier.WIN_2000_PRO_GUEST);
|
||||
s_mapper.put("Windows 2000 Server", VirtualMachineGuestOsIdentifier.WIN_2000_SERV_GUEST);
|
||||
s_mapper.put("Windows 2000 Server SP4 (32-bit)", VirtualMachineGuestOsIdentifier.WIN_2000_SERV_GUEST);
|
||||
s_mapper.put("Windows 2000 Advanced Server", VirtualMachineGuestOsIdentifier.WIN_2000_ADV_SERV_GUEST);
|
||||
|
||||
s_mapper.put("Other 2.6x Linux (32-bit)", VirtualMachineGuestOsIdentifier.other26xLinuxGuest);
|
||||
s_mapper.put("Other 2.6x Linux (64-bit)", VirtualMachineGuestOsIdentifier.other26xLinux64Guest);
|
||||
s_mapper.put("Other Linux (32-bit)", VirtualMachineGuestOsIdentifier.otherLinuxGuest);
|
||||
s_mapper.put("Other Linux (64-bit)", VirtualMachineGuestOsIdentifier.otherLinux64Guest);
|
||||
|
||||
s_mapper.put("Other (32-bit)", VirtualMachineGuestOsIdentifier.otherGuest);
|
||||
s_mapper.put("Other (64-bit)", VirtualMachineGuestOsIdentifier.otherGuest64);
|
||||
s_mapper.put("Windows Server 2003 Enterprise Edition(32-bit)", VirtualMachineGuestOsIdentifier.WIN_NET_ENTERPRISE_GUEST);
|
||||
s_mapper.put("Windows Server 2003 Enterprise Edition(64-bit)", VirtualMachineGuestOsIdentifier.WIN_NET_ENTERPRISE_64_GUEST);
|
||||
s_mapper.put("Windows Server 2008 R2 (64-bit)", VirtualMachineGuestOsIdentifier.WIN_LONGHORN_64_GUEST);
|
||||
s_mapper.put("Windows Server 2003 DataCenter Edition(32-bit)", VirtualMachineGuestOsIdentifier.WIN_NET_DATACENTER_GUEST);
|
||||
s_mapper.put("Windows Server 2003 DataCenter Edition(64-bit)", VirtualMachineGuestOsIdentifier.WIN_NET_DATACENTER_64_GUEST);
|
||||
s_mapper.put("Windows Server 2003 Standard Edition(32-bit)", VirtualMachineGuestOsIdentifier.WIN_NET_STANDARD_GUEST);
|
||||
s_mapper.put("Windows Server 2003 Standard Edition(64-bit)", VirtualMachineGuestOsIdentifier.WIN_NET_STANDARD_64_GUEST);
|
||||
s_mapper.put("Windows Server 2003 Web Edition", VirtualMachineGuestOsIdentifier.WIN_NET_WEB_GUEST);
|
||||
s_mapper.put("Microsoft Small Bussiness Server 2003", VirtualMachineGuestOsIdentifier.WIN_NET_BUSINESS_GUEST);
|
||||
|
||||
s_mapper.put("Windows Server 2008 (32-bit)", VirtualMachineGuestOsIdentifier.WIN_LONGHORN_GUEST);
|
||||
s_mapper.put("Windows Server 2008 (64-bit)", VirtualMachineGuestOsIdentifier.WIN_LONGHORN_64_GUEST);
|
||||
|
||||
s_mapper.put("Windows 8", VirtualMachineGuestOsIdentifier.WINDOWS_8_GUEST);
|
||||
s_mapper.put("Windows 8 (64 bit)", VirtualMachineGuestOsIdentifier.WINDOWS_8_64_GUEST);
|
||||
s_mapper.put("Windows 8 Server (64 bit)", VirtualMachineGuestOsIdentifier.WINDOWS_8_SERVER_64_GUEST);
|
||||
|
||||
s_mapper.put("Open Enterprise Server", VirtualMachineGuestOsIdentifier.OES_GUEST);
|
||||
|
||||
s_mapper.put("Asianux 3(32-bit)", VirtualMachineGuestOsIdentifier.ASIANUX_3_GUEST);
|
||||
s_mapper.put("Asianux 3(64-bit)", VirtualMachineGuestOsIdentifier.ASIANUX_3_64_GUEST);
|
||||
|
||||
s_mapper.put("Debian GNU/Linux 5(64-bit)", VirtualMachineGuestOsIdentifier.DEBIAN_5_64_GUEST);
|
||||
s_mapper.put("Debian GNU/Linux 5.0 (32-bit)", VirtualMachineGuestOsIdentifier.DEBIAN_5_GUEST);
|
||||
s_mapper.put("Debian GNU/Linux 4(32-bit)", VirtualMachineGuestOsIdentifier.DEBIAN_4_GUEST);
|
||||
s_mapper.put("Debian GNU/Linux 4(64-bit)", VirtualMachineGuestOsIdentifier.DEBIAN_4_64_GUEST);
|
||||
|
||||
s_mapper.put("Novell Netware 6.x", VirtualMachineGuestOsIdentifier.NETWARE_6_GUEST);
|
||||
s_mapper.put("Novell Netware 5.1", VirtualMachineGuestOsIdentifier.NETWARE_5_GUEST);
|
||||
|
||||
s_mapper.put("Sun Solaris 10(32-bit)", VirtualMachineGuestOsIdentifier.SOLARIS_10_GUEST);
|
||||
s_mapper.put("Sun Solaris 10(64-bit)", VirtualMachineGuestOsIdentifier.SOLARIS_10_64_GUEST);
|
||||
s_mapper.put("Sun Solaris 9(Experimental)", VirtualMachineGuestOsIdentifier.SOLARIS_9_GUEST);
|
||||
s_mapper.put("Sun Solaris 8(Experimental)", VirtualMachineGuestOsIdentifier.SOLARIS_8_GUEST);
|
||||
|
||||
s_mapper.put("FreeBSD (32-bit)", VirtualMachineGuestOsIdentifier.FREEBSD_GUEST);
|
||||
s_mapper.put("FreeBSD (64-bit)", VirtualMachineGuestOsIdentifier.FREEBSD_64_GUEST);
|
||||
|
||||
s_mapper.put("SCO OpenServer 5", VirtualMachineGuestOsIdentifier.OTHER_GUEST);
|
||||
s_mapper.put("SCO UnixWare 7", VirtualMachineGuestOsIdentifier.UNIX_WARE_7_GUEST);
|
||||
|
||||
s_mapper.put("SUSE Linux Enterprise 8(32-bit)", VirtualMachineGuestOsIdentifier.SUSE_GUEST);
|
||||
s_mapper.put("SUSE Linux Enterprise 8(64-bit)", VirtualMachineGuestOsIdentifier.SUSE_64_GUEST);
|
||||
s_mapper.put("SUSE Linux Enterprise 9(32-bit)", VirtualMachineGuestOsIdentifier.SUSE_GUEST);
|
||||
s_mapper.put("SUSE Linux Enterprise 9(64-bit)", VirtualMachineGuestOsIdentifier.SUSE_64_GUEST);
|
||||
s_mapper.put("SUSE Linux Enterprise 10(32-bit)", VirtualMachineGuestOsIdentifier.SUSE_GUEST);
|
||||
s_mapper.put("SUSE Linux Enterprise 10(64-bit)", VirtualMachineGuestOsIdentifier.SUSE_64_GUEST);
|
||||
s_mapper.put("SUSE Linux Enterprise 10(32-bit)", VirtualMachineGuestOsIdentifier.SUSE_GUEST);
|
||||
s_mapper.put("Other SUSE Linux(32-bit)", VirtualMachineGuestOsIdentifier.SUSE_GUEST);
|
||||
s_mapper.put("Other SUSE Linux(64-bit)", VirtualMachineGuestOsIdentifier.SUSE_64_GUEST);
|
||||
|
||||
s_mapper.put("CentOS 4.5 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
|
||||
s_mapper.put("CentOS 4.6 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
|
||||
s_mapper.put("CentOS 4.7 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
|
||||
s_mapper.put("CentOS 4.8 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
|
||||
s_mapper.put("CentOS 5.0 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
|
||||
s_mapper.put("CentOS 5.0 (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
|
||||
s_mapper.put("CentOS 5.1 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
|
||||
s_mapper.put("CentOS 5.1 (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
|
||||
s_mapper.put("CentOS 5.2 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
|
||||
s_mapper.put("CentOS 5.2 (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
|
||||
s_mapper.put("CentOS 5.3 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
|
||||
s_mapper.put("CentOS 5.3 (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
|
||||
s_mapper.put("CentOS 5.4 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
|
||||
s_mapper.put("CentOS 5.4 (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
|
||||
s_mapper.put("CentOS 5.5 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
|
||||
s_mapper.put("CentOS 5.5 (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
|
||||
s_mapper.put("CentOS 5.6 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
|
||||
s_mapper.put("CentOS 5.6 (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
|
||||
s_mapper.put("CentOS 6.0 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
|
||||
s_mapper.put("CentOS 6.0 (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
|
||||
s_mapper.put("Other CentOS (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
|
||||
s_mapper.put("Other CentOS (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
|
||||
|
||||
s_mapper.put("Red Hat Enterprise Linux 2", VirtualMachineGuestOsIdentifier.RHEL_2_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 3(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_3_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 3(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_3_64_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 4(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_4_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 4(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_4_64_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_64_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 6(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_6_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 6(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_6_64_GUEST);
|
||||
|
||||
s_mapper.put("Red Hat Enterprise Linux 4.5 (32-bit)", VirtualMachineGuestOsIdentifier.RHEL_4_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 4.6 (32-bit)", VirtualMachineGuestOsIdentifier.RHEL_4_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 4.7 (32-bit)", VirtualMachineGuestOsIdentifier.RHEL_4_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 4.8 (32-bit)", VirtualMachineGuestOsIdentifier.RHEL_4_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.0(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.0(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_64_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.1(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.1(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_64_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.2(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.2(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_64_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.3(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.3(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_64_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.4(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_GUEST);
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.4(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_64_GUEST);
|
||||
|
||||
s_mapper.put("Ubuntu 8.04 (32-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_GUEST);
|
||||
s_mapper.put("Ubuntu 8.04 (64-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_64_GUEST);
|
||||
s_mapper.put("Ubuntu 8.10 (32-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_GUEST);
|
||||
s_mapper.put("Ubuntu 8.10 (64-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_64_GUEST);
|
||||
s_mapper.put("Ubuntu 9.04 (32-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_GUEST);
|
||||
s_mapper.put("Ubuntu 9.04 (64-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_64_GUEST);
|
||||
s_mapper.put("Ubuntu 9.10 (32-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_GUEST);
|
||||
s_mapper.put("Ubuntu 9.10 (64-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_64_GUEST);
|
||||
s_mapper.put("Ubuntu 10.04 (32-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_GUEST);
|
||||
s_mapper.put("Ubuntu 10.04 (64-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_64_GUEST);
|
||||
s_mapper.put("Ubuntu 10.10 (32-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_GUEST);
|
||||
s_mapper.put("Ubuntu 10.10 (64-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_64_GUEST);
|
||||
s_mapper.put("Other Ubuntu (32-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_GUEST);
|
||||
s_mapper.put("Other Ubuntu (64-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_64_GUEST);
|
||||
|
||||
s_mapper.put("Other 2.6x Linux (32-bit)", VirtualMachineGuestOsIdentifier.OTHER_26_X_LINUX_GUEST);
|
||||
s_mapper.put("Other 2.6x Linux (64-bit)", VirtualMachineGuestOsIdentifier.OTHER_26_X_LINUX_64_GUEST);
|
||||
s_mapper.put("Other Linux (32-bit)", VirtualMachineGuestOsIdentifier.OTHER_LINUX_GUEST);
|
||||
s_mapper.put("Other Linux (64-bit)", VirtualMachineGuestOsIdentifier.OTHER_LINUX_64_GUEST);
|
||||
|
||||
s_mapper.put("Other (32-bit)", VirtualMachineGuestOsIdentifier.OTHER_GUEST);
|
||||
s_mapper.put("Other (64-bit)", VirtualMachineGuestOsIdentifier.OTHER_GUEST_64);
|
||||
}
|
||||
|
||||
|
||||
public static VirtualMachineGuestOsIdentifier getGuestOsIdentifier(String guestOsName) {
|
||||
return s_mapper.get(guestOsName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import java.io.IOException;
|
|||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
|
@ -69,38 +70,38 @@ import com.vmware.vim25.VirtualVmxnet3;
|
|||
|
||||
public class VmwareHelper {
|
||||
private static final Logger s_logger = Logger.getLogger(VmwareHelper.class);
|
||||
|
||||
|
||||
public static VirtualDevice prepareNicDevice(VirtualMachineMO vmMo, ManagedObjectReference morNetwork, VirtualEthernetCardType deviceType,
|
||||
String portGroupName, String macAddress, int deviceNumber, int contextNumber, boolean conntected, boolean connectOnStart) throws Exception {
|
||||
|
||||
|
||||
VirtualEthernetCard nic;
|
||||
switch(deviceType) {
|
||||
case E1000 :
|
||||
nic = new VirtualE1000();
|
||||
break;
|
||||
|
||||
|
||||
case PCNet32 :
|
||||
nic = new VirtualPCNet32();
|
||||
break;
|
||||
|
||||
|
||||
case Vmxnet2 :
|
||||
nic = new VirtualVmxnet2();
|
||||
break;
|
||||
|
||||
|
||||
case Vmxnet3 :
|
||||
nic = new VirtualVmxnet3();
|
||||
break;
|
||||
|
||||
|
||||
default :
|
||||
assert(false);
|
||||
nic = new VirtualE1000();
|
||||
}
|
||||
|
||||
|
||||
VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
|
||||
nicBacking.setDeviceName(portGroupName);
|
||||
nicBacking.setNetwork(morNetwork);
|
||||
nic.setBacking(nicBacking);
|
||||
|
||||
|
||||
VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
|
||||
connectInfo.setAllowGuestControl(true);
|
||||
connectInfo.setConnected(conntected);
|
||||
|
|
@ -112,7 +113,7 @@ public class VmwareHelper {
|
|||
nic.setKey(-contextNumber);
|
||||
return nic;
|
||||
}
|
||||
|
||||
|
||||
public static VirtualDevice prepareDvNicDevice(VirtualMachineMO vmMo, ManagedObjectReference morNetwork, VirtualEthernetCardType deviceType,
|
||||
String dvPortGroupName, String dvSwitchUuid, String macAddress, int deviceNumber, int contextNumber, boolean conntected, boolean connectOnStart) throws Exception {
|
||||
|
||||
|
|
@ -144,7 +145,7 @@ public class VmwareHelper {
|
|||
final VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
|
||||
|
||||
dvPortConnection.setSwitchUuid(dvSwitchUuid);
|
||||
dvPortConnection.setPortgroupKey(morNetwork.get_value());
|
||||
dvPortConnection.setPortgroupKey(morNetwork.getValue());
|
||||
dvPortBacking.setPort(dvPortConnection);
|
||||
nic.setBacking(dvPortBacking);
|
||||
nic.setKey(30);
|
||||
|
|
@ -162,13 +163,13 @@ public class VmwareHelper {
|
|||
}
|
||||
|
||||
// vmdkDatastorePath: [datastore name] vmdkFilePath
|
||||
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePath,
|
||||
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePath,
|
||||
int sizeInMb, ManagedObjectReference morDs, int deviceNumber, int contextNumber) throws Exception {
|
||||
|
||||
|
||||
VirtualDisk disk = new VirtualDisk();
|
||||
|
||||
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
|
||||
backingInfo.setDiskMode(VirtualDiskMode.persistent.toString());
|
||||
backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
|
||||
backingInfo.setThinProvisioned(true);
|
||||
backingInfo.setEagerlyScrub(false);
|
||||
backingInfo.setDatastore(morDs);
|
||||
|
|
@ -180,7 +181,7 @@ public class VmwareHelper {
|
|||
if(deviceNumber < 0)
|
||||
deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
|
||||
disk.setControllerKey(controllerKey);
|
||||
|
||||
|
||||
disk.setKey(-contextNumber);
|
||||
disk.setUnitNumber(deviceNumber);
|
||||
disk.setCapacityInKB(sizeInMb*1024);
|
||||
|
|
@ -189,19 +190,19 @@ public class VmwareHelper {
|
|||
connectInfo.setConnected(true);
|
||||
connectInfo.setStartConnected(true);
|
||||
disk.setConnectable(connectInfo);
|
||||
|
||||
|
||||
return disk;
|
||||
}
|
||||
|
||||
|
||||
// vmdkDatastorePath: [datastore name] vmdkFilePath, create delta disk based on disk from template
|
||||
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePath,
|
||||
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePath,
|
||||
int sizeInMb, ManagedObjectReference morDs, VirtualDisk templateDisk, int deviceNumber, int contextNumber) throws Exception {
|
||||
|
||||
|
||||
assert(templateDisk != null);
|
||||
VirtualDeviceBackingInfo parentBacking = templateDisk.getBacking();
|
||||
assert(parentBacking != null);
|
||||
|
||||
// TODO Not sure if we need to check if the disk in template and the new disk needs to share the
|
||||
|
||||
// TODO Not sure if we need to check if the disk in template and the new disk needs to share the
|
||||
// same datastore
|
||||
VirtualDisk disk = new VirtualDisk();
|
||||
if(parentBacking instanceof VirtualDiskFlatVer1BackingInfo) {
|
||||
|
|
@ -242,13 +243,13 @@ public class VmwareHelper {
|
|||
} else {
|
||||
throw new Exception("Unsupported disk backing: " + parentBacking.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
|
||||
if(controllerKey < 0)
|
||||
controllerKey = vmMo.getIDEDeviceControllerKey();
|
||||
disk.setControllerKey(controllerKey);
|
||||
if(deviceNumber < 0)
|
||||
deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
|
||||
|
||||
|
||||
disk.setKey(-contextNumber);
|
||||
disk.setUnitNumber(deviceNumber);
|
||||
disk.setCapacityInKB(sizeInMb*1024);
|
||||
|
|
@ -259,94 +260,94 @@ public class VmwareHelper {
|
|||
disk.setConnectable(connectInfo);
|
||||
return disk;
|
||||
}
|
||||
|
||||
|
||||
// vmdkDatastorePath: [datastore name] vmdkFilePath
|
||||
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePathChain[],
|
||||
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePathChain[],
|
||||
ManagedObjectReference morDs, int deviceNumber, int contextNumber) throws Exception {
|
||||
|
||||
|
||||
assert(vmdkDatastorePathChain != null);
|
||||
assert(vmdkDatastorePathChain.length >= 1);
|
||||
|
||||
|
||||
VirtualDisk disk = new VirtualDisk();
|
||||
|
||||
|
||||
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
|
||||
backingInfo.setDatastore(morDs);
|
||||
backingInfo.setFileName(vmdkDatastorePathChain[0]);
|
||||
backingInfo.setDiskMode(VirtualDiskMode.persistent.toString());
|
||||
backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
|
||||
if(vmdkDatastorePathChain.length > 1) {
|
||||
String[] parentDisks = new String[vmdkDatastorePathChain.length - 1];
|
||||
for(int i = 0; i < vmdkDatastorePathChain.length - 1; i++)
|
||||
parentDisks[i] = vmdkDatastorePathChain[i + 1];
|
||||
|
||||
|
||||
setParentBackingInfo(backingInfo, morDs, parentDisks);
|
||||
}
|
||||
|
||||
|
||||
disk.setBacking(backingInfo);
|
||||
|
||||
if(controllerKey < 0)
|
||||
controllerKey = vmMo.getIDEDeviceControllerKey();
|
||||
if(deviceNumber < 0)
|
||||
deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
|
||||
|
||||
|
||||
disk.setControllerKey(controllerKey);
|
||||
disk.setKey(-contextNumber);
|
||||
disk.setUnitNumber(deviceNumber);
|
||||
|
||||
|
||||
VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
|
||||
connectInfo.setConnected(true);
|
||||
connectInfo.setStartConnected(true);
|
||||
disk.setConnectable(connectInfo);
|
||||
|
||||
|
||||
return disk;
|
||||
}
|
||||
|
||||
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey,
|
||||
Pair<String, ManagedObjectReference>[] vmdkDatastorePathChain,
|
||||
|
||||
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey,
|
||||
Pair<String, ManagedObjectReference>[] vmdkDatastorePathChain,
|
||||
int deviceNumber, int contextNumber) throws Exception {
|
||||
|
||||
|
||||
assert(vmdkDatastorePathChain != null);
|
||||
assert(vmdkDatastorePathChain.length >= 1);
|
||||
|
||||
|
||||
VirtualDisk disk = new VirtualDisk();
|
||||
|
||||
|
||||
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
|
||||
backingInfo.setDatastore(vmdkDatastorePathChain[0].second());
|
||||
backingInfo.setFileName(vmdkDatastorePathChain[0].first());
|
||||
backingInfo.setDiskMode(VirtualDiskMode.persistent.toString());
|
||||
backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
|
||||
if(vmdkDatastorePathChain.length > 1) {
|
||||
Pair<String, ManagedObjectReference>[] parentDisks = new Pair[vmdkDatastorePathChain.length - 1];
|
||||
for(int i = 0; i < vmdkDatastorePathChain.length - 1; i++)
|
||||
parentDisks[i] = vmdkDatastorePathChain[i + 1];
|
||||
|
||||
|
||||
setParentBackingInfo(backingInfo, parentDisks);
|
||||
}
|
||||
|
||||
|
||||
disk.setBacking(backingInfo);
|
||||
|
||||
if(controllerKey < 0)
|
||||
controllerKey = vmMo.getIDEDeviceControllerKey();
|
||||
if(deviceNumber < 0)
|
||||
deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
|
||||
|
||||
|
||||
disk.setControllerKey(controllerKey);
|
||||
disk.setKey(-contextNumber);
|
||||
disk.setUnitNumber(deviceNumber);
|
||||
|
||||
|
||||
VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
|
||||
connectInfo.setConnected(true);
|
||||
connectInfo.setStartConnected(true);
|
||||
disk.setConnectable(connectInfo);
|
||||
|
||||
|
||||
return disk;
|
||||
}
|
||||
|
||||
private static void setParentBackingInfo(VirtualDiskFlatVer2BackingInfo backingInfo,
|
||||
|
||||
private static void setParentBackingInfo(VirtualDiskFlatVer2BackingInfo backingInfo,
|
||||
ManagedObjectReference morDs, String[] parentDatastorePathList) {
|
||||
|
||||
|
||||
VirtualDiskFlatVer2BackingInfo parentBacking = new VirtualDiskFlatVer2BackingInfo();
|
||||
parentBacking.setDatastore(morDs);
|
||||
parentBacking.setDiskMode(VirtualDiskMode.persistent.toString());
|
||||
|
||||
parentBacking.setDiskMode(VirtualDiskMode.PERSISTENT.value());
|
||||
|
||||
if(parentDatastorePathList.length > 1) {
|
||||
String[] nextDatastorePathList = new String[parentDatastorePathList.length -1];
|
||||
for(int i = 0; i < parentDatastorePathList.length -1; i++)
|
||||
|
|
@ -354,17 +355,17 @@ public class VmwareHelper {
|
|||
setParentBackingInfo(parentBacking, morDs, nextDatastorePathList);
|
||||
}
|
||||
parentBacking.setFileName(parentDatastorePathList[0]);
|
||||
|
||||
|
||||
backingInfo.setParent(parentBacking);
|
||||
}
|
||||
|
||||
private static void setParentBackingInfo(VirtualDiskFlatVer2BackingInfo backingInfo,
|
||||
|
||||
private static void setParentBackingInfo(VirtualDiskFlatVer2BackingInfo backingInfo,
|
||||
Pair<String, ManagedObjectReference>[] parentDatastorePathList) {
|
||||
|
||||
|
||||
VirtualDiskFlatVer2BackingInfo parentBacking = new VirtualDiskFlatVer2BackingInfo();
|
||||
parentBacking.setDatastore(parentDatastorePathList[0].second());
|
||||
parentBacking.setDiskMode(VirtualDiskMode.persistent.toString());
|
||||
|
||||
parentBacking.setDiskMode(VirtualDiskMode.PERSISTENT.value());
|
||||
|
||||
if(parentDatastorePathList.length > 1) {
|
||||
Pair<String, ManagedObjectReference>[] nextDatastorePathList = new Pair[parentDatastorePathList.length -1];
|
||||
for(int i = 0; i < parentDatastorePathList.length -1; i++)
|
||||
|
|
@ -372,33 +373,33 @@ public class VmwareHelper {
|
|||
setParentBackingInfo(parentBacking, nextDatastorePathList);
|
||||
}
|
||||
parentBacking.setFileName(parentDatastorePathList[0].first());
|
||||
|
||||
|
||||
backingInfo.setParent(parentBacking);
|
||||
}
|
||||
|
||||
|
||||
public static Pair<VirtualDevice, Boolean> prepareIsoDevice(VirtualMachineMO vmMo, String isoDatastorePath, ManagedObjectReference morDs,
|
||||
boolean connect, boolean connectAtBoot, int deviceNumber, int contextNumber) throws Exception {
|
||||
|
||||
|
||||
boolean newCdRom = false;
|
||||
VirtualCdrom cdRom = (VirtualCdrom )vmMo.getIsoDevice();
|
||||
if(cdRom == null) {
|
||||
newCdRom = true;
|
||||
cdRom = new VirtualCdrom();
|
||||
|
||||
|
||||
assert(vmMo.getIDEDeviceControllerKey() >= 0);
|
||||
cdRom.setControllerKey(vmMo.getIDEDeviceControllerKey());
|
||||
if(deviceNumber < 0)
|
||||
deviceNumber = vmMo.getNextIDEDeviceNumber();
|
||||
|
||||
cdRom.setUnitNumber(deviceNumber);
|
||||
cdRom.setUnitNumber(deviceNumber);
|
||||
cdRom.setKey(-contextNumber);
|
||||
}
|
||||
|
||||
|
||||
VirtualDeviceConnectInfo cInfo = new VirtualDeviceConnectInfo();
|
||||
cInfo.setConnected(connect);
|
||||
cInfo.setStartConnected(connectAtBoot);
|
||||
cdRom.setConnectable(cInfo);
|
||||
|
||||
|
||||
if(isoDatastorePath != null) {
|
||||
VirtualCdromIsoBackingInfo backingInfo = new VirtualCdromIsoBackingInfo();
|
||||
backingInfo.setFileName(isoDatastorePath);
|
||||
|
|
@ -409,32 +410,32 @@ public class VmwareHelper {
|
|||
backingInfo.setDeviceName("");
|
||||
cdRom.setBacking(backingInfo);
|
||||
}
|
||||
|
||||
|
||||
return new Pair<VirtualDevice, Boolean>(cdRom, newCdRom);
|
||||
}
|
||||
|
||||
|
||||
public static VirtualDisk getRootDisk(VirtualDisk[] disks) {
|
||||
if(disks.length == 1)
|
||||
return disks[0];
|
||||
|
||||
|
||||
// TODO : for now, always return the first disk as root disk
|
||||
return disks[0];
|
||||
}
|
||||
|
||||
public static ManagedObjectReference findSnapshotInTree(VirtualMachineSnapshotTree[] snapTree, String findName) {
|
||||
|
||||
public static ManagedObjectReference findSnapshotInTree(List<VirtualMachineSnapshotTree> snapTree, String findName) {
|
||||
assert(findName != null);
|
||||
|
||||
|
||||
ManagedObjectReference snapMor = null;
|
||||
if (snapTree == null)
|
||||
if (snapTree == null)
|
||||
return snapMor;
|
||||
|
||||
for (int i = 0; i < snapTree.length && snapMor == null; i++) {
|
||||
VirtualMachineSnapshotTree node = snapTree[i];
|
||||
|
||||
for (int i = 0; i < snapTree.size() && snapMor == null; i++) {
|
||||
VirtualMachineSnapshotTree node = snapTree.get(i);
|
||||
|
||||
if (node.getName().equals(findName)) {
|
||||
snapMor = node.getSnapshot();
|
||||
} else {
|
||||
VirtualMachineSnapshotTree[] childTree = node.getChildSnapshotList();
|
||||
List<VirtualMachineSnapshotTree> childTree = node.getChildSnapshotList();
|
||||
snapMor = findSnapshotInTree(childTree, findName);
|
||||
}
|
||||
}
|
||||
|
|
@ -442,94 +443,94 @@ public class VmwareHelper {
|
|||
}
|
||||
|
||||
public static byte[] composeDiskInfo(List<Ternary<String, String, String>> diskInfo, int disksInChain, boolean includeBase) throws IOException {
|
||||
|
||||
|
||||
BufferedWriter out = null;
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
|
||||
|
||||
try {
|
||||
out = new BufferedWriter(new OutputStreamWriter(bos));
|
||||
out = new BufferedWriter(new OutputStreamWriter(bos));
|
||||
|
||||
out.write("disksInChain=" + disksInChain);
|
||||
out.newLine();
|
||||
|
||||
|
||||
out.write("disksInBackup=" + diskInfo.size());
|
||||
out.newLine();
|
||||
|
||||
|
||||
out.write("baseDiskIncluded=" + includeBase);
|
||||
out.newLine();
|
||||
|
||||
|
||||
int seq = disksInChain - 1;
|
||||
for(Ternary<String, String, String> item : diskInfo) {
|
||||
out.write(String.format("disk%d.fileName=%s", seq, item.first()));
|
||||
out.newLine();
|
||||
|
||||
|
||||
out.write(String.format("disk%d.baseFileName=%s", seq, item.second()));
|
||||
out.newLine();
|
||||
|
||||
|
||||
if(item.third() != null) {
|
||||
out.write(String.format("disk%d.parentFileName=%s", seq, item.third()));
|
||||
out.newLine();
|
||||
}
|
||||
seq--;
|
||||
}
|
||||
|
||||
|
||||
out.newLine();
|
||||
} finally {
|
||||
if(out != null)
|
||||
out.close();
|
||||
}
|
||||
|
||||
|
||||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
public static OptionValue[] composeVncOptions(OptionValue[] optionsToMerge,
|
||||
|
||||
public static OptionValue[] composeVncOptions(OptionValue[] optionsToMerge,
|
||||
boolean enableVnc, String vncPassword, int vncPort, String keyboardLayout) {
|
||||
|
||||
|
||||
int numOptions = 3;
|
||||
boolean needKeyboardSetup = false;
|
||||
if(keyboardLayout != null && !keyboardLayout.isEmpty()) {
|
||||
numOptions++;
|
||||
needKeyboardSetup = true;
|
||||
}
|
||||
|
||||
|
||||
if(optionsToMerge != null)
|
||||
numOptions += optionsToMerge.length;
|
||||
|
||||
|
||||
OptionValue[] options = new OptionValue[numOptions];
|
||||
int i = 0;
|
||||
if(optionsToMerge != null) {
|
||||
for(int j = 0; j < optionsToMerge.length; j++)
|
||||
options[i++] = optionsToMerge[j];
|
||||
}
|
||||
|
||||
|
||||
options[i] = new OptionValue();
|
||||
options[i].setKey("RemoteDisplay.vnc.enabled");
|
||||
options[i++].setValue(enableVnc ? "true" : "false");
|
||||
|
||||
|
||||
options[i] = new OptionValue();
|
||||
options[i].setKey("RemoteDisplay.vnc.password");
|
||||
options[i++].setValue(vncPassword);
|
||||
|
||||
|
||||
options[i] = new OptionValue();
|
||||
options[i].setKey("RemoteDisplay.vnc.port");
|
||||
options[i++].setValue("" + vncPort);
|
||||
|
||||
|
||||
if(needKeyboardSetup) {
|
||||
options[i] = new OptionValue();
|
||||
options[i].setKey("RemoteDisplay.vnc.keymap");
|
||||
options[i++].setValue(keyboardLayout);
|
||||
}
|
||||
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
public static void setBasicVmConfig(VirtualMachineConfigSpec vmConfig, int cpuCount, int cpuSpeedMHz, int cpuReservedMhz,
|
||||
int memoryMB, int memoryReserveMB, String guestOsIdentifier, boolean limitCpuUse) {
|
||||
|
||||
|
||||
// VM config basics
|
||||
vmConfig.setMemoryMB((long)memoryMB);
|
||||
vmConfig.setNumCPUs(cpuCount);
|
||||
|
||||
|
||||
ResourceAllocationInfo cpuInfo = new ResourceAllocationInfo();
|
||||
if (limitCpuUse) {
|
||||
cpuInfo.setLimit((long)(cpuSpeedMHz * cpuCount));
|
||||
|
|
@ -549,47 +550,47 @@ public class VmwareHelper {
|
|||
memInfo.setLimit((long)memoryMB);
|
||||
memInfo.setReservation((long)memoryReserveMB);
|
||||
vmConfig.setMemoryAllocation(memInfo);
|
||||
|
||||
|
||||
vmConfig.setGuestId(guestOsIdentifier);
|
||||
}
|
||||
|
||||
|
||||
public static ManagedObjectReference getDiskDeviceDatastore(VirtualDisk diskDevice) throws Exception {
|
||||
VirtualDeviceBackingInfo backingInfo = diskDevice.getBacking();
|
||||
assert(backingInfo instanceof VirtualDiskFlatVer2BackingInfo);
|
||||
return ((VirtualDiskFlatVer2BackingInfo)backingInfo).getDatastore();
|
||||
}
|
||||
|
||||
|
||||
public static Object getPropValue(ObjectContent oc, String name) {
|
||||
DynamicProperty[] props = oc.getPropSet();
|
||||
|
||||
List<DynamicProperty> props = oc.getPropSet();
|
||||
|
||||
for(DynamicProperty prop : props) {
|
||||
if(prop.getName().equalsIgnoreCase(name))
|
||||
return prop.getVal();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static String getFileExtension(String fileName, String defaultExtension) {
|
||||
int pos = fileName.lastIndexOf('.');
|
||||
if(pos < 0)
|
||||
return defaultExtension;
|
||||
|
||||
return fileName.substring(pos);
|
||||
|
||||
return fileName.substring(pos);
|
||||
}
|
||||
|
||||
|
||||
public static boolean isSameHost(String ipAddress, String destName) {
|
||||
// TODO : may need to do DNS lookup to compare IP address exactly
|
||||
return ipAddress.equals(destName);
|
||||
}
|
||||
|
||||
|
||||
public static void deleteVolumeVmdkFiles(DatastoreMO dsMo, String volumeName, DatacenterMO dcMo) throws Exception {
|
||||
String volumeDatastorePath = String.format("[%s] %s.vmdk", dsMo.getName(), volumeName);
|
||||
dsMo.deleteFile(volumeDatastorePath, dcMo.getMor(), true);
|
||||
|
||||
|
||||
volumeDatastorePath = String.format("[%s] %s-flat.vmdk", dsMo.getName(), volumeName);
|
||||
dsMo.deleteFile(volumeDatastorePath, dcMo.getMor(), true);
|
||||
|
||||
|
||||
volumeDatastorePath = String.format("[%s] %s-delta.vmdk", dsMo.getName(), volumeName);
|
||||
dsMo.deleteFile(volumeDatastorePath, dcMo.getMor(), true);
|
||||
}
|
||||
|
|
@ -597,38 +598,50 @@ public class VmwareHelper {
|
|||
public static String getExceptionMessage(Throwable e) {
|
||||
return getExceptionMessage(e, false);
|
||||
}
|
||||
|
||||
|
||||
public static String getExceptionMessage(Throwable e, boolean printStack) {
|
||||
if(e instanceof MethodFault) {
|
||||
final StringWriter writer = new StringWriter();
|
||||
writer.append("Exception: " + e.getClass().getName() + "\n");
|
||||
writer.append("message: " + ((MethodFault)e).getFaultString() + "\n");
|
||||
|
||||
if(printStack) {
|
||||
writer.append("stack: ");
|
||||
e.printStackTrace(new PrintWriter(writer));
|
||||
}
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
//TODO: in vim 5.1, exceptions do not have a base exception class, MethodFault becomes a FaultInfo that we can only get
|
||||
// from individual exception through getFaultInfo, so we have to use reflection here to get MethodFault information.
|
||||
try{
|
||||
Class cls = e.getClass();
|
||||
Method mth = cls.getDeclaredMethod("getFaultInfo", null);
|
||||
if ( mth != null ){
|
||||
Object fault = mth.invoke(e, null);
|
||||
if (fault instanceof MethodFault) {
|
||||
final StringWriter writer = new StringWriter();
|
||||
writer.append("Exception: " + fault.getClass().getName() + "\n");
|
||||
writer.append("message: " + ((MethodFault)fault).getFaultMessage() + "\n");
|
||||
|
||||
if(printStack) {
|
||||
writer.append("stack: ");
|
||||
e.printStackTrace(new PrintWriter(writer));
|
||||
}
|
||||
return writer.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex){
|
||||
|
||||
}
|
||||
|
||||
return ExceptionUtil.toString(e, printStack);
|
||||
}
|
||||
|
||||
|
||||
public static VirtualMachineMO pickOneVmOnRunningHost(List<VirtualMachineMO> vmList, boolean bFirstFit) throws Exception {
|
||||
List<VirtualMachineMO> candidates = new ArrayList<VirtualMachineMO>();
|
||||
|
||||
|
||||
for(VirtualMachineMO vmMo : vmList) {
|
||||
HostMO hostMo = vmMo.getRunningHost();
|
||||
if(hostMo.isHyperHostConnected())
|
||||
candidates.add(vmMo);
|
||||
}
|
||||
|
||||
|
||||
if(candidates.size() == 0)
|
||||
return null;
|
||||
|
||||
|
||||
if(bFirstFit)
|
||||
return candidates.get(0);
|
||||
|
||||
|
||||
Random random = new Random();
|
||||
return candidates.get(random.nextInt(candidates.size()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,13 @@
|
|||
// under the License.
|
||||
package com.cloud.hypervisor.vmware.mo;
|
||||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareClient;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.vmware.apputils.version.ExtendedAppUtil;
|
||||
|
||||
|
||||
public class TestVmwareContextFactory {
|
||||
private static volatile int s_seq = 1;
|
||||
|
||||
|
||||
static {
|
||||
// skip certificate check
|
||||
System.setProperty("axis.socketSecureFactory", "org.apache.axis.components.net.SunFakeTrustSocketFactory");
|
||||
|
|
@ -33,11 +34,10 @@ public class TestVmwareContextFactory {
|
|||
assert(vCenterPassword != null);
|
||||
|
||||
String serviceUrl = "https://" + vCenterAddress + "/sdk/vimService";
|
||||
String[] params = new String[] {"--url", serviceUrl, "--username", vCenterUserName, "--password", vCenterPassword };
|
||||
ExtendedAppUtil appUtil = ExtendedAppUtil.initialize(vCenterAddress + "-" + s_seq++, params);
|
||||
|
||||
appUtil.connect();
|
||||
VmwareContext context = new VmwareContext(appUtil, vCenterAddress);
|
||||
VmwareClient vimClient = new VmwareClient(vCenterAddress + "-" + s_seq++);
|
||||
vimClient.connect(serviceUrl, vCenterUserName, vCenterPassword);
|
||||
|
||||
VmwareContext context = new VmwareContext(vimClient, vCenterAddress);
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import org.apache.log4j.Logger;
|
|||
|
||||
import com.cloud.hypervisor.vmware.mo.SnapshotDescriptor.SnapshotInfo;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.cloud.serializer.GsonHelper;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.testcase.Log4jEnabledTestCase;
|
||||
import com.google.gson.Gson;
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ import com.cloud.hypervisor.vmware.mo.DistributedVirtualSwitchMO;
|
|||
import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.cloud.utils.PropertiesUtil;
|
||||
import com.vmware.apputils.version.ExtendedAppUtil;
|
||||
import com.vmware.vim25.HostIpConfig;
|
||||
import com.vmware.vim25.HostVirtualNicSpec;
|
||||
import com.vmware.vim25.ArrayOfManagedObjectReference;
|
||||
import com.vmware.vim25.DVPortgroupConfigInfo;
|
||||
import com.vmware.vim25.DVPortgroupConfigSpec;
|
||||
|
|
@ -924,7 +925,7 @@ public class TestVMWare {
|
|||
}
|
||||
private DatacenterMO setupDatacenterObject(String serverAddress, String dcMor) {
|
||||
VmwareContext context = new VmwareContext(cb, serverAddress);
|
||||
|
||||
|
||||
ManagedObjectReference morDc = new ManagedObjectReference();
|
||||
morDc.setType("Datacenter");
|
||||
morDc.set_value(dcMor);
|
||||
|
|
@ -1307,7 +1308,7 @@ public class TestVMWare {
|
|||
// Test addDvNic
|
||||
// Test deleteDvNic
|
||||
// client.testDvNicOperations();
|
||||
|
||||
|
||||
cb.disConnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
Loading…
Reference in New Issue