Search in sources :

Example 1 with VmwareHostService

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

the class VmwareResource method configure.

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    try {
        _name = name;
        _url = (String) params.get("url");
        _username = (String) params.get("username");
        _password = (String) params.get("password");
        _dcId = (String) params.get("zone");
        _pod = (String) params.get("pod");
        _cluster = (String) params.get("cluster");
        _guid = (String) params.get("guid");
        String[] tokens = _guid.split("@");
        _vCenterAddress = tokens[1];
        _morHyperHost = new ManagedObjectReference();
        String[] hostTokens = tokens[0].split(":");
        _morHyperHost.setType(hostTokens[0]);
        _morHyperHost.setValue(hostTokens[1]);
        _guestTrafficInfo = (VmwareTrafficLabel) params.get("guestTrafficInfo");
        _publicTrafficInfo = (VmwareTrafficLabel) params.get("publicTrafficInfo");
        VmwareContext context = getServiceContext();
        VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
        if (mgr == null) {
            throw new ConfigurationException("Invalid vmwareContext:  vmwareMgr stock object is not set or cleared.");
        }
        mgr.setupResourceStartupParams(params);
        CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(context, context.getServiceContent().getCustomFieldsManager());
        cfmMo.ensureCustomFieldDef("Datastore", CustomFieldConstants.CLOUD_UUID);
        if (_publicTrafficInfo != null && _publicTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch || _guestTrafficInfo != null && _guestTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch) {
            cfmMo.ensureCustomFieldDef("DistributedVirtualPortgroup", CustomFieldConstants.CLOUD_GC_DVP);
        }
        cfmMo.ensureCustomFieldDef("Network", CustomFieldConstants.CLOUD_GC);
        cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_UUID);
        cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_NIC_MASK);
        cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
        cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_WORKER);
        cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_WORKER_TAG);
        VmwareHypervisorHost hostMo = this.getHyperHost(context);
        _hostName = hostMo.getHyperHostName();
        if (_guestTrafficInfo.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch || _publicTrafficInfo.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch) {
            _privateNetworkVSwitchName = mgr.getPrivateVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware);
            _vsmCredentials = mgr.getNexusVSMCredentialsByClusterId(Long.parseLong(_cluster));
        }
        if (_privateNetworkVSwitchName == null) {
            _privateNetworkVSwitchName = (String) params.get("private.network.vswitch.name");
        }
        String value = (String) params.get("vmware.recycle.hung.wokervm");
        if (value != null && value.equalsIgnoreCase("true"))
            _recycleHungWorker = true;
        value = (String) params.get("vmware.root.disk.controller");
        if (value != null && value.equalsIgnoreCase("scsi"))
            _rootDiskController = DiskControllerType.scsi;
        else if (value != null && value.equalsIgnoreCase("ide"))
            _rootDiskController = DiskControllerType.ide;
        else
            _rootDiskController = DiskControllerType.osdefault;
        Integer intObj = (Integer) params.get("ports.per.dvportgroup");
        if (intObj != null)
            _portsPerDvPortGroup = intObj.intValue();
        s_logger.info("VmwareResource network configuration info." + " private traffic over vSwitch: " + _privateNetworkVSwitchName + ", public traffic over " + _publicTrafficInfo.getVirtualSwitchType() + " : " + _publicTrafficInfo.getVirtualSwitchName() + ", guest traffic over " + _guestTrafficInfo.getVirtualSwitchType() + " : " + _guestTrafficInfo.getVirtualSwitchName());
        Boolean boolObj = (Boolean) params.get("vmware.create.full.clone");
        if (boolObj != null && boolObj.booleanValue()) {
            _fullCloneFlag = true;
        } else {
            _fullCloneFlag = false;
        }
        boolObj = (Boolean) params.get("vm.instancename.flag");
        if (boolObj != null && boolObj.booleanValue()) {
            _instanceNameFlag = true;
        } else {
            _instanceNameFlag = false;
        }
        value = (String) params.get("scripts.timeout");
        int timeout = NumbersUtil.parseInt(value, 1440) * 1000;
        storageNfsVersion = NfsSecondaryStorageResource.retrieveNfsVersionFromParams(params);
        _storageProcessor = new VmwareStorageProcessor((VmwareHostService) this, _fullCloneFlag, (VmwareStorageMount) mgr, timeout, this, _shutdownWaitMs, null, storageNfsVersion);
        storageHandler = new VmwareStorageSubsystemCommandHandler(_storageProcessor, storageNfsVersion);
        _vrResource = new VirtualRoutingResource(this);
        if (!_vrResource.configure(name, params)) {
            throw new ConfigurationException("Unable to configure VirtualRoutingResource");
        }
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("Successfully configured VmwareResource.");
        }
        return true;
    } catch (Exception e) {
        s_logger.error("Unexpected Exception ", e);
        throw new ConfigurationException("Failed to configure VmwareResource due to unexpect exception.");
    } finally {
        recycleServiceContext();
    }
}
Also used : VmwareStorageProcessor(com.cloud.storage.resource.VmwareStorageProcessor) VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) VirtualRoutingResource(com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource) 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) CustomFieldsManagerMO(com.cloud.hypervisor.vmware.mo.CustomFieldsManagerMO) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VmwareStorageSubsystemCommandHandler(com.cloud.storage.resource.VmwareStorageSubsystemCommandHandler) ConfigurationException(javax.naming.ConfigurationException) VmwareHostService(com.cloud.hypervisor.vmware.manager.VmwareHostService) VmwareStorageMount(com.cloud.hypervisor.vmware.manager.VmwareStorageMount) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

VirtualRoutingResource (com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource)1 CloudException (com.cloud.exception.CloudException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 VmwareHostService (com.cloud.hypervisor.vmware.manager.VmwareHostService)1 VmwareManager (com.cloud.hypervisor.vmware.manager.VmwareManager)1 VmwareStorageMount (com.cloud.hypervisor.vmware.manager.VmwareStorageMount)1 CustomFieldsManagerMO (com.cloud.hypervisor.vmware.mo.CustomFieldsManagerMO)1 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)1 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)1 VmwareStorageProcessor (com.cloud.storage.resource.VmwareStorageProcessor)1 VmwareStorageSubsystemCommandHandler (com.cloud.storage.resource.VmwareStorageSubsystemCommandHandler)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ConnectException (java.net.ConnectException)1 RemoteException (java.rmi.RemoteException)1 ConfigurationException (javax.naming.ConfigurationException)1