Search in sources :

Example 11 with VmwareHypervisorHost

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.

the class VmwareResource method execute.

private Answer execute(GetUnmanagedInstancesCommand cmd) {
    VmwareContext context = getServiceContext();
    HashMap<String, UnmanagedInstanceTO> unmanagedInstances = new HashMap<>();
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(context);
        String vmName = cmd.getInstanceName();
        List<VirtualMachineMO> vmMos = hyperHost.listVmsOnHyperHostWithHypervisorName(vmName);
        for (VirtualMachineMO vmMo : vmMos) {
            if (vmMo == null) {
                continue;
            }
            if (vmMo.isTemplate()) {
                continue;
            }
            // Filter managed instances
            if (cmd.hasManagedInstance(vmMo.getName())) {
                continue;
            }
            // Filter instance if answer is requested for a particular instance name
            if (StringUtils.isNotEmpty(cmd.getInstanceName()) && !cmd.getInstanceName().equals(vmMo.getVmName())) {
                continue;
            }
            UnmanagedInstanceTO instance = getUnmanagedInstance(hyperHost, vmMo);
            if (instance != null) {
                unmanagedInstances.put(instance.getName(), instance);
            }
        }
    } catch (Exception e) {
        s_logger.info("GetUnmanagedInstancesCommand failed due to " + VmwareHelper.getExceptionMessage(e));
    }
    return new GetUnmanagedInstancesAnswer(cmd, "", unmanagedInstances);
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) UnmanagedInstanceTO(org.apache.cloudstack.vm.UnmanagedInstanceTO) HashMap(java.util.HashMap) GetUnmanagedInstancesAnswer(com.cloud.agent.api.GetUnmanagedInstancesAnswer) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Example 12 with VmwareHypervisorHost

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.

the class VmwareResource method fillHostNetworkInfo.

private void fillHostNetworkInfo(VmwareContext serviceContext, StartupRoutingCommand cmd) throws RuntimeFaultFaultMsg, RemoteException {
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
        assert (hyperHost instanceof HostMO);
        VmwareManager mgr = hyperHost.getContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
        VmwareHypervisorHostNetworkSummary summary = hyperHost.getHyperHostNetworkSummary(mgr.getManagementPortGroupByHost((HostMO) hyperHost));
        if (summary == null) {
            throw new Exception("No ESX(i) host found");
        }
        if (s_logger.isInfoEnabled()) {
            s_logger.info("Startup report on host network info. " + _gson.toJson(summary));
        }
        cmd.setPrivateIpAddress(summary.getHostIp());
        cmd.setPrivateNetmask(summary.getHostNetmask());
        cmd.setPrivateMacAddress(summary.getHostMacAddress());
        cmd.setStorageIpAddress(summary.getHostIp());
        cmd.setStorageNetmask(summary.getHostNetmask());
        cmd.setStorageMacAddress(summary.getHostMacAddress());
    } catch (Throwable e) {
        String msg = "querying host network info failed due to " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(msg, e);
        throw new CloudRuntimeException(msg);
    }
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VmwareHypervisorHostNetworkSummary(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Example 13 with VmwareHypervisorHost

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.

the class VmwareResource method execute.

/**
 * UnregisterNicCommand is used to remove a portgroup created for this
 * specific nic. The portgroup will have the name set to the UUID of the
 * nic. Introduced to cleanup the portgroups created for each nic that is
 * plugged into an lswitch (Nicira NVP plugin)
 *
 * @param cmd
 * @return
 */
protected Answer execute(UnregisterNicCommand cmd) {
    if (_guestTrafficInfo == null) {
        return new Answer(cmd, false, "No Guest Traffic Info found, unable to determine where to clean up");
    }
    try {
        if (_guestTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch) {
            // on the standard switches
            return new Answer(cmd, true, "Nothing to do");
        }
        s_logger.debug("Cleaning up portgroup " + cmd.getNicUuid() + " on switch " + _guestTrafficInfo.getVirtualSwitchName());
        VmwareContext context = getServiceContext();
        VmwareHypervisorHost host = getHyperHost(context);
        ManagedObjectReference clusterMO = host.getHyperHostCluster();
        // Get a list of all the hosts in this cluster
        @SuppressWarnings("unchecked") List<ManagedObjectReference> hosts = (List<ManagedObjectReference>) context.getVimClient().getDynamicProperty(clusterMO, "host");
        if (hosts == null) {
            return new Answer(cmd, false, "No hosts in cluster, which is pretty weird");
        }
        for (ManagedObjectReference hostMOR : hosts) {
            HostMO hostMo = new HostMO(context, hostMOR);
            hostMo.deletePortGroup(cmd.getNicUuid().toString());
            s_logger.debug("Removed portgroup " + cmd.getNicUuid() + " from host " + hostMo.getHostName());
        }
        return new Answer(cmd, true, "Unregistered resources for NIC " + cmd.getNicUuid());
    } catch (Exception e) {
        return new Answer(cmd, false, createLogMessageException(e, cmd));
    }
}
Also used : SetupPersistentNetworkAnswer(com.cloud.agent.api.SetupPersistentNetworkAnswer) ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) MigrateVmToPoolAnswer(com.cloud.agent.api.MigrateVmToPoolAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) GetVmVncTicketAnswer(com.cloud.agent.api.GetVmVncTicketAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer) SetupAnswer(com.cloud.agent.api.SetupAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) GetVmNetworkStatsAnswer(com.cloud.agent.api.GetVmNetworkStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) AttachIsoAnswer(com.cloud.agent.api.AttachIsoAnswer) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) GetStoragePoolCapabilitiesAnswer(com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) ReplugNicAnswer(com.cloud.agent.api.ReplugNicAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) GetUnmanagedInstancesAnswer(com.cloud.agent.api.GetUnmanagedInstancesAnswer) ValidateSnapshotAnswer(com.cloud.agent.api.ValidateSnapshotAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareUnmanageVMInstanceAnswer(com.cloud.agent.api.PrepareUnmanageVMInstanceAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) ArrayList(java.util.ArrayList) List(java.util.List) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 14 with VmwareHypervisorHost

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.

the class VmwareResource method getIqn.

private String getIqn() {
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
        if (hyperHost instanceof HostMO) {
            HostMO host = (HostMO) hyperHost;
            HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO();
            for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) {
                if (hba instanceof HostInternetScsiHba) {
                    HostInternetScsiHba hostInternetScsiHba = (HostInternetScsiHba) hba;
                    if (hostInternetScsiHba.isIsSoftwareBased()) {
                        return ((HostInternetScsiHba) hba).getIScsiName();
                    }
                }
            }
        }
    } catch (Exception ex) {
        s_logger.info("Could not locate an IQN for this host.");
    }
    return null;
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) HostInternetScsiHba(com.vmware.vim25.HostInternetScsiHba) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) HostStorageSystemMO(com.cloud.hypervisor.vmware.mo.HostStorageSystemMO) HostHostBusAdapter(com.vmware.vim25.HostHostBusAdapter) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Example 15 with VmwareHypervisorHost

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.

