From 415bc8ae20f708b9d8d964ba5bb0d5a4ee92962d Mon Sep 17 00:00:00 2001
From: Alex Huang
Date: Tue, 24 Aug 2010 14:40:29 -0700
Subject: [PATCH 01/43] bug 5764: checkin before I switch to work on 2.1.x
---
api/src/com/cloud/network/Network.java | 3 +-
.../xen/resource/CitrixResourceBase.java | 2 +-
.../consoleproxy/ConsoleProxyManagerImpl.java | 2 +-
.../xen/discoverer/XcpServerDiscoverer.java | 9 +++--
.../com/cloud/network/NetworkManagerImpl.java | 36 ++++++++++++++++---
.../com/cloud/network/NetworkProfileVO.java | 15 ++++++--
.../cloud/network/NetworkProfilerImpl.java | 1 +
.../cloud/network/dao/NetworkProfileDao.java | 4 ++-
.../network/dao/NetworkProfileDaoImpl.java | 24 ++++++++++++-
setup/db/create-schema.sql | 1 +
10 files changed, 81 insertions(+), 16 deletions(-)
diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java
index c5c35b0d13b..25d77faa11d 100644
--- a/api/src/com/cloud/network/Network.java
+++ b/api/src/com/cloud/network/Network.java
@@ -44,6 +44,7 @@ public class Network {
Native,
Vlan,
Vswitch,
+ LinkLocal,
Vnet;
};
@@ -54,7 +55,7 @@ public class Network {
Public,
Guest,
Storage,
- LinkLocal,
+ Control,
Vpn,
Management
};
diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
index 8b16dec93c9..d88b50528cd 100644
--- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
+++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
@@ -700,7 +700,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
Pair getNetworkForTraffic(Connection conn, TrafficType type) throws XenAPIException, XmlRpcException {
if (type == TrafficType.Guest) {
return new Pair(Network.getByUuid(conn, _host.guestNetwork), _host.guestPif);
- } else if (type == TrafficType.LinkLocal) {
+ } else if (type == TrafficType.Control) {
return new Pair(Network.getByUuid(conn, _host.linkLocalNetwork), null);
} else if (type == TrafficType.Management) {
return new Pair(Network.getByUuid(conn, _host.privateNetwork), _host.privatePif);
diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
index 8402256a5eb..73cf5e94e49 100644
--- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
+++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
@@ -2357,7 +2357,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
_publicNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_publicNetworkOffering);
_managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmManagementNetwork, TrafficType.Management, null);
_managementNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_managementNetworkOffering);
- _linkLocalNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmLinkLocalNetwork, TrafficType.LinkLocal, null);
+ _linkLocalNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmLinkLocalNetwork, TrafficType.Control, null);
_linkLocalNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_linkLocalNetworkOffering);
_capacityScanScheduler.scheduleAtFixedRate(getCapacityScanTask(), STARTUP_DELAY, _capacityScanInterval, TimeUnit.MILLISECONDS);
diff --git a/server/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java b/server/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java
index cc1fb72b343..049d9a70923 100644
--- a/server/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java
+++ b/server/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java
@@ -53,15 +53,14 @@ import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.xen.resource.CitrixResourceBase;
import com.cloud.hypervisor.xen.resource.XcpServerResource;
import com.cloud.hypervisor.xen.resource.XenServerConnectionPool;
-import com.cloud.hypervisor.xen.resource.XenServerResource;
import com.cloud.resource.Discoverer;
import com.cloud.resource.DiscovererBase;
import com.cloud.resource.ServerResource;
+import com.cloud.storage.Storage.FileSystem;
+import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc;
import com.cloud.storage.VMTemplateVO;
-import com.cloud.storage.Storage.FileSystem;
-import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VMTemplateHostDao;
import com.cloud.storage.template.TemplateInfo;
@@ -383,8 +382,8 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
if(prodBrand.equals("XenCloudPlatform") && prodVersion.equals("0.1.1"))
return new XcpServerResource();
- if(prodBrand.equals("XenServer") && prodVersion.equals("5.6.0"))
- return new XenServerResource();
+// if(prodBrand.equals("XenServer") && prodVersion.equals("5.6.0"))
+// return new XenServerResource();
String msg = "Only support XCP 0.1.1 and Xerver 5.6.0, but this one is " + prodBrand + " " + prodVersion;
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg);
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index e88e1344776..60f7ba6e21a 100644
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -102,6 +102,7 @@ import com.cloud.network.Network.TrafficType;
import com.cloud.network.dao.FirewallRulesDao;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.LoadBalancerDao;
+import com.cloud.network.dao.NetworkProfileDao;
import com.cloud.network.dao.SecurityGroupVMMapDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
@@ -193,6 +194,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
@Inject ServiceOfferingDao _serviceOfferingDao = null;
@Inject UserStatisticsDao _statsDao = null;
@Inject NetworkOfferingDao _networkOfferingDao = null;
+ @Inject NetworkProfileDao _networkProfileDao = null;
Adapters _networkProfilers;
@@ -1835,7 +1837,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
_publicNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_publicNetworkOffering);
_managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmManagementNetwork, TrafficType.Management, null);
_managementNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_managementNetworkOffering);
- _linkLocalNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmLinkLocalNetwork, TrafficType.LinkLocal, null);
+ _linkLocalNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmLinkLocalNetwork, TrafficType.Control, null);
_linkLocalNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_linkLocalNetworkOffering);
_guestNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmGuestNetwork, TrafficType.Guest, GuestIpType.Virtualized);
_guestNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_guestNetworkOffering);
@@ -1848,6 +1850,29 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
return true;
}
+
+ public void setupNetworkProfiles(List offerings, AccountVO account) {
+ List extends NetworkProfile> profiles = null;
+ for (NetworkProfiler profiler : _networkProfilers) {
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Sending network profiles to " + profiler.getName());
+ }
+ profiles = profiler.convert(offerings, account);
+ if (profiles != null) {
+ break;
+ }
+ }
+
+ if (profiles == null) {
+ s_logger.debug("Unable to resolve the network profiles");
+ throw new CloudRuntimeException("Uanble to convert network offerings to network profiles for that account");
+ }
+
+ for (NetworkProfile profile : profiles) {
+ NetworkProfileVO vo = new NetworkProfileVO(profile, account.getId());
+ vo = _networkProfileDao.persist(vo);
+ }
+ }
@Override
public String getName() {
@@ -1861,9 +1886,12 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
offerings.add(_guestNetworkOffering);
offerings.add(_linkLocalNetworkOffering);
offerings.add(_managementNetworkOffering);
-
- for (NetworkProfiler profiler : _networkProfilers) {
- List extends NetworkProfile> profiles = profiler.convert(offerings, _accountMgr.getSystemAccount());
+
+ try {
+ setupNetworkProfiles(offerings, _accountMgr.getSystemAccount());
+ } catch (Exception e) {
+ s_logger.warn("Unable to setup the system network profiles");
+ return false;
}
_executor.scheduleAtFixedRate(new RouterCleanupTask(), _routerCleanupInterval, _routerCleanupInterval, TimeUnit.SECONDS);
_executor.scheduleAtFixedRate(new NetworkUsageTask(), _routerStatsInterval, _routerStatsInterval, TimeUnit.SECONDS);
diff --git a/server/src/com/cloud/network/NetworkProfileVO.java b/server/src/com/cloud/network/NetworkProfileVO.java
index cd9099147ac..05531fd8f5a 100644
--- a/server/src/com/cloud/network/NetworkProfileVO.java
+++ b/server/src/com/cloud/network/NetworkProfileVO.java
@@ -57,8 +57,8 @@ public class NetworkProfileVO implements OwnedBy {
@Enumerated(value=EnumType.STRING)
TrafficType trafficType;
- @Column(name="vlanIds")
- String vlanIds;
+ @Column(name="vlan_id")
+ Long vlanId;
@Column(name="gateway")
String gateway;
@@ -69,6 +69,10 @@ public class NetworkProfileVO implements OwnedBy {
public NetworkProfileVO() {
}
+ public NetworkProfileVO(NetworkProfile that, long accountId) {
+ this(accountId, that.getTrafficType(), that.getMode(), that.getBroadcastDomainType());
+ }
+
public NetworkProfileVO(long accountId, TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType) {
this.accountId = accountId;
this.trafficType = trafficType;
@@ -129,4 +133,11 @@ public class NetworkProfileVO implements OwnedBy {
this.cidr = cidr;
}
+ public Long getVlanId() {
+ return vlanId;
+ }
+
+ public void setVlanId(Long vlanId) {
+ this.vlanId = vlanId;
+ }
}
diff --git a/server/src/com/cloud/network/NetworkProfilerImpl.java b/server/src/com/cloud/network/NetworkProfilerImpl.java
index 22ac017126a..a6ce246242a 100644
--- a/server/src/com/cloud/network/NetworkProfilerImpl.java
+++ b/server/src/com/cloud/network/NetworkProfilerImpl.java
@@ -27,6 +27,7 @@ public class NetworkProfilerImpl extends AdapterBase implements NetworkProfiler
@Override
public List extends NetworkProfile> convert(Collection extends NetworkOffering> networkOfferings, Account owner) {
+ List profiles = _profileDao.listBy(owner.getId());
for (NetworkOffering offering : networkOfferings) {
}
return null;
diff --git a/server/src/com/cloud/network/dao/NetworkProfileDao.java b/server/src/com/cloud/network/dao/NetworkProfileDao.java
index 2938d5de2f3..e2e6c713388 100644
--- a/server/src/com/cloud/network/dao/NetworkProfileDao.java
+++ b/server/src/com/cloud/network/dao/NetworkProfileDao.java
@@ -17,9 +17,11 @@
*/
package com.cloud.network.dao;
+import java.util.List;
+
import com.cloud.network.NetworkProfileVO;
import com.cloud.utils.db.GenericDao;
public interface NetworkProfileDao extends GenericDao {
-
+ List listBy(long accountId);
}
diff --git a/server/src/com/cloud/network/dao/NetworkProfileDaoImpl.java b/server/src/com/cloud/network/dao/NetworkProfileDaoImpl.java
index 09da5628ccb..d41967c5c13 100644
--- a/server/src/com/cloud/network/dao/NetworkProfileDaoImpl.java
+++ b/server/src/com/cloud/network/dao/NetworkProfileDaoImpl.java
@@ -17,8 +17,11 @@
*/
package com.cloud.network.dao;
+import java.util.List;
+
import javax.ejb.Local;
+import com.cloud.network.Network.BroadcastDomainType;
import com.cloud.network.Network.Mode;
import com.cloud.network.Network.TrafficType;
import com.cloud.network.NetworkProfileVO;
@@ -29,6 +32,7 @@ import com.cloud.utils.db.SearchCriteria;
@Local(value=NetworkProfileDao.class)
public class NetworkProfileDaoImpl extends GenericDaoBase implements NetworkProfileDao {
final SearchBuilder ProfileSearch;
+ final SearchBuilder AccountSearch;
protected NetworkProfileDaoImpl() {
super();
@@ -38,10 +42,28 @@ public class NetworkProfileDaoImpl extends GenericDaoBase sc = ProfileSearch.create();
+ sc.setParameters("account", accountId);
+ sc.setParameters("trafficType", trafficType);
+ sc.setParameters("broadcastType", broadcastType);
+
return null;
}
+
+ @Override
+ public List listBy(long accountId) {
+ SearchCriteria sc = AccountSearch.create();
+ sc.setParameters("account", accountId);
+
+ return listActiveBy(sc);
+ }
}
diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql
index c4c28ecb2aa..e9dd4fecdb7 100644
--- a/setup/db/create-schema.sql
+++ b/setup/db/create-schema.sql
@@ -95,6 +95,7 @@ CREATE TABLE `cloud`.`network_profiles` (
`gateway` varchar(15) NOT NULL COMMENT 'gateway for this network profile',
`cidr` varchar(32) NOT NULL COMMENT 'network cidr',
`mode` varchar(32) NOT NULL COMMENT 'How to retrieve ip address in this network',
+ `vlan_id` bigint unsigned NULL COMMENT 'vlan id if the broadcast_domain_type is the vlan',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
From 895fb8516296a899ae5e4244c981b7de33b9ebb5 Mon Sep 17 00:00:00 2001
From: jessica
Date: Tue, 24 Aug 2010 15:48:40 -0700
Subject: [PATCH 02/43] check in for Alex.
---
server/src/com/cloud/network/NetworkManagerImpl.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index 60f7ba6e21a..dcc995448c2 100644
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -1887,12 +1887,12 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
offerings.add(_linkLocalNetworkOffering);
offerings.add(_managementNetworkOffering);
- try {
- setupNetworkProfiles(offerings, _accountMgr.getSystemAccount());
- } catch (Exception e) {
- s_logger.warn("Unable to setup the system network profiles");
- return false;
- }
+ // try {
+ // setupNetworkProfiles(offerings, _accountMgr.getSystemAccount());
+ //} catch (Exception e) {
+ // s_logger.warn("Unable to setup the system network profiles");
+ //return false;
+ //}
_executor.scheduleAtFixedRate(new RouterCleanupTask(), _routerCleanupInterval, _routerCleanupInterval, TimeUnit.SECONDS);
_executor.scheduleAtFixedRate(new NetworkUsageTask(), _routerStatsInterval, _routerStatsInterval, TimeUnit.SECONDS);
return true;
From 49900a8985ba7ba660db77bdb9e956f6b1599195 Mon Sep 17 00:00:00 2001
From: Kelven Yang
Date: Tue, 24 Aug 2010 18:58:38 -0700
Subject: [PATCH 03/43] 1) Add VMDK format 2) Make console proxy servlet
explictly return content-type header for console proxy page (this is a bug
fix change)
---
api/src/com/cloud/storage/Storage.java | 3 ++-
server/src/com/cloud/servlet/ConsoleProxyServlet.java | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/api/src/com/cloud/storage/Storage.java b/api/src/com/cloud/storage/Storage.java
index 106616673b3..24ceb5b3fec 100644
--- a/api/src/com/cloud/storage/Storage.java
+++ b/api/src/com/cloud/storage/Storage.java
@@ -22,7 +22,8 @@ public class Storage {
QCOW2(true, true, false),
RAW(false, false, false),
VHD(true, true, true),
- ISO(false, false, false);
+ ISO(false, false, false),
+ VMDK(true, true, true);
private final boolean thinProvisioned;
private final boolean supportSparse;
diff --git a/server/src/com/cloud/servlet/ConsoleProxyServlet.java b/server/src/com/cloud/servlet/ConsoleProxyServlet.java
index 851860f8a04..03372cbd82a 100644
--- a/server/src/com/cloud/servlet/ConsoleProxyServlet.java
+++ b/server/src/com/cloud/servlet/ConsoleProxyServlet.java
@@ -281,7 +281,7 @@ public class ConsoleProxyServlet extends HttpServlet {
}
private void sendResponse(HttpServletResponse resp, String content) {
- try {
+ try {
resp.getWriter().print(content);
} catch(IOException e) {
if(s_logger.isInfoEnabled())
From 45cb68e7e2861efc613cf0fb037c24698b5252ba Mon Sep 17 00:00:00 2001
From: Kelven Yang
Date: Tue, 24 Aug 2010 22:58:05 -0700
Subject: [PATCH 04/43] add templates.vmware.sql modify build to deploy vmware
database records
---
build/developer.xml | 9 ++++++++-
server/src/com/cloud/servlet/ConsoleProxyServlet.java | 1 +
setup/db/templates.xenserver.sql | 2 --
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/build/developer.xml b/build/developer.xml
index 0928e48dfd6..77d760b2af7 100755
--- a/build/developer.xml
+++ b/build/developer.xml
@@ -169,11 +169,18 @@
+
+
+
-
+
+
+
+
+
diff --git a/server/src/com/cloud/servlet/ConsoleProxyServlet.java b/server/src/com/cloud/servlet/ConsoleProxyServlet.java
index 03372cbd82a..2c364122854 100644
--- a/server/src/com/cloud/servlet/ConsoleProxyServlet.java
+++ b/server/src/com/cloud/servlet/ConsoleProxyServlet.java
@@ -282,6 +282,7 @@ public class ConsoleProxyServlet extends HttpServlet {
private void sendResponse(HttpServletResponse resp, String content) {
try {
+ resp.setContentType("text/html");
resp.getWriter().print(content);
} catch(IOException e) {
if(s_logger.isInfoEnabled())
diff --git a/setup/db/templates.xenserver.sql b/setup/db/templates.xenserver.sql
index 5ecd912f575..0432c97716f 100644
--- a/setup/db/templates.xenserver.sql
+++ b/setup/db/templates.xenserver.sql
@@ -72,6 +72,4 @@ INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (58,
INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (59, 7, 'Other install media', 'Ubuntu');
INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (60, 7, 'Other install media', 'Other');
--- temporarily added for vmware, will be moved when vmware support is fully in-place
-INSERT INTO `cloud`.`host_master`(`type`, `service_address`, `admin`, `password`) VALUES('VSphere', 'vsphere-1.lab.vmops.com', 'Administrator', 'Suite219');
From 6ae72df46a86b797d0562230c76cbbf1a62b2082 Mon Sep 17 00:00:00 2001
From: nit
Date: Wed, 25 Aug 2010 11:44:54 +0530
Subject: [PATCH 05/43] bug 5905: Adding deviceId tag to the ListVolumes
command when the volume is attached. status 5905: closed fixed
---
server/src/com/cloud/api/commands/ListVolumesCmd.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
mode change 100644 => 100755 server/src/com/cloud/api/commands/ListVolumesCmd.java
diff --git a/server/src/com/cloud/api/commands/ListVolumesCmd.java b/server/src/com/cloud/api/commands/ListVolumesCmd.java
old mode 100644
new mode 100755
index b856e4eae2f..1eee0aad45a
--- a/server/src/com/cloud/api/commands/ListVolumesCmd.java
+++ b/server/src/com/cloud/api/commands/ListVolumesCmd.java
@@ -185,8 +185,9 @@ public class ListVolumesCmd extends BaseCmd{
volumeData.add(new Pair(BaseCmd.Properties.VIRTUAL_MACHINE_ID.getName(), vm.getId()));
volumeData.add(new Pair(BaseCmd.Properties.VIRTUAL_MACHINE_NAME.getName(), vm.getName()));
volumeData.add(new Pair(BaseCmd.Properties.VIRTUAL_MACHINE_DISPLAYNAME.getName(), vm.getName()));
- volumeData.add(new Pair(BaseCmd.Properties.VIRTUAL_MACHINE_STATE.getName(), vm.getState()));
- }
+ volumeData.add(new Pair(BaseCmd.Properties.VIRTUAL_MACHINE_STATE.getName(), vm.getState()));
+ volumeData.add(new Pair(BaseCmd.Properties.DEVICE_ID.getName(), volume.getDeviceId()));
+ }
// Show the virtual size of the volume
long virtualSizeInBytes = volume.getSize();
From e3af2edc1d4f8ee162d658348b544c6e4aacb28c Mon Sep 17 00:00:00 2001
From: Kelven Yang
Date: Wed, 25 Aug 2010 09:48:31 -0700
Subject: [PATCH 06/43] add vmware DB initial sql scripts for templates and
guest OSes
---
setup/db/templates.vmware.sql | 82 +++++++++++++++++++++++++++++++++++
1 file changed, 82 insertions(+)
create mode 100644 setup/db/templates.vmware.sql
diff --git a/setup/db/templates.vmware.sql b/setup/db/templates.vmware.sql
new file mode 100644
index 00000000000..cc9ac751b5b
--- /dev/null
+++ b/setup/db/templates.vmware.sql
@@ -0,0 +1,82 @@
+INSERT INTO `cloud`.`vm_template` (id, unique_name, name, public, created, type, hvm, bits, account_id, url, checksum, enable_password, display_text, format, guest_os_id, featured, cross_zones)
+ VALUES (1, 'routing', 'SystemVM Template', 0, now(), 'ext3', 0, 64, 1, 'http://nfs1.lab.vmops.com/templates/vmware/fedora11-x86.tar.bz2', '31cd7ce94fe68c973d5dc37c3349d02e', 0, 'SystemVM Template', 'VMDK', 47, 0, 1);
+INSERT INTO `cloud`.`vm_template` (id, unique_name, name, public, created, type, hvm, bits, account_id, url, checksum, enable_password, display_text, format, guest_os_id, featured, cross_zones)
+ VALUES (2, 'fedora11-x86', 'Fedora 11 x86', 1, now(), 'ext3', 0, 32, 1, 'http://nfs1.lab.vmops.com/templates/vmware/fedora11-x86.tar.bz2', 'b63d854a9560c013142567bbae8d98cf', 0, 'Fedora 11 x86', 'VMDK', 47, 1, 1);
+
+INSERT INTO `cloud`.`guest_os_category` (id, name) VALUES (1, 'Windows');
+INSERT INTO `cloud`.`guest_os_category` (id, name) VALUES (2, 'Linux');
+INSERT INTO `cloud`.`guest_os_category` (id, name) VALUES (3, 'Novell Netware');
+INSERT INTO `cloud`.`guest_os_category` (id, name) VALUES (4, 'Solaris');
+INSERT INTO `cloud`.`guest_os_category` (id, name) VALUES (5, 'Other');
+
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (1, 1, 'Microsoft Windows 7(32-bit)', 'Microsoft Windows 7(32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (2, 1, 'Microsoft Windows 7(64-bit)', 'Microsoft Windows 7(64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (3, 1, 'Microsoft Windows Server 2008 R2(64-bit)', 'Microsoft Windows Server 2008 R2(64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (4, 1, 'Microsoft Windows Server 2008(32-bit)', 'Microsoft Windows Server 2008(32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (5, 1, 'Microsoft Windows Server 2008(64-bit)', 'Windows Windows Server 2008(64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (6, 1, 'Microsoft Windows Server 2003, Enterprise Edition (32-bit)', 'Microsoft Windows Server 2003, Enterprise Edition (32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (7, 1, 'Microsoft Windows Server 2003, Enterprise Edition (64-bit)', 'Microsoft Windows Server 2003, Enterprise Edition (64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (8, 1, 'Microsoft Windows Server 2003, Datacenter Edition (32-bit)', 'Microsoft Windows Server 2003, Datacenter Edition (32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (9, 1, 'Microsoft Windows Server 2003, Datacenter Edition (64-bit)', 'Microsoft Windows Server 2003, Datacenter Edition (64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (10, 1, 'Microsoft Windows Server 2003, Standard Edition (32-bit)', 'Microsoft Windows Server 2003, Standard Edition (32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (11, 1, 'Microsoft Windows Server 2003, Standard Edition (64-bit)', 'Microsoft Windows Server 2003, Standard Edition (64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (12, 1, 'Microsoft Windows Server 2003, Web Edition', 'Microsoft Windows Server 2003, Web Edition');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (13, 1, 'Microsoft Small Bussiness Server 2003', 'Microsoft Small Bussiness Server 2003');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (14, 1, 'Microsoft Windows Vista (32-bit)', 'Microsoft Windows Vista (32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (15, 1, 'Microsoft Windows Vista (64-bit)', 'Microsoft Windows Vista (64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (16, 1, 'Microsoft Windows XP Professional (32-bit)', 'Microsoft Windows XP Professional (32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (17, 1, 'Microsoft Windows XP Professional (64-bit)', 'Microsoft Windows XP Professional (64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (18, 1, 'Microsoft Windows 2000 Advanced Server', 'Microsoft Windows 2000 Advanced Server');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (19, 1, 'Microsoft Windows 2000 Server', 'Microsoft Windows 2000 Server');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (20, 1, 'Microsoft Windows 2000 Professional', 'Microsoft Windows 2000 Professional');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (21, 1, 'Microsoft Windows 98', 'Microsoft Windows 98');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (22, 1, 'Microsoft Windows 95', 'Microsoft Windows 95');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (23, 1, 'Microsoft Windows NT 4', 'Microsoft Windows NT 4');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (24, 1, 'Microsoft Windows 3.1', 'Microsoft Windows 3.1');
+
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (25, 2, 'Red Hat Enterprise Linux 5(32-bit)', 'Red Hat Enterprise Linux 5(32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (26, 2, 'Red Hat Enterprise Linux 5(64-bit)', 'Red Hat Enterprise Linux 5(64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (27, 2, 'Red Hat Enterprise Linux 4(32-bit)', 'Red Hat Enterprise Linux 4(32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (28, 2, 'Red Hat Enterprise Linux 4(64-bit)', 'Red Hat Enterprise Linux 4(64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (29, 2, 'Red Hat Enterprise Linux 3(32-bit)', 'Red Hat Enterprise Linux 3(32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (30, 2, 'Red Hat Enterprise Linux 3(64-bit)', 'Red Hat Enterprise Linux 3(64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (31, 2, 'Red Hat Enterprise Linux 2', 'Red Hat Enterprise Linux 2');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (32, 2, 'Suse Linux Enterprise 11(32-bit)', 'Suse Linux Enterprise 11(32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (33, 2, 'Suse Linux Enterprise 11(64-bit)', 'Suse Linux Enterprise 11(64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (34, 2, 'Suse Linux Enterprise 10(32-bit)', 'Suse Linux Enterprise 10(32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (35, 2, 'Suse Linux Enterprise 10(64-bit)', 'Suse Linux Enterprise 10(64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (36, 2, 'Suse Linux Enterprise 8/9(32-bit)', 'Suse Linux Enterprise 8/9(32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (37, 2, 'Suse Linux Enterprise 8/9(64-bit)', 'Suse Linux Enterprise 8/9(64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (38, 2, 'Open Enterprise Server', 'Open Enterprise Server');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (39, 2, 'Asianux 3(32-bit)', 'Asianux 3(32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (40, 2, 'Asianux 3(64-bit)', 'Asianux 3(64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (41, 2, 'Debian GNU/Linux 5(32-bit)', 'Debian GNU/Linux 5(32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (42, 2, 'Debian GNU/Linux 5(64-bit)', 'Debian GNU/Linux 5(64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (43, 2, 'Debian GNU/Linux 4(32-bit)', 'Debian GNU/Linux 4(32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (44, 2, 'Debian GNU/Linux 4(64-bit)', 'Debian GNU/Linux 4(64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (45, 2, 'Ubuntu Linux (32-bit)', 'Ubuntu Linux (32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (46, 2, 'Ubuntu Linux (64-bit)', 'Ubuntu Linux (64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (47, 2, 'Other 2.6x Linux (32-bit)', 'Other 2.6x Linux (32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (48, 2, 'Other 2.6x Linux (64-bit)', 'Other 2.6x Linux (64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (49, 2, 'Other Linux (32-bit)', 'Other Linux (32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (50, 2, 'Other Linux (64-bit)', 'Other Linux (64-bit)');
+
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (51, 3, 'Novell Netware 6.x', 'Novell Netware 6.x');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (52, 3, 'Novell Netware 5.1', 'Novell Netware 5.1');
+
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (53, 4, 'Sun Solaris 10(32-bit)', 'Sun Solaris 10(32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (54, 4, 'Sun Solaris 10(64-bit)', 'Sun Solaris 10(64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (55, 4, 'Sun Solaris 9(Experimental)', 'Sun Solaris 9(Experimental)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (56, 4, 'Sun Solaris 8(Experimental)', 'Sun Solaris 8(Experimental)');
+
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (57, 5, 'FreeBSD (32-bit)', 'FreeBSD (32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (58, 5, 'FreeBSD (64-bit)', 'FreeBSD (64-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (59, 5, 'OS/2', 'OS/2');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (60, 5, 'SCO OpenServer 5', 'SCO OpenServer 5');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (61, 5, 'SCO UnixWare 7', 'SCO UnixWare 7');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (62, 5, 'DOS', 'DOS');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (63, 5, 'Other (32-bit)', 'Other (32-bit)');
+INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (64, 5, 'Other (64-bit)', 'Other (64-bit)');
+
+-- temporarily added for vmware, will be moved when vmware support is fully in-place
+INSERT INTO `cloud`.`host_master`(`type`, `service_address`, `admin`, `password`) VALUES('VSphere', 'vsphere-1.lab.vmops.com', 'Administrator', 'Suite219');
From 0682d70ce60aab521220a80bb1d1fdf2ac7b990f Mon Sep 17 00:00:00 2001
From: Kelven Yang
Date: Wed, 25 Aug 2010 11:07:27 -0700
Subject: [PATCH 07/43] add correct check sum to default vmware template
records Let StoragePoolMonitor be aware of vmware hypervisor
---
server/src/com/cloud/storage/StorageManagerImpl.java | 4 ++++
server/src/com/cloud/storage/listener/StoragePoolMonitor.java | 3 ++-
setup/db/templates.vmware.sql | 4 ++--
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java
index 99c13301707..d3f2156f79d 100644
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -1062,6 +1062,8 @@ public class StorageManagerImpl implements StorageManager {
String hypervisoType = configDao.getValue("hypervisor.type");
if (hypervisoType.equalsIgnoreCase("KVM")) {
_hypervisorType = Hypervisor.Type.KVM;
+ } else if(hypervisoType.equalsIgnoreCase("vmware")) {
+ _hypervisorType = Hypervisor.Type.VmWare;
}
_agentMgr.registerForHostEvents(new StoragePoolMonitor(this, _hostDao, _storagePoolDao), true, false, true);
@@ -1256,6 +1258,8 @@ public class StorageManagerImpl implements StorageManager {
if (hypervisorType == null) {
if (_hypervisorType == Hypervisor.Type.KVM) {
hypervisorType = Hypervisor.Type.KVM;
+ } else if(_hypervisorType == Hypervisor.Type.VmWare) {
+ hypervisorType = Hypervisor.Type.VmWare;
} else {
s_logger.debug("Couldn't find a host to serve in the server pool");
return null;
diff --git a/server/src/com/cloud/storage/listener/StoragePoolMonitor.java b/server/src/com/cloud/storage/listener/StoragePoolMonitor.java
index b66ffe2a374..7017ed83c2a 100755
--- a/server/src/com/cloud/storage/listener/StoragePoolMonitor.java
+++ b/server/src/com/cloud/storage/listener/StoragePoolMonitor.java
@@ -70,7 +70,8 @@ public class StoragePoolMonitor implements Listener {
public boolean processConnect(HostVO host, StartupCommand cmd) {
if (cmd instanceof StartupRoutingCommand) {
StartupRoutingCommand scCmd = (StartupRoutingCommand)cmd;
- if (scCmd.getHypervisorType() == Hypervisor.Type.XenServer || scCmd.getHypervisorType() == Hypervisor.Type.KVM) {
+ if (scCmd.getHypervisorType() == Hypervisor.Type.XenServer || scCmd.getHypervisorType() == Hypervisor.Type.KVM ||
+ scCmd.getHypervisorType() == Hypervisor.Type.VmWare) {
List pools = _poolDao.listBy(host.getDataCenterId(), host.getPodId(), host.getClusterId());
for (StoragePoolVO pool : pools) {
Long hostId = host.getId();
diff --git a/setup/db/templates.vmware.sql b/setup/db/templates.vmware.sql
index cc9ac751b5b..572e42107a9 100644
--- a/setup/db/templates.vmware.sql
+++ b/setup/db/templates.vmware.sql
@@ -1,7 +1,7 @@
INSERT INTO `cloud`.`vm_template` (id, unique_name, name, public, created, type, hvm, bits, account_id, url, checksum, enable_password, display_text, format, guest_os_id, featured, cross_zones)
- VALUES (1, 'routing', 'SystemVM Template', 0, now(), 'ext3', 0, 64, 1, 'http://nfs1.lab.vmops.com/templates/vmware/fedora11-x86.tar.bz2', '31cd7ce94fe68c973d5dc37c3349d02e', 0, 'SystemVM Template', 'VMDK', 47, 0, 1);
+ VALUES (1, 'routing', 'SystemVM Template', 0, now(), 'ext3', 0, 64, 1, 'http://nfs1.lab.vmops.com/templates/vmware/fedora11-x86.tar.bz2', '7957ff05cae838689eb53c7600b2fbe4', 0, 'SystemVM Template', 'VMDK', 47, 0, 1);
INSERT INTO `cloud`.`vm_template` (id, unique_name, name, public, created, type, hvm, bits, account_id, url, checksum, enable_password, display_text, format, guest_os_id, featured, cross_zones)
- VALUES (2, 'fedora11-x86', 'Fedora 11 x86', 1, now(), 'ext3', 0, 32, 1, 'http://nfs1.lab.vmops.com/templates/vmware/fedora11-x86.tar.bz2', 'b63d854a9560c013142567bbae8d98cf', 0, 'Fedora 11 x86', 'VMDK', 47, 1, 1);
+ VALUES (2, 'fedora11-x86', 'Fedora 11 x86', 1, now(), 'ext3', 0, 32, 1, 'http://nfs1.lab.vmops.com/templates/vmware/fedora11-x86.tar.bz2', '7957ff05cae838689eb53c7600b2fbe4', 0, 'Fedora 11 x86', 'VMDK', 47, 1, 1);
INSERT INTO `cloud`.`guest_os_category` (id, name) VALUES (1, 'Windows');
INSERT INTO `cloud`.`guest_os_category` (id, name) VALUES (2, 'Linux');
From 63ebb004346ec25ae6c65c80b9462fd3e536025d Mon Sep 17 00:00:00 2001
From: Kelven Yang
Date: Wed, 25 Aug 2010 11:59:18 -0700
Subject: [PATCH 08/43] Add VMDK processor for template processing at secondary
storage
---
.../storage/template/DownloadManagerImpl.java | 5 ++
.../cloud/storage/template/VmdkProcessor.java | 67 +++++++++++++++++++
2 files changed, 72 insertions(+)
create mode 100644 core/src/com/cloud/storage/template/VmdkProcessor.java
diff --git a/core/src/com/cloud/storage/template/DownloadManagerImpl.java b/core/src/com/cloud/storage/template/DownloadManagerImpl.java
index 2ec957a6d8a..8d41e293e6a 100644
--- a/core/src/com/cloud/storage/template/DownloadManagerImpl.java
+++ b/core/src/com/cloud/storage/template/DownloadManagerImpl.java
@@ -781,6 +781,11 @@ public class DownloadManagerImpl implements DownloadManager {
processor = new QCOW2Processor();
processor.configure("QCOW2 Processor", params);
processors.add(processor);
+
+ processor = new VmdkProcessor();
+ processor.configure("VMDK Processor", params);
+ processors.add(processor);
+
// Add more processors here.
threadPool = Executors.newFixedThreadPool(numInstallThreads);
return true;
diff --git a/core/src/com/cloud/storage/template/VmdkProcessor.java b/core/src/com/cloud/storage/template/VmdkProcessor.java
new file mode 100644
index 00000000000..b8d037c3538
--- /dev/null
+++ b/core/src/com/cloud/storage/template/VmdkProcessor.java
@@ -0,0 +1,67 @@
+package com.cloud.storage.template;
+
+import java.io.File;
+import java.util.Map;
+
+import javax.naming.ConfigurationException;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InternalErrorException;
+import com.cloud.storage.StorageLayer;
+import com.cloud.storage.Storage.ImageFormat;
+
+public class VmdkProcessor implements Processor {
+ private static final Logger s_logger = Logger.getLogger(VmdkProcessor.class);
+
+ String _name;
+ StorageLayer _storage;
+
+ @Override
+ public FormatInfo process(String templatePath, ImageFormat format, String templateName) throws InternalErrorException {
+ if (format != null) {
+ s_logger.debug("We currently don't handle conversion from " + format + " to VMDK.");
+ return null;
+ }
+
+ s_logger.info("Template processing. templatePath: " + templatePath + ", templateName: " + templateName);
+ String templateFilePath = templatePath + File.separator + templateName + ".tar.bz2";
+ if (!_storage.exists(templateFilePath)) {
+ s_logger.debug("Unable to find the vmware template file: " + templateFilePath);
+ return null;
+ }
+
+ FormatInfo info = new FormatInfo();
+ info.format = ImageFormat.VMDK;
+ info.filename = templateName + ".tar.bz2";
+ info.size = _storage.getSize(templateFilePath);
+ info.virtualSize = info.size;
+ return info;
+ }
+
+ @Override
+ public boolean configure(String name, Map params) throws ConfigurationException {
+ _name = name;
+ _storage = (StorageLayer)params.get(StorageLayer.InstanceConfigKey);
+ if (_storage == null) {
+ throw new ConfigurationException("Unable to get storage implementation");
+ }
+
+ return true;
+ }
+
+ @Override
+ public String getName() {
+ return _name;
+ }
+
+ @Override
+ public boolean start() {
+ return true;
+ }
+
+ @Override
+ public boolean stop() {
+ return true;
+ }
+}
From 4fe1d8f335d909f1fc378256066aa5c3d89dc189 Mon Sep 17 00:00:00 2001
From: edison
Date: Wed, 25 Aug 2010 12:25:05 -0700
Subject: [PATCH 09/43] add a web-based Ip Allocator: In external-ip mode,
management server can get user VM's ip from
direct.attach.network.externalIpAllocator.url. This simple tool provides such
kind of ip allocator service.
How to:
1. setup the dnsmasq:
add the following in dnsmasq.conf:
dhcp-range=starting-ip-allocate-to-vm,end-ip,netmask,static
dhcp-option=option:router,gateway
2. run cloud-web-ipallocator,
The default listing port is 8080, if it's used by others, change the port by:
cloud-web-ipallocator other-port
3. set the following in direct.attach.network.externalIpAllocator.url:
http://your-host-ip:listening-port/ipallocator
---
python/bindir/cloud-web-ipallocator.in | 136 +++++++++++++++++++++++++
1 file changed, 136 insertions(+)
create mode 100755 python/bindir/cloud-web-ipallocator.in
diff --git a/python/bindir/cloud-web-ipallocator.in b/python/bindir/cloud-web-ipallocator.in
new file mode 100755
index 00000000000..3a278d29e56
--- /dev/null
+++ b/python/bindir/cloud-web-ipallocator.in
@@ -0,0 +1,136 @@
+#! /usr/bin/python
+import web
+import socket, struct
+import cloud_utils
+from cloud_utils import Command
+urls = ("/ipallocator", "ipallocator")
+app = web.application(urls, globals())
+
+augtool = Command("augtool")
+service = Command("service")
+class dhcp:
+ _instance = None
+ def __init__(self):
+ self.availIP=[]
+ self.router=None
+ self.netmask=None
+ self.initialized=False
+
+ options = augtool.match("/files/etc/dnsmasq.conf/dhcp-option").stdout.strip()
+ for option in options.splitlines():
+ if option.find("option:router") != -1:
+ self.router = option.split("=")[1].strip().split(",")[1]
+ print self.router
+
+ dhcp_range = augtool.get("/files/etc/dnsmasq.conf/dhcp-range").stdout.strip()
+ dhcp_start = dhcp_range.split("=")[1].strip().split(",")[0]
+ dhcp_end = dhcp_range.split("=")[1].strip().split(",")[1]
+ self.netmask = dhcp_range.split("=")[1].strip().split(",")[2]
+ print dhcp_start, dhcp_end, self.netmask
+
+ start_ip_num = self.ipToNum(dhcp_start);
+ end_ip_num = self.ipToNum(dhcp_end)
+ print start_ip_num, end_ip_num
+
+ for ip in range(start_ip_num, end_ip_num + 1):
+ self.availIP.append(ip)
+ print self.availIP[0], self.availIP[len(self.availIP) - 1]
+
+ #load the ip already allocated
+ self.reloadAllocatedIP()
+
+ def ipToNum(self, ip):
+ return struct.unpack("!I", socket.inet_aton(ip))[0]
+
+ def numToIp(self, num):
+ return socket.inet_ntoa(struct.pack('!I', num))
+
+ def getFreeIP(self):
+ if len(self.availIP) > 0:
+ ip = self.numToIp(self.availIP[0])
+ self.availIP.remove(self.availIP[0])
+ return ip
+ else:
+ return None
+
+ def getNetmask(self):
+ return self.netmask
+
+ def getRouter(self):
+ return self.router
+
+ def getInstance():
+ if not dhcp._instance:
+ dhcp._instance = dhcp()
+ return dhcp._instance
+ getInstance = staticmethod(getInstance)
+
+ def reloadAllocatedIP(self):
+ dhcp_hosts = augtool.match("/files/etc/dnsmasq.conf/dhcp-host").stdout.strip().splitlines()
+
+ for host in dhcp_hosts:
+ if host.find("dhcp-host") != -1:
+ allocatedIP = self.ipToNum(host.split("=")[1].strip().split(",")[1])
+ if allocatedIP in self.availIP:
+ self.availIP.remove(allocatedIP)
+
+ def allocateIP(self, mac):
+ newIP = self.getFreeIP()
+ dhcp_host = augtool.match("/files/etc/dnsmasq.conf/dhcp-host").stdout.strip()
+ cnt = len(dhcp_host.splitlines()) + 1
+ script = """set %s %s
+ save"""%("/files/etc/dnsmasq.conf/dhcp-host[" + str(cnt) + "]", str(mac) + "," + newIP)
+ augtool < script
+ #reset dnsmasq
+ service("dnsmasq", "restart", stdout=None, stderr=None)
+ return newIP
+
+ def releaseIP(self, ip):
+ dhcp_host = augtool.match("/files/etc/dnsmasq.conf/dhcp-host").stdout.strip()
+ path = None
+ for host in dhcp_host.splitlines():
+ if host.find(ip) != -1:
+ path = host.split("=")[0].strip()
+
+ if path == None:
+ print "Can't find " + str(ip) + " in conf file"
+ return None
+
+ print path
+ script = """rm %s
+ save"""%(path)
+ augtool < script
+
+ #reset dnsmasq
+ service("dnsmasq", "restart", stdout=None, stderr=None)
+
+class ipallocator:
+ def GET(self):
+ try:
+ user_data = web.input()
+ command = user_data.command
+ print "Processing: " + command
+
+ dhcpInit = dhcp.getInstance()
+
+ if command == "getIpAddr":
+ mac = user_data.mac
+ zone_id = user_data.dc
+ pod_id = user_data.pod
+ print mac, zone_id, pod_id
+ freeIP = dhcpInit.allocateIP(mac)
+ if not freeIP:
+ return "0,0,0"
+ print "Find an available IP: " + freeIP
+
+ return freeIP + "," + dhcpInit.getNetmask() + "," + dhcpInit.getRouter()
+ elif command == "releaseIpAddr":
+ ip = user_data.ip
+ zone_id = user_data.dc
+ pod_id = user_data.pod
+ dhcpInit.releaseIP(ip)
+ except:
+ return None
+
+if __name__ == "__main__":
+ app.run()
From 0a35a8120ddacff63127fce9b24e326f104efef0 Mon Sep 17 00:00:00 2001
From: edison
Date: Mon, 16 Aug 2010 19:35:08 -0700
Subject: [PATCH 10/43] Oh, why there is so many un-compatible libvirt...
---
.../computing/LibvirtComputingResource.java | 21 ++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
index 574b3669113..fdc050d7cca 100644
--- a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
+++ b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
@@ -1189,10 +1189,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
s_logger.debug(result);
return new CreateAnswer(cmd, result);
}
+
+ vol = createVolume(primaryPool, tmplVol);
- LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(UUID.randomUUID().toString(), tmplVol.getInfo().capacity, volFormat.QCOW2, tmplVol.getPath(), volFormat.QCOW2);
- s_logger.debug(volDef.toString());
- vol = primaryPool.storageVolCreateXML(volDef.toString(), 0);
if (vol == null) {
return new Answer(cmd, false, " Can't create storage volume on storage pool");
}
@@ -3502,6 +3501,22 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
}
+ private StorageVol createVolume(StoragePool destPool, StorageVol tmplVol) throws LibvirtException {
+ if (isCentosHost()) {
+ LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(UUID.randomUUID().toString(), tmplVol.getInfo().capacity, volFormat.QCOW2, null, null);
+ s_logger.debug(volDef.toString());
+ StorageVol vol = destPool.storageVolCreateXML(volDef.toString(), 0);
+
+ /*create qcow2 image based on the name*/
+ Script.runSimpleBashScript("qemu-img create -f qcow2 -b " + tmplVol.getPath() + " " + vol.getPath() );
+ return vol;
+ } else {
+ LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(UUID.randomUUID().toString(), tmplVol.getInfo().capacity, volFormat.QCOW2, tmplVol.getPath(), volFormat.QCOW2);
+ s_logger.debug(volDef.toString());
+ return destPool.storageVolCreateXML(volDef.toString(), 0);
+ }
+ }
+
private StorageVol getVolume(StoragePool pool, String volKey) {
StorageVol vol = null;
try {
From 398d38b38c83579452e92ec817396189536b84ab Mon Sep 17 00:00:00 2001
From: edison
Date: Tue, 17 Aug 2010 16:48:46 -0700
Subject: [PATCH 11/43] rename qemu-kvm to cloud-qemu-system*
---
.../agent/resource/computing/LibvirtComputingResource.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
index fdc050d7cca..755a739448d 100644
--- a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
+++ b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
@@ -2941,9 +2941,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
private String getHypervisorPath() {
- File f =new File("/usr/bin/cloud-qemu-kvm");
+ File f =new File("/usr/bin/cloud-qemu-system-x86_64");
if (f.exists()) {
- return "/usr/bin/cloud-qemu-kvm";
+ return "/usr/bin/cloud-qemu-system-x86_64";
} else {
if (_conn == null)
return null;
From 867b49edb6401ba9a5639e524630586f81e07822 Mon Sep 17 00:00:00 2001
From: edison
Date: Tue, 17 Aug 2010 16:52:52 -0700
Subject: [PATCH 12/43] Don't install console proxy agent on agent
---
scripts/vm/hypervisor/kvm/setup_agent.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/vm/hypervisor/kvm/setup_agent.sh b/scripts/vm/hypervisor/kvm/setup_agent.sh
index 7697aaa0d0b..1c0a18112df 100755
--- a/scripts/vm/hypervisor/kvm/setup_agent.sh
+++ b/scripts/vm/hypervisor/kvm/setup_agent.sh
@@ -174,4 +174,4 @@ done
#install_cloud_agent $dflag
#install_cloud_consoleP $dflag
cloud_agent_setup $host $zone $pod $guid
-cloud_consoleP_setup $host $zone $pod
+#cloud_consoleP_setup $host $zone $pod
From dc14cb4b3d3c0230d99860d087d3d1e0fefb1543 Mon Sep 17 00:00:00 2001
From: edison
Date: Wed, 18 Aug 2010 12:26:43 -0700
Subject: [PATCH 13/43] fix vlan dev naming issue: don't naming it by ourself
---
.../agent/resource/computing/LibvirtComputingResource.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
index 755a739448d..67398b29f92 100644
--- a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
+++ b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
@@ -3097,7 +3097,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
brName = setVnetBrName(vnetId);
String vnetDev = "vtap" + vnetId;
createVnet(vnetId, _pifs.first());
- vnetNic.defBridgeNet(brName, vnetDev, guestMac, interfaceDef.nicModel.VIRTIO);
+ vnetNic.defBridgeNet(brName, null, guestMac, interfaceDef.nicModel.VIRTIO);
}
nics.add(vnetNic);
@@ -3113,7 +3113,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
brName = setVnetBrName(vnetId);
String vnetDev = "vtap" + vnetId;
createVnet(vnetId, _pifs.second());
- pubNic.defBridgeNet(brName, vnetDev, pubMac, interfaceDef.nicModel.VIRTIO);
+ pubNic.defBridgeNet(brName, null, pubMac, interfaceDef.nicModel.VIRTIO);
}
nics.add(pubNic);
return nics;
From ea3bbcb4641a18a7456e127315d0a1bb58cf5297 Mon Sep 17 00:00:00 2001
From: edison
Date: Wed, 18 Aug 2010 16:28:22 -0700
Subject: [PATCH 14/43] fix attaching disk
---
.../agent/resource/computing/LibvirtComputingResource.java | 2 +-
.../cloud/agent/resource/computing/LibvirtDomainXMLParser.java | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
index 67398b29f92..fa346e79b1f 100644
--- a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
+++ b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
@@ -2360,7 +2360,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
Iterator> itr = entrySet.iterator();
while (itr.hasNext()) {
Map.Entry entry = itr.next();
- if (entry.getValue().equalsIgnoreCase(sourceFile)) {
+ if ((entry.getValue() != null) && (entry.getValue().equalsIgnoreCase(sourceFile))) {
diskDev = entry.getKey();
break;
}
diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtDomainXMLParser.java b/agent/src/com/cloud/agent/resource/computing/LibvirtDomainXMLParser.java
index 779962af0a4..b5271c8e62c 100644
--- a/agent/src/com/cloud/agent/resource/computing/LibvirtDomainXMLParser.java
+++ b/agent/src/com/cloud/agent/resource/computing/LibvirtDomainXMLParser.java
@@ -94,6 +94,8 @@ public class LibvirtDomainXMLParser extends LibvirtXMLParser {
} else if (qName.equalsIgnoreCase("disk")) {
diskMaps.put(diskDev, diskFile);
_disk = false;
+ diskFile = null;
+ diskDev = null;
} else if (qName.equalsIgnoreCase("description")) {
_desc = false;
}
From 3ab4651cf0f38f4c5508fa4eecd9d9a8dfeb9add Mon Sep 17 00:00:00 2001
From: edison
Date: Thu, 19 Aug 2010 21:36:51 -0700
Subject: [PATCH 15/43] Issue #: 5978 5977 5971 5972 Status 5978: resolved
fixed Status 5977: resolved fixed Status 5971: resolved fixed Status 5972:
resolved fixed
---
.../computing/LibvirtComputingResource.java | 177 ++++++++++++++----
scripts/storage/qcow2/createtmplt.sh | 34 +++-
scripts/storage/qcow2/managesnapshot.sh | 44 +++--
.../com/cloud/storage/StorageManagerImpl.java | 6 +-
.../storage/snapshot/SnapshotManagerImpl.java | 4 +-
.../src/com/cloud/vm/UserVmManagerImpl.java | 8 +-
6 files changed, 203 insertions(+), 70 deletions(-)
diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
index fa346e79b1f..6ae752fd200 100644
--- a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
+++ b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java
@@ -1228,21 +1228,46 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
protected ManageSnapshotAnswer execute(final ManageSnapshotCommand cmd) {
String snapshotName = cmd.getSnapshotName();
String VolPath = cmd.getVolumePath();
+ String snapshotPath = cmd.getSnapshotPath();
+ String vmName = cmd.getVmName();
try {
- StorageVol vol = getVolume(VolPath);
- if (vol == null) {
- return new ManageSnapshotAnswer(cmd, false, null);
+ DomainInfo.DomainState state = null;
+ Domain vm = null;
+ if (vmName != null) {
+ try {
+ vm = getDomain(cmd.getVmName());
+ state = vm.getInfo().state;
+ } catch (LibvirtException e) {
+
+ }
}
- Domain vm = getDomain(cmd.getVmName());
- String vmUuid = vm.getUUIDString();
- Object[] args = new Object[] {snapshotName, vmUuid};
- String snapshot = SnapshotXML.format(args);
- s_logger.debug(snapshot);
- if (cmd.getCommandSwitch().equalsIgnoreCase(ManageSnapshotCommand.CREATE_SNAPSHOT)) {
- vm.snapshotCreateXML(snapshot);
+
+ if (state == DomainInfo.DomainState.VIR_DOMAIN_RUNNING) {
+ String vmUuid = vm.getUUIDString();
+ Object[] args = new Object[] {snapshotName, vmUuid};
+ String snapshot = SnapshotXML.format(args);
+ s_logger.debug(snapshot);
+ if (cmd.getCommandSwitch().equalsIgnoreCase(ManageSnapshotCommand.CREATE_SNAPSHOT)) {
+ vm.snapshotCreateXML(snapshot);
+ } else {
+ DomainSnapshot snap = vm.snapshotLookupByName(snapshotName);
+ snap.delete(0);
+ }
} else {
- DomainSnapshot snap = vm.snapshotLookupByName(snapshotName);
- snap.delete(0);
+ /*VM is not running, create a snapshot by ourself*/
+ final Script command = new Script(_manageSnapshotPath, _timeout, s_logger);
+ if (cmd.getCommandSwitch().equalsIgnoreCase(ManageSnapshotCommand.CREATE_SNAPSHOT)) {
+ command.add("-c", VolPath);
+ } else {
+ command.add("-d", snapshotPath);
+ }
+
+ command.add("-n", snapshotName);
+ String result = command.execute();
+ if (result != null) {
+ s_logger.debug("Failed to manage snapshot: " + result);
+ return new ManageSnapshotAnswer(cmd, false, "Failed to manage snapshot: " + result);
+ }
}
} catch (LibvirtException e) {
s_logger.debug("Failed to manage snapshot: " + e.toString());
@@ -1259,28 +1284,52 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
String snapshotName = cmd.getSnapshotName();
String snapshotPath = cmd.getSnapshotUuid();
String snapshotDestPath = null;
+ String vmName = cmd.getVmName();
try {
StoragePool secondaryStoragePool = getNfsSPbyURI(_conn, new URI(secondaryStoragePoolURL));
String ssPmountPath = _mountPoint + File.separator + secondaryStoragePool.getUUIDString();
snapshotDestPath = ssPmountPath + File.separator + dcId + File.separator + "snapshots" + File.separator + accountId + File.separator + volumeId;
- final Script command = new Script(_manageSnapshotPath, _timeout, s_logger);
+ Script command = new Script(_manageSnapshotPath, _timeout, s_logger);
command.add("-b", snapshotPath);
command.add("-n", snapshotName);
command.add("-p", snapshotDestPath);
+ command.add("-t", snapshotName);
String result = command.execute();
if (result != null) {
s_logger.debug("Failed to backup snaptshot: " + result);
return new BackupSnapshotAnswer(cmd, false, result, null);
}
/*Delete the snapshot on primary*/
- Domain vm = getDomain(cmd.getVmName());
- String vmUuid = vm.getUUIDString();
- Object[] args = new Object[] {snapshotName, vmUuid};
- String snapshot = SnapshotXML.format(args);
- s_logger.debug(snapshot);
- DomainSnapshot snap = vm.snapshotLookupByName(snapshotName);
- snap.delete(0);
+
+ DomainInfo.DomainState state = null;
+ Domain vm = null;
+ if (vmName != null) {
+ try {
+ vm = getDomain(cmd.getVmName());
+ state = vm.getInfo().state;
+ } catch (LibvirtException e) {
+
+ }
+ }
+
+ if (state == DomainInfo.DomainState.VIR_DOMAIN_RUNNING) {
+ String vmUuid = vm.getUUIDString();
+ Object[] args = new Object[] {snapshotName, vmUuid};
+ String snapshot = SnapshotXML.format(args);
+ s_logger.debug(snapshot);
+ DomainSnapshot snap = vm.snapshotLookupByName(snapshotName);
+ snap.delete(0);
+ } else {
+ command = new Script(_manageSnapshotPath, _timeout, s_logger);
+ command.add("-d", snapshotPath);
+ command.add("-n", snapshotName);
+ result = command.execute();
+ if (result != null) {
+ s_logger.debug("Failed to backup snapshot: " + result);
+ return new BackupSnapshotAnswer(cmd, false, "Failed to backup snapshot: " + result, null);
+ }
+ }
} catch (LibvirtException e) {
return new BackupSnapshotAnswer(cmd, false, e.toString(), null);
} catch (URISyntaxException e) {
@@ -1356,7 +1405,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
try {
secondaryPool = getNfsSPbyURI(_conn, new URI(cmd.getSecondaryStoragePoolURL()));
/*TODO: assuming all the storage pools mounted under _mountPoint, the mount point should be got from pool.dumpxml*/
- String templatePath = _mountPoint + File.separator + secondaryPool.getUUIDString() + File.separator + templateInstallFolder;
+ String templatePath = _mountPoint + File.separator + secondaryPool.getUUIDString() + File.separator + templateInstallFolder;
+ File f = new File(templatePath);
+ if (!f.exists()) {
+ f.mkdir();
+ }
String tmplPath = templateInstallFolder + File.separator + tmplFileName;
Script command = new Script(_createTmplPath, _timeout, s_logger);
command.add("-t", templatePath);
@@ -1403,38 +1456,58 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
protected CreatePrivateTemplateAnswer execute(CreatePrivateTemplateCommand cmd) {
String secondaryStorageURL = cmd.getSecondaryStorageURL();
- String snapshotUUID = cmd.getSnapshotPath();
StoragePool secondaryStorage = null;
- StoragePool privateTemplStorage = null;
- StorageVol privateTemplateVol = null;
- StorageVol snapshotVol = null;
try {
String templateFolder = cmd.getAccountId() + File.separator + cmd.getTemplateId() + File.separator;
String templateInstallFolder = "/template/tmpl/" + templateFolder;
-
+
secondaryStorage = getNfsSPbyURI(_conn, new URI(secondaryStorageURL));
/*TODO: assuming all the storage pools mounted under _mountPoint, the mount point should be got from pool.dumpxml*/
- String mountPath = _mountPoint + File.separator + secondaryStorage.getUUIDString() + templateInstallFolder;
- File mpfile = new File(mountPath);
+ String tmpltPath = _mountPoint + File.separator + secondaryStorage.getUUIDString() + templateInstallFolder;
+ File mpfile = new File(tmpltPath);
if (!mpfile.exists()) {
mpfile.mkdir();
}
+
+ Script command = new Script(_createTmplPath, _timeout, s_logger);
+ command.add("-f", cmd.getSnapshotPath());
+ command.add("-c", cmd.getSnapshotName());
+ command.add("-t", tmpltPath);
+ command.add("-n", cmd.getUniqueName() + ".qcow2");
+ command.add("-s");
+ String result = command.execute();
- // Create a SR for the secondary storage installation folder
- privateTemplStorage = getNfsSPbyURI(_conn, new URI(secondaryStorageURL + templateInstallFolder));
- snapshotVol = getVolume(snapshotUUID);
-
- LibvirtStorageVolumeDef vol = new LibvirtStorageVolumeDef(UUID.randomUUID().toString(), snapshotVol.getInfo().capacity, volFormat.QCOW2, null, null);
- s_logger.debug(vol.toString());
- privateTemplateVol = copyVolume(privateTemplStorage, vol, snapshotVol);
+ if (result != null) {
+ s_logger.debug("failed to create template: " + result);
+ return new CreatePrivateTemplateAnswer(cmd,
+ false,
+ result,
+ null,
+ 0,
+ null,
+ null);
+ }
+
+ Map params = new HashMap();
+ params.put(StorageLayer.InstanceConfigKey, _storage);
+ Processor qcow2Processor = new QCOW2Processor();
+
+ qcow2Processor.configure("QCOW2 Processor", params);
+
+ FormatInfo info = qcow2Processor.process(tmpltPath, null, cmd.getUniqueName());
+
+ TemplateLocation loc = new TemplateLocation(_storage, tmpltPath);
+ loc.create(1, true, cmd.getUniqueName());
+ loc.addFormat(info);
+ loc.save();
return new CreatePrivateTemplateAnswer(cmd,
true,
null,
- templateInstallFolder + privateTemplateVol.getName(),
- privateTemplateVol.getInfo().capacity/1024*1024, /*in Mega unit*/
- privateTemplateVol.getName(),
+ templateInstallFolder + cmd.getUniqueName() + ".qcow2",
+ info.virtualSize,
+ cmd.getUniqueName(),
ImageFormat.QCOW2);
} catch (URISyntaxException e) {
return new CreatePrivateTemplateAnswer(cmd,
@@ -1453,7 +1526,31 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
0,
null,
null);
- }
+ } catch (InternalErrorException e) {
+ return new CreatePrivateTemplateAnswer(cmd,
+ false,
+ e.toString(),
+ null,
+ 0,
+ null,
+ null);
+ } catch (IOException e) {
+ return new CreatePrivateTemplateAnswer(cmd,
+ false,
+ e.toString(),
+ null,
+ 0,
+ null,
+ null);
+ } catch (ConfigurationException e) {
+ return new CreatePrivateTemplateAnswer(cmd,
+ false,
+ e.toString(),
+ null,
+ 0,
+ null,
+ null);
+ }
}
private StoragePool getNfsSPbyURI(Connect conn, URI uri) throws LibvirtException {
@@ -3165,7 +3262,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
String datadiskPath = tmplVol.getKey();
diskDef hda = new diskDef();
- hda.defFileBasedDisk(rootkPath, "vda", diskDef.diskBus.IDE, diskDef.diskFmtType.QCOW2);
+ hda.defFileBasedDisk(rootkPath, "hda", diskDef.diskBus.IDE, diskDef.diskFmtType.QCOW2);
disks.add(hda);
diskDef hdb = new diskDef();
diff --git a/scripts/storage/qcow2/createtmplt.sh b/scripts/storage/qcow2/createtmplt.sh
index 55efe952af5..ef75c6270e9 100755
--- a/scripts/storage/qcow2/createtmplt.sh
+++ b/scripts/storage/qcow2/createtmplt.sh
@@ -80,6 +80,20 @@ create_from_file() {
fi
}
+create_from_snapshot() {
+ local tmpltImg=$1
+ local snapshotName=$2
+ local tmpltfs=$3
+ local tmpltname=$4
+
+ cloud-qemu-img convert -f qcow2 -O qcow2 -s $snapshotName $tmpltImg /$tmpltfs/$tmpltname >& /dev/null
+ if [ $? -gt 0 ]
+ then
+ printf "Failed to create template /$tmplfs/$tmpltname from snapshot $snapshotName on disk $tmpltImg "
+ exit 2
+ fi
+}
+
tflag=
nflag=
fflag=
@@ -89,8 +103,9 @@ hvm=false
cleanup=false
dflag=
cflag=
+snapshotName=
-while getopts 'uht:n:f:s:c:d:' OPTION
+while getopts 'uht:n:f:sc:d:' OPTION
do
case $OPTION in
t) tflag=1
@@ -103,10 +118,10 @@ do
tmpltimg="$OPTARG"
;;
s) sflag=1
- volsize="$OPTARG"
+ sflag=1
;;
c) cflag=1
- cksum="$OPTARG"
+ snapshotName="$OPTARG"
;;
d) dflag=1
descr="$OPTARG"
@@ -119,12 +134,6 @@ do
esac
done
-if [ "$tflag$nflag$fflag" != "111" ]
-then
- usage
- exit 2
-fi
-
if [ ! -d /$tmpltfs ]
then
@@ -148,7 +157,12 @@ then
printf "failed to uncompress $tmpltimg\n"
fi
-create_from_file $tmpltfs $tmpltimg $tmpltname
+if [ "$sflag" == "1" ]
+then
+ create_from_snapshot $tmpltimg $snapshotName $tmpltfs $tmpltname
+else
+ create_from_file $tmpltfs $tmpltimg $tmpltname
+fi
touch /$tmpltfs/template.properties
echo -n "" > /$tmpltfs/template.properties
diff --git a/scripts/storage/qcow2/managesnapshot.sh b/scripts/storage/qcow2/managesnapshot.sh
index 3c7692161d6..d9b339267a0 100755
--- a/scripts/storage/qcow2/managesnapshot.sh
+++ b/scripts/storage/qcow2/managesnapshot.sh
@@ -16,13 +16,20 @@ create_snapshot() {
local snapshotname=$2
local failed=0
- qemu-img snapshot -c $snapshotname $disk
+ if [ ! -f $disk ]
+ then
+ failed=1
+ printf "No disk $disk exist\n" >&2
+ return $failed
+ fi
+
+ cloud-qemu-img snapshot -c $snapshotname $disk
if [ $? -gt 0 ]
then
- failed=1
+ failed=2
printf "***Failed to create snapshot $snapshotname for path $disk\n" >&2
- qemu-img snapshot -d $snapshotname $disk
+ cloud-qemu-img snapshot -d $snapshotname $disk
if [ $? -gt 0 ]
then
@@ -34,21 +41,24 @@ create_snapshot() {
}
destroy_snapshot() {
- local backupSnapDir=$1
+ local disk=$1
local snapshotname=$2
local failed=0
- if [ -f $backupSnapDir/$snapshotname ]
+ if [ ! -f $disk ]
then
- rm -f $backupSnapDir/$snapshotname
-
- if [ $? -gt 0 ]
- then
- printf "***Failed to delete snapshot $snapshotname for path $backupSnapDir\n" >&2
- failed=1
- fi
+ failed=1
+ printf "No disk $disk exist\n" >&2
+ return $failed
fi
+ cloud-qemu-img snapshot -d $snapshotname $disk
+ if [ $? -gt 0 ]
+ then
+ failed=2
+ printf "Failed to delete snapshot $snapshotname for path $disk\n" >&2
+ fi
+
return $failed
}
@@ -71,6 +81,7 @@ backup_snapshot() {
local disk=$1
local snapshotname=$2
local destPath=$3
+ local destName=$4
if [ ! -d $destPath ]
then
@@ -90,7 +101,7 @@ backup_snapshot() {
return 1
fi
- cloud-qemu-img convert -f qcow2 -O qcow2 -s $snapshotname $disk $destPath/$snapshotname >& /dev/null
+ cloud-qemu-img convert -f qcow2 -O qcow2 -s $snapshotname $disk $destPath/$destName >& /dev/null
if [ $? -gt 0 ]
then
printf "Failed to backup $snapshotname for disk $disk to $destPath" >&2
@@ -107,8 +118,9 @@ bflag=
nflag=
pathval=
snapshot=
+tmplName=
-while getopts 'c:d:r:n:b:p:' OPTION
+while getopts 'c:d:r:n:b:p:t:' OPTION
do
case $OPTION in
c) cflag=1
@@ -128,6 +140,8 @@ do
;;
p) destPath="$OPTARG"
;;
+ t) tmplName="$OPTARG"
+ ;;
?) usage
;;
esac
@@ -144,7 +158,7 @@ then
exit $?
elif [ "$bflag" == "1" ]
then
- backup_snapshot $pathval $snapshot $destPath
+ backup_snapshot $pathval $snapshot $destPath $tmplName
exit $?
elif [ "$rflag" == "1" ]
then
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java
index d3f2156f79d..53395a5a130 100644
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -939,10 +939,12 @@ public class StorageManagerImpl implements StorageManager {
if (vmId != null) {
VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId);
if (vmInstance != null) {
- return vmInstance.getHostId();
+ Long hostId = vmInstance.getHostId();
+ if (hostId != null && !avoidHosts.contains(vmInstance.getHostId()))
+ return hostId;
}
}
- return null;
+ /*Can't find the vm where host resides on(vm is destroyed? or volume is detached from vm), randomly choose a host to send the cmd */
}
List poolHosts = _poolHostDao.listByHostStatus(poolVO.getId(), Status.Up);
Collections.shuffle(poolHosts);
diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
index a372e17b6e8..c6f82d2f567 100644
--- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@ -287,7 +287,7 @@ public class SnapshotManagerImpl implements SnapshotManager {
}
txn.commit();
- VolumeVO volume = _volsDao.findById(volumeId);
+ VolumeVO volume = _volsDao.lock(volumeId, true);
if (!shouldRunSnapshot(userId, volume, policyIds)) {
// A null snapshot is interpreted as snapshot creation failed which is what we want to indicate
@@ -477,7 +477,7 @@ public class SnapshotManagerImpl implements SnapshotManager {
_snapshotDao.update(snapshot.getId(), snapshot);
long volumeId = snapshot.getVolumeId();
- VolumeVO volume = _volsDao.findById(volumeId);
+ VolumeVO volume = _volsDao.lock(volumeId, true);
String primaryStoragePoolNameLabel = _storageMgr.getPrimaryStorageNameLabel(volume);
Long dcId = volume.getDataCenterId();
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 7a26cc7d100..721f73e3eb4 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -686,6 +686,7 @@ public class UserVmManagerImpl implements UserVmManager {
}
boolean started = false;
+
Transaction txn = Transaction.currentTxn();
try {
@@ -736,6 +737,11 @@ public class UserVmManagerImpl implements UserVmManager {
VolumeVO vol = rootVols.get(0);
List vols = _volsDao.findCreatedByInstance(vm.getId());
+ List vos = new ArrayList();
+ /*compete with take snapshot*/
+ for (VolumeVO userVmVol : vols) {
+ vos.add(_volsDao.lock(userVmVol.getId(), true));
+ }
Answer answer = null;
int retry = _retry;
@@ -2215,7 +2221,7 @@ public class UserVmManagerImpl implements UserVmManager {
@Override @DB
public SnapshotVO createTemplateSnapshot(long userId, long volumeId) {
SnapshotVO createdSnapshot = null;
- VolumeVO volume = _volsDao.findById(volumeId);
+ VolumeVO volume = _volsDao.lock(volumeId, true);
Long id = null;
From 3c92e52886fc8ee8fb8902ddc5f0185f970f88ae Mon Sep 17 00:00:00 2001
From: jessica
Date: Wed, 25 Aug 2010 15:48:08 -0700
Subject: [PATCH 16/43] Issue #: 5785 - support non-ascii character like euro
character
---
ui/scripts/cloud.core.configuration.js | 39 +++++++++++++-------------
ui/scripts/cloud.core.instances.js | 12 ++++----
2 files changed, 25 insertions(+), 26 deletions(-)
diff --git a/ui/scripts/cloud.core.configuration.js b/ui/scripts/cloud.core.configuration.js
index d3ffd9022ae..d648e4a53eb 100644
--- a/ui/scripts/cloud.core.configuration.js
+++ b/ui/scripts/cloud.core.configuration.js
@@ -1244,7 +1244,7 @@ function showConfigurationTab() {
dialogEditService.find("#service_name").text(svcName);
dialogEditService.find("#edit_service_name").val(svcName);
- dialogEditService.find("#edit_service_display").val(template.find("#service_display").text());
+ dialogEditService.find("#edit_service_display").val(template.find("#service_displaytext").text());
dialogEditService.find("#edit_service_offerha").val(toBooleanValue(template.find("#service_offerha").text()));
dialogEditService
@@ -1260,9 +1260,9 @@ function showConfigurationTab() {
var moreCriteria = [];
var name = trim(thisDialog.find("#edit_service_name").val());
- moreCriteria.push("&name="+encodeURIComponent(name));
+ moreCriteria.push("&name="+encodeURIComponent(escape(name)));
var displaytext = trim(thisDialog.find("#edit_service_display").val());
- moreCriteria.push("&displayText="+encodeURIComponent(displaytext));
+ moreCriteria.push("&displayText="+encodeURIComponent(escape(displaytext)));
var offerha = trim(thisDialog.find("#edit_service_offerha").val());
moreCriteria.push("&offerha="+offerha);
@@ -1316,17 +1316,17 @@ function showConfigurationTab() {
function serviceJSONToTemplate(json, template) {
template.attr("id", "service_"+json.id);
(index++ % 2 == 0)? template.addClass("smallrow_even"): template.addClass("smallrow_odd");
- template.data("svcId", json.id).data("svcName", sanitizeXSS(json.name));
+ template.data("svcId", json.id).data("svcName", sanitizeXSS(unescape(json.name)));
template.find("#service_id").text(json.id);
- template.find("#service_name").text(json.name);
- template.find("#service_displaytext").text(json.displaytext);
+ template.find("#service_name").text(unescape(json.name));
+ template.find("#service_displaytext").text(unescape(json.displaytext));
template.find("#service_storagetype").text(json.storagetype);
template.find("#service_cpu").text(json.cpunumber + " x " + convertHz(json.cpuspeed));
template.find("#service_memory").text(convertBytes(parseInt(json.memory)*1024*1024));
template.find("#service_offerha").text(toBooleanText(json.offerha));
template.find("#service_networktype").text(toNetworkType(json.usevirtualnetwork));
- template.find("#service_tags").text(json.tags);
+ template.find("#service_tags").text(unescape(json.tags));
setDateField(json.created, template.find("#service_created"));
}
@@ -1454,10 +1454,10 @@ function showConfigurationTab() {
var array1 = [];
var name = trim(thisDialog.find("#add_service_name").val());
- array1.push("&name="+encodeURIComponent(name));
+ array1.push("&name="+encodeURIComponent(escape(name)));
var display = trim(thisDialog.find("#add_service_display").val());
- array1.push("&displayText="+encodeURIComponent(display));
+ array1.push("&displayText="+encodeURIComponent(escape(display)));
var storagetype = trim(thisDialog.find("#add_service_storagetype").val());
array1.push("&storageType="+storagetype);
@@ -1480,7 +1480,7 @@ function showConfigurationTab() {
var tags = trim(thisDialog.find("#add_service_tags").val());
if(tags != null && tags.length > 0)
- array1.push("&tags="+encodeURIComponent(tags));
+ array1.push("&tags="+encodeURIComponent(escape(tags)));
thisDialog.dialog("close");
$.ajax({
@@ -1544,17 +1544,17 @@ function showConfigurationTab() {
var array1 = [];
var name = trim(thisDialog.find("#add_disk_name").val());
- array1.push("&name="+encodeURIComponent(name));
+ array1.push("&name="+encodeURIComponent(escape(name)));
var description = trim(thisDialog.find("#add_disk_description").val());
- array1.push("&displaytext="+encodeURIComponent(description));
+ array1.push("&displaytext="+encodeURIComponent(escape(description)));
var disksize = trim(thisDialog.find("#add_disk_disksize").val());
array1.push("&disksize="+disksize);
var tags = trim(thisDialog.find("#add_disk_tags").val());
if(tags != null && tags.length > 0)
- array1.push("&tags="+encodeURIComponent(tags));
+ array1.push("&tags="+encodeURIComponent(escape(tags)));
thisDialog.dialog("close");
$.ajax({
@@ -1649,7 +1649,7 @@ function showConfigurationTab() {
var dialogBox = $(this);
dialogBox.dialog("close");
$.ajax({
- data: createURL("command=updateDiskOffering&name="+encodeURIComponent(name)+"&displayText="+encodeURIComponent(display)+"&id="+diskId+"&response=json"),
+ data: createURL("command=updateDiskOffering&name="+encodeURIComponent(escape(name))+"&displayText="+encodeURIComponent(escape(display))+"&id="+diskId+"&response=json"),
dataType: "json",
success: function(json) {
template.find("#disk_description").text(display);
@@ -1699,15 +1699,14 @@ function showConfigurationTab() {
} else {
template.addClass("smallrow_odd");
}
- template.data("diskId", json.id).data("diskName", sanitizeXSS(json.name));
+ template.data("diskId", json.id).data("diskName", sanitizeXSS(unescape(json.name)));
template.find("#disk_id").text(json.id);
- template.find("#disk_name").text(json.name);
- template.find("#disk_description").text(json.displaytext);
+ template.find("#disk_name").text(unescape(json.name));
+ template.find("#disk_description").text(unescape(json.displaytext));
template.find("#disk_disksize").text(convertBytes(json.disksize));
- template.find("#disk_tags").text(json.tags);
- template.find("#disk_domain").text(json.domain);
- template.find("#disk_ismirrored").text(json.ismirrored);
+ template.find("#disk_tags").text(unescape(json.tags));
+ template.find("#disk_domain").text(unescape(json.domain));
}
function listDiskOfferings() {
diff --git a/ui/scripts/cloud.core.instances.js b/ui/scripts/cloud.core.instances.js
index ab2bbf17837..e5a9865f48b 100644
--- a/ui/scripts/cloud.core.instances.js
+++ b/ui/scripts/cloud.core.instances.js
@@ -576,7 +576,7 @@ function showInstancesTab(p_domainId, p_account) {
if (offerings != null && offerings.length > 0) {
for (var i = 0; i < offerings.length; i++) {
- var option = $("").data("name", offerings[i].name);
+ var option = $("").data("name", sanitizeXSS(unescape(offerings[i].name)));
offeringSelect.append(option);
}
}
@@ -611,7 +611,7 @@ function showInstancesTab(p_domainId, p_account) {
vmInstance.find(".row_loading").show();
vmInstance.find(".loadingmessage_container .loadingmessage_top p").html("Your virtual instance has been upgraded. Please restart your virtual instance for the new service offering to take effect.");
vmInstance.find(".loadingmessage_container").fadeIn("slow");
- vmInstance.find("#vm_service").html("Service: " + sanitizeXSS(result.virtualmachine[0].serviceofferingname));
+ vmInstance.find("#vm_service").html("Service: " + sanitizeXSS(unescape(result.virtualmachine[0].serviceofferingname)));
if (result.virtualmachine[0].haenable =='true') {
vmInstance.find("#vm_ha").html("HA: Enabled");
vmInstance.find("#vm_action_ha").text("Disable HA");
@@ -1109,7 +1109,7 @@ function showInstancesTab(p_domainId, p_account) {
instanceTemplate.find("#vm_ip_address").html("IP Address: " + instanceJSON.ipaddress);
instanceTemplate.find("#vm_zone").html("Zone: " + sanitizeXSS(instanceJSON.zonename));
instanceTemplate.find("#vm_template").html("Template: " + sanitizeXSS(instanceJSON.templatename));
- instanceTemplate.find("#vm_service").html("Service: " + sanitizeXSS(instanceJSON.serviceofferingname));
+ instanceTemplate.find("#vm_service").html("Service: " + sanitizeXSS(unescape(instanceJSON.serviceofferingname)));
if (instanceJSON.haenable =='true') {
instanceTemplate.find("#vm_ha").html("HA: Enabled");
instanceTemplate.find("#vm_action_ha").text("Disable HA");
@@ -1277,7 +1277,7 @@ function showInstancesTab(p_domainId, p_account) {
continue;
var checked = "checked";
if (first == false) checked = "";
- var listItem = $("");
+ var listItem = $("");
$("#wizard_service_offering").append(listItem);
first = false;
}
@@ -1306,14 +1306,14 @@ function showInstancesTab(p_domainId, p_account) {
var html =
"
"
+""
- +""
+ +""
+"
";
$("#wizard_root_disk_offering").append(html);
var html2 =
"
"
+""
- +""
+ +""
+"
";
$("#wizard_data_disk_offering").append(html2);
}
From 111f88a1dca2ed69f142c7767a7c3616231a4186 Mon Sep 17 00:00:00 2001
From: jessica
Date: Wed, 25 Aug 2010 16:33:15 -0700
Subject: [PATCH 17/43] Issue #: 5953 - show remove link when host status is
disconnected
---
ui/scripts/cloud.core.hosts.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ui/scripts/cloud.core.hosts.js b/ui/scripts/cloud.core.hosts.js
index 3316b5b19b8..d89c2249f0b 100644
--- a/ui/scripts/cloud.core.hosts.js
+++ b/ui/scripts/cloud.core.hosts.js
@@ -569,7 +569,7 @@ function showHostsTab() {
} else if (state == "Maintenance") {
template.find(".grid_links").find("#host_action_reconnect_container, #host_action_enable_maint_container").hide();
} else if (state == "Disconnected") {
- template.find(".grid_links").find("#host_action_reconnect_container, #host_action_enable_maint_container, #host_action_cancel_maint_container, #host_action_remove_container").hide();
+ template.find(".grid_links").find("#host_action_reconnect_container, #host_action_enable_maint_container, #host_action_cancel_maint_container").hide();
} else {
alert("Unsupported Host State: " + state);
}
From e5bdec33f9f316ad797a61ea46824d3ff905bd18 Mon Sep 17 00:00:00 2001
From: jessica
Date: Wed, 25 Aug 2010 17:09:48 -0700
Subject: [PATCH 18/43] Issue #: 5979 - change text on VM Wizard Step 3.
---
ui/content/tab_instances.html | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/ui/content/tab_instances.html b/ui/content/tab_instances.html
index 9bc3b94701d..55991f3ff01 100644
--- a/ui/content/tab_instances.html
+++ b/ui/content/tab_instances.html
@@ -704,8 +704,7 @@
Step 3: Optional
- To create a new instance, please first select a zone you wish to have your virtual
- instance hosted on.
+ You can choose to name and group your virtual machine for easy identification. You can also choose additional data storage. (These options can be added at any time.)
From 23a38bc2be53254659c58f923c44115b2ba845d2 Mon Sep 17 00:00:00 2001
From: Kelven Yang
Date: Wed, 25 Aug 2010 18:17:20 -0700
Subject: [PATCH 19/43] Debug & Test template copy from secondary storage to
primary stroage on vmware
---
api/src/com/cloud/storage/Storage.java | 16 ++++++++++--
.../PrimaryStorageDownloadCommand.java | 26 +++++++++++++++++++
.../cloud/storage/template/VmdkProcessor.java | 10 ++++---
.../cloud/template/TemplateManagerImpl.java | 8 +++++-
utils/src/com/cloud/utils/DateUtil.java | 14 ++++++++--
5 files changed, 65 insertions(+), 9 deletions(-)
diff --git a/api/src/com/cloud/storage/Storage.java b/api/src/com/cloud/storage/Storage.java
index 24ceb5b3fec..7ebdc5e187e 100644
--- a/api/src/com/cloud/storage/Storage.java
+++ b/api/src/com/cloud/storage/Storage.java
@@ -23,16 +23,25 @@ public class Storage {
RAW(false, false, false),
VHD(true, true, true),
ISO(false, false, false),
- VMDK(true, true, true);
+ VMDK(true, true, true, ".tar.bz2");
private final boolean thinProvisioned;
private final boolean supportSparse;
private final boolean supportSnapshot;
+ private final String fileExtension;
private ImageFormat(boolean thinProvisioned, boolean supportSparse, boolean supportSnapshot) {
this.thinProvisioned = thinProvisioned;
this.supportSparse = supportSparse;
this.supportSnapshot = supportSnapshot;
+ fileExtension = null;
+ }
+
+ private ImageFormat(boolean thinProvisioned, boolean supportSparse, boolean supportSnapshot, String fileExtension) {
+ this.thinProvisioned = thinProvisioned;
+ this.supportSparse = supportSparse;
+ this.supportSnapshot = supportSnapshot;
+ this.fileExtension = fileExtension;
}
public boolean isThinProvisioned() {
@@ -48,7 +57,10 @@ public class Storage {
}
public String getFileExtension() {
- return toString().toLowerCase();
+ if(fileExtension == null)
+ return toString().toLowerCase();
+
+ return fileExtension;
}
}
diff --git a/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadCommand.java b/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadCommand.java
index a9010d5782e..f11f17f1bb5 100644
--- a/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadCommand.java
+++ b/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadCommand.java
@@ -28,6 +28,16 @@ public class PrimaryStorageDownloadCommand extends AbstractDownloadCommand {
String localPath;
String poolUuid;
long poolId;
+
+ //
+ // Temporary hacking to make vmware work quickly, expose NFS raw information to allow
+ // agent do quick copy over NFS.
+ //
+ // provide storage URL (it contains all information to help agent resource to mount the
+ // storage if needed, example of such URL may be as following
+ // nfs://192.168.10.231/export/home/kelven/vmware-test/secondary
+ String secondaryStorageUrl;
+ String primaryStorageUrl;
protected PrimaryStorageDownloadCommand() {
}
@@ -54,6 +64,22 @@ public class PrimaryStorageDownloadCommand extends AbstractDownloadCommand {
return localPath;
}
+ public void setSecondaryStorageUrl(String url) {
+ secondaryStorageUrl = url;
+ }
+
+ public String getSecondaryStorageUrl() {
+ return secondaryStorageUrl;
+ }
+
+ public void setPrimaryStorageUrl(String url) {
+ primaryStorageUrl = url;
+ }
+
+ public String getPrimaryStorageUrl() {
+ return primaryStorageUrl;
+ }
+
@Override
public boolean executeInSequence() {
return true;
diff --git a/core/src/com/cloud/storage/template/VmdkProcessor.java b/core/src/com/cloud/storage/template/VmdkProcessor.java
index b8d037c3538..fe060ab02de 100644
--- a/core/src/com/cloud/storage/template/VmdkProcessor.java
+++ b/core/src/com/cloud/storage/template/VmdkProcessor.java
@@ -20,20 +20,22 @@ public class VmdkProcessor implements Processor {
@Override
public FormatInfo process(String templatePath, ImageFormat format, String templateName) throws InternalErrorException {
if (format != null) {
- s_logger.debug("We currently don't handle conversion from " + format + " to VMDK.");
+ if(s_logger.isInfoEnabled())
+ s_logger.info("We currently don't handle conversion from " + format + " to VMDK.");
return null;
}
s_logger.info("Template processing. templatePath: " + templatePath + ", templateName: " + templateName);
- String templateFilePath = templatePath + File.separator + templateName + ".tar.bz2";
+ String templateFilePath = templatePath + File.separator + templateName + ImageFormat.VMDK.getFileExtension();
if (!_storage.exists(templateFilePath)) {
- s_logger.debug("Unable to find the vmware template file: " + templateFilePath);
+ if(s_logger.isInfoEnabled())
+ s_logger.info("Unable to find the vmware template file: " + templateFilePath);
return null;
}
FormatInfo info = new FormatInfo();
info.format = ImageFormat.VMDK;
- info.filename = templateName + ".tar.bz2";
+ info.filename = templateName + ImageFormat.VMDK.getFileExtension();
info.size = _storage.getSize(templateFilePath);
info.virtualSize = info.size;
return info;
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java
index 700aa85c42c..71fe9be0052 100644
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -223,7 +223,13 @@ public class TemplateManagerImpl implements TemplateManager {
return templateStoragePoolRef;
}
String url = origUrl + "/" + templateHostRef.getInstallPath();
- PrimaryStorageDownloadCommand dcmd = new PrimaryStorageDownloadCommand(template.getUniqueName(), url, template.getFormat(), template.getAccountId(), pool.getId(), pool.getUuid());
+ PrimaryStorageDownloadCommand dcmd = new PrimaryStorageDownloadCommand(template.getUniqueName(), url, template.getFormat(),
+ template.getAccountId(), pool.getId(), pool.getUuid());
+ HostVO secondaryStorageHost = _hostDao.findSecondaryStorageHost(pool.getDataCenterId());
+ assert(secondaryStorageHost != null);
+ dcmd.setSecondaryStorageUrl(secondaryStorageHost.getStorageUrl());
+ // TODO temporary hacking, hard-coded to NFS primary data store
+ dcmd.setPrimaryStorageUrl("nfs://" + pool.getHostAddress() + pool.getPath());
for (StoragePoolHostVO vo : vos) {
if (s_logger.isDebugEnabled()) {
diff --git a/utils/src/com/cloud/utils/DateUtil.java b/utils/src/com/cloud/utils/DateUtil.java
index 436bb8df231..c6659a7cfe1 100644
--- a/utils/src/com/cloud/utils/DateUtil.java
+++ b/utils/src/com/cloud/utils/DateUtil.java
@@ -18,6 +18,7 @@
package com.cloud.utils;
+import java.net.URI;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -235,14 +236,22 @@ public class DateUtil {
throw new CloudRuntimeException("Incorrect interval: "+type.toString());
}
-
return scheduleTime.getTime();
}
// test only
public static void main(String[] args) {
-
+ try {
+ URI uri = new URI("nfs://192.168.10.231/export/home/kelven/vmware-test/secondary");
+ System.out.println("protocol: " + uri.getScheme());
+ System.out.println("Host: " + uri.getHost());
+ System.out.println("path: " + uri.getPath());
+ System.out.println("port: " + uri.getPort());
+ } catch(Exception e) {
+ }
+
+/*
TimeZone localTimezone = Calendar.getInstance().getTimeZone();
TimeZone gmtTimezone = TimeZone.getTimeZone("GMT");
TimeZone estTimezone = TimeZone.getTimeZone("EST");
@@ -265,6 +274,7 @@ public class DateUtil {
System.out.println("Parsed TZ time string : "+ dtParsed.toString());
} catch (ParseException e) {
}
+*/
}
}
From f8c93cd5fa5a9dbcfb465b6ba3f057479fd2f740 Mon Sep 17 00:00:00 2001
From: will
Date: Wed, 25 Aug 2010 18:20:49 -0700
Subject: [PATCH 20/43] Bug #:5975
Merge from 2.1.x
- Fixed issue where listAccounts only return one less than the actual number of accounts in the system. That is because the SQL query asks for X accounts, but the API filters out the SYSTEM account. The fix is to add the filter of the system account in the actual query itself rather than have the code do it.
Conflicts:
server/src/com/cloud/api/commands/ListAccountsCmd.java
---
.../cloud/api/commands/ListAccountsCmd.java | 408 +++++++++---------
.../cloud/server/ManagementServerImpl.java | 4 +
2 files changed, 207 insertions(+), 205 deletions(-)
diff --git a/server/src/com/cloud/api/commands/ListAccountsCmd.java b/server/src/com/cloud/api/commands/ListAccountsCmd.java
index 294248fabd0..f2f8561c23f 100644
--- a/server/src/com/cloud/api/commands/ListAccountsCmd.java
+++ b/server/src/com/cloud/api/commands/ListAccountsCmd.java
@@ -16,8 +16,8 @@
*
*/
-package com.cloud.api.commands;
-
+package com.cloud.api.commands;
+
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -36,206 +36,204 @@ import com.cloud.user.UserStatisticsVO;
import com.cloud.uservm.UserVm;
import com.cloud.utils.Pair;
import com.cloud.vm.State;
-
-public class ListAccountsCmd extends BaseCmd{
- public static final Logger s_logger = Logger.getLogger(ListAccountsCmd.class.getName());
- private static final String s_name = "listaccountsresponse";
- private static final List> s_properties = new ArrayList>();
-
- static {
- s_properties.add(new Pair(BaseCmd.Properties.ID, Boolean.FALSE));
- s_properties.add(new Pair(BaseCmd.Properties.NAME, Boolean.FALSE));
- s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT_TYPE, Boolean.FALSE));
- s_properties.add(new Pair(BaseCmd.Properties.STATE, Boolean.FALSE));
- s_properties.add(new Pair(BaseCmd.Properties.IS_CLEANUP_REQUIRED, Boolean.FALSE));
- s_properties.add(new Pair(BaseCmd.Properties.KEYWORD, Boolean.FALSE));
- s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
- s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT, Boolean.FALSE));
- s_properties.add(new Pair(BaseCmd.Properties.DOMAIN_ID, Boolean.FALSE));
- s_properties.add(new Pair(BaseCmd.Properties.PAGE, Boolean.FALSE));
- s_properties.add(new Pair(BaseCmd.Properties.PAGESIZE, Boolean.FALSE));
- }
-
- public String getName() {
- return s_name;
- }
- public List> getProperties() {
- return s_properties;
- }
-
- @Override
- public List> execute(Map params) {
- Long id = (Long)params.get(BaseCmd.Properties.ID.getName());
- Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
- Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName());
- Long type = (Long)params.get(BaseCmd.Properties.ACCOUNT_TYPE.getName());
- String state = (String)params.get(BaseCmd.Properties.STATE.getName());
- Boolean needCleanup = (Boolean)params.get(BaseCmd.Properties.IS_CLEANUP_REQUIRED.getName());
- Integer page = (Integer)params.get(BaseCmd.Properties.PAGE.getName());
- Integer pageSize = (Integer)params.get(BaseCmd.Properties.PAGESIZE.getName());
- String keyword = (String)params.get(BaseCmd.Properties.KEYWORD.getName());
- boolean isAdmin = false;
- Long accountId = null;
-
- String accountName = null;
-
- if ((account == null) || isAdmin(account.getType())) {
- accountName = (String)params.get(BaseCmd.Properties.NAME.getName());
- isAdmin = true;
- if (domainId == null) {
- // default domainId to the admin's domain
- domainId = ((account == null) ? Domain.ROOT_DOMAIN : account.getDomainId());
- } else if (account != null) {
- if (!getManagementServer().isChildDomain(account.getDomainId(), domainId)) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, "Invalid domain id (" + domainId + ") given, unable to list accounts");
- }
- }
- } else {
- accountName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName());
- accountId = account.getId();
- }
-
- Long startIndex = Long.valueOf(0);
- int pageSizeNum = 50;
- if (pageSize != null) {
- pageSizeNum = pageSize.intValue();
- }
- if (page != null) {
- int pageNum = page.intValue();
- if (pageNum > 0) {
- startIndex = Long.valueOf(pageSizeNum * (pageNum-1));
- }
- }
- Criteria c = new Criteria("id", Boolean.TRUE, startIndex, Long.valueOf(pageSizeNum));
- if (isAdmin == true) {
- c.addCriteria(Criteria.ID, id);
- if (keyword == null) {
- c.addCriteria(Criteria.ACCOUNTNAME, accountName);
- c.addCriteria(Criteria.DOMAINID, domainId);
- c.addCriteria(Criteria.TYPE, type);
- c.addCriteria(Criteria.STATE, state);
- c.addCriteria(Criteria.ISCLEANUPREQUIRED, needCleanup);
- } else {
- c.addCriteria(Criteria.KEYWORD, keyword);
- }
- } else {
- c.addCriteria(Criteria.ID, accountId);
- }
-
- List accounts = getManagementServer().searchForAccounts(c);
-
- List> accountTags = new ArrayList>();
- Object[] aTag = new Object[accounts.size()];
- int i = 0;
- for (AccountVO accountO : accounts) {
- boolean accountIsAdmin = (accountO.getType() == Account.ACCOUNT_TYPE_ADMIN);
-
- if ((accountO.getRemoved() == null)&&(accountO.getId() != 1)) {
- List> accountData = new ArrayList>();
- accountData.add(new Pair(BaseCmd.Properties.ID.getName(), Long.valueOf(accountO.getId()).toString()));
- accountData.add(new Pair(BaseCmd.Properties.NAME.getName(), accountO.getAccountName()));
- accountData.add(new Pair(BaseCmd.Properties.ACCOUNT_TYPE.getName(), Short.valueOf(accountO.getType()).toString()));
- Domain domain = getManagementServer().findDomainIdById(accountO.getDomainId());
- accountData.add(new Pair(BaseCmd.Properties.DOMAIN_ID.getName(), Long.toString(domain.getId())));
- accountData.add(new Pair(BaseCmd.Properties.DOMAIN.getName(), domain.getName()));
-
- //get network stat
- List stats = getManagementServer().listUserStatsBy(accountO.getId());
- if (stats == null) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal error searching for user stats");
- }
-
- long bytesSent = 0;
- long bytesReceived = 0;
- for (UserStatisticsVO stat : stats) {
- long rx = stat.getNetBytesReceived() + stat.getCurrentBytesReceived();
- long tx = stat.getNetBytesSent() + stat.getCurrentBytesSent();
- bytesReceived = bytesReceived + Long.valueOf(rx);
- bytesSent = bytesSent + Long.valueOf(tx);
- }
- accountData.add(new Pair(BaseCmd.Properties.BYTES_RECEIVED.getName(), Long.valueOf(bytesReceived).toString()));
- accountData.add(new Pair(BaseCmd.Properties.BYTES_SENT.getName(), Long.valueOf(bytesSent).toString()));
-
- // Get resource limits and counts
-
- long vmLimit = getManagementServer().findCorrectResourceLimit(ResourceType.user_vm, accountO.getId());
- String vmLimitDisplay = (accountIsAdmin || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit);
- long vmTotal = getManagementServer().getResourceCount(ResourceType.user_vm, accountO.getId());
- String vmAvail = (accountIsAdmin || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit - vmTotal);
- accountData.add(new Pair(BaseCmd.Properties.VM_LIMIT.getName(), vmLimitDisplay));
- accountData.add(new Pair(BaseCmd.Properties.VM_TOTAL.getName(), vmTotal));
- accountData.add(new Pair(BaseCmd.Properties.VM_AVAIL.getName(), vmAvail));
-
- long ipLimit = getManagementServer().findCorrectResourceLimit(ResourceType.public_ip, accountO.getId());
- String ipLimitDisplay = (accountIsAdmin || ipLimit == -1) ? "Unlimited" : String.valueOf(ipLimit);
- long ipTotal = getManagementServer().getResourceCount(ResourceType.public_ip, accountO.getId());
- String ipAvail = (accountIsAdmin || ipLimit == -1) ? "Unlimited" : String.valueOf(ipLimit - ipTotal);
- accountData.add(new Pair(BaseCmd.Properties.IP_LIMIT.getName(), ipLimitDisplay));
- accountData.add(new Pair(BaseCmd.Properties.IP_TOTAL.getName(), ipTotal));
- accountData.add(new Pair(BaseCmd.Properties.IP_AVAIL.getName(), ipAvail));
-
- long volumeLimit = getManagementServer().findCorrectResourceLimit(ResourceType.volume, accountO.getId());
- String volumeLimitDisplay = (accountIsAdmin || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit);
- long volumeTotal = getManagementServer().getResourceCount(ResourceType.volume, accountO.getId());
- String volumeAvail = (accountIsAdmin || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit - volumeTotal);
- accountData.add(new Pair(BaseCmd.Properties.VOLUME_LIMIT.getName(), volumeLimitDisplay));
- accountData.add(new Pair(BaseCmd.Properties.VOLUME_TOTAL.getName(), volumeTotal));
- accountData.add(new Pair(BaseCmd.Properties.VOLUME_AVAIL.getName(), volumeAvail));
-
- long snapshotLimit = getManagementServer().findCorrectResourceLimit(ResourceType.snapshot, accountO.getId());
- String snapshotLimitDisplay = (accountIsAdmin || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit);
- long snapshotTotal = getManagementServer().getResourceCount(ResourceType.snapshot, accountO.getId());
- String snapshotAvail = (accountIsAdmin || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit - snapshotTotal);
- accountData.add(new Pair(BaseCmd.Properties.SNAPSHOT_LIMIT.getName(), snapshotLimitDisplay));
- accountData.add(new Pair(BaseCmd.Properties.SNAPSHOT_TOTAL.getName(), snapshotTotal));
- accountData.add(new Pair(BaseCmd.Properties.SNAPSHOT_AVAIL.getName(), snapshotAvail));
-
- long templateLimit = getManagementServer().findCorrectResourceLimit(ResourceType.template, accountO.getId());
- String templateLimitDisplay = (accountIsAdmin || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit);
- long templateTotal = getManagementServer().getResourceCount(ResourceType.template, accountO.getId());
- String templateAvail = (accountIsAdmin || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit - templateTotal);
- accountData.add(new Pair(BaseCmd.Properties.TEMPLATE_LIMIT.getName(), templateLimitDisplay));
- accountData.add(new Pair(BaseCmd.Properties.TEMPLATE_TOTAL.getName(), templateTotal));
- accountData.add(new Pair(BaseCmd.Properties.TEMPLATE_AVAIL.getName(), templateAvail));
-
- // Get stopped and running VMs
-
- int vmStopped = 0;
- int vmRunning = 0;
-
- Long[] accountIds = new Long[1];
- accountIds[0] = accountO.getId();
-
- Criteria c1 = new Criteria();
- c1.addCriteria(Criteria.ACCOUNTID, accountIds);
- List extends UserVm> virtualMachines = getManagementServer().searchForUserVMs(c1);
-
- //get Running/Stopped VMs
- for (Iterator extends UserVm> iter = virtualMachines.iterator(); iter.hasNext();) {
- // count how many stopped/running vms we have
- UserVm vm = iter.next();
-
- if (vm.getState() == State.Stopped) {
- vmStopped++;
- } else if (vm.getState() == State.Running) {
- vmRunning++;
- }
- }
-
- accountData.add(new Pair(BaseCmd.Properties.VM_STOPPED.getName(), vmStopped));
- accountData.add(new Pair(BaseCmd.Properties.VM_RUNNING.getName(), vmRunning));
-
- //show this info to admins only
- if (isAdmin == true) {
- accountData.add(new Pair(BaseCmd.Properties.STATE.getName(), accountO.getState()));
- accountData.add(new Pair(BaseCmd.Properties.IS_CLEANUP_REQUIRED.getName(), Boolean.valueOf(accountO.getNeedsCleanup()).toString()));
- }
-
- aTag[i++] = accountData;
- }
- }
- Pair accountTag = new Pair("account", aTag);
- accountTags.add(accountTag);
- return accountTags;
- }
-}
+
+public class ListAccountsCmd extends BaseCmd{
+ public static final Logger s_logger = Logger.getLogger(ListAccountsCmd.class.getName());
+ private static final String s_name = "listaccountsresponse";
+ private static final List> s_properties = new ArrayList>();
+
+ static {
+ s_properties.add(new Pair(BaseCmd.Properties.ID, Boolean.FALSE));
+ s_properties.add(new Pair(BaseCmd.Properties.NAME, Boolean.FALSE));
+ s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT_TYPE, Boolean.FALSE));
+ s_properties.add(new Pair(BaseCmd.Properties.STATE, Boolean.FALSE));
+ s_properties.add(new Pair(BaseCmd.Properties.IS_CLEANUP_REQUIRED, Boolean.FALSE));
+ s_properties.add(new Pair(BaseCmd.Properties.KEYWORD, Boolean.FALSE));
+ s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
+ s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT, Boolean.FALSE));
+ s_properties.add(new Pair(BaseCmd.Properties.DOMAIN_ID, Boolean.FALSE));
+ s_properties.add(new Pair(BaseCmd.Properties.PAGE, Boolean.FALSE));
+ s_properties.add(new Pair(BaseCmd.Properties.PAGESIZE, Boolean.FALSE));
+ }
+
+ public String getName() {
+ return s_name;
+ }
+ public List> getProperties() {
+ return s_properties;
+ }
+
+ @Override
+ public List> execute(Map params) {
+ Long id = (Long)params.get(BaseCmd.Properties.ID.getName());
+ Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
+ Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName());
+ Long type = (Long)params.get(BaseCmd.Properties.ACCOUNT_TYPE.getName());
+ String state = (String)params.get(BaseCmd.Properties.STATE.getName());
+ Boolean needCleanup = (Boolean)params.get(BaseCmd.Properties.IS_CLEANUP_REQUIRED.getName());
+ Integer page = (Integer)params.get(BaseCmd.Properties.PAGE.getName());
+ Integer pageSize = (Integer)params.get(BaseCmd.Properties.PAGESIZE.getName());
+ String keyword = (String)params.get(BaseCmd.Properties.KEYWORD.getName());
+ boolean isAdmin = false;
+ Long accountId = null;
+
+ String accountName = null;
+
+ if ((account == null) || isAdmin(account.getType())) {
+ accountName = (String)params.get(BaseCmd.Properties.NAME.getName());
+ isAdmin = true;
+ if (domainId == null) {
+ // default domainId to the admin's domain
+ domainId = ((account == null) ? Domain.ROOT_DOMAIN : account.getDomainId());
+ } else if (account != null) {
+ if (!getManagementServer().isChildDomain(account.getDomainId(), domainId)) {
+ throw new ServerApiException(BaseCmd.PARAM_ERROR, "Invalid domain id (" + domainId + ") given, unable to list accounts");
+ }
+ }
+ } else {
+ accountName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName());
+ accountId = account.getId();
+ }
+
+ Long startIndex = Long.valueOf(0);
+ int pageSizeNum = 50;
+ if (pageSize != null) {
+ pageSizeNum = pageSize.intValue();
+ }
+ if (page != null) {
+ int pageNum = page.intValue();
+ if (pageNum > 0) {
+ startIndex = Long.valueOf(pageSizeNum * (pageNum-1));
+ }
+ }
+ Criteria c = new Criteria("id", Boolean.TRUE, startIndex, Long.valueOf(pageSizeNum));
+ if (isAdmin == true) {
+ c.addCriteria(Criteria.ID, id);
+ if (keyword == null) {
+ c.addCriteria(Criteria.ACCOUNTNAME, accountName);
+ c.addCriteria(Criteria.DOMAINID, domainId);
+ c.addCriteria(Criteria.TYPE, type);
+ c.addCriteria(Criteria.STATE, state);
+ c.addCriteria(Criteria.ISCLEANUPREQUIRED, needCleanup);
+ } else {
+ c.addCriteria(Criteria.KEYWORD, keyword);
+ }
+ } else {
+ c.addCriteria(Criteria.ID, accountId);
+ }
+
+ List accounts = getManagementServer().searchForAccounts(c);
+
+ List> accountTags = new ArrayList>();
+ Object[] aTag = new Object[accounts.size()];
+ int i = 0;
+ for (AccountVO accountO : accounts) {
+ boolean accountIsAdmin = (accountO.getType() == Account.ACCOUNT_TYPE_ADMIN);
+
+ List> accountData = new ArrayList>();
+ accountData.add(new Pair(BaseCmd.Properties.ID.getName(), Long.valueOf(accountO.getId()).toString()));
+ accountData.add(new Pair(BaseCmd.Properties.NAME.getName(), accountO.getAccountName()));
+ accountData.add(new Pair(BaseCmd.Properties.ACCOUNT_TYPE.getName(), Short.valueOf(accountO.getType()).toString()));
+ Domain domain = getManagementServer().findDomainIdById(accountO.getDomainId());
+ accountData.add(new Pair(BaseCmd.Properties.DOMAIN_ID.getName(), Long.toString(domain.getId())));
+ accountData.add(new Pair(BaseCmd.Properties.DOMAIN.getName(), domain.getName()));
+
+ //get network stat
+ List stats = getManagementServer().listUserStatsBy(accountO.getId());
+ if (stats == null) {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal error searching for user stats");
+ }
+
+ long bytesSent = 0;
+ long bytesReceived = 0;
+ for (UserStatisticsVO stat : stats) {
+ long rx = stat.getNetBytesReceived() + stat.getCurrentBytesReceived();
+ long tx = stat.getNetBytesSent() + stat.getCurrentBytesSent();
+ bytesReceived = bytesReceived + Long.valueOf(rx);
+ bytesSent = bytesSent + Long.valueOf(tx);
+ }
+ accountData.add(new Pair(BaseCmd.Properties.BYTES_RECEIVED.getName(), Long.valueOf(bytesReceived).toString()));
+ accountData.add(new Pair(BaseCmd.Properties.BYTES_SENT.getName(), Long.valueOf(bytesSent).toString()));
+
+ // Get resource limits and counts
+
+ long vmLimit = getManagementServer().findCorrectResourceLimit(ResourceType.user_vm, accountO.getId());
+ String vmLimitDisplay = (accountIsAdmin || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit);
+ long vmTotal = getManagementServer().getResourceCount(ResourceType.user_vm, accountO.getId());
+ String vmAvail = (accountIsAdmin || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit - vmTotal);
+ accountData.add(new Pair(BaseCmd.Properties.VM_LIMIT.getName(), vmLimitDisplay));
+ accountData.add(new Pair(BaseCmd.Properties.VM_TOTAL.getName(), vmTotal));
+ accountData.add(new Pair(BaseCmd.Properties.VM_AVAIL.getName(), vmAvail));
+
+ long ipLimit = getManagementServer().findCorrectResourceLimit(ResourceType.public_ip, accountO.getId());
+ String ipLimitDisplay = (accountIsAdmin || ipLimit == -1) ? "Unlimited" : String.valueOf(ipLimit);
+ long ipTotal = getManagementServer().getResourceCount(ResourceType.public_ip, accountO.getId());
+ String ipAvail = (accountIsAdmin || ipLimit == -1) ? "Unlimited" : String.valueOf(ipLimit - ipTotal);
+ accountData.add(new Pair(BaseCmd.Properties.IP_LIMIT.getName(), ipLimitDisplay));
+ accountData.add(new Pair(BaseCmd.Properties.IP_TOTAL.getName(), ipTotal));
+ accountData.add(new Pair(BaseCmd.Properties.IP_AVAIL.getName(), ipAvail));
+
+ long volumeLimit = getManagementServer().findCorrectResourceLimit(ResourceType.volume, accountO.getId());
+ String volumeLimitDisplay = (accountIsAdmin || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit);
+ long volumeTotal = getManagementServer().getResourceCount(ResourceType.volume, accountO.getId());
+ String volumeAvail = (accountIsAdmin || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit - volumeTotal);
+ accountData.add(new Pair(BaseCmd.Properties.VOLUME_LIMIT.getName(), volumeLimitDisplay));
+ accountData.add(new Pair(BaseCmd.Properties.VOLUME_TOTAL.getName(), volumeTotal));
+ accountData.add(new Pair(BaseCmd.Properties.VOLUME_AVAIL.getName(), volumeAvail));
+
+ long snapshotLimit = getManagementServer().findCorrectResourceLimit(ResourceType.snapshot, accountO.getId());
+ String snapshotLimitDisplay = (accountIsAdmin || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit);
+ long snapshotTotal = getManagementServer().getResourceCount(ResourceType.snapshot, accountO.getId());
+ String snapshotAvail = (accountIsAdmin || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit - snapshotTotal);
+ accountData.add(new Pair(BaseCmd.Properties.SNAPSHOT_LIMIT.getName(), snapshotLimitDisplay));
+ accountData.add(new Pair(BaseCmd.Properties.SNAPSHOT_TOTAL.getName(), snapshotTotal));
+ accountData.add(new Pair(BaseCmd.Properties.SNAPSHOT_AVAIL.getName(), snapshotAvail));
+
+ long templateLimit = getManagementServer().findCorrectResourceLimit(ResourceType.template, accountO.getId());
+ String templateLimitDisplay = (accountIsAdmin || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit);
+ long templateTotal = getManagementServer().getResourceCount(ResourceType.template, accountO.getId());
+ String templateAvail = (accountIsAdmin || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit - templateTotal);
+ accountData.add(new Pair(BaseCmd.Properties.TEMPLATE_LIMIT.getName(), templateLimitDisplay));
+ accountData.add(new Pair(BaseCmd.Properties.TEMPLATE_TOTAL.getName(), templateTotal));
+ accountData.add(new Pair(BaseCmd.Properties.TEMPLATE_AVAIL.getName(), templateAvail));
+
+ // Get stopped and running VMs
+
+ int vmStopped = 0;
+ int vmRunning = 0;
+
+ Long[] accountIds = new Long[1];
+ accountIds[0] = accountO.getId();
+
+ Criteria c1 = new Criteria();
+ c1.addCriteria(Criteria.ACCOUNTID, accountIds);
+ List extends UserVm> virtualMachines = getManagementServer().searchForUserVMs(c1);
+
+ //get Running/Stopped VMs
+ for (Iterator extends UserVm> iter = virtualMachines.iterator(); iter.hasNext();) {
+ // count how many stopped/running vms we have
+ UserVm vm = iter.next();
+
+ if (vm.getState() == State.Stopped) {
+ vmStopped++;
+ } else if (vm.getState() == State.Running) {
+ vmRunning++;
+ }
+ }
+
+ accountData.add(new Pair(BaseCmd.Properties.VM_STOPPED.getName(), vmStopped));
+ accountData.add(new Pair(BaseCmd.Properties.VM_RUNNING.getName(), vmRunning));
+
+ //show this info to admins only
+ if (isAdmin == true) {
+ accountData.add(new Pair(BaseCmd.Properties.STATE.getName(), accountO.getState()));
+ accountData.add(new Pair(BaseCmd.Properties.IS_CLEANUP_REQUIRED.getName(), Boolean.valueOf(accountO.getNeedsCleanup()).toString()));
+ }
+
+ aTag[i++] = accountData;
+ }
+ Pair accountTag = new Pair("account", aTag);
+ accountTags.add(accountTag);
+ return accountTags;
+ }
+}
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index c477a6d226e..290bd49f0b3 100644
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -4402,6 +4402,7 @@ public class ManagementServerImpl implements ManagementServer {
SearchBuilder sb = _accountDao.createSearchBuilder();
sb.and("accountName", sb.entity().getAccountName(), SearchCriteria.Op.LIKE);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
+ sb.and("nid", sb.entity().getId(), SearchCriteria.Op.NEQ);
sb.and("type", sb.entity().getType(), SearchCriteria.Op.EQ);
sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
sb.and("needsCleanup", sb.entity().getNeedsCleanup(), SearchCriteria.Op.EQ);
@@ -4433,6 +4434,9 @@ public class ManagementServerImpl implements ManagementServer {
// I want to join on user_vm.domain_id = domain.id where domain.path like 'foo%'
sc.setJoinParameters("domainSearch", "path", domain.getPath() + "%");
+ sc.setParameters("nid", 1L);
+ } else {
+ sc.setParameters("nid", 1L);
}
if (type != null) {
From 99c0c662a83eeec2b92a40bd6417363aa19faebc Mon Sep 17 00:00:00 2001
From: jessica
Date: Wed, 25 Aug 2010 18:01:59 -0700
Subject: [PATCH 21/43] Issue #: 5945 - replace index.html with index.jsp
---
ui/index.jsp | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 173 insertions(+)
create mode 100755 ui/index.jsp
diff --git a/ui/index.jsp b/ui/index.jsp
new file mode 100755
index 00000000000..8be1f714663
--- /dev/null
+++ b/ui/index.jsp
@@ -0,0 +1,173 @@
+<%@ page import="java.util.Date" %>
+
+<%
+long milliseconds = new Date().getTime();
+%>
+
+
+
+
+
+
+
+
+
+
+ cloud.com - User Console
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Cloud.com CloudStack
+
+
+