mirror of https://github.com/apache/cloudstack.git
mac addresses for private ip addresses
This commit is contained in:
parent
5d419be638
commit
d27c0c4b01
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.agent.api;
|
||||
|
||||
import com.cloud.agent.api.to.VirtualMachineTO;
|
||||
|
||||
/**
|
||||
* This command carries information to start a VM.
|
||||
*/
|
||||
public class Start2Command extends Command {
|
||||
VirtualMachineTO vm;
|
||||
|
||||
public VirtualMachineTO getVirtualMachine() {
|
||||
return vm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected Start2Command() {
|
||||
}
|
||||
|
||||
public Start2Command(VirtualMachineTO vm) {
|
||||
this.vm = vm;
|
||||
}
|
||||
}
|
||||
|
|
@ -22,6 +22,9 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
|||
|
||||
public class ResourceUnavailableException extends CloudRuntimeException {
|
||||
private static final long serialVersionUID = SerialVersionUID.ResourceUnavailableException;
|
||||
|
||||
Class<?> _scope;
|
||||
long _id;
|
||||
|
||||
public ResourceUnavailableException(String msg) {
|
||||
super(msg);
|
||||
|
|
@ -30,4 +33,12 @@ public class ResourceUnavailableException extends CloudRuntimeException {
|
|||
public ResourceUnavailableException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
public Class<?> getScope() {
|
||||
return _scope;
|
||||
}
|
||||
|
||||
public long getScopeId() {
|
||||
return _id;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.cloud.agent.api;
|
||||
|
||||
import com.cloud.agent.api.to.VirtualMachineTO;
|
||||
|
||||
public class Start2Command extends Command {
|
||||
VirtualMachineTO vm;
|
||||
|
||||
public VirtualMachineTO getVirtualMachine() {
|
||||
return vm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected Start2Command() {
|
||||
}
|
||||
|
||||
public Start2Command(VirtualMachineTO vm) {
|
||||
this.vm = vm;
|
||||
}
|
||||
}
|
||||
|
|
@ -2110,30 +2110,12 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
|
||||
@DB
|
||||
protected List<String> savePrivateIPRange(String startIP, String endIP, long podId, long zoneId) {
|
||||
long startIPLong = NetUtils.ip2Long(startIP);
|
||||
long endIPLong = NetUtils.ip2Long(endIP);
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
String insertSql = "INSERT INTO `cloud`.`op_dc_ip_address_alloc` (ip_address, data_center_id, pod_id) VALUES (?, ?, ?)";
|
||||
List<String> problemIPs = new ArrayList<String>();
|
||||
|
||||
IPRangeConfig config = new IPRangeConfig();
|
||||
txn.start();
|
||||
PreparedStatement stmt = null;
|
||||
while (startIPLong <= endIPLong) {
|
||||
try {
|
||||
stmt = txn.prepareAutoCloseStatement(insertSql);
|
||||
stmt.setString(1, NetUtils.long2Ip(startIPLong));
|
||||
stmt.setLong(2, zoneId);
|
||||
stmt.setLong(3, podId);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (Exception ex) {
|
||||
problemIPs.add(NetUtils.long2Ip(startIPLong));
|
||||
}
|
||||
startIPLong += 1;
|
||||
}
|
||||
txn.commit();
|
||||
|
||||
return problemIPs;
|
||||
List<String> ips = config.savePrivateIPRange(txn, NetUtils.ip2Long(startIP), NetUtils.ip2Long(endIP), podId, zoneId);
|
||||
txn.commit();
|
||||
return ips;
|
||||
}
|
||||
|
||||
private String genChangeRangeSuccessString(List<String> problemIPs, boolean add) {
|
||||
|
|
|
|||
|
|
@ -56,6 +56,9 @@ public class DataCenterIpAddressVO {
|
|||
@Column(name="instance_id")
|
||||
private Long instanceId;
|
||||
|
||||
@Column(name="mac_address")
|
||||
private long macAddress;
|
||||
|
||||
protected DataCenterIpAddressVO() {
|
||||
}
|
||||
|
||||
|
|
@ -67,10 +70,15 @@ public class DataCenterIpAddressVO {
|
|||
this.reservationId = reservationId;
|
||||
}
|
||||
|
||||
public DataCenterIpAddressVO(String ipAddress, long dataCenterId, long podId) {
|
||||
public DataCenterIpAddressVO(String ipAddress, long dataCenterId, long podId, long macAddress) {
|
||||
this.ipAddress = ipAddress;
|
||||
this.dataCenterId = dataCenterId;
|
||||
this.podId = podId;
|
||||
this.macAddress = macAddress;
|
||||
}
|
||||
|
||||
public long getMacAddress() {
|
||||
return macAddress;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import java.sql.Connection;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
|
|
@ -183,7 +184,7 @@ public class IPRangeConfig {
|
|||
return "success";
|
||||
}
|
||||
|
||||
private String genChangeRangeSuccessString(Vector<String> problemIPs, String op) {
|
||||
private String genChangeRangeSuccessString(List<String> problemIPs, String op) {
|
||||
if (problemIPs == null) {
|
||||
return "";
|
||||
}
|
||||
|
|
@ -205,7 +206,7 @@ public class IPRangeConfig {
|
|||
}
|
||||
|
||||
for (int i = 0; i < problemIPs.size(); i++) {
|
||||
successString += problemIPs.elementAt(i);
|
||||
successString += problemIPs.get(i);
|
||||
if (i != (problemIPs.size() - 1)) {
|
||||
successString += ", ";
|
||||
}
|
||||
|
|
@ -226,7 +227,7 @@ public class IPRangeConfig {
|
|||
private String changeRange(String op, String type, long podId, long zoneId, String startIP, String endIP) {
|
||||
|
||||
// Go through all the IPs and add or delete them
|
||||
Vector<String> problemIPs = null;
|
||||
List<String> problemIPs = null;
|
||||
if (op.equals("add")) {
|
||||
problemIPs = saveIPRange(type, podId, zoneId, 1, startIP, endIP);
|
||||
} else if (op.equals("delete")) {
|
||||
|
|
@ -421,7 +422,7 @@ public class IPRangeConfig {
|
|||
}
|
||||
|
||||
@DB
|
||||
public Vector<String> saveIPRange(String type, long podId, long zoneId, long vlanDbId, String startIP, String endIP) {
|
||||
public List<String> saveIPRange(String type, long podId, long zoneId, long vlanDbId, String startIP, String endIP) {
|
||||
long startIPLong = NetUtils.ip2Long(startIP);
|
||||
long endIPLong = startIPLong;
|
||||
if (endIP != null) {
|
||||
|
|
@ -429,7 +430,7 @@ public class IPRangeConfig {
|
|||
}
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
Vector<String> problemIPs = null;
|
||||
List<String> problemIPs = null;
|
||||
|
||||
if (type.equals("public")) {
|
||||
problemIPs = savePublicIPRange(txn, startIPLong, endIPLong, zoneId, vlanDbId);
|
||||
|
|
@ -460,53 +461,57 @@ public class IPRangeConfig {
|
|||
}
|
||||
|
||||
while (startIP <= endIP) {
|
||||
try {
|
||||
stmt = conn.prepareStatement(insertSql);
|
||||
stmt.setString(1, NetUtils.long2Ip(startIP));
|
||||
stmt.setLong(2, zoneId);
|
||||
stmt.setLong(3, vlanDbId);
|
||||
stmt.setLong(4, zoneId);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
stmt = conn.prepareStatement(updateSql);
|
||||
stmt.setLong(1, zoneId);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (Exception ex) {
|
||||
problemIPs.add(NetUtils.long2Ip(startIP));
|
||||
}
|
||||
startIP += 1;
|
||||
try {
|
||||
stmt = conn.prepareStatement(insertSql);
|
||||
stmt.setString(1, NetUtils.long2Ip(startIP));
|
||||
stmt.setLong(2, zoneId);
|
||||
stmt.setLong(3, vlanDbId);
|
||||
stmt.setLong(4, zoneId);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
stmt = conn.prepareStatement(updateSql);
|
||||
stmt.setLong(1, zoneId);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (Exception ex) {
|
||||
problemIPs.add(NetUtils.long2Ip(startIP));
|
||||
}
|
||||
startIP++;
|
||||
}
|
||||
|
||||
return problemIPs;
|
||||
}
|
||||
|
||||
private Vector<String> savePrivateIPRange(Transaction txn, long startIP, long endIP, long podId, long zoneId) {
|
||||
String insertSql = "INSERT INTO `cloud`.`op_dc_ip_address_alloc` (ip_address, data_center_id, pod_id) VALUES (?, ?, ?)";
|
||||
public List<String> savePrivateIPRange(Transaction txn, long startIP, long endIP, long podId, long zoneId) {
|
||||
String insertSql = "INSERT INTO `cloud`.`op_dc_ip_address_alloc` (ip_address, data_center_id, pod_id, mac_address) VALUES (?, ?, ?, (select mac_address from `cloud`.`data_center` where id=?))";
|
||||
String updateSql = "UPDATE `cloud`.`data_center` set mac_address = mac_address+1 where id=?";
|
||||
Vector<String> problemIPs = new Vector<String>();
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = txn.getConnection();
|
||||
} catch (SQLException e) {
|
||||
System.out.println("Exception: " + e.getMessage());
|
||||
printError("Unable to start DB connection to save private IPs. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
while (startIP <= endIP) {
|
||||
try {
|
||||
stmt = conn.prepareStatement(insertSql);
|
||||
stmt.setString(1, NetUtils.long2Ip(startIP));
|
||||
stmt.setLong(2, zoneId);
|
||||
stmt.setLong(3, podId);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (Exception ex) {
|
||||
problemIPs.add(NetUtils.long2Ip(startIP));
|
||||
}
|
||||
startIP += 1;
|
||||
}
|
||||
try {
|
||||
Connection conn = null;
|
||||
conn = txn.getConnection();
|
||||
while (startIP <= endIP) {
|
||||
try {
|
||||
PreparedStatement stmt = conn.prepareStatement(insertSql);
|
||||
stmt.setString(1, NetUtils.long2Ip(startIP));
|
||||
stmt.setLong(2, zoneId);
|
||||
stmt.setLong(3, podId);
|
||||
stmt.setLong(4, zoneId);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
stmt = conn.prepareStatement(updateSql);
|
||||
stmt.setLong(1, zoneId);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (Exception e) {
|
||||
problemIPs.add(NetUtils.long2Ip(startIP));
|
||||
}
|
||||
startIP++;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.print(ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return problemIPs;
|
||||
}
|
||||
|
|
@ -514,7 +519,6 @@ public class IPRangeConfig {
|
|||
private Vector<String> saveLinkLocalPrivateIPRange(Transaction txn, long startIP, long endIP, long podId, long zoneId) {
|
||||
String insertSql = "INSERT INTO `cloud`.`op_dc_link_local_ip_address_alloc` (ip_address, data_center_id, pod_id) VALUES (?, ?, ?)";
|
||||
Vector<String> problemIPs = new Vector<String>();
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
Connection conn = null;
|
||||
try {
|
||||
|
|
@ -524,18 +528,23 @@ public class IPRangeConfig {
|
|||
printError("Unable to start DB connection to save private IPs. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
while (startIP <= endIP) {
|
||||
try {
|
||||
stmt = conn.prepareStatement(insertSql);
|
||||
stmt.setString(1, NetUtils.long2Ip(startIP));
|
||||
try {
|
||||
long start = startIP;
|
||||
PreparedStatement stmt = conn.prepareStatement(insertSql);
|
||||
while (startIP <= endIP) {
|
||||
stmt.setString(1, NetUtils.long2Ip(startIP++));
|
||||
stmt.setLong(2, zoneId);
|
||||
stmt.setLong(3, podId);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (Exception ex) {
|
||||
problemIPs.add(NetUtils.long2Ip(startIP));
|
||||
}
|
||||
startIP += 1;
|
||||
stmt.addBatch();
|
||||
}
|
||||
int[] results = stmt.executeBatch();
|
||||
for (int i = 0; i < results.length; i += 2) {
|
||||
if (results[i] == Statement.EXECUTE_FAILED) {
|
||||
problemIPs.add(NetUtils.long2Ip(start + (i / 2)));
|
||||
}
|
||||
}
|
||||
stmt.close();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
return problemIPs;
|
||||
|
|
|
|||
|
|
@ -57,12 +57,10 @@ import com.cloud.exception.InsufficientCapacityException;
|
|||
import com.cloud.exception.InsufficientServerCapacityException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.hypervisor.HypervisorGuru;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
|
|
@ -377,6 +375,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Cluster
|
|||
throw new ConcurrentOperationException("Unable to start vm " + vm + " due to concurrent operations");
|
||||
}
|
||||
|
||||
VirtualMachineProfileImpl<T> vmProfile = new VirtualMachineProfileImpl<T>(vm, template, offering, null, params, hyperType);
|
||||
|
||||
ExcludeList avoids = new ExcludeList();
|
||||
int retry = _retry;
|
||||
DeployDestination dest = null;
|
||||
|
|
@ -386,8 +386,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Cluster
|
|||
stateTransitTo(vm, Event.OperationRetry, dest.getHost().getId());
|
||||
}
|
||||
|
||||
VirtualMachineProfileImpl<T> vmProfile = new VirtualMachineProfileImpl<T>(vm, template, offering, null, params, hyperType);
|
||||
|
||||
for (DeploymentPlanner planner : _planners) {
|
||||
dest = planner.plan(vmProfile, plan, avoids);
|
||||
if (dest != null) {
|
||||
|
|
@ -407,15 +405,18 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Cluster
|
|||
|
||||
try {
|
||||
_storageMgr.prepare(vmProfile, dest);
|
||||
_networkMgr.prepare(vmProfile, dest, context);
|
||||
} catch (ConcurrentOperationException e) {
|
||||
stateTransitTo(vm, Event.OperationFailed, dest.getHost().getId());
|
||||
throw e;
|
||||
} catch (StorageUnavailableException e) {
|
||||
} catch (ResourceUnavailableException e) {
|
||||
s_logger.warn("Unable to contact storage.", e);
|
||||
avoids.addCluster(dest.getCluster().getId());
|
||||
continue;
|
||||
} catch (InsufficientCapacityException e) {
|
||||
s_logger.warn("Insufficient capacity ", e);
|
||||
avoids.add(e);
|
||||
}
|
||||
_networkMgr.prepare(vmProfile, dest, context);
|
||||
|
||||
vmGuru.finalizeVirtualMachineProfile(vmProfile, dest, context);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue