bug 9621: set addressFormat during NicProfile creation

status 9621: resolved fixed
This commit is contained in:
alena 2011-04-27 23:19:43 -07:00
parent 485f7a10cc
commit f8742adcd5
3 changed files with 133 additions and 140 deletions

View File

@ -22,32 +22,25 @@ import java.util.Date;
import java.util.List;
import java.util.Set;
import com.cloud.network.Networks.AddressFormat;
import com.cloud.network.Networks.Mode;
import com.cloud.utils.fsm.FiniteState;
import com.cloud.utils.fsm.StateMachine;
/**
* Nic represents one nic on the VM.
*/
public interface Nic {
enum Event {
ReservationRequested,
ReleaseRequested,
CancelRequested,
OperationCompleted,
OperationFailed,
ReservationRequested, ReleaseRequested, CancelRequested, OperationCompleted, OperationFailed,
}
public enum State implements FiniteState<State, Event> {
Allocated("Resource is allocated but not reserved"),
Reserving("Resource is being reserved right now"),
Reserved("Resource has been reserved."),
Releasing("Resource is being released"),
Deallocating("Resource is being deallocated");
Allocated("Resource is allocated but not reserved"), Reserving("Resource is being reserved right now"), Reserved("Resource has been reserved."), Releasing("Resource is being released"), Deallocating(
"Resource is being deallocated");
String _description;
@Override
public StateMachine<State, Event> getStateMachine() {
return s_fsm;
@ -67,16 +60,16 @@ public interface Nic {
public Set<Event> getPossibleEvents() {
return s_fsm.getPossibleEvents(this);
}
private State(String description) {
_description = description;
}
@Override
public String getDescription() {
return _description;
}
final static private StateMachine<State, Event> s_fsm = new StateMachine<State, Event>();
static {
s_fsm.addTransition(State.Allocated, Event.ReservationRequested, State.Reserving);
@ -88,69 +81,69 @@ public interface Nic {
s_fsm.addTransition(State.Releasing, Event.OperationFailed, State.Reserved);
}
}
public enum ReservationStrategy {
PlaceHolder,
Create,
Start;
PlaceHolder, Create, Start;
}
/**
* @return id in the CloudStack database
*/
long getId();
/**
* @return reservation id returned by the allocation source. This can be the
* String version of the database id if the allocation source does not need it's
* own implementation of the reservation id. This is passed back to the
* allocation source to release the resource.
* @return reservation id returned by the allocation source. This can be the String version of the database id if the
* allocation source does not need it's own implementation of the reservation id. This is passed back to the
* allocation source to release the resource.
*/
String getReservationId();
/**
* @return unique name for the allocation source.
*/
String getReserver();
/**
* @return the time a reservation request was made to the allocation source.
*/
Date getUpdateTime();
/**
* @return the reservation state of the resource.
*/
State getState();
ReservationStrategy getReservationStrategy();
boolean isDefaultNic();
String getIp4Address();
String getMacAddress();
String getNetmask();
String getGateway();
/**
* @return network profile id that this
* @return network profile id that this
*/
long getNetworkId();
/**
* @return the vm instance id that this nic belongs to.
*/
long getInstanceId();
int getDeviceId();
Mode getMode();
URI getIsolationUri();
URI getBroadcastUri();
VirtualMachine.Type getVmType();
AddressFormat getAddressFormat();
}

View File

@ -53,55 +53,55 @@ public class NicProfile {
String dns2;
Integer networkRate;
boolean isSecurityGroupEnabled;
public String getDns1() {
return dns1;
}
public String getDns2() {
return dns2;
}
public void setDns1(String dns1) {
this.dns1 = dns1;
}
public void setDns2(String dns2) {
this.dns2 = dns2;
}
public boolean isDefaultNic() {
return defaultNic;
}
public String getNetmask() {
return netmask;
}
public void setNetmask(String netmask) {
this.netmask = netmask;
}
public void setBroadcastUri(URI broadcastUri) {
this.broadcastUri = broadcastUri;
}
public URI getBroadCastUri() {
return broadcastUri;
}
public void setIsolationUri(URI isolationUri) {
this.isolationUri = isolationUri;
}
public URI getIsolationUri() {
return isolationUri;
}
public void setStrategy(ReservationStrategy strategy) {
this.strategy = strategy;
}
public BroadcastDomainType getType() {
return broadcastType;
}
@ -117,11 +117,11 @@ public class NicProfile {
public void setDeviceId(int deviceId) {
this.deviceId = deviceId;
}
public void setDefaultNic(boolean defaultNic) {
this.defaultNic = defaultNic;
}
public Integer getDeviceId() {
return deviceId;
}
@ -145,15 +145,15 @@ public class NicProfile {
public Mode getMode() {
return mode;
}
public long getNetworkId() {
return networkId;
}
public long getVirtualMachineId() {
return vmId;
}
public long getId() {
return id;
}
@ -189,15 +189,15 @@ public class NicProfile {
public String getIp6Address() {
return ip6Address;
}
public String getMacAddress() {
return macAddress;
}
public void setIp4Address(String ip4Address) {
this.ip4Address = ip4Address;
}
public Integer getNetworkRate() {
return networkRate;
}
@ -211,10 +211,10 @@ public class NicProfile {
this.networkId = network.getId();
this.gateway = nic.getGateway();
this.mode = network.getMode();
this.format = null;
this.broadcastType = network.getBroadcastDomainType();
this.trafficType = network.getTrafficType();
this.ip4Address = nic.getIp4Address();
this.format = nic.getAddressFormat();
this.ip6Address = null;
this.macAddress = nic.getMacAddress();
this.reservationId = nic.getReservationId();
@ -226,7 +226,7 @@ public class NicProfile {
this.netmask = nic.getNetmask();
this.isSecurityGroupEnabled = network.isSecurityGroupEnabled();
this.vmId = nic.getInstanceId();
if (networkRate != null) {
this.networkRate = networkRate;
}
@ -238,7 +238,7 @@ public class NicProfile {
this.mode = mode;
this.vmId = vmId;
}
public NicProfile(ReservationStrategy strategy, String ip4Address, String macAddress, String gateway, String netmask) {
this.format = AddressFormat.Ip4;
this.ip4Address = ip4Address;
@ -247,30 +247,30 @@ public class NicProfile {
this.netmask = netmask;
this.strategy = strategy;
}
public NicProfile() {
}
public ReservationStrategy getReservationStrategy() {
return strategy;
}
public String getReservationId() {
return reservationId;
}
public void setReservationId(String reservationId) {
this.reservationId = reservationId;
}
public boolean isSecurityGroupEnabled() {
return this.isSecurityGroupEnabled;
}
public void setSecurityGroupEnabled(boolean enabled) {
this.isSecurityGroupEnabled = enabled;
}
public void deallocate() {
this.gateway = null;
this.mode = null;
@ -289,7 +289,7 @@ public class NicProfile {
this.dns1 = null;
this.dns2 = null;
}
@Override
public String toString() {
return new StringBuilder("NicProfile[").append(id).append("-").append(vmId).append("-").append(reservationId).toString();

View File

@ -34,81 +34,81 @@ import com.cloud.network.Networks.Mode;
import com.cloud.utils.db.GenericDao;
@Entity
@Table(name="nics")
@Table(name = "nics")
public class NicVO implements Nic {
protected NicVO() {
}
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
long id;
@Column(name="instance_id")
@Column(name = "instance_id")
Long instanceId;
@Column(name="ip4_address")
@Column(name = "ip4_address")
String ip4Address;
@Column(name="ip6_address")
@Column(name = "ip6_address")
String ip6Address;
@Column(name="netmask")
@Column(name = "netmask")
String netmask;
@Column(name="isolation_uri")
@Column(name = "isolation_uri")
URI isolationUri;
@Column(name="ip_type")
@Column(name = "ip_type")
AddressFormat addressFormat;
@Column(name="broadcast_uri")
@Column(name = "broadcast_uri")
URI broadcastUri;
@Column(name="gateway")
@Column(name = "gateway")
String gateway;
@Column(name="mac_address")
@Column(name = "mac_address")
String macAddress;
@Column(name="mode")
@Enumerated(value=EnumType.STRING)
@Column(name = "mode")
@Enumerated(value = EnumType.STRING)
Mode mode;
@Column(name="network_id")
@Column(name = "network_id")
long networkId;
@Column(name="state")
@Enumerated(value=EnumType.STRING)
@Column(name = "state")
@Enumerated(value = EnumType.STRING)
State state;
@Column(name="reserver_name")
@Column(name = "reserver_name")
String reserver;
@Column(name="reservation_id")
@Column(name = "reservation_id")
String reservationId;
@Column(name="device_id")
@Column(name = "device_id")
int deviceId;
@Column(name="update_time")
@Column(name = "update_time")
Date updateTime;
@Column(name="default_nic")
@Column(name = "default_nic")
boolean defaultNic;
@Column(name="strategy")
@Enumerated(value=EnumType.STRING)
@Column(name = "strategy")
@Enumerated(value = EnumType.STRING)
ReservationStrategy reservationStrategy;
@Enumerated(value=EnumType.STRING)
@Column(name="vm_type")
@Enumerated(value = EnumType.STRING)
@Column(name = "vm_type")
VirtualMachine.Type vmType;
@Column(name=GenericDao.REMOVED_COLUMN)
@Column(name = GenericDao.REMOVED_COLUMN)
Date removed;
@Column(name=GenericDao.CREATED_COLUMN)
@Column(name = GenericDao.CREATED_COLUMN)
Date created;
public NicVO(String reserver, Long instanceId, long configurationId, VirtualMachine.Type vmType) {
@ -118,12 +118,12 @@ public class NicVO implements Nic {
this.state = State.Allocated;
this.vmType = vmType;
}
@Override
public String getIp4Address() {
return ip4Address;
}
public void setIp4Address(String address) {
ip4Address = address;
}
@ -132,7 +132,7 @@ public class NicVO implements Nic {
public String getMacAddress() {
return macAddress;
}
public void setMacAddress(String macAddress) {
this.macAddress = macAddress;
}
@ -141,16 +141,16 @@ public class NicVO implements Nic {
public State getState() {
return state;
}
@Override
public boolean isDefaultNic() {
return defaultNic;
}
public void setDefaultNic(boolean defaultNic) {
this.defaultNic = defaultNic;
}
public String getIp6Address() {
return ip6Address;
}
@ -163,20 +163,21 @@ public class NicVO implements Nic {
public String getNetmask() {
return netmask;
}
@Override
public String getGateway() {
return gateway;
}
public void setGateway(String gateway) {
this.gateway = gateway;
}
@Override
public AddressFormat getAddressFormat() {
return addressFormat;
}
public void setAddressFormat(AddressFormat format) {
this.addressFormat = format;
}
@ -233,22 +234,21 @@ public class NicVO implements Nic {
public long getNetworkId() {
return networkId;
}
@Override
public int getDeviceId() {
return deviceId;
}
@Override
public String getReservationId() {
return reservationId;
}
public void setReservationId(String id) {
this.reservationId = id;
}
public void setReservationStrategy(ReservationStrategy strategy) {
this.reservationStrategy = strategy;
}
@ -261,7 +261,7 @@ public class NicVO implements Nic {
public Mode getMode() {
return mode;
}
public void setMode(Mode mode) {
this.mode = mode;
}
@ -270,11 +270,11 @@ public class NicVO implements Nic {
public String getReserver() {
return reserver;
}
public void setReserver(String reserver) {
this.reserver = reserver;
}
@Override
public ReservationStrategy getReservationStrategy() {
return reservationStrategy;
@ -300,7 +300,7 @@ public class NicVO implements Nic {
public void setCreated(Date created) {
this.created = created;
}
@Override
public String toString() {
return new StringBuilder("Nic[").append(id).append("-").append(instanceId).append("-").append(reservationId).append("-").append(ip4Address).append("]").toString();