updated to parse ecloud images

This commit is contained in:
Adrian Cole 2011-01-29 21:07:00 -08:00
parent c8d4008c98
commit d306dcbdec
3 changed files with 346 additions and 0 deletions

View File

@ -0,0 +1,73 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.terremark.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrUnrecognized;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.vcloud.compute.functions.ParseOsFromVAppTemplateName;
/**
* @author Adrian Cole
*/
@Singleton
public class TerremarkECloudParseOsFromVAppTemplateName extends ParseOsFromVAppTemplateName {
// CentOS 5 (x64)
public static final Pattern OS_PATTERN = Pattern.compile("^-?([^ ]*) ([0-9.]+)( R[1-9])? ?.*");
@Inject
protected TerremarkECloudParseOsFromVAppTemplateName(Map<OsFamily, Map<String, String>> osVersionMap) {
super(osVersionMap);
}
@Override
public OperatingSystem apply(String from) {
checkNotNull(from, "vapp template name");
OperatingSystemBuilder builder = new OperatingSystemBuilder();
builder.description(from);
if (from.equals("-Windows 2003 Std. R2 SQL 2005 Std. (x64)"))
System.out.print(';');
builder.is64Bit(from.indexOf("64") != -1);
from = from.replace("Red Hat Enterprise Linux", "RHEL").replace("Sun Solaris", "SOLARIS").replace(
" Server", "").replace("Std. ", "");
Matcher matcher = OS_PATTERN.matcher(from);
if (matcher.find()) {
OsFamily osFamily = parseOsFamilyOrUnrecognized(matcher.group(1));
builder.family(osFamily);
String version = (matcher.group(3) != null) ? matcher.group(2) + matcher.group(3) : matcher.group(2);
builder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, version, osVersionMap));
} else {
OsFamily osFamily = parseOsFamilyOrUnrecognized(from);
builder.family(osFamily);
}
return builder.build();
}
}

View File

@ -0,0 +1,169 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.terremark.compute.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Map;
import java.util.Set;
import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.jclouds.vcloud.xml.CatalogHandler;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.TypeLiteral;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "TerremarkECloudParseOsFromVAppTemplateNameTest")
public class TerremarkECloudParseOsFromVAppTemplateNameTest {
public Set<String> parseNames(String resource) {
InputStream is = getClass().getResourceAsStream(resource);
Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
return factory.create(injector.getInstance(CatalogHandler.class)).parse(is).keySet();
}
public void test() {
TerremarkECloudParseOsFromVAppTemplateName function = new TerremarkECloudParseOsFromVAppTemplateName(Guice
.createInjector(new GsonModule()).getInstance(Json.class).<Map<OsFamily, Map<String, String>>> fromJson(
new ComputeServiceConstants.ReferenceData().osVersionMapJson,
new TypeLiteral<Map<OsFamily, Map<String, String>>>() {
}.getType()));
Set<String> names = parseNames("/catalog-ecloud.xml");
assertEquals(Sets.newLinkedHashSet(Iterables.transform(names, function)), ImmutableSet.of(
// CentOS 5 (x64)
new OperatingSystemBuilder().family(OsFamily.CENTOS).version("5.0").description("CentOS 5 (x64)")
.is64Bit(true).build(),
// CentOS 5 (x86)
new OperatingSystemBuilder().family(OsFamily.CENTOS).version("5.0").description("CentOS 5 (x86)")
.is64Bit(false).build(),
// CentOS 5.5 x32
new OperatingSystemBuilder().family(OsFamily.CENTOS).version("5.5").description("CentOS 5.5 x32")
.is64Bit(false).build(),
// CentOS 5.5 x64
new OperatingSystemBuilder().family(OsFamily.CENTOS).version("5.5").description("CentOS 5.5 x64")
.is64Bit(true).build(),
// Red Hat Enterprise Linux 5 (x64)
new OperatingSystemBuilder().family(OsFamily.RHEL).version("5.0").description(
"Red Hat Enterprise Linux 5 (x64)").is64Bit(true).build(),
// Red Hat Enterprise Linux 5 (x86)
new OperatingSystemBuilder().family(OsFamily.RHEL).version("5.0").description(
"Red Hat Enterprise Linux 5 (x86)").is64Bit(false).build(),
// Red Hat Enterprise Linux 5.5 x32
new OperatingSystemBuilder().family(OsFamily.RHEL).version("5.5").description(
"Red Hat Enterprise Linux 5.5 x32").is64Bit(false).build(),
// Red Hat Enterprise Linux 5.5 x64
new OperatingSystemBuilder().family(OsFamily.RHEL).version("5.5").description(
"Red Hat Enterprise Linux 5.5 x64").is64Bit(true).build(),
// Sun Solaris 10 (x64)
new OperatingSystemBuilder().family(OsFamily.SOLARIS).version("10").description("Sun Solaris 10 (x64)")
.is64Bit(true).build(),
// Ubuntu 8.04 LTS (x64)
new OperatingSystemBuilder().family(OsFamily.UBUNTU).version("8.04")
.description("Ubuntu 8.04 LTS (x64)").is64Bit(true).build(),
// Ubuntu 8.04 LTS (x86)
new OperatingSystemBuilder().family(OsFamily.UBUNTU).version("8.04")
.description("Ubuntu 8.04 LTS (x86)").is64Bit(false).build(),
// Ubuntu Server 10.04 x32
new OperatingSystemBuilder().family(OsFamily.UBUNTU).version("10.04").description(
"Ubuntu Server 10.04 x32").is64Bit(false).build(),
// Ubuntu Server 10.04 x64
new OperatingSystemBuilder().family(OsFamily.UBUNTU).version("10.04").description(
"Ubuntu Server 10.04 x64").is64Bit(true).build(),
// -Windows 2003 Std. R2 SQL 2005 Std. (x64)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2003 R2").description(
"-Windows 2003 Std. R2 SQL 2005 Std. (x64)").is64Bit(true).build(),
// -Windows 2003 Std. R2 SQL 2008 Std. (x64)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2003 R2").description(
"-Windows 2003 Std. R2 SQL 2008 Std. (x64)").is64Bit(true).build(),
// -Windows 2008 R2 Std wSQL 2008 R2 Std (x64)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2008 R2").description(
"-Windows 2008 R2 Std wSQL 2008 R2 Std (x64)").is64Bit(true).build(),
// -Windows 2008 R2 Std wSQL 2008 R2 Web (x64)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2008 R2").description(
"-Windows 2008 R2 Std wSQL 2008 R2 Web (x64)").is64Bit(true).build(),
// -Windows 2008 Std wSQL 2008 Std (x64)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2008").description(
"-Windows 2008 Std wSQL 2008 Std (x64)").is64Bit(true).build(),
// -Windows 2008 Std wSQL 2008 Web (x64)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2008").description(
"-Windows 2008 Std wSQL 2008 Web (x64)").is64Bit(true).build(),
// -Windows Server 2003 R2 Enterprise Edition (x64)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2003 R2").description(
"-Windows Server 2003 R2 Enterprise Edition (x64)").is64Bit(true).build(),
// -Windows Server 2003 R2 Enterprise Edition (x86)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2003 R2").description(
"-Windows Server 2003 R2 Enterprise Edition (x86)").is64Bit(false).build(),
// -Windows Server 2003 R2 Standard Edition (x64)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2003 R2").description(
"-Windows Server 2003 R2 Standard Edition (x64)").is64Bit(true).build(),
// -Windows Server 2003 R2 Standard Edition (x86)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2003 R2").description(
"-Windows Server 2003 R2 Standard Edition (x86)").is64Bit(false).build(),
// -Windows Server 2008 Enterprise Edition (x64)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2008").description(
"-Windows Server 2008 Enterprise Edition (x64)").is64Bit(true).build(),
// -Windows Server 2008 Enterprise Edition (x86)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2008").description(
"-Windows Server 2008 Enterprise Edition (x86)").is64Bit(false).build(),
// -Windows Server 2008 R2 Enterprise Edition (x64)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2008 R2").description(
"-Windows Server 2008 R2 Enterprise Edition (x64)").is64Bit(true).build(),
// -Windows Server 2008 R2 Standard Edition (x64)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2008 R2").description(
"-Windows Server 2008 R2 Standard Edition (x64)").is64Bit(true).build(),
// -Windows Server 2008 R2 Web Edition (x64)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2008 R2").description(
"-Windows Server 2008 R2 Web Edition (x64)").is64Bit(true).build(),
// -Windows Server 2008 Standard Edition (x64)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2008").description(
"-Windows Server 2008 Standard Edition (x64)").is64Bit(true).build(),
// -Windows Server 2008 Standard Edition (x86)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2008").description(
"-Windows Server 2008 Standard Edition (x86)").is64Bit(false).build(),
// -Windows Server 2008 Web Edition (x64)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2008").description(
"-Windows Server 2008 Web Edition (x64)").is64Bit(true).build(),
// -Windows Server 2008 Web Edition (x86)
new OperatingSystemBuilder().family(OsFamily.WINDOWS).version("2008").description(
"-Windows Server 2008 Web Edition (x86)").is64Bit(false).build()
));
}
}

