org.jclouds.compute.domain.OsFamily Java Examples

The following examples show how to use org.jclouds.compute.domain.OsFamily. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AWSEC2ImageParserTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testParseCCImage() {

      Set<org.jclouds.compute.domain.Image> result = convertImages("/describe_images_cc.xml");

      assertEquals(
            Iterables.get(result, 0),
            new ImageBuilder()
                  .name("EC2 CentOS 5.4 HVM AMI")
                  .operatingSystem(
                        new OperatingSystem.Builder().family(OsFamily.CENTOS).arch("hvm").version("5.4")
                              .description("amazon/EC2 CentOS 5.4 HVM AMI").is64Bit(true).build())
                  .description("EC2 CentOS 5.4 HVM AMI")
                  .defaultCredentials(LoginCredentials.builder().user("root").build()).id("us-east-1/ami-7ea24a17")
                  .providerId("ami-7ea24a17").location(defaultLocation)
                  .userMetadata(ImmutableMap.of(
                     "owner", "206029621532",
                     "rootDeviceType", "ebs",
                     "virtualizationType", "hvm",
                     "hypervisor", "xen"))
                  .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build());
      assertEquals(Iterables.get(result, 0).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);

   }
 
Example #2
Source File: AWSEC2ImageParserTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testParseVostokImage() {

      Set<org.jclouds.compute.domain.Image> result = convertImages("/vostok.xml");

      assertEquals(
            Iterables.get(result, 0),
            new ImageBuilder()
                  .operatingSystem(
                        new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("")
                              .description("vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml")
                              .is64Bit(false).build())
                  .description("vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml")
                  .defaultCredentials(LoginCredentials.builder().user("root").build()).id("us-east-1/ami-870de2ee")
                  .providerId("ami-870de2ee").location(defaultLocation).version("5622")
                  .userMetadata(ImmutableMap.of("owner", "133804938231", "rootDeviceType", "instance-store"))
                  .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build());

   }
 
Example #3
Source File: BrooklynImageChooser.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected double punishmentForOldOsVersions(Image img, OsFamily family, double minVersion) {
    OperatingSystem os = img.getOperatingSystem();
    if (os!=null && family.equals(os.getFamily())) {
        String v = os.getVersion();
        if (v!=null) {
            try {
                double vd = Double.parseDouble(v);
                // punish older versions, with a -log function (so 0.5 version behind is -log(1.5)=-0.5 and 2 versions behind is -log(3)=-1.2  
                if (vd < minVersion) return -Math.log(1+(minVersion - vd));
            } catch (Exception e) {
                /* ignore unparseable versions */
            }
        }
    }
    return 0;
}
 
Example #4
Source File: JcloudsStubTemplateBuilder.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected Image getImage() {
    switch (providerName) {
    case "aws-ec2" :
    case "ec2" :
        return new ImageBuilder().providerId("ebs-image-provider").name("image")
                .id(regionName+"/bogus-image").location(jcloudsDomainLocation)
                .userMetadata(ImmutableMap.of("rootDeviceType", RootDeviceType.EBS.value()))
                .operatingSystem(new OperatingSystem(OsFamily.UBUNTU, null, "1.0", VirtualizationType.PARAVIRTUAL.value(), "ubuntu", true))
                .description("description").version("1.0").defaultCredentials(LoginCredentials.builder().user("root").build())
                .status(Image.Status.AVAILABLE)
                .build();
    case "google-compute-engine" :
        return new ImageBuilder().providerId("gce-image-provider").name("image")
                .id(regionName+"/bogus-image").location(jcloudsDomainLocation)
                .operatingSystem(new OperatingSystem(OsFamily.UBUNTU, null, "1.0", VirtualizationType.PARAVIRTUAL.value(), "ubuntu", true))
                .description("description").version("1.0").defaultCredentials(LoginCredentials.builder().user("root").build())
                .status(Image.Status.AVAILABLE)
                .build();
    default:
        throw new UnsupportedOperationException("Unsupported stubbed Image for provider "+providerName);
    }
}
 
