| 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.domain.network.internal; |
| 20 | |
| 21 | import org.jclouds.vcloud.domain.Task; |
| 22 | import org.jclouds.vcloud.domain.network.DhcpService; |
| 23 | import org.jclouds.vcloud.domain.network.Features; |
| 24 | import org.jclouds.vcloud.domain.network.FenceMode; |
| 25 | import org.jclouds.vcloud.domain.network.FirewallService; |
| 26 | import org.jclouds.vcloud.domain.network.IpRange; |
| 27 | import org.jclouds.vcloud.domain.network.IpScope; |
| 28 | import org.jclouds.vcloud.domain.network.NatService; |
| 29 | import org.jclouds.vcloud.domain.network.VCloudExpressNetwork; |
| 30 | |
| 31 | import com.google.common.collect.ImmutableSet; |
| 32 | import com.google.common.collect.Iterables; |
| 33 | |
| 34 | /** |
| 35 | * |
| 36 | * @author Adrian Cole |
| 37 | */ |
| 38 | public class VCloudExpressOrgNetworkAdapter extends OrgNetworkImpl { |
| 39 | |
| 40 | public VCloudExpressOrgNetworkAdapter(VCloudExpressNetwork in) { |
| 41 | super(in.getName(), in.getType(), in.getHref(), null, in.getDescription(), ImmutableSet.<Task> of(), |
| 42 | parseConfiguration(in), null, ImmutableSet.<String> of()); |
| 43 | } |
| 44 | |
| 45 | static Configuration parseConfiguration(VCloudExpressNetwork in) { |
| 46 | |
| 47 | String dns1 = (in.getDnsServers().size() > 0) ? Iterables.get(in.getDnsServers(), 0) : null; |
| 48 | String dns2 = (in.getDnsServers().size() > 1) ? Iterables.get(in.getDnsServers(), 1) : null; |
| 49 | |
| 50 | String gateway = in.getGateway(); |
| 51 | |
| 52 | String netmask = in.getNetmask(); |
| 53 | |
| 54 | FenceMode mode = in.getFenceModes().size() > 0 ? Iterables.get(in.getFenceModes(), 0) : FenceMode.BRIDGED; |
| 55 | |
| 56 | DhcpService dhcp = in.isDhcp() != null && in.isDhcp() ? new DhcpService(true, null, null, null) : null; |
| 57 | |
| 58 | NatService nat = in.getNatRules().size() > 0 ? new NatService(true, null, null, in.getNatRules()) : null; |
| 59 | |
| 60 | FirewallService firewall = in.getFirewallRules().size() > 0 ? new FirewallService(true, in.getFirewallRules()) |
| 61 | : null; |
| 62 | return new OrgNetworkImpl.ConfigurationImpl(new IpScope(true, gateway, netmask, dns1, dns2, null, ImmutableSet |
| 63 | .<IpRange> of(), ImmutableSet.<String> of()), null, mode, new Features(dhcp, firewall, nat)); |
| 64 | } |
| 65 | } |