Java 类com.vmware.vim25.mo.Datastore 实例源码

项目:newrelic-pcf-drain    文件:VSphereMetricsForwarder.java   
@Scheduled(fixedRateString = "${collection.interval:30000}")
public void forwardMetricsToInsights() throws InvalidProperty, RuntimeFault, RemoteException {
    long start = startTiming();
    int datastoreCount = 0;
    for (String name : datastores) {
        Datastore datastore = (Datastore) inventoryNavigator.searchManagedEntity("Datastore",
                name);
        if (datastore != null) {
            Map<String, Object> attributes = Maps.newHashMap();
            attributes.put("platform_instance", cfInstanceName);
            attributes.put("type", "datastore");
            attributes.put("name", name);
            attributes.put("capacity", bytesToGb(datastore.getSummary().getCapacity()));
            attributes.put("free_space", bytesToGb(datastore.getSummary().getFreeSpace()));
            attributes.put("uncommitted", bytesToGb(datastore.getSummary().getUncommitted()));
            insights.recordCustomEvent("cf_iaas_metrics", attributes);
            datastoreCount++;
        } else {
            LOG.error("Unable to find datastore {}", name);
        }
    }
    endTiming(start, datastoreCount);
}
项目:cf-new-relic-drain    文件:VSphereMetricsForwarder.java   
@Scheduled(fixedRateString = "${collection.interval:30000}")
public void forwardMetricsToInsights() throws InvalidProperty, RuntimeFault, RemoteException {
    long start = startTiming();
    int datastoreCount = 0;
    for (String name : datastores) {
        Datastore datastore = (Datastore) inventoryNavigator.searchManagedEntity("Datastore",
                name);
        if (datastore != null) {
            Map<String, Object> attributes = Maps.newHashMap();
            attributes.put("platform_instance", cfInstanceName);
            attributes.put("type", "datastore");
            attributes.put("name", name);
            attributes.put("capacity", bytesToGb(datastore.getSummary().getCapacity()));
            attributes.put("free_space", bytesToGb(datastore.getSummary().getFreeSpace()));
            attributes.put("uncommitted", bytesToGb(datastore.getSummary().getUncommitted()));
            insights.recordCustomEvent("cf_iaas_metrics", attributes);
            datastoreCount++;
        } else {
            LOG.error("Unable to find datastore {}", name);
        }
    }
    endTiming(start, datastoreCount);
}
项目:vijava    文件:VmDiskOp.java   
static String getFreeDatastoreName(VirtualMachine vm, 
    int size) throws Exception
{
  String dsName = null;
  Datastore[] datastores = vm.getDatastores();
  for(int i=0; i<datastores.length; i++) 
  {
    DatastoreSummary ds = datastores[i].getSummary(); 
    if(ds.getFreeSpace() > size) 
    {
      dsName = ds.getName();
      break;           
    }
  }
  return dsName;
}
项目:jcloud-vsphere    文件:MasterToVirtualMachineCloneSpec.java   
@Inject
public MasterToVirtualMachineCloneSpec(ResourcePool resourcePool, Datastore datastore, String cloningStrategy, String linuxName, boolean postConfiguration) {
   this.resourcePool = resourcePool;
   this.datastore = datastore;
   this.cloningStrategy = cloningStrategy;
   this.linuxName = linuxName;
   this.postConfiguration = postConfiguration;
}
项目:jcloud-vsphere    文件:MasterToVirtualMachineCloneSpec.java   
private VirtualMachineRelocateSpec configureRelocateSpec(ResourcePool resourcePool, Datastore datastore, VirtualMachine master)
        throws Exception, InvalidProperty, RuntimeFault, RemoteException {
   VirtualMachineRelocateSpec rSpec = new VirtualMachineRelocateSpec();
   if (cloningStrategy.equals("linked")) {
      ArrayList<Integer> diskKeys = getIndependentVirtualDiskKeys(master);
      if (diskKeys.size() > 0) {
         Datastore[] dss = master.getDatastores();

         VirtualMachineRelocateSpecDiskLocator[] diskLocator = new VirtualMachineRelocateSpecDiskLocator[diskKeys.size()];
         int count = 0;
         for (Integer key : diskKeys) {
            diskLocator[count] = new VirtualMachineRelocateSpecDiskLocator();
            diskLocator[count].setDatastore(dss[0].getMOR());
            diskLocator[count]
                    .setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.moveAllDiskBackingsAndDisallowSharing
                            .toString());
            diskLocator[count].setDiskId(key);
            count = count + 1;
         }
         rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.createNewChildDiskBacking.toString());
         rSpec.setDisk(diskLocator);
      } else {
         rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.createNewChildDiskBacking.toString());
      }
   } else if (cloningStrategy.equals("full")) {
      rSpec.setDatastore(datastore.getMOR());
      rSpec.setPool(resourcePool.getMOR());
      //rSpec.setHost();
   } else
      throw new Exception(String.format("Cloning strategy %s not supported", cloningStrategy));
   return rSpec;
}
项目:jcloud-vsphere    文件:VSphereHost.java   
public Datastore getDatastore() {
   Datastore datastore = null;
   long freeSpace = 0;
   try {
      for (Datastore d : host.getDatastores()) {
         if (d.getSummary().getFreeSpace() > freeSpace) {
            freeSpace = d.getSummary().getFreeSpace();
            datastore = d;
         }
      }
   } catch (Throwable e) {
      Throwables.propagate(e);
   }
   return datastore;
}
项目:primecloud-controller    文件:VmwareProcessClient.java   
protected VirtualMachineCloneSpec createCloneSpec(String computeResourceName, String resourcePoolName,
        String datastoreName) {
    VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec();

    // ComputeResource
    ComputeResource computeResource = vmwareClient.search(ComputeResource.class, computeResourceName);
    if (computeResource == null) {
        // ComputeResourceが見つからない場合
        throw new AutoException("EPROCESS-000503", computeResourceName);
    }

    // ResourcePool
    if (StringUtils.isEmpty(resourcePoolName)) {
        resourcePoolName = "Resources";
    }
    ResourcePool resourcePool = vmwareClient.search(computeResource, ResourcePool.class, resourcePoolName);
    if (resourcePool == null) {
        // ResourcePoolが見つからない場合
        throw new AutoException("EPROCESS-000504", resourcePoolName);
    }
    relocateSpec.setPool(resourcePool.getMOR());

    // Datastore
    if (StringUtils.isNotEmpty(datastoreName)) {
        // データストアが指定されている場合
        Datastore datastore = vmwareClient.search(Datastore.class, datastoreName);
        if (datastore == null) {
            // データストアが見つからない場合
            throw new AutoException("EPROCESS-000505", datastoreName);
        }
        relocateSpec.setDatastore(datastore.getMOR());
    }

    VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
    cloneSpec.setLocation(relocateSpec);
    cloneSpec.setPowerOn(false);
    cloneSpec.setTemplate(false);

    return cloneSpec;
}
项目:primecloud-controller    文件:VmwareProcessClient.java   
public void deleteDisk(String datastoreName, String fileName) {
    // Datacenter
    ManagedEntity datacenter = vmwareClient.getRootEntity();

    // Datastore
    Datastore datastore = vmwareClient.search(Datastore.class, datastoreName);
    if (datastore == null) {
        // データストアが見つからない場合
        throw new AutoException("EPROCESS-000505", datastoreName);
    }

    // ディスクの削除
    FileManager fileManager = vmwareClient.getServiceInstance().getFileManager();
    if (fileManager == null) {
        // fileManagerが利用できない場合
        throw new AutoException("EPROCESS-000533");
    }

    try {
        // ディスク削除
        fileManager.deleteDatastoreFile_Task(fileName, (Datacenter) datacenter);
        // ディスク削除後にごみができ、再度アタッチするとエラーになるので削除
        String flatname;
        flatname = fileName.substring(0, fileName.length() - 5) + "-flat.vmdk";
        fileManager.deleteDatastoreFile_Task(flatname, (Datacenter) datacenter);
    } catch (RemoteException e) {
        throw new AutoException("EPROCESS-000522", e, fileName);
    }

    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100455", fileName));
    }
}
项目:primecloud-controller    文件:VmwareMachineProcess.java   
protected String selectDatastore(VmwareProcessClient vmwareProcessClient, VmwareInstance vmwareInstance) {
    // データストアフォルダ内のデータストアのうち、アクセス可能で空き容量が最も大きいものを用いる
    Datastore datastore = null;
    long freeSpace = 0L;

    // ComputeResourceごとのフォルダがあれば、その中のデータストアを用いる
    String datastoreFolderName = vmwareInstance.getComputeResource() + "-storage";
    Folder datastoreFolder = vmwareProcessClient.getVmwareClient().search(Folder.class, datastoreFolderName);
    if (datastoreFolder == null) {
        // ComputeResourceごとのフォルダがなければ、"storage"フォルダの中のデータストアを用いる
        datastoreFolder = vmwareProcessClient.getVmwareClient().search(Folder.class, "storage");
    }

    if (datastoreFolder != null) {
        ManagedEntity[] entities = vmwareProcessClient.getVmwareClient().searchByType(datastoreFolder,
                Datastore.class);
        for (ManagedEntity entity : entities) {
            Datastore datastore2 = Datastore.class.cast(entity);
            DatastoreSummary summary2 = datastore2.getSummary();

            if (summary2.isAccessible() && freeSpace < summary2.getFreeSpace()) {
                datastore = datastore2;
                freeSpace = summary2.getFreeSpace();
            }
        }
    }

    if (datastore == null) {
        // 利用可能なデータストアがない場合
        throw new AutoException("EPROCESS-000528", vmwareInstance.getComputeResource());
    }

    return datastore.getName();
}
项目:WBSAirback    文件:HypervisorManagerVMware.java   
public boolean existsNFSStore(String name, String host, String address, String path) throws Exception {
    if(address == null || path == null || address.isEmpty() || path.isEmpty()) {
        return false;
    }
    ServiceInstance si = new ServiceInstance(new URL(this._url), this._user, this._password, true);
    if(host == null || host.isEmpty()) {
        si.getServerConnection().logout();
        throw new Exception("invalid host name");
    }
    try {
        HostSystem _host = (HostSystem) new InventoryNavigator(si.getRootFolder()).searchManagedEntity("HostSystem", host);
        if(_host == null) {
            si.getServerConnection().logout();
            throw new Exception("host system not found");
        }

        HostDatastoreSystem _hds = _host.getHostDatastoreSystem();
        for(Datastore _ds : _hds.getDatastores()) {
            DatastoreInfo _info = _ds.getInfo();
            if(_info instanceof NasDatastoreInfo) {
                NasDatastoreInfo _nasinfo = (NasDatastoreInfo) _info;
                if(name.equalsIgnoreCase(_nasinfo.getNas().getName())) {
                    return true;
                } else if(address.equalsIgnoreCase(_nasinfo.getNas().getRemoteHost()) &&
                        path.equalsIgnoreCase(_nasinfo.getNas().getRemotePath())) {
                    return true;
                }
            }
        }
    } catch(Exception _ex) {
    } finally {
        si.getServerConnection().logout();
    }
    return false;
}
项目:primecloud-controller    文件:VmwareDiskProcess.java   
/**
 * TODO: メソッドコメントを記述
 *
 * @param vmwareProcessClient
 * @param instanceNo
 * @param diskNo
 */
