mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge branch 'master' into vpc
Conflicts: api/src/com/cloud/api/ApiConstants.java api/src/com/cloud/api/BaseCmd.java api/src/com/cloud/api/ResponseGenerator.java api/src/com/cloud/api/commands/ListNetworksCmd.java api/src/com/cloud/api/response/NetworkResponse.java api/src/com/cloud/event/EventTypes.java api/src/com/cloud/network/NetworkService.java client/tomcatconf/commands.properties.in scripts/network/domr/getDomRVersion.sh scripts/network/domr/ipassoc.sh scripts/network/domr/l2tp_vpn.sh scripts/network/domr/networkUsage.sh scripts/network/domr/router_proxy.sh server/src/com/cloud/api/ApiDBUtils.java server/src/com/cloud/api/ApiResponseHelper.java server/src/com/cloud/configuration/DefaultComponentLibrary.java server/src/com/cloud/network/NetworkManagerImpl.java server/src/com/cloud/network/dao/IPAddressDao.java server/src/com/cloud/network/dao/IPAddressDaoImpl.java setup/apidoc/gen_toc.py setup/db/create-schema.sql wscript
This commit is contained in:
commit
634cd78baa
@ -50,7 +50,9 @@ wait_for_network() {
|
||||
i=1
|
||||
while [ $i -lt 10 ]
|
||||
do
|
||||
if ip addr show cloudbr0 |grep -w inet > /dev/null 2>&1; then
|
||||
# Under Ubuntu and Debian libvirt by default creates a bridge called virbr0.
|
||||
# That's why we want more then 3 lines back from brctl, so that there is a manually created bridge
|
||||
if [ "$(brctl show|wc -l)" -gt 2 ]; then
|
||||
break
|
||||
else
|
||||
sleep 1
|
||||
@ -74,9 +76,8 @@ start() {
|
||||
log_end_msg 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#FIXME: wait for network
|
||||
wait_for_network
|
||||
|
||||
wait_for_network
|
||||
|
||||
if start-stop-daemon --start --quiet \
|
||||
--pidfile "$PIDFILE" \
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,272 +0,0 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.agent.dhcp;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Formatter;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jnetpcap.packet.JMemoryPacket;
|
||||
import org.jnetpcap.packet.JPacket;
|
||||
import org.jnetpcap.packet.PcapPacket;
|
||||
import org.jnetpcap.protocol.lan.Ethernet;
|
||||
import org.jnetpcap.protocol.lan.IEEE802dot1q;
|
||||
import org.jnetpcap.protocol.network.Ip4;
|
||||
import org.jnetpcap.protocol.tcpip.Udp;
|
||||
|
||||
import com.cloud.agent.dhcp.DhcpSnooperImpl.DHCPState;
|
||||
|
||||
public class DhcpPacketParser implements Runnable {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(DhcpPacketParser.class);
|
||||
|
||||
private enum DHCPPACKET {
|
||||
OP(0), HTYPE(1), HLEN(2), HOPS(3), XID(4), SECS(8), FLAGS(10), CIADDR(
|
||||
12), YIADDR(16), SIDADDR(20), GIADDR(24), CHADDR(28), SNAME(44), FILE(
|
||||
108), MAGIC(236), OPTIONS(240);
|
||||
int offset;
|
||||
|
||||
DHCPPACKET(int i) {
|
||||
offset = i;
|
||||
}
|
||||
|
||||
int getValue() {
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
|
||||
private enum DHCPOPTIONTYPE {
|
||||
PAD(0), MESSAGETYPE(53), REQUESTEDIP(50), END(255);
|
||||
int type;
|
||||
|
||||
DHCPOPTIONTYPE(int i) {
|
||||
type = i;
|
||||
}
|
||||
|
||||
int getValue() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
private enum DHCPMSGTYPE {
|
||||
DHCPDISCOVER(1), DHCPOFFER(2), DHCPREQUEST(3), DHCPDECLINE(4), DHCPACK(
|
||||
5), DHCPNAK(6), DHCPRELEASE(7), DHCPINFORM(8);
|
||||
int _type;
|
||||
|
||||
DHCPMSGTYPE(int type) {
|
||||
_type = type;
|
||||
}
|
||||
|
||||
int getValue() {
|
||||
return _type;
|
||||
}
|
||||
|
||||
public static DHCPMSGTYPE valueOf(int type) {
|
||||
for (DHCPMSGTYPE t : values()) {
|
||||
if (type == t.getValue()) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private class DHCPMSG {
|
||||
DHCPMSGTYPE msgType;
|
||||
byte[] caddr;
|
||||
byte[] yaddr;
|
||||
byte[] chaddr;
|
||||
byte[] requestedIP;
|
||||
|
||||
public DHCPMSG() {
|
||||
caddr = new byte[4];
|
||||
yaddr = new byte[4];
|
||||
chaddr = new byte[6];
|
||||
}
|
||||
}
|
||||
|
||||
private PcapPacket _buffer;
|
||||
private int _offset;
|
||||
private int _len;
|
||||
private DhcpSnooperImpl _manager;
|
||||
|
||||
public DhcpPacketParser(PcapPacket buffer, int offset, int len,
|
||||
DhcpSnooperImpl manager) {
|
||||
_buffer = buffer;
|
||||
_offset = offset;
|
||||
_len = len;
|
||||
_manager = manager;
|
||||
}
|
||||
|
||||
private int getPos(int pos) {
|
||||
return _offset + pos;
|
||||
}
|
||||
|
||||
private byte getByte(int offset) {
|
||||
return _buffer.getByte(getPos(offset));
|
||||
}
|
||||
|
||||
private void getByteArray(int offset, byte[] array) {
|
||||
_buffer.getByteArray(getPos(offset), array);
|
||||
}
|
||||
|
||||
private long getUInt(int offset) {
|
||||
return _buffer.getUInt(getPos(offset));
|
||||
}
|
||||
|
||||
private DHCPMSG getDhcpMsg() {
|
||||
long magic = getUInt(DHCPPACKET.MAGIC.getValue());
|
||||
if (magic != 0x63538263) {
|
||||
return null;
|
||||
}
|
||||
|
||||
DHCPMSG msg = new DHCPMSG();
|
||||
|
||||
int pos = DHCPPACKET.OPTIONS.getValue();
|
||||
while (pos <= _len) {
|
||||
int type = (int) getByte(pos++) & 0xff;
|
||||
|
||||
if (type == DHCPOPTIONTYPE.END.getValue()) {
|
||||
break;
|
||||
}
|
||||
if (type == DHCPOPTIONTYPE.PAD.getValue()) {
|
||||
continue;
|
||||
}
|
||||
int len = 0;
|
||||
if (pos <= _len) {
|
||||
len = ((int) getByte(pos++)) & 0xff;
|
||||
}
|
||||
|
||||
if (type == DHCPOPTIONTYPE.MESSAGETYPE.getValue()
|
||||
|| type == DHCPOPTIONTYPE.REQUESTEDIP.getValue()) {
|
||||
/* Read data only if needed */
|
||||
byte[] data = null;
|
||||
if ((len + pos) <= _len) {
|
||||
data = new byte[len];
|
||||
getByteArray(pos, data);
|
||||
}
|
||||
|
||||
if (type == DHCPOPTIONTYPE.MESSAGETYPE.getValue()) {
|
||||
msg.msgType = DHCPMSGTYPE.valueOf((int) data[0]);
|
||||
} else if (type == DHCPOPTIONTYPE.REQUESTEDIP.getValue()) {
|
||||
msg.requestedIP = data;
|
||||
}
|
||||
}
|
||||
|
||||
pos += len;
|
||||
}
|
||||
|
||||
if (msg.msgType == DHCPMSGTYPE.DHCPREQUEST) {
|
||||
getByteArray(DHCPPACKET.CHADDR.getValue(), msg.chaddr);
|
||||
getByteArray(DHCPPACKET.CIADDR.getValue(), msg.caddr);
|
||||
} else if (msg.msgType == DHCPMSGTYPE.DHCPACK) {
|
||||
getByteArray(DHCPPACKET.YIADDR.getValue(), msg.yaddr);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
private String formatMacAddress(byte[] mac) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
Formatter formatter = new Formatter(sb);
|
||||
for (int i = 0; i < mac.length; i++) {
|
||||
formatter.format("%02X%s", mac[i], (i < mac.length - 1) ? ":" : "");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String getDestMacAddress() {
|
||||
Ethernet ether = new Ethernet();
|
||||
if (_buffer.hasHeader(ether)) {
|
||||
byte[] destMac = ether.destination();
|
||||
return formatMacAddress(destMac);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private InetAddress getDHCPServerIP() {
|
||||
Ip4 ip = new Ip4();
|
||||
if (_buffer.hasHeader(ip)) {
|
||||
try {
|
||||
return InetAddress.getByAddress(ip.source());
|
||||
} catch (UnknownHostException e) {
|
||||
s_logger.debug("Failed to get dhcp server ip address: "
|
||||
+ e.toString());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
DHCPMSG msg = getDhcpMsg();
|
||||
|
||||
if (msg == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.msgType == DHCPMSGTYPE.DHCPACK) {
|
||||
InetAddress ip = null;
|
||||
try {
|
||||
ip = InetAddress.getByAddress(msg.yaddr);
|
||||
String macAddr = getDestMacAddress();
|
||||
_manager.setIPAddr(macAddr, ip, DHCPState.DHCPACKED,
|
||||
getDHCPServerIP());
|
||||
} catch (UnknownHostException e) {
|
||||
|
||||
}
|
||||
} else if (msg.msgType == DHCPMSGTYPE.DHCPREQUEST) {
|
||||
InetAddress ip = null;
|
||||
if (msg.requestedIP != null) {
|
||||
try {
|
||||
ip = InetAddress.getByAddress(msg.requestedIP);
|
||||
} catch (UnknownHostException e) {
|
||||
}
|
||||
}
|
||||
if (ip == null) {
|
||||
try {
|
||||
ip = InetAddress.getByAddress(msg.caddr);
|
||||
} catch (UnknownHostException e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (ip != null) {
|
||||
String macAddr = formatMacAddress(msg.chaddr);
|
||||
_manager.setIPAddr(macAddr, ip, DHCPState.DHCPREQUESTED, null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void test() {
|
||||
JPacket packet = new JMemoryPacket(
|
||||
Ethernet.ID,
|
||||
" 06fa 8800 00b3 0656 d200 0027 8100 001a 0800 4500 0156 64bf 0000 4011 f3f2 ac1a 6412 ac1a 649e 0043 0044 0001 0000 0001");
|
||||
Ethernet eth = new Ethernet();
|
||||
if (packet.hasHeader(eth)) {
|
||||
System.out.print(" ether:" + eth);
|
||||
}
|
||||
IEEE802dot1q vlan = new IEEE802dot1q();
|
||||
if (packet.hasHeader(vlan)) {
|
||||
System.out.print(" vlan: " + vlan);
|
||||
}
|
||||
|
||||
if (packet.hasHeader(Udp.ID)) {
|
||||
System.out.print("has udp");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
|
||||
}
|
||||
|
||||
@ -1,324 +0,0 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.agent.dhcp;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jnetpcap.Pcap;
|
||||
import org.jnetpcap.PcapBpfProgram;
|
||||
import org.jnetpcap.PcapIf;
|
||||
import org.jnetpcap.packet.PcapPacket;
|
||||
import org.jnetpcap.packet.PcapPacketHandler;
|
||||
import org.jnetpcap.protocol.tcpip.Udp;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
|
||||
@Local(value = { DhcpSnooper.class })
|
||||
public class DhcpSnooperImpl implements DhcpSnooper {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(DhcpSnooperImpl.class);
|
||||
|
||||
public enum DHCPState {
|
||||
DHCPACKED, DHCPREQUESTED, DHCPRESET;
|
||||
}
|
||||
|
||||
public class IPAddr {
|
||||
String _vmName;
|
||||
InetAddress _ip;
|
||||
DHCPState _state;
|
||||
|
||||
public IPAddr(InetAddress ip, DHCPState state, String vmName) {
|
||||
_ip = ip;
|
||||
_state = state;
|
||||
_vmName = vmName;
|
||||
}
|
||||
}
|
||||
|
||||
protected ExecutorService _executor;
|
||||
protected Map<String, IPAddr> _macIpMap;
|
||||
protected Map<InetAddress, String> _ipMacMap;
|
||||
private DhcpServer _server;
|
||||
protected long _timeout = 1200000;
|
||||
protected InetAddress _dhcpServerIp;
|
||||
|
||||
public DhcpSnooperImpl(String bridge, long timeout) {
|
||||
|
||||
_timeout = timeout;
|
||||
_executor = new ThreadPoolExecutor(10, 10 * 10, 1, TimeUnit.DAYS,
|
||||
new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory(
|
||||
"DhcpListener"));
|
||||
_macIpMap = new ConcurrentHashMap<String, IPAddr>();
|
||||
_ipMacMap = new ConcurrentHashMap<InetAddress, String>();
|
||||
_server = new DhcpServer(this, bridge);
|
||||
_server.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetAddress getIPAddr(String macAddr, String vmName) {
|
||||
String macAddrLowerCase = macAddr.toLowerCase();
|
||||
IPAddr addr = _macIpMap.get(macAddrLowerCase);
|
||||
if (addr == null) {
|
||||
addr = new IPAddr(null, DHCPState.DHCPRESET, vmName);
|
||||
_macIpMap.put(macAddrLowerCase, addr);
|
||||
} else {
|
||||
addr._state = DHCPState.DHCPRESET;
|
||||
}
|
||||
|
||||
synchronized (addr) {
|
||||
try {
|
||||
addr.wait(_timeout);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
if (addr._state == DHCPState.DHCPACKED) {
|
||||
addr._state = DHCPState.DHCPRESET;
|
||||
return addr._ip;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public InetAddress getDhcpServerIP() {
|
||||
return _dhcpServerIp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup(String macAddr, String vmName) {
|
||||
try {
|
||||
if (macAddr == null) {
|
||||
return;
|
||||
}
|
||||
_macIpMap.remove(macAddr);
|
||||
_ipMacMap.values().remove(macAddr);
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("Failed to cleanup: " + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, InetAddress> syncIpAddr() {
|
||||
Collection<IPAddr> ips = _macIpMap.values();
|
||||
HashMap<String, InetAddress> vmIpMap = new HashMap<String, InetAddress>();
|
||||
for (IPAddr ip : ips) {
|
||||
if (ip._state == DHCPState.DHCPACKED) {
|
||||
vmIpMap.put(ip._vmName, ip._ip);
|
||||
}
|
||||
}
|
||||
return vmIpMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeMacTable(List<Pair<String, String>> macVmNameList) {
|
||||
for (Pair<String, String> macVmname : macVmNameList) {
|
||||
IPAddr ipAdrr = new IPAddr(null, DHCPState.DHCPRESET,
|
||||
macVmname.second());
|
||||
_macIpMap.put(macVmname.first(), ipAdrr);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setIPAddr(String macAddr, InetAddress ip, DHCPState state,
|
||||
InetAddress dhcpServerIp) {
|
||||
String macAddrLowerCase = macAddr.toLowerCase();
|
||||
if (state == DHCPState.DHCPREQUESTED) {
|
||||
IPAddr ipAddr = _macIpMap.get(macAddrLowerCase);
|
||||
if (ipAddr == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
_ipMacMap.put(ip, macAddr);
|
||||
} else if (state == DHCPState.DHCPACKED) {
|
||||
_dhcpServerIp = dhcpServerIp;
|
||||
String destMac = macAddrLowerCase;
|
||||
if (macAddrLowerCase.equalsIgnoreCase("ff:ff:ff:ff:ff:ff")) {
|
||||
destMac = _ipMacMap.get(ip);
|
||||
if (destMac == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
IPAddr addr = _macIpMap.get(destMac);
|
||||
if (addr != null) {
|
||||
addr._ip = ip;
|
||||
addr._state = state;
|
||||
synchronized (addr) {
|
||||
addr.notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.cloud.agent.dhcp.DhcpSnooper#stop()
|
||||
*/
|
||||
@Override
|
||||
public boolean stop() {
|
||||
_executor.shutdown();
|
||||
_server.StopServer();
|
||||
return true;
|
||||
}
|
||||
|
||||
private class DhcpServer extends Thread {
|
||||
private DhcpSnooperImpl _manager;
|
||||
private String _bridge;
|
||||
private Pcap _pcapedDev;
|
||||
private boolean _loop;
|
||||
|
||||
public DhcpServer(DhcpSnooperImpl mgt, String bridge) {
|
||||
_manager = mgt;
|
||||
_bridge = bridge;
|
||||
_loop = true;
|
||||
}
|
||||
|
||||
public void StopServer() {
|
||||
_loop = false;
|
||||
_pcapedDev.breakloop();
|
||||
_pcapedDev.close();
|
||||
}
|
||||
|
||||
private Pcap initializePcap() {
|
||||
try {
|
||||
List<PcapIf> alldevs = new ArrayList<PcapIf>();
|
||||
StringBuilder errBuf = new StringBuilder();
|
||||
int r = Pcap.findAllDevs(alldevs, errBuf);
|
||||
if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PcapIf dev = null;
|
||||
for (PcapIf device : alldevs) {
|
||||
if (device.getName().equalsIgnoreCase(_bridge)) {
|
||||
dev = device;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (dev == null) {
|
||||
s_logger.debug("Pcap: Can't find device: " + _bridge
|
||||
+ " to listen on");
|
||||
return null;
|
||||
}
|
||||
|
||||
int snaplen = 64 * 1024;
|
||||
int flags = Pcap.MODE_PROMISCUOUS;
|
||||
int timeout = 10 * 1000;
|
||||
Pcap pcap = Pcap.openLive(dev.getName(), snaplen, flags,
|
||||
timeout, errBuf);
|
||||
if (pcap == null) {
|
||||
s_logger.debug("Pcap: Can't open " + _bridge);
|
||||
return null;
|
||||
}
|
||||
|
||||
PcapBpfProgram program = new PcapBpfProgram();
|
||||
String expr = "dst port 68 or 67";
|
||||
int optimize = 0;
|
||||
int netmask = 0xFFFFFF00;
|
||||
if (pcap.compile(program, expr, optimize, netmask) != Pcap.OK) {
|
||||
s_logger.debug("Pcap: can't compile BPF");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (pcap.setFilter(program) != Pcap.OK) {
|
||||
s_logger.debug("Pcap: Can't set filter");
|
||||
return null;
|
||||
}
|
||||
return pcap;
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("Failed to initialized: " + e.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (_loop) {
|
||||
try {
|
||||
_pcapedDev = initializePcap();
|
||||
if (_pcapedDev == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PcapPacketHandler<String> jpacketHandler = new PcapPacketHandler<String>() {
|
||||
public void nextPacket(PcapPacket packet, String user) {
|
||||
Udp u = new Udp();
|
||||
if (packet.hasHeader(u)) {
|
||||
int offset = u.getOffset() + u.getLength();
|
||||
_executor.execute(new DhcpPacketParser(packet,
|
||||
offset, u.length() - u.getLength(),
|
||||
_manager));
|
||||
}
|
||||
}
|
||||
};
|
||||
s_logger.debug("Starting DHCP snooping on " + _bridge);
|
||||
int retValue = _pcapedDev.loop(-1, jpacketHandler,
|
||||
"pcapPacketHandler");
|
||||
if (retValue == -1) {
|
||||
s_logger.debug("Pcap: failed to set loop handler");
|
||||
} else if (retValue == -2 && !_loop) {
|
||||
s_logger.debug("Pcap: terminated");
|
||||
return;
|
||||
}
|
||||
_pcapedDev.close();
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("Pcap error:" + e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
s_logger.addAppender(new org.apache.log4j.ConsoleAppender(
|
||||
new org.apache.log4j.PatternLayout(), "System.out"));
|
||||
final DhcpSnooperImpl manager = new DhcpSnooperImpl("cloudbr0", 10000);
|
||||
s_logger.debug(manager.getIPAddr("02:00:4c:66:00:03", "i-2-5-VM"));
|
||||
manager.stop();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
// TODO configure timeout here
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "DhcpSnooperImpl";
|
||||
}
|
||||
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,293 +0,0 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.agent.resource.computing;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.libvirt.Connect;
|
||||
import org.libvirt.Domain;
|
||||
import org.libvirt.LibvirtException;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.StartAnswer;
|
||||
import com.cloud.agent.api.StartCommand;
|
||||
|
||||
import com.cloud.agent.api.StopAnswer;
|
||||
import com.cloud.agent.api.StopCommand;
|
||||
|
||||
import com.cloud.agent.api.routing.SavePasswordCommand;
|
||||
import com.cloud.agent.api.routing.VmDataCommand;
|
||||
import com.cloud.agent.api.to.NicTO;
|
||||
import com.cloud.agent.api.to.VirtualMachineTO;
|
||||
import com.cloud.agent.dhcp.DhcpSnooper;
|
||||
import com.cloud.agent.dhcp.DhcpSnooperImpl;
|
||||
|
||||
import com.cloud.agent.resource.computing.LibvirtComputingResource;
|
||||
import com.cloud.agent.resource.computing.LibvirtConnection;
|
||||
import com.cloud.agent.resource.computing.LibvirtVMDef;
|
||||
import com.cloud.agent.resource.computing.LibvirtVMDef.DiskDef;
|
||||
import com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef;
|
||||
import com.cloud.agent.vmdata.JettyVmDataServer;
|
||||
import com.cloud.agent.vmdata.VmDataServer;
|
||||
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
/**
|
||||
* Logic specific to the Cloudzones feature
|
||||
*
|
||||
* }
|
||||
**/
|
||||
|
||||
public class CloudZonesComputingResource extends LibvirtComputingResource {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(CloudZonesComputingResource.class);
|
||||
protected DhcpSnooper _dhcpSnooper;
|
||||
String _parent;
|
||||
long _dhcpTimeout;
|
||||
protected String _hostIp;
|
||||
protected String _hostMacAddress;
|
||||
protected VmDataServer _vmDataServer = new JettyVmDataServer();
|
||||
|
||||
private void setupDhcpManager(Connect conn, String bridgeName) {
|
||||
|
||||
_dhcpSnooper = new DhcpSnooperImpl(bridgeName, _dhcpTimeout);
|
||||
|
||||
List<Pair<String, String>> macs = new ArrayList<Pair<String, String>>();
|
||||
try {
|
||||
int[] domainIds = conn.listDomains();
|
||||
for (int i = 0; i < domainIds.length; i++) {
|
||||
Domain vm = conn.domainLookupByID(domainIds[i]);
|
||||
if (vm.getName().startsWith("i-")) {
|
||||
List<InterfaceDef> nics = getInterfaces(conn, vm.getName());
|
||||
InterfaceDef nic = nics.get(0);
|
||||
macs.add(new Pair<String, String>(nic.getMacAddress(), vm
|
||||
.getName()));
|
||||
}
|
||||
}
|
||||
} catch (LibvirtException e) {
|
||||
s_logger.debug("Failed to get MACs: " + e.toString());
|
||||
}
|
||||
|
||||
_dhcpSnooper.initializeMacTable(macs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
boolean success = super.configure(name, params);
|
||||
if (!success) {
|
||||
return false;
|
||||
}
|
||||
|
||||
_parent = (String) params.get("mount.path");
|
||||
|
||||
try {
|
||||
_dhcpTimeout = Long.parseLong((String) params.get("dhcp.timeout"));
|
||||
} catch (Exception e) {
|
||||
_dhcpTimeout = 1200000;
|
||||
}
|
||||
|
||||
_hostIp = (String) params.get("host.ip");
|
||||
_hostMacAddress = (String) params.get("host.mac.address");
|
||||
|
||||
try {
|
||||
Connect conn;
|
||||
conn = LibvirtConnection.getConnection();
|
||||
setupDhcpManager(conn, _guestBridgeName);
|
||||
} catch (LibvirtException e) {
|
||||
s_logger.debug("Failed to get libvirt connection:" + e.toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
_dhcpSnooper.configure(name, params);
|
||||
_vmDataServer.configure(name, params);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized StartAnswer execute(StartCommand cmd) {
|
||||
VirtualMachineTO vmSpec = cmd.getVirtualMachine();
|
||||
String vmName = vmSpec.getName();
|
||||
LibvirtVMDef vm = null;
|
||||
|
||||
State state = State.Stopped;
|
||||
Connect conn = null;
|
||||
try {
|
||||
conn = LibvirtConnection.getConnection();
|
||||
synchronized (_vms) {
|
||||
_vms.put(vmName, State.Starting);
|
||||
}
|
||||
|
||||
vm = createVMFromSpec(vmSpec);
|
||||
|
||||
createVbd(conn, vmSpec, vmName, vm);
|
||||
|
||||
createVifs(conn, vmSpec, vm);
|
||||
|
||||
s_logger.debug("starting " + vmName + ": " + vm.toString());
|
||||
startDomain(conn, vmName, vm.toString());
|
||||
|
||||
NicTO[] nics = vmSpec.getNics();
|
||||
for (NicTO nic : nics) {
|
||||
if (nic.isSecurityGroupEnabled()) {
|
||||
if (vmSpec.getType() != VirtualMachine.Type.User) {
|
||||
default_network_rules_for_systemvm(conn, vmName);
|
||||
} else {
|
||||
nic.setIp(null);
|
||||
default_network_rules(conn, vmName, nic, vmSpec.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Attach each data volume to the VM, if there is a deferred
|
||||
// attached disk
|
||||
for (DiskDef disk : vm.getDevices().getDisks()) {
|
||||
if (disk.isAttachDeferred()) {
|
||||
attachOrDetachDevice(conn, true, vmName, disk.toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (vmSpec.getType() == VirtualMachine.Type.User) {
|
||||
for (NicTO nic : nics) {
|
||||
if (nic.getType() == TrafficType.Guest) {
|
||||
InetAddress ipAddr = _dhcpSnooper.getIPAddr(
|
||||
nic.getMac(), vmName);
|
||||
if (ipAddr == null) {
|
||||
s_logger.debug("Failed to get guest DHCP ip, stop it");
|
||||
StopCommand stpCmd = new StopCommand(vmName);
|
||||
execute(stpCmd);
|
||||
return new StartAnswer(cmd,
|
||||
"Failed to get guest DHCP ip, stop it");
|
||||
}
|
||||
s_logger.debug(ipAddr);
|
||||
nic.setIp(ipAddr.getHostAddress());
|
||||
|
||||
post_default_network_rules(conn, vmName, nic,
|
||||
vmSpec.getId(), _dhcpSnooper.getDhcpServerIP(),
|
||||
_hostIp, _hostMacAddress);
|
||||
_vmDataServer.handleVmStarted(cmd.getVirtualMachine());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
state = State.Running;
|
||||
return new StartAnswer(cmd);
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Exception ", e);
|
||||
if (conn != null) {
|
||||
handleVmStartFailure(conn, vmName, vm);
|
||||
}
|
||||
return new StartAnswer(cmd, e.getMessage());
|
||||
} finally {
|
||||
synchronized (_vms) {
|
||||
if (state != State.Stopped) {
|
||||
_vms.put(vmName, state);
|
||||
} else {
|
||||
_vms.remove(vmName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Answer execute(StopCommand cmd) {
|
||||
final String vmName = cmd.getVmName();
|
||||
|
||||
Long bytesReceived = new Long(0);
|
||||
Long bytesSent = new Long(0);
|
||||
|
||||
State state = null;
|
||||
synchronized (_vms) {
|
||||
state = _vms.get(vmName);
|
||||
_vms.put(vmName, State.Stopping);
|
||||
}
|
||||
try {
|
||||
Connect conn = LibvirtConnection.getConnection();
|
||||
|
||||
try {
|
||||
Domain dm = conn.domainLookupByUUID(UUID
|
||||
.nameUUIDFromBytes(vmName.getBytes()));
|
||||
} catch (LibvirtException e) {
|
||||
state = State.Stopped;
|
||||
return new StopAnswer(cmd, null, 0, bytesSent, bytesReceived);
|
||||
}
|
||||
|
||||
String macAddress = null;
|
||||
if (vmName.startsWith("i-")) {
|
||||
List<InterfaceDef> nics = getInterfaces(conn, vmName);
|
||||
if (!nics.isEmpty()) {
|
||||
macAddress = nics.get(0).getMacAddress();
|
||||
}
|
||||
}
|
||||
|
||||
destroy_network_rules_for_vm(conn, vmName);
|
||||
String result = stopVM(conn, vmName, defineOps.UNDEFINE_VM);
|
||||
|
||||
try {
|
||||
cleanupVnet(conn, cmd.getVnet());
|
||||
_dhcpSnooper.cleanup(macAddress, vmName);
|
||||
_vmDataServer.handleVmStopped(cmd.getVmName());
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
state = State.Stopped;
|
||||
return new StopAnswer(cmd, result, 0, bytesSent, bytesReceived);
|
||||
} catch (LibvirtException e) {
|
||||
return new StopAnswer(cmd, e.getMessage());
|
||||
} finally {
|
||||
synchronized (_vms) {
|
||||
if (state != null) {
|
||||
_vms.put(vmName, state);
|
||||
} else {
|
||||
_vms.remove(vmName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer executeRequest(Command cmd) {
|
||||
if (cmd instanceof VmDataCommand) {
|
||||
return execute((VmDataCommand) cmd);
|
||||
} else if (cmd instanceof SavePasswordCommand) {
|
||||
return execute((SavePasswordCommand) cmd);
|
||||
}
|
||||
return super.executeRequest(cmd);
|
||||
}
|
||||
|
||||
protected Answer execute(final VmDataCommand cmd) {
|
||||
return _vmDataServer.handleVmDataCommand(cmd);
|
||||
}
|
||||
|
||||
protected Answer execute(final SavePasswordCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@ -2483,7 +2483,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
ConsoleDef console = new ConsoleDef("pty", null, null, (short) 0);
|
||||
devices.addDevice(console);
|
||||
|
||||
GraphicDef grap = new GraphicDef("vnc", (short) 0, true, null, null,
|
||||
GraphicDef grap = new GraphicDef("vnc", (short) 0, true, vmTO.getVncAddr(), null,
|
||||
null);
|
||||
devices.addDevice(grap);
|
||||
|
||||
@ -2509,6 +2509,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
|
||||
protected synchronized StartAnswer execute(StartCommand cmd) {
|
||||
VirtualMachineTO vmSpec = cmd.getVirtualMachine();
|
||||
vmSpec.setVncAddr(cmd.getHostIp());
|
||||
String vmName = vmSpec.getName();
|
||||
LibvirtVMDef vm = null;
|
||||
|
||||
@ -3952,24 +3953,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
if (!_can_bridge_firewall) {
|
||||
return false;
|
||||
}
|
||||
List<InterfaceDef> intfs = getInterfaces(conn, vmName);
|
||||
if (intfs.size() < 1) {
|
||||
return false;
|
||||
}
|
||||
/* FIX ME: */
|
||||
String brname = null;
|
||||
if (vmName.startsWith("r-")) {
|
||||
InterfaceDef intf = intfs.get(0);
|
||||
brname = intf.getBrName();
|
||||
} else {
|
||||
InterfaceDef intf = intfs.get(intfs.size() - 1);
|
||||
brname = intf.getBrName();
|
||||
}
|
||||
|
||||
Script cmd = new Script(_securityGroupPath, _timeout, s_logger);
|
||||
cmd.add("default_network_rules_systemvm");
|
||||
cmd.add("--vmname", vmName);
|
||||
cmd.add("--brname", brname);
|
||||
cmd.add("--localbrname", _linkLocalBridgeName);
|
||||
String result = cmd.execute();
|
||||
if (result != null) {
|
||||
return false;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -17,12 +17,14 @@
|
||||
package com.cloud.agent.api;
|
||||
|
||||
import com.cloud.agent.api.to.VirtualMachineTO;
|
||||
import com.cloud.host.Host;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class StartCommand extends Command {
|
||||
VirtualMachineTO vm;
|
||||
|
||||
String hostIp;
|
||||
|
||||
public VirtualMachineTO getVirtualMachine() {
|
||||
return vm;
|
||||
}
|
||||
@ -34,8 +36,17 @@ public class StartCommand extends Command {
|
||||
|
||||
protected StartCommand() {
|
||||
}
|
||||
|
||||
|
||||
public StartCommand(VirtualMachineTO vm) {
|
||||
this.vm = vm;
|
||||
}
|
||||
|
||||
public StartCommand(VirtualMachineTO vm, Host host) {
|
||||
this.vm = vm;
|
||||
this.hostIp = host.getPrivateIpAddress();
|
||||
}
|
||||
|
||||
public String getHostIp() {
|
||||
return this.hostIp;
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,6 +40,7 @@ public class VirtualMachineTO {
|
||||
boolean enableHA;
|
||||
boolean limitCpuUse;
|
||||
String vncPassword;
|
||||
String vncAddr;
|
||||
Map<String, String> params;
|
||||
|
||||
VolumeTO[] disks;
|
||||
@ -191,6 +192,14 @@ public class VirtualMachineTO {
|
||||
public void setVncPassword(String vncPassword) {
|
||||
this.vncPassword = vncPassword;
|
||||
}
|
||||
|
||||
public String getVncAddr() {
|
||||
return this.vncAddr;
|
||||
}
|
||||
|
||||
public void setVncAddr(String vncAddr) {
|
||||
this.vncAddr = vncAddr;
|
||||
}
|
||||
|
||||
public Map<String, String> getDetails() {
|
||||
return params;
|
||||
|
||||
@ -361,6 +361,10 @@ public class ApiConstants {
|
||||
public static final String NETWORK = "network";
|
||||
public static final String VPC_ID = "vpcid";
|
||||
public static final String GATEWAY_ID = "gatewayid";
|
||||
public static final String CAN_USE_FOR_DEPLOY = "canusefordeploy";
|
||||
public static final String RESOURCE_IDS = "resourceids";
|
||||
public static final String RESOURCE_ID = "resourceid";
|
||||
public static final String CUSTOMER = "customer";
|
||||
|
||||
public enum HostDetails {
|
||||
all, capacity, events, stats, min;
|
||||
|
||||
@ -51,6 +51,7 @@ import com.cloud.projects.Project;
|
||||
import com.cloud.projects.ProjectService;
|
||||
import com.cloud.resource.ResourceService;
|
||||
import com.cloud.server.ManagementService;
|
||||
import com.cloud.server.TaggedResourceService;
|
||||
import com.cloud.storage.StorageService;
|
||||
import com.cloud.storage.snapshot.SnapshotService;
|
||||
import com.cloud.template.TemplateService;
|
||||
@ -131,6 +132,7 @@ public abstract class BaseCmd {
|
||||
public static StorageNetworkService _storageNetworkService;
|
||||
public static VpcService _vpcService;
|
||||
public static NetworkACLService _networkACLService;
|
||||
public static TaggedResourceService _taggedResourceService;
|
||||
|
||||
static void setComponents(ResponseGenerator generator) {
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
|
||||
@ -160,6 +162,7 @@ public abstract class BaseCmd {
|
||||
_storageNetworkService = locator.getManager(StorageNetworkService.class);
|
||||
_vpcService = locator.getManager(VpcService.class);
|
||||
_networkACLService = locator.getManager(NetworkACLService.class);
|
||||
_taggedResourceService = locator.getManager(TaggedResourceService.class);
|
||||
}
|
||||
|
||||
public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException;
|
||||
|
||||
@ -58,6 +58,7 @@ import com.cloud.api.response.ProviderResponse;
|
||||
import com.cloud.api.response.RemoteAccessVpnResponse;
|
||||
import com.cloud.api.response.ResourceCountResponse;
|
||||
import com.cloud.api.response.ResourceLimitResponse;
|
||||
import com.cloud.api.response.ResourceTagResponse;
|
||||
import com.cloud.api.response.SecurityGroupResponse;
|
||||
import com.cloud.api.response.ServiceOfferingResponse;
|
||||
import com.cloud.api.response.ServiceResponse;
|
||||
@ -124,6 +125,7 @@ import com.cloud.org.Cluster;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.projects.ProjectAccount;
|
||||
import com.cloud.projects.ProjectInvitation;
|
||||
import com.cloud.server.ResourceTag;
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.storage.StoragePool;
|
||||
import com.cloud.storage.Swift;
|
||||
@ -292,6 +294,7 @@ public interface ResponseGenerator {
|
||||
Long getIdentiyId(String tableName, String token);
|
||||
|
||||
/**
|
||||
<<<<<<< HEAD
|
||||
* @param offering
|
||||
* @return
|
||||
*/
|
||||
@ -320,4 +323,6 @@ public interface ResponseGenerator {
|
||||
* @return
|
||||
*/
|
||||
StaticRouteResponse createStaticRouteResponse(StaticRoute result);
|
||||
|
||||
ResourceTagResponse createResourceTagResponse(ResourceTag resourceTag);
|
||||
}
|
||||
|
||||
@ -31,8 +31,10 @@ import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.ClusterResponse;
|
||||
import com.cloud.api.response.ListResponse;
|
||||
import com.cloud.exception.DiscoveryException;
|
||||
import com.cloud.exception.ResourceInUseException;
|
||||
import com.cloud.org.Cluster;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.IdentityProxy;
|
||||
|
||||
@Implementation(description="Adds a new cluster", responseObject=ClusterResponse.class)
|
||||
public class AddClusterCmd extends BaseCmd {
|
||||
@ -166,7 +168,14 @@ public class AddClusterCmd extends BaseCmd {
|
||||
this.setResponseObject(response);
|
||||
} catch (DiscoveryException ex) {
|
||||
s_logger.warn("Exception: ", ex);
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
|
||||
} catch (ResourceInUseException ex) {
|
||||
s_logger.warn("Exception: ", ex);
|
||||
ServerApiException e = new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
|
||||
for (IdentityProxy proxyObj : ex.getIdProxyList()) {
|
||||
e.addProxyObject(proxyObj.getTableName(), proxyObj.getValue(), proxyObj.getidFieldName());
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
131
api/src/com/cloud/api/commands/CreateTagsCmd.java
Normal file
131
api/src/com/cloud/api/commands/CreateTagsCmd.java
Normal file
@ -0,0 +1,131 @@
|
||||
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
||||
// Apache License, Version 2.0 (the "License"); you may not use this
|
||||
// file except in compliance with the License. Citrix Systems, Inc.
|
||||
// reserves all rights not expressly granted by the License.
|
||||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.SuccessResponse;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.server.ResourceTag;
|
||||
import com.cloud.server.ResourceTag.TaggedResourceType;
|
||||
|
||||
/**
|
||||
* @author Alena Prokharchyk
|
||||
*/
|
||||
|
||||
@Implementation(description = "Creates resource tag(s)", responseObject = SuccessResponse.class, since = "Burbank")
|
||||
public class CreateTagsCmd extends BaseAsyncCmd{
|
||||
public static final Logger s_logger = Logger.getLogger(CreateTagsCmd.class.getName());
|
||||
|
||||
private static final String s_name = "createtagsresponse";
|
||||
|
||||
// ///////////////////////////////////////////////////
|
||||
// ////////////// API parameters /////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name = ApiConstants.TAGS, type = CommandType.MAP, required=true, description = "Map of tags (key/value pairs)")
|
||||
private Map tag;
|
||||
|
||||
@Parameter(name=ApiConstants.RESOURCE_TYPE, type=CommandType.STRING, required=true, description="type of the resource")
|
||||
private String resourceType;
|
||||
|
||||
@Parameter(name=ApiConstants.RESOURCE_IDS, type=CommandType.LIST, required=true,
|
||||
collectionType=CommandType.STRING, description="list of resources to create the tags for")
|
||||
private List<String> resourceIds;
|
||||
|
||||
@Parameter(name=ApiConstants.CUSTOMER, type=CommandType.STRING, description="identifies client specific tag. " +
|
||||
"When the value is not null, the tag can't be used by cloudStack code internally")
|
||||
private String customer;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public TaggedResourceType getResourceType(){
|
||||
return _taggedResourceService.getResourceType(resourceType);
|
||||
}
|
||||
|
||||
public Map<String, String> getTags() {
|
||||
Map<String, String> tagsMap = null;
|
||||
if (!tag.isEmpty()) {
|
||||
tagsMap = new HashMap<String, String>();
|
||||
Collection<?> servicesCollection = tag.values();
|
||||
Iterator<?> iter = servicesCollection.iterator();
|
||||
while (iter.hasNext()) {
|
||||
HashMap<String, String> services = (HashMap<String, String>) iter.next();
|
||||
String key = services.get("key");
|
||||
String value = services.get("value");
|
||||
tagsMap.put(key, value);
|
||||
}
|
||||
}
|
||||
return tagsMap;
|
||||
}
|
||||
|
||||
public List<String> getResourceIds() {
|
||||
return resourceIds;
|
||||
}
|
||||
|
||||
public String getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////// API Implementation///////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
//FIXME - validate the owner here
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
List<ResourceTag> tags = _taggedResourceService.createTags(getResourceIds(), getResourceType(), getTags(), getCustomer());
|
||||
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create tags");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_TAGS_CREATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "creating tags";
|
||||
}
|
||||
}
|
||||
112
api/src/com/cloud/api/commands/DeleteTagsCmd.java
Normal file
112
api/src/com/cloud/api/commands/DeleteTagsCmd.java
Normal file
@ -0,0 +1,112 @@
|
||||
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.SuccessResponse;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.server.ResourceTag;
|
||||
import com.cloud.server.ResourceTag.TaggedResourceType;
|
||||
|
||||
/**
|
||||
* @author Alena Prokharchyk
|
||||
*/
|
||||
|
||||
@Implementation(description = "Deleting resource tag(s)", responseObject = SuccessResponse.class, since = "Burbank")
|
||||
public class DeleteTagsCmd extends BaseAsyncCmd{
|
||||
public static final Logger s_logger = Logger.getLogger(DeleteTagsCmd.class.getName());
|
||||
|
||||
private static final String s_name = "deleteTagsresponse";
|
||||
|
||||
// ///////////////////////////////////////////////////
|
||||
// ////////////// API parameters /////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name = ApiConstants.TAGS, type = CommandType.MAP, description = "Delete tags matching key/value pairs")
|
||||
private Map tag;
|
||||
|
||||
@Parameter(name=ApiConstants.RESOURCE_TYPE, type=CommandType.STRING, required=true, description="Delete tag by resource type")
|
||||
private String resourceType;
|
||||
|
||||
@Parameter(name=ApiConstants.RESOURCE_IDS, type=CommandType.LIST, required=true,
|
||||
collectionType=CommandType.STRING, description="Delete tags for resource id(s)")
|
||||
private List<String> resourceIds;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public TaggedResourceType getResourceType(){
|
||||
return _taggedResourceService.getResourceType(resourceType);
|
||||
}
|
||||
|
||||
public Map<String, String> getTags() {
|
||||
Map<String, String> tagsMap = null;
|
||||
if (tag != null && !tag.isEmpty()) {
|
||||
tagsMap = new HashMap<String, String>();
|
||||
Collection<?> servicesCollection = tag.values();
|
||||
Iterator<?> iter = servicesCollection.iterator();
|
||||
while (iter.hasNext()) {
|
||||
HashMap<String, String> services = (HashMap<String, String>) iter.next();
|
||||
String key = services.get("key");
|
||||
String value = services.get("value");
|
||||
tagsMap.put(key, value);
|
||||
}
|
||||
}
|
||||
return tagsMap;
|
||||
}
|
||||
|
||||
public List<String> getResourceIds() {
|
||||
return resourceIds;
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////// API Implementation///////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
//FIXME - validate the owner here
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
boolean success = _taggedResourceService.deleteTags(getResourceIds(), getResourceType(), getTags());
|
||||
|
||||
if (success) {
|
||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete tags");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_TAGS_DELETE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "Deleting tags";
|
||||
}
|
||||
}
|
||||
@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -252,9 +253,9 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
|
||||
if ((networkIds != null || ipAddress != null) && ipToNetworkList != null) {
|
||||
throw new InvalidParameterValueException("NetworkIds and ipAddress can't be specified along with ipToNetworkMap parameter");
|
||||
}
|
||||
Map<Long, String> ipToNetworkMap = null;
|
||||
LinkedHashMap<Long, String> ipToNetworkMap = null;
|
||||
if (ipToNetworkList != null && !ipToNetworkList.isEmpty()) {
|
||||
ipToNetworkMap = new HashMap<Long, String>();
|
||||
ipToNetworkMap = new LinkedHashMap<Long, String>();
|
||||
Collection ipsCollection = ipToNetworkList.values();
|
||||
Iterator iter = ipsCollection.iterator();
|
||||
while (iter.hasNext()) {
|
||||
|
||||
@ -63,10 +63,11 @@ public class ListNetworksCmd extends BaseListProjectAndAccountResourcesCmd {
|
||||
@Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="list networks by physical network id")
|
||||
private Long physicalNetworkId;
|
||||
|
||||
@Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING, description="list network offerings supporting certain services")
|
||||
@Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING, description="list networks supporting certain services")
|
||||
private List<String> supportedServices;
|
||||
|
||||
@Parameter(name=ApiConstants.RESTART_REQUIRED, type=CommandType.BOOLEAN, description="list networks by restartRequired")
|
||||
|
||||
private Boolean restartRequired;
|
||||
|
||||
@Parameter(name=ApiConstants.SPECIFY_IP_RANGES, type=CommandType.BOOLEAN, description="true if need to list only networks which support specifying ip ranges")
|
||||
@ -75,6 +76,9 @@ public class ListNetworksCmd extends BaseListProjectAndAccountResourcesCmd {
|
||||
@IdentityMapper(entityTableName="vpc")
|
||||
@Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="List networks by VPC")
|
||||
private Long vpcId;
|
||||
|
||||
@Parameter(name=ApiConstants.CAN_USE_FOR_DEPLOY, type=CommandType.BOOLEAN, description="list networks available for vm deployment")
|
||||
private Boolean canUseForDeploy;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
@ -122,6 +126,10 @@ public class ListNetworksCmd extends BaseListProjectAndAccountResourcesCmd {
|
||||
|
||||
public Long getVpcId() {
|
||||
return vpcId;
|
||||
}
|
||||
|
||||
public Boolean canUseForDeploy() {
|
||||
return canUseForDeploy;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
94
api/src/com/cloud/api/commands/ListTagsCmd.java
Normal file
94
api/src/com/cloud/api/commands/ListTagsCmd.java
Normal file
@ -0,0 +1,94 @@
|
||||
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
||||
// Apache License, Version 2.0 (the "License"); you may not use this
|
||||
// file except in compliance with the License. Citrix Systems, Inc.
|
||||
// reserves all rights not expressly granted by the License.
|
||||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.response.ListResponse;
|
||||
import com.cloud.api.response.ResourceTagResponse;
|
||||
import com.cloud.server.ResourceTag;
|
||||
|
||||
/**
|
||||
* @author Alena Prokharchyk
|
||||
*/
|
||||
|
||||
@Implementation(description = "List resource tag(s)", responseObject = ResourceTagResponse.class, since = "Burbank")
|
||||
public class ListTagsCmd extends BaseListProjectAndAccountResourcesCmd{
|
||||
private static final String s_name = "listtagsresponse";
|
||||
|
||||
@Parameter(name=ApiConstants.RESOURCE_TYPE, type=CommandType.STRING, description="list by resource type")
|
||||
private String resourceType;
|
||||
|
||||
@Parameter(name=ApiConstants.RESOURCE_ID, type=CommandType.STRING, description="list by resource id")
|
||||
private String resourceId;
|
||||
|
||||
@Parameter(name=ApiConstants.KEY, type=CommandType.STRING, description="list by key")
|
||||
private String key;
|
||||
|
||||
@Parameter(name=ApiConstants.VALUE, type=CommandType.STRING, description="list by value")
|
||||
private String value;
|
||||
|
||||
@Parameter(name=ApiConstants.CUSTOMER, type=CommandType.STRING, description="list by customer name")
|
||||
private String customer;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
List<? extends ResourceTag> tags = _taggedResourceService.listTags(this);
|
||||
ListResponse<ResourceTagResponse> response = new ListResponse<ResourceTagResponse>();
|
||||
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
|
||||
for (ResourceTag tag : tags) {
|
||||
ResourceTagResponse tagResponse = _responseGenerator.createResourceTagResponse(tag);
|
||||
tagResponses.add(tagResponse);
|
||||
}
|
||||
response.setResponses(tagResponses);
|
||||
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
}
|
||||
|
||||
public String getResourceType() {
|
||||
return resourceType;
|
||||
}
|
||||
|
||||
public String getResourceId() {
|
||||
return resourceId;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
public String getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
}
|
||||
@ -133,6 +133,9 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes
|
||||
|
||||
@SerializedName(ApiConstants.VPC_ID) @Param(description="VPC the network belongs to")
|
||||
private IdentityProxy vpcId = new IdentityProxy("vpc");
|
||||
|
||||
@SerializedName(ApiConstants.CAN_USE_FOR_DEPLOY) @Param(description="list networks available for vm deployment")
|
||||
private Boolean canUseForDeploy;
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id.setValue(id);
|
||||
@ -279,4 +282,8 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes
|
||||
public void setVpcId(Long vpcId) {
|
||||
this.vpcId.setValue(vpcId);
|
||||
}
|
||||
|
||||
public void setCanUseForDeploy(Boolean canUseForDeploy) {
|
||||
this.canUseForDeploy = canUseForDeploy;
|
||||
}
|
||||
}
|
||||
|
||||
100
api/src/com/cloud/api/response/ResourceTagResponse.java
Normal file
100
api/src/com/cloud/api/response/ResourceTagResponse.java
Normal file
@ -0,0 +1,100 @@
|
||||
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
||||
// Apache License, Version 2.0 (the "License"); you may not use this
|
||||
// file except in compliance with the License. Citrix Systems, Inc.
|
||||
// reserves all rights not expressly granted by the License.
|
||||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package com.cloud.api.response;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.serializer.Param;
|
||||
import com.cloud.utils.IdentityProxy;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* @author Alena Prokharchyk
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ResourceTagResponse extends BaseResponse implements ControlledEntityResponse{
|
||||
@SerializedName(ApiConstants.KEY) @Param(description="tag key name")
|
||||
private String key;
|
||||
|
||||
@SerializedName(ApiConstants.VALUE) @Param(description="tag value")
|
||||
private String value;
|
||||
|
||||
@SerializedName(ApiConstants.RESOURCE_TYPE) @Param(description="resource type")
|
||||
private String resourceType;
|
||||
|
||||
@SerializedName(ApiConstants.RESOURCE_ID) @Param(description="id of the resource")
|
||||
private String id;
|
||||
|
||||
@SerializedName(ApiConstants.ACCOUNT)
|
||||
@Param(description = "the account associated with the tag")
|
||||
private String accountName;
|
||||
|
||||
@SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id the tag belongs to")
|
||||
private IdentityProxy projectId = new IdentityProxy("projects");
|
||||
|
||||
@SerializedName(ApiConstants.PROJECT) @Param(description="the project name where tag belongs to")
|
||||
private String projectName;
|
||||
|
||||
@SerializedName(ApiConstants.DOMAIN_ID)
|
||||
@Param(description = "the ID of the domain associated with the tag")
|
||||
private IdentityProxy domainId = new IdentityProxy("domain");
|
||||
|
||||
@SerializedName(ApiConstants.DOMAIN)
|
||||
@Param(description = "the domain associated with the tag")
|
||||
private String domainName;
|
||||
|
||||
@SerializedName(ApiConstants.CUSTOMER) @Param(description="customer associated with the tag")
|
||||
private String customer;
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void setResourceType(String resourceType) {
|
||||
this.resourceType = resourceType;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setAccountName(String accountName) {
|
||||
this.accountName = accountName;
|
||||
}
|
||||
|
||||
public void setDomainId(Long domainId) {
|
||||
this.domainId.setValue(domainId);
|
||||
}
|
||||
|
||||
public void setDomainName(String domainName) {
|
||||
this.domainName = domainName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProjectId(Long projectId) {
|
||||
this.projectId.setValue(projectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProjectName(String projectName) {
|
||||
this.projectName = projectName;
|
||||
}
|
||||
|
||||
public void setCustomer(String customer) {
|
||||
this.customer = customer;
|
||||
}
|
||||
}
|
||||
@ -278,4 +278,9 @@ public class EventTypes {
|
||||
// Static routes
|
||||
public static final String EVENT_STATIC_ROUTE_CREATE = "STATIC.ROUTE.CREATE";
|
||||
public static final String EVENT_STATIC_ROUTE_DELETE = "STATIC.ROUTE.DELETE";
|
||||
|
||||
// tag related events
|
||||
public static final String EVENT_TAGS_CREATE = "CREATE_TAGS";
|
||||
public static final String EVENT_TAGS_DELETE = "DELETE_TAGS";
|
||||
|
||||
}
|
||||
|
||||
@ -168,5 +168,9 @@ public interface NetworkService {
|
||||
Network createPrivateNetwork(String networkName, String displayText, long physicalNetworkId, String vlan,
|
||||
String startIp, String endIP, String gateway, String netmask, long networkOwnerId)
|
||||
throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException;
|
||||
|
||||
/**
|
||||
* @param network
|
||||
* @return
|
||||
*/
|
||||
boolean canUseForDeploy(Network network);
|
||||
}
|
||||
|
||||
@ -31,6 +31,7 @@ import com.cloud.api.commands.UpdateHostCmd;
|
||||
import com.cloud.api.commands.UpdateHostPasswordCmd;
|
||||
import com.cloud.exception.DiscoveryException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceInUseException;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.org.Cluster;
|
||||
@ -61,7 +62,7 @@ public interface ResourceService {
|
||||
* @throws IllegalArgumentException
|
||||
* @throws DiscoveryException
|
||||
*/
|
||||
List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException;
|
||||
List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException, ResourceInUseException;
|
||||
|
||||
boolean deleteCluster(DeleteClusterCmd cmd);
|
||||
|
||||
|
||||
66
api/src/com/cloud/server/ResourceTag.java
Normal file
66
api/src/com/cloud/server/ResourceTag.java
Normal file
@ -0,0 +1,66 @@
|
||||
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
||||
// Apache License, Version 2.0 (the "License"); you may not use this
|
||||
// file except in compliance with the License. Citrix Systems, Inc.
|
||||
// reserves all rights not expressly granted by the License.
|
||||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package com.cloud.server;
|
||||
|
||||
import com.cloud.acl.ControlledEntity;
|
||||
|
||||
/**
|
||||
* @author Alena Prokharchyk
|
||||
*/
|
||||
public interface ResourceTag extends ControlledEntity{
|
||||
|
||||
public enum TaggedResourceType {
|
||||
UserVm,
|
||||
Template,
|
||||
ISO,
|
||||
Volume,
|
||||
Snapshot,
|
||||
Network,
|
||||
LoadBalancer,
|
||||
PortForwardingRule,
|
||||
FirewallRule,
|
||||
SecurityGroup,
|
||||
PublicIpAddress
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
long getId();
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
String getKey();
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
String getValue();
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
long getResourceId();
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
TaggedResourceType getResourceType();
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
String getCustomer();
|
||||
|
||||
}
|
||||
57
api/src/com/cloud/server/TaggedResourceService.java
Normal file
57
api/src/com/cloud/server/TaggedResourceService.java
Normal file
@ -0,0 +1,57 @@
|
||||
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
||||
// Apache License, Version 2.0 (the "License"); you may not use this
|
||||
// file except in compliance with the License. Citrix Systems, Inc.
|
||||
// reserves all rights not expressly granted by the License.
|
||||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package com.cloud.server;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.api.commands.ListTagsCmd;
|
||||
import com.cloud.server.ResourceTag.TaggedResourceType;
|
||||
|
||||
/**
|
||||
* @author Alena Prokharchyk
|
||||
*/
|
||||
public interface TaggedResourceService {
|
||||
|
||||
TaggedResourceType getResourceType (String resourceTypeStr);
|
||||
|
||||
/**
|
||||
* @param resourceIds TODO
|
||||
* @param resourceType
|
||||
* @param tags
|
||||
* @param customer TODO
|
||||
* @return
|
||||
*/
|
||||
List<ResourceTag> createTags(List<String> resourceIds, TaggedResourceType resourceType, Map<String, String> tags, String customer);
|
||||
|
||||
/**
|
||||
* @param resourceId
|
||||
* @param resourceType
|
||||
* @return
|
||||
*/
|
||||
String getUuid(String resourceId, TaggedResourceType resourceType);
|
||||
|
||||
/**
|
||||
* @param listTagsCmd
|
||||
* @return
|
||||
*/
|
||||
List<? extends ResourceTag> listTags(ListTagsCmd listTagsCmd);
|
||||
|
||||
/**
|
||||
* @param resourceIds
|
||||
* @param resourceType
|
||||
* @param tags
|
||||
* @return
|
||||
*/
|
||||
boolean deleteTags(List<String> resourceIds, TaggedResourceType resourceType, Map<String, String> tags);
|
||||
}
|
||||
@ -23,6 +23,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.KeyStore;
|
||||
import java.security.SignatureException;
|
||||
import java.security.cert.Certificate;
|
||||
@ -178,7 +179,7 @@ public class EC2RestServlet extends HttpServlet {
|
||||
}
|
||||
String keystore = EC2Prop.getProperty( "keystore" );
|
||||
keystorePassword = EC2Prop.getProperty( "keystorePass" );
|
||||
wsdlVersion = EC2Prop.getProperty( "WSDLVersion", "2009-11-30" );
|
||||
wsdlVersion = EC2Prop.getProperty( "WSDLVersion", "2010-11-15" );
|
||||
version = EC2Prop.getProperty( "cloudbridgeVersion", "UNKNOWN VERSION" );
|
||||
|
||||
String installedPath = System.getenv("CATALINA_HOME");
|
||||
@ -1706,18 +1707,37 @@ public class EC2RestServlet extends HttpServlet {
|
||||
|
||||
// [C] Verify the signature
|
||||
// -> getting the query-string in this way maintains its URL encoding
|
||||
EC2RestAuth restAuth = new EC2RestAuth();
|
||||
restAuth.setHostHeader( request.getHeader( "Host" ));
|
||||
String requestUri = request.getRequestURI();
|
||||
|
||||
//If forwarded from another basepath:
|
||||
String forwardedPath = (String) request.getAttribute("javax.servlet.forward.request_uri");
|
||||
if(forwardedPath!=null){
|
||||
requestUri=forwardedPath;
|
||||
}
|
||||
restAuth.setHTTPRequestURI( requestUri);
|
||||
restAuth.setQueryString( request.getQueryString());
|
||||
|
||||
EC2RestAuth restAuth = new EC2RestAuth();
|
||||
restAuth.setHostHeader( request.getHeader( "Host" ));
|
||||
String requestUri = request.getRequestURI();
|
||||
|
||||
// If forwarded from another basepath:
|
||||
String forwardedPath = (String) request.getAttribute("javax.servlet.forward.request_uri");
|
||||
if(forwardedPath!=null){
|
||||
requestUri=forwardedPath;
|
||||
}
|
||||
restAuth.setHTTPRequestURI( requestUri);
|
||||
|
||||
String queryString = request.getQueryString();
|
||||
// getQueryString returns null (does it ever NOT return null for these),
|
||||
// we need to construct queryString to avoid changing the auth code...
|
||||
if (queryString == null) {
|
||||
// construct our idea of a queryString with parameters!
|
||||
Enumeration<?> params = request.getParameterNames();
|
||||
if (params != null) {
|
||||
while(params.hasMoreElements()) {
|
||||
String paramName = (String) params.nextElement();
|
||||
// exclude the signature string obviously. ;)
|
||||
if (paramName.equalsIgnoreCase("Signature")) continue;
|
||||
if (queryString == null)
|
||||
queryString = paramName + "=" + request.getParameter(paramName);
|
||||
else
|
||||
queryString = queryString + "&" + paramName + "=" + URLEncoder.encode(request.getParameter(paramName), "UTF-8");
|
||||
}
|
||||
}
|
||||
}
|
||||
restAuth.setQueryString(queryString);
|
||||
|
||||
if ( restAuth.verifySignature( request.getMethod(), cloudSecretKey, signature, sigMethod )) {
|
||||
UserContext.current().initContext( cloudAccessKey, cloudSecretKey, cloudAccessKey, "REST request", null );
|
||||
return true;
|
||||
|
||||
@ -18,13 +18,16 @@ package com.cloud.bridge.service.core.ec2;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import com.cloud.bridge.service.UserContext;
|
||||
import com.cloud.bridge.service.exception.EC2ServiceException;
|
||||
import com.cloud.bridge.util.DateHelper;
|
||||
import com.cloud.bridge.util.EC2RestAuth;
|
||||
|
||||
public class EC2SnapshotFilterSet {
|
||||
|
||||
@ -121,7 +124,12 @@ public class EC2SnapshotFilterSet {
|
||||
}
|
||||
else if (filterName.equalsIgnoreCase( "status" ))
|
||||
{
|
||||
return containsString( "completed", valueSet );
|
||||
if ( snap.getState().equalsIgnoreCase("backedup"))
|
||||
return containsString( "completed", valueSet );
|
||||
else if (snap.getState().equalsIgnoreCase("creating") || snap.getState().equalsIgnoreCase("backingup"))
|
||||
return containsString( "pending", valueSet );
|
||||
else
|
||||
return containsString( "error", valueSet );
|
||||
}
|
||||
else if (filterName.equalsIgnoreCase( "volume-id" ))
|
||||
{
|
||||
@ -160,11 +168,14 @@ public class EC2SnapshotFilterSet {
|
||||
|
||||
private boolean containsTime( Calendar lookingFor, String[] set ) throws ParseException
|
||||
{
|
||||
lookingFor.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
Date lookingForDate = lookingFor.getTime();
|
||||
for (String s : set) {
|
||||
//System.out.println( "contsinsCalendar: " + lookingFor + " " + set[i] );
|
||||
Calendar toMatch = Calendar.getInstance();
|
||||
toMatch.setTime( DateHelper.parseISO8601DateString( s ));
|
||||
if (0 == lookingFor.compareTo( toMatch )) return true;
|
||||
Calendar toMatch = EC2RestAuth.parseDateString(s);
|
||||
toMatch.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
Date toMatchDate = toMatch.getTime();
|
||||
if ( 0 == lookingForDate.compareTo(toMatchDate)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -285,7 +285,6 @@
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="build-ovm" depends="compile-ovm" />
|
||||
|
||||
<target name="build-server" depends="compile-server">
|
||||
<mkdir dir="${server.dist.dir}" />
|
||||
@ -480,7 +479,7 @@
|
||||
|
||||
<target name="build-servers" depends="-init, build-server" />
|
||||
|
||||
<target name="build-opensource" depends="-init, build-server, build-agent, build-scripts, build-ui, build-ovm, package-oss-systemvm-iso">
|
||||
<target name="build-opensource" depends="-init, build-server, build-agent, build-scripts, build-ui, build-console-proxy, build-ovm, package-oss-systemvm-iso, build-netscaler, build-f5, build-srx, build-dp-user-dispersing, build-dp-user-concentrated-pod, build-host-allocator-random, build-user-authenticator-ldap">
|
||||
<copy overwrite="true" todir="${dist.dir}">
|
||||
<fileset dir="${base.dir}/build/deploy/">
|
||||
<include name="deploy-agent.sh" />
|
||||
@ -586,24 +585,59 @@
|
||||
<delete dir="${dist.dir}" />
|
||||
<delete dir="${unittest.dir}"/>
|
||||
</target>
|
||||
|
||||
<!-- ===================== Ovm.Jar ===================== -->
|
||||
<property name="ovm.jar" value="cloud-ovm.jar" />
|
||||
<property name="ovm.dir" location="${base.dir}/ovm" />
|
||||
<property name="ovm-scripts.dir" location="${ovm.dir}/scripts" />
|
||||
<path id="ovm.classpath" >
|
||||
<path refid="deps.classpath" />
|
||||
<path refid="dist.classpath" />
|
||||
</path>
|
||||
<target name="compile-ovm" depends="-init, compile-server" description="Compile OVM">
|
||||
<compile-java jar.name="${ovm.jar}" top.dir="${ovm.dir}" classpath="ovm.classpath" />
|
||||
</target>
|
||||
|
||||
<target name="compile-all" description="Compile all of the jars" depends="compile-utils, compile-api, compile-core, compile-server, compile-ovm"/>
|
||||
<target name="compile-all" description="Compile all of the jars" depends="compile-utils, compile-api, compile-core, compile-server, compile-ovm, compile-netscaler, compile-f5, compile-srx, compile-dp-user-dispersing, compile-dp-user-concentrated-pod, compile-host-allocator-random, compile-host-allocator-random"/>
|
||||
|
||||
<target name="clean-all" depends="clean, clean-awsapi" description="Clean all of the generated files, including dependency cache and javadoc">
|
||||
<delete dir="${target.dir}" />
|
||||
</target>
|
||||
|
||||
<!-- ===================== Ovm.Jar ===================== -->
|
||||
<target name="compile-ovm" depends="-init, compile-server" description="Compile OVM">
|
||||
<ant antfile="${base.dir}/plugins/hypervisors/ovm/build.xml" target="build"/>
|
||||
</target>
|
||||
<target name="build-ovm" depends="compile-ovm" />
|
||||
|
||||
<!-- =====================cloud-dp-user-dispersing.Jar ===================== -->
|
||||
<target name="compile-dp-user-dispersing" depends="-init, compile-server" description="Compile dp-user-dispersing">
|
||||
<ant antfile="${base.dir}/plugins/deployment-planners/user-dispersing/build.xml" target="build"/>
|
||||
</target>
|
||||
<target name="build-dp-user-dispersing" depends="compile-dp-user-dispersing" />
|
||||
|
||||
<!-- =====================cloud-dp-user-concentrated-pod.Jar ===================== -->
|
||||
<target name="compile-dp-user-concentrated-pod" depends="-init, compile-server" description="Compile ">
|
||||
<ant antfile="${base.dir}/plugins/deployment-planners/user-concentrated-pod/build.xml" target="build"/>
|
||||
</target>
|
||||
<target name="build-dp-user-concentrated-pod" depends="compile-dp-user-concentrated-pod" />
|
||||
|
||||
<!-- =====================cloud-host-allocator-random.jar ===================== -->
|
||||
<target name="compile-host-allocator-random" depends="-init, compile-server" description="Compile ">
|
||||
<ant antfile="${base.dir}/plugins/host-allocators/random/build.xml" target="build"/>
|
||||
</target>
|
||||
<target name="build-host-allocator-random" depends="compile-host-allocator-random" />
|
||||
|
||||
<!-- =====================cloud-user-authenticator-ldap.jar ===================== -->
|
||||
<target name="compile-user-authenticator-ldap" depends="-init, compile-server" description="Compile ">
|
||||
<ant antfile="${base.dir}/plugins/user-authenticators/ldap/build.xml" target="build"/>
|
||||
</target>
|
||||
<target name="build-user-authenticator-ldap" depends="compile-user-authenticator-ldap" />
|
||||
|
||||
<!-- ===================== Cloud-Plugin-Netscaler.Jar ===================== -->
|
||||
<target name="compile-netscaler" depends="-init, compile-server" description="Compile NetScaler plugin">
|
||||
<ant antfile="${base.dir}/plugins/network-elements/netscaler/build.xml" target="build"/>
|
||||
</target>
|
||||
<target name="build-netscaler" depends="compile-netscaler"/>
|
||||
|
||||
<!-- ===================== Cloud-Plugin-F5.Jar ===================== -->
|
||||
<target name="compile-f5" depends="-init, compile-server" description="Compile F5 plugin">
|
||||
<ant antfile="${base.dir}/plugins/network-elements/f5/build.xml" target="build"/>
|
||||
</target>
|
||||
<target name="build-f5" depends="compile-f5"/>
|
||||
|
||||
<!-- ===================== Cloud-Plugin-Srx.Jar ===================== -->
|
||||
<target name="compile-srx" depends="-init, compile-server" description="Compile SRX plugin">
|
||||
<ant antfile="${base.dir}/plugins/network-elements/juniper-srx/build.xml" target="build"/>
|
||||
</target>
|
||||
<target name="build-srx" depends="compile-srx"/>
|
||||
|
||||
</project>
|
||||
|
||||
|
||||
|
||||
@ -73,7 +73,7 @@
|
||||
<manifest>
|
||||
<attribute name="Class-Path" value="" />
|
||||
<attribute name="Built-By" value="${built.by}" />
|
||||
<attribute name="Specification-Title" value="VMOps Cloud Stack" />
|
||||
<attribute name="Specification-Title" value="Apache Cloud Stack" />
|
||||
<attribute name="Specification-Version" value="${impl.version}" />
|
||||
<attribute name="Specification-Vendor" value="${company.name}" />
|
||||
<attribute name="Implementation-Title" value="@{jar.name}" />
|
||||
|
||||
@ -36,8 +36,6 @@
|
||||
<property name="unittest.target.dir" location="${unittest.dir}/classes"/>
|
||||
<property name="unittest.jar.dir" location="${unittest.dir}/jar"/>
|
||||
<property name="ovm.dir" location="${base.dir}/ovm" />
|
||||
<property name="ovm-scripts.dir" location="${ovm.dir}/scripts" />
|
||||
|
||||
|
||||
<!-- directories for api doc -->
|
||||
<property name="api.docs.dir" location="${dist.dir}/apidocs" />
|
||||
@ -163,11 +161,7 @@
|
||||
</target>
|
||||
|
||||
<target name="deploy-ovm" >
|
||||
<copy todir="${server.deploy.to.dir}/webapps/client/WEB-INF/lib/scripts">
|
||||
<fileset dir="${ovm-scripts.dir}">
|
||||
<include name="**/*"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<ant antfile="${base.dir}/plugins/hypervisors/ovm/build.xml" target="deploy-ovm"/>
|
||||
</target>
|
||||
|
||||
<target name="deploy-server" depends="deploy-common, deploy-ovm, deploy-awsapi" >
|
||||
|
||||
@ -226,6 +226,7 @@
|
||||
<include name="${api.jar}" />
|
||||
<include name="${vmware-base.jar}" />
|
||||
</zipfileset>
|
||||
<zipfileset dir="${console-proxy.dist.dir}" filemode="555"/>
|
||||
<zipfileset dir="${scripts.dir}/storage/secondary" prefix="scripts/storage/secondary" filemode="555">
|
||||
<exclude name="**/.project" />
|
||||
<exclude name="**/.classpath" />
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
DBUSER=cloud
|
||||
DBPW=cloud
|
||||
MSLOG=vmops.log
|
||||
APISERVERLOG=api.log
|
||||
DBHOST=localhost
|
||||
AGENTLOGDIR=logs
|
||||
AGENTLOG=logs/agent.log
|
||||
MSMNTDIR=/mnt
|
||||
COMPONENTS-SPEC=components-premium.xml
|
||||
AWSAPILOG=awsapi.log
|
||||
@ -333,6 +333,7 @@ addNetworkDevice=com.cloud.api.commands.AddNetworkDeviceCmd;1
|
||||
listNetworkDevice=com.cloud.api.commands.ListNetworkDeviceCmd;1
|
||||
deleteNetworkDevice=com.cloud.api.commands.DeleteNetworkDeviceCmd;1
|
||||
|
||||
<<<<<<< HEAD
|
||||
### Network Devices commands
|
||||
addNetworkDevice=com.cloud.api.commands.AddNetworkDeviceCmd;1
|
||||
listNetworkDevice=com.cloud.api.commands.ListNetworkDeviceCmd;1
|
||||
@ -364,4 +365,9 @@ listNetworkACLs=com.cloud.api.commands.ListNetworkACLsCmd;15
|
||||
#### Static route commands
|
||||
createStaticRoute=com.cloud.api.commands.CreateStaticRouteCmd;15
|
||||
deleteStaticRoute=com.cloud.api.commands.DeleteStaticRouteCmd;15
|
||||
listStaticRoutes=com.cloud.api.commands.ListStaticRoutesCmd;15
|
||||
listStaticRoutes=com.cloud.api.commands.ListStaticRoutesCmd;15
|
||||
|
||||
#### Tags commands
|
||||
createTags=com.cloud.api.commands.CreateTagsCmd;15
|
||||
deleteTags=com.cloud.api.commands.DeleteTagsCmd;15
|
||||
listTags=com.cloud.api.commands.ListTagsCmd;15
|
||||
|
||||
@ -160,6 +160,10 @@
|
||||
<adapter name="BasicAgentAuthorizer" class="com.cloud.agent.manager.authn.impl.BasicAgentAuthManager"/>
|
||||
</adapters>
|
||||
<pluggableservice name="VirtualRouterElementService" key="com.cloud.network.element.VirtualRouterElementService" class="com.cloud.network.element.VirtualRouterElement"/>
|
||||
<pluggableservice name="NetscalerExternalLoadBalancerElementService" key="com.cloud.network.element.NetscalerLoadBalancerElementService" class="com.cloud.network.element.NetscalerElement"/>
|
||||
<pluggableservice name="F5ExternalLoadBalancerElementService" key="com.cloud.network.element.F5ExternalLoadBalancerElementService" class="com.cloud.network.element.F5ExternalLoadBalancerElement"/>
|
||||
<pluggableservice name="JuniperSRXFirewallElementService" key="com.cloud.network.element.JuniperSRXFirewallElementService" class="com.cloud.network.element.JuniperSRXExternalFirewallElement"/>
|
||||
<dao name="NetScalerPodDao" class="com.cloud.network.dao.NetScalerPodDaoImpl" singleton="false"/>
|
||||
</management-server>
|
||||
|
||||
<configuration-server class="com.cloud.server.ConfigurationServerImpl">
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
<!-- A time/date based rolling appender -->
|
||||
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="cloud.log"/>
|
||||
<param name="File" value="/var/log/cloud/systemvm.log"/>
|
||||
<param name="Append" value="true"/>
|
||||
<param name="Threshold" value="DEBUG"/>
|
||||
|
||||
|
||||
@ -1133,6 +1133,27 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
||||
return cdromVBD;
|
||||
}
|
||||
|
||||
protected void destroyPatchVbd(Connection conn, String vmName) throws XmlRpcException, XenAPIException {
|
||||
try {
|
||||
if( !vmName.startsWith("r-") && !vmName.startsWith("s-") && !vmName.startsWith("v-") ) {
|
||||
return;
|
||||
}
|
||||
Set<VM> vms = VM.getByNameLabel(conn, vmName);
|
||||
for ( VM vm : vms ) {
|
||||
Set<VBD> vbds = vm.getVBDs(conn);
|
||||
for( VBD vbd : vbds ) {
|
||||
if (vbd.getType(conn) == Types.VbdType.CD ) {
|
||||
vbd.eject(conn);
|
||||
vbd.destroy(conn);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("Cannot destory CD-ROM device for VM " + vmName + " due to " + e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
protected CheckSshAnswer execute(CheckSshCommand cmd) {
|
||||
Connection conn = getConnection();
|
||||
String vmName = cmd.getName();
|
||||
@ -1148,6 +1169,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
||||
if (result != null) {
|
||||
return new CheckSshAnswer(cmd, "Can not ping System vm " + vmName + "due to:" + result);
|
||||
}
|
||||
destroyPatchVbd(conn, vmName);
|
||||
} catch (Exception e) {
|
||||
return new CheckSshAnswer(cmd, e);
|
||||
}
|
||||
@ -2712,7 +2734,15 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
||||
callHostPlugin(conn, "vmopsSnapshot", "unmountSnapshotsDir", "dcId", dcId.toString());
|
||||
|
||||
setupLinkLocalNetwork(conn);
|
||||
|
||||
// try to destroy CD-ROM device for all system VMs on this host
|
||||
try {
|
||||
Host host = Host.getByUuid(conn, _host.uuid);
|
||||
Set<VM> vms = host.getResidentVMs(conn);
|
||||
for ( VM vm : vms ) {
|
||||
destroyPatchVbd(conn, vm.getNameLabel(conn));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
boolean result = cleanupHaltedVms(conn);
|
||||
if (!result) {
|
||||
|
||||
@ -39,7 +39,6 @@ import org.apache.commons.httpclient.auth.AuthScope;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.commons.httpclient.params.HttpMethodParams;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jnetpcap.util.resolver.Resolver.ResolverType;
|
||||
|
||||
import com.cloud.agent.api.storage.DownloadCommand.Proxy;
|
||||
import com.cloud.agent.api.storage.DownloadCommand.ResourceType;
|
||||
|
||||
0
debian/cloud-console-proxy.config
vendored
0
debian/cloud-console-proxy.config
vendored
2
debian/control
vendored
2
debian/control
vendored
@ -142,7 +142,7 @@ Provides: vmops-agent
|
||||
Conflicts: vmops-agent
|
||||
Replaces: vmops-agent
|
||||
Architecture: any
|
||||
Depends: openjdk-6-jre, cloud-utils (= ${source:Version}), cloud-core (= ${source:Version}), cloud-agent-deps (= ${source:Version}), python, cloud-python (= ${source:Version}), cloud-agent-libs (= ${source:Version}), cloud-agent-scripts (= ${source:Version}), libcommons-httpclient-java, libcommons-collections-java, libcommons-dbcp-java, libcommons-pool-java, libcommons-logging-java, libvirt0, cloud-daemonize, sysvinit-utils, chkconfig, qemu-kvm, libvirt-bin, uuid-runtime, rsync, grep, iproute, jnetpcap, ebtables, vlan, libcglib-java, libcommons-httpclient-java, libservlet2.5-java, liblog4j1.2-java, libjna-java, wget
|
||||
Depends: openjdk-6-jre, cloud-utils (= ${source:Version}), cloud-core (= ${source:Version}), cloud-agent-deps (= ${source:Version}), python, cloud-python (= ${source:Version}), cloud-agent-libs (= ${source:Version}), cloud-agent-scripts (= ${source:Version}), libcommons-httpclient-java, libcommons-collections-java, libcommons-dbcp-java, libcommons-pool-java, libcommons-logging-java, libvirt0, cloud-daemonize, sysvinit-utils, chkconfig, qemu-kvm, libvirt-bin, uuid-runtime, rsync, grep, iproute, ebtables, vlan, libcglib-java, libcommons-httpclient-java, libservlet2.5-java, liblog4j1.2-java, libjna-java, wget
|
||||
Description: CloudStack agent
|
||||
The CloudStack agent is in charge of managing shared computing resources in
|
||||
a CloudStack Cloud Stack-powered cloud. Install this package if this computer
|
||||
|
||||
10
plugins/deployment-planners/user-concentrated-pod/.classpath
Executable file
10
plugins/deployment-planners/user-concentrated-pod/.classpath
Executable file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/server"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
plugins/deployment-planners/user-concentrated-pod/.project
Executable file
17
plugins/deployment-planners/user-concentrated-pod/.project
Executable file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>user-concentrated-pod-dp</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
128
plugins/deployment-planners/user-concentrated-pod/build.xml
Executable file
128
plugins/deployment-planners/user-concentrated-pod/build.xml
Executable file
@ -0,0 +1,128 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
|
||||
<project name="Cloud Stack User Concentrated Pod Deployment Planner" default="help" basedir=".">
|
||||
<description>
|
||||
Cloud Stack ant build file
|
||||
</description>
|
||||
|
||||
<dirname property="dp-user-concentrated-pod.base.dir" file="${ant.file.Cloud Stack User Concentrated Pod Deployment Planner}/"/>
|
||||
<!-- This directory must be set -->
|
||||
<property name="top.dir" location="${dp-user-concentrated-pod.base.dir}/../../.."/>
|
||||
<property name="build.dir" location="${top.dir}/build"/>
|
||||
|
||||
<echo message="build.dir=${build.dir}; top.dir=${top.dir}; dp-user-concentrated-pod.base.dir=${dp-user-concentrated-pod.base.dir}"/>
|
||||
|
||||
<!-- Import anything that the user wants to set-->
|
||||
<!-- Import properties files and environment variables here -->
|
||||
|
||||
<property environment="env" />
|
||||
|
||||
<condition property="build-cloud.properties.file" value="${build.dir}/override/build-cloud.properties" else="${build.dir}/build-cloud.properties">
|
||||
<available file="${build.dir}/override/build-cloud.properties" />
|
||||
</condition>
|
||||
|
||||
<condition property="cloud.properties.file" value="${build.dir}/override/cloud.properties" else="${build.dir}/cloud.properties">
|
||||
<available file="${build.dir}/override/cloud.properties" />
|
||||
</condition>
|
||||
|
||||
<condition property="override.file" value="${build.dir}/override/replace.properties" else="${build.dir}/replace.properties">
|
||||
<available file="${build.dir}/override/replace.properties" />
|
||||
</condition>
|
||||
|
||||
<echo message="Using build parameters from ${build-cloud.properties.file}" />
|
||||
<property file="${build-cloud.properties.file}" />
|
||||
|
||||
<echo message="Using company info from ${cloud.properties.file}" />
|
||||
<property file="${cloud.properties.file}" />
|
||||
|
||||
<echo message="Using override file from ${override.file}" />
|
||||
<property file="${override.file}" />
|
||||
|
||||
<property file="${build.dir}/build.number" />
|
||||
|
||||
<!-- In case these didn't get defined in the build-cloud.properties -->
|
||||
<property name="branding.name" value="default" />
|
||||
<property name="deprecation" value="off" />
|
||||
<property name="target.compat.version" value="1.6" />
|
||||
<property name="source.compat.version" value="1.6" />
|
||||
<property name="debug" value="true" />
|
||||
<property name="debuglevel" value="lines,source"/>
|
||||
|
||||
<echo message="target.dir=${target.dir}; top.dir=${top.dir}"/>
|
||||
<!-- directories for build and distribution -->
|
||||
<property name="target.dir" location="${top.dir}/target" />
|
||||
<property name="classes.dir" location="${target.dir}/classes" />
|
||||
<property name="jar.dir" location="${target.dir}/jar" />
|
||||
<property name="dep.cache.dir" location="${target.dir}/dep-cache" />
|
||||
<property name="build.log" location="${target.dir}/ant_verbose.txt" />
|
||||
|
||||
<property name="deps.dir" location="${top.dir}/deps" />
|
||||
|
||||
<property name="dp-user-concentrated-pod.jar" value="cloud-dp-user-concentrated-pod.jar" />
|
||||
<property name="dp-user-concentrated-pod-scripts.dir" location="${dp-user-concentrated-pod.base.dir}/scripts" />
|
||||
|
||||
<import file="${build.dir}/build-common.xml"/>
|
||||
|
||||
<echo message="target.dir=${target.dir}; top.dir=${top.dir}"/>
|
||||
|
||||
<!-- This section needs to be replaced by some kind of dependency library-->
|
||||
<path id="deps.classpath">
|
||||
<!--filelist files="${deps.classpath}" /-->
|
||||
<fileset dir="${deps.dir}" erroronmissingdir="false">
|
||||
<include name="*.jar" />
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<path id="cloudstack.classpath">
|
||||
<fileset dir="${jar.dir}">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<path id="dp-user-concentrated-pod.classpath">
|
||||
<path refid="deps.classpath"/>
|
||||
<path refid="cloudstack.classpath"/>
|
||||
</path>
|
||||
|
||||
<!-- This section needs to be replaced by some kind of dependency library-->
|
||||
|
||||
|
||||
<target name="init" description="Initialize binaries directory">
|
||||
<mkdir dir="${classes.dir}/${user-concentrated-pod.jar}"/>
|
||||
<mkdir dir="${jar.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="compile-dp-user-concentrated-pod" depends="init" description="Compile user-concentrated-pod">
|
||||
<compile-java jar.name="${dp-user-concentrated-pod.jar}" top.dir="${dp-user-concentrated-pod.base.dir}" classpath="dp-user-concentrated-pod.classpath" />
|
||||
</target>
|
||||
|
||||
<target name="help" description="help">
|
||||
<echo level="info" message="This is the build file for dp-user-concentrated-pod."/>
|
||||
<echo level="info" message="You can do a build by doing ant build or clean by ant clean" />
|
||||
</target>
|
||||
|
||||
<target name="clean-dp-user-concentrated-pod">
|
||||
<delete dir="${classes.dir}/${dp-user-concentrated-pod.jar}"/>
|
||||
</target>
|
||||
|
||||
<target name="build" depends="compile-dp-user-concentrated-pod"/>
|
||||
<target name="clean" depends="clean-dp-user-concentrated-pod"/>
|
||||
|
||||
</project>
|
||||
10
plugins/deployment-planners/user-dispersing/.classpath
Executable file
10
plugins/deployment-planners/user-dispersing/.classpath
Executable file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/server"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
plugins/deployment-planners/user-dispersing/.project
Executable file
17
plugins/deployment-planners/user-dispersing/.project
Executable file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>user-dispersing</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@ -0,0 +1,12 @@
|
||||
#Tue Jun 19 15:34:37 PDT 2012
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
128
plugins/deployment-planners/user-dispersing/build.xml
Executable file
128
plugins/deployment-planners/user-dispersing/build.xml
Executable file
@ -0,0 +1,128 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
|
||||
<project name="Cloud Stack User Dispersing Deployment Planner" default="help" basedir=".">
|
||||
<description>
|
||||
Cloud Stack ant build file
|
||||
</description>
|
||||
|
||||
<dirname property="dp-user-dispersing.base.dir" file="${ant.file.Cloud Stack User Dispersing Deployment Planner}/"/>
|
||||
<!-- This directory must be set -->
|
||||
<property name="top.dir" location="${dp-user-dispersing.base.dir}/../../.."/>
|
||||
<property name="build.dir" location="${top.dir}/build"/>
|
||||
|
||||
<echo message="build.dir=${build.dir}; top.dir=${top.dir}; dp-user-dispersing.base.dir=${dp-user-dispersing.base.dir}"/>
|
||||
|
||||
<!-- Import anything that the user wants to set-->
|
||||
<!-- Import properties files and environment variables here -->
|
||||
|
||||
<property environment="env" />
|
||||
|
||||
<condition property="build-cloud.properties.file" value="${build.dir}/override/build-cloud.properties" else="${build.dir}/build-cloud.properties">
|
||||
<available file="${build.dir}/override/build-cloud.properties" />
|
||||
</condition>
|
||||
|
||||
<condition property="cloud.properties.file" value="${build.dir}/override/cloud.properties" else="${build.dir}/cloud.properties">
|
||||
<available file="${build.dir}/override/cloud.properties" />
|
||||
</condition>
|
||||
|
||||
<condition property="override.file" value="${build.dir}/override/replace.properties" else="${build.dir}/replace.properties">
|
||||
<available file="${build.dir}/override/replace.properties" />
|
||||
</condition>
|
||||
|
||||
<echo message="Using build parameters from ${build-cloud.properties.file}" />
|
||||
<property file="${build-cloud.properties.file}" />
|
||||
|
||||
<echo message="Using company info from ${cloud.properties.file}" />
|
||||
<property file="${cloud.properties.file}" />
|
||||
|
||||
<echo message="Using override file from ${override.file}" />
|
||||
<property file="${override.file}" />
|
||||
|
||||
<property file="${build.dir}/build.number" />
|
||||
|
||||
<!-- In case these didn't get defined in the build-cloud.properties -->
|
||||
<property name="branding.name" value="default" />
|
||||
<property name="deprecation" value="off" />
|
||||
<property name="target.compat.version" value="1.6" />
|
||||
<property name="source.compat.version" value="1.6" />
|
||||
<property name="debug" value="true" />
|
||||
<property name="debuglevel" value="lines,source"/>
|
||||
|
||||
<echo message="target.dir=${target.dir}; top.dir=${top.dir}"/>
|
||||
<!-- directories for build and distribution -->
|
||||
<property name="target.dir" location="${top.dir}/target" />
|
||||
<property name="classes.dir" location="${target.dir}/classes" />
|
||||
<property name="jar.dir" location="${target.dir}/jar" />
|
||||
<property name="dep.cache.dir" location="${target.dir}/dep-cache" />
|
||||
<property name="build.log" location="${target.dir}/ant_verbose.txt" />
|
||||
|
||||
<property name="deps.dir" location="${top.dir}/deps" />
|
||||
|
||||
<property name="dp-user-dispersing.jar" value="cloud-dp-user-dispersing.jar" />
|
||||
<property name="dp-user-dispersing-scripts.dir" location="${dp-user-dispersing.base.dir}/scripts" />
|
||||
|
||||
<import file="${build.dir}/build-common.xml"/>
|
||||
|
||||
<echo message="target.dir=${target.dir}; top.dir=${top.dir}"/>
|
||||
|
||||
<!-- This section needs to be replaced by some kind of dependency library-->
|
||||
<path id="deps.classpath">
|
||||
<!--filelist files="${deps.classpath}" /-->
|
||||
<fileset dir="${deps.dir}" erroronmissingdir="false">
|
||||
<include name="*.jar" />
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<path id="cloudstack.classpath">
|
||||
<fileset dir="${jar.dir}">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<path id="dp-user-dispersing.classpath">
|
||||
<path refid="deps.classpath"/>
|
||||
<path refid="cloudstack.classpath"/>
|
||||
</path>
|
||||
|
||||
<!-- This section needs to be replaced by some kind of dependency library-->
|
||||
|
||||
|
||||
<target name="init" description="Initialize binaries directory">
|
||||
<mkdir dir="${classes.dir}/${dp-user-dispersing.jar}"/>
|
||||
<mkdir dir="${jar.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="compile-dp-user-dispersing" depends="init" description="Compile dp-user-dispersing">
|
||||
<compile-java jar.name="${dp-user-dispersing.jar}" top.dir="${dp-user-dispersing.base.dir}" classpath="dp-user-dispersing.classpath" />
|
||||
</target>
|
||||
|
||||
<target name="help" description="help">
|
||||
<echo level="info" message="This is the build file for dp-user-dispersing"/>
|
||||
<echo level="info" message="You can do a build by doing ant build or clean by ant clean" />
|
||||
</target>
|
||||
|
||||
<target name="clean-dp-user-dispersing">
|
||||
<delete dir="${classes.dir}/${dp-user-dispersing.jar}"/>
|
||||
</target>
|
||||
|
||||
<target name="build" depends="compile-dp-user-dispersing"/>
|
||||
<target name="clean" depends="clean-dp-user-dispersing"/>
|
||||
|
||||
</project>
|
||||
10
plugins/host-allocators/random/.classpath
Executable file
10
plugins/host-allocators/random/.classpath
Executable file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/server"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
plugins/host-allocators/random/.project
Executable file
17
plugins/host-allocators/random/.project
Executable file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>random-host-allocator</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
128
plugins/host-allocators/random/build.xml
Executable file
128
plugins/host-allocators/random/build.xml
Executable file
@ -0,0 +1,128 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
|
||||
<project name="Cloud Stack Random Host Allocator" default="help" basedir=".">
|
||||
<description>
|
||||
Cloud Stack ant build file
|
||||
</description>
|
||||
|
||||
<dirname property="host-allocator-random.base.dir" file="${ant.file.Cloud Stack Random Host Allocator}/"/>
|
||||
<!-- This directory must be set -->
|
||||
<property name="top.dir" location="${host-allocator-random.base.dir}/../../.."/>
|
||||
<property name="build.dir" location="${top.dir}/build"/>
|
||||
|
||||
<echo message="build.dir=${build.dir}; top.dir=${top.dir}; host-allocator-random.base.dir=${host-allocator-random.base.dir}"/>
|
||||
|
||||
<!-- Import anything that the user wants to set-->
|
||||
<!-- Import properties files and environment variables here -->
|
||||
|
||||
<property environment="env" />
|
||||
|
||||
<condition property="build-cloud.properties.file" value="${build.dir}/override/build-cloud.properties" else="${build.dir}/build-cloud.properties">
|
||||
<available file="${build.dir}/override/build-cloud.properties" />
|
||||
</condition>
|
||||
|
||||
<condition property="cloud.properties.file" value="${build.dir}/override/cloud.properties" else="${build.dir}/cloud.properties">
|
||||
<available file="${build.dir}/override/cloud.properties" />
|
||||
</condition>
|
||||
|
||||
<condition property="override.file" value="${build.dir}/override/replace.properties" else="${build.dir}/replace.properties">
|
||||
<available file="${build.dir}/override/replace.properties" />
|
||||
</condition>
|
||||
|
||||
<echo message="Using build parameters from ${build-cloud.properties.file}" />
|
||||
<property file="${build-cloud.properties.file}" />
|
||||
|
||||
<echo message="Using company info from ${cloud.properties.file}" />
|
||||
<property file="${cloud.properties.file}" />
|
||||
|
||||
<echo message="Using override file from ${override.file}" />
|
||||
<property file="${override.file}" />
|
||||
|
||||
<property file="${build.dir}/build.number" />
|
||||
|
||||
<!-- In case these didn't get defined in the build-cloud.properties -->
|
||||
<property name="branding.name" value="default" />
|
||||
<property name="deprecation" value="off" />
|
||||
<property name="target.compat.version" value="1.6" />
|
||||
<property name="source.compat.version" value="1.6" />
|
||||
<property name="debug" value="true" />
|
||||
<property name="debuglevel" value="lines,source"/>
|
||||
|
||||
<echo message="target.dir=${target.dir}; top.dir=${top.dir}"/>
|
||||
<!-- directories for build and distribution -->
|
||||
<property name="target.dir" location="${top.dir}/target" />
|
||||
<property name="classes.dir" location="${target.dir}/classes" />
|
||||
<property name="jar.dir" location="${target.dir}/jar" />
|
||||
<property name="dep.cache.dir" location="${target.dir}/dep-cache" />
|
||||
<property name="build.log" location="${target.dir}/ant_verbose.txt" />
|
||||
|
||||
<property name="deps.dir" location="${top.dir}/deps" />
|
||||
|
||||
<property name="host-allocator-random.jar" value="cloud-host-allocator-random.jar" />
|
||||
<property name="host-allocator-random-scripts.dir" location="${host-allocator-random.base.dir}/scripts" />
|
||||
|
||||
<import file="${build.dir}/build-common.xml"/>
|
||||
|
||||
<echo message="target.dir=${target.dir}; top.dir=${top.dir}"/>
|
||||
|
||||
<!-- This section needs to be replaced by some kind of dependency library-->
|
||||
<path id="deps.classpath">
|
||||
<!--filelist files="${deps.classpath}" /-->
|
||||
<fileset dir="${deps.dir}" erroronmissingdir="false">
|
||||
<include name="*.jar" />
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<path id="cloudstack.classpath">
|
||||
<fileset dir="${jar.dir}">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<path id="host-allocator-random.classpath">
|
||||
<path refid="deps.classpath"/>
|
||||
<path refid="cloudstack.classpath"/>
|
||||
</path>
|
||||
|
||||
<!-- This section needs to be replaced by some kind of dependency library-->
|
||||
|
||||
|
||||
<target name="init" description="Initialize binaries directory">
|
||||
<mkdir dir="${classes.dir}/${host-allocator-random.jar}"/>
|
||||
<mkdir dir="${jar.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="compile-host-allocator-random" depends="init" description="Compile host-allocator-random">
|
||||
<compile-java jar.name="${host-allocator-random.jar}" top.dir="${host-allocator-random.base.dir}" classpath="host-allocator-random.classpath" />
|
||||
</target>
|
||||
|
||||
<target name="help" description="help">
|
||||
<echo level="info" message="This is the build file for host-allocator-random"/>
|
||||
<echo level="info" message="You can do a build by doing ant build or clean by ant clean" />
|
||||
</target>
|
||||
|
||||
<target name="clean-host-allocator-random">
|
||||
<delete dir="${classes.dir}/${host-allocator-random.jar}"/>
|
||||
</target>
|
||||
|
||||
<target name="build" depends="compile-host-allocator-random"/>
|
||||
<target name="clean" depends="clean-host-allocator-random"/>
|
||||
|
||||
</project>
|
||||
0
ovm/.classpath → plugins/hypervisors/ovm/.classpath
Normal file → Executable file
0
ovm/.classpath → plugins/hypervisors/ovm/.classpath
Normal file → Executable file
@ -1,23 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ovm</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.python.pydev.PyDevBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.python.pydev.pythonNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ovm</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.python.pydev.PyDevBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.python.pydev.pythonNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
136
plugins/hypervisors/ovm/build.xml
Executable file
136
plugins/hypervisors/ovm/build.xml
Executable file
@ -0,0 +1,136 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
|
||||
<project name="Cloud Stack OVM" default="help" basedir=".">
|
||||
<description>
|
||||
Cloud Stack ant build file
|
||||
</description>
|
||||
|
||||
<dirname property="ovm.base.dir" file="${ant.file.Cloud Stack OVM}/"/>
|
||||
<!-- This directory must be set -->
|
||||
<property name="top.dir" location="${ovm.base.dir}/../../.."/>
|
||||
<property name="build.dir" location="${top.dir}/build"/>
|
||||
|
||||
<echo message="build.dir=${build.dir}; top.dir=${top.dir}; ovm.base.dir=${ovm.base.dir}"/>
|
||||
|
||||
<!-- Import anything that the user wants to set-->
|
||||
<!-- Import properties files and environment variables here -->
|
||||
|
||||
<property environment="env" />
|
||||
|
||||
<condition property="build-cloud.properties.file" value="${build.dir}/override/build-cloud.properties" else="${build.dir}/build-cloud.properties">
|
||||
<available file="${build.dir}/override/build-cloud.properties" />
|
||||
</condition>
|
||||
|
||||
<condition property="cloud.properties.file" value="${build.dir}/override/cloud.properties" else="${build.dir}/cloud.properties">
|
||||
<available file="${build.dir}/override/cloud.properties" />
|
||||
</condition>
|
||||
|
||||
<condition property="override.file" value="${build.dir}/override/replace.properties" else="${build.dir}/replace.properties">
|
||||
<available file="${build.dir}/override/replace.properties" />
|
||||
</condition>
|
||||
|
||||
<echo message="Using build parameters from ${build-cloud.properties.file}" />
|
||||
<property file="${build-cloud.properties.file}" />
|
||||
|
||||
<echo message="Using company info from ${cloud.properties.file}" />
|
||||
<property file="${cloud.properties.file}" />
|
||||
|
||||
<echo message="Using override file from ${override.file}" />
|
||||
<property file="${override.file}" />
|
||||
|
||||
<property file="${build.dir}/build.number" />
|
||||
|
||||
<!-- In case these didn't get defined in the build-cloud.properties -->
|
||||
<property name="branding.name" value="default" />
|
||||
<property name="deprecation" value="off" />
|
||||
<property name="target.compat.version" value="1.6" />
|
||||
<property name="source.compat.version" value="1.6" />
|
||||
<property name="debug" value="true" />
|
||||
<property name="debuglevel" value="lines,source"/>
|
||||
|
||||
<echo message="target.dir=${target.dir}; top.dir=${top.dir}"/>
|
||||
<!-- directories for build and distribution -->
|
||||
<property name="target.dir" location="${top.dir}/target" />
|
||||
<property name="classes.dir" location="${target.dir}/classes" />
|
||||
<property name="jar.dir" location="${target.dir}/jar" />
|
||||
<property name="dep.cache.dir" location="${target.dir}/dep-cache" />
|
||||
<property name="build.log" location="${target.dir}/ant_verbose.txt" />
|
||||
|
||||
<property name="deps.dir" location="${top.dir}/deps" />
|
||||
|
||||
<property name="ovm.jar" value="cloud-ovm.jar" />
|
||||
<property name="ovm-scripts.dir" location="${base.dir}/plugins/hypervisors/ovm/scripts" />
|
||||
|
||||
<import file="${build.dir}/build-common.xml"/>
|
||||
|
||||
<echo message="target.dir=${target.dir}; top.dir=${top.dir}"/>
|
||||
|
||||
<!-- This section needs to be replaced by some kind of dependency library-->
|
||||
<path id="deps.classpath">
|
||||
<!--filelist files="${deps.classpath}" /-->
|
||||
<fileset dir="${deps.dir}" erroronmissingdir="false">
|
||||
<include name="*.jar" />
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<path id="cloudstack.classpath">
|
||||
<fileset dir="${jar.dir}">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<path id="ovm.classpath">
|
||||
<path refid="deps.classpath"/>
|
||||
<path refid="cloudstack.classpath"/>
|
||||
</path>
|
||||
|
||||
<!-- This section needs to be replaced by some kind of dependency library-->
|
||||
|
||||
<target name="deploy-ovm" >
|
||||
<echo level="info" message="Copying OVM scripts from ${ovm-scripts.dir} to ${server.deploy.to.dir}/webapps/client/WEB-INF/lib/scripts" />
|
||||
<copy todir="${server.deploy.to.dir}/webapps/client/WEB-INF/lib/scripts">
|
||||
<fileset dir="${ovm-scripts.dir}">
|
||||
<include name="**/*"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="init" description="Initialize binaries directory">
|
||||
<mkdir dir="${classes.dir}/${ovm.jar}"/>
|
||||
<mkdir dir="${jar.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="compile-ovm" depends="init" description="Compile OVM">
|
||||
<compile-java jar.name="${ovm.jar}" top.dir="${ovm.base.dir}" classpath="ovm.classpath" />
|
||||
</target>
|
||||
|
||||
<target name="help" description="help">
|
||||
<echo level="info" message="This is the build file for OVM"/>
|
||||
<echo level="info" message="You can do a build by doing ant build or clean by ant clean" />
|
||||
</target>
|
||||
|
||||
<target name="clean-ovm">
|
||||
<delete dir="${classes.dir}/${ovm.jar}"/>
|
||||
</target>
|
||||
|
||||
<target name="build" depends="compile-ovm"/>
|
||||
<target name="clean" depends="clean-ovm"/>
|
||||
|
||||
</project>
|
||||
0
ovm/scripts/vm/hypervisor/ovm/ConfigFileOps.py → plugins/hypervisors/ovm/scripts/vm/hypervisor/ovm/ConfigFileOps.py
Normal file → Executable file
0
ovm/scripts/vm/hypervisor/ovm/ConfigFileOps.py → plugins/hypervisors/ovm/scripts/vm/hypervisor/ovm/ConfigFileOps.py
Normal file → Executable file
0
ovm/scripts/vm/hypervisor/ovm/OvmDiskModule.py → plugins/hypervisors/ovm/scripts/vm/hypervisor/ovm/OvmDiskModule.py
Normal file → Executable file
0
ovm/scripts/vm/hypervisor/ovm/OvmDiskModule.py → plugins/hypervisors/ovm/scripts/vm/hypervisor/ovm/OvmDiskModule.py
Normal file → Executable file
0
ovm/scripts/vm/hypervisor/ovm/OvmDispatcher.py → plugins/hypervisors/ovm/scripts/vm/hypervisor/ovm/OvmDispatcher.py
Normal file → Executable file
0
ovm/scripts/vm/hypervisor/ovm/OvmDispatcher.py → plugins/hypervisors/ovm/scripts/vm/hypervisor/ovm/OvmDispatcher.py
Normal file → Executable file
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user