View File

@ -0,0 +1,104 @@
<Catalog
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/vdc/691/catalog"
type="application/vnd.vmware.vcloud.catalog+xml" name="Opscode, Inc. Catalog"
xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CatalogItems>
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/36-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="CentOS 5 (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/35-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="CentOS 5 (x86)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/346-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="CentOS 5.5 x32" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/347-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="CentOS 5.5 x64" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/233-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="Red Hat Enterprise Linux 5 (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/107-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="Red Hat Enterprise Linux 5 (x86)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/348-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="Red Hat Enterprise Linux 5.5 x32" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/349-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="Red Hat Enterprise Linux 5.5 x64" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/6-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="Sun Solaris 10 (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/103-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="Ubuntu 8.04 LTS (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/55-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="Ubuntu 8.04 LTS (x86)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/350-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="Ubuntu Server 10.04 x32" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/351-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="Ubuntu Server 10.04 x64" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/325-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows 2003 Std. R2 SQL 2005 Std. (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/335-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows 2003 Std. R2 SQL 2008 Std. (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/340-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows 2008 R2 Std wSQL 2008 R2 Std (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/341-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows 2008 R2 Std wSQL 2008 R2 Web (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/336-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows 2008 Std wSQL 2008 Std (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/327-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows 2008 Std wSQL 2008 Web (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/249-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows Server 2003 R2 Enterprise Edition (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/248-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows Server 2003 R2 Enterprise Edition (x86)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/281-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows Server 2003 R2 Standard Edition (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/280-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows Server 2003 R2 Standard Edition (x86)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/261-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows Server 2008 Enterprise Edition (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/307-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows Server 2008 Enterprise Edition (x86)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/256-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows Server 2008 R2 Enterprise Edition (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/322-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows Server 2008 R2 Standard Edition (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/270-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows Server 2008 R2 Web Edition (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/269-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows Server 2008 Standard Edition (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/267-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows Server 2008 Standard Edition (x86)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/277-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows Server 2008 Web Edition (x64)" />
<CatalogItem
href="https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.7/catalogItem/276-691"
type="application/vnd.vmware.vcloud.catalogItem+xml" name="-Windows Server 2008 Web Edition (x86)" />
</CatalogItems>
</Catalog>