Search in sources :

Example 6 with WindowsSystemWinRM

use of com.iwave.ext.windows.WindowsSystemWinRM 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)

Example 7 with WindowsSystemWinRM

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

the class WindowsHostDiscoveryAdapter method createWindowsSystem.

public static WindowsSystemWinRM createWindowsSystem(Host host) {
    boolean ssl = (host.getUseSSL() != null) ? host.getUseSSL() : false;
    int port = (host.getPortNumber() != null) ? host.getPortNumber() : (ssl ? WinRMTarget.DEFAULT_HTTPS_PORT : WinRMTarget.DEFAULT_HTTP_PORT);
    WinRMTarget target = new WinRMTarget(host.getHostName(), port, ssl, host.getUsername(), host.getPassword());
    return new WindowsSystemWinRM(target);
}
Also used : WindowsSystemWinRM(com.iwave.ext.windows.WindowsSystemWinRM) WinRMTarget(com.iwave.ext.windows.winrm.WinRMTarget)

Example 8 with WindowsSystemWinRM

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

the class MountBlockVolumeHelper method createHelpers.

public static List<MountBlockVolumeHelper> createHelpers(List<WindowsSystemWinRM> windowsSystems, long volumeCapacityInBytes) {
    List<MountBlockVolumeHelper> helpers = Lists.newArrayList();
    for (WindowsSystemWinRM windowsSystem : windowsSystems) {
        WindowsSupport windowsSupport = new WindowsSupport(windowsSystem);
        MountBlockVolumeHelper mountBlockVolumeHelper = new MountBlockVolumeHelper(windowsSupport, volumeCapacityInBytes);
        BindingUtils.bind(mountBlockVolumeHelper, ExecutionUtils.currentContext().getParameters());
        helpers.add(mountBlockVolumeHelper);
    }
    return helpers;
}
Also used : WindowsSystemWinRM(com.iwave.ext.windows.WindowsSystemWinRM)

Example 9 with WindowsSystemWinRM

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

the class UnmountBlockVolumeHelper method createHelpers.

public static List<UnmountBlockVolumeHelper> createHelpers(URI hostId, List<WindowsSystemWinRM> windowsSystems) {
    List<UnmountBlockVolumeHelper> helpers = Lists.newArrayList();
    for (WindowsSystemWinRM windowsSystem : windowsSystems) {
        WindowsSupport windowsSupport = new WindowsSupport(windowsSystem);
        UnmountBlockVolumeHelper unmountBlockVolumeHelper = new UnmountBlockVolumeHelper(hostId, windowsSupport);
        BindingUtils.bind(unmountBlockVolumeHelper, ExecutionUtils.currentContext().getParameters());
        helpers.add(unmountBlockVolumeHelper);
    }
    return helpers;
}
Also used : WindowsSystemWinRM(com.iwave.ext.windows.WindowsSystemWinRM)

Example 10 with WindowsSystemWinRM

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

the class WindowsHostConnectionValidator method validateConnection.

@Override
public boolean validateConnection(HostParam hostParam, Host existingHost) {
    HostType hostType = HostType.valueOf(hostParam.getType());
    if (getType().equals(hostType) == false) {
        throw new IllegalStateException(String.format("Invalid HostType [%s]", hostParam.getType()));
    }
    String password = hostParam.getPassword();
    if (password == null && existingHost != null) {
        password = existingHost.getPassword();
    }
    List<URI> authProviderIds = dbClient.queryByType(AuthnProvider.class, true);
    List<AuthnProvider> authProviders = dbClient.queryObject(AuthnProvider.class, authProviderIds);
    KerberosUtil.initializeKerberos(authProviders);
    WinRMTarget target = new WinRMTarget(hostParam.getHostName(), hostParam.getPortNumber(), hostParam.getUseSsl(), hostParam.getUserName(), password);
    WindowsSystemWinRM cli = new WindowsSystemWinRM(target);
    try {
        cli.listDiskDrives();
        return true;
    } catch (Exception e) {
        log.error(String.format("Error Validating Host %s", hostParam.getName()), e);
    }
    return false;
}
Also used : HostType(com.emc.storageos.db.client.model.Host.HostType) WindowsSystemWinRM(com.iwave.ext.windows.WindowsSystemWinRM) AuthnProvider(com.emc.storageos.db.client.model.AuthnProvider) WinRMTarget(com.iwave.ext.windows.winrm.WinRMTarget) URI(java.net.URI)

Aggregations

WindowsSystemWinRM (com.iwave.ext.windows.WindowsSystemWinRM)10 WinRMException (com.iwave.ext.windows.winrm.WinRMException)4 URI (java.net.URI)3 WinRMTarget (com.iwave.ext.windows.winrm.WinRMTarget)2 ArrayList (java.util.ArrayList)2 AuthnProvider (com.emc.storageos.db.client.model.AuthnProvider)1 HostType (com.emc.storageos.db.client.model.Host.HostType)1 Initiator (com.emc.storageos.db.client.model.Initiator)1 IpInterface (com.emc.storageos.db.client.model.IpInterface)1 WinRMSoapException (com.iwave.ext.windows.winrm.WinRMSoapException)1 List (java.util.List)1