Example #5
Source File: JcloudsAwsImageChoiceStubbedLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private void assertCentos(Image image, String expectedVersion) {
    // Expect owner RightScale (i.e. "RightImage")
    assertEquals(image.getUserMetadata().get("owner"), "411009282317", "image="+image);
    assertTrue(image.getName().toLowerCase().contains("centos"), "image="+image);
    assertTrue(image.getName().contains(expectedVersion), "image="+image);
    assertEquals(image.getOperatingSystem().getFamily(), OsFamily.CENTOS, "image="+image);
    assertEquals(image.getOperatingSystem().getVersion(), expectedVersion, "image="+image);
}
 
Example #6
Source File: AWSEC2ImageParserTest.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
public static Set<org.jclouds.compute.domain.Image> convertImages(String resource) {

      Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
      }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
            .getInstance(Json.class));

      Set<Image> result = DescribeImagesResponseHandlerTest.parseImages(resource);
      EC2ImageParser parser = new EC2ImageParser(EC2ComputeServiceDependenciesModule.toPortableImageStatus,
               new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, Suppliers
                        .<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
                        .ofInstance(defaultLocation), new AWSEC2ReviseParsedImage(map));
      return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull()));
   }
 
Example #7
Source File: AWSEC2ImageParserTest.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
public void testParseRightScaleImage() {

      Set<org.jclouds.compute.domain.Image> result = convertImages("/rightscale_images.xml");

      assertEquals(
            Iterables.get(result, 0),
            new ImageBuilder()
                  .operatingSystem(
                        new OperatingSystem.Builder().family(OsFamily.CENTOS).arch("paravirtual").version("5.4")
                              .description("rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml").is64Bit(true)
                              .build()).description("rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml")
                  .defaultCredentials(LoginCredentials.builder().user("root").build()).id("us-east-1/ami-ccb35ea5")
                  .providerId("ami-ccb35ea5").location(defaultLocation).version("4.4.10")
                  .userMetadata(ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store"))
                  .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build());
      assertEquals(Iterables.get(result, 0).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);

      assertEquals(
            new Gson().toJson(Iterables.get(result, 1)),
            "{\"operatingSystem\":{\"family\":\"UBUNTU\",\"arch\":\"paravirtual\",\"version\":\"9.10\",\"description\":\"411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"is64Bit\":true},\"status\":\"AVAILABLE\",\"backendStatus\":\"available\",\"version\":\"4.5.3_EBS_Alpha\",\"description\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"defaultCredentials\":{\"authenticateSudo\":false,\"password\":{},\"privateKey\":{},\"identity\":\"root\"},\"id\":\"us-east-1/ami-c19db6b5\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-c19db6b5\",\"name\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"paravirtual\",\"hypervisor\":\"xen\"}}");

      assertEquals(
              new Gson().toJson(Iterables.get(result, 2)),
              "{\"operatingSystem\":{\"family\":\"WINDOWS\",\"arch\":\"hvm\",\"version\":\"2003\",\"description\":\"411009282317/RightImage Windows_2003_i386_v5.4.3\",\"is64Bit\":false},\"status\":\"AVAILABLE\",\"backendStatus\":\"available\",\"version\":\"5.4.3\",\"description\":\"Built by RightScale\",\"defaultCredentials\":{\"authenticateSudo\":false,\"password\":{},\"privateKey\":{},\"identity\":\"root\"},\"id\":\"us-east-1/ami-710c2605\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-710c2605\",\"name\":\"RightImage Windows_2003_i386_v5.4.3\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"hvm\",\"hypervisor\":\"xen\"}}");

      assertEquals(
              new Gson().toJson(Iterables.get(result, 3)),
              "{\"operatingSystem\":{\"family\":\"CENTOS\",\"arch\":\"paravirtual\",\"version\":\"6.5\",\"description\":\"411009282317/RightImage_CentOS_6.5_x64_v13.5.2.2_EBS\",\"is64Bit\":true},\"status\":\"AVAILABLE\",\"backendStatus\":\"available\",\"version\":\"13.5.2.2_EBS\",\"description\":\"RightImage_CentOS_6.5_x64_v13.5.2.2_EBS\",\"defaultCredentials\":{\"authenticateSudo\":false,\"password\":{},\"privateKey\":{},\"identity\":\"root\"},\"id\":\"us-east-1/ami-05ebd06c\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-05ebd06c\",\"name\":\"RightImage_CentOS_6.5_x64_v13.5.2.2_EBS\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"paravirtual\",\"hypervisor\":\"xen\"}}");

      assertEquals(
              new Gson().toJson(Iterables.get(result, 4)),
              "{\"operatingSystem\":{\"family\":\"UBUNTU\",\"arch\":\"paravirtual\",\"version\":\"10.04\",\"description\":\"411009282317/RightImage_Ubuntu_10.04_x64_v12.11.4_EBS\",\"is64Bit\":true},\"status\":\"AVAILABLE\",\"backendStatus\":\"available\",\"version\":\"12.11.4_EBS\",\"description\":\"RightImage_Ubuntu_10.04_x64_v12.11.4_EBS\",\"defaultCredentials\":{\"authenticateSudo\":false,\"password\":{},\"privateKey\":{},\"identity\":\"root\"},\"id\":\"us-east-1/ami-08bffe61\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-08bffe61\",\"name\":\"RightImage_Ubuntu_10.04_x64_v12.11.4_EBS\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"paravirtual\",\"hypervisor\":\"xen\"}}");

   }
 
Example #8
Source File: RebindOsgiTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@DataProvider(name = "valInEntityDataProvider")
public Object[][] valInEntityDataProvider() {
    return new Object[][] {
        {Predicates.alwaysTrue(), false},
        {Predicates.alwaysTrue(), true},
        {OsFamily.CENTOS, false},
        {OsFamily.CENTOS, true},
    };
}
 
Example #9
Source File: DockerJcloudsLocationLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups = {"Live", "Live-sanity"})
public void testMatchingOsFamilyConfiguredOnLocationHasAutoGeneratedCredentials() throws Exception {
    loc = newDockerLocation(ImmutableMap.<String, Object>of(
            JcloudsLocation.OS_FAMILY.getName(), OsFamily.UBUNTU,
            JcloudsLocation.OS_VERSION_REGEX.getName(), "16.04.*",
            JcloudsLocation.WAIT_FOR_SSHABLE.getName(), "1m"));
    JcloudsSshMachineLocation machine = newDockerMachine(loc, ImmutableMap.<String, Object>of());

    assertMachineSshableSecureAndFromImage(machine, "brooklyncentral/ubuntu:16.04");
}
 