public void attachDisk(VmwareProcessClient vmwareProcessClient, Long instanceNo, Long diskNo) {
    VmwareDisk vmwareDisk = vmwareDiskDao.read(diskNo);

    if (BooleanUtils.isTrue(vmwareDisk.getAttached())) {
        // ディスクがアタッチ済みの場合はスキップ
        return;
    }

    VmwareInstance vmwareInstance = vmwareInstanceDao.read(instanceNo);

    //イベントログ出力
    Component component = componentDao.read(vmwareDisk.getComponentNo());
    Instance instance = instanceDao.read(instanceNo);
    Platform platform = platformDao.read(vmwareProcessClient.getPlatformNo());
    if (StringUtils.isEmpty(vmwareDisk.getFileName())) {
        processLogger.debug(component, instance, "VmwareDiskCreate", new Object[] { platform.getPlatformName() });
    } else {
        processLogger.debug(component, instance, "VmwareDiskAttach", new Object[] { platform.getPlatformName(),
                vmwareDisk.getFileName() });
    }

    // ディスクのアタッチ
    VirtualDisk disk = vmwareProcessClient.attachDisk(vmwareInstance.getMachineName(), vmwareDisk.getScsiId(),
            vmwareDisk.getSize(), vmwareDisk.getFileName());

    // ディスク情報の取得
    VirtualDeviceFileBackingInfo backingInfo = VirtualDeviceFileBackingInfo.class.cast(disk.getBacking());
    Datastore datastore = new Datastore(vmwareProcessClient.getVmwareClient().getServiceInstance()
            .getServerConnection(), backingInfo.getDatastore());

    //イベントログ出力
    if (StringUtils.isEmpty(vmwareDisk.getFileName())) {
        processLogger.debug(component, instance, "VmwareDiskCreateFinish",
                new Object[] { platform.getPlatformName(), backingInfo.getFileName(), vmwareDisk.getSize() });
    } else {
        processLogger.debug(component, instance, "VmwareDiskAttachFinish",
                new Object[] { platform.getPlatformName(), vmwareDisk.getFileName(), vmwareDisk.getSize() });
    }

    // データベース更新
    vmwareDisk = vmwareDiskDao.read(diskNo);
    vmwareDisk.setAttached(true);
    vmwareDisk.setDatastore(datastore.getName());
    vmwareDisk.setFileName(backingInfo.getFileName());
    vmwareDiskDao.update(vmwareDisk);
}
项目:WBSAirback    文件:HypervisorManagerVMware.java   
public Map<String, String> getVirtualMachine(String name) throws Exception {
    if(name == null || name.isEmpty()) {
        throw new Exception("invalid virtual machine name");
    }

    Map<String,String> _machine = new HashMap<String, String>();
    ServiceInstance si = new ServiceInstance(new URL(this._url), this._user, this._password, true);
    try {
        Folder rootFolder = si.getRootFolder();
        VirtualMachine _vm = (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine", name);
        if(_vm == null) {
            throw new Exception("virtual machine not found");
        }

        StringBuilder _sb = new StringBuilder();
        _machine.put("name", _vm.getName());
        for(Datastore _ds : _vm.getDatastores()) {
            if(_sb.length() > 0) {
                _sb.append(":");
            }
            _sb.append(_ds.getName());
        }
        _machine.put("datastore", _sb.toString());
        _sb = new StringBuilder();
        for(Network _nw : _vm.getNetworks()) {
            if(_sb.length() > 0) {
                _sb.append(":");
            }
            _sb.append(_nw.getName());
        }
        _machine.put("network", _sb.toString());
        _sb = new StringBuilder();
        VirtualMachineSnapshotTree[] _stree = _vm.getSnapshot().getRootSnapshotList();
        if(_stree != null) {
            for(VirtualMachineSnapshotTree _st : _stree) {
                if(_sb.length() > 0) {
                    _sb.append(":");
                }
                _sb.append(_st.getName());
            }
            _machine.put("snapshot", _sb.toString());
        } else {
            _machine.put("snapshot", "");
        }

    } catch(Exception _ex) {
        throw new Exception("hypervisor error - " + _ex.getMessage());
    } finally {
        si.getServerConnection().logout();
    }
    return _machine;
}