mirror of https://github.com/apache/cloudstack.git
more checkins
This commit is contained in:
parent
286e78c849
commit
8acba8fbd1
|
|
@ -16,8 +16,12 @@ public interface Pod extends Grouping {
|
|||
long getId();
|
||||
|
||||
String getCidrAddress();
|
||||
|
||||
int getCidrSize();
|
||||
public String getGateway();
|
||||
|
||||
String getGateway();
|
||||
|
||||
long getDataCenterId();
|
||||
|
||||
//String getUniqueName();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,4 +59,12 @@ public class Network {
|
|||
Vpn,
|
||||
Management
|
||||
};
|
||||
|
||||
public enum IsolationType {
|
||||
None,
|
||||
Ec2,
|
||||
Vlan,
|
||||
Vswitch,
|
||||
Vnet;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,4 +29,6 @@ public interface NetworkElement extends Adapter {
|
|||
* @return
|
||||
*/
|
||||
boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering);
|
||||
|
||||
boolean shutdown(NetworkConfiguration config, NetworkOffering offering);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
*/
|
||||
package com.cloud.vm;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import com.cloud.network.Network.AddressFormat;
|
||||
import com.cloud.network.Network.BroadcastDomainType;
|
||||
import com.cloud.network.Network.Mode;
|
||||
|
|
@ -22,6 +24,33 @@ public class NicProfile {
|
|||
String ip4Address;
|
||||
String ip6Address;
|
||||
String macAddress;
|
||||
URI isolationUri;
|
||||
String netmask;
|
||||
URI broadcastUri;
|
||||
|
||||
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 setIsolationUril(URI isolationUri) {
|
||||
this.isolationUri = isolationUri;
|
||||
}
|
||||
|
||||
public URI getIsolationUri() {
|
||||
return isolationUri;
|
||||
}
|
||||
|
||||
public BroadcastDomainType getType() {
|
||||
return broadcastType;
|
||||
|
|
|
|||
|
|
@ -2477,7 +2477,17 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
|
|||
NetworkConcierge concierge = _networkConcierges.get(nic.getReserver());
|
||||
nic.setState(Resource.State.Reserving);
|
||||
_nicDao.update(nic.getId(), nic);
|
||||
concierge.reserve(null, toNicProfile(nic), dest);
|
||||
NicProfile profile = toNicProfile(nic);
|
||||
String reservationId = concierge.reserve(null, profile, dest);
|
||||
nic.setIp4Address(profile.getIp4Address());
|
||||
nic.setIp6Address(profile.getIp6Address());
|
||||
nic.setMacAddress(profile.getMacAddress());
|
||||
nic.setIsolationUri(profile.getIsolationUri());
|
||||
nic.setBroadcastUri(profile.getBroadCastUri());
|
||||
nic.setReservationId(reservationId);
|
||||
nic.setReserver(concierge.getUniqueName());
|
||||
nic.setState(Resource.State.Reserved);
|
||||
_nicDao.update(nic.getId(), nic);
|
||||
} else {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ public class ControlNetworkGuru extends AdapterBase implements NetworkGuru, Netw
|
|||
String ip = _dcDao.allocateLinkLocalPrivateIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), vm.getId());
|
||||
nic.setIp4Address(ip);
|
||||
nic.setMacAddress("FE:FF:FF:FF:FF:FF");
|
||||
nic.setNetmask("255.255.0.0");
|
||||
return Long.toString(nic.getId());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import javax.ejb.Local;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.Pod;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
|
|
@ -23,6 +24,7 @@ import com.cloud.user.Account;
|
|||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.NetworkConcierge;
|
||||
import com.cloud.vm.Nic;
|
||||
import com.cloud.vm.NicProfile;
|
||||
|
|
@ -79,10 +81,18 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru, Net
|
|||
@Override
|
||||
public String reserve(VirtualMachine vm, NicProfile nic, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException,
|
||||
InsufficientAddressCapacityException {
|
||||
DataCenter dc = dest.getDataCenter();
|
||||
Pod pod = dest.getPod();
|
||||
|
||||
String ip = _dcDao.allocatePrivateIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), nic.getId());
|
||||
String[] macs = _dcDao.getNextAvailableMacAddressPair(dc.getId());
|
||||
|
||||
nic.setIp4Address(ip);
|
||||
nic.setCidr(pod.getCidrAddress() + "/" + pod.getCidrSize());
|
||||
nic.setGateway(pod.getGateway());
|
||||
nic.setMacAddress(macs[0]);
|
||||
String netmask = NetUtils.getCidrSubNet(pod.getCidrAddress(), pod.getCidrSize());
|
||||
nic.setNetmask(netmask);
|
||||
|
||||
return Long.toString(nic.getId());
|
||||
}
|
||||
|
|
@ -95,8 +105,7 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru, Net
|
|||
|
||||
@Override
|
||||
public NetworkConfiguration implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination destination) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
*/
|
||||
package com.cloud.network.configuration;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -13,7 +16,6 @@ import com.cloud.dc.dao.DataCenterDao;
|
|||
import com.cloud.dc.dao.VlanDao;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.deploy.DeploymentPlan;
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
|
||||
import com.cloud.network.Network.BroadcastDomainType;
|
||||
|
|
@ -82,25 +84,26 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru, Netwo
|
|||
long podId = dest.getPod().getId();
|
||||
|
||||
Pair<String, VlanVO> ipAndVlan = _vlanDao.assignIpAddress(dcId, vm.getAccountId(), vm.getDomainId(), VlanType.VirtualNetwork, true);
|
||||
|
||||
if (ipAndVlan == null) {
|
||||
s_logger.debug("Unable to get public ip address (type=Virtual) for console proxy vm for data center : " + dcId);
|
||||
ipAndVlan = _vlanDao.assignPodDirectAttachIpAddress(dcId, podId, Account.ACCOUNT_ID_SYSTEM, DomainVO.ROOT_DOMAIN);
|
||||
if (ipAndVlan == null)
|
||||
s_logger.debug("Unable to get public ip address (type=DirectAttach) for console proxy vm for data center : " + dcId);
|
||||
throw new InsufficientVirtualNetworkCapcityException("Unable to get public ip address in " + dcId);
|
||||
}
|
||||
if (ipAndVlan != null) {
|
||||
VlanVO vlan = ipAndVlan.second();
|
||||
return null;
|
||||
// networkInfo net = new networkInfo(ipAndVlan.first(), vlan.getVlanNetmask(), vlan.getVlanGateway(), vlan.getId(), vlan.getVlanId());
|
||||
// return net;
|
||||
VlanVO vlan = ipAndVlan.second();
|
||||
ch.setIp4Address(ipAndVlan.first());
|
||||
ch.setGateway(vlan.getVlanGateway());
|
||||
ch.setNetmask(vlan.getVlanNetmask());
|
||||
try {
|
||||
ch.setIsolationUril(new URI("vlan://" + vlan.getVlanId()));
|
||||
} catch (URISyntaxException e) {
|
||||
throw new CloudRuntimeException("URI Syntax: " + "vlan://" + vlan.getVlanId(), e);
|
||||
}
|
||||
return null;
|
||||
ch.setBroadcastType(BroadcastDomainType.Vlan);
|
||||
|
||||
return Long.toString(vlan.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean release(String uniqueName, String uniqueId) {
|
||||
return false;
|
||||
return _vlanDao.release(Long.parseLong(uniqueId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
package com.cloud.vm;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
|
|
@ -47,6 +48,18 @@ public class NicVO implements Nic {
|
|||
@Column(name="ip4_address")
|
||||
String ip4Address;
|
||||
|
||||
@Column(name="ip6_address")
|
||||
String ip6Address;
|
||||
|
||||
@Column(name="netmask")
|
||||
String netmask;
|
||||
|
||||
@Column(name="isolation_uri")
|
||||
URI isolationUri;
|
||||
|
||||
@Column(name="broadcast_uri")
|
||||
URI broadcastUri;
|
||||
|
||||
@Column(name="mac_address")
|
||||
String macAddress;
|
||||
|
||||
|
|
@ -103,6 +116,50 @@ public class NicVO implements Nic {
|
|||
return state;
|
||||
}
|
||||
|
||||
public String getIp6Address() {
|
||||
return ip6Address;
|
||||
}
|
||||
|
||||
public void setIp6Address(String ip6Address) {
|
||||
this.ip6Address = ip6Address;
|
||||
}
|
||||
|
||||
public String getNetmask() {
|
||||
return netmask;
|
||||
}
|
||||
|
||||
public void setNetmask(String netmask) {
|
||||
this.netmask = netmask;
|
||||
}
|
||||
|
||||
public URI getIsolationUri() {
|
||||
return isolationUri;
|
||||
}
|
||||
|
||||
public void setIsolationUri(URI isolationUri) {
|
||||
this.isolationUri = isolationUri;
|
||||
}
|
||||
|
||||
public URI getBroadcastUri() {
|
||||
return broadcastUri;
|
||||
}
|
||||
|
||||
public void setBroadcastUri(URI broadcastUri) {
|
||||
this.broadcastUri = broadcastUri;
|
||||
}
|
||||
|
||||
public void setInstanceId(long instanceId) {
|
||||
this.instanceId = instanceId;
|
||||
}
|
||||
|
||||
public void setNetworkConfigurationId(long networkConfigurationId) {
|
||||
this.networkConfigurationId = networkConfigurationId;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public void setState(State state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ CREATE TABLE `cloud`.`network_configurations` (
|
|||
`traffic_type` varchar(32) NOT NULL COMMENT 'type of traffic going through this network',
|
||||
`broadcast_domain_type` varchar(32) NOT NULL COMMENT 'type of broadcast domain used',
|
||||
`gateway` varchar(15) COMMENT 'gateway for this network configuration',
|
||||
`cidr` varchar(18) COMMENT 'network cidr',
|
||||
`cidr` varchar(18) COMMENT 'network cidr',
|
||||
`mode` varchar(32) COMMENT 'How to retrieve ip address in this network',
|
||||
`vlan_id` bigint unsigned NULL COMMENT 'vlan id if the broadcast_domain_type is the vlan',
|
||||
`network_offering_id` bigint unsigned NOT NULL COMMENT 'network offering id that this configuration is created from',
|
||||
|
|
@ -116,8 +116,12 @@ CREATE TABLE `cloud`.`account_network_ref` (
|
|||
CREATE TABLE `cloud`.`nics` (
|
||||
`id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id',
|
||||
`instance_id` bigint unsigned NOT NULL COMMENT 'vm instance id',
|
||||
`ip4_address` varchar(15) COMMENT 'ip4 address',
|
||||
`mac_address` varchar(17) COMMENT 'mac address',
|
||||
`ip4_address` varchar(15) COMMENT 'ip4 address',
|
||||
`netmask` varchar(15) COMMENT 'netmask for ip4 address',
|
||||
`gateway` varchar(15) COMMENT 'gateway',
|
||||
`ip_type` varchar(32) COMMENT 'type of ip',
|
||||
`broadcast_uri` varchar(255) COMMENT 'broadcast uri',
|
||||
`network_configuration_id` bigint unsigned NOT NULL COMMENT 'network configuration id',
|
||||
`mode` varchar(32) COMMENT 'mode of getting ip address',
|
||||
`state` varchar(32) NOT NULL COMMENT 'state of the creation',
|
||||
|
|
@ -125,6 +129,8 @@ CREATE TABLE `cloud`.`nics` (
|
|||
`reservation_id` varchar(64) COMMENT 'id for the reservation',
|
||||
`device_id` int(10) COMMENT 'device id for the network when plugged into the virtual machine',
|
||||
`update_time` timestamp NOT NULL COMMENT 'time the state was changed',
|
||||
`isolation_uri` varchar(255) COMMENT 'id for isolation',
|
||||
`ip6_address` varchar(32) COMMENT 'ip6 address',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,10 @@ import java.io.Serializable;
|
|||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
|
@ -439,14 +443,6 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
|
|||
final Class<?> type = field.getType();
|
||||
if (type == String.class) {
|
||||
field.set(entity, rs.getString(index));
|
||||
} else if (type == int.class) {
|
||||
field.set(entity, rs.getInt(index));
|
||||
} else if (type == Integer.class) {
|
||||
if (rs.getObject(index) == null) {
|
||||
field.set(entity, null);
|
||||
} else {
|
||||
field.set(entity, rs.getInt(index));
|
||||
}
|
||||
} else if (type == long.class) {
|
||||
field.setLong(entity, rs.getLong(index));
|
||||
} else if (type == Long.class) {
|
||||
|
|
@ -455,6 +451,26 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
|
|||
} else {
|
||||
field.set(entity, rs.getLong(index));
|
||||
}
|
||||
} else if (type.isEnum()) {
|
||||
final Enumerated enumerated = field.getAnnotation(Enumerated.class);
|
||||
final EnumType enumType = (enumerated == null) ? EnumType.STRING : enumerated.value();
|
||||
|
||||
final Enum<?>[] enums = (Enum<?>[])field.getType().getEnumConstants();
|
||||
for (final Enum<?> e : enums) {
|
||||
if ((enumType == EnumType.STRING && e.name().equalsIgnoreCase(rs.getString(index))) ||
|
||||
(enumType == EnumType.ORDINAL && e.ordinal() == rs.getInt(index))) {
|
||||
field.set(entity, e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (type == int.class) {
|
||||
field.set(entity, rs.getInt(index));
|
||||
} else if (type == Integer.class) {
|
||||
if (rs.getObject(index) == null) {
|
||||
field.set(entity, null);
|
||||
} else {
|
||||
field.set(entity, rs.getInt(index));
|
||||
}
|
||||
} else if (type == Date.class) {
|
||||
final Object data = rs.getDate(index);
|
||||
if (data == null) {
|
||||
|
|
@ -462,14 +478,15 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
|
|||
return;
|
||||
}
|
||||
field.set(entity, DateUtil.parseDateString(s_gmtTimeZone, rs.getString(index)));
|
||||
} else if (type == short.class) {
|
||||
field.setShort(entity, rs.getShort(index));
|
||||
} else if (type == Short.class) {
|
||||
if (rs.getObject(index) == null) {
|
||||
} else if (type == Calendar.class) {
|
||||
final Object data = rs.getDate(index);
|
||||
if (data == null) {
|
||||
field.set(entity, null);
|
||||
} else {
|
||||
field.set(entity, rs.getShort(index));
|
||||
return;
|
||||
}
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(DateUtil.parseDateString(s_gmtTimeZone, rs.getString(index)));
|
||||
field.set(entity, cal);
|
||||
} else if (type == boolean.class) {
|
||||
field.setBoolean(entity, rs.getBoolean(index));
|
||||
} else if (type == Boolean.class) {
|
||||
|
|
@ -478,6 +495,29 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
|
|||
} else {
|
||||
field.set(entity, rs.getBoolean(index));
|
||||
}
|
||||
} else if (type == URI.class) {
|
||||
try {
|
||||
URI uri = new URI(rs.getString(index));
|
||||
field.set(entity, uri);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new CloudRuntimeException("Invalid URI: " + rs.getString(index), e);
|
||||
}
|
||||
} else if (type == URL.class) {
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(rs.getString(index));
|
||||
} catch (MalformedURLException e) {
|
||||
throw new CloudRuntimeException("Invalid URL: " + rs.getString(index), e);
|
||||
}
|
||||
field.set(entity, url);
|
||||
} else if (type == short.class) {
|
||||
field.setShort(entity, rs.getShort(index));
|
||||
} else if (type == Short.class) {
|
||||
if (rs.getObject(index) == null) {
|
||||
field.set(entity, null);
|
||||
} else {
|
||||
field.set(entity, rs.getShort(index));
|
||||
}
|
||||
} else if (type == float.class) {
|
||||
field.setFloat(entity, rs.getFloat(index));
|
||||
} else if (type == Float.class) {
|
||||
|
|
@ -502,27 +542,6 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
|
|||
} else {
|
||||
field.set(entity, rs.getByte(index));
|
||||
}
|
||||
} else if (type == Calendar.class) {
|
||||
final Object data = rs.getDate(index);
|
||||
if (data == null) {
|
||||
field.set(entity, null);
|
||||
return;
|
||||
}
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(DateUtil.parseDateString(s_gmtTimeZone, rs.getString(index)));
|
||||
field.set(entity, cal);
|
||||
} else if (type.isEnum()) {
|
||||
final Enumerated enumerated = field.getAnnotation(Enumerated.class);
|
||||
final EnumType enumType = (enumerated == null) ? EnumType.STRING : enumerated.value();
|
||||
|
||||
final Enum<?>[] enums = (Enum<?>[])field.getType().getEnumConstants();
|
||||
for (final Enum<?> e : enums) {
|
||||
if ((enumType == EnumType.STRING && e.name().equalsIgnoreCase(rs.getString(index))) ||
|
||||
(enumType == EnumType.ORDINAL && e.ordinal() == rs.getInt(index))) {
|
||||
field.set(entity, e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (type == byte[].class) {
|
||||
field.set(entity, rs.getBytes(index));
|
||||
} else {
|
||||
|
|
@ -1189,6 +1208,10 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
|
|||
} else if (type == EnumType.ORDINAL) {
|
||||
pstmt.setInt(j, value == null ? null : ((Enum<?>)value).ordinal());
|
||||
}
|
||||
} else if (attr.field.getType() == URI.class) {
|
||||
pstmt.setString(j, value == null ? null : value.toString());
|
||||
} else if (attr.field.getType() == URL.class) {
|
||||
pstmt.setURL(j, (URL)value);
|
||||
} else if (attr.field.getType() == byte[].class) {
|
||||
pstmt.setBytes(j, (byte[])value);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue