Ejemplo n.º 1
0
  @Test
  public void testIsNotChefEnabled() {
    VirtualMachine nochef = eg().createUniqueInstance();
    assertFalse(nochef.isChefEnabled());

    Enterprise enterprise = enterpriseGenerator.createChefInstance();
    VirtualMachineTemplate image = virtualImageGenerator.createInstance(enterprise);
    image.setChefEnabled(true);

    VirtualMachine chef =
        ((VirtualMachineGenerator) eg()).createInstance(image, enterprise, "Test");
    assertTrue(chef.isChefEnabled());
  }
  /**
   * Static method that converts the persistence {@link VirtualMachine} object to transfer {@link
   * VirtualMachineDto} object. It also adds REST self-discover {@link RESTLink}s
   *
   * @param vm Input persistence object.
   * @param restBuilder Context-injected {@link RESTLink} builder to create the links.
   * @return the corresponding transfer object.
   * @throws Exception Serialization unhandled exception.
   */
  public static VirtualMachineDto createTransferObject(
      final Integer datacenterId,
      final Integer rackId,
      final Integer machineId,
      final VirtualMachine vm,
      final VirtualAppliance vapp,
      final IRESTBuilder restBuilder)
      throws Exception {
    // TODO: Try with enterprise and user != null
    VirtualMachineDto vmDto =
        ModelTransformer.transportFromPersistence(VirtualMachineDto.class, vm);
    if (vm.getIdType() == 0) {
      vmDto.setIdType(com.abiquo.server.core.cloud.VirtualMachine.NOT_MANAGED);
    } else {
      vmDto.setIdType(com.abiquo.server.core.cloud.VirtualMachine.MANAGED);
    }
    Integer enterpriseId = null;
    Integer userId = null;

    if (vm.getEnterprise() != null) {
      enterpriseId = vm.getEnterprise().getId();
    }
    if (vm.getUser() != null) {
      userId = vm.getUser().getId();
    }
    vmDto.setLinks(
        restBuilder.buildVirtualMachineAdminLinks(
            datacenterId,
            rackId,
            machineId,
            enterpriseId,
            userId,
            vm.getHypervisor().getType(),
            vapp,
            vm.getId()));

    final VirtualMachineTemplate vmtemplate = vm.getVirtualMachineTemplate();
    if (vmtemplate != null) {
      if (vmtemplate.getRepository() != null) {
        vmDto.addLink(
            restBuilder.buildVirtualMachineTemplateLink(
                vmtemplate.getEnterprise().getId(),
                vmtemplate.getRepository().getDatacenter().getId(),
                vmtemplate.getId()));
      } else {
        // imported virtual machines
        vmDto.addLink(
            restBuilder.buildVirtualMachineTemplateLink(
                vmtemplate.getEnterprise().getId(),
                vm.getHypervisor().getMachine().getRack().getDatacenter().getId(),
                vmtemplate.getId()));
      }
    }
    return vmDto;
  }