Search in sources :

Example 1 with AlreadyExistsFaultMsg

use of com.vmware.vim25.AlreadyExistsFaultMsg in project cloudstack by apache.

the class HostMO method mountDatastore.

@Override
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.getValue() + ", vmfs: " + vmfsDatastore + ", poolHost: " + poolHostAddress + ", poolHostPort: " + poolHostPort + ", poolPath: " + poolPath + ", poolUuid: " + poolUuid);
    HostDatastoreSystemMO hostDatastoreSystemMo = getHostDatastoreSystemMO();
    ManagedObjectReference morDatastore = hostDatastoreSystemMo.findDatastore(poolUuid);
    if (morDatastore == null) {
        if (!vmfsDatastore) {
            try {
                morDatastore = hostDatastoreSystemMo.createNfsDatastore(poolHostAddress, poolHostPort, poolPath, poolUuid);
            } catch (AlreadyExistsFaultMsg e) {
                s_logger.info("Creation of NFS datastore on vCenter failed since datastore already exists." + " Details: vCenter API trace - mountDatastore(). target MOR: " + _mor.getValue() + ", vmfs: " + vmfsDatastore + ", poolHost: " + poolHostAddress + ", poolHostPort: " + poolHostPort + ", poolPath: " + poolPath + ", poolUuid: " + poolUuid);
                // Retrieve the morDatastore and return it.
                return (getExistingDataStoreOnHost(vmfsDatastore, poolHostAddress, poolHostPort, poolPath, poolUuid, hostDatastoreSystemMo));
            } catch (Exception e) {
                s_logger.info("Creation of NFS datastore on vCenter failed. " + " Details: vCenter API trace - mountDatastore(). target MOR: " + _mor.getValue() + ", vmfs: " + vmfsDatastore + ", poolHost: " + poolHostAddress + ", poolHostPort: " + poolHostPort + ", poolPath: " + poolPath + ", poolUuid: " + poolUuid + ". Exception mesg: " + e.getMessage());
                throw new Exception("Creation of NFS datastore on vCenter failed.");
            }
            if (morDatastore == null) {
                String msg = "Unable to create NFS datastore. host: " + poolHostAddress + ", port: " + poolHostPort + ", path: " + poolPath + ", uuid: " + poolUuid;
                s_logger.error(msg);
                if (s_logger.isTraceEnabled())
                    s_logger.trace("vCenter API trace - mountDatastore() done(failed)");
                throw new Exception(msg);
            }
        } else {
            morDatastore = _context.getDatastoreMorByPath(poolPath);
            if (morDatastore == null) {
                String msg = "Unable to create VMFS datastore. host: " + poolHostAddress + ", port: " + poolHostPort + ", path: " + poolPath + ", uuid: " + poolUuid;
                s_logger.error(msg);
                if (s_logger.isTraceEnabled())
                    s_logger.trace("vCenter API trace - mountDatastore() done(failed)");
                throw new Exception(msg);
            }
            DatastoreMO dsMo = new DatastoreMO(_context, morDatastore);
            dsMo.setCustomFieldValue(CustomFieldConstants.CLOUD_UUID, poolUuid);
        }
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - mountDatastore() done(successfully)");
    return morDatastore;
}
Also used : AlreadyExistsFaultMsg(com.vmware.vim25.AlreadyExistsFaultMsg) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 2 with AlreadyExistsFaultMsg

use of com.vmware.vim25.AlreadyExistsFaultMsg in project cloudstack by apache.

the class HypervisorHostHelper method setupPVlanPair.

