Java 类com.vmware.vim25.HostHostBusAdapter 实例源码

项目:cloudstack    文件:VmwareResource.java   
private String getIqn() {
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());

        if (hyperHost instanceof HostMO) {
            HostMO host = (HostMO)hyperHost;
            HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO();

            for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) {
                if (hba instanceof HostInternetScsiHba) {
                    HostInternetScsiHba hostInternetScsiHba = (HostInternetScsiHba)hba;

                    if (hostInternetScsiHba.isIsSoftwareBased()) {
                        return ((HostInternetScsiHba)hba).getIScsiName();
                    }
                }
            }
        }
    } catch (Exception ex) {
        s_logger.info("Could not locate an IQN for this host.");
    }

    return null;
}
项目:vijava    文件:PrintStorageSystem.java   
static void printHBAs(HostHostBusAdapter[] hbas)
{
  for(int i=0; hbas!=null && i<hbas.length; i++)
  {
    System.out.println("Device:" + hbas[i].getDevice());
    System.out.println("Bus:" + hbas[i].getBus());
    System.out.println("Driver:" + hbas[i].getDriver());
    System.out.println("Key:" + hbas[i].getKey());
    System.out.println("Model:" + hbas[i].getModel());
    System.out.println("PCI:" + hbas[i].getPci());
    System.out.println("Status:" + hbas[i].getStatus());
  }
}
项目:cloudstack    文件:VmwareStorageProcessor.java   
private HostDiscoveryMethod getHostDiscoveryMethod(String address, List<HostMO> lstHosts) throws Exception {
    List<HostMO> hostsUsingDynamicDiscovery = new ArrayList<>();
    List<HostMO> hostsUsingStaticDiscovery = new ArrayList<>();

    for (HostMO host : lstHosts) {
        boolean usingDynamicDiscovery = false;

        HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO();

        for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) {
            if (hba instanceof HostInternetScsiHba) {
                HostInternetScsiHba hostInternetScsiHba = (HostInternetScsiHba)hba;

                if (hostInternetScsiHba.isIsSoftwareBased()) {
                    List<HostInternetScsiHbaSendTarget> sendTargets = hostInternetScsiHba.getConfiguredSendTarget();

                    if (sendTargets != null) {
                        for (HostInternetScsiHbaSendTarget sendTarget : sendTargets) {
                            String sendTargetAddress = sendTarget.getAddress();

                            if (sendTargetAddress.contains(address)) {
                                usingDynamicDiscovery = true;
                            }
                        }
                    }
                }
            }
        }

        if (usingDynamicDiscovery) {
            hostsUsingDynamicDiscovery.add(host);
        }
        else {
            hostsUsingStaticDiscovery.add(host);
        }
    }

    return new HostDiscoveryMethod(hostsUsingDynamicDiscovery, hostsUsingStaticDiscovery);
}
项目:cloudstack    文件:VmwareStorageProcessor.java   
private void addRemoveInternetScsiTargetsToAllHosts(boolean add, List<HostInternetScsiHbaStaticTarget> targets,
                                                    List<HostMO> hosts) throws Exception {
    ExecutorService executorService = Executors.newFixedThreadPool(hosts.size());

    final List<Exception> exceptions = new ArrayList<>();

    for (HostMO host : hosts) {
        HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO();

        boolean iScsiHbaConfigured = false;

        for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) {
            if (hba instanceof HostInternetScsiHba && ((HostInternetScsiHba)hba).isIsSoftwareBased()) {
                iScsiHbaConfigured = true;

                final String iScsiHbaDevice = hba.getDevice();

                final HostStorageSystemMO hss = hostStorageSystem;

                executorService.submit(new Thread(() -> {
                    try {
                        if (add) {
                            hss.addInternetScsiStaticTargets(iScsiHbaDevice, targets);
                        } else {
                            hss.removeInternetScsiStaticTargets(iScsiHbaDevice, targets);
                        }
                    } catch (Exception ex) {
                        synchronized (exceptions) {
                            exceptions.add(ex);
                        }
                    }
                }));
            }
        }

        if (!iScsiHbaConfigured) {
            throw new Exception("An iSCSI HBA must be configured before a host can use iSCSI storage.");
        }
    }

    executorService.shutdown();

    if (!executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MINUTES)) {
        throw new Exception("The system timed out before completing the task 'addRemoveInternetScsiTargetsToAllHosts'.");
    }

    if (exceptions.size() > 0) {
        throw new Exception(exceptions.get(0).getMessage());
    }
}
项目:cloudstack    文件:VmwareStorageProcessor.java   
private void rescanAllHosts(List<HostMO> lstHosts, boolean rescanHba, boolean rescanVmfs) throws Exception {
    if (!rescanHba && !rescanVmfs) {
        // nothing to do
        return;
    }

    ExecutorService executorService = Executors.newFixedThreadPool(lstHosts.size());

    final List<Exception> exceptions = new ArrayList<>();

    for (HostMO host : lstHosts) {
        HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO();

        boolean iScsiHbaConfigured = false;

        for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) {
            if (hba instanceof HostInternetScsiHba && ((HostInternetScsiHba)hba).isIsSoftwareBased()) {
                iScsiHbaConfigured = true;

                final String iScsiHbaDevice = hba.getDevice();

                final HostStorageSystemMO hss = hostStorageSystem;

                executorService.submit(new Thread(() -> {
                    try {
                        if (rescanHba) {
                            hss.rescanHba(iScsiHbaDevice);
                        }

                        if (rescanVmfs) {
                            hss.rescanVmfs();
                        }
                    } catch (Exception ex) {
                        synchronized (exceptions) {
                            exceptions.add(ex);
                        }
                    }
                }));
            }
        }

        if (!iScsiHbaConfigured) {
            throw new Exception("An iSCSI HBA must be configured before a host can use iSCSI storage.");
        }
    }

    executorService.shutdown();

    if (!executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MINUTES)) {
        throw new Exception("The system timed out before completing the task 'rescanAllHosts'.");
    }

    if (exceptions.size() > 0) {
        throw new Exception(exceptions.get(0).getMessage());
    }
}
项目:cloudstack    文件:VmwareStorageProcessor.java   
private void removeManagedTargetsFromCluster(List<String> managedDatastoreNames) throws Exception {
    List<HostInternetScsiHbaStaticTarget> lstManagedTargets = new ArrayList<>();

    VmwareContext context = hostService.getServiceContext(null);
    VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
    ManagedObjectReference morCluster = hyperHost.getHyperHostCluster();
    ClusterMO cluster = new ClusterMO(context, morCluster);
    List<Pair<ManagedObjectReference, String>> lstHosts = cluster.getClusterHosts();
    HostMO hostMO = new HostMO(context, lstHosts.get(0).first());
    HostStorageSystemMO hostStorageSystem = hostMO.getHostStorageSystemMO();

    for (String managedDatastoreName : managedDatastoreNames) {
        unmountVmfsDatastore(context, hyperHost, managedDatastoreName, lstHosts);
    }

    for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) {
        if (hba instanceof HostInternetScsiHba && ((HostInternetScsiHba)hba).isIsSoftwareBased()) {
            List<HostInternetScsiHbaStaticTarget> lstTargets = ((HostInternetScsiHba)hba).getConfiguredStaticTarget();

            if (lstTargets != null) {
                for (HostInternetScsiHbaStaticTarget target : lstTargets) {
                    if (managedDatastoreNames.contains(VmwareResource.createDatastoreNameFromIqn(target.getIScsiName()))) {
                        lstManagedTargets.add(target);
                    }
                }
            }
        }
    }

    ExecutorService executorService = Executors.newFixedThreadPool(lstHosts.size());

    for (Pair<ManagedObjectReference, String> host : lstHosts) {
        List<Pair<ManagedObjectReference, String>> hosts = new ArrayList<>();

        hosts.add(host);

        List<HostInternetScsiHbaStaticTarget> staticTargetsForHost = new ArrayList<>();

        for (HostInternetScsiHbaStaticTarget iScsiManagedTarget : lstManagedTargets) {
            String storageAddress = iScsiManagedTarget.getAddress();

            HostDiscoveryMethod hostDiscoveryMethod = getHostDiscoveryMethod(context, storageAddress, hosts);
            List<HostMO> hostsUsingStaticDiscovery = hostDiscoveryMethod.getHostsUsingStaticDiscovery();

            if (hostsUsingStaticDiscovery != null && hostsUsingStaticDiscovery.size() > 0) {
                staticTargetsForHost.add(iScsiManagedTarget);
            }
        }

        if (staticTargetsForHost.size() > 0) {
            executorService.submit(new Thread(() -> {
                try {
                    addRemoveInternetScsiTargetsToAllHosts(context, false, staticTargetsForHost, hosts);

                    rescanAllHosts(context, hosts, true, false);
                }
                catch (Exception ex) {
                    s_logger.warn(ex.getMessage());
                }
            }));
        }
    }

    executorService.shutdown();

    if (!executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MINUTES)) {
        throw new Exception("The system timed out before completing the task 'removeManagedTargetsFromCluster'.");
    }
}