Example #10
Source File: DockerJcloudsLocationLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups = {"Live", "Live-sanity"})
public void testMatchingOsFamilyUbuntu16HasAutoGeneratedCredentials() throws Exception {
    loc = newDockerLocation(ImmutableMap.<String, Object>of());
    JcloudsSshMachineLocation machine = newDockerMachine(loc, ImmutableMap.<String, Object>of(
            JcloudsLocation.OS_FAMILY.getName(), OsFamily.UBUNTU,
            JcloudsLocation.OS_VERSION_REGEX.getName(), "16.04.*",
            JcloudsLocation.WAIT_FOR_SSHABLE.getName(), "1m"));

    assertMachineSshableSecureAndFromImage(machine, "brooklyncentral/ubuntu:16.04");
}
 
Example #11
Source File: DockerJcloudsLocationLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups = {"Live", "Live-sanity"})
public void testMatchingOsFamilyUbuntu14HasAutoGeneratedCredentials() throws Exception {
    loc = newDockerLocation(ImmutableMap.<String, Object>of());
    JcloudsSshMachineLocation machine = newDockerMachine(loc, ImmutableMap.<String, Object>of(
            JcloudsLocation.OS_FAMILY.getName(), OsFamily.UBUNTU,
            JcloudsLocation.OS_VERSION_REGEX.getName(), "14.04.*",
            JcloudsLocation.WAIT_FOR_SSHABLE.getName(), "1m"));

    assertMachineSshableSecureAndFromImage(machine, "brooklyncentral/ubuntu:14.04");
}
 
