EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.vcloud.compute.util]

COVERAGE SUMMARY FOR SOURCE FILE [VCloudComputeUtils.java]

nameclass, %method, %block, %line, %
VCloudComputeUtils.java100% (1/1)60%  (6/10)54%  (109/201)57%  (20/35)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VCloudComputeUtils100% (1/1)60%  (6/10)54%  (109/201)57%  (20/35)
VCloudComputeUtils (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getCredentialsFrom (VAppTemplate): Credentials 0%   (0/1)0%   (0/13)0%   (0/1)
getVirtualSystemIdentifierOf (Vm): String 0%   (0/1)0%   (0/14)0%   (0/3)
getVirtualSystemIdentifierOfFirstVMIn (VApp): String 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 * 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 */
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 String getVirtualSystemIdentifierOfFirstVMIn(VApp vApp) {
61      return vApp.getChildren().size() > 0 ? getVirtualSystemIdentifierOf(Iterables.get(vApp.getChildren(), 0)) : null;
62   }
63 
64   public static String getVirtualSystemIdentifierOf(Vm vm) {
65      if (vm.getVirtualHardwareSection() != null && vm.getVirtualHardwareSection().getSystem() != null)
66         return vm.getVirtualHardwareSection().getSystem().getVirtualSystemIdentifier();
67      return null;
68   }
69 
70   public static Credentials getCredentialsFrom(VApp vApp) {
71      return vApp.getChildren().size() > 0 ? getCredentialsFrom(Iterables.get(vApp.getChildren(), 0)) : null;
72   }
73 
74   public static Credentials getCredentialsFrom(VAppTemplate vApp) {
75      return vApp.getChildren().size() > 0 ? getCredentialsFrom(Iterables.get(vApp.getChildren(), 0)) : null;
76   }
77 
78   public static Credentials getCredentialsFrom(Vm vm) {
79      String user = "root";
80      if (vm.getOperatingSystemSection() != null && vm.getOperatingSystemSection().getDescription() != null
81            && vm.getOperatingSystemSection().getDescription().indexOf("Windows") >= 0)
82         user = "Administrator";
83      String password = null;
84      if (vm.getGuestCustomizationSection() != null)
85         password = vm.getGuestCustomizationSection().getAdminPassword();
86      return new Credentials(user, password);
87   }
88 
89   public static Set<String> getIpsFromVApp(VApp vApp) {
90      // TODO make this work with composite vApps
91      if (vApp.getChildren().size() == 0)
92         return ImmutableSet.of();
93      Builder<String> ips = ImmutableSet.<String> builder();
94      Vm vm = Iterables.get(vApp.getChildren(), 0);
95      // TODO: figure out how to differentiate public from private ip addresses
96      // assumption is that we'll do this from the network object, which may
97      // have
98      // enough data to tell whether or not it is a public network without
99      // string
100      // parsing. At worst, we could have properties set per cloud provider to
101      // declare the networks which are public, then check against these in
102      // networkconnection.getNetwork
103      if (vm.getNetworkConnectionSection() != null) {
104         for (NetworkConnection connection : vm.getNetworkConnectionSection().getConnections()) {
105            if (connection.getIpAddress() != null)
106               ips.add(connection.getIpAddress());
107            if (connection.getExternalIpAddress() != null)
108               ips.add(connection.getExternalIpAddress());
109         }
110      } else {
111         for (ResourceAllocationSettingData net : filter(vm.getVirtualHardwareSection().getItems(),
112               CIMPredicates.resourceTypeIn(ResourceType.ETHERNET_ADAPTER))) {
113            if (net instanceof VCloudNetworkAdapter) {
114               VCloudNetworkAdapter vNet = VCloudNetworkAdapter.class.cast(net);
115               if (vNet.getIpAddress() != null)
116                  ips.add(vNet.getIpAddress());
117            }
118         }
119      }
120      return ips.build();
121   }
122}

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