Exemplo n.º 1
0
  /**
   * Get the {@link IMachine} of VirtualBox with the given name.
   *
   * @param name name of the IMachine to get
   * @return IMachine with the searched name
   * @throws VirtualMachineNotFoundException thrown if there is no IMachine with this name
   */
  public IMachine getMachine(final String name) throws VirtualMachineNotFoundException {

    if (StringUtils.isBlank(name)) {
      throw new IllegalArgumentException("name of the virtual machine must not be null or empty");
    }

    List<String> groups = new LinkedList<>();
    groups.add(BETSY_VBOX_GROUP);
    List<IMachine> machines = vBox.getMachinesByGroups(groups);
    for (IMachine machine : machines) {
      if (machine.getName().equals(name)) {
        return machine;
      }
    }

    throw new VirtualMachineNotFoundException(
        "VirtualMachine with name '" + name + "' could not be found in group " + BETSY_VBOX_GROUP);
  }