Example #12
Source File: DockerJcloudsLocationLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups = {"Live", "Live-sanity"})
public void testMatchingOsFamilyCentosHasAutoGeneratedCredentials() throws Exception {
    loc = newDockerLocation(ImmutableMap.<String, Object>of());
    JcloudsSshMachineLocation machine = newDockerMachine(loc, ImmutableMap.<String, Object>of(
            JcloudsLocation.OS_FAMILY.getName(), OsFamily.CENTOS,
            JcloudsLocation.OS_VERSION_REGEX.getName(), "7.*",
            JcloudsLocation.WAIT_FOR_SSHABLE.getName(), "1m"));

    assertMachineSshableSecureAndFromImage(machine, "brooklyncentral/centos:7");
}
 
Example #13
Source File: ImageChooser.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public Optional<String> chooseImage(OsFamily osFamily, String osVersionRegex) {
    for (ImageMetadata imageMetadata : images) {
        if (imageMetadata.matches(osFamily, osVersionRegex)) {
            String imageName = imageMetadata.getImageName();
            LOG.debug("Choosing container image {}, for osFamily={} and osVersionRegex={}",imageName, osFamily, osVersionRegex);
            return Optional.of(imageName);
        }
    }
    return Optional.absent();
}
 
Example #14
Source File: DockerJcloudsLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
protected MachineLocation obtainOnce(ConfigBag setup) throws NoMachinesAvailableException {
    // Use the provider name that jclouds expects; rely on resolver to have validated this.
    setup.configure(JcloudsLocation.CLOUD_PROVIDER, "docker");

    // Inject default image, if absent
    String imageId = setup.get(JcloudsLocation.IMAGE_ID);
    String imageNameRegex = setup.get(JcloudsLocation.IMAGE_NAME_REGEX);
    String imageDescriptionRegex = setup.get(JcloudsLocation.IMAGE_DESCRIPTION_REGEX);
    String defaultImageDescriptionRegex = setup.get(DEFAULT_IMAGE_DESCRIPTION_REGEX);
    OsFamily osFamily = setup.get(OS_FAMILY);
    String osVersionRegex = setup.get(OS_VERSION_REGEX);

    if (Strings.isBlank(imageId) && Strings.isBlank(imageNameRegex) && Strings.isBlank(imageDescriptionRegex)) {
        if (osFamily != null || osVersionRegex != null) {
            for (ImageMetadata imageMetadata : DEFAULT_IMAGES) {
                if (imageMetadata.matches(osFamily, osVersionRegex)) {
                    String imageDescription = imageMetadata.getImageDescription();
                    LOG.debug("Setting default image regex to {}, for obtain call in {}; removing osFamily={} and osVersionRegex={}",
                            new Object[]{imageDescription, this, osFamily, osVersionRegex});
                    setup.configure(JcloudsLocation.IMAGE_DESCRIPTION_REGEX, imageDescription);
                    setup.configure(OS_FAMILY, null);
                    setup.configure(OS_VERSION_REGEX, null);
                    break;
                }
            }
        } else if (Strings.isNonBlank(defaultImageDescriptionRegex)) {
            LOG.debug("Setting default image regex to {}, for obtain call in {}", defaultImageDescriptionRegex, this);
            setup.configure(JcloudsLocation.IMAGE_DESCRIPTION_REGEX, defaultImageDescriptionRegex);
        }
    }

    return super.obtainOnce(setup);
}
 
Example #15
Source File: JcloudsAwsImageChoiceStubbedLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private void assertUbuntu(Image image, String version) {
    // Expect owner Canonical 
    assertEquals(image.getUserMetadata().get("owner"), "099720109477", "image="+image);
    assertTrue(image.getName().toLowerCase().contains("ubuntu"), "image="+image);
    assertTrue(image.getName().contains(version), "image="+image);
    assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU, "image="+image);
    assertEquals(image.getOperatingSystem().getVersion(), version, "image="+image);
}
 
Example #16
Source File: BrooklynImageChooserTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testCentosUbuntuRHEL() {
    assertOrderOfPreference(
            getScore(OsFamily.CENTOS, "7.0"),
            getScore(OsFamily.UBUNTU, "14.04"),
            getScore(OsFamily.RHEL, "7.0"));
}
 
