| 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 | */ |
| 19 | package org.jclouds.vcloud.compute.config; |
| 20 | |
| 21 | |
| 22 | import static org.jclouds.compute.domain.OsFamily.UBUNTU; |
| 23 | |
| 24 | import org.jclouds.compute.ComputeServiceContext; |
| 25 | import org.jclouds.compute.config.BindComputeStrategiesByClass; |
| 26 | import org.jclouds.compute.config.BindComputeSuppliersByClass; |
| 27 | import org.jclouds.compute.domain.Hardware; |
| 28 | import org.jclouds.compute.domain.Image; |
| 29 | import org.jclouds.compute.domain.NodeMetadata; |
| 30 | import org.jclouds.compute.domain.TemplateBuilder; |
| 31 | import org.jclouds.compute.internal.ComputeServiceContextImpl; |
| 32 | import org.jclouds.compute.options.TemplateOptions; |
| 33 | import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; |
| 34 | import org.jclouds.rest.RestContext; |
| 35 | import org.jclouds.rest.internal.RestContextImpl; |
| 36 | import org.jclouds.vcloud.VCloudClient; |
| 37 | import org.jclouds.vcloud.compute.functions.HardwareForVApp; |
| 38 | import org.jclouds.vcloud.compute.functions.HardwareInOrg; |
| 39 | import org.jclouds.vcloud.compute.functions.ImagesInOrg; |
| 40 | import org.jclouds.vcloud.compute.functions.VAppToNodeMetadata; |
| 41 | import org.jclouds.vcloud.compute.internal.VCloudTemplateBuilderImpl; |
| 42 | import org.jclouds.vcloud.compute.options.VCloudTemplateOptions; |
| 43 | import org.jclouds.vcloud.compute.strategy.GetLoginCredentialsFromGuestConfiguration; |
| 44 | import org.jclouds.vcloud.domain.Org; |
| 45 | import org.jclouds.vcloud.domain.VApp; |
| 46 | |
| 47 | import com.google.common.base.Function; |
| 48 | import com.google.inject.Injector; |
| 49 | import com.google.inject.Scopes; |
| 50 | import com.google.inject.TypeLiteral; |
| 51 | |
| 52 | /** |
| 53 | * Configures the {@link VCloudComputeServiceContext}; requires {@link VCloudComputeClientImpl} |
| 54 | * bound. |
| 55 | * |
| 56 | * @author Adrian Cole |
| 57 | */ |
| 58 | public class VCloudComputeServiceContextModule extends CommonVCloudComputeServiceContextModule { |
| 59 | |
| 60 | @Override |
| 61 | protected void configure() { |
| 62 | super.configure(); |
| 63 | bind(new TypeLiteral<Function<VApp, NodeMetadata>>() { |
| 64 | }).to(VAppToNodeMetadata.class); |
| 65 | bind(TemplateOptions.class).to(VCloudTemplateOptions.class); |
| 66 | bind(TemplateBuilder.class).to(VCloudTemplateBuilderImpl.class); |
| 67 | bind(new TypeLiteral<Function<VApp, Hardware>>() { |
| 68 | }).to(new TypeLiteral<HardwareForVApp>() { |
| 69 | }); |
| 70 | bind(new TypeLiteral<ComputeServiceContext>() { |
| 71 | }).to(new TypeLiteral<ComputeServiceContextImpl<VCloudClient, VCloudClient>>() { |
| 72 | }).in(Scopes.SINGLETON); |
| 73 | bind(new TypeLiteral<RestContext<VCloudClient, VCloudClient>>() { |
| 74 | }).to(new TypeLiteral<RestContextImpl<VCloudClient, VCloudClient>>() { |
| 75 | }).in(Scopes.SINGLETON); |
| 76 | bind(new TypeLiteral<Function<Org, Iterable<? extends Image>>>() { |
| 77 | }).to(new TypeLiteral<ImagesInOrg>() { |
| 78 | }); |
| 79 | bind(new TypeLiteral<Function<Org, Iterable<? extends Hardware>>>() { |
| 80 | }).to(new TypeLiteral<HardwareInOrg>() { |
| 81 | }); |
| 82 | bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to(GetLoginCredentialsFromGuestConfiguration.class); |
| 83 | } |
| 84 | |
| 85 | //CIM ostype does not include version info |
| 86 | @Override |
| 87 | protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { |
| 88 | return template.osFamily(UBUNTU).os64Bit(true); |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public BindComputeStrategiesByClass defineComputeStrategyModule() { |
| 93 | return new VCloudBindComputeStrategiesByClass(); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public BindComputeSuppliersByClass defineComputeSupplierModule() { |
| 98 | return new VCloudBindComputeSuppliersByClass(); |
| 99 | } |
| 100 | } |