| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.trmk.ecloud.compute.functions; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrUnrecognized; |
| 23 | |
| 24 | import java.util.Map; |
| 25 | import java.util.regex.Matcher; |
| 26 | import java.util.regex.Pattern; |
| 27 | |
| 28 | import javax.inject.Inject; |
| 29 | import javax.inject.Singleton; |
| 30 | |
| 31 | import org.jclouds.compute.domain.OperatingSystem; |
| 32 | import org.jclouds.compute.domain.OperatingSystem.Builder; |
| 33 | import org.jclouds.compute.domain.OsFamily; |
| 34 | import org.jclouds.compute.util.ComputeServiceUtils; |
| 35 | import org.jclouds.trmk.vcloud_0_8.compute.functions.ParseOsFromVAppTemplateName; |
| 36 | |
| 37 | /** |
| 38 | * @author Adrian Cole |
| 39 | */ |
| 40 | @Singleton |
| 41 | public class TerremarkECloudParseOsFromVAppTemplateName extends ParseOsFromVAppTemplateName { |
| 42 | // CentOS 5 (x64) |
| 43 | public static final Pattern OS_PATTERN = Pattern.compile("^-?([^ ]*) ([0-9.]+)( R[1-9])? ?.*"); |
| 44 | |
| 45 | @Inject |
| 46 | protected TerremarkECloudParseOsFromVAppTemplateName(Map<OsFamily, Map<String, String>> osVersionMap) { |
| 47 | super(osVersionMap); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public OperatingSystem apply(String from) { |
| 52 | checkNotNull(from, "vapp template name"); |
| 53 | Builder builder = new OperatingSystem.Builder(); |
| 54 | builder.description(from); |
| 55 | if (from.equals("-Windows 2003 Std. R2 SQL 2005 Std. (x64)")) |
| 56 | System.out.print(';'); |
| 57 | builder.is64Bit(from.indexOf("64") != -1); |
| 58 | from = from.replace("Red Hat Enterprise Linux", "RHEL").replace("Sun Solaris", "SOLARIS").replace( |
| 59 | " Server", "").replace("Std. ", ""); |
| 60 | Matcher matcher = OS_PATTERN.matcher(from); |
| 61 | if (matcher.find()) { |
| 62 | OsFamily osFamily = parseOsFamilyOrUnrecognized(matcher.group(1)); |
| 63 | builder.family(osFamily); |
| 64 | String version = (matcher.group(3) != null) ? matcher.group(2) + matcher.group(3) : matcher.group(2); |
| 65 | builder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, version, osVersionMap)); |
| 66 | } else { |
| 67 | OsFamily osFamily = parseOsFamilyOrUnrecognized(from); |
| 68 | builder.family(osFamily); |
| 69 | } |
| 70 | return builder.build(); |
| 71 | } |
| 72 | } |