EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.vcloud.compute.util]

COVERAGE SUMMARY FOR SOURCE FILE [VCloudComputeUtils.java]

nameclass, %method, %block, %line, %
VCloudComputeUtils.java100% (1/1)75%  (6/8)63%  (109/174)65%  (20/31)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VCloudComputeUtils100% (1/1)75%  (6/8)63%  (109/174)65%  (20/31)
VCloudComputeUtils (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getCredentialsFrom (VAppTemplate): Credentials 0%   (0/1)0%   (0/13)0%   (0/1)
getIpsFromVApp (VApp): Set 100% (1/1)49%  (43/87)55%  (9.3/17)
toComputeOs (VApp, OperatingSystem): OperatingSystem 100% (1/1)89%  (8/9)94%  (1.9/2)
getCredentialsFrom (VApp): Credentials 100% (1/1)92%  (12/13)92%  (0.9/1)
toComputeOs (VApp): CIMOperatingSystem 100% (1/1)92%  (12/13)92%  (0.9/1)
getCredentialsFrom (Vm): Credentials 100% (1/1)94%  (30/32)86%  (6/7)
toComputeOs (Vm): CIMOperatingSystem 100% (1/1)100% (4/4)100% (1/1)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.vcloud.compute.util;
20 
21import static com.google.common.collect.Iterables.filter;
22 
23import java.util.Set;
24 
25import org.jclouds.cim.CIMPredicates;
26import org.jclouds.cim.ResourceAllocationSettingData;
27import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
28import org.jclouds.compute.domain.CIMOperatingSystem;
29import org.jclouds.compute.domain.OperatingSystem;
30import org.jclouds.domain.Credentials;
31import org.jclouds.vcloud.domain.NetworkConnection;
32import org.jclouds.vcloud.domain.VApp;
33import org.jclouds.vcloud.domain.VAppTemplate;
34import org.jclouds.vcloud.domain.Vm;
35import org.jclouds.vcloud.domain.ovf.VCloudNetworkAdapter;
36 
37import com.google.common.collect.ImmutableSet;
38import com.google.common.collect.Iterables;
39import com.google.common.collect.ImmutableSet.Builder;
40 
41/**
42 * 
43 * @author Adrian Cole
44 */
45public class VCloudComputeUtils {
46   public static OperatingSystem toComputeOs(VApp vApp, OperatingSystem defaultOs) {
47      CIMOperatingSystem cimOs = toComputeOs(vApp);
48      return cimOs != null ? cimOs : defaultOs;
49   }
50 
51   public static CIMOperatingSystem toComputeOs(VApp vApp) {
52      // TODO we need to change the design so that it doesn't assume single-vms
53      return vApp.getChildren().size() > 0 ? toComputeOs(Iterables.get(vApp.getChildren(), 0)) : null;
54   }
55 
56   public static CIMOperatingSystem toComputeOs(Vm vm) {
57      return CIMOperatingSystem.toComputeOs(vm.getOperatingSystemSection());
58   }
59 
60   public static Credentials getCredentialsFrom(VApp vApp) {
61      return vApp.getChildren().size() > 0 ? getCredentialsFrom(Iterables.get(vApp.getChildren(), 0)) : null;
62   }
63 
64   public static Credentials getCredentialsFrom(VAppTemplate vApp) {
65      return vApp.getChildren().size() > 0 ? getCredentialsFrom(Iterables.get(vApp.getChildren(), 0)) : null;
66   }
67 
68   public static Credentials getCredentialsFrom(Vm vm) {
69      String user = "root";
70      if (vm.getOperatingSystemSection() != null && vm.getOperatingSystemSection().getDescription() != null
71            && vm.getOperatingSystemSection().getDescription().indexOf("Windows") >= 0)
72         user = "Administrator";
73      String password = null;
74      if (vm.getGuestCustomizationSection() != null)
75         password = vm.getGuestCustomizationSection().getAdminPassword();
76      return new Credentials(user, password);
77   }
78 
79   public static Set<String> getIpsFromVApp(VApp vApp) {
80      // TODO make this work with composite vApps
81      if (vApp.getChildren().size() == 0)
82         return ImmutableSet.of();
83      Builder<String> ips = ImmutableSet.<String> builder();
84      Vm vm = Iterables.get(vApp.getChildren(), 0);
85      // TODO: figure out how to differentiate public from private ip addresses
86      // assumption is that we'll do this from the network object, which may have
87      // enough data to tell whether or not it is a public network without string
88      // parsing. At worst, we could have properties set per cloud provider to
89      // declare the networks which are public, then check against these in
90      // networkconnection.getNetwork
91      if (vm.getNetworkConnectionSection() != null) {
92         for (NetworkConnection connection : vm.getNetworkConnectionSection().getConnections()) {
93            if (connection.getIpAddress() != null)
94               ips.add(connection.getIpAddress());
95            if (connection.getExternalIpAddress() != null)
96               ips.add(connection.getExternalIpAddress());
97         }
98      } else {
99         for (ResourceAllocationSettingData net : filter(vm.getVirtualHardwareSection().getItems(),
100               CIMPredicates.resourceTypeIn(ResourceType.ETHERNET_ADAPTER))) {
101            if (net instanceof VCloudNetworkAdapter) {
102               VCloudNetworkAdapter vNet = VCloudNetworkAdapter.class.cast(net);
103               if (vNet.getIpAddress() != null)
104                  ips.add(vNet.getIpAddress());
105            }
106         }
107      }
108      return ips.build();
109   }
110}

[all classes][org.jclouds.vcloud.compute.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov