Search in sources :

Example 6 with VmwareDatacenterVO

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

the class VmwareManagerImpl method removeVmwareDatacenter.

@Override
public boolean removeVmwareDatacenter(RemoveVmwareDcCmd cmd) throws ResourceInUseException {
    Long zoneId = cmd.getZoneId();
    // Validate Id of zone
    doesZoneExist(zoneId);
    // Zone validation to check if the zone already has resources.
    // Association of VMware DC to zone is not allowed if zone already has resources added.
    validateZoneWithResources(zoneId, "remove VMware datacenter to zone");
    // Get DC associated with this zone
    VmwareDatacenterVO vmwareDatacenter;
    String vmwareDcName;
    String vCenterHost;
    String userName;
    String password;
    DatacenterMO dcMo = null;
    final VmwareDatacenterZoneMapVO vmwareDcZoneMap = vmwareDatacenterZoneMapDao.findByZoneId(zoneId);
    // Check if zone is associated with VMware DC
    if (vmwareDcZoneMap == null) {
        throw new CloudRuntimeException("Zone " + zoneId + " is not associated with any VMware datacenter.");
    }
    final long vmwareDcId = vmwareDcZoneMap.getVmwareDcId();
    vmwareDatacenter = vmwareDcDao.findById(vmwareDcId);
    vmwareDcName = vmwareDatacenter.getVmwareDatacenterName();
    vCenterHost = vmwareDatacenter.getVcenterHost();
    userName = vmwareDatacenter.getUser();
    password = vmwareDatacenter.getPassword();
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            // Remove the VMware datacenter entry in table vmware_data_center
            vmwareDcDao.remove(vmwareDcId);
            // Remove the map entry in table vmware_data_center_zone_map
            vmwareDatacenterZoneMapDao.remove(vmwareDcZoneMap.getId());
        }
    });
    // Construct context
    VmwareContext context = null;
    try {
        context = VmwareContextFactory.create(vCenterHost, userName, password);
        // Check if DC exists on vCenter
        try {
            dcMo = new DatacenterMO(context, vmwareDcName);
        } catch (Throwable t) {
            String msg = "Unable to find DC " + vmwareDcName + " in vCenter " + vCenterHost;
            s_logger.error(msg);
            throw new DiscoveryException(msg);
        }
        assert (dcMo != null);
        // Reset custom field property cloud.zone over this DC
        dcMo.setCustomFieldValue(CustomFieldConstants.CLOUD_ZONE, "false");
        s_logger.info("Sucessfully reset custom field property cloud.zone over DC " + vmwareDcName);
    } catch (Exception e) {
        String msg = "Unable to reset custom field property cloud.zone over DC " + vmwareDcName + " due to : " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(msg);
        throw new CloudRuntimeException(msg);
    } finally {
        if (context != null) {
            context.close();
        }
        context = null;
    }
    return true;
}
Also used : VmwareDatacenterZoneMapVO(com.cloud.hypervisor.vmware.VmwareDatacenterZoneMapVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) DiscoveredWithErrorException(com.cloud.exception.DiscoveredWithErrorException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) DiscoveryException(com.cloud.exception.DiscoveryException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) RemoteException(java.rmi.RemoteException) ConfigurationException(javax.naming.ConfigurationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VmwareDatacenterVO(com.cloud.hypervisor.vmware.VmwareDatacenterVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DiscoveryException(com.cloud.exception.DiscoveryException) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO)

Example 7 with VmwareDatacenterVO

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

the class ResultWrapper method getLoginInfo.

private LoginInfo getLoginInfo(long zoneId) {
    VmwareDatacenterZoneMapVO vmwareDcZoneMap = vmwareDcZoneMapDao.findByZoneId(zoneId);
    Long associatedVmwareDcId = vmwareDcZoneMap.getVmwareDcId();
    VmwareDatacenterVO associatedVmwareDc = vmwareDcDao.findById(associatedVmwareDcId);
    String host = associatedVmwareDc.getVcenterHost();
    String username = associatedVmwareDc.getUser();
    String password = associatedVmwareDc.getPassword();
    return new LoginInfo(host, username, password);
}
Also used : LoginInfo(org.apache.cloudstack.util.LoginInfo) VmwareDatacenterZoneMapVO(com.cloud.hypervisor.vmware.VmwareDatacenterZoneMapVO) VmwareDatacenterVO(com.cloud.hypervisor.vmware.VmwareDatacenterVO)

Example 8 with VmwareDatacenterVO

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

the class VmwareManagerImpl method importVsphereStoragePoliciesInternal.

public List<? extends VsphereStoragePolicy> importVsphereStoragePoliciesInternal(Long zoneId, Long vmwareDcId) {
    // Get DC associated with this zone
    VmwareDatacenterVO vmwareDatacenter = vmwareDcDao.findById(vmwareDcId);
    String vmwareDcName = vmwareDatacenter.getVmwareDatacenterName();
    String vCenterHost = vmwareDatacenter.getVcenterHost();
    String userName = vmwareDatacenter.getUser();
    String password = vmwareDatacenter.getPassword();
    List<PbmProfile> storageProfiles = null;
    try {
        s_logger.debug(String.format("Importing vSphere Storage Policies for the vmware DC %d in zone %d", vmwareDcId, zoneId));
        VmwareContext context = VmwareContextFactory.getContext(vCenterHost, userName, password);
        PbmProfileManagerMO profileManagerMO = new PbmProfileManagerMO(context);
        storageProfiles = profileManagerMO.getStorageProfiles();
        s_logger.debug(String.format("Import vSphere Storage Policies for the vmware DC %d in zone %d is successful", vmwareDcId, zoneId));
    } catch (Exception e) {
        String msg = String.format("Unable to list storage profiles from DC %s due to : %s", vmwareDcName, VmwareHelper.getExceptionMessage(e));
        s_logger.error(msg);
        throw new CloudRuntimeException(msg);
    }
    for (PbmProfile storageProfile : storageProfiles) {
        VsphereStoragePolicyVO storagePolicyVO = vsphereStoragePolicyDao.findByPolicyId(zoneId, storageProfile.getProfileId().getUniqueId());
        if (storagePolicyVO == null) {
            storagePolicyVO = new VsphereStoragePolicyVO(zoneId, storageProfile.getProfileId().getUniqueId(), storageProfile.getName(), storageProfile.getDescription());
            vsphereStoragePolicyDao.persist(storagePolicyVO);
        } else {
            storagePolicyVO.setDescription(storageProfile.getDescription());
            storagePolicyVO.setName(storageProfile.getName());
            vsphereStoragePolicyDao.update(storagePolicyVO.getId(), storagePolicyVO);
        }
    }
    List<VsphereStoragePolicyVO> allStoragePolicies = vsphereStoragePolicyDao.listAll();
    List<PbmProfile> finalStorageProfiles = storageProfiles;
    List<VsphereStoragePolicyVO> needToMarkRemoved = allStoragePolicies.stream().filter(existingPolicy -> !finalStorageProfiles.stream().anyMatch(storageProfile -> storageProfile.getProfileId().getUniqueId().equals(existingPolicy.getPolicyId()))).collect(Collectors.toList());
    for (VsphereStoragePolicyVO storagePolicy : needToMarkRemoved) {
        vsphereStoragePolicyDao.remove(storagePolicy.getId());
    }
    List<VsphereStoragePolicyVO> storagePolicies = vsphereStoragePolicyDao.listAll();
    return storagePolicies;
}
Also used : DiscoveredWithErrorException(com.cloud.exception.DiscoveredWithErrorException) NetworkModel(com.cloud.network.NetworkModel) HostDao(com.cloud.host.dao.HostDao) HypervisorGuruManager(com.cloud.hypervisor.HypervisorGuruManager) VmwareDatacenterZoneMap(com.cloud.hypervisor.vmware.VmwareDatacenterZoneMap) Transaction(com.cloud.utils.db.Transaction) ClusterType(com.cloud.org.Cluster.ClusterType) StringUtils(org.apache.commons.lang3.StringUtils) AgentManager(com.cloud.agent.AgentManager) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) VirtualSwitchType(com.cloud.hypervisor.vmware.mo.VirtualSwitchType) VMTemplatePoolDao(com.cloud.storage.dao.VMTemplatePoolDao) RemoveVmwareDcCmd(org.apache.cloudstack.api.command.admin.zone.RemoveVmwareDcCmd) Duration(java.time.Duration) Map(java.util.Map) VsphereStoragePolicy(com.cloud.dc.VsphereStoragePolicy) TrafficType(com.cloud.network.Networks.TrafficType) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) VmwareContextFactory(com.cloud.hypervisor.vmware.resource.VmwareContextFactory) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) VmwareDatacenter(com.cloud.hypervisor.vmware.VmwareDatacenter) TransactionStatus(com.cloud.utils.db.TransactionStatus) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) FileUtil(com.cloud.utils.FileUtil) Executors(java.util.concurrent.Executors) Script(com.cloud.utils.script.Script) ConfigurationServer(com.cloud.server.ConfigurationServer) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) ImageStoreDetailsUtil(com.cloud.storage.ImageStoreDetailsUtil) AsyncJobManagerImpl(org.apache.cloudstack.framework.jobs.impl.AsyncJobManagerImpl) ClusterVSMMapDao(com.cloud.dc.dao.ClusterVSMMapDao) ManagementServerHostPeerDao(com.cloud.cluster.dao.ManagementServerHostPeerDao) HypervisorCapabilitiesDao(com.cloud.hypervisor.dao.HypervisorCapabilitiesDao) JavaStorageLayer(com.cloud.storage.JavaStorageLayer) NumbersUtil(com.cloud.utils.NumbersUtil) ManagerBase(com.cloud.utils.component.ManagerBase) DataCenterVO(com.cloud.dc.DataCenterVO) VirtualEthernetCardType(com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType) CiscoNexusVSMDeviceVO(com.cloud.network.CiscoNexusVSMDeviceVO) ArrayList(java.util.ArrayList) LegacyZoneDao(com.cloud.hypervisor.vmware.dao.LegacyZoneDao) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ClusterDao(com.cloud.dc.dao.ClusterDao) DomainRouterVO(com.cloud.vm.DomainRouterVO) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) UpdateVmwareDcCmd(org.apache.cloudstack.api.command.admin.zone.UpdateVmwareDcCmd) ClusterVO(com.cloud.dc.ClusterVO) VMInstanceDao(com.cloud.vm.dao.VMInstanceDao) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) VmwareCleanupMaid(com.cloud.hypervisor.vmware.VmwareCleanupMaid) VmwareDatacenterDao(com.cloud.hypervisor.vmware.dao.VmwareDatacenterDao) UserVmCloneSettingDao(com.cloud.vm.dao.UserVmCloneSettingDao) ClusterVSMMapVO(com.cloud.dc.ClusterVSMMapVO) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) IOException(java.io.IOException) DB(com.cloud.utils.db.DB) File(java.io.File) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) ClusterManager(com.cloud.cluster.ClusterManager) VmwareHelper(com.cloud.hypervisor.vmware.util.VmwareHelper) Command(com.cloud.agent.api.Command) Host(com.cloud.host.Host) AddVmwareDcCmd(org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd) ActionEvent(com.cloud.event.ActionEvent) ClusterDetailsDao(com.cloud.dc.ClusterDetailsDao) GlobalLock(com.cloud.utils.db.GlobalLock) ConfigurationDao(org.apache.cloudstack.framework.config.dao.ConfigurationDao) ResourceInUseException(com.cloud.exception.ResourceInUseException) StorageManager(com.cloud.storage.StorageManager) TemplateManager(com.cloud.template.TemplateManager) URLDecoder(java.net.URLDecoder) HypervisorHostHelper(com.cloud.hypervisor.vmware.mo.HypervisorHostHelper) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) DiscoveryException(com.cloud.exception.DiscoveryException) StoragePoolStatus(com.cloud.storage.StoragePoolStatus) Random(java.util.Random) StoragePool(com.cloud.storage.StoragePool) UriUtils(com.cloud.utils.UriUtils) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Cluster(com.cloud.org.Cluster) Logger(org.apache.log4j.Logger) StartupCommand(com.cloud.agent.api.StartupCommand) CommandExecLogDao(com.cloud.secstorage.CommandExecLogDao) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) URI(java.net.URI) Answer(com.cloud.agent.api.Answer) Config(com.cloud.configuration.Config) VmwareHostType(com.cloud.hypervisor.vmware.mo.VmwareHostType) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) PrimaryDataStoreDao(org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao) TransactionCallback(com.cloud.utils.db.TransactionCallback) UUID(java.util.UUID) Pair(com.cloud.utils.Pair) Instant(java.time.Instant) VsphereStoragePolicyVO(com.cloud.dc.VsphereStoragePolicyVO) HostFirewallSystemMO(com.cloud.hypervisor.vmware.mo.HostFirewallSystemMO) Collectors(java.util.stream.Collectors) CheckDataStoreStoragePolicyComplainceCommand(org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand) RemoteException(java.rmi.RemoteException) Status(com.cloud.host.Status) List(java.util.List) DataCenterDao(com.cloud.dc.dao.DataCenterDao) DiskControllerType(com.cloud.hypervisor.vmware.mo.DiskControllerType) AboutInfo(com.vmware.vim25.AboutInfo) VmwareDatacenterZoneMapVO(com.cloud.hypervisor.vmware.VmwareDatacenterZoneMapVO) BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) DataStoreManager(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager) HashMap(java.util.HashMap) ListVsphereStoragePoliciesCmd(org.apache.cloudstack.api.command.admin.zone.ListVsphereStoragePoliciesCmd) ConfigurationException(javax.naming.ConfigurationException) EventTypes(com.cloud.event.EventTypes) CollectionUtils(com.amazonaws.util.CollectionUtils) Inject(javax.inject.Inject) ConfigKey(org.apache.cloudstack.framework.config.ConfigKey) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Listener(com.cloud.agent.Listener) ListVmwareDcsCmd(org.apache.cloudstack.api.command.admin.zone.ListVmwareDcsCmd) SshHelper(com.cloud.utils.ssh.SshHelper) PbmProfile(com.vmware.pbm.PbmProfile) CiscoNexusVSMDeviceDao(com.cloud.network.dao.CiscoNexusVSMDeviceDao) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) Configurable(org.apache.cloudstack.framework.config.Configurable) ListVsphereStoragePolicyCompatiblePoolsCmd(org.apache.cloudstack.api.command.admin.zone.ListVsphereStoragePolicyCompatiblePoolsCmd) ManagementServerNode(org.apache.cloudstack.utils.identity.ManagementServerNode) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) HostVO(com.cloud.host.HostVO) VsphereStoragePolicyDao(com.cloud.dc.dao.VsphereStoragePolicyDao) MapUtils(org.apache.commons.collections.MapUtils) VmwareDatacenterZoneMapDao(com.cloud.hypervisor.vmware.dao.VmwareDatacenterZoneMapDao) CustomFieldConstants(com.cloud.hypervisor.vmware.mo.CustomFieldConstants) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) Hypervisor(com.cloud.hypervisor.Hypervisor) LegacyZoneVO(com.cloud.hypervisor.vmware.LegacyZoneVO) FileInputStream(java.io.FileInputStream) PbmProfileManagerMO(com.cloud.hypervisor.vmware.mo.PbmProfileManagerMO) ImportVsphereStoragePoliciesCmd(org.apache.cloudstack.api.command.admin.zone.ImportVsphereStoragePoliciesCmd) HostDetailsDao(com.cloud.host.dao.HostDetailsDao) TimeUnit(java.util.concurrent.TimeUnit) TemplateJoinDao(com.cloud.api.query.dao.TemplateJoinDao) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VmwareTrafficLabel(com.cloud.network.VmwareTrafficLabel) VmwareDatacenterVO(com.cloud.hypervisor.vmware.VmwareDatacenterVO) VmwareDatacenterService(com.cloud.hypervisor.vmware.VmwareDatacenterService) DigestUtils(org.apache.commons.codec.digest.DigestUtils) StorageLayer(com.cloud.storage.StorageLayer) Collections(java.util.Collections) ManagementServerHost(org.apache.cloudstack.management.ManagementServerHost) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) PbmProfile(com.vmware.pbm.PbmProfile) VmwareDatacenterVO(com.cloud.hypervisor.vmware.VmwareDatacenterVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PbmProfileManagerMO(com.cloud.hypervisor.vmware.mo.PbmProfileManagerMO) DiscoveredWithErrorException(com.cloud.exception.DiscoveredWithErrorException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) DiscoveryException(com.cloud.exception.DiscoveryException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) RemoteException(java.rmi.RemoteException) ConfigurationException(javax.naming.ConfigurationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) VsphereStoragePolicyVO(com.cloud.dc.VsphereStoragePolicyVO)

Example 9 with VmwareDatacenterVO

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

the class VmwareManagerImplTest method beforeTest.

@Before
public void beforeTest() {
    VmwareDatacenterZoneMapVO vmwareDatacenterZoneMap = new VmwareDatacenterZoneMapVO();
    vmwareDatacenterZoneMap.setZoneId(1);
    vmwareDatacenterZoneMap.setVmwareDcId(1);
    VmwareDatacenterVO vmwareDatacenterVO = new VmwareDatacenterVO(1, "some-guid", "some-name", "10.1.1.1", "username", "password");
    Mockito.doReturn(vmwareDatacenterZoneMap).when(vmwareDatacenterZoneMapDao).findByZoneId(Mockito.anyLong());
    Mockito.doReturn(vmwareDatacenterVO).when(vmwareDcDao).findById(Mockito.anyLong());
    Mockito.doReturn(1L).when(updateVmwareDcCmd).getZoneId();
}
Also used : VmwareDatacenterZoneMapVO(com.cloud.hypervisor.vmware.VmwareDatacenterZoneMapVO) VmwareDatacenterVO(com.cloud.hypervisor.vmware.VmwareDatacenterVO) Before(org.junit.Before)

Aggregations

VmwareDatacenterVO (com.cloud.hypervisor.vmware.VmwareDatacenterVO)9 VmwareDatacenterZoneMapVO (com.cloud.hypervisor.vmware.VmwareDatacenterZoneMapVO)6 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 ResourceInUseException (com.cloud.exception.ResourceInUseException)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 DiscoveryException (com.cloud.exception.DiscoveryException)3 DatacenterMO (com.cloud.hypervisor.vmware.mo.DatacenterMO)3 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)3 ActionEvent (com.cloud.event.ActionEvent)2 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)2 DiscoveredWithErrorException (com.cloud.exception.DiscoveredWithErrorException)2 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)2 Host (com.cloud.host.Host)2 TransactionStatus (com.cloud.utils.db.TransactionStatus)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)2 RemoteException (java.rmi.RemoteException)2 CollectionUtils (com.amazonaws.util.CollectionUtils)1 AgentManager (com.cloud.agent.AgentManager)1 Listener (com.cloud.agent.Listener)1 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1