private static void setupPVlanPair(DistributedVirtualSwitchMO dvSwitchMo, ManagedObjectReference morDvSwitch, Integer vid, Integer spvlanid) throws Exception {
    Map<Integer, HypervisorHostHelper.PvlanType> vlanmap = dvSwitchMo.retrieveVlanPvlan(vid, spvlanid, morDvSwitch);
    if (!vlanmap.isEmpty()) {
        // First the primary pvlan id.
        if (vlanmap.containsKey(vid) && !vlanmap.get(vid).equals(HypervisorHostHelper.PvlanType.promiscuous)) {
            // This VLAN ID is already setup as a non-promiscuous vlan id on the DVS. Throw an exception.
            String msg = "Specified primary PVLAN ID " + vid + " is already in use as a " + vlanmap.get(vid).toString() + " VLAN on the DVSwitch";
            s_logger.error(msg);
            throw new Exception(msg);
        }
        // Next the secondary pvlan id.
        if (spvlanid.equals(vid)) {
            if (vlanmap.containsKey(spvlanid) && !vlanmap.get(spvlanid).equals(HypervisorHostHelper.PvlanType.promiscuous)) {
                String msg = "Specified secondary PVLAN ID " + spvlanid + " is already in use as a " + vlanmap.get(spvlanid).toString() + " VLAN in the DVSwitch";
                s_logger.error(msg);
                throw new Exception(msg);
            }
        } else {
            if (vlanmap.containsKey(spvlanid) && !vlanmap.get(spvlanid).equals(HypervisorHostHelper.PvlanType.isolated)) {
                // This PVLAN ID is already setup as a non-isolated vlan id on the DVS. Throw an exception.
                String msg = "Specified secondary PVLAN ID " + spvlanid + " is already in use as a " + vlanmap.get(spvlanid).toString() + " VLAN in the DVSwitch";
                s_logger.error(msg);
                throw new Exception(msg);
            }
        }
    }
    // First create a DVSconfig spec.
    VMwareDVSConfigSpec dvsSpec = new VMwareDVSConfigSpec();
    // Next, add the required primary and secondary vlan config specs to the dvs config spec.
    if (!vlanmap.containsKey(vid)) {
        VMwareDVSPvlanConfigSpec ppvlanConfigSpec = createDVPortPvlanConfigSpec(vid, vid, PvlanType.promiscuous, PvlanOperation.add);
        dvsSpec.getPvlanConfigSpec().add(ppvlanConfigSpec);
    }
    if (!vid.equals(spvlanid) && !vlanmap.containsKey(spvlanid)) {
        VMwareDVSPvlanConfigSpec spvlanConfigSpec = createDVPortPvlanConfigSpec(vid, spvlanid, PvlanType.isolated, PvlanOperation.add);
        dvsSpec.getPvlanConfigSpec().add(spvlanConfigSpec);
    }
    if (dvsSpec.getPvlanConfigSpec().size() > 0) {
        // We have something to configure on the DVS... so send it the command.
        // When reconfiguring a vmware DVSwitch, we need to send in the configVersion in the spec.
        // Let's retrieve this switch's configVersion first.
        String dvsConfigVersion = dvSwitchMo.getDVSConfigVersion(morDvSwitch);
        dvsSpec.setConfigVersion(dvsConfigVersion);
        // Reconfigure the dvs using this spec.
        try {
            dvSwitchMo.updateVMWareDVSwitchGetTask(morDvSwitch, dvsSpec);
        } catch (AlreadyExistsFaultMsg e) {
            s_logger.info("Specified vlan id (" + vid + ") private vlan id (" + spvlanid + ") tuple already configured on VMWare DVSwitch");
        // Do nothing, good if the tuple's already configured on the dvswitch.
        } catch (Exception e) {
            // Rethrow the exception
            s_logger.error("Failed to configure vlan/pvlan tuple on VMware DVSwitch: " + vid + "/" + spvlanid + ", failure message: ", e);
            throw e;
        }
    }
}
Also used : AlreadyExistsFaultMsg(com.vmware.vim25.AlreadyExistsFaultMsg) VMwareDVSConfigSpec(com.vmware.vim25.VMwareDVSConfigSpec) VMwareDVSPvlanConfigSpec(com.vmware.vim25.VMwareDVSPvlanConfigSpec) URISyntaxException(java.net.URISyntaxException) InvalidParameterException(java.security.InvalidParameterException) CloudException(com.cloud.exception.CloudException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

AlreadyExistsFaultMsg (com.vmware.vim25.AlreadyExistsFaultMsg)2 CloudException (com.cloud.exception.CloudException)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)1 VMwareDVSConfigSpec (com.vmware.vim25.VMwareDVSConfigSpec)1 VMwareDVSPvlanConfigSpec (com.vmware.vim25.VMwareDVSPvlanConfigSpec)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 InvalidParameterException (java.security.InvalidParameterException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 SAXException (org.xml.sax.SAXException)1