| 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.elasticstack.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.util.Set; |
| 24 | |
| 25 | import org.jclouds.javax.annotation.Nullable; |
| 26 | |
| 27 | import com.google.common.collect.ImmutableSet; |
| 28 | |
| 29 | /** |
| 30 | * |
| 31 | * @author Adrian Cole |
| 32 | */ |
| 33 | public class NIC { |
| 34 | public static class Builder { |
| 35 | private String dhcp; |
| 36 | private Model model; |
| 37 | private String vlan; |
| 38 | private String mac; |
| 39 | // TODO elasticstack specific |
| 40 | private Set<String> block = ImmutableSet.of(); |
| 41 | |
| 42 | public Builder dhcp(String dhcp) { |
| 43 | this.dhcp = dhcp; |
| 44 | return this; |
| 45 | } |
| 46 | |
| 47 | public Builder model(Model model) { |
| 48 | this.model = model; |
| 49 | return this; |
| 50 | } |
| 51 | |
| 52 | public Builder vlan(String vlan) { |
| 53 | this.vlan = vlan; |
| 54 | return this; |
| 55 | } |
| 56 | |
| 57 | public Builder mac(String mac) { |
| 58 | this.mac = mac; |
| 59 | return this; |
| 60 | } |
| 61 | |
| 62 | public Builder block(Iterable<String> block) { |
| 63 | this.block = ImmutableSet.copyOf(checkNotNull(block, "block")); |
| 64 | return this; |
| 65 | } |
| 66 | |
| 67 | public NIC build() { |
| 68 | return new NIC(dhcp, model, vlan, mac, block); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | private final String dhcp; |
| 73 | private final Model model; |
| 74 | private final String vlan; |
| 75 | private final String mac; |
| 76 | private final Set<String> block; |
| 77 | |
| 78 | public NIC(@Nullable String dhcp, Model model, @Nullable String vlan, @Nullable String mac, Iterable<String> block) { |
| 79 | this.dhcp = dhcp; |
| 80 | this.model = checkNotNull(model, "model"); |
| 81 | this.vlan = vlan; |
| 82 | this.mac = mac; |
| 83 | this.block = ImmutableSet.copyOf(checkNotNull(block, "block")); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * |
| 88 | * @return The IP address offered by DHCP to network interface 0. If unset, no address is |
| 89 | * offered. Set to 'auto' to allocate a temporary IP at boot. |
| 90 | */ |
| 91 | public String getDhcp() { |
| 92 | return dhcp; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * |
| 97 | * @return Create network interface with given type (use 'e1000' as default value; 'rtl8139' or |
| 98 | * 'virtio' are also available). |
| 99 | */ |
| 100 | public Model getModel() { |
| 101 | return model; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * |
| 106 | * @return The VLAN to which the network interface is attached. |
| 107 | */ |
| 108 | public String getVlan() { |
| 109 | return vlan; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * |
| 114 | * @return The MAC address of the network interface. If unset, a randomly generated address is |
| 115 | * used. If set, should be unique on the VLAN. |
| 116 | */ |
| 117 | public String getMac() { |
| 118 | return mac; |
| 119 | } |
| 120 | |
| 121 | // TODO undocumented |
| 122 | public Set<String> getBlock() { |
| 123 | return block; |
| 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public int hashCode() { |
| 128 | final int prime = 31; |
| 129 | int result = 1; |
| 130 | result = prime * result + ((block == null) ? 0 : block.hashCode()); |
| 131 | result = prime * result + ((dhcp == null) ? 0 : dhcp.hashCode()); |
| 132 | result = prime * result + ((mac == null) ? 0 : mac.hashCode()); |
| 133 | result = prime * result + ((model == null) ? 0 : model.hashCode()); |
| 134 | result = prime * result + ((vlan == null) ? 0 : vlan.hashCode()); |
| 135 | return result; |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public boolean equals(Object obj) { |
| 140 | if (this == obj) |
| 141 | return true; |
| 142 | if (obj == null) |
| 143 | return false; |
| 144 | if (getClass() != obj.getClass()) |
| 145 | return false; |
| 146 | NIC other = (NIC) obj; |
| 147 | if (block == null) { |
| 148 | if (other.block != null) |
| 149 | return false; |
| 150 | } else if (!block.equals(other.block)) |
| 151 | return false; |
| 152 | if (dhcp == null) { |
| 153 | if (other.dhcp != null) |
| 154 | return false; |
| 155 | } else if (!dhcp.equals(other.dhcp)) |
| 156 | return false; |
| 157 | if (mac == null) { |
| 158 | if (other.mac != null) |
| 159 | return false; |
| 160 | } else if (!mac.equals(other.mac)) |
| 161 | return false; |
| 162 | if (model != other.model) |
| 163 | return false; |
| 164 | if (vlan == null) { |
| 165 | if (other.vlan != null) |
| 166 | return false; |
| 167 | } else if (!vlan.equals(other.vlan)) |
| 168 | return false; |
| 169 | return true; |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public String toString() { |
| 174 | return "[dhcp=" + dhcp + ", model=" + model + ", vlan=" + vlan + ", mac=" + mac + ", block=" + block + "]"; |
| 175 | } |
| 176 | } |