Search in sources :

Example 1 with WinRMException

use of com.iwave.ext.windows.winrm.WinRMException in project coprhd-controller by CoprHD.

the class WindowsHostDiscoveryAdapter method setNativeGuid.

@Override
protected void setNativeGuid(Host host) {
    WindowsSystemWinRM windows = createWindowsSystem(host);
    try {
        NetworkAdapter adapter = getPrimaryNetworkAdapter(windows.listNetworkAdapters());
        if (adapter != null && !host.getNativeGuid().equalsIgnoreCase(adapter.getMacAddress())) {
            checkDuplicateHost(host, adapter.getMacAddress());
            info("Setting nativeGuid for " + host.getId() + " as " + adapter.getMacAddress());
            host.setNativeGuid(adapter.getMacAddress());
            save(host);
        }
    } catch (WinRMException e) {
        throw new RuntimeException(e);
    }
}
Also used : WindowsSystemWinRM(com.iwave.ext.windows.WindowsSystemWinRM) WinRMException(com.iwave.ext.windows.winrm.WinRMException)

Example 2 with WinRMException

use of com.iwave.ext.windows.winrm.WinRMException in project coprhd-controller by CoprHD.

the class WindowsSystemWinRM method diskPart.

public String diskPart(List<String> commands) throws WinRMException {
    StrBuilder sb = new StrBuilder();
    sb.append("(");
    for (int i = 0; i < commands.size(); i++) {
        sb.appendSeparator(" && ", i);
        sb.append("echo ").append(commands.get(i));
    }
    sb.append(" && echo EXIT) | (CHCP 437 & DISKPART)");
    CommandOutput output = executeCommand(sb.toString());
    String error = WindowsUtils.getDiskPartError(output);
    if (StringUtils.isNotBlank(error)) {
        error("DiskPart Error: %s", error);
        throw new WinRMException(String.format("DiskPart Error: %s", error));
    }
    return output.getStdout();
}
Also used : WinRMException(com.iwave.ext.windows.winrm.WinRMException) CommandOutput(com.iwave.ext.command.CommandOutput) StrBuilder(org.apache.commons.lang.text.StrBuilder)

Example 3 with WinRMException

use of com.iwave.ext.windows.winrm.WinRMException in project coprhd-controller by CoprHD.

the class WindowsHostDiscoveryAdapter method discoverIpInterfaces.

@Override
protected void discoverIpInterfaces(Host host, List<IpInterface> oldIpInterfaces) {
    WindowsSystemWinRM windows = createWindowsSystem(host);
    try {
        for (NetworkAdapter adapter : windows.listNetworkAdapters()) {
            if (StringUtils.isNotBlank(adapter.getIpAddress())) {
                IpInterface ipInterface = getOrCreateIpInterface(oldIpInterfaces, adapter.getIpAddress());
                discoverIp4Interface(host, ipInterface, adapter);
            }
            if (StringUtils.isNotBlank(adapter.getIp6Address())) {
                IpInterface ipInterface = getOrCreateIpInterface(oldIpInterfaces, adapter.getIp6Address());
                discoverIp6Interface(host, ipInterface, adapter);
            }
        }
    } catch (WinRMException e) {
        warn(e, "Error while retrieving IP interfaces: %s", e.getMessage());
        oldIpInterfaces.clear();
    }
}
Also used : IpInterface(com.emc.storageos.db.client.model.IpInterface) WindowsSystemWinRM(com.iwave.ext.windows.WindowsSystemWinRM) WinRMException(com.iwave.ext.windows.winrm.WinRMException)

Example 4 with WinRMException

use of com.iwave.ext.windows.winrm.WinRMException in project coprhd-controller by CoprHD.

the class WindowsHostDiscoveryAdapter method discoverInitiators.