Example #17
Source File: JcloudsWinrmingLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups = "Live", dataProvider="cloudAndImageNames")
public void testCreatesWindowsVm(String locationSpec, String imageNameRegex, Map<String, ?> additionalConfig) throws Exception {
    jcloudsLocation = (JcloudsLocation) managementContext.getLocationRegistry().getLocationManaged(locationSpec);

    JcloudsWinRmMachineLocation machine = obtainWinrmMachine(MutableMap.<String,Object>builder()
            .putIfAbsent("inboundPorts", ImmutableList.of(5986, 5985, 3389))
            .put(JcloudsLocation.IMAGE_NAME_REGEX.getName(), imageNameRegex)
            .put(JcloudsLocation.USE_JCLOUDS_SSH_INIT.getName(), false)
            .put(JcloudsLocation.OS_FAMILY_OVERRIDE.getName(), OsFamily.WINDOWS)
            .putAll(additionalConfig != null ? additionalConfig : ImmutableMap.<String, Object>of())
            .build());
    assertWinrmable(machine);
}
 
Example #18
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/**
 * Whether the given VM is Windows.
 *
 * @see #isWindows(Image, ConfigBag)
 */
public boolean isWindows(NodeMetadata node, ConfigBag config) {
    OsFamily override = config.get(OS_FAMILY_OVERRIDE);
    if (override != null) return override == OsFamily.WINDOWS;

    OsFamily confFamily = config.get(OS_FAMILY);
    OperatingSystem os = (node != null) ? node.getOperatingSystem() : null;
    return (os != null && os.getFamily() != OsFamily.UNRECOGNIZED)
            ? (OsFamily.WINDOWS == os.getFamily())
            : (OsFamily.WINDOWS == confFamily);
}
 
Example #19
Source File: AbstractPortableTemplateBuilder.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public T osFamily(final OsFamily os) {
    this.os = os;
    commands.add(new Function<TemplateBuilder,TemplateBuilder>() { 
        @Override
        public TemplateBuilder apply(TemplateBuilder b) { return b.osFamily(os); }});
    return (T)this;
}
 
Example #20
Source File: TemplateBuilderCustomizers.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(TemplateBuilder tb, ConfigBag props, Object v) {
    Maybe<OsFamily> osFamily = Enums.valueOfIgnoreCase(OsFamily.class, v.toString());
    if (osFamily.isAbsent()) {
        throw new IllegalArgumentException("Invalid " + JcloudsLocationConfig.OS_FAMILY + " value " + v);
    }
    tb.osFamily(osFamily.get());
}
 
Example #21
Source File: JcloudsReachableAddressStubbedTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected JcloudsWinRmMachineLocation newWinrmMachine(Map<? extends ConfigKey<?>, ?> additionalConfig) throws Exception {
    return obtainWinrmMachine(ImmutableMap.<ConfigKey<?>,Object>builder()
            .put(WinRmMachineLocation.WINRM_TOOL_CLASS, RecordingWinRmTool.class.getName())
            .put(JcloudsLocation.POLL_FOR_FIRST_REACHABLE_ADDRESS_PREDICATE, addressChooser)
            .put(JcloudsLocation.OS_FAMILY_OVERRIDE, OsFamily.WINDOWS)
            .putAll(additionalConfig)
            .build());
}
 
Example #22
Source File: JcloudsSshMachineLocationStubbedTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
    public void testWinrmConfigPassedToMachine() throws Exception {
        JcloudsWinRmMachineLocation machine = obtainWinrmMachine(ImmutableMap.of(
                JcloudsLocation.OS_FAMILY_OVERRIDE.getName(), OsFamily.WINDOWS,
//                JcloudsLocation.WAIT_FOR_WINRM_AVAILABLE.getName(), "false",
                WinRmMachineLocation.COPY_FILE_CHUNK_SIZE_BYTES.getName(), 123,
                WinRmTool.PROP_EXEC_TRIES.getName(), 456));
        assertEquals(machine.config().get(WinRmMachineLocation.COPY_FILE_CHUNK_SIZE_BYTES), Integer.valueOf(123));
        assertEquals(machine.config().get(WinRmTool.PROP_EXEC_TRIES), Integer.valueOf(456));
    }
 