the class VmwareResource method execute.

protected Answer execute(MigrateCommand cmd) {
    final String vmName = cmd.getVmName();
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
        ManagedObjectReference morDc = hyperHost.getHyperHostDatacenter();
        // find VM through datacenter (VM is not at the target host yet)
        VirtualMachineMO vmMo = hyperHost.findVmOnPeerHyperHost(vmName);
        if (vmMo == null) {
            String msg = "VM " + vmName + " does not exist in VMware datacenter";
            s_logger.error(msg);
            throw new Exception(msg);
        }
        VmwareHypervisorHost destHyperHost = getTargetHyperHost(new DatacenterMO(hyperHost.getContext(), morDc), cmd.getDestinationIp());
        ManagedObjectReference morTargetPhysicalHost = destHyperHost.findMigrationTarget(vmMo);
        if (morTargetPhysicalHost == null) {
            throw new Exception("Unable to find a target capable physical host");
        }
        if (!vmMo.migrate(destHyperHost.getHyperHostOwnerResourcePool(), morTargetPhysicalHost)) {
            throw new Exception("Migration failed");
        }
        return new MigrateAnswer(cmd, true, "migration succeeded", null);
    } catch (Throwable e) {
        return new MigrateAnswer(cmd, false, createLogMessageException(e, cmd), null);
    }
}
Also used : MigrateAnswer(com.cloud.agent.api.MigrateAnswer) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO)

Aggregations

VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)85 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)65 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)65 RemoteException (java.rmi.RemoteException)59 UnsupportedEncodingException (java.io.UnsupportedEncodingException)57 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)48 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)46 CloudException (com.cloud.exception.CloudException)40 InternalErrorException (com.cloud.exception.InternalErrorException)40 IOException (java.io.IOException)40 ConnectException (java.net.ConnectException)40 ConfigurationException (javax.naming.ConfigurationException)40 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)31 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)27 DatacenterMO (com.cloud.hypervisor.vmware.mo.DatacenterMO)23 Pair (com.cloud.utils.Pair)15 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)12 Answer (com.cloud.agent.api.Answer)11 AttachIsoAnswer (com.cloud.agent.api.AttachIsoAnswer)10 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)10