@Override
protected void discoverInitiators(Host host, List<Initiator> oldInitiators, HostStateChange changes) {
    WindowsSystemWinRM windows = createWindowsSystem(host);
    List<Initiator> addedInitiators = new ArrayList<Initiator>();
    try {
        for (FibreChannelHBA hba : windows.listFibreChannelHBAs()) {
            Initiator initiator;
            if (findInitiatorByPort(oldInitiators, hba.getPortWWN()) == null) {
                initiator = getOrCreateInitiator(host.getId(), oldInitiators, hba.getPortWWN());
                addedInitiators.add(initiator);
            } else {
                initiator = getOrCreateInitiator(host.getId(), oldInitiators, hba.getPortWWN());
            }
            discoverFCInitiator(host, initiator, hba);
        }
    } catch (WinRMSoapException e) {
        info("Could not retrieve fibre channel HBAs: %s", e.getMessage());
        clearInitiators(oldInitiators, Protocol.FC.name());
    } catch (WinRMException e) {
        warn(e, "Error while retrieving fibre channel HBAs: %s", e.getMessage());
        clearInitiators(oldInitiators, Protocol.FC.name());
    }
    try {
        for (String iqn : windows.listIScsiInitiators()) {
            Initiator initiator;
            if (findInitiatorByPort(oldInitiators, iqn) == null) {
                initiator = getOrCreateInitiator(host.getId(), oldInitiators, iqn);
                addedInitiators.add(initiator);
            } else {
                initiator = getOrCreateInitiator(host.getId(), oldInitiators, iqn);
            }
            discoverISCSIInitiator(host, initiator, iqn);
        }
    } catch (WinRMSoapException e) {
        info("Could not retrieve iSCSI interfaces: %s", e.getMessage());
        clearInitiators(oldInitiators, Protocol.iSCSI.name());
    } catch (WinRMException e) {
        warn(e, "Error while retrieving iSCSI interfaces: %s", e.getMessage());
        clearInitiators(oldInitiators, Protocol.iSCSI.name());
    }
    // update export groups with new initiators if host is in use.
    if (!addedInitiators.isEmpty()) {
        Collection<URI> addedInitiatorIds = Lists.newArrayList(Collections2.transform(addedInitiators, CommonTransformerFunctions.fctnDataObjectToID()));
        changes.setNewInitiators(addedInitiatorIds);
    }
}
Also used : WindowsSystemWinRM(com.iwave.ext.windows.WindowsSystemWinRM) WinRMException(com.iwave.ext.windows.winrm.WinRMException) Initiator(com.emc.storageos.db.client.model.Initiator) ArrayList(java.util.ArrayList) WinRMSoapException(com.iwave.ext.windows.winrm.WinRMSoapException) URI(java.net.URI)

Example 5 with WinRMException

use of com.iwave.ext.windows.winrm.WinRMException in project coprhd-controller by CoprHD.

the class WindowsHostDiscoveryAdapter method findCluster.

protected URI findCluster(Host host) {
    WindowsSystemWinRM system = createWindowsSystem(host);
    try {
        if (system.isClustered()) {
            Map<String, List<MSClusterNetworkInterface>> clusterToNetworkInterfaces = system.getClusterToNetworkInterfaces();
            String clusterName = WindowsClusterUtils.findWindowsClusterHostIsIn(host.getHostName(), clusterToNetworkInterfaces);
            if (clusterName == null) {
                if (clusterToNetworkInterfaces.size() == 1) {
                    clusterName = clusterToNetworkInterfaces.keySet().iterator().next();
                } else if (clusterToNetworkInterfaces.isEmpty()) {
                    warn("Host '%s' appears to be clustered, but cannot find any cluster interfaces", host.getHostName());
                    return NullColumnValueGetter.getNullURI();
                } else {
                    warn("Host '%s' is configured in multiple clusters %s, cannot determine primary cluster by network interface", host.getHostName(), clusterToNetworkInterfaces.keySet());
                    return NullColumnValueGetter.getNullURI();
                }
            }
            List<String> clusterIpAddresses = WindowsClusterUtils.getClusterIpAddresses(clusterToNetworkInterfaces.get(clusterName));
            // Find the cluster by address
            URI cluster = findClusterByAddresses(host, host.getTenant(), HostType.Windows, clusterIpAddresses);
            if (cluster != null) {
                updateClusterName(cluster, clusterName);
                return cluster;
            }
            // Find the cluster by name
            cluster = findClusterByName(host.getTenant(), clusterName);
            if (cluster != null) {
                // Ensure the cluster is empty before using it or if host already belongs to this cluster
                if (Iterables.isEmpty(getModelClient().hosts().findByCluster(cluster, true)) || (!NullColumnValueGetter.isNullURI(host.getCluster()) && host.getCluster().toString().equals(cluster.toString()))) {
                    updateClusterName(cluster, clusterName);
                    return cluster;
                }
                // Log a warning
                warn("Host '%s' is in a cluster named '%s' which could not be matched by address. " + "An existing non-empty ViPR cluster exists with the same name; " + "manual cluster assignment required", host.getHostName(), clusterName);
                return NullColumnValueGetter.getNullURI();
            }
            // No cluster matched by address or name, create a new one
            return createNewCluster(host.getTenant(), clusterName);
        }
        // Host is not currently in a Windows Cluster
        return NullColumnValueGetter.getNullURI();
    } catch (WinRMException e) {
        throw new RuntimeException(e);
    }
}
Also used : WindowsSystemWinRM(com.iwave.ext.windows.WindowsSystemWinRM) WinRMException(com.iwave.ext.windows.winrm.WinRMException) ArrayList(java.util.ArrayList) List(java.util.List) URI(java.net.URI)

Aggregations

WinRMException (com.iwave.ext.windows.winrm.WinRMException)5 WindowsSystemWinRM (com.iwave.ext.windows.WindowsSystemWinRM)4 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Initiator (com.emc.storageos.db.client.model.Initiator)1 IpInterface (com.emc.storageos.db.client.model.IpInterface)1 CommandOutput (com.iwave.ext.command.CommandOutput)1 WinRMSoapException (com.iwave.ext.windows.winrm.WinRMSoapException)1 List (java.util.List)1 StrBuilder (org.apache.commons.lang.text.StrBuilder)1