Example #23
Source File: BrooklynImageChooserTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testUbuntuLts() {
    assertOrderOfPreference(
            getScore(OsFamily.UBUNTU, "18.04"),
            getScore(OsFamily.UBUNTU, "16.04"),
            getScore(OsFamily.UBUNTU, "14.04"),
            getScore(OsFamily.UBUNTU, "12.04"),
            getScore(OsFamily.UBUNTU, "18.10"));
}
 
Example #24
Source File: BrooklynImageChooserTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testCentos7then6then5() {
    assertOrderOfPreference(
            getScore(OsFamily.CENTOS, "7.0"),
            getScore(OsFamily.CENTOS, "6.6"),
            getScore(OsFamily.CENTOS, "5.4"));
}
 
Example #25
Source File: ImageChooser.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public Optional<String> chooseImage(String osFamily, String osVersionRegex) {
    return chooseImage((osFamily == null ? (OsFamily) null : OsFamily.fromValue(osFamily)), osVersionRegex);
}
 
Example #26
Source File: BrooklynImageChooserTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
double getScore(OsFamily centos, String version) {
    return brooklynImageChooser.score(getImg(centos, version));
}
 
Example #27
Source File: AWSEC2ImageParserTest.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
public void testParseAmznImage() {

      Set<org.jclouds.compute.domain.Image> result = convertImages("/amzn_images.xml");

      assertEquals(
            Iterables.get(result, 0),
            new ImageBuilder()
                  .name("amzn-ami-0.9.7-beta.i386-ebs")
                  .operatingSystem(
                        new OperatingSystem.Builder().family(OsFamily.AMZN_LINUX).arch("paravirtual")
                              .version("0.9.7-beta").description("137112412989/amzn-ami-0.9.7-beta.i386-ebs")
                              .is64Bit(false).build()).description("Amazon")
                  .defaultCredentials(LoginCredentials.builder().user("ec2-user").build()).id("us-east-1/ami-82e4b5c7")
                  .providerId("ami-82e4b5c7").location(defaultLocation).version("0.9.7-beta")
                  .userMetadata(ImmutableMap.of(
                     "owner", "137112412989",
                     "rootDeviceType", "ebs",
                     "virtualizationType", "paravirtual",
                     "hypervisor", "xen"))
                  .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build());
      assertEquals(Iterables.get(result, 0).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);

      assertEquals(
            Iterables.get(result, 3),
            new ImageBuilder()
                  .name("amzn-ami-0.9.7-beta.x86_64-S3")
                  .operatingSystem(
                        new OperatingSystem.Builder().family(OsFamily.AMZN_LINUX).arch("paravirtual")
                              .version("0.9.7-beta")
                              .description("amzn-ami-us-west-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml").is64Bit(true)
                              .build()).description("Amazon Linux AMI x86_64 S3")
                  .defaultCredentials(LoginCredentials.builder().user("ec2-user").build()).id("us-east-1/ami-f2e4b5b7")
                  .providerId("ami-f2e4b5b7").location(defaultLocation).version("0.9.7-beta")
                  .userMetadata(ImmutableMap.of(
                     "owner", "137112412989",
                     "rootDeviceType", "ebs",
                     "virtualizationType", "paravirtual",
                     "hypervisor", "xen"))
                  .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build());
      assertEquals(Iterables.get(result, 3).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);

   }
 
Example #28
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
/**
 * Create the user immediately - executing ssh commands as required.
 */
