Example #1
0
 public Builder fromOperatingSystem(OperatingSystem in) {
   return family(in.getFamily())
       .name(in.getName())
       .version(in.getVersion())
       .arch(in.getArch())
       .description(in.getDescription())
       .is64Bit(in.is64Bit());
 }
  @Test
  public void testTryStackNatty() {

    String name = "natty-server-cloudimg-amd64";

    Image imageToConvert = Image.builder().id("id-" + name).name(name).build();

    OperatingSystem convertedOs = converterForUbuntu.apply(imageToConvert);

    assertEquals(convertedOs.getName(), imageToConvert.getName());
    assertEquals(convertedOs.getFamily(), OsFamily.UBUNTU);
    assertEquals(convertedOs.getDescription(), imageToConvert.getName());
    assertEquals(convertedOs.getVersion(), "11.04");
    assertEquals(convertedOs.getArch(), null);
    assertTrue(convertedOs.is64Bit());
  }
  @Test(dataProvider = "getOsFamilyValues")
  public void testOsFamilyValues(OsFamily family) {

    Image imageToConvert = Image.builder().id("id-" + family.name()).name(family.name()).build();

    ImageToOperatingSystem converter =
        new ImageToOperatingSystem(new HashMap<OsFamily, Map<String, String>>());

    OperatingSystem convertedOs = converter.apply(imageToConvert);

    assertEquals(convertedOs.getName(), imageToConvert.getName());
    assertEquals(convertedOs.getFamily(), family);
    assertEquals(convertedOs.getDescription(), imageToConvert.getName());
    assertEquals(convertedOs.getVersion(), null);
    assertEquals(convertedOs.getArch(), null);
    assertTrue(convertedOs.is64Bit());
  }
  @Test
  public void testOEL() {
    String name = "Oracle EL";

    Image imageToConvert = Image.builder().id("id-" + name).name(name).build();

    ImageToOperatingSystem converter =
        new ImageToOperatingSystem(new HashMap<OsFamily, Map<String, String>>());

    OperatingSystem convertedOs = converter.apply(imageToConvert);

    assertEquals(convertedOs.getName(), imageToConvert.getName());
    assertEquals(convertedOs.getFamily(), OsFamily.OEL);
    assertEquals(convertedOs.getDescription(), imageToConvert.getName());
    assertEquals(convertedOs.getVersion(), null);
    assertEquals(convertedOs.getArch(), null);
    assertTrue(convertedOs.is64Bit());
  }
Example #5
0
  @Override
  public Image apply(DiskImage from) {
    checkNotNull(from, "disk image");

    ImageBuilder builder = new ImageBuilder();

    builder.ids(from.getId());
    builder.name(from.getName());
    builder.description(from.getDescription());
    builder.location(Iterables.getOnlyElement(regionSupplier.get()));
    // in fgcp, if the image is listed it is available
    builder.status(Status.AVAILABLE);

    OperatingSystem os = diskImageToOperatingSystem.apply(from);
    builder.operatingSystem(os);
    String user = os.getFamily() == OsFamily.WINDOWS ? "Administrator" : "root";
    builder.defaultCredentials(LoginCredentials.builder().identity(user).noPassword().build());

    return builder.build();
  }
  @Test
  public void testWindows98x86() {
    String name = "Windows 98 x86";

    Image imageToConvert = Image.builder().id("id-" + name).name(name).build();

    Map<OsFamily, Map<String, String>> osFamilyMap = new HashMap<OsFamily, Map<String, String>>();
    osFamilyMap.put(OsFamily.WINDOWS, ImmutableMap.of("98", "98"));

    ImageToOperatingSystem converter = new ImageToOperatingSystem(osFamilyMap);

    OperatingSystem convertedOs = converter.apply(imageToConvert);

    assertEquals(convertedOs.getName(), imageToConvert.getName());
    assertEquals(convertedOs.getFamily(), OsFamily.WINDOWS);
    assertEquals(convertedOs.getDescription(), imageToConvert.getName());
    assertEquals(convertedOs.getVersion(), "98");
    assertEquals(convertedOs.getArch(), null);
    assertFalse(convertedOs.is64Bit());
  }
  /**
   * If knife is installed and configured on the local machine this function can be used to
   * bootstrap a node.
   *
   * <p>/etc/chef/validation.pem needs to be present as well!
   *
   * @param chefNodeName
   * @param node
   * @param nodeCredentials
   */
  public String bootstrapNode(
      String chefNodeName,
      NodeMetadata node,
      LoginCredentials nodeCredentials,
      OperatingSystem operatingSystem) {

    KnifeOperatingSystem os = this.osName2knifeOs(operatingSystem.getFamily().name());

    String ret = null;

    Boolean useIdentityFile = null;
    String credentials = null;
    String userName = null;

    Boolean doSudo = true; // for the moment we assume, that sudo is
    // necessary

    String publicAddress = null;
    for (String a : node.getPublicAddresses()) {
      publicAddress = a;
    }

    if (nodeCredentials instanceof LoginCredentialsPassword) {
      useIdentityFile = false;
      credentials = ((LoginCredentialsPassword) nodeCredentials).getPassword();
    } else if (nodeCredentials instanceof LoginCredentialsPrivateKey) {
      useIdentityFile = true;
      credentials = ((LoginCredentialsPrivateKey) nodeCredentials).getKey().getKeyPath();
    }
    userName = nodeCredentials.getUsername();

    try {
      KnifeController knife;
      // KnifeCOntroller without parameters: local knife
      File remoteCreds = File.createTempFile("creds", ".tmp");
      if (this.useRemoteKnife) {
        knife = new KnifeController(this.chefHost, this.chefHostCredentials);
        if (useIdentityFile) {
          gt.redundancyrouter.utils.Utils.copyFileToHost(
              new File(credentials),
              knife.getKnifeHost(),
              knife.getKnifeHostCredentials(),
              remoteCreds);
          credentials = remoteCreds.getAbsolutePath();
        }
      }
      // KnifeController with parameters: remote knife
      else knife = new KnifeController();

      int result =
          knife.bootstrap(
              publicAddress,
              credentials,
              userName,
              doSudo,
              false,
              os,
              chefNodeName,
              useIdentityFile);

      if (useIdentityFile && this.useRemoteKnife) {
        gt.redundancyrouter.utils.Utils.deleteFileOnHost(
            knife.getKnifeHost(), knife.getKnifeHostCredentials(), remoteCreds);
      }

      if (result == 0) {
        ret = chefNodeName;
        log.info("bootstrapping successfull");
      }

    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ExecutionException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (KnifeControllerException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return ret;
  }