| 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.vcloud.domain.network.nat.rules; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import org.jclouds.javax.annotation.Nullable; |
| 24 | |
| 25 | import org.jclouds.vcloud.domain.network.nat.NatRule; |
| 26 | |
| 27 | /** |
| 28 | * The OneToOneVmRule element describes a NAT rule that specifies network address translation |
| 29 | * details for a single virtual machine. The external IP address can be specified manually or |
| 30 | * assigned automatically at deployment time. The internal IP address is discovered by looking up |
| 31 | * the specified VmReference and NIC ID. |
| 32 | * |
| 33 | * @since vcloud 0.9 |
| 34 | * @author Adrian Cole |
| 35 | */ |
| 36 | public class OneToOneVmRule implements NatRule { |
| 37 | private final MappingMode mappingMode; |
| 38 | @Nullable |
| 39 | private final String externalIP; |
| 40 | @Nullable |
| 41 | private final String vAppScopedVmId; |
| 42 | private final int vmNicId; |
| 43 | |
| 44 | public OneToOneVmRule(MappingMode mappingMode, @Nullable String externalIp, @Nullable String vAppScopedVmId, |
| 45 | int vmNicId) { |
| 46 | this.mappingMode = checkNotNull(mappingMode, "mappingMode"); |
| 47 | this.externalIP = externalIp; |
| 48 | this.vAppScopedVmId = vAppScopedVmId; |
| 49 | this.vmNicId = vmNicId; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @return how IP address mapping is implemented by the NAT service |
| 54 | * @since vcloud 0.9 |
| 55 | */ |
| 56 | public MappingMode getMappingMode() { |
| 57 | return mappingMode; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @return if MappingMode is manual, specifies the external IP address of this Vm, otherwise |
| 62 | * null. |
| 63 | * @since vcloud 0.9 |
| 64 | */ |
| 65 | @Nullable |
| 66 | @Override |
| 67 | public String getExternalIP() { |
| 68 | return externalIP; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @return read?only identifier created on import |
| 73 | * @since vcloud 0.9 |
| 74 | */ |
| 75 | @Nullable |
| 76 | public String getVAppScopedVmId() { |
| 77 | return vAppScopedVmId; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @return device number of the NIC on the referenced virtual machine |
| 82 | * @since vcloud 0.9 |
| 83 | */ |
| 84 | public int getVmNicId() { |
| 85 | return vmNicId; |
| 86 | } |
| 87 | |
| 88 | } |