protected LoginCredentials createUser(
        ComputeService computeService, NodeMetadata node, HostAndPort managementHostAndPort,
        LoginCredentials initialCredentials, ConfigBag config) {
    Image image = (node.getImageId() != null) ? computeService.getImage(node.getImageId()) : null;
    CreateUserStatements userCreation = createUserStatements(image, config);

    if (!userCreation.statements().isEmpty()) {
        // If unsure of OS family, default to unix for rendering statements.
        org.jclouds.scriptbuilder.domain.OsFamily scriptOsFamily;
        if (isWindows(node, config)) {
            scriptOsFamily = org.jclouds.scriptbuilder.domain.OsFamily.WINDOWS;
        } else {
            scriptOsFamily = org.jclouds.scriptbuilder.domain.OsFamily.UNIX;
        }

        boolean windows = isWindows(node, config);

        if (windows) {
            LOG.warn("Unable to execute statements on WinRM in JcloudsLocation; skipping for "+node+": "+userCreation.statements());
        } else {
            List<String> commands = Lists.newArrayList();
            for (Statement statement : userCreation.statements()) {
                InitAdminAccess initAdminAccess = new InitAdminAccess(new AdminAccessConfiguration.Default());
                initAdminAccess.visit(statement);
                commands.add(statement.render(scriptOsFamily));
            }

            String initialUser = initialCredentials.getUser();
            boolean authSudo = initialCredentials.shouldAuthenticateSudo();
            Optional<String> password = initialCredentials.getOptionalPassword();
            
            // TODO Retrying lots of times as workaround for vcloud-director. There the guest customizations
            // can cause the VM to reboot shortly after it was ssh'able.
            Map<String,Object> execProps = MutableMap.<String, Object>builder()
                    .put(ShellTool.PROP_RUN_AS_ROOT.getName(), true)
                    .put(SshTool.PROP_AUTH_SUDO.getName(), authSudo)
                    .put(SshTool.PROP_ALLOCATE_PTY.getName(), true)
                    .putIfNotNull(SshTool.PROP_PASSWORD.getName(), authSudo ? password.orNull() : null)
                    .put(SshTool.PROP_SSH_TRIES.getName(), 50)
            .put(SshTool.PROP_SSH_TRIES_TIMEOUT.getName(), 10*60*1000)
            .build();

            if (LOG.isDebugEnabled()) {
                LOG.debug("VM {}: executing user creation/setup via {}@{}; commands: {}", new Object[] {
                        getCreationString(config), initialUser, managementHostAndPort, commands});
            }

            SshMachineLocation sshLoc = createTemporarySshMachineLocation(managementHostAndPort, initialCredentials, config);
            try {
                // BROOKLYN-188: for SUSE, need to specify the path (for groupadd, useradd, etc)
                Map<String, ?> env = ImmutableMap.of("PATH", sbinPath());

                int exitcode = sshLoc.execScript(execProps, "create-user", commands, env);

                if (exitcode != 0) {
                    LOG.warn("exit code {} when creating user for {}; usage may subsequently fail", exitcode, node);
                }
            } finally {
                if (getManagementContext().getLocationManager().isManaged(sshLoc)) {
                    getManagementContext().getLocationManager().unmanage(sshLoc);
                }
                Streams.closeQuietly(sshLoc);
            }
        }
    }

    return userCreation.credentials();
}
 
Example #29
Source File: BrooklynImageChooserTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
Image getImg(final OsFamily osFamily, final String version) {
    return new Image() {
        @Override
        public OperatingSystem getOperatingSystem() {
            return new OperatingSystem(osFamily, "", version, "", "", true);
        }

        @Override
        public String getVersion() {
            return version;
        }

        @Override
        public String getDescription() {
            return null;
        }

        @Override
        public LoginCredentials getDefaultCredentials() {
            return null;
        }

        @Override
        public Status getStatus() {
            return null;
        }

        @Override
        public String getBackendStatus() {
            return null;
        }

        @Override
        public ComputeType getType() {
            return null;
        }

        @Override
        public String getProviderId() {
            return null;
        }

        @Override
        public String getName() {
            return null;
        }

        @Override
        public String getId() {
            return null;
        }

        @Override
        public Set<String> getTags() {
            return null;
        }

        @Override
        public Location getLocation() {
            return null;
        }

        @Override
        public URI getUri() {
            return null;
        }

        @Override
        public Map<String, String> getUserMetadata() {
            return ImmutableMap.of();
        }

        @Override
        public int compareTo(ResourceMetadata<ComputeType> o) {
            return 0;
        }
    };
}
 
Example #30
Source File: AbstractPortableTemplateBuilder.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public OsFamily getOsFamily() {
    return os;
}