mirror of https://github.com/apache/cloudstack.git
agent: Replace tabs by 4 spaces
A lot of old code still has tabs inspead of 4 spaces for indentation. The Coding Convention requires spaces, so we correct it.
This commit is contained in:
parent
d630fa8697
commit
5e9a193f2c
|
|
@ -245,9 +245,9 @@ public class Agent implements HandlerFactory, IAgentControl {
|
|||
|
||||
_connection.start();
|
||||
while (!_connection.isStartup()) {
|
||||
_shell.getBackoffAlgorithm().waitBeforeRetry();
|
||||
_connection = new NioClient("Agent", _shell.getHost(), _shell.getPort(), _shell.getWorkers(), this);
|
||||
_connection.start();
|
||||
_shell.getBackoffAlgorithm().waitBeforeRetry();
|
||||
_connection = new NioClient("Agent", _shell.getHost(), _shell.getPort(), _shell.getWorkers(), this);
|
||||
_connection.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -495,7 +495,7 @@ public class Agent implements HandlerFactory, IAgentControl {
|
|||
_reconnectAllowed = false;
|
||||
answer = new Answer(cmd, true, null);
|
||||
} else if (cmd instanceof MaintainCommand) {
|
||||
s_logger.debug("Received maintainCommand" );
|
||||
s_logger.debug("Received maintainCommand" );
|
||||
cancelTasks();
|
||||
_reconnectAllowed = false;
|
||||
answer = new MaintainAnswer((MaintainCommand)cmd);
|
||||
|
|
@ -820,17 +820,17 @@ public class Agent implements HandlerFactory, IAgentControl {
|
|||
}
|
||||
|
||||
public class AgentRequestHandler extends Task {
|
||||
public AgentRequestHandler(Task.Type type, Link link, Request req) {
|
||||
public AgentRequestHandler(Task.Type type, Link link, Request req) {
|
||||
super(type, link, req);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doTask(Task task) throws Exception {
|
||||
Request req = (Request)this.get();
|
||||
if (!(req instanceof Response)) {
|
||||
processRequest(req, task.getLink());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void doTask(Task task) throws Exception {
|
||||
Request req = (Request)this.get();
|
||||
if (!(req instanceof Response)) {
|
||||
processRequest(req, task.getLink());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ServerHandler extends Task {
|
||||
|
|
@ -853,12 +853,12 @@ public class Agent implements HandlerFactory, IAgentControl {
|
|||
try {
|
||||
request = Request.parse(task.getData());
|
||||
if (request instanceof Response) {
|
||||
//It's for pinganswer etc, should be processed immediately.
|
||||
//It's for pinganswer etc, should be processed immediately.
|
||||
processResponse((Response) request, task.getLink());
|
||||
} else {
|
||||
//put the requests from mgt server into another thread pool, as the request may take a longer time to finish. Don't block the NIO main thread pool
|
||||
//put the requests from mgt server into another thread pool, as the request may take a longer time to finish. Don't block the NIO main thread pool
|
||||
//processRequest(request, task.getLink());
|
||||
_executor.execute(new AgentRequestHandler(this.getType(), this.getLink(), request));
|
||||
_executor.execute(new AgentRequestHandler(this.getType(), this.getLink(), request));
|
||||
}
|
||||
} catch (final ClassNotFoundException e) {
|
||||
s_logger.error("Unable to find this request ");
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -22,35 +22,35 @@ import java.util.Properties;
|
|||
import com.cloud.utils.backoff.BackoffAlgorithm;
|
||||
|
||||
public interface IAgentShell {
|
||||
public Map<String, Object> getCmdLineProperties();
|
||||
public Map<String, Object> getCmdLineProperties();
|
||||
|
||||
public Properties getProperties();
|
||||
public Properties getProperties();
|
||||
|
||||
public String getPersistentProperty(String prefix, String name);
|
||||
public String getPersistentProperty(String prefix, String name);
|
||||
|
||||
public void setPersistentProperty(String prefix, String name, String value);
|
||||
public void setPersistentProperty(String prefix, String name, String value);
|
||||
|
||||
public String getHost();
|
||||
public String getHost();
|
||||
|
||||
public String getPrivateIp();
|
||||
public String getPrivateIp();
|
||||
|
||||
public int getPort();
|
||||
public int getPort();
|
||||
|
||||
public int getWorkers();
|
||||
public int getWorkers();
|
||||
|
||||
public int getProxyPort();
|
||||
public int getProxyPort();
|
||||
|
||||
public String getGuid();
|
||||
public String getGuid();
|
||||
|
||||
public String getZone();
|
||||
public String getZone();
|
||||
|
||||
public String getPod();
|
||||
public String getPod();
|
||||
|
||||
public BackoffAlgorithm getBackoffAlgorithm();
|
||||
public BackoffAlgorithm getBackoffAlgorithm();
|
||||
|
||||
public int getPingRetries();
|
||||
public int getPingRetries();
|
||||
|
||||
public void upgradeAgent(final String url);
|
||||
public void upgradeAgent(final String url);
|
||||
|
||||
public String getVersion();
|
||||
public String getVersion();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,50 +27,50 @@ import com.cloud.utils.component.PluggableService;
|
|||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public class AgentComponentLibraryBase extends ComponentLibraryBase {
|
||||
@Override
|
||||
public Map<String, ComponentInfo<GenericDao<?, ?>>> getDaos() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Map<String, ComponentInfo<GenericDao<?, ?>>> getDaos() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ComponentInfo<Manager>> getManagers() {
|
||||
if (_managers.size() == 0) {
|
||||
populateManagers();
|
||||
}
|
||||
return _managers;
|
||||
}
|
||||
@Override
|
||||
public Map<String, ComponentInfo<Manager>> getManagers() {
|
||||
if (_managers.size() == 0) {
|
||||
populateManagers();
|
||||
}
|
||||
return _managers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<ComponentInfo<Adapter>>> getAdapters() {
|
||||
if (_adapters.size() == 0) {
|
||||
populateAdapters();
|
||||
}
|
||||
return _adapters;
|
||||
}
|
||||
@Override
|
||||
public Map<String, List<ComponentInfo<Adapter>>> getAdapters() {
|
||||
if (_adapters.size() == 0) {
|
||||
populateAdapters();
|
||||
}
|
||||
return _adapters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Class<?>, Class<?>> getFactories() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Map<Class<?>, Class<?>> getFactories() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void populateManagers() {
|
||||
// addManager("StackMaidManager", StackMaidManagerImpl.class);
|
||||
}
|
||||
protected void populateManagers() {
|
||||
// addManager("StackMaidManager", StackMaidManagerImpl.class);
|
||||
}
|
||||
|
||||
protected void populateAdapters() {
|
||||
protected void populateAdapters() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void populateServices() {
|
||||
protected void populateServices() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ComponentInfo<PluggableService>> getPluggableServices() {
|
||||
if (_pluggableServices.size() == 0) {
|
||||
populateServices();
|
||||
}
|
||||
return _pluggableServices;
|
||||
}
|
||||
@Override
|
||||
public Map<String, ComponentInfo<PluggableService>> getPluggableServices() {
|
||||
if (_pluggableServices.size() == 0) {
|
||||
populateServices();
|
||||
}
|
||||
return _pluggableServices;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import com.cloud.utils.component.Manager;
|
|||
*
|
||||
*/
|
||||
public interface StorageComponent extends Manager {
|
||||
String get(String key);
|
||||
String get(String key);
|
||||
|
||||
void persist(String key, String value);
|
||||
void persist(String key, String value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,92 +39,92 @@ import com.cloud.utils.PropertiesUtil;
|
|||
**/
|
||||
@Local(value = { StorageComponent.class })
|
||||
public class PropertiesStorage implements StorageComponent {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(PropertiesStorage.class);
|
||||
Properties _properties = new Properties();
|
||||
File _file;
|
||||
String _name;
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(PropertiesStorage.class);
|
||||
Properties _properties = new Properties();
|
||||
File _file;
|
||||
String _name;
|
||||
|
||||
@Override
|
||||
public synchronized String get(String key) {
|
||||
return _properties.getProperty(key);
|
||||
}
|
||||
@Override
|
||||
public synchronized String get(String key) {
|
||||
return _properties.getProperty(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void persist(String key, String value) {
|
||||
_properties.setProperty(key, value);
|
||||
FileOutputStream output = null;
|
||||
try {
|
||||
output = new FileOutputStream(_file);
|
||||
_properties.store(output, _name);
|
||||
output.flush();
|
||||
output.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
s_logger.error("Who deleted the file? ", e);
|
||||
} catch (IOException e) {
|
||||
s_logger.error("Uh-oh: ", e);
|
||||
} finally {
|
||||
if (output != null) {
|
||||
try {
|
||||
output.close();
|
||||
} catch (IOException e) {
|
||||
// ignore.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public synchronized void persist(String key, String value) {
|
||||
_properties.setProperty(key, value);
|
||||
FileOutputStream output = null;
|
||||
try {
|
||||
output = new FileOutputStream(_file);
|
||||
_properties.store(output, _name);
|
||||
output.flush();
|
||||
output.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
s_logger.error("Who deleted the file? ", e);
|
||||
} catch (IOException e) {
|
||||
s_logger.error("Uh-oh: ", e);
|
||||
} finally {
|
||||
if (output != null) {
|
||||
try {
|
||||
output.close();
|
||||
} catch (IOException e) {
|
||||
// ignore.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) {
|
||||
_name = name;
|
||||
String path = (String) params.get("path");
|
||||
if (path == null) {
|
||||
path = "agent.properties";
|
||||
}
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) {
|
||||
_name = name;
|
||||
String path = (String) params.get("path");
|
||||
if (path == null) {
|
||||
path = "agent.properties";
|
||||
}
|
||||
|
||||
File file = PropertiesUtil.findConfigFile(path);
|
||||
if (file == null) {
|
||||
file = new File(path);
|
||||
try {
|
||||
if (!file.createNewFile()) {
|
||||
s_logger.error("Unable to create _file: "
|
||||
+ file.getAbsolutePath());
|
||||
return false;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
s_logger.error(
|
||||
"Unable to create _file: " + file.getAbsolutePath(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
File file = PropertiesUtil.findConfigFile(path);
|
||||
if (file == null) {
|
||||
file = new File(path);
|
||||
try {
|
||||
if (!file.createNewFile()) {
|
||||
s_logger.error("Unable to create _file: "
|
||||
+ file.getAbsolutePath());
|
||||
return false;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
s_logger.error(
|
||||
"Unable to create _file: " + file.getAbsolutePath(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
_properties.load(new FileInputStream(file));
|
||||
_file = file;
|
||||
} catch (FileNotFoundException e) {
|
||||
s_logger.error("How did we get here? ", e);
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
s_logger.error("IOException: ", e);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
_properties.load(new FileInputStream(file));
|
||||
_file = file;
|
||||
} catch (FileNotFoundException e) {
|
||||
s_logger.error("How did we get here? ", e);
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
s_logger.error("IOException: ", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,36 +31,36 @@ import org.apache.log4j.Logger;
|
|||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
|
||||
public class DhcpProtocolParserServer extends Thread {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(DhcpProtocolParserServer.class);;
|
||||
protected ExecutorService _executor;
|
||||
private int dhcpServerPort = 67;
|
||||
private int bufferSize = 300;
|
||||
protected boolean _running = false;
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(DhcpProtocolParserServer.class);;
|
||||
protected ExecutorService _executor;
|
||||
private int dhcpServerPort = 67;
|
||||
private int bufferSize = 300;
|
||||
protected boolean _running = false;
|
||||
|
||||
public DhcpProtocolParserServer(int workers) {
|
||||
_executor = new ThreadPoolExecutor(workers, 10 * workers, 1,
|
||||
TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(),
|
||||
new NamedThreadFactory("DhcpListener"));
|
||||
_running = true;
|
||||
}
|
||||
public DhcpProtocolParserServer(int workers) {
|
||||
_executor = new ThreadPoolExecutor(workers, 10 * workers, 1,
|
||||
TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(),
|
||||
new NamedThreadFactory("DhcpListener"));
|
||||
_running = true;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (_running) {
|
||||
try {
|
||||
DatagramSocket dhcpSocket = new DatagramSocket(dhcpServerPort,
|
||||
InetAddress.getByAddress(new byte[] { 0, 0, 0, 0 }));
|
||||
dhcpSocket.setBroadcast(true);
|
||||
public void run() {
|
||||
while (_running) {
|
||||
try {
|
||||
DatagramSocket dhcpSocket = new DatagramSocket(dhcpServerPort,
|
||||
InetAddress.getByAddress(new byte[] { 0, 0, 0, 0 }));
|
||||
dhcpSocket.setBroadcast(true);
|
||||
|
||||
while (true) {
|
||||
byte[] buf = new byte[bufferSize];
|
||||
DatagramPacket dgp = new DatagramPacket(buf, buf.length);
|
||||
dhcpSocket.receive(dgp);
|
||||
// _executor.execute(new DhcpPacketParser(buf));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
s_logger.debug(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
byte[] buf = new byte[bufferSize];
|
||||
DatagramPacket dgp = new DatagramPacket(buf, buf.length);
|
||||
dhcpSocket.receive(dgp);
|
||||
// _executor.execute(new DhcpPacketParser(buf));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
s_logger.debug(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,16 +25,16 @@ import com.cloud.utils.component.Adapter;
|
|||
|
||||
public interface DhcpSnooper extends Adapter {
|
||||
|
||||
public InetAddress getIPAddr(String macAddr, String vmName);
|
||||
public InetAddress getIPAddr(String macAddr, String vmName);
|
||||
|
||||
public InetAddress getDhcpServerIP();
|
||||
public InetAddress getDhcpServerIP();
|
||||
|
||||
public void cleanup(String macAddr, String vmName);
|
||||
public void cleanup(String macAddr, String vmName);
|
||||
|
||||
public Map<String, InetAddress> syncIpAddr();
|
||||
public Map<String, InetAddress> syncIpAddr();
|
||||
|
||||
public boolean stop();
|
||||
public boolean stop();
|
||||
|
||||
public void initializeMacTable(List<Pair<String, String>> macVmNameList);
|
||||
public void initializeMacTable(List<Pair<String, String>> macVmNameList);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,104 +39,104 @@ import com.cloud.utils.net.NetUtils;
|
|||
|
||||
@Local(value = { DhcpSnooper.class })
|
||||
public class FakeDhcpSnooper implements DhcpSnooper {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(FakeDhcpSnooper.class);
|
||||
private Queue<String> _ipAddresses = new ConcurrentLinkedQueue<String>();
|
||||
private Map<String, String> _macIpMap = new ConcurrentHashMap<String, String>();
|
||||
private Map<String, InetAddress> _vmIpMap = new ConcurrentHashMap<String, InetAddress>();
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(FakeDhcpSnooper.class);
|
||||
private Queue<String> _ipAddresses = new ConcurrentLinkedQueue<String>();
|
||||
private Map<String, String> _macIpMap = new ConcurrentHashMap<String, String>();
|
||||
private Map<String, InetAddress> _vmIpMap = new ConcurrentHashMap<String, InetAddress>();
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
String guestIpRange = (String) params.get("guest.ip.range");
|
||||
if (guestIpRange != null) {
|
||||
String[] guestIps = guestIpRange.split("-");
|
||||
if (guestIps.length == 2) {
|
||||
long start = NetUtils.ip2Long(guestIps[0]);
|
||||
long end = NetUtils.ip2Long(guestIps[1]);
|
||||
while (start <= end) {
|
||||
_ipAddresses.offer(NetUtils.long2Ip(start++));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
String guestIpRange = (String) params.get("guest.ip.range");
|
||||
if (guestIpRange != null) {
|
||||
String[] guestIps = guestIpRange.split("-");
|
||||
if (guestIps.length == 2) {
|
||||
long start = NetUtils.ip2Long(guestIps[0]);
|
||||
long end = NetUtils.ip2Long(guestIps[1]);
|
||||
while (start <= end) {
|
||||
_ipAddresses.offer(NetUtils.long2Ip(start++));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "FakeDhcpSnooper";
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "FakeDhcpSnooper";
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetAddress getIPAddr(String macAddr, String vmName) {
|
||||
String ipAddr = _ipAddresses.poll();
|
||||
if (ipAddr == null) {
|
||||
s_logger.warn("No ip addresses left in queue");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
InetAddress inetAddr = InetAddress.getByName(ipAddr);
|
||||
_macIpMap.put(macAddr.toLowerCase(), ipAddr);
|
||||
_vmIpMap.put(vmName, inetAddr);
|
||||
s_logger.info("Got ip address " + ipAddr + " for vm " + vmName
|
||||
+ " mac=" + macAddr.toLowerCase());
|
||||
return inetAddr;
|
||||
} catch (UnknownHostException e) {
|
||||
s_logger.warn("Failed to get InetAddress for " + ipAddr);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public InetAddress getIPAddr(String macAddr, String vmName) {
|
||||
String ipAddr = _ipAddresses.poll();
|
||||
if (ipAddr == null) {
|
||||
s_logger.warn("No ip addresses left in queue");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
InetAddress inetAddr = InetAddress.getByName(ipAddr);
|
||||
_macIpMap.put(macAddr.toLowerCase(), ipAddr);
|
||||
_vmIpMap.put(vmName, inetAddr);
|
||||
s_logger.info("Got ip address " + ipAddr + " for vm " + vmName
|
||||
+ " mac=" + macAddr.toLowerCase());
|
||||
return inetAddr;
|
||||
} catch (UnknownHostException e) {
|
||||
s_logger.warn("Failed to get InetAddress for " + ipAddr);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup(String macAddr, String vmName) {
|
||||
try {
|
||||
if (macAddr == null) {
|
||||
return;
|
||||
}
|
||||
InetAddress inetAddr = _vmIpMap.remove(vmName);
|
||||
String ipAddr = inetAddr.getHostName();
|
||||
for (Map.Entry<String, String> entry : _macIpMap.entrySet()) {
|
||||
if (entry.getValue().equalsIgnoreCase(ipAddr)) {
|
||||
macAddr = entry.getKey();
|
||||
break;
|
||||
}
|
||||
}
|
||||
ipAddr = _macIpMap.remove(macAddr);
|
||||
@Override
|
||||
public void cleanup(String macAddr, String vmName) {
|
||||
try {
|
||||
if (macAddr == null) {
|
||||
return;
|
||||
}
|
||||
InetAddress inetAddr = _vmIpMap.remove(vmName);
|
||||
String ipAddr = inetAddr.getHostName();
|
||||
for (Map.Entry<String, String> entry : _macIpMap.entrySet()) {
|
||||
if (entry.getValue().equalsIgnoreCase(ipAddr)) {
|
||||
macAddr = entry.getKey();
|
||||
break;
|
||||
}
|
||||
}
|
||||
ipAddr = _macIpMap.remove(macAddr);
|
||||
|
||||
s_logger.info("Cleaning up for mac address: " + macAddr + " ip="
|
||||
+ ipAddr + " inetAddr=" + inetAddr);
|
||||
if (ipAddr != null) {
|
||||
_ipAddresses.offer(ipAddr);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("Failed to cleanup: " + e.toString());
|
||||
}
|
||||
}
|
||||
s_logger.info("Cleaning up for mac address: " + macAddr + " ip="
|
||||
+ ipAddr + " inetAddr=" + inetAddr);
|
||||
if (ipAddr != null) {
|
||||
_ipAddresses.offer(ipAddr);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("Failed to cleanup: " + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, InetAddress> syncIpAddr() {
|
||||
return _vmIpMap;
|
||||
}
|
||||
@Override
|
||||
public Map<String, InetAddress> syncIpAddr() {
|
||||
return _vmIpMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeMacTable(List<Pair<String, String>> macVmNameList) {
|
||||
@Override
|
||||
public void initializeMacTable(List<Pair<String, String>> macVmNameList) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetAddress getDhcpServerIP() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public InetAddress getDhcpServerIP() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,61 +21,61 @@ import com.cloud.vm.VirtualMachine.State;
|
|||
// As storage is mapped from storage device, can virtually treat that VM here does
|
||||
public class MockVm {
|
||||
|
||||
private String vmName;
|
||||
private State state = State.Stopped;
|
||||
private String vmName;
|
||||
private State state = State.Stopped;
|
||||
|
||||
private long ramSize; // unit of Mbytes
|
||||
private int cpuCount;
|
||||
private int utilization; // in percentage
|
||||
private int vncPort; // 0-based allocation, real port number needs to be
|
||||
// applied with base
|
||||
private long ramSize; // unit of Mbytes
|
||||
private int cpuCount;
|
||||
private int utilization; // in percentage
|
||||
private int vncPort; // 0-based allocation, real port number needs to be
|
||||
// applied with base
|
||||
|
||||
public MockVm() {
|
||||
}
|
||||
public MockVm() {
|
||||
}
|
||||
|
||||
public MockVm(String vmName, State state, long ramSize, int cpuCount,
|
||||
int utilization, int vncPort) {
|
||||
this.vmName = vmName;
|
||||
this.state = state;
|
||||
this.ramSize = ramSize;
|
||||
this.cpuCount = cpuCount;
|
||||
this.utilization = utilization;
|
||||
this.vncPort = vncPort;
|
||||
}
|
||||
public MockVm(String vmName, State state, long ramSize, int cpuCount,
|
||||
int utilization, int vncPort) {
|
||||
this.vmName = vmName;
|
||||
this.state = state;
|
||||
this.ramSize = ramSize;
|
||||
this.cpuCount = cpuCount;
|
||||
this.utilization = utilization;
|
||||
this.vncPort = vncPort;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return vmName;
|
||||
}
|
||||
public String getName() {
|
||||
return vmName;
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(State state) {
|
||||
this.state = state;
|
||||
}
|
||||
public void setState(State state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public long getRamSize() {
|
||||
return ramSize;
|
||||
}
|
||||
public long getRamSize() {
|
||||
return ramSize;
|
||||
}
|
||||
|
||||
public int getCpuCount() {
|
||||
return cpuCount;
|
||||
}
|
||||
public int getCpuCount() {
|
||||
return cpuCount;
|
||||
}
|
||||
|
||||
public int getUtilization() {
|
||||
return utilization;
|
||||
}
|
||||
public int getUtilization() {
|
||||
return utilization;
|
||||
}
|
||||
|
||||
public int getVncPort() {
|
||||
return vncPort;
|
||||
}
|
||||
public int getVncPort() {
|
||||
return vncPort;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
long i = 10;
|
||||
Long l = null;
|
||||
if (i == l) {
|
||||
System.out.print("fdfd");
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
long i = 10;
|
||||
Long l = null;
|
||||
if (i == l) {
|
||||
System.out.print("fdfd");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,295 +29,295 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
|||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
public class MockVmMgr implements VmMgr {
|
||||
private static final Logger s_logger = Logger.getLogger(MockVmMgr.class);
|
||||
private static final Logger s_logger = Logger.getLogger(MockVmMgr.class);
|
||||
|
||||
private static final int DEFAULT_DOM0_MEM_MB = 128;
|
||||
private static final Random randSeed = new Random();
|
||||
private static final int DEFAULT_DOM0_MEM_MB = 128;
|
||||
private static final Random randSeed = new Random();
|
||||
|
||||
private final Map<String, MockVm> vms = new HashMap<String, MockVm>();
|
||||
private long vncPortMap = 0;
|
||||
private final Map<String, MockVm> vms = new HashMap<String, MockVm>();
|
||||
private long vncPortMap = 0;
|
||||
|
||||
private Map<String, Object> _params = null;
|
||||
private Map<String, Object> _params = null;
|
||||
|
||||
public MockVmMgr() {
|
||||
}
|
||||
public MockVmMgr() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCurrentVMs() {
|
||||
HashSet<String> vmNameSet = new HashSet<String>();
|
||||
synchronized (this) {
|
||||
for (String vmName : vms.keySet())
|
||||
vmNameSet.add(vmName);
|
||||
}
|
||||
return vmNameSet;
|
||||
}
|
||||
@Override
|
||||
public Set<String> getCurrentVMs() {
|
||||
HashSet<String> vmNameSet = new HashSet<String>();
|
||||
synchronized (this) {
|
||||
for (String vmName : vms.keySet())
|
||||
vmNameSet.add(vmName);
|
||||
}
|
||||
return vmNameSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String startVM(String vmName, String vnetId, String gateway,
|
||||
String dns, String privateIP, String privateMac,
|
||||
String privateMask, String publicIP, String publicMac,
|
||||
String publicMask, int cpuCount, int cpuUtilization, long ramSize,
|
||||
String localPath, String vncPassword) {
|
||||
@Override
|
||||
public String startVM(String vmName, String vnetId, String gateway,
|
||||
String dns, String privateIP, String privateMac,
|
||||
String privateMask, String publicIP, String publicMac,
|
||||
String publicMask, int cpuCount, int cpuUtilization, long ramSize,
|
||||
String localPath, String vncPassword) {
|
||||
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("Start VM. name: " + vmName + ", vnet: " + vnetId
|
||||
+ ", dns: " + dns);
|
||||
sb.append(", privateIP: " + privateIP + ", privateMac: "
|
||||
+ privateMac + ", privateMask: " + privateMask);
|
||||
sb.append(", publicIP: " + publicIP + ", publicMac: " + publicMac
|
||||
+ ", publicMask: " + publicMask);
|
||||
sb.append(", cpu count: " + cpuCount + ", cpuUtilization: "
|
||||
+ cpuUtilization + ", ram : " + ramSize);
|
||||
sb.append(", localPath: " + localPath);
|
||||
s_logger.info(sb.toString());
|
||||
}
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("Start VM. name: " + vmName + ", vnet: " + vnetId
|
||||
+ ", dns: " + dns);
|
||||
sb.append(", privateIP: " + privateIP + ", privateMac: "
|
||||
+ privateMac + ", privateMask: " + privateMask);
|
||||
sb.append(", publicIP: " + publicIP + ", publicMac: " + publicMac
|
||||
+ ", publicMask: " + publicMask);
|
||||
sb.append(", cpu count: " + cpuCount + ", cpuUtilization: "
|
||||
+ cpuUtilization + ", ram : " + ramSize);
|
||||
sb.append(", localPath: " + localPath);
|
||||
s_logger.info(sb.toString());
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
if (vm == null) {
|
||||
if (ramSize > getHostFreeMemory())
|
||||
return "Out of memory";
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
if (vm == null) {
|
||||
if (ramSize > getHostFreeMemory())
|
||||
return "Out of memory";
|
||||
|
||||
int vncPort = allocVncPort();
|
||||
if (vncPort < 0)
|
||||
return "Unable to allocate VNC port";
|
||||
int vncPort = allocVncPort();
|
||||
if (vncPort < 0)
|
||||
return "Unable to allocate VNC port";
|
||||
|
||||
vm = new MockVm(vmName, State.Running, ramSize, cpuCount,
|
||||
cpuUtilization, vncPort);
|
||||
vms.put(vmName, vm);
|
||||
}
|
||||
}
|
||||
vm = new MockVm(vmName, State.Running, ramSize, cpuCount,
|
||||
cpuUtilization, vncPort);
|
||||
vms.put(vmName, vm);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stopVM(String vmName, boolean force) {
|
||||
if (s_logger.isInfoEnabled())
|
||||
s_logger.info("Stop VM. name: " + vmName);
|
||||
@Override
|
||||
public String stopVM(String vmName, boolean force) {
|
||||
if (s_logger.isInfoEnabled())
|
||||
s_logger.info("Stop VM. name: " + vmName);
|
||||
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
if (vm != null) {
|
||||
vm.setState(State.Stopped);
|
||||
freeVncPort(vm.getVncPort());
|
||||
}
|
||||
}
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
if (vm != null) {
|
||||
vm.setState(State.Stopped);
|
||||
freeVncPort(vm.getVncPort());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String rebootVM(String vmName) {
|
||||
if (s_logger.isInfoEnabled())
|
||||
s_logger.info("Reboot VM. name: " + vmName);
|
||||
@Override
|
||||
public String rebootVM(String vmName) {
|
||||
if (s_logger.isInfoEnabled())
|
||||
s_logger.info("Reboot VM. name: " + vmName);
|
||||
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
if (vm != null)
|
||||
vm.setState(State.Running);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
if (vm != null)
|
||||
vm.setState(State.Running);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean migrate(String vmName, String params) {
|
||||
if (s_logger.isInfoEnabled())
|
||||
s_logger.info("Migrate VM. name: " + vmName);
|
||||
@Override
|
||||
public boolean migrate(String vmName, String params) {
|
||||
if (s_logger.isInfoEnabled())
|
||||
s_logger.info("Migrate VM. name: " + vmName);
|
||||
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
if (vm != null) {
|
||||
vm.setState(State.Stopped);
|
||||
freeVncPort(vm.getVncPort());
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
if (vm != null) {
|
||||
vm.setState(State.Stopped);
|
||||
freeVncPort(vm.getVncPort());
|
||||
|
||||
vms.remove(vmName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
vms.remove(vmName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public MockVm getVm(String vmName) {
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
return vm;
|
||||
}
|
||||
}
|
||||
public MockVm getVm(String vmName) {
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
return vm;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public State checkVmState(String vmName) {
|
||||
@Override
|
||||
public State checkVmState(String vmName) {
|
||||
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
if (vm != null)
|
||||
return vm.getState();
|
||||
}
|
||||
return State.Unknown;
|
||||
}
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
if (vm != null)
|
||||
return vm.getState();
|
||||
}
|
||||
return State.Unknown;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, State> getVmStates() {
|
||||
Map<String, State> states = new HashMap<String, State>();
|
||||
@Override
|
||||
public Map<String, State> getVmStates() {
|
||||
Map<String, State> states = new HashMap<String, State>();
|
||||
|
||||
synchronized (this) {
|
||||
for (MockVm vm : vms.values()) {
|
||||
states.put(vm.getName(), vm.getState());
|
||||
}
|
||||
}
|
||||
return states;
|
||||
}
|
||||
synchronized (this) {
|
||||
for (MockVm vm : vms.values()) {
|
||||
states.put(vm.getName(), vm.getState());
|
||||
}
|
||||
}
|
||||
return states;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanupVM(String vmName, String local, String vnet) {
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
if (vm != null) {
|
||||
freeVncPort(vm.getVncPort());
|
||||
}
|
||||
vms.remove(vmName);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void cleanupVM(String vmName, String local, String vnet) {
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
if (vm != null) {
|
||||
freeVncPort(vm.getVncPort());
|
||||
}
|
||||
vms.remove(vmName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHostCpuUtilization() {
|
||||
return 0.0d;
|
||||
}
|
||||
@Override
|
||||
public double getHostCpuUtilization() {
|
||||
return 0.0d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHostCpuCount() {
|
||||
@Override
|
||||
public int getHostCpuCount() {
|
||||
|
||||
return getConfiguredProperty("cpus", 4);
|
||||
}
|
||||
return getConfiguredProperty("cpus", 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getHostCpuSpeed() {
|
||||
return getConfiguredProperty("cpuspeed", 4000L);
|
||||
@Override
|
||||
public long getHostCpuSpeed() {
|
||||
return getConfiguredProperty("cpuspeed", 4000L);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getHostTotalMemory() { // total memory in bytes
|
||||
return getConfiguredProperty("memory", 16000L);
|
||||
@Override
|
||||
public long getHostTotalMemory() { // total memory in bytes
|
||||
return getConfiguredProperty("memory", 16000L);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getHostFreeMemory() { // free memory in bytes
|
||||
long memSize = getHostTotalMemory();
|
||||
memSize -= getHostDom0Memory();
|
||||
@Override
|
||||
public long getHostFreeMemory() { // free memory in bytes
|
||||
long memSize = getHostTotalMemory();
|
||||
memSize -= getHostDom0Memory();
|
||||
|
||||
synchronized (this) {
|
||||
for (MockVm vm : vms.values()) {
|
||||
if (vm.getState() != State.Stopped)
|
||||
memSize -= vm.getRamSize();
|
||||
}
|
||||
}
|
||||
synchronized (this) {
|
||||
for (MockVm vm : vms.values()) {
|
||||
if (vm.getState() != State.Stopped)
|
||||
memSize -= vm.getRamSize();
|
||||
}
|
||||
}
|
||||
|
||||
return memSize;
|
||||
}
|
||||
return memSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getHostDom0Memory() { // memory size in bytes
|
||||
return DEFAULT_DOM0_MEM_MB * 1024 * 1024L;
|
||||
}
|
||||
@Override
|
||||
public long getHostDom0Memory() { // memory size in bytes
|
||||
return DEFAULT_DOM0_MEM_MB * 1024 * 1024L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String cleanupVnet(String vnetId) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String cleanupVnet(String vnetId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getVncPort(String name) {
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(name);
|
||||
if (vm != null)
|
||||
return vm.getVncPort();
|
||||
}
|
||||
@Override
|
||||
public Integer getVncPort(String name) {
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(name);
|
||||
if (vm != null)
|
||||
return vm.getVncPort();
|
||||
}
|
||||
|
||||
return new Integer(-1);
|
||||
}
|
||||
return new Integer(-1);
|
||||
}
|
||||
|
||||
public int allocVncPort() {
|
||||
for (int i = 0; i < 64; i++) {
|
||||
if (((1L << i) & vncPortMap) == 0) {
|
||||
vncPortMap |= (1L << i);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public int allocVncPort() {
|
||||
for (int i = 0; i < 64; i++) {
|
||||
if (((1L << i) & vncPortMap) == 0) {
|
||||
vncPortMap |= (1L << i);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void freeVncPort(int port) {
|
||||
vncPortMap &= ~(1L << port);
|
||||
}
|
||||
public void freeVncPort(int port) {
|
||||
vncPortMap &= ~(1L << port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MockVm createVmFromSpec(VirtualMachineTO vmSpec) {
|
||||
String vmName = vmSpec.getName();
|
||||
long ramSize = vmSpec.getMinRam();
|
||||
int utilizationPercent = randSeed.nextInt() % 100;
|
||||
MockVm vm = null;
|
||||
@Override
|
||||
public MockVm createVmFromSpec(VirtualMachineTO vmSpec) {
|
||||
String vmName = vmSpec.getName();
|
||||
long ramSize = vmSpec.getMinRam();
|
||||
int utilizationPercent = randSeed.nextInt() % 100;
|
||||
MockVm vm = null;
|
||||
|
||||
synchronized (this) {
|
||||
vm = vms.get(vmName);
|
||||
if (vm == null) {
|
||||
if (ramSize > getHostFreeMemory()) {
|
||||
s_logger.debug("host is out of memory");
|
||||
throw new CloudRuntimeException("Host is out of Memory");
|
||||
}
|
||||
synchronized (this) {
|
||||
vm = vms.get(vmName);
|
||||
if (vm == null) {
|
||||
if (ramSize > getHostFreeMemory()) {
|
||||
s_logger.debug("host is out of memory");
|
||||
throw new CloudRuntimeException("Host is out of Memory");
|
||||
}
|
||||
|
||||
int vncPort = allocVncPort();
|
||||
if (vncPort < 0) {
|
||||
s_logger.debug("Unable to allocate VNC port");
|
||||
throw new CloudRuntimeException(
|
||||
"Unable to allocate vnc port");
|
||||
}
|
||||
int vncPort = allocVncPort();
|
||||
if (vncPort < 0) {
|
||||
s_logger.debug("Unable to allocate VNC port");
|
||||
throw new CloudRuntimeException(
|
||||
"Unable to allocate vnc port");
|
||||
}
|
||||
|
||||
vm = new MockVm(vmName, State.Running, ramSize,
|
||||
vmSpec.getCpus(), utilizationPercent, vncPort);
|
||||
vms.put(vmName, vm);
|
||||
}
|
||||
}
|
||||
return vm;
|
||||
}
|
||||
vm = new MockVm(vmName, State.Running, ramSize,
|
||||
vmSpec.getCpus(), utilizationPercent, vncPort);
|
||||
vms.put(vmName, vm);
|
||||
}
|
||||
}
|
||||
return vm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createVbd(VirtualMachineTO vmSpec, String vmName, MockVm vm) {
|
||||
// TODO Auto-generated method stub
|
||||
@Override
|
||||
public void createVbd(VirtualMachineTO vmSpec, String vmName, MockVm vm) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createVif(VirtualMachineTO vmSpec, String vmName, MockVm vm) {
|
||||
// TODO Auto-generated method stub
|
||||
@Override
|
||||
public void createVif(VirtualMachineTO vmSpec, String vmName, MockVm vm) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(Map<String, Object> params) {
|
||||
_params = params;
|
||||
}
|
||||
@Override
|
||||
public void configure(Map<String, Object> params) {
|
||||
_params = params;
|
||||
}
|
||||
|
||||
protected Long getConfiguredProperty(String key, Long defaultValue) {
|
||||
String val = (String) _params.get(key);
|
||||
protected Long getConfiguredProperty(String key, Long defaultValue) {
|
||||
String val = (String) _params.get(key);
|
||||
|
||||
if (val != null) {
|
||||
Long result = Long.parseLong(val);
|
||||
return result;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
if (val != null) {
|
||||
Long result = Long.parseLong(val);
|
||||
return result;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
protected Integer getConfiguredProperty(String key, Integer defaultValue) {
|
||||
String val = (String) _params.get(key);
|
||||
protected Integer getConfiguredProperty(String key, Integer defaultValue) {
|
||||
String val = (String) _params.get(key);
|
||||
|
||||
if (val != null) {
|
||||
Integer result = Integer.parseInt(val);
|
||||
return result;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
if (val != null) {
|
||||
Integer result = Integer.parseInt(val);
|
||||
return result;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,49 +23,49 @@ import com.cloud.agent.api.to.VirtualMachineTO;
|
|||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
public interface VmMgr {
|
||||
public Set<String> getCurrentVMs();
|
||||
public Set<String> getCurrentVMs();
|
||||
|
||||
public String startVM(String vmName, String vnetId, String gateway,
|
||||
String dns, String privateIP, String privateMac,
|
||||
String privateMask, String publicIP, String publicMac,
|
||||
String publicMask, int cpuCount, int cpuUtilization, long ramSize,
|
||||
String localPath, String vncPassword);
|
||||
public String startVM(String vmName, String vnetId, String gateway,
|
||||
String dns, String privateIP, String privateMac,
|
||||
String privateMask, String publicIP, String publicMac,
|
||||
String publicMask, int cpuCount, int cpuUtilization, long ramSize,
|
||||
String localPath, String vncPassword);
|
||||
|
||||
public String stopVM(String vmName, boolean force);
|
||||
public String stopVM(String vmName, boolean force);
|
||||
|
||||
public String rebootVM(String vmName);
|
||||
public String rebootVM(String vmName);
|
||||
|
||||
public void cleanupVM(String vmName, String local, String vnet);
|
||||
public void cleanupVM(String vmName, String local, String vnet);
|
||||
|
||||
public boolean migrate(String vmName, String params);
|
||||
public boolean migrate(String vmName, String params);
|
||||
|
||||
public MockVm getVm(String vmName);
|
||||
public MockVm getVm(String vmName);
|
||||
|
||||
public State checkVmState(String vmName);
|
||||
public State checkVmState(String vmName);
|
||||
|
||||
public Map<String, State> getVmStates();
|
||||
public Map<String, State> getVmStates();
|
||||
|
||||
public Integer getVncPort(String name);
|
||||
public Integer getVncPort(String name);
|
||||
|
||||
public String cleanupVnet(String vnetId);
|
||||
public String cleanupVnet(String vnetId);
|
||||
|
||||
public double getHostCpuUtilization();
|
||||
public double getHostCpuUtilization();
|
||||
|
||||
public int getHostCpuCount();
|
||||
public int getHostCpuCount();
|
||||
|
||||
public long getHostCpuSpeed();
|
||||
public long getHostCpuSpeed();
|
||||
|
||||
public long getHostTotalMemory();
|
||||
public long getHostTotalMemory();
|
||||
|
||||
public long getHostFreeMemory();
|
||||
public long getHostFreeMemory();
|
||||
|
||||
public long getHostDom0Memory();
|
||||
public long getHostDom0Memory();
|
||||
|
||||
public MockVm createVmFromSpec(VirtualMachineTO vmSpec);
|
||||
public MockVm createVmFromSpec(VirtualMachineTO vmSpec);
|
||||
|
||||
public void createVbd(VirtualMachineTO vmSpec, String vmName, MockVm vm);
|
||||
public void createVbd(VirtualMachineTO vmSpec, String vmName, MockVm vm);
|
||||
|
||||
public void createVif(VirtualMachineTO vmSpec, String vmName, MockVm vm);
|
||||
public void createVif(VirtualMachineTO vmSpec, String vmName, MockVm vm);
|
||||
|
||||
public void configure(Map<String, Object> params);
|
||||
public void configure(Map<String, Object> params);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,183 +45,183 @@ import com.cloud.storage.Storage.StoragePoolType;
|
|||
|
||||
@Local(value = { ServerResource.class })
|
||||
public class DummyResource implements ServerResource {
|
||||
String _name;
|
||||
Host.Type _type;
|
||||
boolean _negative;
|
||||
IAgentControl _agentControl;
|
||||
private Map<String, Object> _params;
|
||||
String _name;
|
||||
Host.Type _type;
|
||||
boolean _negative;
|
||||
IAgentControl _agentControl;
|
||||
private Map<String, Object> _params;
|
||||
|
||||
@Override
|
||||
public void disconnected() {
|
||||
}
|
||||
@Override
|
||||
public void disconnected() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer executeRequest(Command cmd) {
|
||||
if (cmd instanceof CheckNetworkCommand) {
|
||||
return new CheckNetworkAnswer((CheckNetworkCommand) cmd, true, null);
|
||||
}
|
||||
System.out.println("Received Command: " + cmd.toString());
|
||||
Answer answer = new Answer(cmd, !_negative, "response");
|
||||
System.out.println("Replying with: " + answer.toString());
|
||||
return answer;
|
||||
}
|
||||
@Override
|
||||
public Answer executeRequest(Command cmd) {
|
||||
if (cmd instanceof CheckNetworkCommand) {
|
||||
return new CheckNetworkAnswer((CheckNetworkCommand) cmd, true, null);
|
||||
}
|
||||
System.out.println("Received Command: " + cmd.toString());
|
||||
Answer answer = new Answer(cmd, !_negative, "response");
|
||||
System.out.println("Replying with: " + answer.toString());
|
||||
return answer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
return new PingCommand(_type, id);
|
||||
}
|
||||
@Override
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
return new PingCommand(_type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return _type;
|
||||
}
|
||||
@Override
|
||||
public Type getType() {
|
||||
return _type;
|
||||
}
|
||||
|
||||
protected String getConfiguredProperty(String key, String defaultValue) {
|
||||
String val = (String) _params.get(key);
|
||||
return val == null ? defaultValue : val;
|
||||
}
|
||||
protected String getConfiguredProperty(String key, String defaultValue) {
|
||||
String val = (String) _params.get(key);
|
||||
return val == null ? defaultValue : val;
|
||||
}
|
||||
|
||||
protected Long getConfiguredProperty(String key, Long defaultValue) {
|
||||
String val = (String) _params.get(key);
|
||||
protected Long getConfiguredProperty(String key, Long defaultValue) {
|
||||
String val = (String) _params.get(key);
|
||||
|
||||
if (val != null) {
|
||||
Long result = Long.parseLong(val);
|
||||
return result;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
if (val != null) {
|
||||
Long result = Long.parseLong(val);
|
||||
return result;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
protected List<Object> getHostInfo() {
|
||||
final ArrayList<Object> info = new ArrayList<Object>();
|
||||
long speed = getConfiguredProperty("cpuspeed", 4000L);
|
||||
long cpus = getConfiguredProperty("cpus", 4L);
|
||||
long ram = getConfiguredProperty("memory", 16000L * 1024L * 1024L);
|
||||
long dom0ram = Math.min(ram / 10, 768 * 1024 * 1024L);
|
||||
protected List<Object> getHostInfo() {
|
||||
final ArrayList<Object> info = new ArrayList<Object>();
|
||||
long speed = getConfiguredProperty("cpuspeed", 4000L);
|
||||
long cpus = getConfiguredProperty("cpus", 4L);
|
||||
long ram = getConfiguredProperty("memory", 16000L * 1024L * 1024L);
|
||||
long dom0ram = Math.min(ram / 10, 768 * 1024 * 1024L);
|
||||
|
||||
String cap = getConfiguredProperty("capabilities", "hvm");
|
||||
info.add((int) cpus);
|
||||
info.add(speed);
|
||||
info.add(ram);
|
||||
info.add(cap);
|
||||
info.add(dom0ram);
|
||||
return info;
|
||||
String cap = getConfiguredProperty("capabilities", "hvm");
|
||||
info.add((int) cpus);
|
||||
info.add(speed);
|
||||
info.add(ram);
|
||||
info.add(cap);
|
||||
info.add(dom0ram);
|
||||
return info;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void fillNetworkInformation(final StartupCommand cmd) {
|
||||
protected void fillNetworkInformation(final StartupCommand cmd) {
|
||||
|
||||
cmd.setPrivateIpAddress((String) getConfiguredProperty(
|
||||
"private.ip.address", "127.0.0.1"));
|
||||
cmd.setPrivateMacAddress((String) getConfiguredProperty(
|
||||
"private.mac.address", "8A:D2:54:3F:7C:C3"));
|
||||
cmd.setPrivateNetmask((String) getConfiguredProperty(
|
||||
"private.ip.netmask", "255.255.255.0"));
|
||||
cmd.setPrivateIpAddress((String) getConfiguredProperty(
|
||||
"private.ip.address", "127.0.0.1"));
|
||||
cmd.setPrivateMacAddress((String) getConfiguredProperty(
|
||||
"private.mac.address", "8A:D2:54:3F:7C:C3"));
|
||||
cmd.setPrivateNetmask((String) getConfiguredProperty(
|
||||
"private.ip.netmask", "255.255.255.0"));
|
||||
|
||||
cmd.setStorageIpAddress((String) getConfiguredProperty(
|
||||
"private.ip.address", "127.0.0.1"));
|
||||
cmd.setStorageMacAddress((String) getConfiguredProperty(
|
||||
"private.mac.address", "8A:D2:54:3F:7C:C3"));
|
||||
cmd.setStorageNetmask((String) getConfiguredProperty(
|
||||
"private.ip.netmask", "255.255.255.0"));
|
||||
cmd.setGatewayIpAddress((String) getConfiguredProperty(
|
||||
"gateway.ip.address", "127.0.0.1"));
|
||||
cmd.setStorageIpAddress((String) getConfiguredProperty(
|
||||
"private.ip.address", "127.0.0.1"));
|
||||
cmd.setStorageMacAddress((String) getConfiguredProperty(
|
||||
"private.mac.address", "8A:D2:54:3F:7C:C3"));
|
||||
cmd.setStorageNetmask((String) getConfiguredProperty(
|
||||
"private.ip.netmask", "255.255.255.0"));
|
||||
cmd.setGatewayIpAddress((String) getConfiguredProperty(
|
||||
"gateway.ip.address", "127.0.0.1"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> getVersionStrings() {
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
String hostOs = (String) _params.get("Host.OS");
|
||||
String hostOsVer = (String) _params.get("Host.OS.Version");
|
||||
String hostOsKernVer = (String) _params.get("Host.OS.Kernel.Version");
|
||||
result.put("Host.OS", hostOs == null ? "Fedora" : hostOs);
|
||||
result.put("Host.OS.Version", hostOsVer == null ? "14" : hostOsVer);
|
||||
result.put("Host.OS.Kernel.Version",
|
||||
hostOsKernVer == null ? "2.6.35.6-45.fc14.x86_64"
|
||||
: hostOsKernVer);
|
||||
return result;
|
||||
}
|
||||
private Map<String, String> getVersionStrings() {
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
String hostOs = (String) _params.get("Host.OS");
|
||||
String hostOsVer = (String) _params.get("Host.OS.Version");
|
||||
String hostOsKernVer = (String) _params.get("Host.OS.Kernel.Version");
|
||||
result.put("Host.OS", hostOs == null ? "Fedora" : hostOs);
|
||||
result.put("Host.OS.Version", hostOsVer == null ? "14" : hostOsVer);
|
||||
result.put("Host.OS.Kernel.Version",
|
||||
hostOsKernVer == null ? "2.6.35.6-45.fc14.x86_64"
|
||||
: hostOsKernVer);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected StoragePoolInfo initializeLocalStorage() {
|
||||
String hostIp = (String) getConfiguredProperty("private.ip.address",
|
||||
"127.0.0.1");
|
||||
String localStoragePath = (String) getConfiguredProperty(
|
||||
"local.storage.path", "/mnt");
|
||||
String lh = hostIp + localStoragePath;
|
||||
String uuid = UUID.nameUUIDFromBytes(lh.getBytes()).toString();
|
||||
protected StoragePoolInfo initializeLocalStorage() {
|
||||
String hostIp = (String) getConfiguredProperty("private.ip.address",
|
||||
"127.0.0.1");
|
||||
String localStoragePath = (String) getConfiguredProperty(
|
||||
"local.storage.path", "/mnt");
|
||||
String lh = hostIp + localStoragePath;
|
||||
String uuid = UUID.nameUUIDFromBytes(lh.getBytes()).toString();
|
||||
|
||||
String capacity = (String) getConfiguredProperty(
|
||||
"local.storage.capacity", "1000000000");
|
||||
String available = (String) getConfiguredProperty(
|
||||
"local.storage.avail", "10000000");
|
||||
String capacity = (String) getConfiguredProperty(
|
||||
"local.storage.capacity", "1000000000");
|
||||
String available = (String) getConfiguredProperty(
|
||||
"local.storage.avail", "10000000");
|
||||
|
||||
return new StoragePoolInfo(uuid, hostIp, localStoragePath,
|
||||
localStoragePath, StoragePoolType.Filesystem,
|
||||
Long.parseLong(capacity), Long.parseLong(available));
|
||||
return new StoragePoolInfo(uuid, hostIp, localStoragePath,
|
||||
localStoragePath, StoragePoolType.Filesystem,
|
||||
Long.parseLong(capacity), Long.parseLong(available));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
Map<String, VmState> changes = null;
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
Map<String, VmState> changes = null;
|
||||
|
||||
final List<Object> info = getHostInfo();
|
||||
final List<Object> info = getHostInfo();
|
||||
|
||||
final StartupRoutingCommand cmd = new StartupRoutingCommand(
|
||||
(Integer) info.get(0), (Long) info.get(1), (Long) info.get(2),
|
||||
(Long) info.get(4), (String) info.get(3), HypervisorType.KVM,
|
||||
RouterPrivateIpStrategy.HostLocal, changes);
|
||||
fillNetworkInformation(cmd);
|
||||
cmd.getHostDetails().putAll(getVersionStrings());
|
||||
cmd.setCluster(getConfiguredProperty("cluster", "1"));
|
||||
StoragePoolInfo pi = initializeLocalStorage();
|
||||
StartupStorageCommand sscmd = new StartupStorageCommand();
|
||||
sscmd.setPoolInfo(pi);
|
||||
sscmd.setGuid(pi.getUuid());
|
||||
sscmd.setDataCenter((String) _params.get("zone"));
|
||||
sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
|
||||
final StartupRoutingCommand cmd = new StartupRoutingCommand(
|
||||
(Integer) info.get(0), (Long) info.get(1), (Long) info.get(2),
|
||||
(Long) info.get(4), (String) info.get(3), HypervisorType.KVM,
|
||||
RouterPrivateIpStrategy.HostLocal, changes);
|
||||
fillNetworkInformation(cmd);
|
||||
cmd.getHostDetails().putAll(getVersionStrings());
|
||||
cmd.setCluster(getConfiguredProperty("cluster", "1"));
|
||||
StoragePoolInfo pi = initializeLocalStorage();
|
||||
StartupStorageCommand sscmd = new StartupStorageCommand();
|
||||
sscmd.setPoolInfo(pi);
|
||||
sscmd.setGuid(pi.getUuid());
|
||||
sscmd.setDataCenter((String) _params.get("zone"));
|
||||
sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
|
||||
|
||||
return new StartupCommand[] { cmd, sscmd };
|
||||
}
|
||||
return new StartupCommand[] { cmd, sscmd };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) {
|
||||
_name = name;
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) {
|
||||
_name = name;
|
||||
|
||||
String value = (String) params.get("type");
|
||||
_type = Host.Type.valueOf(value);
|
||||
String value = (String) params.get("type");
|
||||
_type = Host.Type.valueOf(value);
|
||||
|
||||
value = (String) params.get("negative.reply");
|
||||
_negative = Boolean.parseBoolean(value);
|
||||
setParams(params);
|
||||
return true;
|
||||
}
|
||||
value = (String) params.get("negative.reply");
|
||||
_negative = Boolean.parseBoolean(value);
|
||||
setParams(params);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setParams(Map<String, Object> _params) {
|
||||
this._params = _params;
|
||||
}
|
||||
public void setParams(Map<String, Object> _params) {
|
||||
this._params = _params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAgentControl getAgentControl() {
|
||||
return _agentControl;
|
||||
}
|
||||
@Override
|
||||
public IAgentControl getAgentControl() {
|
||||
return _agentControl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAgentControl(IAgentControl agentControl) {
|
||||
_agentControl = agentControl;
|
||||
}
|
||||
@Override
|
||||
public void setAgentControl(IAgentControl agentControl) {
|
||||
_agentControl = agentControl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -22,148 +22,148 @@ import java.util.Map;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
public class KVMGuestOsMapper {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(KVMGuestOsMapper.class);
|
||||
private static Map<String, String> s_mapper = new HashMap<String, String>();
|
||||
static {
|
||||
s_mapper.put("CentOS 4.5 (32-bit)", "CentOS 4.5");
|
||||
s_mapper.put("CentOS 4.6 (32-bit)", "CentOS 4.6");
|
||||
s_mapper.put("CentOS 4.7 (32-bit)", "CentOS 4.7");
|
||||
s_mapper.put("CentOS 4.8 (32-bit)", "CentOS 4.8");
|
||||
s_mapper.put("CentOS 5.0 (32-bit)", "CentOS 5.0");
|
||||
s_mapper.put("CentOS 5.0 (64-bit)", "CentOS 5.0");
|
||||
s_mapper.put("CentOS 5.1 (32-bit)", "CentOS 5.1");
|
||||
s_mapper.put("CentOS 5.1 (64-bit)", "CentOS 5.1");
|
||||
s_mapper.put("CentOS 5.2 (32-bit)", "CentOS 5.2");
|
||||
s_mapper.put("CentOS 5.2 (64-bit)", "CentOS 5.2");
|
||||
s_mapper.put("CentOS 5.3 (32-bit)", "CentOS 5.3");
|
||||
s_mapper.put("CentOS 5.3 (64-bit)", "CentOS 5.3");
|
||||
s_mapper.put("CentOS 5.4 (32-bit)", "CentOS 5.4");
|
||||
s_mapper.put("CentOS 5.4 (64-bit)", "CentOS 5.4");
|
||||
s_mapper.put("CentOS 5.5 (32-bit)", "CentOS 5.5");
|
||||
s_mapper.put("CentOS 5.5 (64-bit)", "CentOS 5.5");
|
||||
s_mapper.put("Red Hat Enterprise Linux 2", "Red Hat Enterprise Linux 2");
|
||||
s_mapper.put("Red Hat Enterprise Linux 3 (32-bit)",
|
||||
"Red Hat Enterprise Linux 3");
|
||||
s_mapper.put("Red Hat Enterprise Linux 3 (64-bit)",
|
||||
"Red Hat Enterprise Linux 3");
|
||||
s_mapper.put("Red Hat Enterprise Linux 4(64-bit)",
|
||||
"Red Hat Enterprise Linux 4");
|
||||
s_mapper.put("Red Hat Enterprise Linux 4.5 (32-bit)",
|
||||
"Red Hat Enterprise Linux 4.5");
|
||||
s_mapper.put("Red Hat Enterprise Linux 4.6 (32-bit)",
|
||||
"Red Hat Enterprise Linux 4.6");
|
||||
s_mapper.put("Red Hat Enterprise Linux 4.7 (32-bit)",
|
||||
"Red Hat Enterprise Linux 4.7");
|
||||
s_mapper.put("Red Hat Enterprise Linux 4.8 (32-bit)",
|
||||
"Red Hat Enterprise Linux 4.8");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.0 (32-bit)",
|
||||
"Red Hat Enterprise Linux 5.0");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.0 (64-bit)",
|
||||
"Red Hat Enterprise Linux 5.0");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.1 (32-bit)",
|
||||
"Red Hat Enterprise Linux 5.1");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.1 (32-bit)",
|
||||
"Red Hat Enterprise Linux 5.1");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.2 (32-bit)",
|
||||
"Red Hat Enterprise Linux 5.2");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.2 (64-bit)",
|
||||
"Red Hat Enterprise Linux 5.2");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.3 (32-bit)",
|
||||
"Red Hat Enterprise Linux 5.3");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.3 (64-bit)",
|
||||
"Red Hat Enterprise Linux 5.3");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.4 (32-bit)",
|
||||
"Red Hat Enterprise Linux 5.4");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.4 (64-bit)",
|
||||
"Red Hat Enterprise Linux 5.4");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.5 (32-bit)",
|
||||
"Red Hat Enterprise Linux 5.5");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.5 (64-bit)",
|
||||
"Red Hat Enterprise Linux 5.5");
|
||||
s_mapper.put("Red Hat Enterprise Linux 6.0 (32-bit)",
|
||||
"Red Hat Enterprise Linux 6.0");
|
||||
s_mapper.put("Red Hat Enterprise Linux 6.0 (64-bit)",
|
||||
"Red Hat Enterprise Linux 6.0");
|
||||
s_mapper.put("Fedora 13", "Fedora 13");
|
||||
s_mapper.put("Fedora 12", "Fedora 12");
|
||||
s_mapper.put("Fedora 11", "Fedora 11");
|
||||
s_mapper.put("Fedora 10", "Fedora 10");
|
||||
s_mapper.put("Fedora 9", "Fedora 9");
|
||||
s_mapper.put("Fedora 8", "Fedora 8");
|
||||
s_mapper.put("Ubuntu 10.04 (32-bit)", "Ubuntu 10.04");
|
||||
s_mapper.put("Ubuntu 10.04 (64-bit)", "Ubuntu 10.04");
|
||||
s_mapper.put("Ubuntu 10.10 (32-bit)", "Ubuntu 10.10");
|
||||
s_mapper.put("Ubuntu 10.10 (64-bit)", "Ubuntu 10.10");
|
||||
s_mapper.put("Ubuntu 9.10 (32-bit)", "Ubuntu 9.10");
|
||||
s_mapper.put("Ubuntu 9.10 (64-bit)", "Ubuntu 9.10");
|
||||
s_mapper.put("Ubuntu 9.04 (32-bit)", "Ubuntu 9.04");
|
||||
s_mapper.put("Ubuntu 9.04 (64-bit)", "Ubuntu 9.04");
|
||||
s_mapper.put("Ubuntu 8.10 (32-bit)", "Ubuntu 8.10");
|
||||
s_mapper.put("Ubuntu 8.10 (64-bit)", "Ubuntu 8.10");
|
||||
s_mapper.put("Ubuntu 8.04 (32-bit)", "Other Linux");
|
||||
s_mapper.put("Ubuntu 8.04 (64-bit)", "Other Linux");
|
||||
s_mapper.put("Debian GNU/Linux 5(32-bit)", "Debian GNU/Linux 5");
|
||||
s_mapper.put("Debian GNU/Linux 5(64-bit)", "Debian GNU/Linux 5");
|
||||
s_mapper.put("Debian GNU/Linux 4(32-bit)", "Debian GNU/Linux 4");
|
||||
s_mapper.put("Debian GNU/Linux 4(64-bit)", "Debian GNU/Linux 4");
|
||||
s_mapper.put("Debian GNU/Linux 6(64-bit)", "Debian GNU/Linux 6");
|
||||
s_mapper.put("Debian GNU/Linux 6(32-bit)", "Debian GNU/Linux 6");
|
||||
s_mapper.put("Other 2.6x Linux (32-bit)", "Other 2.6x Linux");
|
||||
s_mapper.put("Other 2.6x Linux (64-bit)", "Other 2.6x Linux");
|
||||
s_mapper.put("Other Linux (32-bit)", "Other Linux");
|
||||
s_mapper.put("Other Linux (64-bit)", "Other Linux");
|
||||
s_mapper.put("Other Ubuntu (32-bit)", "Other Linux");
|
||||
s_mapper.put("Other Ubuntu (64-bit)", "Other Linux");
|
||||
s_mapper.put("Asianux 3(32-bit)", "Other Linux");
|
||||
s_mapper.put("Asianux 3(64-bit)", "Other Linux");
|
||||
s_mapper.put("Windows 7 (32-bit)", "Windows 7");
|
||||
s_mapper.put("Windows 7 (64-bit)", "Windows 7");
|
||||
s_mapper.put("Windows Server 2003 Enterprise Edition(32-bit)",
|
||||
"Windows Server 2003");
|
||||
s_mapper.put("Windows Server 2003 Enterprise Edition(64-bit)",
|
||||
"Windows Server 2003");
|
||||
s_mapper.put("Windows Server 2003 DataCenter Edition(32-bit)",
|
||||
"Windows Server 2003");
|
||||
s_mapper.put("Windows Server 2003 DataCenter Edition(64-bit)",
|
||||
"Windows Server 2003");
|
||||
s_mapper.put("Windows Server 2003 Standard Edition(32-bit)",
|
||||
"Windows Server 2003");
|
||||
s_mapper.put("Windows Server 2003 Standard Edition(64-bit)",
|
||||
"Windows Server 2003");
|
||||
s_mapper.put("Windows Server 2003 Web Edition", "Windows Server 2003");
|
||||
s_mapper.put("Microsoft Small Bussiness Server 2003",
|
||||
"Windows Server 2003");
|
||||
s_mapper.put("Windows Server 2008 (32-bit)", "Windows Server 2008");
|
||||
s_mapper.put("Windows Server 2008 (64-bit)", "Windows Server 2008");
|
||||
s_mapper.put("Windows Server 2008 R2 (64-bit)", "Windows Server 2008");
|
||||
s_mapper.put("Windows 2000 Server SP4 (32-bit)", "Windows 2000");
|
||||
s_mapper.put("Windows 2000 Server", "Windows 2000");
|
||||
s_mapper.put("Windows 2000 Advanced Server", "Windows 2000");
|
||||
s_mapper.put("Windows 2000 Professional", "Windows 2000");
|
||||
s_mapper.put("Windows Vista (32-bit)", "Windows Vista");
|
||||
s_mapper.put("Windows Vista (64-bit)", "Windows Vista");
|
||||
s_mapper.put("Windows XP SP2 (32-bit)", "Windows XP");
|
||||
s_mapper.put("Windows XP SP3 (32-bit)", "Windows XP");
|
||||
s_mapper.put("Windows XP (32-bit)", "Windows XP");
|
||||
s_mapper.put("Windows XP (64-bit)", "Windows XP");
|
||||
s_mapper.put("Windows 98", "Windows 98");
|
||||
s_mapper.put("Windows 95", "Windows 95");
|
||||
s_mapper.put("Windows NT 4", "Windows NT");
|
||||
s_mapper.put("Windows 3.1", "Windows 3.1");
|
||||
s_mapper.put("Windows PV", "Other PV");
|
||||
s_mapper.put("Other PV (32-bit)", "Other PV");
|
||||
s_mapper.put("Other PV (64-bit)", "Other PV");
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(KVMGuestOsMapper.class);
|
||||
private static Map<String, String> s_mapper = new HashMap<String, String>();
|
||||
static {
|
||||
s_mapper.put("CentOS 4.5 (32-bit)", "CentOS 4.5");
|
||||
s_mapper.put("CentOS 4.6 (32-bit)", "CentOS 4.6");
|
||||
s_mapper.put("CentOS 4.7 (32-bit)", "CentOS 4.7");
|
||||
s_mapper.put("CentOS 4.8 (32-bit)", "CentOS 4.8");
|
||||
s_mapper.put("CentOS 5.0 (32-bit)", "CentOS 5.0");
|
||||
s_mapper.put("CentOS 5.0 (64-bit)", "CentOS 5.0");
|
||||
s_mapper.put("CentOS 5.1 (32-bit)", "CentOS 5.1");
|
||||
s_mapper.put("CentOS 5.1 (64-bit)", "CentOS 5.1");
|
||||
s_mapper.put("CentOS 5.2 (32-bit)", "CentOS 5.2");
|
||||
s_mapper.put("CentOS 5.2 (64-bit)", "CentOS 5.2");
|
||||
s_mapper.put("CentOS 5.3 (32-bit)", "CentOS 5.3");
|
||||
s_mapper.put("CentOS 5.3 (64-bit)", "CentOS 5.3");
|
||||
s_mapper.put("CentOS 5.4 (32-bit)", "CentOS 5.4");
|
||||
s_mapper.put("CentOS 5.4 (64-bit)", "CentOS 5.4");
|
||||
s_mapper.put("CentOS 5.5 (32-bit)", "CentOS 5.5");
|
||||
s_mapper.put("CentOS 5.5 (64-bit)", "CentOS 5.5");
|
||||
s_mapper.put("Red Hat Enterprise Linux 2", "Red Hat Enterprise Linux 2");
|
||||
s_mapper.put("Red Hat Enterprise Linux 3 (32-bit)",
|
||||
"Red Hat Enterprise Linux 3");
|
||||
s_mapper.put("Red Hat Enterprise Linux 3 (64-bit)",
|
||||
"Red Hat Enterprise Linux 3");
|
||||
s_mapper.put("Red Hat Enterprise Linux 4(64-bit)",
|
||||
"Red Hat Enterprise Linux 4");
|
||||
s_mapper.put("Red Hat Enterprise Linux 4.5 (32-bit)",
|
||||
"Red Hat Enterprise Linux 4.5");
|
||||
s_mapper.put("Red Hat Enterprise Linux 4.6 (32-bit)",
|
||||
"Red Hat Enterprise Linux 4.6");
|
||||
s_mapper.put("Red Hat Enterprise Linux 4.7 (32-bit)",
|
||||
"Red Hat Enterprise Linux 4.7");
|
||||
s_mapper.put("Red Hat Enterprise Linux 4.8 (32-bit)",
|
||||
"Red Hat Enterprise Linux 4.8");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.0 (32-bit)",
|
||||
"Red Hat Enterprise Linux 5.0");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.0 (64-bit)",
|
||||
"Red Hat Enterprise Linux 5.0");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.1 (32-bit)",
|
||||
"Red Hat Enterprise Linux 5.1");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.1 (32-bit)",
|
||||
"Red Hat Enterprise Linux 5.1");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.2 (32-bit)",
|
||||
"Red Hat Enterprise Linux 5.2");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.2 (64-bit)",
|
||||
"Red Hat Enterprise Linux 5.2");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.3 (32-bit)",
|
||||
"Red Hat Enterprise Linux 5.3");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.3 (64-bit)",
|
||||
"Red Hat Enterprise Linux 5.3");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.4 (32-bit)",
|
||||
"Red Hat Enterprise Linux 5.4");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.4 (64-bit)",
|
||||
"Red Hat Enterprise Linux 5.4");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.5 (32-bit)",
|
||||
"Red Hat Enterprise Linux 5.5");
|
||||
s_mapper.put("Red Hat Enterprise Linux 5.5 (64-bit)",
|
||||
"Red Hat Enterprise Linux 5.5");
|
||||
s_mapper.put("Red Hat Enterprise Linux 6.0 (32-bit)",
|
||||
"Red Hat Enterprise Linux 6.0");
|
||||
s_mapper.put("Red Hat Enterprise Linux 6.0 (64-bit)",
|
||||
"Red Hat Enterprise Linux 6.0");
|
||||
s_mapper.put("Fedora 13", "Fedora 13");
|
||||
s_mapper.put("Fedora 12", "Fedora 12");
|
||||
s_mapper.put("Fedora 11", "Fedora 11");
|
||||
s_mapper.put("Fedora 10", "Fedora 10");
|
||||
s_mapper.put("Fedora 9", "Fedora 9");
|
||||
s_mapper.put("Fedora 8", "Fedora 8");
|
||||
s_mapper.put("Ubuntu 10.04 (32-bit)", "Ubuntu 10.04");
|
||||
s_mapper.put("Ubuntu 10.04 (64-bit)", "Ubuntu 10.04");
|
||||
s_mapper.put("Ubuntu 10.10 (32-bit)", "Ubuntu 10.10");
|
||||
s_mapper.put("Ubuntu 10.10 (64-bit)", "Ubuntu 10.10");
|
||||
s_mapper.put("Ubuntu 9.10 (32-bit)", "Ubuntu 9.10");
|
||||
s_mapper.put("Ubuntu 9.10 (64-bit)", "Ubuntu 9.10");
|
||||
s_mapper.put("Ubuntu 9.04 (32-bit)", "Ubuntu 9.04");
|
||||
s_mapper.put("Ubuntu 9.04 (64-bit)", "Ubuntu 9.04");
|
||||
s_mapper.put("Ubuntu 8.10 (32-bit)", "Ubuntu 8.10");
|
||||
s_mapper.put("Ubuntu 8.10 (64-bit)", "Ubuntu 8.10");
|
||||
s_mapper.put("Ubuntu 8.04 (32-bit)", "Other Linux");
|
||||
s_mapper.put("Ubuntu 8.04 (64-bit)", "Other Linux");
|
||||
s_mapper.put("Debian GNU/Linux 5(32-bit)", "Debian GNU/Linux 5");
|
||||
s_mapper.put("Debian GNU/Linux 5(64-bit)", "Debian GNU/Linux 5");
|
||||
s_mapper.put("Debian GNU/Linux 4(32-bit)", "Debian GNU/Linux 4");
|
||||
s_mapper.put("Debian GNU/Linux 4(64-bit)", "Debian GNU/Linux 4");
|
||||
s_mapper.put("Debian GNU/Linux 6(64-bit)", "Debian GNU/Linux 6");
|
||||
s_mapper.put("Debian GNU/Linux 6(32-bit)", "Debian GNU/Linux 6");
|
||||
s_mapper.put("Other 2.6x Linux (32-bit)", "Other 2.6x Linux");
|
||||
s_mapper.put("Other 2.6x Linux (64-bit)", "Other 2.6x Linux");
|
||||
s_mapper.put("Other Linux (32-bit)", "Other Linux");
|
||||
s_mapper.put("Other Linux (64-bit)", "Other Linux");
|
||||
s_mapper.put("Other Ubuntu (32-bit)", "Other Linux");
|
||||
s_mapper.put("Other Ubuntu (64-bit)", "Other Linux");
|
||||
s_mapper.put("Asianux 3(32-bit)", "Other Linux");
|
||||
s_mapper.put("Asianux 3(64-bit)", "Other Linux");
|
||||
s_mapper.put("Windows 7 (32-bit)", "Windows 7");
|
||||
s_mapper.put("Windows 7 (64-bit)", "Windows 7");
|
||||
s_mapper.put("Windows Server 2003 Enterprise Edition(32-bit)",
|
||||
"Windows Server 2003");
|
||||
s_mapper.put("Windows Server 2003 Enterprise Edition(64-bit)",
|
||||
"Windows Server 2003");
|
||||
s_mapper.put("Windows Server 2003 DataCenter Edition(32-bit)",
|
||||
"Windows Server 2003");
|
||||
s_mapper.put("Windows Server 2003 DataCenter Edition(64-bit)",
|
||||
"Windows Server 2003");
|
||||
s_mapper.put("Windows Server 2003 Standard Edition(32-bit)",
|
||||
"Windows Server 2003");
|
||||
s_mapper.put("Windows Server 2003 Standard Edition(64-bit)",
|
||||
"Windows Server 2003");
|
||||
s_mapper.put("Windows Server 2003 Web Edition", "Windows Server 2003");
|
||||
s_mapper.put("Microsoft Small Bussiness Server 2003",
|
||||
"Windows Server 2003");
|
||||
s_mapper.put("Windows Server 2008 (32-bit)", "Windows Server 2008");
|
||||
s_mapper.put("Windows Server 2008 (64-bit)", "Windows Server 2008");
|
||||
s_mapper.put("Windows Server 2008 R2 (64-bit)", "Windows Server 2008");
|
||||
s_mapper.put("Windows 2000 Server SP4 (32-bit)", "Windows 2000");
|
||||
s_mapper.put("Windows 2000 Server", "Windows 2000");
|
||||
s_mapper.put("Windows 2000 Advanced Server", "Windows 2000");
|
||||
s_mapper.put("Windows 2000 Professional", "Windows 2000");
|
||||
s_mapper.put("Windows Vista (32-bit)", "Windows Vista");
|
||||
s_mapper.put("Windows Vista (64-bit)", "Windows Vista");
|
||||
s_mapper.put("Windows XP SP2 (32-bit)", "Windows XP");
|
||||
s_mapper.put("Windows XP SP3 (32-bit)", "Windows XP");
|
||||
s_mapper.put("Windows XP (32-bit)", "Windows XP");
|
||||
s_mapper.put("Windows XP (64-bit)", "Windows XP");
|
||||
s_mapper.put("Windows 98", "Windows 98");
|
||||
s_mapper.put("Windows 95", "Windows 95");
|
||||
s_mapper.put("Windows NT 4", "Windows NT");
|
||||
s_mapper.put("Windows 3.1", "Windows 3.1");
|
||||
s_mapper.put("Windows PV", "Other PV");
|
||||
s_mapper.put("Other PV (32-bit)", "Other PV");
|
||||
s_mapper.put("Other PV (64-bit)", "Other PV");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static String getGuestOsName(String guestOsName) {
|
||||
String guestOS = s_mapper.get(guestOsName);
|
||||
if (guestOS == null) {
|
||||
s_logger.debug("Can't find the mapping of guest os: " + guestOsName);
|
||||
return "Other";
|
||||
} else {
|
||||
return guestOS;
|
||||
}
|
||||
}
|
||||
public static String getGuestOsName(String guestOsName) {
|
||||
String guestOS = s_mapper.get(guestOsName);
|
||||
if (guestOS == null) {
|
||||
s_logger.debug("Can't find the mapping of guest os: " + guestOsName);
|
||||
return "Other";
|
||||
} else {
|
||||
return guestOS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,187 +34,187 @@ import com.cloud.utils.script.OutputInterpreter.AllLinesParser;
|
|||
import com.cloud.utils.script.Script;
|
||||
|
||||
public class KVMHABase {
|
||||
private long _timeout = 60000; /* 1 minutes */
|
||||
protected static String _heartBeatPath;
|
||||
protected long _heartBeatUpdateTimeout = 60000;
|
||||
protected long _heartBeatUpdateFreq = 60000;
|
||||
protected long _heartBeatUpdateMaxRetry = 3;
|
||||
private long _timeout = 60000; /* 1 minutes */
|
||||
protected static String _heartBeatPath;
|
||||
protected long _heartBeatUpdateTimeout = 60000;
|
||||
protected long _heartBeatUpdateFreq = 60000;
|
||||
protected long _heartBeatUpdateMaxRetry = 3;
|
||||
|
||||
public static enum PoolType {
|
||||
PrimaryStorage, SecondaryStorage
|
||||
}
|
||||
public static enum PoolType {
|
||||
PrimaryStorage, SecondaryStorage
|
||||
}
|
||||
|
||||
public static class NfsStoragePool {
|
||||
String _poolUUID;
|
||||
String _poolIp;
|
||||
String _poolMountSourcePath;
|
||||
String _mountDestPath;
|
||||
PoolType _type;
|
||||
public static class NfsStoragePool {
|
||||
String _poolUUID;
|
||||
String _poolIp;
|
||||
String _poolMountSourcePath;
|
||||
String _mountDestPath;
|
||||
PoolType _type;
|
||||
|
||||
public NfsStoragePool(String poolUUID, String poolIp,
|
||||
String poolSourcePath, String mountDestPath, PoolType type) {
|
||||
this._poolUUID = poolUUID;
|
||||
this._poolIp = poolIp;
|
||||
this._poolMountSourcePath = poolSourcePath;
|
||||
this._mountDestPath = mountDestPath;
|
||||
this._type = type;
|
||||
}
|
||||
}
|
||||
public NfsStoragePool(String poolUUID, String poolIp,
|
||||
String poolSourcePath, String mountDestPath, PoolType type) {
|
||||
this._poolUUID = poolUUID;
|
||||
this._poolIp = poolIp;
|
||||
this._poolMountSourcePath = poolSourcePath;
|
||||
this._mountDestPath = mountDestPath;
|
||||
this._type = type;
|
||||
}
|
||||
}
|
||||
|
||||
protected String checkingMountPoint(NfsStoragePool pool, String poolName) {
|
||||
String mountSource = pool._poolIp + ":" + pool._poolMountSourcePath;
|
||||
String mountPaths = Script
|
||||
.runSimpleBashScript("cat /proc/mounts | grep " + mountSource);
|
||||
String destPath = pool._mountDestPath;
|
||||
protected String checkingMountPoint(NfsStoragePool pool, String poolName) {
|
||||
String mountSource = pool._poolIp + ":" + pool._poolMountSourcePath;
|
||||
String mountPaths = Script
|
||||
.runSimpleBashScript("cat /proc/mounts | grep " + mountSource);
|
||||
String destPath = pool._mountDestPath;
|
||||
|
||||
if (mountPaths != null) {
|
||||
String token[] = mountPaths.split(" ");
|
||||
String mountType = token[2];
|
||||
String mountDestPath = token[1];
|
||||
if (mountType.equalsIgnoreCase("nfs")) {
|
||||
if (poolName != null && !mountDestPath.startsWith(destPath)) {
|
||||
/* we need to mount it under poolName */
|
||||
Script mount = new Script("/bin/bash", 60000);
|
||||
mount.add("-c");
|
||||
mount.add("mount " + mountSource + " " + destPath);
|
||||
String result = mount.execute();
|
||||
if (result != null) {
|
||||
destPath = null;
|
||||
}
|
||||
destroyVMs(destPath);
|
||||
} else if (poolName == null) {
|
||||
destPath = mountDestPath;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Can't find the mount point? */
|
||||
/* we need to mount it under poolName */
|
||||
if (poolName != null) {
|
||||
Script mount = new Script("/bin/bash", 60000);
|
||||
mount.add("-c");
|
||||
mount.add("mount " + mountSource + " " + destPath);
|
||||
String result = mount.execute();
|
||||
if (result != null) {
|
||||
destPath = null;
|
||||
}
|
||||
if (mountPaths != null) {
|
||||
String token[] = mountPaths.split(" ");
|
||||
String mountType = token[2];
|
||||
String mountDestPath = token[1];
|
||||
if (mountType.equalsIgnoreCase("nfs")) {
|
||||
if (poolName != null && !mountDestPath.startsWith(destPath)) {
|
||||
/* we need to mount it under poolName */
|
||||
Script mount = new Script("/bin/bash", 60000);
|
||||
mount.add("-c");
|
||||
mount.add("mount " + mountSource + " " + destPath);
|
||||
String result = mount.execute();
|
||||
if (result != null) {
|
||||
destPath = null;
|
||||
}
|
||||
destroyVMs(destPath);
|
||||
} else if (poolName == null) {
|
||||
destPath = mountDestPath;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Can't find the mount point? */
|
||||
/* we need to mount it under poolName */
|
||||
if (poolName != null) {
|
||||
Script mount = new Script("/bin/bash", 60000);
|
||||
mount.add("-c");
|
||||
mount.add("mount " + mountSource + " " + destPath);
|
||||
String result = mount.execute();
|
||||
if (result != null) {
|
||||
destPath = null;
|
||||
}
|
||||
|
||||
destroyVMs(destPath);
|
||||
}
|
||||
}
|
||||
destroyVMs(destPath);
|
||||
}
|
||||
}
|
||||
|
||||
return destPath;
|
||||
}
|
||||
return destPath;
|
||||
}
|
||||
|
||||
protected String getMountPoint(NfsStoragePool storagePool) {
|
||||
protected String getMountPoint(NfsStoragePool storagePool) {
|
||||
|
||||
StoragePool pool = null;
|
||||
String poolName = null;
|
||||
try {
|
||||
pool = LibvirtConnection.getConnection()
|
||||
.storagePoolLookupByUUIDString(storagePool._poolUUID);
|
||||
if (pool != null) {
|
||||
StoragePoolInfo spi = pool.getInfo();
|
||||
if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
|
||||
pool.create(0);
|
||||
} else {
|
||||
/*
|
||||
* Sometimes, the mount point is lost, even libvirt thinks
|
||||
* the storage pool still running
|
||||
*/
|
||||
}
|
||||
}
|
||||
poolName = pool.getName();
|
||||
} catch (LibvirtException e) {
|
||||
StoragePool pool = null;
|
||||
String poolName = null;
|
||||
try {
|
||||
pool = LibvirtConnection.getConnection()
|
||||
.storagePoolLookupByUUIDString(storagePool._poolUUID);
|
||||
if (pool != null) {
|
||||
StoragePoolInfo spi = pool.getInfo();
|
||||
if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
|
||||
pool.create(0);
|
||||
} else {
|
||||
/*
|
||||
* Sometimes, the mount point is lost, even libvirt thinks
|
||||
* the storage pool still running
|
||||
*/
|
||||
}
|
||||
}
|
||||
poolName = pool.getName();
|
||||
} catch (LibvirtException e) {
|
||||
|
||||
} finally {
|
||||
try {
|
||||
if (pool != null) {
|
||||
pool.free();
|
||||
}
|
||||
} catch (LibvirtException e) {
|
||||
} finally {
|
||||
try {
|
||||
if (pool != null) {
|
||||
pool.free();
|
||||
}
|
||||
} catch (LibvirtException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return checkingMountPoint(storagePool, poolName);
|
||||
}
|
||||
return checkingMountPoint(storagePool, poolName);
|
||||
}
|
||||
|
||||
protected void destroyVMs(String mountPath) {
|
||||
/* if there are VMs using disks under this mount path, destroy them */
|
||||
Script cmd = new Script("/bin/bash", _timeout);
|
||||
cmd.add("-c");
|
||||
cmd.add("ps axu|grep qemu|grep " + mountPath + "* |awk '{print $2}'");
|
||||
AllLinesParser parser = new OutputInterpreter.AllLinesParser();
|
||||
String result = cmd.execute(parser);
|
||||
protected void destroyVMs(String mountPath) {
|
||||
/* if there are VMs using disks under this mount path, destroy them */
|
||||
Script cmd = new Script("/bin/bash", _timeout);
|
||||
cmd.add("-c");
|
||||
cmd.add("ps axu|grep qemu|grep " + mountPath + "* |awk '{print $2}'");
|
||||
AllLinesParser parser = new OutputInterpreter.AllLinesParser();
|
||||
String result = cmd.execute(parser);
|
||||
|
||||
if (result != null) {
|
||||
return;
|
||||
}
|
||||
if (result != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String pids[] = parser.getLines().split("\n");
|
||||
for (String pid : pids) {
|
||||
Script.runSimpleBashScript("kill -9 " + pid);
|
||||
}
|
||||
}
|
||||
String pids[] = parser.getLines().split("\n");
|
||||
for (String pid : pids) {
|
||||
Script.runSimpleBashScript("kill -9 " + pid);
|
||||
}
|
||||
}
|
||||
|
||||
protected String getHBFile(String mountPoint, String hostIP) {
|
||||
return mountPoint + File.separator + "KVMHA" + File.separator + "hb-"
|
||||
+ hostIP;
|
||||
}
|
||||
protected String getHBFile(String mountPoint, String hostIP) {
|
||||
return mountPoint + File.separator + "KVMHA" + File.separator + "hb-"
|
||||
+ hostIP;
|
||||
}
|
||||
|
||||
protected String getHBFolder(String mountPoint) {
|
||||
return mountPoint + File.separator + "KVMHA" + File.separator;
|
||||
}
|
||||
protected String getHBFolder(String mountPoint) {
|
||||
return mountPoint + File.separator + "KVMHA" + File.separator;
|
||||
}
|
||||
|
||||
protected String runScriptRetry(String cmdString,
|
||||
OutputInterpreter interpreter) {
|
||||
String result = null;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Script cmd = new Script("/bin/bash", _timeout);
|
||||
cmd.add("-c");
|
||||
cmd.add(cmdString);
|
||||
if (interpreter != null)
|
||||
result = cmd.execute(interpreter);
|
||||
else {
|
||||
result = cmd.execute();
|
||||
}
|
||||
if (result == Script.ERR_TIMEOUT) {
|
||||
continue;
|
||||
} else if (result == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
protected String runScriptRetry(String cmdString,
|
||||
OutputInterpreter interpreter) {
|
||||
String result = null;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Script cmd = new Script("/bin/bash", _timeout);
|
||||
cmd.add("-c");
|
||||
cmd.add(cmdString);
|
||||
if (interpreter != null)
|
||||
result = cmd.execute(interpreter);
|
||||
else {
|
||||
result = cmd.execute();
|
||||
}
|
||||
if (result == Script.ERR_TIMEOUT) {
|
||||
continue;
|
||||
} else if (result == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) {
|
||||
|
||||
NfsStoragePool pool = new KVMHAMonitor.NfsStoragePool(null, null, null,
|
||||
null, PoolType.PrimaryStorage);
|
||||
NfsStoragePool pool = new KVMHAMonitor.NfsStoragePool(null, null, null,
|
||||
null, PoolType.PrimaryStorage);
|
||||
|
||||
KVMHAMonitor haWritter = new KVMHAMonitor(pool, "192.168.1.163", null);
|
||||
Thread ha = new Thread(haWritter);
|
||||
ha.start();
|
||||
KVMHAMonitor haWritter = new KVMHAMonitor(pool, "192.168.1.163", null);
|
||||
Thread ha = new Thread(haWritter);
|
||||
ha.start();
|
||||
|
||||
KVMHAChecker haChecker = new KVMHAChecker(haWritter.getStoragePools(),
|
||||
"192.168.1.163");
|
||||
KVMHAChecker haChecker = new KVMHAChecker(haWritter.getStoragePools(),
|
||||
"192.168.1.163");
|
||||
|
||||
ExecutorService exe = Executors.newFixedThreadPool(1);
|
||||
Future<Boolean> future = exe.submit((Callable<Boolean>) haChecker);
|
||||
try {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println(future.get());
|
||||
future = exe.submit((Callable<Boolean>) haChecker);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (ExecutionException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
ExecutorService exe = Executors.newFixedThreadPool(1);
|
||||
Future<Boolean> future = exe.submit((Callable<Boolean>) haChecker);
|
||||
try {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println(future.get());
|
||||
future = exe.submit((Callable<Boolean>) haChecker);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (ExecutionException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,59 +27,59 @@ import com.cloud.utils.script.OutputInterpreter;
|
|||
import com.cloud.utils.script.Script;
|
||||
|
||||
public class KVMHAChecker extends KVMHABase implements Callable<Boolean> {
|
||||
private static final Logger s_logger = Logger.getLogger(KVMHAChecker.class);
|
||||
private List<NfsStoragePool> _pools;
|
||||
private String _hostIP;
|
||||
private long _heartBeatCheckerTimeout = 360000; /* 6 minutes */
|
||||
private static final Logger s_logger = Logger.getLogger(KVMHAChecker.class);
|
||||
private List<NfsStoragePool> _pools;
|
||||
private String _hostIP;
|
||||
private long _heartBeatCheckerTimeout = 360000; /* 6 minutes */
|
||||
|
||||
public KVMHAChecker(List<NfsStoragePool> pools, String host) {
|
||||
this._pools = pools;
|
||||
this._hostIP = host;
|
||||
}
|
||||
public KVMHAChecker(List<NfsStoragePool> pools, String host) {
|
||||
this._pools = pools;
|
||||
this._hostIP = host;
|
||||
}
|
||||
|
||||
/*
|
||||
* True means heartbeaing is on going, or we can't get it's status. False
|
||||
* means heartbeating is stopped definitely
|
||||
*/
|
||||
private Boolean checkingHB() {
|
||||
List<Boolean> results = new ArrayList<Boolean>();
|
||||
for (NfsStoragePool pool : _pools) {
|
||||
/*
|
||||
* True means heartbeaing is on going, or we can't get it's status. False
|
||||
* means heartbeating is stopped definitely
|
||||
*/
|
||||
private Boolean checkingHB() {
|
||||
List<Boolean> results = new ArrayList<Boolean>();
|
||||
for (NfsStoragePool pool : _pools) {
|
||||
|
||||
Script cmd = new Script(_heartBeatPath, _heartBeatCheckerTimeout,
|
||||
s_logger);
|
||||
cmd.add("-i", pool._poolIp);
|
||||
cmd.add("-p", pool._poolMountSourcePath);
|
||||
cmd.add("-m", pool._mountDestPath);
|
||||
cmd.add("-h", _hostIP);
|
||||
cmd.add("-r");
|
||||
cmd.add("-t",
|
||||
String.valueOf((_heartBeatUpdateFreq + _heartBeatUpdateTimeout) / 1000 * 2));
|
||||
OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
|
||||
String result = cmd.execute(parser);
|
||||
s_logger.debug("pool: " + pool._poolIp);
|
||||
s_logger.debug("reture: " + result);
|
||||
s_logger.debug("parser: " + parser.getLine());
|
||||
if (result == null && parser.getLine().contains("> DEAD <")) {
|
||||
s_logger.debug("read heartbeat failed: " + result);
|
||||
results.add(false);
|
||||
} else {
|
||||
results.add(true);
|
||||
}
|
||||
}
|
||||
Script cmd = new Script(_heartBeatPath, _heartBeatCheckerTimeout,
|
||||
s_logger);
|
||||
cmd.add("-i", pool._poolIp);
|
||||
cmd.add("-p", pool._poolMountSourcePath);
|
||||
cmd.add("-m", pool._mountDestPath);
|
||||
cmd.add("-h", _hostIP);
|
||||
cmd.add("-r");
|
||||
cmd.add("-t",
|
||||
String.valueOf((_heartBeatUpdateFreq + _heartBeatUpdateTimeout) / 1000 * 2));
|
||||
OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
|
||||
String result = cmd.execute(parser);
|
||||
s_logger.debug("pool: " + pool._poolIp);
|
||||
s_logger.debug("reture: " + result);
|
||||
s_logger.debug("parser: " + parser.getLine());
|
||||
if (result == null && parser.getLine().contains("> DEAD <")) {
|
||||
s_logger.debug("read heartbeat failed: " + result);
|
||||
results.add(false);
|
||||
} else {
|
||||
results.add(true);
|
||||
}
|
||||
}
|
||||
|
||||
for (Boolean r : results) {
|
||||
if (r) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (Boolean r : results) {
|
||||
if (r) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
// s_logger.addAppender(new org.apache.log4j.ConsoleAppender(new
|
||||
// org.apache.log4j.PatternLayout(), "System.out"));
|
||||
return checkingHB();
|
||||
}
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
// s_logger.addAppender(new org.apache.log4j.ConsoleAppender(new
|
||||
// org.apache.log4j.PatternLayout(), "System.out"));
|
||||
return checkingHB();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,96 +24,96 @@ import org.apache.log4j.Logger;
|
|||
import com.cloud.utils.script.Script;
|
||||
|
||||
public class KVMHAMonitor extends KVMHABase implements Runnable {
|
||||
private static final Logger s_logger = Logger.getLogger(KVMHAMonitor.class);
|
||||
private Map<String, NfsStoragePool> _storagePool = new ConcurrentHashMap<String, NfsStoragePool>();
|
||||
private static final Logger s_logger = Logger.getLogger(KVMHAMonitor.class);
|
||||
private Map<String, NfsStoragePool> _storagePool = new ConcurrentHashMap<String, NfsStoragePool>();
|
||||
|
||||
private String _hostIP; /* private ip address */
|
||||
private String _hostIP; /* private ip address */
|
||||
|
||||
public KVMHAMonitor(NfsStoragePool pool, String host, String scriptPath) {
|
||||
if (pool != null) {
|
||||
this._storagePool.put(pool._poolUUID, pool);
|
||||
}
|
||||
this._hostIP = host;
|
||||
this._heartBeatPath = scriptPath;
|
||||
}
|
||||
public KVMHAMonitor(NfsStoragePool pool, String host, String scriptPath) {
|
||||
if (pool != null) {
|
||||
this._storagePool.put(pool._poolUUID, pool);
|
||||
}
|
||||
this._hostIP = host;
|
||||
this._heartBeatPath = scriptPath;
|
||||
}
|
||||
|
||||
public void addStoragePool(NfsStoragePool pool) {
|
||||
synchronized (_storagePool) {
|
||||
this._storagePool.put(pool._poolUUID, pool);
|
||||
}
|
||||
}
|
||||
public void addStoragePool(NfsStoragePool pool) {
|
||||
synchronized (_storagePool) {
|
||||
this._storagePool.put(pool._poolUUID, pool);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeStoragePool(String uuid) {
|
||||
synchronized (_storagePool) {
|
||||
this._storagePool.remove(uuid);
|
||||
}
|
||||
}
|
||||
public void removeStoragePool(String uuid) {
|
||||
synchronized (_storagePool) {
|
||||
this._storagePool.remove(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
public List<NfsStoragePool> getStoragePools() {
|
||||
synchronized (_storagePool) {
|
||||
return new ArrayList<NfsStoragePool>(_storagePool.values());
|
||||
}
|
||||
}
|
||||
public List<NfsStoragePool> getStoragePools() {
|
||||
synchronized (_storagePool) {
|
||||
return new ArrayList<NfsStoragePool>(_storagePool.values());
|
||||
}
|
||||
}
|
||||
|
||||
private class Monitor implements Runnable {
|
||||
private class Monitor implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (_storagePool) {
|
||||
for (NfsStoragePool primaryStoragePool : _storagePool.values()) {
|
||||
String result = null;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Script cmd = new Script(_heartBeatPath,
|
||||
_heartBeatUpdateTimeout, s_logger);
|
||||
cmd.add("-i", primaryStoragePool._poolIp);
|
||||
cmd.add("-p", primaryStoragePool._poolMountSourcePath);
|
||||
cmd.add("-m", primaryStoragePool._mountDestPath);
|
||||
cmd.add("-h", _hostIP);
|
||||
result = cmd.execute();
|
||||
if (result != null) {
|
||||
s_logger.warn("write heartbeat failed: " + result
|
||||
+ ", retry: " + i);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (_storagePool) {
|
||||
for (NfsStoragePool primaryStoragePool : _storagePool.values()) {
|
||||
String result = null;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Script cmd = new Script(_heartBeatPath,
|
||||
_heartBeatUpdateTimeout, s_logger);
|
||||
cmd.add("-i", primaryStoragePool._poolIp);
|
||||
cmd.add("-p", primaryStoragePool._poolMountSourcePath);
|
||||
cmd.add("-m", primaryStoragePool._mountDestPath);
|
||||
cmd.add("-h", _hostIP);
|
||||
result = cmd.execute();
|
||||
if (result != null) {
|
||||
s_logger.warn("write heartbeat failed: " + result
|
||||
+ ", retry: " + i);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
s_logger.warn("write heartbeat failed: " + result
|
||||
+ "; reboot the host");
|
||||
Script cmd = new Script(_heartBeatPath,
|
||||
_heartBeatUpdateTimeout, s_logger);
|
||||
cmd.add("-i", primaryStoragePool._poolIp);
|
||||
cmd.add("-p", primaryStoragePool._poolMountSourcePath);
|
||||
cmd.add("-m", primaryStoragePool._mountDestPath);
|
||||
cmd.add("-c");
|
||||
result = cmd.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result != null) {
|
||||
s_logger.warn("write heartbeat failed: " + result
|
||||
+ "; reboot the host");
|
||||
Script cmd = new Script(_heartBeatPath,
|
||||
_heartBeatUpdateTimeout, s_logger);
|
||||
cmd.add("-i", primaryStoragePool._poolIp);
|
||||
cmd.add("-p", primaryStoragePool._poolMountSourcePath);
|
||||
cmd.add("-m", primaryStoragePool._mountDestPath);
|
||||
cmd.add("-c");
|
||||
result = cmd.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// s_logger.addAppender(new org.apache.log4j.ConsoleAppender(new
|
||||
// org.apache.log4j.PatternLayout(), "System.out"));
|
||||
while (true) {
|
||||
Thread monitorThread = new Thread(new Monitor());
|
||||
monitorThread.start();
|
||||
try {
|
||||
monitorThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
@Override
|
||||
public void run() {
|
||||
// s_logger.addAppender(new org.apache.log4j.ConsoleAppender(new
|
||||
// org.apache.log4j.PatternLayout(), "System.out"));
|
||||
while (true) {
|
||||
Thread monitorThread = new Thread(new Monitor());
|
||||
monitorThread.start();
|
||||
try {
|
||||
monitorThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(_heartBeatUpdateFreq);
|
||||
} catch (InterruptedException e) {
|
||||
try {
|
||||
Thread.sleep(_heartBeatUpdateFreq);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,165 +30,165 @@ import org.xml.sax.SAXException;
|
|||
*
|
||||
*/
|
||||
public class LibvirtCapXMLParser extends LibvirtXMLParser {
|
||||
private boolean _host = false;
|
||||
private boolean _guest = false;
|
||||
private boolean _osType = false;
|
||||
private boolean _domainTypeKVM = false;
|
||||
private boolean _emulatorFlag = false;
|
||||
private final StringBuffer _emulator = new StringBuffer();
|
||||
private final StringBuffer _capXML = new StringBuffer();
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(LibvirtCapXMLParser.class);
|
||||
private final ArrayList<String> guestOsTypes = new ArrayList<String>();
|
||||
private boolean _host = false;
|
||||
private boolean _guest = false;
|
||||
private boolean _osType = false;
|
||||
private boolean _domainTypeKVM = false;
|
||||
private boolean _emulatorFlag = false;
|
||||
private final StringBuffer _emulator = new StringBuffer();
|
||||
private final StringBuffer _capXML = new StringBuffer();
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(LibvirtCapXMLParser.class);
|
||||
private final ArrayList<String> guestOsTypes = new ArrayList<String>();
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName)
|
||||
throws SAXException {
|
||||
if (qName.equalsIgnoreCase("host")) {
|
||||
_host = false;
|
||||
} else if (qName.equalsIgnoreCase("os_type")) {
|
||||
_osType = false;
|
||||
} else if (qName.equalsIgnoreCase("guest")) {
|
||||
_guest = false;
|
||||
} else if (qName.equalsIgnoreCase("domain")) {
|
||||
_domainTypeKVM = false;
|
||||
} else if (qName.equalsIgnoreCase("emulator")) {
|
||||
_emulatorFlag = false;
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName)
|
||||
throws SAXException {
|
||||
if (qName.equalsIgnoreCase("host")) {
|
||||
_host = false;
|
||||
} else if (qName.equalsIgnoreCase("os_type")) {
|
||||
_osType = false;
|
||||
} else if (qName.equalsIgnoreCase("guest")) {
|
||||
_guest = false;
|
||||
} else if (qName.equalsIgnoreCase("domain")) {
|
||||
_domainTypeKVM = false;
|
||||
} else if (qName.equalsIgnoreCase("emulator")) {
|
||||
_emulatorFlag = false;
|
||||
|
||||
} else if (_host) {
|
||||
_capXML.append("<").append("/").append(qName).append(">");
|
||||
}
|
||||
}
|
||||
} else if (_host) {
|
||||
_capXML.append("<").append("/").append(qName).append(">");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length)
|
||||
throws SAXException {
|
||||
if (_host) {
|
||||
_capXML.append(ch, start, length);
|
||||
} else if (_osType) {
|
||||
guestOsTypes.add(new String(ch, start, length));
|
||||
} else if (_emulatorFlag) {
|
||||
_emulator.append(ch, start, length);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length)
|
||||
throws SAXException {
|
||||
if (_host) {
|
||||
_capXML.append(ch, start, length);
|
||||
} else if (_osType) {
|
||||
guestOsTypes.add(new String(ch, start, length));
|
||||
} else if (_emulatorFlag) {
|
||||
_emulator.append(ch, start, length);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName,
|
||||
Attributes attributes) throws SAXException {
|
||||
if (qName.equalsIgnoreCase("host")) {
|
||||
_host = true;
|
||||
} else if (qName.equalsIgnoreCase("guest")) {
|
||||
_guest = true;
|
||||
} else if (qName.equalsIgnoreCase("os_type")) {
|
||||
if (_guest) {
|
||||
_osType = true;
|
||||
}
|
||||
} else if (qName.equalsIgnoreCase("domain")) {
|
||||
for (int i = 0; i < attributes.getLength(); i++) {
|
||||
if (attributes.getQName(i).equalsIgnoreCase("type")
|
||||
&& attributes.getValue(i).equalsIgnoreCase("kvm")) {
|
||||
_domainTypeKVM = true;
|
||||
}
|
||||
}
|
||||
} else if (qName.equalsIgnoreCase("emulator") && _domainTypeKVM) {
|
||||
_emulatorFlag = true;
|
||||
_emulator.delete(0, _emulator.length());
|
||||
} else if (_host) {
|
||||
_capXML.append("<").append(qName);
|
||||
for (int i = 0; i < attributes.getLength(); i++) {
|
||||
_capXML.append(" ").append(attributes.getQName(i)).append("=")
|
||||
.append(attributes.getValue(i));
|
||||
}
|
||||
_capXML.append(">");
|
||||
}
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName,
|
||||
Attributes attributes) throws SAXException {
|
||||
if (qName.equalsIgnoreCase("host")) {
|
||||
_host = true;
|
||||
} else if (qName.equalsIgnoreCase("guest")) {
|
||||
_guest = true;
|
||||
} else if (qName.equalsIgnoreCase("os_type")) {
|
||||
if (_guest) {
|
||||
_osType = true;
|
||||
}
|
||||
} else if (qName.equalsIgnoreCase("domain")) {
|
||||
for (int i = 0; i < attributes.getLength(); i++) {
|
||||
if (attributes.getQName(i).equalsIgnoreCase("type")
|
||||
&& attributes.getValue(i).equalsIgnoreCase("kvm")) {
|
||||
_domainTypeKVM = true;
|
||||
}
|
||||
}
|
||||
} else if (qName.equalsIgnoreCase("emulator") && _domainTypeKVM) {
|
||||
_emulatorFlag = true;
|
||||
_emulator.delete(0, _emulator.length());
|
||||
} else if (_host) {
|
||||
_capXML.append("<").append(qName);
|
||||
for (int i = 0; i < attributes.getLength(); i++) {
|
||||
_capXML.append(" ").append(attributes.getQName(i)).append("=")
|
||||
.append(attributes.getValue(i));
|
||||
}
|
||||
_capXML.append(">");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public String parseCapabilitiesXML(String capXML) {
|
||||
if (!_initialized) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
_sp.parse(new InputSource(new StringReader(capXML)), this);
|
||||
return _capXML.toString();
|
||||
} catch (SAXException se) {
|
||||
s_logger.warn(se.getMessage());
|
||||
} catch (IOException ie) {
|
||||
s_logger.error(ie.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public String parseCapabilitiesXML(String capXML) {
|
||||
if (!_initialized) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
_sp.parse(new InputSource(new StringReader(capXML)), this);
|
||||
return _capXML.toString();
|
||||
} catch (SAXException se) {
|
||||
s_logger.warn(se.getMessage());
|
||||
} catch (IOException ie) {
|
||||
s_logger.error(ie.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArrayList<String> getGuestOsType() {
|
||||
return guestOsTypes;
|
||||
}
|
||||
public ArrayList<String> getGuestOsType() {
|
||||
return guestOsTypes;
|
||||
}
|
||||
|
||||
public String getEmulator() {
|
||||
return _emulator.toString();
|
||||
}
|
||||
public String getEmulator() {
|
||||
return _emulator.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String capXML = "<capabilities>" + " <host>" + " <cpu>"
|
||||
+ " <arch>x86_64</arch>" + " <model>core2duo</model>"
|
||||
+ " <topology sockets='1' cores='2' threads='1'/>"
|
||||
+ " <feature name='lahf_lm'/>"
|
||||
+ " <feature name='xtpr'/>"
|
||||
+ " <feature name='cx16'/>"
|
||||
+ " <feature name='tm2'/>" + " <feature name='est'/>"
|
||||
+ " <feature name='vmx'/>"
|
||||
+ " <feature name='ds_cpl'/>"
|
||||
+ " <feature name='pbe'/>" + " <feature name='tm'/>"
|
||||
+ " <feature name='ht'/>" + " <feature name='ss'/>"
|
||||
+ " <feature name='acpi'/>" + " <feature name='ds'/>"
|
||||
+ " </cpu>" + " <migration_features>" + " <live/>"
|
||||
+ " <uri_transports>"
|
||||
+ " <uri_transport>tcp</uri_transport>"
|
||||
+ " </uri_transports>" + " </migration_features>"
|
||||
+ " <topology>" + " <cells num='1'>"
|
||||
+ " <cell id='0'>" + " <cpus num='2'>"
|
||||
+ " <cpu id='0'/>" + " <cpu id='1'/>"
|
||||
+ " </cpus>" + " </cell>" + " </cells>"
|
||||
+ " </topology>" + " </host>" + "" + " <guest>"
|
||||
+ " <os_type>hvm</os_type>" + " <arch name='i686'>"
|
||||
+ " <wordsize>32</wordsize>"
|
||||
+ " <emulator>/usr/bin/qemu</emulator>"
|
||||
+ " <machine>pc-0.11</machine>"
|
||||
+ " <machine canonical='pc-0.11'>pc</machine>"
|
||||
+ " <machine>pc-0.10</machine>"
|
||||
+ " <machine>isapc</machine>"
|
||||
+ " <domain type='qemu'>" + " </domain>"
|
||||
+ " <domain type='kvm'>"
|
||||
+ " <emulator>/usr/bin/qemu-kvm</emulator>"
|
||||
+ " <machine>pc-0.11</machine>"
|
||||
+ " <machine canonical='pc-0.11'>pc</machine>"
|
||||
+ " <machine>pc-0.10</machine>"
|
||||
+ " <machine>isapc</machine>" + " </domain>"
|
||||
+ " </arch>" + " <features>" + " <cpuselection/>"
|
||||
+ " <pae/>" + " <nonpae/>"
|
||||
+ " <acpi default='on' toggle='yes'/>"
|
||||
+ " <apic default='on' toggle='no'/>" + " </features>"
|
||||
+ " </guest>" + " <guest>" + " <os_type>hvm</os_type>"
|
||||
+ " <arch name='x86_64'>" + " <wordsize>64</wordsize>"
|
||||
+ " <emulator>/usr/bin/qemu-system-x86_64</emulator>"
|
||||
+ " <machine>pc-0.11</machine>"
|
||||
+ " <machine canonical='pc-0.11'>pc</machine>"
|
||||
+ " <machine>pc-0.10</machine>"
|
||||
+ " <machine>isapc</machine>"
|
||||
+ " <domain type='qemu'>" + " </domain>"
|
||||
+ " <domain type='kvm'>"
|
||||
+ " <emulator>/usr/bin/qemu-kvm</emulator>"
|
||||
+ " <machine>pc-0.11</machine>"
|
||||
+ " <machine canonical='pc-0.11'>pc</machine>"
|
||||
+ " <machine>pc-0.10</machine>"
|
||||
+ " <machine>isapc</machine>" + " </domain>"
|
||||
+ " </arch>" + " <features>" + " <cpuselection/>"
|
||||
+ " <acpi default='on' toggle='yes'/>"
|
||||
+ " <apic default='on' toggle='no'/>" + " </features>"
|
||||
+ " </guest>" + "</capabilities>";
|
||||
public static void main(String[] args) {
|
||||
String capXML = "<capabilities>" + " <host>" + " <cpu>"
|
||||
+ " <arch>x86_64</arch>" + " <model>core2duo</model>"
|
||||
+ " <topology sockets='1' cores='2' threads='1'/>"
|
||||
+ " <feature name='lahf_lm'/>"
|
||||
+ " <feature name='xtpr'/>"
|
||||
+ " <feature name='cx16'/>"
|
||||
+ " <feature name='tm2'/>" + " <feature name='est'/>"
|
||||
+ " <feature name='vmx'/>"
|
||||
+ " <feature name='ds_cpl'/>"
|
||||
+ " <feature name='pbe'/>" + " <feature name='tm'/>"
|
||||
+ " <feature name='ht'/>" + " <feature name='ss'/>"
|
||||
+ " <feature name='acpi'/>" + " <feature name='ds'/>"
|
||||
+ " </cpu>" + " <migration_features>" + " <live/>"
|
||||
+ " <uri_transports>"
|
||||
+ " <uri_transport>tcp</uri_transport>"
|
||||
+ " </uri_transports>" + " </migration_features>"
|
||||
+ " <topology>" + " <cells num='1'>"
|
||||
+ " <cell id='0'>" + " <cpus num='2'>"
|
||||
+ " <cpu id='0'/>" + " <cpu id='1'/>"
|
||||
+ " </cpus>" + " </cell>" + " </cells>"
|
||||
+ " </topology>" + " </host>" + "" + " <guest>"
|
||||
+ " <os_type>hvm</os_type>" + " <arch name='i686'>"
|
||||
+ " <wordsize>32</wordsize>"
|
||||
+ " <emulator>/usr/bin/qemu</emulator>"
|
||||
+ " <machine>pc-0.11</machine>"
|
||||
+ " <machine canonical='pc-0.11'>pc</machine>"
|
||||
+ " <machine>pc-0.10</machine>"
|
||||
+ " <machine>isapc</machine>"
|
||||
+ " <domain type='qemu'>" + " </domain>"
|
||||
+ " <domain type='kvm'>"
|
||||
+ " <emulator>/usr/bin/qemu-kvm</emulator>"
|
||||
+ " <machine>pc-0.11</machine>"
|
||||
+ " <machine canonical='pc-0.11'>pc</machine>"
|
||||
+ " <machine>pc-0.10</machine>"
|
||||
+ " <machine>isapc</machine>" + " </domain>"
|
||||
+ " </arch>" + " <features>" + " <cpuselection/>"
|
||||
+ " <pae/>" + " <nonpae/>"
|
||||
+ " <acpi default='on' toggle='yes'/>"
|
||||
+ " <apic default='on' toggle='no'/>" + " </features>"
|
||||
+ " </guest>" + " <guest>" + " <os_type>hvm</os_type>"
|
||||
+ " <arch name='x86_64'>" + " <wordsize>64</wordsize>"
|
||||
+ " <emulator>/usr/bin/qemu-system-x86_64</emulator>"
|
||||
+ " <machine>pc-0.11</machine>"
|
||||
+ " <machine canonical='pc-0.11'>pc</machine>"
|
||||
+ " <machine>pc-0.10</machine>"
|
||||
+ " <machine>isapc</machine>"
|
||||
+ " <domain type='qemu'>" + " </domain>"
|
||||
+ " <domain type='kvm'>"
|
||||
+ " <emulator>/usr/bin/qemu-kvm</emulator>"
|
||||
+ " <machine>pc-0.11</machine>"
|
||||
+ " <machine canonical='pc-0.11'>pc</machine>"
|
||||
+ " <machine>pc-0.10</machine>"
|
||||
+ " <machine>isapc</machine>" + " </domain>"
|
||||
+ " </arch>" + " <features>" + " <cpuselection/>"
|
||||
+ " <acpi default='on' toggle='yes'/>"
|
||||
+ " <apic default='on' toggle='no'/>" + " </features>"
|
||||
+ " </guest>" + "</capabilities>";
|
||||
|
||||
LibvirtCapXMLParser parser = new LibvirtCapXMLParser();
|
||||
String cap = parser.parseCapabilitiesXML(capXML);
|
||||
System.out.println(parser.getGuestOsType());
|
||||
System.out.println(parser.getEmulator());
|
||||
}
|
||||
LibvirtCapXMLParser parser = new LibvirtCapXMLParser();
|
||||
String cap = parser.parseCapabilitiesXML(capXML);
|
||||
System.out.println(parser.getGuestOsType());
|
||||
System.out.println(parser.getEmulator());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -21,28 +21,28 @@ import org.libvirt.Connect;
|
|||
import org.libvirt.LibvirtException;
|
||||
|
||||
public class LibvirtConnection {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(LibvirtConnection.class);
|
||||
static private Connect _connection;
|
||||
static private String _hypervisorURI;
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(LibvirtConnection.class);
|
||||
static private Connect _connection;
|
||||
static private String _hypervisorURI;
|
||||
|
||||
static public Connect getConnection() throws LibvirtException {
|
||||
if (_connection == null) {
|
||||
_connection = new Connect(_hypervisorURI, false);
|
||||
} else {
|
||||
try {
|
||||
_connection.getVersion();
|
||||
} catch (LibvirtException e) {
|
||||
s_logger.debug("Connection with libvirtd is broken, due to "
|
||||
+ e.getMessage());
|
||||
_connection = new Connect(_hypervisorURI, false);
|
||||
}
|
||||
}
|
||||
static public Connect getConnection() throws LibvirtException {
|
||||
if (_connection == null) {
|
||||
_connection = new Connect(_hypervisorURI, false);
|
||||
} else {
|
||||
try {
|
||||
_connection.getVersion();
|
||||
} catch (LibvirtException e) {
|
||||
s_logger.debug("Connection with libvirtd is broken, due to "
|
||||
+ e.getMessage());
|
||||
_connection = new Connect(_hypervisorURI, false);
|
||||
}
|
||||
}
|
||||
|
||||
return _connection;
|
||||
}
|
||||
return _connection;
|
||||
}
|
||||
|
||||
static void initialize(String hypervisorURI) {
|
||||
_hypervisorURI = hypervisorURI;
|
||||
}
|
||||
static void initialize(String hypervisorURI) {
|
||||
_hypervisorURI = hypervisorURI;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,209 +45,209 @@ import com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef.nicModel;
|
|||
*
|
||||
*/
|
||||
public class LibvirtDomainXMLParser {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(LibvirtDomainXMLParser.class);
|
||||
private final List<InterfaceDef> interfaces = new ArrayList<InterfaceDef>();
|
||||
private final List<DiskDef> diskDefs = new ArrayList<DiskDef>();
|
||||
private Integer vncPort;
|
||||
private String desc;
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(LibvirtDomainXMLParser.class);
|
||||
private final List<InterfaceDef> interfaces = new ArrayList<InterfaceDef>();
|
||||
private final List<DiskDef> diskDefs = new ArrayList<DiskDef>();
|
||||
private Integer vncPort;
|
||||
private String desc;
|
||||
|
||||
public boolean parseDomainXML(String domXML) {
|
||||
DocumentBuilder builder;
|
||||
try {
|
||||
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
public boolean parseDomainXML(String domXML) {
|
||||
DocumentBuilder builder;
|
||||
try {
|
||||
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
|
||||
InputSource is = new InputSource();
|
||||
is.setCharacterStream(new StringReader(domXML));
|
||||
Document doc = builder.parse(is);
|
||||
InputSource is = new InputSource();
|
||||
is.setCharacterStream(new StringReader(domXML));
|
||||
Document doc = builder.parse(is);
|
||||
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
|
||||
desc = getTagValue("description", rootElement);
|
||||
desc = getTagValue("description", rootElement);
|
||||
|
||||
Element devices = (Element) rootElement.getElementsByTagName(
|
||||
"devices").item(0);
|
||||
NodeList disks = devices.getElementsByTagName("disk");
|
||||
for (int i = 0; i < disks.getLength(); i++) {
|
||||
Element disk = (Element) disks.item(i);
|
||||
String diskFmtType = getAttrValue("driver", "type", disk);
|
||||
String diskFile = getAttrValue("source", "file", disk);
|
||||
String diskDev = getAttrValue("source", "dev", disk);
|
||||
Element devices = (Element) rootElement.getElementsByTagName(
|
||||
"devices").item(0);
|
||||
NodeList disks = devices.getElementsByTagName("disk");
|
||||
for (int i = 0; i < disks.getLength(); i++) {
|
||||
Element disk = (Element) disks.item(i);
|
||||
String diskFmtType = getAttrValue("driver", "type", disk);
|
||||
String diskFile = getAttrValue("source", "file", disk);
|
||||
String diskDev = getAttrValue("source", "dev", disk);
|
||||
|
||||
String diskLabel = getAttrValue("target", "dev", disk);
|
||||
String bus = getAttrValue("target", "bus", disk);
|
||||
String type = disk.getAttribute("type");
|
||||
String device = disk.getAttribute("device");
|
||||
String diskLabel = getAttrValue("target", "dev", disk);
|
||||
String bus = getAttrValue("target", "bus", disk);
|
||||
String type = disk.getAttribute("type");
|
||||
String device = disk.getAttribute("device");
|
||||
|
||||
DiskDef def = new DiskDef();
|
||||
if (type.equalsIgnoreCase("file")) {
|
||||
if (device.equalsIgnoreCase("disk")) {
|
||||
DiskDef.diskFmtType fmt = null;
|
||||
if (diskFmtType != null) {
|
||||
fmt = DiskDef.diskFmtType.valueOf(diskFmtType
|
||||
.toUpperCase());
|
||||
}
|
||||
def.defFileBasedDisk(diskFile, diskLabel,
|
||||
DiskDef.diskBus.valueOf(bus.toUpperCase()), fmt);
|
||||
} else if (device.equalsIgnoreCase("cdrom")) {
|
||||
def.defISODisk(diskFile);
|
||||
}
|
||||
} else if (type.equalsIgnoreCase("block")) {
|
||||
def.defBlockBasedDisk(diskDev, diskLabel,
|
||||
DiskDef.diskBus.valueOf(bus.toUpperCase()));
|
||||
}
|
||||
diskDefs.add(def);
|
||||
}
|
||||
DiskDef def = new DiskDef();
|
||||
if (type.equalsIgnoreCase("file")) {
|
||||
if (device.equalsIgnoreCase("disk")) {
|
||||
DiskDef.diskFmtType fmt = null;
|
||||
if (diskFmtType != null) {
|
||||
fmt = DiskDef.diskFmtType.valueOf(diskFmtType
|
||||
.toUpperCase());
|
||||
}
|
||||
def.defFileBasedDisk(diskFile, diskLabel,
|
||||
DiskDef.diskBus.valueOf(bus.toUpperCase()), fmt);
|
||||
} else if (device.equalsIgnoreCase("cdrom")) {
|
||||
def.defISODisk(diskFile);
|
||||
}
|
||||
} else if (type.equalsIgnoreCase("block")) {
|
||||
def.defBlockBasedDisk(diskDev, diskLabel,
|
||||
DiskDef.diskBus.valueOf(bus.toUpperCase()));
|
||||
}
|
||||
diskDefs.add(def);
|
||||
}
|
||||
|
||||
NodeList nics = devices.getElementsByTagName("interface");
|
||||
for (int i = 0; i < nics.getLength(); i++) {
|
||||
Element nic = (Element) nics.item(i);
|
||||
NodeList nics = devices.getElementsByTagName("interface");
|
||||
for (int i = 0; i < nics.getLength(); i++) {
|
||||
Element nic = (Element) nics.item(i);
|
||||
|
||||
String type = nic.getAttribute("type");
|
||||
String mac = getAttrValue("mac", "address", nic);
|
||||
String dev = getAttrValue("target", "dev", nic);
|
||||
String model = getAttrValue("model", "type", nic);
|
||||
InterfaceDef def = new InterfaceDef();
|
||||
String type = nic.getAttribute("type");
|
||||
String mac = getAttrValue("mac", "address", nic);
|
||||
String dev = getAttrValue("target", "dev", nic);
|
||||
String model = getAttrValue("model", "type", nic);
|
||||
InterfaceDef def = new InterfaceDef();
|
||||
|
||||
if (type.equalsIgnoreCase("network")) {
|
||||
String network = getAttrValue("source", "network", nic);
|
||||
def.defPrivateNet(network, dev, mac,
|
||||
nicModel.valueOf(model.toUpperCase()));
|
||||
} else if (type.equalsIgnoreCase("bridge")) {
|
||||
String bridge = getAttrValue("source", "bridge", nic);
|
||||
def.defBridgeNet(bridge, dev, mac,
|
||||
nicModel.valueOf(model.toUpperCase()));
|
||||
}
|
||||
interfaces.add(def);
|
||||
}
|
||||
if (type.equalsIgnoreCase("network")) {
|
||||
String network = getAttrValue("source", "network", nic);
|
||||
def.defPrivateNet(network, dev, mac,
|
||||
nicModel.valueOf(model.toUpperCase()));
|
||||
} else if (type.equalsIgnoreCase("bridge")) {
|
||||
String bridge = getAttrValue("source", "bridge", nic);
|
||||
def.defBridgeNet(bridge, dev, mac,
|
||||
nicModel.valueOf(model.toUpperCase()));
|
||||
}
|
||||
interfaces.add(def);
|
||||
}
|
||||
|
||||
Element graphic = (Element) devices
|
||||
.getElementsByTagName("graphics").item(0);
|
||||
String port = graphic.getAttribute("port");
|
||||
if (port != null) {
|
||||
try {
|
||||
vncPort = Integer.parseInt(port);
|
||||
if (vncPort != -1) {
|
||||
vncPort = vncPort - 5900;
|
||||
} else {
|
||||
vncPort = null;
|
||||
}
|
||||
} catch (NumberFormatException nfe) {
|
||||
vncPort = null;
|
||||
}
|
||||
}
|
||||
Element graphic = (Element) devices
|
||||
.getElementsByTagName("graphics").item(0);
|
||||
String port = graphic.getAttribute("port");
|
||||
if (port != null) {
|
||||
try {
|
||||
vncPort = Integer.parseInt(port);
|
||||
if (vncPort != -1) {
|
||||
vncPort = vncPort - 5900;
|
||||
} else {
|
||||
vncPort = null;
|
||||
}
|
||||
} catch (NumberFormatException nfe) {
|
||||
vncPort = null;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (ParserConfigurationException e) {
|
||||
s_logger.debug(e.toString());
|
||||
} catch (SAXException e) {
|
||||
s_logger.debug(e.toString());
|
||||
} catch (IOException e) {
|
||||
s_logger.debug(e.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (ParserConfigurationException e) {
|
||||
s_logger.debug(e.toString());
|
||||
} catch (SAXException e) {
|
||||
s_logger.debug(e.toString());
|
||||
} catch (IOException e) {
|
||||
s_logger.debug(e.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String getTagValue(String tag, Element eElement) {
|
||||
NodeList tagNodeList = eElement.getElementsByTagName(tag);
|
||||
if (tagNodeList == null || tagNodeList.getLength() == 0) {
|
||||
return null;
|
||||
}
|
||||
private static String getTagValue(String tag, Element eElement) {
|
||||
NodeList tagNodeList = eElement.getElementsByTagName(tag);
|
||||
if (tagNodeList == null || tagNodeList.getLength() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
NodeList nlList = tagNodeList.item(0).getChildNodes();
|
||||
NodeList nlList = tagNodeList.item(0).getChildNodes();
|
||||
|
||||
Node nValue = (Node) nlList.item(0);
|
||||
Node nValue = (Node) nlList.item(0);
|
||||
|
||||
return nValue.getNodeValue();
|
||||
}
|
||||
return nValue.getNodeValue();
|
||||
}
|
||||
|
||||
private static String getAttrValue(String tag, String attr, Element eElement) {
|
||||
NodeList tagNode = eElement.getElementsByTagName(tag);
|
||||
if (tagNode.getLength() == 0) {
|
||||
return null;
|
||||
}
|
||||
Element node = (Element) tagNode.item(0);
|
||||
return node.getAttribute(attr);
|
||||
}
|
||||
private static String getAttrValue(String tag, String attr, Element eElement) {
|
||||
NodeList tagNode = eElement.getElementsByTagName(tag);
|
||||
if (tagNode.getLength() == 0) {
|
||||
return null;
|
||||
}
|
||||
Element node = (Element) tagNode.item(0);
|
||||
return node.getAttribute(attr);
|
||||
}
|
||||
|
||||
public Integer getVncPort() {
|
||||
return vncPort;
|
||||
}
|
||||
public Integer getVncPort() {
|
||||
return vncPort;
|
||||
}
|
||||
|
||||
public List<InterfaceDef> getInterfaces() {
|
||||
return interfaces;
|
||||
}
|
||||
public List<InterfaceDef> getInterfaces() {
|
||||
return interfaces;
|
||||
}
|
||||
|
||||
public List<DiskDef> getDisks() {
|
||||
return diskDefs;
|
||||
}
|
||||
public List<DiskDef> getDisks() {
|
||||
return diskDefs;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return desc;
|
||||
}
|
||||
public String getDescription() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
|
||||
parser.parseDomainXML("<domain type='kvm' id='12'>"
|
||||
+ "<name>r-6-CV-5002-1</name>"
|
||||
+ "<uuid>581b5a4b-b496-8d4d-e44e-a7dcbe9df0b5</uuid>"
|
||||
+ "<description>testVM</description>"
|
||||
+ "<memory>131072</memory>"
|
||||
+ "<currentMemory>131072</currentMemory>"
|
||||
+ "<vcpu>1</vcpu>"
|
||||
+ "<os>"
|
||||
+ "<type arch='i686' machine='pc-0.11'>hvm</type>"
|
||||
+ "<kernel>/var/lib/libvirt/qemu/vmlinuz-2.6.31.6-166.fc12.i686</kernel>"
|
||||
+ "<cmdline>ro root=/dev/sda1 acpi=force selinux=0 eth0ip=10.1.1.1 eth0mask=255.255.255.0 eth2ip=192.168.10.152 eth2mask=255.255.255.0 gateway=192.168.10.1 dns1=72.52.126.11 dns2=72.52.126.12 domain=v4.myvm.com</cmdline>"
|
||||
+ "<boot dev='hd'/>"
|
||||
+ "</os>"
|
||||
+ "<features>"
|
||||
+ "<acpi/>"
|
||||
+ "<pae/>"
|
||||
+ "</features>"
|
||||
+ "<clock offset='utc'/>"
|
||||
+ "<on_poweroff>destroy</on_poweroff>"
|
||||
+ "<on_reboot>restart</on_reboot>"
|
||||
+ "<on_crash>destroy</on_crash>"
|
||||
+ "<devices>"
|
||||
+ "<emulator>/usr/bin/qemu-kvm</emulator>"
|
||||
+ "<disk type='file' device='disk'>"
|
||||
+ "<driver name='qemu' type='raw'/>"
|
||||
+ "<source file='/mnt/tank//vmops/CV/vm/u000004/r000006/rootdisk'/>"
|
||||
+ "<target dev='hda' bus='ide'/>" + "</disk>"
|
||||
+ "<interface type='bridge'>"
|
||||
+ "<mac address='02:00:50:02:00:01'/>"
|
||||
+ "<source bridge='vnbr5002'/>" + "<target dev='vtap5002'/>"
|
||||
+ "<model type='e1000'/>" + "</interface>"
|
||||
+ "<interface type='network'>"
|
||||
+ "<mac address='00:16:3e:77:e2:a1'/>"
|
||||
+ "<source network='vmops-private'/>" + "<target dev='vnet3'/>"
|
||||
+ "<model type='e1000'/>" + "</interface>"
|
||||
+ "<interface type='bridge'>"
|
||||
+ "<mac address='06:85:00:00:00:04'/>"
|
||||
+ "<source bridge='br0'/>" + "<target dev='tap5002'/>"
|
||||
+ "<model type='e1000'/>" + "</interface>"
|
||||
+ "<input type='mouse' bus='ps2'/>"
|
||||
+ "<graphics type='vnc' port='6031' autoport='no' listen=''/>"
|
||||
+ "<video>" + "<model type='cirrus' vram='9216' heads='1'/>"
|
||||
+ "</video>" + "</devices>" + "</domain>"
|
||||
public static void main(String[] args) {
|
||||
LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
|
||||
parser.parseDomainXML("<domain type='kvm' id='12'>"
|
||||
+ "<name>r-6-CV-5002-1</name>"
|
||||
+ "<uuid>581b5a4b-b496-8d4d-e44e-a7dcbe9df0b5</uuid>"
|
||||
+ "<description>testVM</description>"
|
||||
+ "<memory>131072</memory>"
|
||||
+ "<currentMemory>131072</currentMemory>"
|
||||
+ "<vcpu>1</vcpu>"
|
||||
+ "<os>"
|
||||
+ "<type arch='i686' machine='pc-0.11'>hvm</type>"
|
||||
+ "<kernel>/var/lib/libvirt/qemu/vmlinuz-2.6.31.6-166.fc12.i686</kernel>"
|
||||
+ "<cmdline>ro root=/dev/sda1 acpi=force selinux=0 eth0ip=10.1.1.1 eth0mask=255.255.255.0 eth2ip=192.168.10.152 eth2mask=255.255.255.0 gateway=192.168.10.1 dns1=72.52.126.11 dns2=72.52.126.12 domain=v4.myvm.com</cmdline>"
|
||||
+ "<boot dev='hd'/>"
|
||||
+ "</os>"
|
||||
+ "<features>"
|
||||
+ "<acpi/>"
|
||||
+ "<pae/>"
|
||||
+ "</features>"
|
||||
+ "<clock offset='utc'/>"
|
||||
+ "<on_poweroff>destroy</on_poweroff>"
|
||||
+ "<on_reboot>restart</on_reboot>"
|
||||
+ "<on_crash>destroy</on_crash>"
|
||||
+ "<devices>"
|
||||
+ "<emulator>/usr/bin/qemu-kvm</emulator>"
|
||||
+ "<disk type='file' device='disk'>"
|
||||
+ "<driver name='qemu' type='raw'/>"
|
||||
+ "<source file='/mnt/tank//vmops/CV/vm/u000004/r000006/rootdisk'/>"
|
||||
+ "<target dev='hda' bus='ide'/>" + "</disk>"
|
||||
+ "<interface type='bridge'>"
|
||||
+ "<mac address='02:00:50:02:00:01'/>"
|
||||
+ "<source bridge='vnbr5002'/>" + "<target dev='vtap5002'/>"
|
||||
+ "<model type='e1000'/>" + "</interface>"
|
||||
+ "<interface type='network'>"
|
||||
+ "<mac address='00:16:3e:77:e2:a1'/>"
|
||||
+ "<source network='vmops-private'/>" + "<target dev='vnet3'/>"
|
||||
+ "<model type='e1000'/>" + "</interface>"
|
||||
+ "<interface type='bridge'>"
|
||||
+ "<mac address='06:85:00:00:00:04'/>"
|
||||
+ "<source bridge='br0'/>" + "<target dev='tap5002'/>"
|
||||
+ "<model type='e1000'/>" + "</interface>"
|
||||
+ "<input type='mouse' bus='ps2'/>"
|
||||
+ "<graphics type='vnc' port='6031' autoport='no' listen=''/>"
|
||||
+ "<video>" + "<model type='cirrus' vram='9216' heads='1'/>"
|
||||
+ "</video>" + "</devices>" + "</domain>"
|
||||
|
||||
);
|
||||
for (InterfaceDef intf : parser.getInterfaces()) {
|
||||
System.out.println(intf);
|
||||
}
|
||||
for (DiskDef disk : parser.getDisks()) {
|
||||
System.out.println(disk);
|
||||
}
|
||||
System.out.println(parser.getVncPort());
|
||||
System.out.println(parser.getDescription());
|
||||
);
|
||||
for (InterfaceDef intf : parser.getInterfaces()) {
|
||||
System.out.println(intf);
|
||||
}
|
||||
for (DiskDef disk : parser.getDisks()) {
|
||||
System.out.println(disk);
|
||||
}
|
||||
System.out.println(parser.getVncPort());
|
||||
System.out.println(parser.getDescription());
|
||||
|
||||
List<String> test = new ArrayList<String>(1);
|
||||
test.add("1");
|
||||
test.add("2");
|
||||
if (test.contains("1")) {
|
||||
System.out.print("fdf");
|
||||
}
|
||||
}
|
||||
List<String> test = new ArrayList<String>(1);
|
||||
test.add("1");
|
||||
test.add("2");
|
||||
if (test.contains("1")) {
|
||||
System.out.print("fdf");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,174 +20,174 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
public class LibvirtNetworkDef {
|
||||
enum netType {
|
||||
BRIDGE, NAT, LOCAL
|
||||
}
|
||||
enum netType {
|
||||
BRIDGE, NAT, LOCAL
|
||||
}
|
||||
|
||||
private final String _networkName;
|
||||
private final String _uuid;
|
||||
private netType _networkType;
|
||||
private String _brName;
|
||||
private boolean _stp;
|
||||
private int _delay;
|
||||
private String _fwDev;
|
||||
private final String _domainName;
|
||||
private String _brIPAddr;
|
||||
private String _brNetMask;
|
||||
private final List<IPRange> ipranges = new ArrayList<IPRange>();
|
||||
private final List<dhcpMapping> dhcpMaps = new ArrayList<dhcpMapping>();
|
||||
private final String _networkName;
|
||||
private final String _uuid;
|
||||
private netType _networkType;
|
||||
private String _brName;
|
||||
private boolean _stp;
|
||||
private int _delay;
|
||||
private String _fwDev;
|
||||
private final String _domainName;
|
||||
private String _brIPAddr;
|
||||
private String _brNetMask;
|
||||
private final List<IPRange> ipranges = new ArrayList<IPRange>();
|
||||
private final List<dhcpMapping> dhcpMaps = new ArrayList<dhcpMapping>();
|
||||
|
||||
public static class dhcpMapping {
|
||||
String _mac;
|
||||
String _name;
|
||||
String _ip;
|
||||
public static class dhcpMapping {
|
||||
String _mac;
|
||||
String _name;
|
||||
String _ip;
|
||||
|
||||
public dhcpMapping(String mac, String name, String ip) {
|
||||
_mac = mac;
|
||||
_name = name;
|
||||
_ip = ip;
|
||||
}
|
||||
}
|
||||
public dhcpMapping(String mac, String name, String ip) {
|
||||
_mac = mac;
|
||||
_name = name;
|
||||
_ip = ip;
|
||||
}
|
||||
}
|
||||
|
||||
public static class IPRange {
|
||||
String _start;
|
||||
String _end;
|
||||
public static class IPRange {
|
||||
String _start;
|
||||
String _end;
|
||||
|
||||
public IPRange(String start, String end) {
|
||||
_start = start;
|
||||
_end = end;
|
||||
}
|
||||
}
|
||||
public IPRange(String start, String end) {
|
||||
_start = start;
|
||||
_end = end;
|
||||
}
|
||||
}
|
||||
|
||||
public LibvirtNetworkDef(String netName, String uuid, String domName) {
|
||||
_networkName = netName;
|
||||
_uuid = uuid;
|
||||
_domainName = domName;
|
||||
}
|
||||
public LibvirtNetworkDef(String netName, String uuid, String domName) {
|
||||
_networkName = netName;
|
||||
_uuid = uuid;
|
||||
_domainName = domName;
|
||||
}
|
||||
|
||||
public void defNATNetwork(String brName, boolean stp, int delay,
|
||||
String fwNic, String ipAddr, String netMask) {
|
||||
_networkType = netType.NAT;
|
||||
_brName = brName;
|
||||
_stp = stp;
|
||||
_delay = delay;
|
||||
_fwDev = fwNic;
|
||||
_brIPAddr = ipAddr;
|
||||
_brNetMask = netMask;
|
||||
}
|
||||
public void defNATNetwork(String brName, boolean stp, int delay,
|
||||
String fwNic, String ipAddr, String netMask) {
|
||||
_networkType = netType.NAT;
|
||||
_brName = brName;
|
||||
_stp = stp;
|
||||
_delay = delay;
|
||||
_fwDev = fwNic;
|
||||
_brIPAddr = ipAddr;
|
||||
_brNetMask = netMask;
|
||||
}
|
||||
|
||||
public void defBrNetwork(String brName, boolean stp, int delay,
|
||||
String fwNic, String ipAddr, String netMask) {
|
||||
_networkType = netType.BRIDGE;
|
||||
_brName = brName;
|
||||
_stp = stp;
|
||||
_delay = delay;
|
||||
_fwDev = fwNic;
|
||||
_brIPAddr = ipAddr;
|
||||
_brNetMask = netMask;
|
||||
}
|
||||
public void defBrNetwork(String brName, boolean stp, int delay,
|
||||
String fwNic, String ipAddr, String netMask) {
|
||||
_networkType = netType.BRIDGE;
|
||||
_brName = brName;
|
||||
_stp = stp;
|
||||
_delay = delay;
|
||||
_fwDev = fwNic;
|
||||
_brIPAddr = ipAddr;
|
||||
_brNetMask = netMask;
|
||||
}
|
||||
|
||||
public void defLocalNetwork(String brName, boolean stp, int delay,
|
||||
String ipAddr, String netMask) {
|
||||
_networkType = netType.LOCAL;
|
||||
_brName = brName;
|
||||
_stp = stp;
|
||||
_delay = delay;
|
||||
_brIPAddr = ipAddr;
|
||||
_brNetMask = netMask;
|
||||
}
|
||||
public void defLocalNetwork(String brName, boolean stp, int delay,
|
||||
String ipAddr, String netMask) {
|
||||
_networkType = netType.LOCAL;
|
||||
_brName = brName;
|
||||
_stp = stp;
|
||||
_delay = delay;
|
||||
_brIPAddr = ipAddr;
|
||||
_brNetMask = netMask;
|
||||
}
|
||||
|
||||
public void adddhcpIPRange(String start, String end) {
|
||||
IPRange ipr = new IPRange(start, end);
|
||||
ipranges.add(ipr);
|
||||
}
|
||||
public void adddhcpIPRange(String start, String end) {
|
||||
IPRange ipr = new IPRange(start, end);
|
||||
ipranges.add(ipr);
|
||||
}
|
||||
|
||||
public void adddhcpMapping(String mac, String host, String ip) {
|
||||
dhcpMapping map = new dhcpMapping(mac, host, ip);
|
||||
dhcpMaps.add(map);
|
||||
}
|
||||
public void adddhcpMapping(String mac, String host, String ip) {
|
||||
dhcpMapping map = new dhcpMapping(mac, host, ip);
|
||||
dhcpMaps.add(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder netBuilder = new StringBuilder();
|
||||
netBuilder.append("<network>\n");
|
||||
netBuilder.append("<name>" + _networkName + "</name>\n");
|
||||
if (_uuid != null)
|
||||
netBuilder.append("<uuid>" + _uuid + "</uuid>\n");
|
||||
if (_brName != null) {
|
||||
netBuilder.append("<bridge name='" + _brName + "'");
|
||||
if (_stp) {
|
||||
netBuilder.append(" stp='on'");
|
||||
} else {
|
||||
netBuilder.append(" stp='off'");
|
||||
}
|
||||
if (_delay != -1) {
|
||||
netBuilder.append(" delay='" + _delay + "'");
|
||||
}
|
||||
netBuilder.append("/>\n");
|
||||
}
|
||||
if (_domainName != null) {
|
||||
netBuilder.append("<domain name='" + _domainName + "'/>\n");
|
||||
}
|
||||
if (_networkType == netType.BRIDGE) {
|
||||
netBuilder.append("<forward mode='route'");
|
||||
if (_fwDev != null) {
|
||||
netBuilder.append(" dev='" + _fwDev + "'");
|
||||
}
|
||||
netBuilder.append("/>\n");
|
||||
} else if (_networkType == netType.NAT) {
|
||||
netBuilder.append("<forward mode='nat'");
|
||||
if (_fwDev != null) {
|
||||
netBuilder.append(" dev='" + _fwDev + "'");
|
||||
}
|
||||
netBuilder.append("/>\n");
|
||||
}
|
||||
if (_brIPAddr != null || _brNetMask != null || !ipranges.isEmpty()
|
||||
|| !dhcpMaps.isEmpty()) {
|
||||
netBuilder.append("<ip");
|
||||
if (_brIPAddr != null)
|
||||
netBuilder.append(" address='" + _brIPAddr + "'");
|
||||
if (_brNetMask != null) {
|
||||
netBuilder.append(" netmask='" + _brNetMask + "'");
|
||||
}
|
||||
netBuilder.append(">\n");
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder netBuilder = new StringBuilder();
|
||||
netBuilder.append("<network>\n");
|
||||
netBuilder.append("<name>" + _networkName + "</name>\n");
|
||||
if (_uuid != null)
|
||||
netBuilder.append("<uuid>" + _uuid + "</uuid>\n");
|
||||
if (_brName != null) {
|
||||
netBuilder.append("<bridge name='" + _brName + "'");
|
||||
if (_stp) {
|
||||
netBuilder.append(" stp='on'");
|
||||
} else {
|
||||
netBuilder.append(" stp='off'");
|
||||
}
|
||||
if (_delay != -1) {
|
||||
netBuilder.append(" delay='" + _delay + "'");
|
||||
}
|
||||
netBuilder.append("/>\n");
|
||||
}
|
||||
if (_domainName != null) {
|
||||
netBuilder.append("<domain name='" + _domainName + "'/>\n");
|
||||
}
|
||||
if (_networkType == netType.BRIDGE) {
|
||||
netBuilder.append("<forward mode='route'");
|
||||
if (_fwDev != null) {
|
||||
netBuilder.append(" dev='" + _fwDev + "'");
|
||||
}
|
||||
netBuilder.append("/>\n");
|
||||
} else if (_networkType == netType.NAT) {
|
||||
netBuilder.append("<forward mode='nat'");
|
||||
if (_fwDev != null) {
|
||||
netBuilder.append(" dev='" + _fwDev + "'");
|
||||
}
|
||||
netBuilder.append("/>\n");
|
||||
}
|
||||
if (_brIPAddr != null || _brNetMask != null || !ipranges.isEmpty()
|
||||
|| !dhcpMaps.isEmpty()) {
|
||||
netBuilder.append("<ip");
|
||||
if (_brIPAddr != null)
|
||||
netBuilder.append(" address='" + _brIPAddr + "'");
|
||||
if (_brNetMask != null) {
|
||||
netBuilder.append(" netmask='" + _brNetMask + "'");
|
||||
}
|
||||
netBuilder.append(">\n");
|
||||
|
||||
if (!ipranges.isEmpty() || !dhcpMaps.isEmpty()) {
|
||||
netBuilder.append("<dhcp>\n");
|
||||
for (IPRange ip : ipranges) {
|
||||
netBuilder.append("<range start='" + ip._start + "'"
|
||||
+ " end='" + ip._end + "'/>\n");
|
||||
}
|
||||
for (dhcpMapping map : dhcpMaps) {
|
||||
netBuilder.append("<host mac='" + map._mac + "' name='"
|
||||
+ map._name + "' ip='" + map._ip + "'/>\n");
|
||||
}
|
||||
netBuilder.append("</dhcp>\n");
|
||||
}
|
||||
netBuilder.append("</ip>\n");
|
||||
}
|
||||
netBuilder.append("</network>\n");
|
||||
return netBuilder.toString();
|
||||
}
|
||||
if (!ipranges.isEmpty() || !dhcpMaps.isEmpty()) {
|
||||
netBuilder.append("<dhcp>\n");
|
||||
for (IPRange ip : ipranges) {
|
||||
netBuilder.append("<range start='" + ip._start + "'"
|
||||
+ " end='" + ip._end + "'/>\n");
|
||||
}
|
||||
for (dhcpMapping map : dhcpMaps) {
|
||||
netBuilder.append("<host mac='" + map._mac + "' name='"
|
||||
+ map._name + "' ip='" + map._ip + "'/>\n");
|
||||
}
|
||||
netBuilder.append("</dhcp>\n");
|
||||
}
|
||||
netBuilder.append("</ip>\n");
|
||||
}
|
||||
netBuilder.append("</network>\n");
|
||||
return netBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
LibvirtNetworkDef net = new LibvirtNetworkDef("cloudPrivate", null,
|
||||
"cloud.com");
|
||||
net.defNATNetwork("cloudbr0", false, 0, null, "192.168.168.1",
|
||||
"255.255.255.0");
|
||||
net.adddhcpIPRange("192.168.168.100", "192.168.168.220");
|
||||
net.adddhcpIPRange("192.168.168.10", "192.168.168.50");
|
||||
net.adddhcpMapping("branch0.cloud.com", "00:16:3e:77:e2:ed",
|
||||
"192.168.168.100");
|
||||
net.adddhcpMapping("branch1.cloud.com", "00:16:3e:77:e2:ef",
|
||||
"192.168.168.101");
|
||||
net.adddhcpMapping("branch2.cloud.com", "00:16:3e:77:e2:f0",
|
||||
"192.168.168.102");
|
||||
System.out.println(net.toString());
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
LibvirtNetworkDef net = new LibvirtNetworkDef("cloudPrivate", null,
|
||||
"cloud.com");
|
||||
net.defNATNetwork("cloudbr0", false, 0, null, "192.168.168.1",
|
||||
"255.255.255.0");
|
||||
net.adddhcpIPRange("192.168.168.100", "192.168.168.220");
|
||||
net.adddhcpIPRange("192.168.168.10", "192.168.168.50");
|
||||
net.adddhcpMapping("branch0.cloud.com", "00:16:3e:77:e2:ed",
|
||||
"192.168.168.100");
|
||||
net.adddhcpMapping("branch1.cloud.com", "00:16:3e:77:e2:ef",
|
||||
"192.168.168.101");
|
||||
net.adddhcpMapping("branch2.cloud.com", "00:16:3e:77:e2:f0",
|
||||
"192.168.168.102");
|
||||
System.out.println(net.toString());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,74 +17,74 @@
|
|||
package com.cloud.agent.resource.computing;
|
||||
|
||||
public class LibvirtStoragePoolDef {
|
||||
public enum poolType {
|
||||
ISCSI("iscsi"), NETFS("netfs"), LOGICAL("logical"), DIR("dir");
|
||||
String _poolType;
|
||||
public enum poolType {
|
||||
ISCSI("iscsi"), NETFS("netfs"), LOGICAL("logical"), DIR("dir");
|
||||
String _poolType;
|
||||
|
||||
poolType(String poolType) {
|
||||
_poolType = poolType;
|
||||
}
|
||||
poolType(String poolType) {
|
||||
_poolType = poolType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return _poolType;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return _poolType;
|
||||
}
|
||||
}
|
||||
|
||||
private poolType _poolType;
|
||||
private String _poolName;
|
||||
private String _uuid;
|
||||
private String _sourceHost;
|
||||
private String _sourceDir;
|
||||
private String _targetPath;
|
||||
private poolType _poolType;
|
||||
private String _poolName;
|
||||
private String _uuid;
|
||||
private String _sourceHost;
|
||||
private String _sourceDir;
|
||||
private String _targetPath;
|
||||
|
||||
public LibvirtStoragePoolDef(poolType type, String poolName, String uuid,
|
||||
String host, String dir, String targetPath) {
|
||||
_poolType = type;
|
||||
_poolName = poolName;
|
||||
_uuid = uuid;
|
||||
_sourceHost = host;
|
||||
_sourceDir = dir;
|
||||
_targetPath = targetPath;
|
||||
}
|
||||
public LibvirtStoragePoolDef(poolType type, String poolName, String uuid,
|
||||
String host, String dir, String targetPath) {
|
||||
_poolType = type;
|
||||
_poolName = poolName;
|
||||
_uuid = uuid;
|
||||
_sourceHost = host;
|
||||
_sourceDir = dir;
|
||||
_targetPath = targetPath;
|
||||
}
|
||||
|
||||
public String getPoolName() {
|
||||
return _poolName;
|
||||
}
|
||||
public String getPoolName() {
|
||||
return _poolName;
|
||||
}
|
||||
|
||||
public poolType getPoolType() {
|
||||
return _poolType;
|
||||
}
|
||||
public poolType getPoolType() {
|
||||
return _poolType;
|
||||
}
|
||||
|
||||
public String getSourceHost() {
|
||||
return _sourceHost;
|
||||
}
|
||||
public String getSourceHost() {
|
||||
return _sourceHost;
|
||||
}
|
||||
|
||||
public String getSourceDir() {
|
||||
return _sourceDir;
|
||||
}
|
||||
public String getSourceDir() {
|
||||
return _sourceDir;
|
||||
}
|
||||
|
||||
public String getTargetPath() {
|
||||
return _targetPath;
|
||||
}
|
||||
public String getTargetPath() {
|
||||
return _targetPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder storagePoolBuilder = new StringBuilder();
|
||||
storagePoolBuilder.append("<pool type='" + _poolType + "'>\n");
|
||||
storagePoolBuilder.append("<name>" + _poolName + "</name>\n");
|
||||
if (_uuid != null)
|
||||
storagePoolBuilder.append("<uuid>" + _uuid + "</uuid>\n");
|
||||
if (_poolType == poolType.NETFS) {
|
||||
storagePoolBuilder.append("<source>\n");
|
||||
storagePoolBuilder.append("<host name='" + _sourceHost + "'/>\n");
|
||||
storagePoolBuilder.append("<dir path='" + _sourceDir + "'/>\n");
|
||||
storagePoolBuilder.append("</source>\n");
|
||||
}
|
||||
storagePoolBuilder.append("<target>\n");
|
||||
storagePoolBuilder.append("<path>" + _targetPath + "</path>\n");
|
||||
storagePoolBuilder.append("</target>\n");
|
||||
storagePoolBuilder.append("</pool>\n");
|
||||
return storagePoolBuilder.toString();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder storagePoolBuilder = new StringBuilder();
|
||||
storagePoolBuilder.append("<pool type='" + _poolType + "'>\n");
|
||||
storagePoolBuilder.append("<name>" + _poolName + "</name>\n");
|
||||
if (_uuid != null)
|
||||
storagePoolBuilder.append("<uuid>" + _uuid + "</uuid>\n");
|
||||
if (_poolType == poolType.NETFS) {
|
||||
storagePoolBuilder.append("<source>\n");
|
||||
storagePoolBuilder.append("<host name='" + _sourceHost + "'/>\n");
|
||||
storagePoolBuilder.append("<dir path='" + _sourceDir + "'/>\n");
|
||||
storagePoolBuilder.append("</source>\n");
|
||||
}
|
||||
storagePoolBuilder.append("<target>\n");
|
||||
storagePoolBuilder.append("<path>" + _targetPath + "</path>\n");
|
||||
storagePoolBuilder.append("</target>\n");
|
||||
storagePoolBuilder.append("</pool>\n");
|
||||
return storagePoolBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,81 +29,81 @@ import org.xml.sax.InputSource;
|
|||
import org.xml.sax.SAXException;
|
||||
|
||||
public class LibvirtStoragePoolXMLParser {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(LibvirtStoragePoolXMLParser.class);
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(LibvirtStoragePoolXMLParser.class);
|
||||
|
||||
public LibvirtStoragePoolDef parseStoragePoolXML(String poolXML) {
|
||||
DocumentBuilder builder;
|
||||
try {
|
||||
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
public LibvirtStoragePoolDef parseStoragePoolXML(String poolXML) {
|
||||
DocumentBuilder builder;
|
||||
try {
|
||||
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
|
||||
InputSource is = new InputSource();
|
||||
is.setCharacterStream(new StringReader(poolXML));
|
||||
Document doc = builder.parse(is);
|
||||
InputSource is = new InputSource();
|
||||
is.setCharacterStream(new StringReader(poolXML));
|
||||
Document doc = builder.parse(is);
|
||||
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
String type = rootElement.getAttribute("type");
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
String type = rootElement.getAttribute("type");
|
||||
|
||||
String uuid = getTagValue("uuid", rootElement);
|
||||
String uuid = getTagValue("uuid", rootElement);
|
||||
|
||||
String poolName = getTagValue("name", rootElement);
|
||||
String poolName = getTagValue("name", rootElement);
|
||||
|
||||
Element source = (Element) rootElement.getElementsByTagName(
|
||||
"source").item(0);
|
||||
String host = getAttrValue("host", "name", source);
|
||||
String path = getAttrValue("dir", "path", source);
|
||||
Element source = (Element) rootElement.getElementsByTagName(
|
||||
"source").item(0);
|
||||
String host = getAttrValue("host", "name", source);
|
||||
String path = getAttrValue("dir", "path", source);
|
||||
|
||||
Element target = (Element) rootElement.getElementsByTagName(
|
||||
"target").item(0);
|
||||
String targetPath = getTagValue("path", target);
|
||||
Element target = (Element) rootElement.getElementsByTagName(
|
||||
"target").item(0);
|
||||
String targetPath = getTagValue("path", target);
|
||||
|
||||
return new LibvirtStoragePoolDef(
|
||||
LibvirtStoragePoolDef.poolType.valueOf(type.toUpperCase()),
|
||||
poolName, uuid, host, path, targetPath);
|
||||
} catch (ParserConfigurationException e) {
|
||||
s_logger.debug(e.toString());
|
||||
} catch (SAXException e) {
|
||||
s_logger.debug(e.toString());
|
||||
} catch (IOException e) {
|
||||
s_logger.debug(e.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return new LibvirtStoragePoolDef(
|
||||
LibvirtStoragePoolDef.poolType.valueOf(type.toUpperCase()),
|
||||
poolName, uuid, host, path, targetPath);
|
||||
} catch (ParserConfigurationException e) {
|
||||
s_logger.debug(e.toString());
|
||||
} catch (SAXException e) {
|
||||
s_logger.debug(e.toString());
|
||||
} catch (IOException e) {
|
||||
s_logger.debug(e.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getTagValue(String tag, Element eElement) {
|
||||
NodeList nlList = eElement.getElementsByTagName(tag).item(0)
|
||||
.getChildNodes();
|
||||
Node nValue = (Node) nlList.item(0);
|
||||
private static String getTagValue(String tag, Element eElement) {
|
||||
NodeList nlList = eElement.getElementsByTagName(tag).item(0)
|
||||
.getChildNodes();
|
||||
Node nValue = (Node) nlList.item(0);
|
||||
|
||||
return nValue.getNodeValue();
|
||||
}
|
||||
return nValue.getNodeValue();
|
||||
}
|
||||
|
||||
private static String getAttrValue(String tag, String attr, Element eElement) {
|
||||
NodeList tagNode = eElement.getElementsByTagName(tag);
|
||||
if (tagNode.getLength() == 0) {
|
||||
return null;
|
||||
}
|
||||
Element node = (Element) tagNode.item(0);
|
||||
return node.getAttribute(attr);
|
||||
}
|
||||
private static String getAttrValue(String tag, String attr, Element eElement) {
|
||||
NodeList tagNode = eElement.getElementsByTagName(tag);
|
||||
if (tagNode.getLength() == 0) {
|
||||
return null;
|
||||
}
|
||||
Element node = (Element) tagNode.item(0);
|
||||
return node.getAttribute(attr);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
s_logger.addAppender(new org.apache.log4j.ConsoleAppender(
|
||||
new org.apache.log4j.PatternLayout(), "System.out"));
|
||||
String storagePool = "<pool type='dir'>" + "<name>test</name>"
|
||||
+ "<uuid>bf723c83-4b95-259c-7089-60776e61a11f</uuid>"
|
||||
+ "<capacity>20314165248</capacity>"
|
||||
+ "<allocation>1955450880</allocation>"
|
||||
+ "<available>18358714368</available>" + "<source>"
|
||||
+ "<host name='nfs1.lab.vmops.com'/>"
|
||||
+ "<dir path='/export/home/edison/kvm/primary'/>"
|
||||
+ "<format type='auto'/>" + "</source>" + "<target>"
|
||||
+ "<path>/media</path>" + "<permissions>" + "<mode>0700</mode>"
|
||||
+ "<owner>0</owner>" + "<group>0</group>" + "</permissions>"
|
||||
+ "</target>" + "</pool>";
|
||||
public static void main(String[] args) {
|
||||
s_logger.addAppender(new org.apache.log4j.ConsoleAppender(
|
||||
new org.apache.log4j.PatternLayout(), "System.out"));
|
||||
String storagePool = "<pool type='dir'>" + "<name>test</name>"
|
||||
+ "<uuid>bf723c83-4b95-259c-7089-60776e61a11f</uuid>"
|
||||
+ "<capacity>20314165248</capacity>"
|
||||
+ "<allocation>1955450880</allocation>"
|
||||
+ "<available>18358714368</available>" + "<source>"
|
||||
+ "<host name='nfs1.lab.vmops.com'/>"
|
||||
+ "<dir path='/export/home/edison/kvm/primary'/>"
|
||||
+ "<format type='auto'/>" + "</source>" + "<target>"
|
||||
+ "<path>/media</path>" + "<permissions>" + "<mode>0700</mode>"
|
||||
+ "<owner>0</owner>" + "<group>0</group>" + "</permissions>"
|
||||
+ "</target>" + "</pool>";
|
||||
|
||||
LibvirtStoragePoolXMLParser parser = new LibvirtStoragePoolXMLParser();
|
||||
LibvirtStoragePoolDef pool = parser.parseStoragePoolXML(storagePool);
|
||||
s_logger.debug(pool.toString());
|
||||
}
|
||||
LibvirtStoragePoolXMLParser parser = new LibvirtStoragePoolXMLParser();
|
||||
LibvirtStoragePoolDef pool = parser.parseStoragePoolXML(storagePool);
|
||||
s_logger.debug(pool.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,75 +17,75 @@
|
|||
package com.cloud.agent.resource.computing;
|
||||
|
||||
public class LibvirtStorageVolumeDef {
|
||||
public enum volFormat {
|
||||
RAW("raw"), QCOW2("qcow2"), DIR("dir");
|
||||
private String _format;
|
||||
public enum volFormat {
|
||||
RAW("raw"), QCOW2("qcow2"), DIR("dir");
|
||||
private String _format;
|
||||
|
||||
volFormat(String format) {
|
||||
_format = format;
|
||||
}
|
||||
volFormat(String format) {
|
||||
_format = format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return _format;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return _format;
|
||||
}
|
||||
|
||||
public static volFormat getFormat(String format) {
|
||||
if (format == null) {
|
||||
return null;
|
||||
}
|
||||
if (format.equalsIgnoreCase("raw")) {
|
||||
return RAW;
|
||||
} else if (format.equalsIgnoreCase("qcow2")) {
|
||||
return QCOW2;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static volFormat getFormat(String format) {
|
||||
if (format == null) {
|
||||
return null;
|
||||
}
|
||||
if (format.equalsIgnoreCase("raw")) {
|
||||
return RAW;
|
||||
} else if (format.equalsIgnoreCase("qcow2")) {
|
||||
return QCOW2;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String _volName;
|
||||
private Long _volSize;
|
||||
private volFormat _volFormat;
|
||||
private String _backingPath;
|
||||
private volFormat _backingFormat;
|
||||
private String _volName;
|
||||
private Long _volSize;
|
||||
private volFormat _volFormat;
|
||||
private String _backingPath;
|
||||
private volFormat _backingFormat;
|
||||
|
||||
public LibvirtStorageVolumeDef(String volName, Long size, volFormat format,
|
||||
String tmplPath, volFormat tmplFormat) {
|
||||
_volName = volName;
|
||||
_volSize = size;
|
||||
_volFormat = format;
|
||||
_backingPath = tmplPath;
|
||||
_backingFormat = tmplFormat;
|
||||
}
|
||||
public LibvirtStorageVolumeDef(String volName, Long size, volFormat format,
|
||||
String tmplPath, volFormat tmplFormat) {
|
||||
_volName = volName;
|
||||
_volSize = size;
|
||||
_volFormat = format;
|
||||
_backingPath = tmplPath;
|
||||
_backingFormat = tmplFormat;
|
||||
}
|
||||
|
||||
public volFormat getFormat() {
|
||||
return this._volFormat;
|
||||
}
|
||||
public volFormat getFormat() {
|
||||
return this._volFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder storageVolBuilder = new StringBuilder();
|
||||
storageVolBuilder.append("<volume>\n");
|
||||
storageVolBuilder.append("<name>" + _volName + "</name>\n");
|
||||
if (_volSize != null) {
|
||||
storageVolBuilder
|
||||
.append("<capacity >" + _volSize + "</capacity>\n");
|
||||
}
|
||||
storageVolBuilder.append("<target>\n");
|
||||
storageVolBuilder.append("<format type='" + _volFormat + "'/>\n");
|
||||
storageVolBuilder.append("<permissions>");
|
||||
storageVolBuilder.append("<mode>0744</mode>");
|
||||
storageVolBuilder.append("</permissions>");
|
||||
storageVolBuilder.append("</target>\n");
|
||||
if (_backingPath != null) {
|
||||
storageVolBuilder.append("<backingStore>\n");
|
||||
storageVolBuilder.append("<path>" + _backingPath + "</path>\n");
|
||||
storageVolBuilder.append("<format type='" + _backingFormat
|
||||
+ "'/>\n");
|
||||
storageVolBuilder.append("</backingStore>\n");
|
||||
}
|
||||
storageVolBuilder.append("</volume>\n");
|
||||
return storageVolBuilder.toString();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder storageVolBuilder = new StringBuilder();
|
||||
storageVolBuilder.append("<volume>\n");
|
||||
storageVolBuilder.append("<name>" + _volName + "</name>\n");
|
||||
if (_volSize != null) {
|
||||
storageVolBuilder
|
||||
.append("<capacity >" + _volSize + "</capacity>\n");
|
||||
}
|
||||
storageVolBuilder.append("<target>\n");
|
||||
storageVolBuilder.append("<format type='" + _volFormat + "'/>\n");
|
||||
storageVolBuilder.append("<permissions>");
|
||||
storageVolBuilder.append("<mode>0744</mode>");
|
||||
storageVolBuilder.append("</permissions>");
|
||||
storageVolBuilder.append("</target>\n");
|
||||
if (_backingPath != null) {
|
||||
storageVolBuilder.append("<backingStore>\n");
|
||||
storageVolBuilder.append("<path>" + _backingPath + "</path>\n");
|
||||
storageVolBuilder.append("<format type='" + _backingFormat
|
||||
+ "'/>\n");
|
||||
storageVolBuilder.append("</backingStore>\n");
|
||||
}
|
||||
storageVolBuilder.append("</volume>\n");
|
||||
return storageVolBuilder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,73 +32,73 @@ import org.xml.sax.InputSource;
|
|||
import org.xml.sax.SAXException;
|
||||
|
||||
public class LibvirtStorageVolumeXMLParser {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(LibvirtStorageVolumeXMLParser.class);
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(LibvirtStorageVolumeXMLParser.class);
|
||||
|
||||
public LibvirtStorageVolumeDef parseStorageVolumeXML(String volXML) {
|
||||
DocumentBuilder builder;
|
||||
try {
|
||||
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
public LibvirtStorageVolumeDef parseStorageVolumeXML(String volXML) {
|
||||
DocumentBuilder builder;
|
||||
try {
|
||||
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
|
||||
InputSource is = new InputSource();
|
||||
is.setCharacterStream(new StringReader(volXML));
|
||||
Document doc = builder.parse(is);
|
||||
InputSource is = new InputSource();
|
||||
is.setCharacterStream(new StringReader(volXML));
|
||||
Document doc = builder.parse(is);
|
||||
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
|
||||
String VolName = getTagValue("name", rootElement);
|
||||
Element target = (Element) rootElement.getElementsByTagName(
|
||||
"target").item(0);
|
||||
String format = getAttrValue("type", "format", target);
|
||||
Long capacity = Long
|
||||
.parseLong(getTagValue("capacity", rootElement));
|
||||
return new LibvirtStorageVolumeDef(VolName, capacity,
|
||||
LibvirtStorageVolumeDef.volFormat.getFormat(format), null,
|
||||
null);
|
||||
} catch (ParserConfigurationException e) {
|
||||
s_logger.debug(e.toString());
|
||||
} catch (SAXException e) {
|
||||
s_logger.debug(e.toString());
|
||||
} catch (IOException e) {
|
||||
s_logger.debug(e.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
String VolName = getTagValue("name", rootElement);
|
||||
Element target = (Element) rootElement.getElementsByTagName(
|
||||
"target").item(0);
|
||||
String format = getAttrValue("type", "format", target);
|
||||
Long capacity = Long
|
||||
.parseLong(getTagValue("capacity", rootElement));
|
||||
return new LibvirtStorageVolumeDef(VolName, capacity,
|
||||
LibvirtStorageVolumeDef.volFormat.getFormat(format), null,
|
||||
null);
|
||||
} catch (ParserConfigurationException e) {
|
||||
s_logger.debug(e.toString());
|
||||
} catch (SAXException e) {
|
||||
s_logger.debug(e.toString());
|
||||
} catch (IOException e) {
|
||||
s_logger.debug(e.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getTagValue(String tag, Element eElement) {
|
||||
NodeList nlList = eElement.getElementsByTagName(tag).item(0)
|
||||
.getChildNodes();
|
||||
Node nValue = (Node) nlList.item(0);
|
||||
private static String getTagValue(String tag, Element eElement) {
|
||||
NodeList nlList = eElement.getElementsByTagName(tag).item(0)
|
||||
.getChildNodes();
|
||||
Node nValue = (Node) nlList.item(0);
|
||||
|
||||
return nValue.getNodeValue();
|
||||
}
|
||||
return nValue.getNodeValue();
|
||||
}
|
||||
|
||||
private static String getAttrValue(String tag, String attr, Element eElement) {
|
||||
NodeList tagNode = eElement.getElementsByTagName(tag);
|
||||
if (tagNode.getLength() == 0) {
|
||||
return null;
|
||||
}
|
||||
Element node = (Element) tagNode.item(0);
|
||||
return node.getAttribute(attr);
|
||||
}
|
||||
private static String getAttrValue(String tag, String attr, Element eElement) {
|
||||
NodeList tagNode = eElement.getElementsByTagName(tag);
|
||||
if (tagNode.getLength() == 0) {
|
||||
return null;
|
||||
}
|
||||
Element node = (Element) tagNode.item(0);
|
||||
return node.getAttribute(attr);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
s_logger.addAppender(new org.apache.log4j.ConsoleAppender(
|
||||
new org.apache.log4j.PatternLayout(), "System.out"));
|
||||
String storagePool = "<pool type='dir'>" + "<name>test</name>"
|
||||
+ "<uuid>bf723c83-4b95-259c-7089-60776e61a11f</uuid>"
|
||||
+ "<capacity>20314165248</capacity>"
|
||||
+ "<allocation>1955450880</allocation>"
|
||||
+ "<available>18358714368</available>" + "<source>"
|
||||
+ "<host name='nfs1.lab.vmops.com'/>"
|
||||
+ "<dir path='/export/home/edison/kvm/primary'/>"
|
||||
+ "<format type='auto'/>" + "</source>" + "<target>"
|
||||
+ "<path>/media</path>" + "<permissions>" + "<mode>0700</mode>"
|
||||
+ "<owner>0</owner>" + "<group>0</group>" + "</permissions>"
|
||||
+ "</target>" + "</pool>";
|
||||
public static void main(String[] args) {
|
||||
s_logger.addAppender(new org.apache.log4j.ConsoleAppender(
|
||||
new org.apache.log4j.PatternLayout(), "System.out"));
|
||||
String storagePool = "<pool type='dir'>" + "<name>test</name>"
|
||||
+ "<uuid>bf723c83-4b95-259c-7089-60776e61a11f</uuid>"
|
||||
+ "<capacity>20314165248</capacity>"
|
||||
+ "<allocation>1955450880</allocation>"
|
||||
+ "<available>18358714368</available>" + "<source>"
|
||||
+ "<host name='nfs1.lab.vmops.com'/>"
|
||||
+ "<dir path='/export/home/edison/kvm/primary'/>"
|
||||
+ "<format type='auto'/>" + "</source>" + "<target>"
|
||||
+ "<path>/media</path>" + "<permissions>" + "<mode>0700</mode>"
|
||||
+ "<owner>0</owner>" + "<group>0</group>" + "</permissions>"
|
||||
+ "</target>" + "</pool>";
|
||||
|
||||
LibvirtStoragePoolXMLParser parser = new LibvirtStoragePoolXMLParser();
|
||||
LibvirtStoragePoolDef pool = parser.parseStoragePoolXML(storagePool);
|
||||
s_logger.debug(pool.toString());
|
||||
}
|
||||
LibvirtStoragePoolXMLParser parser = new LibvirtStoragePoolXMLParser();
|
||||
LibvirtStoragePoolDef pool = parser.parseStoragePoolXML(storagePool);
|
||||
s_logger.debug(pool.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -28,45 +28,45 @@ import org.xml.sax.SAXException;
|
|||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
public class LibvirtXMLParser extends DefaultHandler {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(LibvirtXMLParser.class);
|
||||
protected static SAXParserFactory s_spf;
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(LibvirtXMLParser.class);
|
||||
protected static SAXParserFactory s_spf;
|
||||
|
||||
static {
|
||||
s_spf = SAXParserFactory.newInstance();
|
||||
static {
|
||||
s_spf = SAXParserFactory.newInstance();
|
||||
|
||||
}
|
||||
protected SAXParser _sp;
|
||||
protected boolean _initialized = false;
|
||||
}
|
||||
protected SAXParser _sp;
|
||||
protected boolean _initialized = false;
|
||||
|
||||
public LibvirtXMLParser() {
|
||||
public LibvirtXMLParser() {
|
||||
|
||||
try {
|
||||
_sp = s_spf.newSAXParser();
|
||||
_initialized = true;
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
try {
|
||||
_sp = s_spf.newSAXParser();
|
||||
_initialized = true;
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public boolean parseDomainXML(String domXML) {
|
||||
if (!_initialized) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
_sp.parse(new InputSource(new StringReader(domXML)), this);
|
||||
return true;
|
||||
} catch (SAXException se) {
|
||||
s_logger.warn(se.getMessage());
|
||||
} catch (IOException ie) {
|
||||
s_logger.error(ie.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean parseDomainXML(String domXML) {
|
||||
if (!_initialized) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
_sp.parse(new InputSource(new StringReader(domXML)), this);
|
||||
return true;
|
||||
} catch (SAXException se) {
|
||||
s_logger.warn(se.getMessage());
|
||||
} catch (IOException ie) {
|
||||
s_logger.error(ie.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length)
|
||||
throws SAXException {
|
||||
}
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length)
|
||||
throws SAXException {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,64 +17,64 @@
|
|||
package com.cloud.agent.resource.consoleproxy;
|
||||
|
||||
public class ConsoleProxyAuthenticationResult {
|
||||
private boolean success;
|
||||
private boolean isReauthentication;
|
||||
private String host;
|
||||
private int port;
|
||||
private String tunnelUrl;
|
||||
private String tunnelSession;
|
||||
|
||||
public ConsoleProxyAuthenticationResult() {
|
||||
success = false;
|
||||
isReauthentication = false;
|
||||
port = 0;
|
||||
}
|
||||
private boolean success;
|
||||
private boolean isReauthentication;
|
||||
private String host;
|
||||
private int port;
|
||||
private String tunnelUrl;
|
||||
private String tunnelSession;
|
||||
|
||||
public ConsoleProxyAuthenticationResult() {
|
||||
success = false;
|
||||
isReauthentication = false;
|
||||
port = 0;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public boolean isReauthentication() {
|
||||
return isReauthentication;
|
||||
}
|
||||
public boolean isReauthentication() {
|
||||
return isReauthentication;
|
||||
}
|
||||
|
||||
public void setReauthentication(boolean isReauthentication) {
|
||||
this.isReauthentication = isReauthentication;
|
||||
}
|
||||
public void setReauthentication(boolean isReauthentication) {
|
||||
this.isReauthentication = isReauthentication;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getTunnelUrl() {
|
||||
return tunnelUrl;
|
||||
}
|
||||
public String getTunnelUrl() {
|
||||
return tunnelUrl;
|
||||
}
|
||||
|
||||
public void setTunnelUrl(String tunnelUrl) {
|
||||
this.tunnelUrl = tunnelUrl;
|
||||
}
|
||||
public void setTunnelUrl(String tunnelUrl) {
|
||||
this.tunnelUrl = tunnelUrl;
|
||||
}
|
||||
|
||||
public String getTunnelSession() {
|
||||
return tunnelSession;
|
||||
}
|
||||
public String getTunnelSession() {
|
||||
return tunnelSession;
|
||||
}
|
||||
|
||||
public void setTunnelSession(String tunnelSession) {
|
||||
this.tunnelSession = tunnelSession;
|
||||
}
|
||||
public void setTunnelSession(String tunnelSession) {
|
||||
this.tunnelSession = tunnelSession;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,415 +78,415 @@ import com.google.gson.Gson;
|
|||
*
|
||||
*/
|
||||
public class ConsoleProxyResource extends ServerResourceBase implements
|
||||
ServerResource {
|
||||
static final Logger s_logger = Logger.getLogger(ConsoleProxyResource.class);
|
||||
ServerResource {
|
||||
static final Logger s_logger = Logger.getLogger(ConsoleProxyResource.class);
|
||||
|
||||
private final Properties _properties = new Properties();
|
||||
private Thread _consoleProxyMain = null;
|
||||
private final Properties _properties = new Properties();
|
||||
private Thread _consoleProxyMain = null;
|
||||
|
||||
long _proxyVmId;
|
||||
int _proxyPort;
|
||||
long _proxyVmId;
|
||||
int _proxyPort;
|
||||
|
||||
String _localgw;
|
||||
String _eth1ip;
|
||||
String _eth1mask;
|
||||
String _pubIp;
|
||||
String _localgw;
|
||||
String _eth1ip;
|
||||
String _eth1mask;
|
||||
String _pubIp;
|
||||
|
||||
@Override
|
||||
public Answer executeRequest(final Command cmd) {
|
||||
if (cmd instanceof CheckConsoleProxyLoadCommand) {
|
||||
return execute((CheckConsoleProxyLoadCommand) cmd);
|
||||
} else if (cmd instanceof WatchConsoleProxyLoadCommand) {
|
||||
return execute((WatchConsoleProxyLoadCommand) cmd);
|
||||
} else if (cmd instanceof ReadyCommand) {
|
||||
s_logger.info("Receive ReadyCommand, response with ReadyAnswer");
|
||||
return new ReadyAnswer((ReadyCommand) cmd);
|
||||
} else if (cmd instanceof CheckHealthCommand) {
|
||||
return new CheckHealthAnswer((CheckHealthCommand) cmd, true);
|
||||
} else if (cmd instanceof StartConsoleProxyAgentHttpHandlerCommand) {
|
||||
return execute((StartConsoleProxyAgentHttpHandlerCommand) cmd);
|
||||
} else {
|
||||
return Answer.createUnsupportedCommandAnswer(cmd);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Answer executeRequest(final Command cmd) {
|
||||
if (cmd instanceof CheckConsoleProxyLoadCommand) {
|
||||
return execute((CheckConsoleProxyLoadCommand) cmd);
|
||||
} else if (cmd instanceof WatchConsoleProxyLoadCommand) {
|
||||
return execute((WatchConsoleProxyLoadCommand) cmd);
|
||||
} else if (cmd instanceof ReadyCommand) {
|
||||
s_logger.info("Receive ReadyCommand, response with ReadyAnswer");
|
||||
return new ReadyAnswer((ReadyCommand) cmd);
|
||||
} else if (cmd instanceof CheckHealthCommand) {
|
||||
return new CheckHealthAnswer((CheckHealthCommand) cmd, true);
|
||||
} else if (cmd instanceof StartConsoleProxyAgentHttpHandlerCommand) {
|
||||
return execute((StartConsoleProxyAgentHttpHandlerCommand) cmd);
|
||||
} else {
|
||||
return Answer.createUnsupportedCommandAnswer(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
private Answer execute(StartConsoleProxyAgentHttpHandlerCommand cmd) {
|
||||
launchConsoleProxy(cmd.getKeystoreBits(), cmd.getKeystorePassword(), cmd.getEncryptorPassword());
|
||||
return new Answer(cmd);
|
||||
}
|
||||
private Answer execute(StartConsoleProxyAgentHttpHandlerCommand cmd) {
|
||||
launchConsoleProxy(cmd.getKeystoreBits(), cmd.getKeystorePassword(), cmd.getEncryptorPassword());
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
private void disableRpFilter() {
|
||||
try {
|
||||
FileWriter fstream = new FileWriter(
|
||||
"/proc/sys/net/ipv4/conf/eth2/rp_filter");
|
||||
BufferedWriter out = new BufferedWriter(fstream);
|
||||
out.write("0");
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
s_logger.warn("Unable to disable rp_filter");
|
||||
}
|
||||
}
|
||||
private void disableRpFilter() {
|
||||
try {
|
||||
FileWriter fstream = new FileWriter(
|
||||
"/proc/sys/net/ipv4/conf/eth2/rp_filter");
|
||||
BufferedWriter out = new BufferedWriter(fstream);
|
||||
out.write("0");
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
s_logger.warn("Unable to disable rp_filter");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean copyCertToDirectory(String certificate, String filePath)
|
||||
throws IOException {
|
||||
boolean success;
|
||||
// copy cert to the dir
|
||||
FileWriter fstream = new FileWriter(filePath);
|
||||
BufferedWriter out = new BufferedWriter(fstream);
|
||||
out.write(certificate);
|
||||
// Close the output stream
|
||||
out.close();
|
||||
success = true;
|
||||
return success;
|
||||
}
|
||||
private boolean copyCertToDirectory(String certificate, String filePath)
|
||||
throws IOException {
|
||||
boolean success;
|
||||
// copy cert to the dir
|
||||
FileWriter fstream = new FileWriter(filePath);
|
||||
BufferedWriter out = new BufferedWriter(fstream);
|
||||
out.write(certificate);
|
||||
// Close the output stream
|
||||
out.close();
|
||||
success = true;
|
||||
return success;
|
||||
}
|
||||
|
||||
protected Answer execute(final CheckConsoleProxyLoadCommand cmd) {
|
||||
return executeProxyLoadScan(cmd, cmd.getProxyVmId(),
|
||||
cmd.getProxyVmName(), cmd.getProxyManagementIp(),
|
||||
cmd.getProxyCmdPort());
|
||||
}
|
||||
protected Answer execute(final CheckConsoleProxyLoadCommand cmd) {
|
||||
return executeProxyLoadScan(cmd, cmd.getProxyVmId(),
|
||||
cmd.getProxyVmName(), cmd.getProxyManagementIp(),
|
||||
cmd.getProxyCmdPort());
|
||||
}
|
||||
|
||||
protected Answer execute(final WatchConsoleProxyLoadCommand cmd) {
|
||||
return executeProxyLoadScan(cmd, cmd.getProxyVmId(),
|
||||
cmd.getProxyVmName(), cmd.getProxyManagementIp(),
|
||||
cmd.getProxyCmdPort());
|
||||
}
|
||||
protected Answer execute(final WatchConsoleProxyLoadCommand cmd) {
|
||||
return executeProxyLoadScan(cmd, cmd.getProxyVmId(),
|
||||
cmd.getProxyVmName(), cmd.getProxyManagementIp(),
|
||||
cmd.getProxyCmdPort());
|
||||
}
|
||||
|
||||
private Answer executeProxyLoadScan(final Command cmd,
|
||||
final long proxyVmId, final String proxyVmName,
|
||||
final String proxyManagementIp, final int cmdPort) {
|
||||
String result = null;
|
||||
private Answer executeProxyLoadScan(final Command cmd,
|
||||
final long proxyVmId, final String proxyVmName,
|
||||
final String proxyManagementIp, final int cmdPort) {
|
||||
String result = null;
|
||||
|
||||
final StringBuffer sb = new StringBuffer();
|
||||
sb.append("http://").append(proxyManagementIp).append(":" + cmdPort)
|
||||
.append("/cmd/getstatus");
|
||||
final StringBuffer sb = new StringBuffer();
|
||||
sb.append("http://").append(proxyManagementIp).append(":" + cmdPort)
|
||||
.append("/cmd/getstatus");
|
||||
|
||||
boolean success = true;
|
||||
try {
|
||||
final URL url = new URL(sb.toString());
|
||||
final URLConnection conn = url.openConnection();
|
||||
boolean success = true;
|
||||
try {
|
||||
final URL url = new URL(sb.toString());
|
||||
final URLConnection conn = url.openConnection();
|
||||
|
||||
final InputStream is = conn.getInputStream();
|
||||
final BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(is));
|
||||
final StringBuilder sb2 = new StringBuilder();
|
||||
String line = null;
|
||||
try {
|
||||
while ((line = reader.readLine()) != null)
|
||||
sb2.append(line + "\n");
|
||||
result = sb2.toString();
|
||||
} catch (final IOException e) {
|
||||
success = false;
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (final IOException e) {
|
||||
s_logger.warn("Exception when closing , console proxy address : "
|
||||
+ proxyManagementIp);
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
s_logger.warn("Unable to open console proxy command port url, console proxy address : "
|
||||
+ proxyManagementIp);
|
||||
success = false;
|
||||
}
|
||||
final InputStream is = conn.getInputStream();
|
||||
final BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(is));
|
||||
final StringBuilder sb2 = new StringBuilder();
|
||||
String line = null;
|
||||
try {
|
||||
while ((line = reader.readLine()) != null)
|
||||
sb2.append(line + "\n");
|
||||
result = sb2.toString();
|
||||
} catch (final IOException e) {
|
||||
success = false;
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (final IOException e) {
|
||||
s_logger.warn("Exception when closing , console proxy address : "
|
||||
+ proxyManagementIp);
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
s_logger.warn("Unable to open console proxy command port url, console proxy address : "
|
||||
+ proxyManagementIp);
|
||||
success = false;
|
||||
}
|
||||
|
||||
return new ConsoleProxyLoadAnswer(cmd, proxyVmId, proxyVmName, success,
|
||||
result);
|
||||
}
|
||||
return new ConsoleProxyLoadAnswer(cmd, proxyVmId, proxyVmName, success,
|
||||
result);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultScriptsDir() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
protected String getDefaultScriptsDir() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return Host.Type.ConsoleProxy;
|
||||
}
|
||||
public Type getType() {
|
||||
return Host.Type.ConsoleProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized StartupCommand[] initialize() {
|
||||
final StartupProxyCommand cmd = new StartupProxyCommand();
|
||||
fillNetworkInformation(cmd);
|
||||
cmd.setProxyPort(_proxyPort);
|
||||
cmd.setProxyVmId(_proxyVmId);
|
||||
if (_pubIp != null)
|
||||
cmd.setPublicIpAddress(_pubIp);
|
||||
return new StartupCommand[] { cmd };
|
||||
}
|
||||
@Override
|
||||
public synchronized StartupCommand[] initialize() {
|
||||
final StartupProxyCommand cmd = new StartupProxyCommand();
|
||||
fillNetworkInformation(cmd);
|
||||
cmd.setProxyPort(_proxyPort);
|
||||
cmd.setProxyVmId(_proxyVmId);
|
||||
if (_pubIp != null)
|
||||
cmd.setPublicIpAddress(_pubIp);
|
||||
return new StartupCommand[] { cmd };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected() {
|
||||
}
|
||||
@Override
|
||||
public void disconnected() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
return new PingCommand(Type.ConsoleProxy, id);
|
||||
}
|
||||
@Override
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
return new PingCommand(Type.ConsoleProxy, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
_localgw = (String) params.get("localgw");
|
||||
_eth1mask = (String) params.get("eth1mask");
|
||||
_eth1ip = (String) params.get("eth1ip");
|
||||
if (_eth1ip != null) {
|
||||
params.put("private.network.device", "eth1");
|
||||
} else {
|
||||
s_logger.warn("WARNING: eth1ip parameter is not found!");
|
||||
}
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
_localgw = (String) params.get("localgw");
|
||||
_eth1mask = (String) params.get("eth1mask");
|
||||
_eth1ip = (String) params.get("eth1ip");
|
||||
if (_eth1ip != null) {
|
||||
params.put("private.network.device", "eth1");
|
||||
} else {
|
||||
s_logger.warn("WARNING: eth1ip parameter is not found!");
|
||||
}
|
||||
|
||||
String eth2ip = (String) params.get("eth2ip");
|
||||
if (eth2ip != null) {
|
||||
params.put("public.network.device", "eth2");
|
||||
} else {
|
||||
s_logger.warn("WARNING: eth2ip parameter is not found!");
|
||||
}
|
||||
String eth2ip = (String) params.get("eth2ip");
|
||||
if (eth2ip != null) {
|
||||
params.put("public.network.device", "eth2");
|
||||
} else {
|
||||
s_logger.warn("WARNING: eth2ip parameter is not found!");
|
||||
}
|
||||
|
||||
super.configure(name, params);
|
||||
super.configure(name, params);
|
||||
|
||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||
_properties.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||
_properties.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
String value = (String) params.get("premium");
|
||||
if (value != null && value.equals("premium"))
|
||||
_proxyPort = 443;
|
||||
else {
|
||||
value = (String) params.get("consoleproxy.httpListenPort");
|
||||
_proxyPort = NumbersUtil.parseInt(value, 80);
|
||||
}
|
||||
String value = (String) params.get("premium");
|
||||
if (value != null && value.equals("premium"))
|
||||
_proxyPort = 443;
|
||||
else {
|
||||
value = (String) params.get("consoleproxy.httpListenPort");
|
||||
_proxyPort = NumbersUtil.parseInt(value, 80);
|
||||
}
|
||||
|
||||
value = (String) params.get("proxy_vm");
|
||||
_proxyVmId = NumbersUtil.parseLong(value, 0);
|
||||
value = (String) params.get("proxy_vm");
|
||||
_proxyVmId = NumbersUtil.parseLong(value, 0);
|
||||
|
||||
if (_localgw != null) {
|
||||
String mgmtHost = (String) params.get("host");
|
||||
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, mgmtHost);
|
||||
if (_localgw != null) {
|
||||
String mgmtHost = (String) params.get("host");
|
||||
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, mgmtHost);
|
||||
|
||||
String internalDns1 = (String) params.get("internaldns1");
|
||||
if (internalDns1 == null) {
|
||||
s_logger.warn("No DNS entry found during configuration of NfsSecondaryStorage");
|
||||
} else {
|
||||
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask,
|
||||
internalDns1);
|
||||
}
|
||||
String internalDns1 = (String) params.get("internaldns1");
|
||||
if (internalDns1 == null) {
|
||||
s_logger.warn("No DNS entry found during configuration of NfsSecondaryStorage");
|
||||
} else {
|
||||
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask,
|
||||
internalDns1);
|
||||
}
|
||||
|
||||
String internalDns2 = (String) params.get("internaldns2");
|
||||
if (internalDns2 != null) {
|
||||
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask,
|
||||
internalDns2);
|
||||
}
|
||||
}
|
||||
String internalDns2 = (String) params.get("internaldns2");
|
||||
if (internalDns2 != null) {
|
||||
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask,
|
||||
internalDns2);
|
||||
}
|
||||
}
|
||||
|
||||
_pubIp = (String) params.get("public.ip");
|
||||
_pubIp = (String) params.get("public.ip");
|
||||
|
||||
value = (String) params.get("disable_rp_filter");
|
||||
if (value != null && value.equalsIgnoreCase("true")) {
|
||||
disableRpFilter();
|
||||
}
|
||||
value = (String) params.get("disable_rp_filter");
|
||||
if (value != null && value.equalsIgnoreCase("true")) {
|
||||
disableRpFilter();
|
||||
}
|
||||
|
||||
if (s_logger.isInfoEnabled())
|
||||
s_logger.info("Receive proxyVmId in ConsoleProxyResource configuration as "
|
||||
+ _proxyVmId);
|
||||
if (s_logger.isInfoEnabled())
|
||||
s_logger.info("Receive proxyVmId in ConsoleProxyResource configuration as "
|
||||
+ _proxyVmId);
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void addRouteToInternalIpOrCidr(String localgw, String eth1ip,
|
||||
String eth1mask, String destIpOrCidr) {
|
||||
s_logger.debug("addRouteToInternalIp: localgw=" + localgw + ", eth1ip="
|
||||
+ eth1ip + ", eth1mask=" + eth1mask + ",destIp=" + destIpOrCidr);
|
||||
if (destIpOrCidr == null) {
|
||||
s_logger.debug("addRouteToInternalIp: destIp is null");
|
||||
return;
|
||||
}
|
||||
if (!NetUtils.isValidIp(destIpOrCidr)
|
||||
&& !NetUtils.isValidCIDR(destIpOrCidr)) {
|
||||
s_logger.warn(" destIp is not a valid ip address or cidr destIp="
|
||||
+ destIpOrCidr);
|
||||
return;
|
||||
}
|
||||
boolean inSameSubnet = false;
|
||||
if (NetUtils.isValidIp(destIpOrCidr)) {
|
||||
if (eth1ip != null && eth1mask != null) {
|
||||
inSameSubnet = NetUtils.sameSubnet(eth1ip, destIpOrCidr,
|
||||
eth1mask);
|
||||
} else {
|
||||
s_logger.warn("addRouteToInternalIp: unable to determine same subnet: _eth1ip="
|
||||
+ eth1ip
|
||||
+ ", dest ip="
|
||||
+ destIpOrCidr
|
||||
+ ", _eth1mask="
|
||||
+ eth1mask);
|
||||
}
|
||||
} else {
|
||||
inSameSubnet = NetUtils.isNetworkAWithinNetworkB(destIpOrCidr,
|
||||
NetUtils.ipAndNetMaskToCidr(eth1ip, eth1mask));
|
||||
}
|
||||
if (inSameSubnet) {
|
||||
s_logger.debug("addRouteToInternalIp: dest ip " + destIpOrCidr
|
||||
+ " is in the same subnet as eth1 ip " + eth1ip);
|
||||
return;
|
||||
}
|
||||
Script command = new Script("/bin/bash", s_logger);
|
||||
command.add("-c");
|
||||
command.add("ip route delete " + destIpOrCidr);
|
||||
command.execute();
|
||||
command = new Script("/bin/bash", s_logger);
|
||||
command.add("-c");
|
||||
command.add("ip route add " + destIpOrCidr + " via " + localgw);
|
||||
String result = command.execute();
|
||||
if (result != null) {
|
||||
s_logger.warn("Error in configuring route to internal ip err="
|
||||
+ result);
|
||||
} else {
|
||||
s_logger.debug("addRouteToInternalIp: added route to internal ip="
|
||||
+ destIpOrCidr + " via " + localgw);
|
||||
}
|
||||
}
|
||||
private void addRouteToInternalIpOrCidr(String localgw, String eth1ip,
|
||||
String eth1mask, String destIpOrCidr) {
|
||||
s_logger.debug("addRouteToInternalIp: localgw=" + localgw + ", eth1ip="
|
||||
+ eth1ip + ", eth1mask=" + eth1mask + ",destIp=" + destIpOrCidr);
|
||||
if (destIpOrCidr == null) {
|
||||
s_logger.debug("addRouteToInternalIp: destIp is null");
|
||||
return;
|
||||
}
|
||||
if (!NetUtils.isValidIp(destIpOrCidr)
|
||||
&& !NetUtils.isValidCIDR(destIpOrCidr)) {
|
||||
s_logger.warn(" destIp is not a valid ip address or cidr destIp="
|
||||
+ destIpOrCidr);
|
||||
return;
|
||||
}
|
||||
boolean inSameSubnet = false;
|
||||
if (NetUtils.isValidIp(destIpOrCidr)) {
|
||||
if (eth1ip != null && eth1mask != null) {
|
||||
inSameSubnet = NetUtils.sameSubnet(eth1ip, destIpOrCidr,
|
||||
eth1mask);
|
||||
} else {
|
||||
s_logger.warn("addRouteToInternalIp: unable to determine same subnet: _eth1ip="
|
||||
+ eth1ip
|
||||
+ ", dest ip="
|
||||
+ destIpOrCidr
|
||||
+ ", _eth1mask="
|
||||
+ eth1mask);
|
||||
}
|
||||
} else {
|
||||
inSameSubnet = NetUtils.isNetworkAWithinNetworkB(destIpOrCidr,
|
||||
NetUtils.ipAndNetMaskToCidr(eth1ip, eth1mask));
|
||||
}
|
||||
if (inSameSubnet) {
|
||||
s_logger.debug("addRouteToInternalIp: dest ip " + destIpOrCidr
|
||||
+ " is in the same subnet as eth1 ip " + eth1ip);
|
||||
return;
|
||||
}
|
||||
Script command = new Script("/bin/bash", s_logger);
|
||||
command.add("-c");
|
||||
command.add("ip route delete " + destIpOrCidr);
|
||||
command.execute();
|
||||
command = new Script("/bin/bash", s_logger);
|
||||
command.add("-c");
|
||||
command.add("ip route add " + destIpOrCidr + " via " + localgw);
|
||||
String result = command.execute();
|
||||
if (result != null) {
|
||||
s_logger.warn("Error in configuring route to internal ip err="
|
||||
+ result);
|
||||
} else {
|
||||
s_logger.debug("addRouteToInternalIp: added route to internal ip="
|
||||
+ destIpOrCidr + " via " + localgw);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
private void launchConsoleProxy(final byte[] ksBits, final String ksPassword, final String encryptorPassword) {
|
||||
final Object resource = this;
|
||||
if (_consoleProxyMain == null) {
|
||||
_consoleProxyMain = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Class<?> consoleProxyClazz = Class.forName("com.cloud.consoleproxy.ConsoleProxy");
|
||||
try {
|
||||
Method methodSetup = consoleProxyClazz.getMethod(
|
||||
"setEncryptorPassword", String.class);
|
||||
methodSetup.invoke(null, encryptorPassword);
|
||||
|
||||
Method method = consoleProxyClazz.getMethod(
|
||||
"startWithContext", Properties.class,
|
||||
Object.class, byte[].class, String.class);
|
||||
method.invoke(null, _properties, resource, ksBits,
|
||||
ksPassword);
|
||||
} catch (SecurityException e) {
|
||||
s_logger.error("Unable to launch console proxy due to SecurityException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (NoSuchMethodException e) {
|
||||
s_logger.error("Unable to launch console proxy due to NoSuchMethodException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (IllegalArgumentException e) {
|
||||
s_logger.error("Unable to launch console proxy due to IllegalArgumentException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (IllegalAccessException e) {
|
||||
s_logger.error("Unable to launch console proxy due to IllegalAccessException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (InvocationTargetException e) {
|
||||
s_logger.error("Unable to launch console proxy due to InvocationTargetException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
}
|
||||
} catch (final ClassNotFoundException e) {
|
||||
s_logger.error("Unable to launch console proxy due to ClassNotFoundException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
}
|
||||
}
|
||||
}, "Console-Proxy-Main");
|
||||
_consoleProxyMain.setDaemon(true);
|
||||
_consoleProxyMain.start();
|
||||
} else {
|
||||
s_logger.info("com.cloud.consoleproxy.ConsoleProxy is already running");
|
||||
|
||||
try {
|
||||
Class<?> consoleProxyClazz = Class.forName("com.cloud.consoleproxy.ConsoleProxy");
|
||||
Method methodSetup = consoleProxyClazz.getMethod("setEncryptorPassword", String.class);
|
||||
methodSetup.invoke(null, encryptorPassword);
|
||||
} catch (SecurityException e) {
|
||||
s_logger.error("Unable to launch console proxy due to SecurityException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (NoSuchMethodException e) {
|
||||
s_logger.error("Unable to launch console proxy due to NoSuchMethodException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (IllegalArgumentException e) {
|
||||
s_logger.error("Unable to launch console proxy due to IllegalArgumentException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (IllegalAccessException e) {
|
||||
s_logger.error("Unable to launch console proxy due to IllegalAccessException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (InvocationTargetException e) {
|
||||
s_logger.error("Unable to launch console proxy due to InvocationTargetException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (final ClassNotFoundException e) {
|
||||
s_logger.error("Unable to launch console proxy due to ClassNotFoundException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
private void launchConsoleProxy(final byte[] ksBits, final String ksPassword, final String encryptorPassword) {
|
||||
final Object resource = this;
|
||||
if (_consoleProxyMain == null) {
|
||||
_consoleProxyMain = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Class<?> consoleProxyClazz = Class.forName("com.cloud.consoleproxy.ConsoleProxy");
|
||||
try {
|
||||
Method methodSetup = consoleProxyClazz.getMethod(
|
||||
"setEncryptorPassword", String.class);
|
||||
methodSetup.invoke(null, encryptorPassword);
|
||||
|
||||
Method method = consoleProxyClazz.getMethod(
|
||||
"startWithContext", Properties.class,
|
||||
Object.class, byte[].class, String.class);
|
||||
method.invoke(null, _properties, resource, ksBits,
|
||||
ksPassword);
|
||||
} catch (SecurityException e) {
|
||||
s_logger.error("Unable to launch console proxy due to SecurityException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (NoSuchMethodException e) {
|
||||
s_logger.error("Unable to launch console proxy due to NoSuchMethodException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (IllegalArgumentException e) {
|
||||
s_logger.error("Unable to launch console proxy due to IllegalArgumentException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (IllegalAccessException e) {
|
||||
s_logger.error("Unable to launch console proxy due to IllegalAccessException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (InvocationTargetException e) {
|
||||
s_logger.error("Unable to launch console proxy due to InvocationTargetException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
}
|
||||
} catch (final ClassNotFoundException e) {
|
||||
s_logger.error("Unable to launch console proxy due to ClassNotFoundException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
}
|
||||
}
|
||||
}, "Console-Proxy-Main");
|
||||
_consoleProxyMain.setDaemon(true);
|
||||
_consoleProxyMain.start();
|
||||
} else {
|
||||
s_logger.info("com.cloud.consoleproxy.ConsoleProxy is already running");
|
||||
|
||||
try {
|
||||
Class<?> consoleProxyClazz = Class.forName("com.cloud.consoleproxy.ConsoleProxy");
|
||||
Method methodSetup = consoleProxyClazz.getMethod("setEncryptorPassword", String.class);
|
||||
methodSetup.invoke(null, encryptorPassword);
|
||||
} catch (SecurityException e) {
|
||||
s_logger.error("Unable to launch console proxy due to SecurityException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (NoSuchMethodException e) {
|
||||
s_logger.error("Unable to launch console proxy due to NoSuchMethodException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (IllegalArgumentException e) {
|
||||
s_logger.error("Unable to launch console proxy due to IllegalArgumentException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (IllegalAccessException e) {
|
||||
s_logger.error("Unable to launch console proxy due to IllegalAccessException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (InvocationTargetException e) {
|
||||
s_logger.error("Unable to launch console proxy due to InvocationTargetException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (final ClassNotFoundException e) {
|
||||
s_logger.error("Unable to launch console proxy due to ClassNotFoundException");
|
||||
System.exit(ExitStatus.Error.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String authenticateConsoleAccess(String host, String port,
|
||||
String vmId, String sid, String ticket, Boolean isReauthentication) {
|
||||
|
||||
ConsoleAccessAuthenticationCommand cmd = new ConsoleAccessAuthenticationCommand(
|
||||
host, port, vmId, sid, ticket);
|
||||
cmd.setReauthenticating(isReauthentication);
|
||||
|
||||
ConsoleProxyAuthenticationResult result = new ConsoleProxyAuthenticationResult();
|
||||
result.setSuccess(false);
|
||||
result.setReauthentication(isReauthentication);
|
||||
public String authenticateConsoleAccess(String host, String port,
|
||||
String vmId, String sid, String ticket, Boolean isReauthentication) {
|
||||
|
||||
ConsoleAccessAuthenticationCommand cmd = new ConsoleAccessAuthenticationCommand(
|
||||
host, port, vmId, sid, ticket);
|
||||
cmd.setReauthenticating(isReauthentication);
|
||||
|
||||
ConsoleProxyAuthenticationResult result = new ConsoleProxyAuthenticationResult();
|
||||
result.setSuccess(false);
|
||||
result.setReauthentication(isReauthentication);
|
||||
|
||||
try {
|
||||
AgentControlAnswer answer = getAgentControl().sendRequest(cmd, 10000);
|
||||
|
||||
if (answer != null) {
|
||||
ConsoleAccessAuthenticationAnswer authAnswer = (ConsoleAccessAuthenticationAnswer)answer;
|
||||
result.setSuccess(authAnswer.succeeded());
|
||||
result.setHost(authAnswer.getHost());
|
||||
result.setPort(authAnswer.getPort());
|
||||
result.setTunnelUrl(authAnswer.getTunnelUrl());
|
||||
result.setTunnelSession(authAnswer.getTunnelSession());
|
||||
} else {
|
||||
s_logger.error("Authentication failed for vm: " + vmId + " with sid: " + sid);
|
||||
}
|
||||
} catch (AgentControlChannelException e) {
|
||||
s_logger.error("Unable to send out console access authentication request due to "
|
||||
+ e.getMessage(), e);
|
||||
}
|
||||
try {
|
||||
AgentControlAnswer answer = getAgentControl().sendRequest(cmd, 10000);
|
||||
|
||||
if (answer != null) {
|
||||
ConsoleAccessAuthenticationAnswer authAnswer = (ConsoleAccessAuthenticationAnswer)answer;
|
||||
result.setSuccess(authAnswer.succeeded());
|
||||
result.setHost(authAnswer.getHost());
|
||||
result.setPort(authAnswer.getPort());
|
||||
result.setTunnelUrl(authAnswer.getTunnelUrl());
|
||||
result.setTunnelSession(authAnswer.getTunnelSession());
|
||||
} else {
|
||||
s_logger.error("Authentication failed for vm: " + vmId + " with sid: " + sid);
|
||||
}
|
||||
} catch (AgentControlChannelException e) {
|
||||
s_logger.error("Unable to send out console access authentication request due to "
|
||||
+ e.getMessage(), e);
|
||||
}
|
||||
|
||||
return new Gson().toJson(result);
|
||||
}
|
||||
return new Gson().toJson(result);
|
||||
}
|
||||
|
||||
public void reportLoadInfo(String gsonLoadInfo) {
|
||||
ConsoleProxyLoadReportCommand cmd = new ConsoleProxyLoadReportCommand(
|
||||
_proxyVmId, gsonLoadInfo);
|
||||
try {
|
||||
getAgentControl().postRequest(cmd);
|
||||
public void reportLoadInfo(String gsonLoadInfo) {
|
||||
ConsoleProxyLoadReportCommand cmd = new ConsoleProxyLoadReportCommand(
|
||||
_proxyVmId, gsonLoadInfo);
|
||||
try {
|
||||
getAgentControl().postRequest(cmd);
|
||||
|
||||
if (s_logger.isDebugEnabled())
|
||||
s_logger.debug("Report proxy load info, proxy : " + _proxyVmId
|
||||
+ ", load: " + gsonLoadInfo);
|
||||
} catch (AgentControlChannelException e) {
|
||||
s_logger.error(
|
||||
"Unable to send out load info due to " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
if (s_logger.isDebugEnabled())
|
||||
s_logger.debug("Report proxy load info, proxy : " + _proxyVmId
|
||||
+ ", load: " + gsonLoadInfo);
|
||||
} catch (AgentControlChannelException e) {
|
||||
s_logger.error(
|
||||
"Unable to send out load info due to " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void ensureRoute(String address) {
|
||||
if (_localgw != null) {
|
||||
if (s_logger.isDebugEnabled())
|
||||
s_logger.debug("Ensure route for " + address + " via "
|
||||
+ _localgw);
|
||||
public void ensureRoute(String address) {
|
||||
if (_localgw != null) {
|
||||
if (s_logger.isDebugEnabled())
|
||||
s_logger.debug("Ensure route for " + address + " via "
|
||||
+ _localgw);
|
||||
|
||||
// this method won't be called in high frequency, serialize access
|
||||
// to script execution
|
||||
synchronized (this) {
|
||||
try {
|
||||
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask,
|
||||
address);
|
||||
} catch (Throwable e) {
|
||||
s_logger.warn(
|
||||
"Unexpected exception while adding internal route to "
|
||||
+ address, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// this method won't be called in high frequency, serialize access
|
||||
// to script execution
|
||||
synchronized (this) {
|
||||
try {
|
||||
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask,
|
||||
address);
|
||||
} catch (Throwable e) {
|
||||
s_logger.warn(
|
||||
"Unexpected exception while adding internal route to "
|
||||
+ address, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,66 +17,66 @@
|
|||
package com.cloud.agent.storage;
|
||||
|
||||
public class KVMPhysicalDisk {
|
||||
private String path;
|
||||
private String name;
|
||||
private KVMStoragePool pool;
|
||||
private String path;
|
||||
private String name;
|
||||
private KVMStoragePool pool;
|
||||
|
||||
public static enum PhysicalDiskFormat {
|
||||
RAW("raw"), QCOW2("qcow2");
|
||||
String format;
|
||||
public static enum PhysicalDiskFormat {
|
||||
RAW("raw"), QCOW2("qcow2");
|
||||
String format;
|
||||
|
||||
private PhysicalDiskFormat(String format) {
|
||||
this.format = format;
|
||||
}
|
||||
private PhysicalDiskFormat(String format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.format;
|
||||
}
|
||||
}
|
||||
public String toString() {
|
||||
return this.format;
|
||||
}
|
||||
}
|
||||
|
||||
private PhysicalDiskFormat format;
|
||||
private long size;
|
||||
private long virtualSize;
|
||||
private PhysicalDiskFormat format;
|
||||
private long size;
|
||||
private long virtualSize;
|
||||
|
||||
public KVMPhysicalDisk(String path, String name, KVMStoragePool pool) {
|
||||
this.path = path;
|
||||
this.name = name;
|
||||
this.pool = pool;
|
||||
}
|
||||
public KVMPhysicalDisk(String path, String name, KVMStoragePool pool) {
|
||||
this.path = path;
|
||||
this.name = name;
|
||||
this.pool = pool;
|
||||
}
|
||||
|
||||
public void setFormat(PhysicalDiskFormat format) {
|
||||
this.format = format;
|
||||
}
|
||||
public void setFormat(PhysicalDiskFormat format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public PhysicalDiskFormat getFormat() {
|
||||
return this.format;
|
||||
}
|
||||
public PhysicalDiskFormat getFormat() {
|
||||
return this.format;
|
||||
}
|
||||
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return this.size;
|
||||
}
|
||||
public long getSize() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
public void setVirtualSize(long size) {
|
||||
this.virtualSize = size;
|
||||
}
|
||||
public void setVirtualSize(long size) {
|
||||
this.virtualSize = size;
|
||||
}
|
||||
|
||||
public long getVirtualSize() {
|
||||
return this.virtualSize;
|
||||
}
|
||||
public long getVirtualSize() {
|
||||
return this.virtualSize;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public KVMStoragePool getPool() {
|
||||
return this.pool;
|
||||
}
|
||||
public KVMStoragePool getPool() {
|
||||
return this.pool;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,34 +22,34 @@ import com.cloud.agent.storage.KVMPhysicalDisk.PhysicalDiskFormat;
|
|||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
|
||||
public interface KVMStoragePool {
|
||||
public KVMPhysicalDisk createPhysicalDisk(String name,
|
||||
PhysicalDiskFormat format, long size);
|
||||
public KVMPhysicalDisk createPhysicalDisk(String name,
|
||||
PhysicalDiskFormat format, long size);
|
||||
|
||||
public KVMPhysicalDisk createPhysicalDisk(String name, long size);
|
||||
public KVMPhysicalDisk createPhysicalDisk(String name, long size);
|
||||
|
||||
public KVMPhysicalDisk getPhysicalDisk(String volumeUuid);
|
||||
public KVMPhysicalDisk getPhysicalDisk(String volumeUuid);
|
||||
|
||||
public boolean deletePhysicalDisk(String uuid);
|
||||
public boolean deletePhysicalDisk(String uuid);
|
||||
|
||||
public List<KVMPhysicalDisk> listPhysicalDisks();
|
||||
public List<KVMPhysicalDisk> listPhysicalDisks();
|
||||
|
||||
public String getUuid();
|
||||
public String getUuid();
|
||||
|
||||
public long getCapacity();
|
||||
public long getCapacity();
|
||||
|
||||
public long getUsed();
|
||||
public long getUsed();
|
||||
|
||||
public boolean refresh();
|
||||
public boolean refresh();
|
||||
|
||||
public boolean isExternalSnapshot();
|
||||
public boolean isExternalSnapshot();
|
||||
|
||||
public String getLocalPath();
|
||||
public String getLocalPath();
|
||||
|
||||
public StoragePoolType getType();
|
||||
public StoragePoolType getType();
|
||||
|
||||
public boolean delete();
|
||||
public boolean delete();
|
||||
|
||||
PhysicalDiskFormat getDefaultFormat();
|
||||
PhysicalDiskFormat getDefaultFormat();
|
||||
|
||||
public boolean createFolder(String path);
|
||||
public boolean createFolder(String path);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,78 +27,78 @@ import com.cloud.storage.Storage.StoragePoolType;
|
|||
import com.cloud.storage.StorageLayer;
|
||||
|
||||
public class KVMStoragePoolManager {
|
||||
private StorageAdaptor _storageAdaptor;
|
||||
private KVMHAMonitor _haMonitor;
|
||||
private final Map<String, Object> _storagePools = new ConcurrentHashMap<String, Object>();
|
||||
private StorageAdaptor _storageAdaptor;
|
||||
private KVMHAMonitor _haMonitor;
|
||||
private final Map<String, Object> _storagePools = new ConcurrentHashMap<String, Object>();
|
||||
|
||||
private void addStoragePool(String uuid) {
|
||||
synchronized (_storagePools) {
|
||||
if (!_storagePools.containsKey(uuid)) {
|
||||
_storagePools.put(uuid, new Object());
|
||||
}
|
||||
}
|
||||
}
|
||||
private void addStoragePool(String uuid) {
|
||||
synchronized (_storagePools) {
|
||||
if (!_storagePools.containsKey(uuid)) {
|
||||
_storagePools.put(uuid, new Object());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public KVMStoragePoolManager(StorageLayer storagelayer, KVMHAMonitor monitor) {
|
||||
this._storageAdaptor = new LibvirtStorageAdaptor(storagelayer);
|
||||
this._haMonitor = monitor;
|
||||
}
|
||||
public KVMStoragePoolManager(StorageLayer storagelayer, KVMHAMonitor monitor) {
|
||||
this._storageAdaptor = new LibvirtStorageAdaptor(storagelayer);
|
||||
this._haMonitor = monitor;
|
||||
}
|
||||
|
||||
public KVMStoragePool getStoragePool(String uuid) {
|
||||
return this._storageAdaptor.getStoragePool(uuid);
|
||||
}
|
||||
public KVMStoragePool getStoragePool(String uuid) {
|
||||
return this._storageAdaptor.getStoragePool(uuid);
|
||||
}
|
||||
|
||||
public KVMStoragePool getStoragePoolByURI(String uri) {
|
||||
return this._storageAdaptor.getStoragePoolByUri(uri);
|
||||
}
|
||||
public KVMStoragePool getStoragePoolByURI(String uri) {
|
||||
return this._storageAdaptor.getStoragePoolByUri(uri);
|
||||
}
|
||||
|
||||
public KVMStoragePool createStoragePool(String name, String host,
|
||||
String path, StoragePoolType type) {
|
||||
KVMStoragePool pool = this._storageAdaptor.createStoragePool(name,
|
||||
host, path, type);
|
||||
if (type == StoragePoolType.NetworkFilesystem) {
|
||||
KVMHABase.NfsStoragePool nfspool = new KVMHABase.NfsStoragePool(
|
||||
pool.getUuid(), host, path, pool.getLocalPath(),
|
||||
PoolType.PrimaryStorage);
|
||||
_haMonitor.addStoragePool(nfspool);
|
||||
}
|
||||
addStoragePool(pool.getUuid());
|
||||
return pool;
|
||||
}
|
||||
public KVMStoragePool createStoragePool(String name, String host,
|
||||
String path, StoragePoolType type) {
|
||||
KVMStoragePool pool = this._storageAdaptor.createStoragePool(name,
|
||||
host, path, type);
|
||||
if (type == StoragePoolType.NetworkFilesystem) {
|
||||
KVMHABase.NfsStoragePool nfspool = new KVMHABase.NfsStoragePool(
|
||||
pool.getUuid(), host, path, pool.getLocalPath(),
|
||||
PoolType.PrimaryStorage);
|
||||
_haMonitor.addStoragePool(nfspool);
|
||||
}
|
||||
addStoragePool(pool.getUuid());
|
||||
return pool;
|
||||
}
|
||||
|
||||
public boolean deleteStoragePool(String uuid) {
|
||||
_haMonitor.removeStoragePool(uuid);
|
||||
this._storageAdaptor.deleteStoragePool(uuid);
|
||||
_storagePools.remove(uuid);
|
||||
return true;
|
||||
}
|
||||
public boolean deleteStoragePool(String uuid) {
|
||||
_haMonitor.removeStoragePool(uuid);
|
||||
this._storageAdaptor.deleteStoragePool(uuid);
|
||||
_storagePools.remove(uuid);
|
||||
return true;
|
||||
}
|
||||
|
||||
public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,
|
||||
String name, KVMStoragePool destPool) {
|
||||
return this._storageAdaptor.createDiskFromTemplate(template, name,
|
||||
KVMPhysicalDisk.PhysicalDiskFormat.QCOW2,
|
||||
template.getSize(), destPool);
|
||||
}
|
||||
public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,
|
||||
String name, KVMStoragePool destPool) {
|
||||
return this._storageAdaptor.createDiskFromTemplate(template, name,
|
||||
KVMPhysicalDisk.PhysicalDiskFormat.QCOW2,
|
||||
template.getSize(), destPool);
|
||||
}
|
||||
|
||||
public KVMPhysicalDisk createTemplateFromDisk(KVMPhysicalDisk disk,
|
||||
String name, PhysicalDiskFormat format, long size,
|
||||
KVMStoragePool destPool) {
|
||||
return this._storageAdaptor.createTemplateFromDisk(disk, name, format,
|
||||
size, destPool);
|
||||
}
|
||||
public KVMPhysicalDisk createTemplateFromDisk(KVMPhysicalDisk disk,
|
||||
String name, PhysicalDiskFormat format, long size,
|
||||
KVMStoragePool destPool) {
|
||||
return this._storageAdaptor.createTemplateFromDisk(disk, name, format,
|
||||
size, destPool);
|
||||
}
|
||||
|
||||
public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name,
|
||||
KVMStoragePool destPool) {
|
||||
return this._storageAdaptor.copyPhysicalDisk(disk, name, destPool);
|
||||
}
|
||||
public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name,
|
||||
KVMStoragePool destPool) {
|
||||
return this._storageAdaptor.copyPhysicalDisk(disk, name, destPool);
|
||||
}
|
||||
|
||||
public KVMPhysicalDisk createDiskFromSnapshot(KVMPhysicalDisk snapshot,
|
||||
String snapshotName, String name, KVMStoragePool destPool) {
|
||||
return this._storageAdaptor.createDiskFromSnapshot(snapshot,
|
||||
snapshotName, name, destPool);
|
||||
}
|
||||
public KVMPhysicalDisk createDiskFromSnapshot(KVMPhysicalDisk snapshot,
|
||||
String snapshotName, String name, KVMStoragePool destPool) {
|
||||
return this._storageAdaptor.createDiskFromSnapshot(snapshot,
|
||||
snapshotName, name, destPool);
|
||||
}
|
||||
|
||||
public KVMPhysicalDisk getPhysicalDiskFromUrl(String url) {
|
||||
return this._storageAdaptor.getPhysicalDiskFromURI(url);
|
||||
}
|
||||
public KVMPhysicalDisk getPhysicalDiskFromUrl(String url) {
|
||||
return this._storageAdaptor.getPhysicalDiskFromURI(url);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -24,135 +24,135 @@ import com.cloud.agent.storage.KVMPhysicalDisk.PhysicalDiskFormat;
|
|||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
|
||||
public class LibvirtStoragePool implements KVMStoragePool {
|
||||
protected String uuid;
|
||||
protected String uri;
|
||||
protected long capacity;
|
||||
protected long used;
|
||||
protected String name;
|
||||
protected String localPath;
|
||||
protected PhysicalDiskFormat defaultFormat;
|
||||
protected StoragePoolType type;
|
||||
protected StorageAdaptor _storageAdaptor;
|
||||
protected StoragePool _pool;
|
||||
protected String uuid;
|
||||
protected String uri;
|
||||
protected long capacity;
|
||||
protected long used;
|
||||
protected String name;
|
||||
protected String localPath;
|
||||
protected PhysicalDiskFormat defaultFormat;
|
||||
protected StoragePoolType type;
|
||||
protected StorageAdaptor _storageAdaptor;
|
||||
protected StoragePool _pool;
|
||||
|
||||
public LibvirtStoragePool(String uuid, String name, StoragePoolType type,
|
||||
StorageAdaptor adaptor, StoragePool pool) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this._storageAdaptor = adaptor;
|
||||
this.capacity = 0;
|
||||
this.used = 0;
|
||||
this._pool = pool;
|
||||
public LibvirtStoragePool(String uuid, String name, StoragePoolType type,
|
||||
StorageAdaptor adaptor, StoragePool pool) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this._storageAdaptor = adaptor;
|
||||
this.capacity = 0;
|
||||
this.used = 0;
|
||||
this._pool = pool;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void setCapacity(long capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
public void setCapacity(long capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCapacity() {
|
||||
return this.capacity;
|
||||
}
|
||||
@Override
|
||||
public long getCapacity() {
|
||||
return this.capacity;
|
||||
}
|
||||
|
||||
public void setUsed(long used) {
|
||||
this.used = used;
|
||||
}
|
||||
public void setUsed(long used) {
|
||||
this.used = used;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUsed() {
|
||||
return this.used;
|
||||
}
|
||||
@Override
|
||||
public long getUsed() {
|
||||
return this.used;
|
||||
}
|
||||
|
||||
public StoragePoolType getStoragePoolType() {
|
||||
return this.type;
|
||||
}
|
||||
public StoragePoolType getStoragePoolType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
public String getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public String uri() {
|
||||
return this.uri;
|
||||
}
|
||||
public String uri() {
|
||||
return this.uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PhysicalDiskFormat getDefaultFormat() {
|
||||
return PhysicalDiskFormat.QCOW2;
|
||||
}
|
||||
@Override
|
||||
public PhysicalDiskFormat getDefaultFormat() {
|
||||
return PhysicalDiskFormat.QCOW2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KVMPhysicalDisk createPhysicalDisk(String name,
|
||||
PhysicalDiskFormat format, long size) {
|
||||
return this._storageAdaptor
|
||||
.createPhysicalDisk(name, this, format, size);
|
||||
}
|
||||
@Override
|
||||
public KVMPhysicalDisk createPhysicalDisk(String name,
|
||||
PhysicalDiskFormat format, long size) {
|
||||
return this._storageAdaptor
|
||||
.createPhysicalDisk(name, this, format, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KVMPhysicalDisk createPhysicalDisk(String name, long size) {
|
||||
return this._storageAdaptor.createPhysicalDisk(name, this,
|
||||
this.getDefaultFormat(), size);
|
||||
}
|
||||
@Override
|
||||
public KVMPhysicalDisk createPhysicalDisk(String name, long size) {
|
||||
return this._storageAdaptor.createPhysicalDisk(name, this,
|
||||
this.getDefaultFormat(), size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KVMPhysicalDisk getPhysicalDisk(String volumeUuid) {
|
||||
return this._storageAdaptor.getPhysicalDisk(volumeUuid, this);
|
||||
}
|
||||
@Override
|
||||
public KVMPhysicalDisk getPhysicalDisk(String volumeUuid) {
|
||||
return this._storageAdaptor.getPhysicalDisk(volumeUuid, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletePhysicalDisk(String uuid) {
|
||||
return this._storageAdaptor.deletePhysicalDisk(uuid, this);
|
||||
}
|
||||
@Override
|
||||
public boolean deletePhysicalDisk(String uuid) {
|
||||
return this._storageAdaptor.deletePhysicalDisk(uuid, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<KVMPhysicalDisk> listPhysicalDisks() {
|
||||
return this._storageAdaptor.listPhysicalDisks(this.uuid, this);
|
||||
}
|
||||
@Override
|
||||
public List<KVMPhysicalDisk> listPhysicalDisks() {
|
||||
return this._storageAdaptor.listPhysicalDisks(this.uuid, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean refresh() {
|
||||
return this._storageAdaptor.refresh(this);
|
||||
}
|
||||
@Override
|
||||
public boolean refresh() {
|
||||
return this._storageAdaptor.refresh(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExternalSnapshot() {
|
||||
if (this.type == StoragePoolType.Filesystem) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isExternalSnapshot() {
|
||||
if (this.type == StoragePoolType.Filesystem) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalPath() {
|
||||
return this.localPath;
|
||||
}
|
||||
@Override
|
||||
public String getLocalPath() {
|
||||
return this.localPath;
|
||||
}
|
||||
|
||||
public void setLocalPath(String localPath) {
|
||||
this.localPath = localPath;
|
||||
}
|
||||
public void setLocalPath(String localPath) {
|
||||
this.localPath = localPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StoragePoolType getType() {
|
||||
return this.type;
|
||||
}
|
||||
@Override
|
||||
public StoragePoolType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public StoragePool getPool() {
|
||||
return this._pool;
|
||||
}
|
||||
public StoragePool getPool() {
|
||||
return this._pool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete() {
|
||||
return this._storageAdaptor.deleteStoragePool(this);
|
||||
}
|
||||
@Override
|
||||
public boolean delete() {
|
||||
return this._storageAdaptor.deleteStoragePool(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createFolder(String path) {
|
||||
return this._storageAdaptor.createFolder(this.uuid, path);
|
||||
}
|
||||
@Override
|
||||
public boolean createFolder(String path) {
|
||||
return this._storageAdaptor.createFolder(this.uuid, path);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,46 +25,46 @@ import com.cloud.storage.Storage.StoragePoolType;
|
|||
|
||||
public interface StorageAdaptor {
|
||||
|
||||
public KVMStoragePool getStoragePool(String uuid);
|
||||
public KVMStoragePool getStoragePool(String uuid);
|
||||
|
||||
public KVMPhysicalDisk getPhysicalDisk(String volumeUuid,
|
||||
KVMStoragePool pool);
|
||||
public KVMPhysicalDisk getPhysicalDisk(String volumeUuid,
|
||||
KVMStoragePool pool);
|
||||
|
||||
public KVMStoragePool createStoragePool(String name, String host,
|
||||
String path, StoragePoolType type);
|
||||
public KVMStoragePool createStoragePool(String name, String host,
|
||||
String path, StoragePoolType type);
|
||||
|
||||
public boolean deleteStoragePool(String uuid);
|
||||
public boolean deleteStoragePool(String uuid);
|
||||
|
||||
public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool,
|
||||
PhysicalDiskFormat format, long size);
|
||||
public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool,
|
||||
PhysicalDiskFormat format, long size);
|
||||
|
||||
public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool);
|
||||
public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool);
|
||||
|
||||
public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,
|
||||
String name, PhysicalDiskFormat format, long size,
|
||||
KVMStoragePool destPool);
|
||||
public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,
|
||||
String name, PhysicalDiskFormat format, long size,
|
||||
KVMStoragePool destPool);
|
||||
|
||||
public KVMPhysicalDisk createTemplateFromDisk(KVMPhysicalDisk disk,
|
||||
String name, PhysicalDiskFormat format, long size,
|
||||
KVMStoragePool destPool);
|
||||
public KVMPhysicalDisk createTemplateFromDisk(KVMPhysicalDisk disk,
|
||||
String name, PhysicalDiskFormat format, long size,
|
||||
KVMStoragePool destPool);
|
||||
|
||||
public List<KVMPhysicalDisk> listPhysicalDisks(String storagePoolUuid,
|
||||
KVMStoragePool pool);
|
||||
public List<KVMPhysicalDisk> listPhysicalDisks(String storagePoolUuid,
|
||||
KVMStoragePool pool);
|
||||
|
||||
public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name,
|
||||
KVMStoragePool destPools);
|
||||
public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name,
|
||||
KVMStoragePool destPools);
|
||||
|
||||
public KVMPhysicalDisk createDiskFromSnapshot(KVMPhysicalDisk snapshot,
|
||||
String snapshotName, String name, KVMStoragePool destPool);
|
||||
public KVMPhysicalDisk createDiskFromSnapshot(KVMPhysicalDisk snapshot,
|
||||
String snapshotName, String name, KVMStoragePool destPool);
|
||||
|
||||
public KVMStoragePool getStoragePoolByUri(String uri);
|
||||
public KVMStoragePool getStoragePoolByUri(String uri);
|
||||
|
||||
public KVMPhysicalDisk getPhysicalDiskFromURI(String uri);
|
||||
public KVMPhysicalDisk getPhysicalDiskFromURI(String uri);
|
||||
|
||||
public boolean refresh(KVMStoragePool pool);
|
||||
public boolean refresh(KVMStoragePool pool);
|
||||
|
||||
public boolean deleteStoragePool(KVMStoragePool pool);
|
||||
public boolean deleteStoragePool(KVMStoragePool pool);
|
||||
|
||||
public boolean createFolder(String uuid, String path);
|
||||
public boolean createFolder(String uuid, String path);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,305 +66,305 @@ import com.cloud.utils.script.Script;
|
|||
*/
|
||||
@Local(value = { VmDataServer.class })
|
||||
public class JettyVmDataServer implements VmDataServer {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(JettyVmDataServer.class);
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(JettyVmDataServer.class);
|
||||
|
||||
public static final String USER_DATA = "user-data";
|
||||
public static final String META_DATA = "meta-data";
|
||||
protected String _vmDataDir;
|
||||
protected Server _jetty;
|
||||
protected String _hostIp;
|
||||
protected Map<String, String> _ipVmMap = new HashMap<String, String>();
|
||||
protected StorageLayer _fs = new JavaStorageLayer();
|
||||
public static final String USER_DATA = "user-data";
|
||||
public static final String META_DATA = "meta-data";
|
||||
protected String _vmDataDir;
|
||||
protected Server _jetty;
|
||||
protected String _hostIp;
|
||||
protected Map<String, String> _ipVmMap = new HashMap<String, String>();
|
||||
protected StorageLayer _fs = new JavaStorageLayer();
|
||||
|
||||
public class VmDataServlet extends HttpServlet {
|
||||
public class VmDataServlet extends HttpServlet {
|
||||
|
||||
private static final long serialVersionUID = -1640031398971742349L;
|
||||
private static final long serialVersionUID = -1640031398971742349L;
|
||||
|
||||
JettyVmDataServer _vmDataServer;
|
||||
String _dataType; // userdata or meta-data
|
||||
JettyVmDataServer _vmDataServer;
|
||||
String _dataType; // userdata or meta-data
|
||||
|
||||
public VmDataServlet(JettyVmDataServer dataServer, String dataType) {
|
||||
this._vmDataServer = dataServer;
|
||||
this._dataType = dataType;
|
||||
}
|
||||
public VmDataServlet(JettyVmDataServer dataServer, String dataType) {
|
||||
this._vmDataServer = dataServer;
|
||||
this._dataType = dataType;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
int port = req.getServerPort();
|
||||
if (port != 80 && port != 8000) {
|
||||
resp.sendError(HttpServletResponse.SC_NOT_FOUND,
|
||||
"Request not understood");
|
||||
return;
|
||||
}
|
||||
if (_dataType.equalsIgnoreCase(USER_DATA)) {
|
||||
handleUserData(req, resp);
|
||||
} else if (_dataType.equalsIgnoreCase(META_DATA)) {
|
||||
handleMetaData(req, resp);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
int port = req.getServerPort();
|
||||
if (port != 80 && port != 8000) {
|
||||
resp.sendError(HttpServletResponse.SC_NOT_FOUND,
|
||||
"Request not understood");
|
||||
return;
|
||||
}
|
||||
if (_dataType.equalsIgnoreCase(USER_DATA)) {
|
||||
handleUserData(req, resp);
|
||||
} else if (_dataType.equalsIgnoreCase(META_DATA)) {
|
||||
handleMetaData(req, resp);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleUserData(HttpServletRequest req,
|
||||
HttpServletResponse resp) throws ServletException, IOException {
|
||||
String metadataItem = req.getPathInfo();
|
||||
String requester = req.getRemoteAddr();
|
||||
resp.setContentType("text/html");
|
||||
resp.setStatus(HttpServletResponse.SC_OK);
|
||||
String data = null;
|
||||
if (metadataItem != null) {
|
||||
String[] path = metadataItem.split("/");
|
||||
if (path.length > 1) {
|
||||
metadataItem = path[1];
|
||||
}
|
||||
}
|
||||
protected void handleUserData(HttpServletRequest req,
|
||||
HttpServletResponse resp) throws ServletException, IOException {
|
||||
String metadataItem = req.getPathInfo();
|
||||
String requester = req.getRemoteAddr();
|
||||
resp.setContentType("text/html");
|
||||
resp.setStatus(HttpServletResponse.SC_OK);
|
||||
String data = null;
|
||||
if (metadataItem != null) {
|
||||
String[] path = metadataItem.split("/");
|
||||
if (path.length > 1) {
|
||||
metadataItem = path[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (metadataItem != null)
|
||||
data = _vmDataServer.getVmDataItem(requester, metadataItem);
|
||||
if (metadataItem != null)
|
||||
data = _vmDataServer.getVmDataItem(requester, metadataItem);
|
||||
|
||||
if (data != null) {
|
||||
resp.getWriter().print(data);
|
||||
} else {
|
||||
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
resp.sendError(HttpServletResponse.SC_NOT_FOUND,
|
||||
"Request not found");
|
||||
}
|
||||
if (data != null) {
|
||||
resp.getWriter().print(data);
|
||||
} else {
|
||||
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
resp.sendError(HttpServletResponse.SC_NOT_FOUND,
|
||||
"Request not found");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleMetaData(HttpServletRequest req,
|
||||
HttpServletResponse resp) throws ServletException, IOException {
|
||||
String metadataItem = req.getPathInfo();
|
||||
String requester = req.getRemoteAddr();
|
||||
resp.setContentType("text/html");
|
||||
resp.setStatus(HttpServletResponse.SC_OK);
|
||||
String metaData = _vmDataServer.getVmDataItem(requester,
|
||||
metadataItem);
|
||||
if (metaData != null) {
|
||||
resp.getWriter().print(
|
||||
_vmDataServer.getVmDataItem(requester, metadataItem));
|
||||
} else {
|
||||
resp.sendError(HttpServletResponse.SC_NOT_FOUND,
|
||||
"Request not found");
|
||||
}
|
||||
}
|
||||
protected void handleMetaData(HttpServletRequest req,
|
||||
HttpServletResponse resp) throws ServletException, IOException {
|
||||
String metadataItem = req.getPathInfo();
|
||||
String requester = req.getRemoteAddr();
|
||||
resp.setContentType("text/html");
|
||||
resp.setStatus(HttpServletResponse.SC_OK);
|
||||
String metaData = _vmDataServer.getVmDataItem(requester,
|
||||
metadataItem);
|
||||
if (metaData != null) {
|
||||
resp.getWriter().print(
|
||||
_vmDataServer.getVmDataItem(requester, metadataItem));
|
||||
} else {
|
||||
resp.sendError(HttpServletResponse.SC_NOT_FOUND,
|
||||
"Request not found");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
boolean success = true;
|
||||
try {
|
||||
int vmDataPort = 80;
|
||||
int fileservingPort = 8000;
|
||||
_vmDataDir = (String) params.get("vm.data.dir");
|
||||
String port = (String) params.get("vm.data.port");
|
||||
if (port != null) {
|
||||
vmDataPort = Integer.parseInt(port);
|
||||
}
|
||||
port = (String) params.get("file.server.port");
|
||||
if (port != null) {
|
||||
fileservingPort = Integer.parseInt(port);
|
||||
}
|
||||
_hostIp = (String) params.get("host.ip");
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
boolean success = true;
|
||||
try {
|
||||
int vmDataPort = 80;
|
||||
int fileservingPort = 8000;
|
||||
_vmDataDir = (String) params.get("vm.data.dir");
|
||||
String port = (String) params.get("vm.data.port");
|
||||
if (port != null) {
|
||||
vmDataPort = Integer.parseInt(port);
|
||||
}
|
||||
port = (String) params.get("file.server.port");
|
||||
if (port != null) {
|
||||
fileservingPort = Integer.parseInt(port);
|
||||
}
|
||||
_hostIp = (String) params.get("host.ip");
|
||||
|
||||
if (_vmDataDir == null) {
|
||||
_vmDataDir = "/var/www/html";
|
||||
}
|
||||
success = _fs.mkdirs(_vmDataDir);
|
||||
success = success && buildIpVmMap();
|
||||
if (success) {
|
||||
setupJetty(vmDataPort, fileservingPort);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Failed to configure jetty", e);
|
||||
throw new ConfigurationException("Failed to configure jetty!!");
|
||||
}
|
||||
return success;
|
||||
}
|
||||
if (_vmDataDir == null) {
|
||||
_vmDataDir = "/var/www/html";
|
||||
}
|
||||
success = _fs.mkdirs(_vmDataDir);
|
||||
success = success && buildIpVmMap();
|
||||
if (success) {
|
||||
setupJetty(vmDataPort, fileservingPort);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Failed to configure jetty", e);
|
||||
throw new ConfigurationException("Failed to configure jetty!!");
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
protected boolean buildIpVmMap() {
|
||||
String[] dirs = _fs.listFiles(_vmDataDir);
|
||||
for (String dir : dirs) {
|
||||
String[] path = dir.split("/");
|
||||
String vm = path[path.length - 1];
|
||||
if (vm.startsWith("i-")) {
|
||||
String[] dataFiles = _fs.listFiles(dir);
|
||||
for (String dfile : dataFiles) {
|
||||
String path2[] = dfile.split("/");
|
||||
String ipv4file = path2[path2.length - 1];
|
||||
if (ipv4file.equalsIgnoreCase("local-ipv4")) {
|
||||
try {
|
||||
BufferedReader input = new BufferedReader(
|
||||
new FileReader(dfile));
|
||||
String line = null;
|
||||
while ((line = input.readLine()) != null) {
|
||||
if (NetUtils.isValidIp(line)) {
|
||||
_ipVmMap.put(line, vm);
|
||||
s_logger.info("Found ip " + line
|
||||
+ " for vm " + vm);
|
||||
} else {
|
||||
s_logger.info("Invalid ip " + line
|
||||
+ " for vm " + vm);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
s_logger.warn("Failed to find file " + dfile);
|
||||
} catch (IOException e) {
|
||||
s_logger.warn("Failed to get ip address of " + vm);
|
||||
}
|
||||
protected boolean buildIpVmMap() {
|
||||
String[] dirs = _fs.listFiles(_vmDataDir);
|
||||
for (String dir : dirs) {
|
||||
String[] path = dir.split("/");
|
||||
String vm = path[path.length - 1];
|
||||
if (vm.startsWith("i-")) {
|
||||
String[] dataFiles = _fs.listFiles(dir);
|
||||
for (String dfile : dataFiles) {
|
||||
String path2[] = dfile.split("/");
|
||||
String ipv4file = path2[path2.length - 1];
|
||||
if (ipv4file.equalsIgnoreCase("local-ipv4")) {
|
||||
try {
|
||||
BufferedReader input = new BufferedReader(
|
||||
new FileReader(dfile));
|
||||
String line = null;
|
||||
while ((line = input.readLine()) != null) {
|
||||
if (NetUtils.isValidIp(line)) {
|
||||
_ipVmMap.put(line, vm);
|
||||
s_logger.info("Found ip " + line
|
||||
+ " for vm " + vm);
|
||||
} else {
|
||||
s_logger.info("Invalid ip " + line
|
||||
+ " for vm " + vm);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
s_logger.warn("Failed to find file " + dfile);
|
||||
} catch (IOException e) {
|
||||
s_logger.warn("Failed to get ip address of " + vm);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getVmDataItem(String requester, String dataItem) {
|
||||
String vmName = _ipVmMap.get(requester);
|
||||
if (vmName == null) {
|
||||
return null;
|
||||
}
|
||||
String vmDataFile = _vmDataDir + File.separator + vmName
|
||||
+ File.separator + dataItem;
|
||||
try {
|
||||
BufferedReader input = new BufferedReader(
|
||||
new FileReader(vmDataFile));
|
||||
StringBuilder result = new StringBuilder();
|
||||
String line = null;
|
||||
while ((line = input.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
input.close();
|
||||
return result.toString();
|
||||
} catch (FileNotFoundException e) {
|
||||
s_logger.warn("Failed to find requested file " + vmDataFile);
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
s_logger.warn("Failed to read requested file " + vmDataFile);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public String getVmDataItem(String requester, String dataItem) {
|
||||
String vmName = _ipVmMap.get(requester);
|
||||
if (vmName == null) {
|
||||
return null;
|
||||
}
|
||||
String vmDataFile = _vmDataDir + File.separator + vmName
|
||||
+ File.separator + dataItem;
|
||||
try {
|
||||
BufferedReader input = new BufferedReader(
|
||||
new FileReader(vmDataFile));
|
||||
StringBuilder result = new StringBuilder();
|
||||
String line = null;
|
||||
while ((line = input.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
input.close();
|
||||
return result.toString();
|
||||
} catch (FileNotFoundException e) {
|
||||
s_logger.warn("Failed to find requested file " + vmDataFile);
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
s_logger.warn("Failed to read requested file " + vmDataFile);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void setupJetty(int vmDataPort, int fileservingPort)
|
||||
throws Exception {
|
||||
_jetty = new Server();
|
||||
private void setupJetty(int vmDataPort, int fileservingPort)
|
||||
throws Exception {
|
||||
_jetty = new Server();
|
||||
|
||||
SelectChannelConnector connector0 = new SelectChannelConnector();
|
||||
connector0.setHost(_hostIp);
|
||||
connector0.setPort(fileservingPort);
|
||||
connector0.setMaxIdleTime(30000);
|
||||
connector0.setRequestBufferSize(8192);
|
||||
SelectChannelConnector connector0 = new SelectChannelConnector();
|
||||
connector0.setHost(_hostIp);
|
||||
connector0.setPort(fileservingPort);
|
||||
connector0.setMaxIdleTime(30000);
|
||||
connector0.setRequestBufferSize(8192);
|
||||
|
||||
SelectChannelConnector connector1 = new SelectChannelConnector();
|
||||
connector1.setHost(_hostIp);
|
||||
connector1.setPort(vmDataPort);
|
||||
connector1.setThreadPool(new QueuedThreadPool(5));
|
||||
connector1.setMaxIdleTime(30000);
|
||||
connector1.setRequestBufferSize(8192);
|
||||
SelectChannelConnector connector1 = new SelectChannelConnector();
|
||||
connector1.setHost(_hostIp);
|
||||
connector1.setPort(vmDataPort);
|
||||
connector1.setThreadPool(new QueuedThreadPool(5));
|
||||
connector1.setMaxIdleTime(30000);
|
||||
connector1.setRequestBufferSize(8192);
|
||||
|
||||
_jetty.setConnectors(new Connector[] { connector0, connector1 });
|
||||
_jetty.setConnectors(new Connector[] { connector0, connector1 });
|
||||
|
||||
Context root = new Context(_jetty, "/latest", Context.SESSIONS);
|
||||
root.setResourceBase(_vmDataDir);
|
||||
root.addServlet(new ServletHolder(new VmDataServlet(this, USER_DATA)),
|
||||
"/*");
|
||||
Context root = new Context(_jetty, "/latest", Context.SESSIONS);
|
||||
root.setResourceBase(_vmDataDir);
|
||||
root.addServlet(new ServletHolder(new VmDataServlet(this, USER_DATA)),
|
||||
"/*");
|
||||
|
||||
ResourceHandler resource_handler = new ResourceHandler();
|
||||
resource_handler.setResourceBase("/var/lib/images/");
|
||||
ResourceHandler resource_handler = new ResourceHandler();
|
||||
resource_handler.setResourceBase("/var/lib/images/");
|
||||
|
||||
HandlerList handlers = new HandlerList();
|
||||
handlers.setHandlers(new Handler[] { root, resource_handler,
|
||||
new DefaultHandler() });
|
||||
_jetty.setHandler(handlers);
|
||||
HandlerList handlers = new HandlerList();
|
||||
handlers.setHandlers(new Handler[] { root, resource_handler,
|
||||
new DefaultHandler() });
|
||||
_jetty.setHandler(handlers);
|
||||
|
||||
_jetty.start();
|
||||
// _jetty.join();
|
||||
}
|
||||
_jetty.start();
|
||||
// _jetty.join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean start() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "JettyVmDataServer";
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "JettyVmDataServer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer handleVmDataCommand(VmDataCommand cmd) {
|
||||
String vmDataDir = _vmDataDir + File.separator + cmd.getVmName();
|
||||
@Override
|
||||
public Answer handleVmDataCommand(VmDataCommand cmd) {
|
||||
String vmDataDir = _vmDataDir + File.separator + cmd.getVmName();
|
||||
|
||||
Script.runSimpleBashScript("rm -rf " + vmDataDir);
|
||||
_fs.mkdirs(vmDataDir);
|
||||
Script.runSimpleBashScript("rm -rf " + vmDataDir);
|
||||
_fs.mkdirs(vmDataDir);
|
||||
|
||||
for (String[] item : cmd.getVmData()) {
|
||||
try {
|
||||
_fs.create(vmDataDir, item[1]);
|
||||
String vmDataFile = vmDataDir + File.separator + item[1];
|
||||
byte[] data;
|
||||
if (item[2] != null) {
|
||||
if (item[1].equals("user-data")) {
|
||||
data = Base64.decodeBase64(item[2]);
|
||||
} else {
|
||||
data = item[2].getBytes();
|
||||
}
|
||||
if (data != null && data.length > 0) {
|
||||
FileOutputStream writer = new FileOutputStream(
|
||||
vmDataFile);
|
||||
writer.write(data);
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
s_logger.warn("Failed to write vm data item " + item[1], e);
|
||||
return new Answer(cmd, false, "Failed to write vm data item "
|
||||
+ item[1]);
|
||||
}
|
||||
}
|
||||
return new Answer(cmd);
|
||||
for (String[] item : cmd.getVmData()) {
|
||||
try {
|
||||
_fs.create(vmDataDir, item[1]);
|
||||
String vmDataFile = vmDataDir + File.separator + item[1];
|
||||
byte[] data;
|
||||
if (item[2] != null) {
|
||||
if (item[1].equals("user-data")) {
|
||||
data = Base64.decodeBase64(item[2]);
|
||||
} else {
|
||||
data = item[2].getBytes();
|
||||
}
|
||||
if (data != null && data.length > 0) {
|
||||
FileOutputStream writer = new FileOutputStream(
|
||||
vmDataFile);
|
||||
writer.write(data);
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
s_logger.warn("Failed to write vm data item " + item[1], e);
|
||||
return new Answer(cmd, false, "Failed to write vm data item "
|
||||
+ item[1]);
|
||||
}
|
||||
}
|
||||
return new Answer(cmd);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleVmStarted(VirtualMachineTO vm) {
|
||||
for (NicTO nic : vm.getNics()) {
|
||||
if (nic.getType() == TrafficType.Guest) {
|
||||
if (nic.getIp() != null) {
|
||||
String ipv4File = _vmDataDir + File.separator
|
||||
+ vm.getName() + File.separator + "local-ipv4";
|
||||
try {
|
||||
_fs.create(_vmDataDir + File.separator + vm.getName(),
|
||||
"local-ipv4");
|
||||
BufferedWriter writer = new BufferedWriter(
|
||||
new FileWriter(ipv4File));
|
||||
writer.write(nic.getIp());
|
||||
_ipVmMap.put(nic.getIp(), vm.getName());
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
s_logger.warn(
|
||||
"Failed to create or write to local-ipv4 file "
|
||||
+ ipv4File, e);
|
||||
}
|
||||
@Override
|
||||
public void handleVmStarted(VirtualMachineTO vm) {
|
||||
for (NicTO nic : vm.getNics()) {
|
||||
if (nic.getType() == TrafficType.Guest) {
|
||||
if (nic.getIp() != null) {
|
||||
String ipv4File = _vmDataDir + File.separator
|
||||
+ vm.getName() + File.separator + "local-ipv4";
|
||||
try {
|
||||
_fs.create(_vmDataDir + File.separator + vm.getName(),
|
||||
"local-ipv4");
|
||||
BufferedWriter writer = new BufferedWriter(
|
||||
new FileWriter(ipv4File));
|
||||
writer.write(nic.getIp());
|
||||
_ipVmMap.put(nic.getIp(), vm.getName());
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
s_logger.warn(
|
||||
"Failed to create or write to local-ipv4 file "
|
||||
+ ipv4File, e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleVmStopped(String vmName) {
|
||||
String vmDataDir = _vmDataDir + File.separator + vmName;
|
||||
Script.runSimpleBashScript("rm -rf " + vmDataDir);
|
||||
}
|
||||
@Override
|
||||
public void handleVmStopped(String vmName) {
|
||||
String vmDataDir = _vmDataDir + File.separator + vmName;
|
||||
Script.runSimpleBashScript("rm -rf " + vmDataDir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ import com.cloud.utils.component.Manager;
|
|||
*/
|
||||
public interface VmDataServer extends Manager {
|
||||
|
||||
public Answer handleVmDataCommand(VmDataCommand cmd);
|
||||
public Answer handleVmDataCommand(VmDataCommand cmd);
|
||||
|
||||
public void handleVmStarted(VirtualMachineTO vm);
|
||||
public void handleVmStarted(VirtualMachineTO vm);
|
||||
|
||||
public void handleVmStopped(String vmName);
|
||||
public void handleVmStopped(String vmName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,12 +31,12 @@ public class TestAgentShell extends Log4jEnabledTestCase {
|
|||
File file = null;
|
||||
try {
|
||||
file = File.createTempFile("wget", ".html");
|
||||
AgentShell.wget("http://www.google.com/", file);
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("file saved to " + file.getAbsolutePath());
|
||||
}
|
||||
|
||||
AgentShell.wget("http://www.google.com/", file);
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("file saved to " + file.getAbsolutePath());
|
||||
}
|
||||
|
||||
} catch (final IOException e) {
|
||||
s_logger.warn("Exception while downloading agent update package, ", e);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue