From 0ed810824c52a5ff062bd74438515bda52c1a0ff Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 29 Mar 2011 10:52:11 -0700 Subject: [PATCH 01/72] bug 9189: add new command --- .../agent/api/CreateStoragePoolCommand.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 api/src/com/cloud/agent/api/CreateStoragePoolCommand.java diff --git a/api/src/com/cloud/agent/api/CreateStoragePoolCommand.java b/api/src/com/cloud/agent/api/CreateStoragePoolCommand.java new file mode 100644 index 00000000000..5c8e41f6f14 --- /dev/null +++ b/api/src/com/cloud/agent/api/CreateStoragePoolCommand.java @@ -0,0 +1,32 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.cloud.agent.api; + +import com.cloud.storage.StoragePool; + +public class CreateStoragePoolCommand extends ModifyStoragePoolCommand { + + + public CreateStoragePoolCommand() { + } + + public CreateStoragePoolCommand(boolean add, StoragePool pool) { + super(add, pool); + } +} From e87ffdec3e5802d97fad1e94c58b2169116d23ef Mon Sep 17 00:00:00 2001 From: prachi Date: Tue, 29 Mar 2011 11:05:05 -0700 Subject: [PATCH 02/72] Database upgrade from 222 to 224 for Bug 6873 - disable/enable mode for clusters (and pods and zones and hosts) - Adding column and index 'allocation_state' to clusters and pods and zones and hosts --- setup/db/schema-222to224-cleanup.sql | 2 ++ setup/db/schema-222to224.sql | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/setup/db/schema-222to224-cleanup.sql b/setup/db/schema-222to224-cleanup.sql index 82df638a24c..650482bb563 100644 --- a/setup/db/schema-222to224-cleanup.sql +++ b/setup/db/schema-222to224-cleanup.sql @@ -1,3 +1,5 @@ ALTER TABLE `cloud`.`account_vlan_map` DROP FOREIGN KEY `fk_account_vlan_map__domain_id`; ALTER TABLE `cloud`.`account_vlan_map` DROP COLUMN `domain_id`; DELETE FROM `cloud`.`account_vlan_map` WHERE account_id IS NULL; +ALTER TABLE `cloud`.`data_center` DROP COLUMN `enable`; +ALTER TABLE `cloud`.`host_pod_ref` DROP COLUMN `enabled`; \ No newline at end of file diff --git a/setup/db/schema-222to224.sql b/setup/db/schema-222to224.sql index b8a309af666..56be9cd85e1 100644 --- a/setup/db/schema-222to224.sql +++ b/setup/db/schema-222to224.sql @@ -50,4 +50,11 @@ INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (138, 7, ' UPDATE `cloud`.`network_offerings` SET `nw_rate`=0, `mc_rate`=0 WHERE system_only=1 and guest_type IS NULL; UPDATE `cloud`.`network_offerings` SET `default`=1 WHERE system_only=1; - +ALTER TABLE `cloud`.`data_center` ADD COLUMN `allocation_state` varchar(32) NOT NULL DEFAULT 'Enabled'; +ALTER TABLE `cloud`.`data_center` ADD INDEX `i_data_center__allocation_state`(`allocation_state`); +ALTER TABLE `cloud`.`cluster` ADD COLUMN `allocation_state` varchar(32) NOT NULL DEFAULT 'Enabled'; +ALTER TABLE `cloud`.`cluster` ADD INDEX `i_cluster__allocation_state`(`allocation_state`); +ALTER TABLE `cloud`.`host_pod_ref` ADD COLUMN `allocation_state` varchar(32) NOT NULL DEFAULT 'Enabled'; +ALTER TABLE `cloud`.`host_pod_ref` ADD INDEX `i_host_pod_ref__allocation_state`(`allocation_state`); +ALTER TABLE `cloud`.`host` ADD COLUMN `allocation_state` varchar(32) NOT NULL DEFAULT 'Enabled'; +ALTER TABLE `cloud`.`host` ADD INDEX `i_host__allocation_state`(`allocation_state`); \ No newline at end of file From 6bd978abfe4e68fa62b708fd5eb4b8eb2b5c19f8 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Tue, 29 Mar 2011 11:31:11 -0700 Subject: [PATCH 03/72] bug 9192: fixes the caches that are gone due to configuration server uses the same dao without cache --- .../xen/resource/CitrixResourceBase.java | 19 +++++++++++-------- .../com/cloud/resource/ServerResource.java | 14 ++++++-------- setup/db/create-schema.sql | 11 +++++++---- .../utils/component/ComponentLocator.java | 5 ++++- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 8daab50a175..710194405aa 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -172,6 +172,7 @@ import com.cloud.network.ovs.OvsDestroyTunnelCommand; import com.cloud.network.ovs.OvsSetTagAndFlowAnswer; import com.cloud.network.ovs.OvsSetTagAndFlowCommand; import com.cloud.resource.ServerResource; +import com.cloud.resource.hypervisor.HypervisorResource; import com.cloud.storage.Storage; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.StoragePoolType; @@ -221,7 +222,7 @@ import com.xensource.xenapi.XenAPIObject; * */ @Local(value = ServerResource.class) -public abstract class CitrixResourceBase implements ServerResource { +public abstract class CitrixResourceBase implements ServerResource, HypervisorResource { private static final Logger s_logger = Logger.getLogger(CitrixResourceBase.class); protected static final XenServerConnectionPool _connPool = XenServerConnectionPool.getInstance(); protected static final int MB = 1024 * 1024; @@ -376,7 +377,6 @@ public abstract class CitrixResourceBase implements ServerResource { @Override public Answer executeRequest(Command cmd) { - if (cmd instanceof CreateCommand) { return execute((CreateCommand) cmd); } else if (cmd instanceof SetPortForwardingRulesCommand) { @@ -1006,7 +1006,8 @@ public abstract class CitrixResourceBase implements ServerResource { } } - protected StartAnswer execute(StartCommand cmd) { + @Override + public StartAnswer execute(StartCommand cmd) { Connection conn = getConnection(); VirtualMachineTO vmSpec = cmd.getVirtualMachine(); String vmName = vmSpec.getName(); @@ -2575,7 +2576,8 @@ public abstract class CitrixResourceBase implements ServerResource { return NumbersUtil.parseInt(vncport, -1); } - protected Answer execute(final RebootCommand cmd) { + @Override + public RebootAnswer execute(RebootCommand cmd) { Connection conn = getConnection(); synchronized (_vms) { _vms.put(cmd.getVmName(), State.Starting); @@ -2617,7 +2619,7 @@ public abstract class CitrixResourceBase implements ServerResource { bytesSent = stats[0]; bytesRcvd = stats[1]; } - RebootAnswer answer = (RebootAnswer) execute((RebootCommand) cmd); + RebootAnswer answer = execute((RebootCommand) cmd); answer.setBytesSent(bytesSent); answer.setBytesReceived(bytesRcvd); if (answer.getResult()) { @@ -2952,8 +2954,9 @@ public abstract class CitrixResourceBase implements ServerResource { } return null; } - - protected StopAnswer execute(final StopCommand cmd) { + + @Override + public StopAnswer execute(StopCommand cmd) { Connection conn = getConnection(); String vmName = cmd.getVmName(); try { @@ -3082,7 +3085,7 @@ public abstract class CitrixResourceBase implements ServerResource { } return new StopAnswer(cmd, "Stop VM failed"); } - + private List getVdis(Connection conn, VM vm) { List vdis = new ArrayList(); try { diff --git a/core/src/com/cloud/resource/ServerResource.java b/core/src/com/cloud/resource/ServerResource.java index ca657140f60..af1dc3e6cab 100755 --- a/core/src/com/cloud/resource/ServerResource.java +++ b/core/src/com/cloud/resource/ServerResource.java @@ -40,35 +40,33 @@ public interface ServerResource extends Manager { * Generate a startup command containing information regarding the resource. * @return StartupCommand ready to be sent to the management server. */ - public StartupCommand[] initialize(); + StartupCommand[] initialize(); /** * @param id id of the server to put in the PingCommand * @return PingCommand */ - public PingCommand getCurrentStatus(long id); + PingCommand getCurrentStatus(long id); /** * Execute the request coming from the computing server. * @param cmd Command to execute. * @return Answer */ - public Answer executeRequest(Command cmd); - -// public void revertRequest(Command cmd, Answer answer); + Answer executeRequest(Command cmd); /** * disconnected() is called when the connection is down between the * agent and the management server. If there are any cleanups, this * is the time to do it. */ - public void disconnected(); + void disconnected(); /** * This is added to allow calling agent control service from within the resource * @return */ - public IAgentControl getAgentControl(); + IAgentControl getAgentControl(); - public void setAgentControl(IAgentControl agentControl); + void setAgentControl(IAgentControl agentControl); } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 2ac0784399b..6fd9850fc6d 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -189,7 +189,8 @@ CREATE TABLE `cloud`.`networks` ( CONSTRAINT `fk_networks__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`), CONSTRAINT `fk_networks__related` FOREIGN KEY(`related`) REFERENCES `networks`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_networks__account_id` FOREIGN KEY(`account_id`) REFERENCES `account`(`id`), - CONSTRAINT `fk_networks__domain_id` FOREIGN KEY(`domain_id`) REFERENCES `domain`(`id`) + CONSTRAINT `fk_networks__domain_id` FOREIGN KEY(`domain_id`) REFERENCES `domain`(`id`), + INDEX `i_networks__removed`(`removed`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `cloud`.`account_network_ref` ( @@ -237,7 +238,8 @@ CREATE TABLE `cloud`.`nics` ( `removed` datetime COMMENT 'date removed if not null', PRIMARY KEY (`id`), CONSTRAINT `fk_nics__instance_id` FOREIGN KEY `fk_nics__instance_id`(`instance_id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE, - CONSTRAINT `fk_nics__networks_id` FOREIGN KEY `fk_nics__networks_id`(`network_id`) REFERENCES `networks`(`id`) + CONSTRAINT `fk_nics__networks_id` FOREIGN KEY `fk_nics__networks_id`(`network_id`) REFERENCES `networks`(`id`), + INDEX `i_nics__removed`(`removed`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `cloud`.`network_offerings` ( @@ -264,7 +266,8 @@ CREATE TABLE `cloud`.`network_offerings` ( `vpn_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if network offering provides vpn service', `dhcp_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if network offering provides dhcp service', `guest_type` char(32) COMMENT 'guest ip type of network offering', - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), + INDEX `i_network_offerings__removed`(`removed`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `cloud`.`cluster` ( @@ -435,7 +438,7 @@ CREATE TABLE `cloud`.`vlan` ( `data_center_id` bigint unsigned NOT NULL, `network_id` bigint unsigned NOT NULL COMMENT 'id of corresponding network offering', PRIMARY KEY (`id`), -# CONSTRAINT `fk_vlan__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`), + CONSTRAINT `fk_vlan__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`), CONSTRAINT `fk_vlan__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/utils/src/com/cloud/utils/component/ComponentLocator.java b/utils/src/com/cloud/utils/component/ComponentLocator.java index 87e4b7662d6..0ca1ddc1b91 100755 --- a/utils/src/com/cloud/utils/component/ComponentLocator.java +++ b/utils/src/com/cloud/utils/component/ComponentLocator.java @@ -856,7 +856,6 @@ public class ComponentLocator implements ComponentLocatorMBean { if (info.name == null) { throw new CloudRuntimeException("Missing name attribute for " + interphace.getName()); } - info.name = info.name; s_logger.debug("Looking for class " + clazzName); try { info.clazz = Class.forName(clazzName); @@ -869,6 +868,10 @@ public class ComponentLocator implements ComponentLocatorMBean { if (!interphace.isAssignableFrom(info.clazz)) { throw new CloudRuntimeException("Class " + info.clazz.toString() + " does not implment " + interphace); } + String singleton = getAttribute(atts, "singleton"); + if (singleton != null) { + info.singleton = Boolean.parseBoolean(singleton); + } info.fillInfo(); } From a7953c1e7a837a4dd75b23dc28e9a2f51997b5d2 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Tue, 29 Mar 2011 14:57:16 -0400 Subject: [PATCH 04/72] bug 9205: resolved fixed status 9205: fix NPE in usageEvent --- server/src/com/cloud/template/TemplateManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index b21a0dd1c44..5408358aadf 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -941,7 +941,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe } } - Account account = _accountDao.findById(template.getAccountId()); + Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId()); String eventType = ""; if (template.getFormat().equals(ImageFormat.ISO)){ From 0a66b176aaf9c4814da6cb49b2b7f201c1983f79 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 29 Mar 2011 15:14:44 -0700 Subject: [PATCH 05/72] Fix the incorrect "," in CitrixResourceBase.java --- .../cloud/hypervisor/xen/resource/CitrixResourceBase.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 710194405aa..35dc9355061 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -4703,8 +4703,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe continue; } if (target.equals(dc.get("target")) && targetiqn.equals(dc.get("targetIQN")) && lunid.equals(dc.get("lunid"))) { - throw new CloudRuntimeException("There is a SR using the same configuration target:" + dc.get("target") + ", targetIQN:" - + dc.get("targetIQN") + ", lunid:" + dc.get("lunid") + " for pool " + pool.getUuid() + "on host:" + _host.uuid); + throw new CloudRuntimeException("There is a SR using the same configuration target:" + dc.get("target") + ", targetIQN:" + + dc.get("targetIQN") + ", lunid:" + dc.get("lunid") + " for pool " + pool.getUuid() + "on host:" + _host.uuid); } } deviceConfig.put("target", target); @@ -4816,7 +4816,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } if (server.equals(dc.get("server")) && serverpath.equals(dc.get("serverpath"))) { - throw new CloudRuntimeException("There is a SR using the same configuration server:" + dc.get("server") + ", serverpath:" + throw new CloudRuntimeException("There is a SR using the same configuration server:" + dc.get("server") + ", serverpath:" + dc.get("serverpath") + " for pool " + pool.getUuid() + "on host:" + _host.uuid); } From 38e95455d128d8c0f54a123db1435f447460cfa4 Mon Sep 17 00:00:00 2001 From: will Date: Tue, 29 Mar 2011 17:23:18 -0700 Subject: [PATCH 06/72] rollbacked create-schema foreign key constraint until we can figure out a way to make sure server-setup.xml isn't broken by this for developers. --- setup/db/create-schema.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 6fd9850fc6d..1b727bb089b 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -438,7 +438,7 @@ CREATE TABLE `cloud`.`vlan` ( `data_center_id` bigint unsigned NOT NULL, `network_id` bigint unsigned NOT NULL COMMENT 'id of corresponding network offering', PRIMARY KEY (`id`), - CONSTRAINT `fk_vlan__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`), + #CONSTRAINT `fk_vlan__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`), CONSTRAINT `fk_vlan__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; From bdb42c306ccb80d5b90439aa621f236e0aa02043 Mon Sep 17 00:00:00 2001 From: will Date: Tue, 29 Mar 2011 18:52:01 -0700 Subject: [PATCH 07/72] bug 9021: Fixed network rate display issue in network offering. Merge from master --- client/WEB-INF/classes/resources/messages.properties | 1 + client/WEB-INF/classes/resources/messages_es.properties | 1 + client/WEB-INF/classes/resources/messages_ja.properties | 3 ++- .../WEB-INF/classes/resources/messages_zh_CN.properties | 1 + ui/jsp/networkoffering.jsp | 3 ++- ui/scripts/cloud.core.networkoffering.js | 9 +++++++-- 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/client/WEB-INF/classes/resources/messages.properties b/client/WEB-INF/classes/resources/messages.properties index 632f5a76abd..2fdd1e50ea2 100644 --- a/client/WEB-INF/classes/resources/messages.properties +++ b/client/WEB-INF/classes/resources/messages.properties @@ -559,6 +559,7 @@ label.tuesday=Tuesday label.type.id=Type ID label.type=Type label.unavailable=Unavailable +label.unlimited=Unlimited label.untagged=Untagged label.update.ssl.cert=Update SSL Certificate label.update.ssl=Update SSL Certificate diff --git a/client/WEB-INF/classes/resources/messages_es.properties b/client/WEB-INF/classes/resources/messages_es.properties index 48967dc1dd9..310912df12d 100644 --- a/client/WEB-INF/classes/resources/messages_es.properties +++ b/client/WEB-INF/classes/resources/messages_es.properties @@ -559,6 +559,7 @@ label.tuesday = martes label.type = Tipo label.type.id = Tipo de identificación label.unavailable = no disponible +label.unlimited=Unlimited label.untagged = sin etiquetar label.update.ssl = Actualizar certificado SSL label.update.ssl.cert = Actualizar certificado SSL diff --git a/client/WEB-INF/classes/resources/messages_ja.properties b/client/WEB-INF/classes/resources/messages_ja.properties index 19f46ca19b8..ffb2aea15bc 100644 --- a/client/WEB-INF/classes/resources/messages_ja.properties +++ b/client/WEB-INF/classes/resources/messages_ja.properties @@ -558,7 +558,8 @@ label.traffic.type =トラフィックタイプ label.tuesday =火曜日 label.type =タイプ label.type.id =タイプID -label.unavailable =使用不可 +label.unavailable =使用不可 +label.unlimited=無制限の label.untagged=タグなし label.update.ssl =SSL証明書更新 label.update.ssl.cert =SSL証明書更新 diff --git a/client/WEB-INF/classes/resources/messages_zh_CN.properties b/client/WEB-INF/classes/resources/messages_zh_CN.properties index 63c55e52e57..825103c79a6 100644 --- a/client/WEB-INF/classes/resources/messages_zh_CN.properties +++ b/client/WEB-INF/classes/resources/messages_zh_CN.properties @@ -559,6 +559,7 @@ label.tuesday =星期二 label.type =类型 label.type.id = 类型编码 label.unavailable =不可用 +label.unlimited=无限 label.untagged =Untagged label.update.ssl =更新SSL证书 label.update.ssl.cert =更新SSL证书 diff --git a/ui/jsp/networkoffering.jsp b/ui/jsp/networkoffering.jsp index 1e8fb207b25..b90834da9d1 100644 --- a/ui/jsp/networkoffering.jsp +++ b/ui/jsp/networkoffering.jsp @@ -7,7 +7,8 @@ diff --git a/ui/scripts/cloud.core.networkoffering.js b/ui/scripts/cloud.core.networkoffering.js index aea24a74575..1b1443d874c 100644 --- a/ui/scripts/cloud.core.networkoffering.js +++ b/ui/scripts/cloud.core.networkoffering.js @@ -166,8 +166,13 @@ function networkOfferingJsonToDetailsTab() { setBooleanReadField(jsonObj.isdefault, $thisTab.find("#isdefault")); setBooleanReadField(jsonObj.specifyvlan, $thisTab.find("#specifyvlan")); - - $thisTab.find("#rate").text(fromdb(jsonObj.networkrate) + " Mb/s"); + + var networkRate = jsonObj.networkrate; + if (networkRate == undefined || networkRate == "-1") { + $thisTab.find("#rate").text(dictionary["label.unlimited"]); + } else { + $thisTab.find("#rate").text(fromdb(networkRate) + " Mb/s"); + } $thisTab.find("#traffictype").text(fromdb(jsonObj.traffictype)); //actions *** From 2af46789cb3c4d9cd78fc76f9cb3f1295547ffe0 Mon Sep 17 00:00:00 2001 From: alena Date: Tue, 29 Mar 2011 16:42:25 -0700 Subject: [PATCH 08/72] bug 9192: multiple improvementes to listVms command. 1) No longer do multiple searches involving "domain" table; only one join with domain is being done. 2) Do join with domain table only when command is executed by domainAdmin 3) Added index for "path" field in "domain" table 4) No longer do joins with account table as account_id is already present in vm_instance table. --- .../com/cloud/api/commands/ListVMsCmd.java | 2 +- server/src/com/cloud/acl/DomainChecker.java | 6 +- server/src/com/cloud/api/ApiDBUtils.java | 2 +- .../src/com/cloud/api/ApiResponseHelper.java | 9 +- .../src/com/cloud/vm/UserVmManagerImpl.java | 184 +++++++----------- setup/db/create-schema.sql | 3 +- setup/db/schema-222to224.sql | 5 +- 7 files changed, 84 insertions(+), 127 deletions(-) diff --git a/api/src/com/cloud/api/commands/ListVMsCmd.java b/api/src/com/cloud/api/commands/ListVMsCmd.java index f6351361b29..ca96b338ae0 100755 --- a/api/src/com/cloud/api/commands/ListVMsCmd.java +++ b/api/src/com/cloud/api/commands/ListVMsCmd.java @@ -47,7 +47,7 @@ public class ListVMsCmd extends BaseListCmd { @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID. If used with the account parameter, lists virtual machines for the specified account in this domain.") private Long domainId; - @Parameter(name=ApiConstants.IS_RECURSIVE, type=CommandType.BOOLEAN, description="defaults to false, but if true, lists all vms from the parent specified by the domain id till leaves.") + @Parameter(name=ApiConstants.IS_RECURSIVE, type=CommandType.BOOLEAN, description="Must be used with domainId parameter. Defaults to false, but if true, lists all vms from the parent specified by the domain id till leaves.") private Boolean recursive; @Parameter(name=ApiConstants.GROUP_ID, type=CommandType.LONG, description="the group ID") diff --git a/server/src/com/cloud/acl/DomainChecker.java b/server/src/com/cloud/acl/DomainChecker.java index 720e44a226d..ee98e80b3ce 100755 --- a/server/src/com/cloud/acl/DomainChecker.java +++ b/server/src/com/cloud/acl/DomainChecker.java @@ -53,7 +53,11 @@ public class DomainChecker extends AdapterBase implements SecurityChecker { throw new PermissionDeniedException(account + " is disabled."); } - if (!_domainDao.isChildDomain(account.getDomainId(), domain.getId())) { + if (account.getType() == Account.ACCOUNT_TYPE_NORMAL) { + if (account.getDomainId() != domain.getId()) { + throw new PermissionDeniedException(account + " does not have permission to operate within " + domain); + } + } else if (!_domainDao.isChildDomain(account.getDomainId(), domain.getId())) { throw new PermissionDeniedException(account + " does not have permission to operate within " + domain); } diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 26446a73360..571226d8040 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -299,7 +299,7 @@ public class ApiDBUtils { ///////////////////////////////////////////////////////////// public static Account findAccountById(Long accountId) { - return _accountDao.findById(accountId); + return _accountDao.findByIdIncludingRemoved(accountId); } public static Account findAccountByIdIncludingRemoved(Long accountId) { diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 7a0d931b18b..6507d3870b4 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -995,17 +995,10 @@ public class ApiResponseHelper implements ResponseGenerator { public UserVmResponse createUserVmResponse(UserVm userVm) { UserVmResponse userVmResponse = new UserVmResponse(); Account acct = ApiDBUtils.findAccountById(Long.valueOf(userVm.getAccountId())); - // FIXME - this check should be done in searchForUserVm method in - // ManagementServerImpl; - // otherwise the number of vms returned is not going to match pageSize - // request parameter - if ((acct != null) && (acct.getRemoved() == null)) { + if (acct != null) { userVmResponse.setAccountName(acct.getAccountName()); userVmResponse.setDomainId(acct.getDomainId()); userVmResponse.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName()); - } else { - return null; // the account has been deleted, skip this VM in the - // response } userVmResponse.setId(userVm.getId()); diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 2198d4dad09..266c29cda2f 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -2621,58 +2621,57 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager @Override public List searchForUserVMs(ListVMsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException { - Account account = UserContext.current().getCaller(); + Account caller = UserContext.current().getCaller(); Long domainId = cmd.getDomainId(); String accountName = cmd.getAccountName(); - Long accountId = null; Boolean isRecursive = cmd.isRecursive(); String hypervisor = cmd.getHypervisor(); - List domainsToSearchForVms = new ArrayList(); - boolean isAdmin = false; + Long accountId = null; String path = null; - if ((account == null) || isAdmin(account.getType())) { - isAdmin = true; - if (domainId != null) { - if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), domainId)) { - throw new PermissionDeniedException("Invalid domain id (" + domainId + ") given, unable to list virtual machines."); - } - - if (accountName != null) { - account = _accountDao.findActiveAccount(accountName, domainId); - if (account == null) { - throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId); - } - accountId = account.getId(); - } - } - if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) { - DomainVO domain = _domainDao.findById(account.getDomainId()); - if (domain != null) { - path = domain.getPath(); - } - } - } else { - accountId = account.getId(); - } - - if(isRecursive == null) { - isRecursive = false; - } - if(isRecursive && domainId != null) { - DomainVO parentDomain = _domainDao.findById(domainId); - if(parentDomain.getName().equals("ROOT")) { - domainsToSearchForVms.addAll(_domainDao.listAll()); - return recursivelySearchForVms(cmd, path, isAdmin, domainsToSearchForVms, accountId); - }else { - domainsToSearchForVms.add(parentDomain); - domainsToSearchForVms.addAll(_domainDao.findAllChildren(parentDomain.getPath(), parentDomain.getId())); - return recursivelySearchForVms(cmd, path, isAdmin, domainsToSearchForVms, accountId); - } - } else if(isRecursive && domainId == null){ + if (isRecursive != null && isRecursive && domainId == null){ throw new InvalidParameterValueException("Please enter a parent domain id for listing vms recursively"); } - + + if (domainId != null) { + //Verify if user is authorized to see instances belonging to the domain + DomainVO domain = _domainDao.findById(domainId); + if (domain == null) { + throw new InvalidParameterValueException("Domain id=" + domainId + " doesn't exist"); + } + _accountMgr.checkAccess(caller, domain); + } + + boolean isAdmin = false; + + if (_accountMgr.isAdmin(caller.getType())) { + isAdmin = true; + if (accountName != null && domainId != null) { + caller = _accountDao.findActiveAccount(accountName, domainId); + if (caller == null) { + throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId); + } + accountId = caller.getId(); + } + + if (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) { + if (isRecursive == null) { + DomainVO domain = _domainDao.findById(caller.getDomainId()); + path = domain.getPath(); + } + } + } else { + accountId = caller.getId(); + } + + if (isRecursive != null && isRecursive && isAdmin) { + if (isRecursive) { + DomainVO domain = _domainDao.findById(domainId); + path = domain.getPath(); + domainId = null; + } + } + Criteria c = new Criteria("id", Boolean.TRUE, cmd.getStartIndex(), cmd.getPageSizeVal()); c.addCriteria(Criteria.KEYWORD, cmd.getKeyword()); c.addCriteria(Criteria.ID, cmd.getId()); @@ -2683,19 +2682,22 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager c.addCriteria(Criteria.FOR_VIRTUAL_NETWORK, cmd.getForVirtualNetwork()); c.addCriteria(Criteria.NETWORKID, cmd.getNetworkId()); + if (domainId != null) { + c.addCriteria(Criteria.DOMAINID, domainId); + } + if (path != null) { c.addCriteria(Criteria.PATH, path); } if (HypervisorType.getType(hypervisor) != HypervisorType.None){ c.addCriteria(Criteria.HYPERVISOR, hypervisor); - }else if (hypervisor != null){ + } else if (hypervisor != null){ throw new InvalidParameterValueException("Invalid HypervisorType " + hypervisor); } // ignore these search requests if it's not an admin - if (isAdmin == true) { - c.addCriteria(Criteria.DOMAINID, domainId); + if (isAdmin) { c.addCriteria(Criteria.PODID, cmd.getPodId()); c.addCriteria(Criteria.HOSTID, cmd.getHostId()); c.addCriteria(Criteria.STORAGE_ID, cmd.getStorageId()); @@ -2709,60 +2711,14 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager return searchForUserVMs(c); } - private List recursivelySearchForVms(ListVMsCmd cmd, String path, boolean isAdmin, List domainToSearchWithin, Long accountId) { - - List result = new ArrayList(); - String hypervisor = cmd.getHypervisor(); - for(DomainVO domain : domainToSearchWithin) { - - Criteria c = new Criteria("id", Boolean.TRUE, cmd.getStartIndex(), cmd.getPageSizeVal()); - c.addCriteria(Criteria.KEYWORD, cmd.getKeyword()); - c.addCriteria(Criteria.ID, cmd.getId()); - c.addCriteria(Criteria.NAME, cmd.getInstanceName()); - c.addCriteria(Criteria.STATE, cmd.getState()); - c.addCriteria(Criteria.DATACENTERID, cmd.getZoneId()); - c.addCriteria(Criteria.GROUPID, cmd.getGroupId()); - c.addCriteria(Criteria.FOR_VIRTUAL_NETWORK, cmd.getForVirtualNetwork()); - c.addCriteria(Criteria.NETWORKID, cmd.getNetworkId()); - - if (path != null) { - c.addCriteria(Criteria.PATH, path); - } - - // ignore these search requests if it's not an admin - if (isAdmin == true) { - c.addCriteria(Criteria.DOMAINID, domain.getId()); - c.addCriteria(Criteria.PODID, cmd.getPodId()); - c.addCriteria(Criteria.HOSTID, cmd.getHostId()); - } - - if (HypervisorType.getType(hypervisor) != HypervisorType.None){ - c.addCriteria(Criteria.HYPERVISOR, hypervisor); - }else if (hypervisor != null){ - throw new InvalidParameterValueException("Invalid HypervisorType " + hypervisor); - } - - if (accountId != null) { - c.addCriteria(Criteria.ACCOUNTID, new Object[] {accountId}); - } - c.addCriteria(Criteria.ISADMIN, isAdmin); - - result.addAll(searchForUserVMs(c)); - } - return result; - } @Override public List searchForUserVMs(Criteria c) { Filter searchFilter = new Filter(UserVmVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit()); SearchBuilder sb = _vmDao.createSearchBuilder(); - - // some criteria matter for generating the join condition Object[] accountIds = (Object[]) c.getCriteria(Criteria.ACCOUNTID); Object domainId = c.getCriteria(Criteria.DOMAINID); - - // get the rest of the criteria Object id = c.getCriteria(Criteria.ID); Object name = c.getCriteria(Criteria.NAME); Object state = c.getCriteria(Criteria.STATE); @@ -2793,21 +2749,14 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ); sb.and("hostIdEQ", sb.entity().getHostId(), SearchCriteria.Op.EQ); sb.and("hostIdIN", sb.entity().getHostId(), SearchCriteria.Op.IN); + sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ); - if (domainId != null || path != null) { - // if accountId isn't specified, we can do a domain match for the admin case + if (path != null) { SearchBuilder domainSearch = _domainDao.createSearchBuilder(); - domainSearch.and("id", domainSearch.entity().getId(), SearchCriteria.Op.EQ); domainSearch.and("path", domainSearch.entity().getPath(), SearchCriteria.Op.LIKE); sb.join("domainSearch", domainSearch, sb.entity().getDomainId(), domainSearch.entity().getId(), JoinBuilder.JoinType.INNER); } - if (storageId != null) { - SearchBuilder volumeSearch = _volsDao.createSearchBuilder(); - volumeSearch.and("poolId", volumeSearch.entity().getPoolId(), SearchCriteria.Op.EQ); - sb.join("volumeSearch", volumeSearch, sb.entity().getId(), volumeSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER); - } - if (groupId != null && (Long)groupId == -1) { SearchBuilder vmSearch = _groupVMMapDao.createSearchBuilder(); vmSearch.and("instanceId", vmSearch.entity().getInstanceId(), SearchCriteria.Op.EQ); @@ -2829,13 +2778,14 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager sb.join("nicSearch", nicSearch, sb.entity().getId(), nicSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER); } - SearchBuilder accountRemoved = _accountDao.createSearchBuilder(); - accountRemoved.and("accountremoved", accountRemoved.entity().getRemoved(), SearchCriteria.Op.NULL); - sb.join("accountRemoved", accountRemoved, sb.entity().getAccountId(), accountRemoved.entity().getId(), JoinBuilder.JoinType.INNER); + if (storageId != null) { + SearchBuilder volumeSearch = _volsDao.createSearchBuilder(); + volumeSearch.and("poolId", volumeSearch.entity().getPoolId(), SearchCriteria.Op.EQ); + sb.join("volumeSearch", volumeSearch, sb.entity().getId(), volumeSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER); + } // populate the search criteria with the values passed in - SearchCriteria sc = sb.create(); - + SearchCriteria sc = sb.create(); if (groupId != null && (Long)groupId == -1){ sc.setJoinParameters("vmSearch", "instanceId", (Object)null); } else if (groupId != null ) { @@ -2855,6 +2805,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (id != null) { sc.setParameters("id", id); } + if (accountIds != null) { if (accountIds.length == 1) { if (accountIds[0] != null) { @@ -2863,18 +2814,16 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } else { sc.setParameters("accountIdIN", accountIds); } - } else if (domainId != null) { - sc.setJoinParameters("domainSearch", "id", domainId); + } + + if (domainId != null) { + sc.setParameters("domainId", domainId); } if (path != null) { sc.setJoinParameters("domainSearch", "path", path + "%"); } - if (storageId != null) { - sc.setJoinParameters("volumeSearch", "poolId", storageId); - } - if (networkId != null) { sc.setJoinParameters("nicSearch", "networkId", networkId); } @@ -2882,6 +2831,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (name != null) { sc.setParameters("name", "%" + name + "%"); } + if (state != null) { if (notState != null && (Boolean) notState == true) { sc.setParameters("stateNEQ", state); @@ -2893,6 +2843,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (hypervisor != null){ sc.setParameters("hypervisorType", hypervisor); } + + //Don't show Destroyed and Expunging vms to the end user if ((isAdmin != null) && ((Boolean) isAdmin != true)) { sc.setParameters("stateNIN", "Destroyed", "Expunging"); } @@ -2900,7 +2852,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (zone != null) { sc.setParameters("dataCenterId", zone); - if(state == null) { + if (state == null) { sc.setParameters("stateNEQ", "Destroyed"); } } @@ -2929,6 +2881,10 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } } } + + if (storageId != null) { + sc.setJoinParameters("volumeSearch", "poolId", storageId); + } return _vmDao.search(sc, searchFilter); } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 1b727bb089b..73869d5fba1 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -967,7 +967,8 @@ CREATE TABLE `cloud`.`domain` ( `removed` datetime COMMENT 'date removed', `state` char(32) NOT NULL default 'Active' COMMENT 'state of the domain', PRIMARY KEY (`id`), - UNIQUE (parent, name, removed) + UNIQUE (parent, name, removed), + INDEX `i_domain__path`(`path`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `cloud`.`account` ( diff --git a/setup/db/schema-222to224.sql b/setup/db/schema-222to224.sql index 56be9cd85e1..c5dc4c636b8 100644 --- a/setup/db/schema-222to224.sql +++ b/setup/db/schema-222to224.sql @@ -57,4 +57,7 @@ ALTER TABLE `cloud`.`cluster` ADD INDEX `i_cluster__allocation_state`(`allocatio ALTER TABLE `cloud`.`host_pod_ref` ADD COLUMN `allocation_state` varchar(32) NOT NULL DEFAULT 'Enabled'; ALTER TABLE `cloud`.`host_pod_ref` ADD INDEX `i_host_pod_ref__allocation_state`(`allocation_state`); ALTER TABLE `cloud`.`host` ADD COLUMN `allocation_state` varchar(32) NOT NULL DEFAULT 'Enabled'; -ALTER TABLE `cloud`.`host` ADD INDEX `i_host__allocation_state`(`allocation_state`); \ No newline at end of file +ALTER TABLE `cloud`.`host` ADD INDEX `i_host__allocation_state`(`allocation_state`); + +ALTER TABLE `cloud`.`domain` ADD INDEX `i_domain__path`(`path`); + From f04f2ab10c4d2d2b50d3e4490b5be07ea33f6da8 Mon Sep 17 00:00:00 2001 From: alena Date: Tue, 29 Mar 2011 18:33:26 -0700 Subject: [PATCH 09/72] bug 9192: More improvements to listVm performance - cache dataCenter/serviceOffering/Network/Template/Iso information on Api level status 9192: resolved fixed --- api/src/com/cloud/api/ResponseGenerator.java | 2 +- .../com/cloud/api/commands/AttachIsoCmd.java | 2 +- .../com/cloud/api/commands/DeployVMCmd.java | 3 +- .../com/cloud/api/commands/DestroyVMCmd.java | 2 +- .../com/cloud/api/commands/DetachIsoCmd.java | 4 +- .../ListLoadBalancerRuleInstancesCmd.java | 6 +- .../com/cloud/api/commands/ListVMsCmd.java | 10 +- .../com/cloud/api/commands/MigrateVMCmd.java | 3 +- .../com/cloud/api/commands/RebootVMCmd.java | 2 +- .../com/cloud/api/commands/RecoverVMCmd.java | 2 +- .../api/commands/ResetVMPasswordCmd.java | 2 +- .../com/cloud/api/commands/StartVMCmd.java | 2 +- api/src/com/cloud/api/commands/StopVMCmd.java | 2 +- .../com/cloud/api/commands/UpdateVMCmd.java | 2 +- .../com/cloud/api/commands/UpgradeVMCmd.java | 2 +- .../src/com/cloud/api/ApiResponseHelper.java | 330 ++++++++++-------- 16 files changed, 199 insertions(+), 177 deletions(-) diff --git a/api/src/com/cloud/api/ResponseGenerator.java b/api/src/com/cloud/api/ResponseGenerator.java index 02d4dee5b81..67f617c2ea0 100644 --- a/api/src/com/cloud/api/ResponseGenerator.java +++ b/api/src/com/cloud/api/ResponseGenerator.java @@ -116,7 +116,7 @@ public interface ResponseGenerator { SnapshotPolicyResponse createSnapshotPolicyResponse(SnapshotPolicy policy); - UserVmResponse createUserVmResponse(UserVm userVm); + List createUserVmResponse(String objectName, UserVm... userVms); SystemVmResponse createSystemVmResponse(VirtualMachine systemVM); diff --git a/api/src/com/cloud/api/commands/AttachIsoCmd.java b/api/src/com/cloud/api/commands/AttachIsoCmd.java index d74d1c098f1..6e0d74a58da 100755 --- a/api/src/com/cloud/api/commands/AttachIsoCmd.java +++ b/api/src/com/cloud/api/commands/AttachIsoCmd.java @@ -95,7 +95,7 @@ public class AttachIsoCmd extends BaseAsyncCmd { if (result) { UserVm userVm = _responseGenerator.findUserVmById(virtualMachineId); if (userVm != null) { - UserVmResponse response = _responseGenerator.createUserVmResponse(userVm); + UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", userVm).get(0); response.setResponseName(DeployVMCmd.getResultObjectName()); this.setResponseObject(response); } else { diff --git a/api/src/com/cloud/api/commands/DeployVMCmd.java b/api/src/com/cloud/api/commands/DeployVMCmd.java index 402e306b805..b22e5ed922d 100644 --- a/api/src/com/cloud/api/commands/DeployVMCmd.java +++ b/api/src/com/cloud/api/commands/DeployVMCmd.java @@ -28,7 +28,6 @@ import com.cloud.api.BaseCmd; import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; -import com.cloud.api.BaseCmd.CommandType; import com.cloud.api.response.UserVmResponse; import com.cloud.async.AsyncJob; import com.cloud.dc.DataCenter; @@ -252,7 +251,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd { } if (result != null) { - UserVmResponse response = _responseGenerator.createUserVmResponse(result); + UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { diff --git a/api/src/com/cloud/api/commands/DestroyVMCmd.java b/api/src/com/cloud/api/commands/DestroyVMCmd.java index 3a44ed19857..864ae0b0353 100644 --- a/api/src/com/cloud/api/commands/DestroyVMCmd.java +++ b/api/src/com/cloud/api/commands/DestroyVMCmd.java @@ -104,7 +104,7 @@ public class DestroyVMCmd extends BaseAsyncCmd { } if (result != null) { - UserVmResponse response = _responseGenerator.createUserVmResponse(result); + UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0); response.setResponseName("virtualmachine"); this.setResponseObject(response); } else { diff --git a/api/src/com/cloud/api/commands/DetachIsoCmd.java b/api/src/com/cloud/api/commands/DetachIsoCmd.java index 2adc6b0be21..7f69f6c1841 100755 --- a/api/src/com/cloud/api/commands/DetachIsoCmd.java +++ b/api/src/com/cloud/api/commands/DetachIsoCmd.java @@ -84,8 +84,8 @@ public class DetachIsoCmd extends BaseAsyncCmd { public void execute(){ boolean result = _templateService.detachIso(this); if (result) { - UserVm userVm = _entityMgr.findById(UserVm.class, virtualMachineId); - UserVmResponse response = _responseGenerator.createUserVmResponse(userVm); + UserVm userVm = _entityMgr.findById(UserVm.class, virtualMachineId); + UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", userVm).get(0); response.setResponseName(DeployVMCmd.getResultObjectName()); this.setResponseObject(response); } else { diff --git a/api/src/com/cloud/api/commands/ListLoadBalancerRuleInstancesCmd.java b/api/src/com/cloud/api/commands/ListLoadBalancerRuleInstancesCmd.java index 958b8fb380d..718cd5b306b 100644 --- a/api/src/com/cloud/api/commands/ListLoadBalancerRuleInstancesCmd.java +++ b/api/src/com/cloud/api/commands/ListLoadBalancerRuleInstancesCmd.java @@ -73,11 +73,7 @@ public class ListLoadBalancerRuleInstancesCmd extends BaseListCmd { ListResponse response = new ListResponse(); List vmResponses = new ArrayList(); if (result != null) { - for (UserVm instance : result) { - UserVmResponse userVmResponse = _responseGenerator.createUserVmResponse(instance); - userVmResponse.setObjectName("loadbalancerruleinstance"); - vmResponses.add(userVmResponse); - } + vmResponses = _responseGenerator.createUserVmResponse("loadbalancerruleinstance", result.toArray(new UserVm[result.size()])); } response.setResponses(vmResponses); response.setResponseName(getCommandName()); diff --git a/api/src/com/cloud/api/commands/ListVMsCmd.java b/api/src/com/cloud/api/commands/ListVMsCmd.java index ca96b338ae0..41788af902d 100755 --- a/api/src/com/cloud/api/commands/ListVMsCmd.java +++ b/api/src/com/cloud/api/commands/ListVMsCmd.java @@ -17,7 +17,6 @@ */ package com.cloud.api.commands; -import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; @@ -163,14 +162,7 @@ public class ListVMsCmd extends BaseListCmd { public void execute(){ List result = _userVmService.searchForUserVMs(this); ListResponse response = new ListResponse(); - List vmResponses = new ArrayList(); - for (UserVm userVm : result) { - UserVmResponse userVmResponse = _responseGenerator.createUserVmResponse(userVm); - if (userVmResponse != null) { - userVmResponse.setObjectName("virtualmachine"); - vmResponses.add(userVmResponse); - } - } + List vmResponses = _responseGenerator.createUserVmResponse("virtualmachine", result.toArray(new UserVm[result.size()])); response.setResponses(vmResponses); response.setResponseName(getCommandName()); this.setResponseObject(response); diff --git a/api/src/com/cloud/api/commands/MigrateVMCmd.java b/api/src/com/cloud/api/commands/MigrateVMCmd.java index 398077a10f5..7f8ce362532 100644 --- a/api/src/com/cloud/api/commands/MigrateVMCmd.java +++ b/api/src/com/cloud/api/commands/MigrateVMCmd.java @@ -107,9 +107,8 @@ public class MigrateVMCmd extends BaseAsyncCmd { } try{ UserVm migratedVm = _userVmService.migrateVirtualMachine(userVm, destinationHost); - if (migratedVm != null) { - UserVmResponse response = _responseGenerator.createUserVmResponse(migratedVm); + UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", migratedVm).get(0); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { diff --git a/api/src/com/cloud/api/commands/RebootVMCmd.java b/api/src/com/cloud/api/commands/RebootVMCmd.java index dc1669fd80d..755c840f154 100644 --- a/api/src/com/cloud/api/commands/RebootVMCmd.java +++ b/api/src/com/cloud/api/commands/RebootVMCmd.java @@ -103,7 +103,7 @@ public class RebootVMCmd extends BaseAsyncCmd { } if (result !=null){ - UserVmResponse response = _responseGenerator.createUserVmResponse(result); + UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { diff --git a/api/src/com/cloud/api/commands/RecoverVMCmd.java b/api/src/com/cloud/api/commands/RecoverVMCmd.java index 193f7e6a0f6..4b895721192 100644 --- a/api/src/com/cloud/api/commands/RecoverVMCmd.java +++ b/api/src/com/cloud/api/commands/RecoverVMCmd.java @@ -74,7 +74,7 @@ public class RecoverVMCmd extends BaseCmd { public void execute() throws ResourceAllocationException{ UserVm result = _userVmService.recoverVirtualMachine(this); if (result != null){ - UserVmResponse recoverVmResponse = _responseGenerator.createUserVmResponse(result); + UserVmResponse recoverVmResponse = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0); recoverVmResponse.setResponseName(getCommandName()); this.setResponseObject(recoverVmResponse); } else { diff --git a/api/src/com/cloud/api/commands/ResetVMPasswordCmd.java b/api/src/com/cloud/api/commands/ResetVMPasswordCmd.java index 2080392817e..049b6900714 100644 --- a/api/src/com/cloud/api/commands/ResetVMPasswordCmd.java +++ b/api/src/com/cloud/api/commands/ResetVMPasswordCmd.java @@ -112,7 +112,7 @@ public class ResetVMPasswordCmd extends BaseAsyncCmd { UserContext.current().setEventDetails("Vm Id: "+getId()); UserVm result = _userVmService.resetVMPassword(this, password); if (result != null){ - UserVmResponse response = _responseGenerator.createUserVmResponse(result); + UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { diff --git a/api/src/com/cloud/api/commands/StartVMCmd.java b/api/src/com/cloud/api/commands/StartVMCmd.java index 389de61828f..a4ba5c1f331 100644 --- a/api/src/com/cloud/api/commands/StartVMCmd.java +++ b/api/src/com/cloud/api/commands/StartVMCmd.java @@ -113,7 +113,7 @@ public class StartVMCmd extends BaseAsyncCmd { } if (result != null){ - UserVmResponse response = _responseGenerator.createUserVmResponse(result); + UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { diff --git a/api/src/com/cloud/api/commands/StopVMCmd.java b/api/src/com/cloud/api/commands/StopVMCmd.java index bdef118bd8c..8230ec44414 100644 --- a/api/src/com/cloud/api/commands/StopVMCmd.java +++ b/api/src/com/cloud/api/commands/StopVMCmd.java @@ -117,7 +117,7 @@ public class StopVMCmd extends BaseAsyncCmd { } if (result != null) { - UserVmResponse response = _responseGenerator.createUserVmResponse(result); + UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { diff --git a/api/src/com/cloud/api/commands/UpdateVMCmd.java b/api/src/com/cloud/api/commands/UpdateVMCmd.java index 103871f8da7..f380abc23f8 100644 --- a/api/src/com/cloud/api/commands/UpdateVMCmd.java +++ b/api/src/com/cloud/api/commands/UpdateVMCmd.java @@ -105,7 +105,7 @@ public class UpdateVMCmd extends BaseCmd{ UserContext.current().setEventDetails("Vm Id: "+getId()); UserVm result = _userVmService.updateVirtualMachine(this); if (result != null){ - UserVmResponse response = _responseGenerator.createUserVmResponse(result); + UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { diff --git a/api/src/com/cloud/api/commands/UpgradeVMCmd.java b/api/src/com/cloud/api/commands/UpgradeVMCmd.java index 1073ffdaa06..033e33d8fcb 100644 --- a/api/src/com/cloud/api/commands/UpgradeVMCmd.java +++ b/api/src/com/cloud/api/commands/UpgradeVMCmd.java @@ -86,7 +86,7 @@ public class UpgradeVMCmd extends BaseCmd { UserContext.current().setEventDetails("Vm Id: "+getId()); UserVm result = _userVmService.upgradeVirtualMachine(this); if (result != null){ - UserVmResponse response = _responseGenerator.createUserVmResponse(result); + UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 6507d3870b4..3728048cc4d 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -992,157 +992,193 @@ public class ApiResponseHelper implements ResponseGenerator { } @Override - public UserVmResponse createUserVmResponse(UserVm userVm) { - UserVmResponse userVmResponse = new UserVmResponse(); - Account acct = ApiDBUtils.findAccountById(Long.valueOf(userVm.getAccountId())); - if (acct != null) { - userVmResponse.setAccountName(acct.getAccountName()); - userVmResponse.setDomainId(acct.getDomainId()); - userVmResponse.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName()); - } - - userVmResponse.setId(userVm.getId()); - userVmResponse.setName(userVm.getName()); - userVmResponse.setCreated(userVm.getCreated()); - - if (userVm.getState() != null) { - userVmResponse.setState(userVm.getState().toString()); - } - - userVmResponse.setHaEnable(userVm.isHaEnabled()); - - if (userVm.getDisplayName() != null) { - userVmResponse.setDisplayName(userVm.getDisplayName()); - } else { - userVmResponse.setDisplayName(userVm.getName()); - } - - InstanceGroupVO group = ApiDBUtils.findInstanceGroupForVM(userVm.getId()); - if (group != null) { - userVmResponse.setGroup(group.getName()); - userVmResponse.setGroupId(group.getId()); - } - - // Data Center Info - userVmResponse.setZoneId(userVm.getDataCenterId()); - userVmResponse.setZoneName(ApiDBUtils.findZoneById(userVm.getDataCenterId()).getName()); - - Account account = UserContext.current().getCaller(); - // if user is an admin, display host id - if (((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) && (userVm.getHostId() != null)) { - userVmResponse.setHostId(userVm.getHostId()); - userVmResponse.setHostName(ApiDBUtils.findHostById(userVm.getHostId()).getName()); - } - - if(userVm.getHypervisorType() != null){ - userVmResponse.setHypervisor(userVm.getHypervisorType().toString()); - } - // Template Info - VMTemplateVO template = ApiDBUtils.findTemplateById(userVm.getTemplateId()); - if (template != null) { - userVmResponse.setTemplateId(userVm.getTemplateId()); - userVmResponse.setTemplateName(template.getName()); - userVmResponse.setTemplateDisplayText(template.getDisplayText()); - userVmResponse.setPasswordEnabled(template.getEnablePassword()); - } else { - userVmResponse.setTemplateId(-1L); - userVmResponse.setTemplateName("ISO Boot"); - userVmResponse.setTemplateDisplayText("ISO Boot"); - userVmResponse.setPasswordEnabled(false); - } - - if (userVm.getPassword() != null) { - userVmResponse.setPassword(userVm.getPassword()); - } - - // ISO Info - if (userVm.getIsoId() != null) { - VMTemplateVO iso = ApiDBUtils.findTemplateById(userVm.getIsoId()); - if (iso != null) { - userVmResponse.setIsoId(userVm.getIsoId()); - userVmResponse.setIsoName(iso.getName()); - } - } - - // Service Offering Info - ServiceOffering offering = ApiDBUtils.findServiceOfferingById(userVm.getServiceOfferingId()); - userVmResponse.setServiceOfferingId(userVm.getServiceOfferingId()); - userVmResponse.setServiceOfferingName(offering.getName()); - userVmResponse.setCpuNumber(offering.getCpu()); - userVmResponse.setCpuSpeed(offering.getSpeed()); - userVmResponse.setMemory(offering.getRamSize()); - - VolumeVO rootVolume = ApiDBUtils.findRootVolume(userVm.getId()); - if (rootVolume != null) { - userVmResponse.setRootDeviceId(rootVolume.getDeviceId()); - String rootDeviceType = "Not created"; - if (rootVolume.getPoolId() != null) { - StoragePoolVO storagePool = ApiDBUtils.findStoragePoolById(rootVolume.getPoolId()); - rootDeviceType = storagePool.getPoolType().toString(); - } - userVmResponse.setRootDeviceType(rootDeviceType); - } - - // stats calculation - DecimalFormat decimalFormat = new DecimalFormat("#.##"); - String cpuUsed = null; - VmStats vmStats = ApiDBUtils.getVmStatistics(userVm.getId()); - if (vmStats != null) { - float cpuUtil = (float) vmStats.getCPUUtilization(); - cpuUsed = decimalFormat.format(cpuUtil) + "%"; - userVmResponse.setCpuUsed(cpuUsed); - - Double networkKbRead = Double.valueOf(vmStats.getNetworkReadKBs()); - userVmResponse.setNetworkKbsRead(networkKbRead.longValue()); - - Double networkKbWrite = Double.valueOf(vmStats.getNetworkWriteKBs()); - userVmResponse.setNetworkKbsWrite(networkKbWrite.longValue()); - } - - userVmResponse.setGuestOsId(userVm.getGuestOSId()); - // security groups - List securityGroups = ApiDBUtils.getSecurityGroupsForVm(userVm.getId()); - List securityGroupResponse = new ArrayList(); - for(SecurityGroupVO grp : securityGroups) { - SecurityGroupResponse resp = new SecurityGroupResponse(); - resp.setId(grp.getId()); - resp.setName(grp.getName()); - resp.setDescription(grp.getDescription()); - resp.setObjectName("securitygroup"); - securityGroupResponse.add(resp); - } + public List createUserVmResponse(String objectName, UserVm...userVms) { + Account caller = UserContext.current().getCaller(); + Map dataCenters = new HashMap(); + Map hosts = new HashMap(); + Map templates = new HashMap(); + Map serviceOfferings = new HashMap(); + Map networks = new HashMap(); - userVmResponse.setSecurityGroupList(securityGroupResponse); - - List nicProfiles = ApiDBUtils.getNics(userVm); - List nicResponses = new ArrayList(); - for (NicProfile singleNicProfile : nicProfiles) { - NicResponse nicResponse = new NicResponse(); - nicResponse.setId(singleNicProfile.getId()); - nicResponse.setIpaddress(singleNicProfile.getIp4Address()); - nicResponse.setGateway(singleNicProfile.getGateway()); - nicResponse.setNetmask(singleNicProfile.getNetmask()); - nicResponse.setNetworkid(singleNicProfile.getNetworkId()); - if (acct.getType() == Account.ACCOUNT_TYPE_ADMIN) { - if (singleNicProfile.getBroadCastUri() != null) { - nicResponse.setBroadcastUri(singleNicProfile.getBroadCastUri().toString()); - } - if (singleNicProfile.getIsolationUri() != null) { - nicResponse.setIsolationUri(singleNicProfile.getIsolationUri().toString()); - } + List vmResponses = new ArrayList(); + + for (UserVm userVm : userVms) { + UserVmResponse userVmResponse = new UserVmResponse(); + Account acct = ApiDBUtils.findAccountById(Long.valueOf(userVm.getAccountId())); + if (acct != null) { + userVmResponse.setAccountName(acct.getAccountName()); + userVmResponse.setDomainId(acct.getDomainId()); + userVmResponse.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName()); + } + + userVmResponse.setId(userVm.getId()); + userVmResponse.setName(userVm.getName()); + userVmResponse.setCreated(userVm.getCreated()); + + if (userVm.getState() != null) { + userVmResponse.setState(userVm.getState().toString()); + } + + userVmResponse.setHaEnable(userVm.isHaEnabled()); + + if (userVm.getDisplayName() != null) { + userVmResponse.setDisplayName(userVm.getDisplayName()); + } else { + userVmResponse.setDisplayName(userVm.getName()); + } + + InstanceGroupVO group = ApiDBUtils.findInstanceGroupForVM(userVm.getId()); + if (group != null) { + userVmResponse.setGroup(group.getName()); + userVmResponse.setGroupId(group.getId()); + } + + // Data Center Info + if (!dataCenters.containsKey(userVm.getDataCenterId())) { + dataCenters.put(userVm.getDataCenterId(), ApiDBUtils.findZoneById(userVm.getDataCenterId())); } - Network network = ApiDBUtils.findNetworkById(singleNicProfile.getNetworkId()); - nicResponse.setTrafficType(network.getTrafficType().toString()); - nicResponse.setType(network.getGuestType().toString()); - nicResponse.setIsDefault(singleNicProfile.isDefaultNic()); + userVmResponse.setZoneId(userVm.getDataCenterId()); + userVmResponse.setZoneName(dataCenters.get(userVm.getDataCenterId()).getName()); + - nicResponse.setObjectName("nic"); + // if user is an admin, display host id + if (((caller == null) || (caller.getType() == Account.ACCOUNT_TYPE_ADMIN)) && (userVm.getHostId() != null)) { + Long hostId = userVm.getHostId(); + if (!hosts.containsKey(hostId)) { + hosts.put(hostId, ApiDBUtils.findHostById(hostId)); + } + + userVmResponse.setHostId(hostId); + userVmResponse.setHostName(hosts.get(hostId).getName()); + } + + if(userVm.getHypervisorType() != null){ + userVmResponse.setHypervisor(userVm.getHypervisorType().toString()); + } - nicResponses.add(nicResponse); - } - userVmResponse.setNics(nicResponses); - userVmResponse.setObjectName("virtualmachine"); - return userVmResponse; + // Template Info + if (!templates.containsKey(userVm.getTemplateId())) { + templates.put(userVm.getTemplateId(),ApiDBUtils.findTemplateById(userVm.getTemplateId())); + } + + VMTemplateVO template = templates.get(userVm.getTemplateId()); + if (template != null) { + userVmResponse.setTemplateId(userVm.getTemplateId()); + userVmResponse.setTemplateName(template.getName()); + userVmResponse.setTemplateDisplayText(template.getDisplayText()); + userVmResponse.setPasswordEnabled(template.getEnablePassword()); + } else { + userVmResponse.setTemplateId(-1L); + userVmResponse.setTemplateName("ISO Boot"); + userVmResponse.setTemplateDisplayText("ISO Boot"); + userVmResponse.setPasswordEnabled(false); + } + + if (userVm.getPassword() != null) { + userVmResponse.setPassword(userVm.getPassword()); + } + + // ISO Info + Long isoId = userVm.getIsoId(); + if (isoId != null) { + if (!templates.containsKey(isoId)) { + templates.put(isoId,ApiDBUtils.findTemplateById(isoId)); + } + userVmResponse.setIsoId(isoId); + userVmResponse.setIsoName(templates.get(isoId).getName()); + } + + // Service Offering Info + Long soId = userVm.getServiceOfferingId(); + if (!serviceOfferings.containsKey(soId)) { + serviceOfferings.put(soId, ApiDBUtils.findServiceOfferingById(userVm.getServiceOfferingId())); + } + + ServiceOffering offering = serviceOfferings.get(soId); + userVmResponse.setServiceOfferingId(userVm.getServiceOfferingId()); + userVmResponse.setServiceOfferingName(offering.getName()); + userVmResponse.setCpuNumber(offering.getCpu()); + userVmResponse.setCpuSpeed(offering.getSpeed()); + userVmResponse.setMemory(offering.getRamSize()); + + VolumeVO rootVolume = ApiDBUtils.findRootVolume(userVm.getId()); + if (rootVolume != null) { + userVmResponse.setRootDeviceId(rootVolume.getDeviceId()); + String rootDeviceType = "Not created"; + if (rootVolume.getPoolId() != null) { + StoragePoolVO storagePool = ApiDBUtils.findStoragePoolById(rootVolume.getPoolId()); + rootDeviceType = storagePool.getPoolType().toString(); + } + userVmResponse.setRootDeviceType(rootDeviceType); + } + + // stats calculation + DecimalFormat decimalFormat = new DecimalFormat("#.##"); + String cpuUsed = null; + VmStats vmStats = ApiDBUtils.getVmStatistics(userVm.getId()); + if (vmStats != null) { + float cpuUtil = (float) vmStats.getCPUUtilization(); + cpuUsed = decimalFormat.format(cpuUtil) + "%"; + userVmResponse.setCpuUsed(cpuUsed); + + Double networkKbRead = Double.valueOf(vmStats.getNetworkReadKBs()); + userVmResponse.setNetworkKbsRead(networkKbRead.longValue()); + + Double networkKbWrite = Double.valueOf(vmStats.getNetworkWriteKBs()); + userVmResponse.setNetworkKbsWrite(networkKbWrite.longValue()); + } + + userVmResponse.setGuestOsId(userVm.getGuestOSId()); + // security groups + List securityGroups = ApiDBUtils.getSecurityGroupsForVm(userVm.getId()); + List securityGroupResponse = new ArrayList(); + for(SecurityGroupVO grp : securityGroups) { + SecurityGroupResponse resp = new SecurityGroupResponse(); + resp.setId(grp.getId()); + resp.setName(grp.getName()); + resp.setDescription(grp.getDescription()); + resp.setObjectName("securitygroup"); + securityGroupResponse.add(resp); + } + + userVmResponse.setSecurityGroupList(securityGroupResponse); + + List nicProfiles = ApiDBUtils.getNics(userVm); + List nicResponses = new ArrayList(); + for (NicProfile singleNicProfile : nicProfiles) { + NicResponse nicResponse = new NicResponse(); + nicResponse.setId(singleNicProfile.getId()); + nicResponse.setIpaddress(singleNicProfile.getIp4Address()); + nicResponse.setGateway(singleNicProfile.getGateway()); + nicResponse.setNetmask(singleNicProfile.getNetmask()); + nicResponse.setNetworkid(singleNicProfile.getNetworkId()); + if (acct.getType() == Account.ACCOUNT_TYPE_ADMIN) { + if (singleNicProfile.getBroadCastUri() != null) { + nicResponse.setBroadcastUri(singleNicProfile.getBroadCastUri().toString()); + } + if (singleNicProfile.getIsolationUri() != null) { + nicResponse.setIsolationUri(singleNicProfile.getIsolationUri().toString()); + } + } + + Long networkId = singleNicProfile.getNetworkId(); + if (!networks.containsKey(networkId)) { + networks.put(networkId, ApiDBUtils.findNetworkById(networkId)); + } + + Network network = networks.get(networkId); + nicResponse.setTrafficType(network.getTrafficType().toString()); + nicResponse.setType(network.getGuestType().toString()); + nicResponse.setIsDefault(singleNicProfile.isDefaultNic()); + nicResponse.setObjectName("nic"); + nicResponses.add(nicResponse); + } + userVmResponse.setNics(nicResponses); + userVmResponse.setObjectName(objectName); + vmResponses.add(userVmResponse); + } + + return vmResponses; } @Override From aab78874c75ba5b805f8ba67b27eee18ed384938 Mon Sep 17 00:00:00 2001 From: alena Date: Tue, 29 Mar 2011 19:16:44 -0700 Subject: [PATCH 10/72] bug 9201: listNetworkOfferings - return -1 when network_rate is Unlimited; if value is NULL - return global configuration value status 9201: resolved fixed --- .../api/commands/ListNetworkOfferingsCmd.java | 1 - .../xen/resource/CitrixResourceBase.java | 2 +- server/src/com/cloud/api/ApiDBUtils.java | 3 - .../src/com/cloud/api/ApiResponseHelper.java | 2 +- .../ConfigurationManagerImpl.java | 10 +- ui/scripts/cloud.core.networkoffering.js | 244 +++++++++--------- 6 files changed, 131 insertions(+), 131 deletions(-) diff --git a/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java b/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java index 27750f09f09..078b1cd85e4 100644 --- a/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java +++ b/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java @@ -27,7 +27,6 @@ import com.cloud.api.ApiConstants; import com.cloud.api.BaseListCmd; import com.cloud.api.Implementation; import com.cloud.api.Parameter; -import com.cloud.api.BaseCmd.CommandType; import com.cloud.api.response.ListResponse; import com.cloud.api.response.NetworkOfferingResponse; import com.cloud.offering.NetworkOffering; diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 35dc9355061..245b75eb86c 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -641,7 +641,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe vifr.network = getNetwork(conn, nic); - if (nic.getNetworkRateMbps() != null) { + if (nic.getNetworkRateMbps() != null && nic.getNetworkRateMbps().intValue() != -1) { vifr.qosAlgorithmType = "ratelimit"; vifr.qosAlgorithmParams = new HashMap(); // convert mbs to kilobyte per second diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 571226d8040..ac6d848af66 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -30,7 +30,6 @@ import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.IPAddressVO; import com.cloud.network.LoadBalancerVO; -import com.cloud.network.Network; import com.cloud.network.Network.Capability; import com.cloud.network.Network.Service; import com.cloud.network.NetworkManager; @@ -57,7 +56,6 @@ import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.GuestOS; import com.cloud.storage.GuestOSCategoryVO; import com.cloud.storage.Snapshot; -import com.cloud.storage.SnapshotPolicyVO; import com.cloud.storage.SnapshotVO; import com.cloud.storage.StorageManager; import com.cloud.storage.StoragePoolVO; @@ -87,7 +85,6 @@ import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; import com.cloud.user.dao.UserStatisticsDao; import com.cloud.uservm.UserVm; -import com.cloud.utils.DateUtil; import com.cloud.utils.component.ComponentLocator; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.InstanceGroupVO; diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 3728048cc4d..2f6004b02b2 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -2280,7 +2280,7 @@ public class ApiResponseHelper implements ResponseGenerator { response.setIsDefault(offering.isDefault()); response.setSpecifyVlan(offering.getSpecifyVlan()); response.setAvailability(offering.getAvailability().toString()); - response.setNetworkRate(offering.getRateMbps()); + response.setNetworkRate(ApiDBUtils.getNetworkRate(offering.getId())); if (offering.getGuestType() != null) { response.setGuestIpType(offering.getGuestType().toString()); diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 06ed8ab946f..8ded152d2a0 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -2780,20 +2780,24 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura @Override public Integer getNetworkRate(long networkOfferingId) { + + //validate network offering information NetworkOffering no = getNetworkOffering(networkOfferingId); - Integer networkRate = null; if (no == null) { throw new InvalidParameterValueException("Unable to find network offering by id=" + networkOfferingId); } + + Integer networkRate; if (no.getRateMbps() != null) { networkRate = no.getRateMbps(); } else { networkRate = Integer.parseInt(_configDao.getValue(Config.NetworkThrottlingRate.key())); } + //networkRate is unsigned int in netowrkOfferings table, and can't be set to -1 + //so 0 means unlimited; we convert it to -1, so we are consistent with all our other resources where -1 means unlimited if (networkRate == 0) { - //0 means no network limits should be applied - return null; + networkRate = -1; } return networkRate; diff --git a/ui/scripts/cloud.core.networkoffering.js b/ui/scripts/cloud.core.networkoffering.js index 1b1443d874c..88bdff64b3e 100644 --- a/ui/scripts/cloud.core.networkoffering.js +++ b/ui/scripts/cloud.core.networkoffering.js @@ -17,33 +17,33 @@ */ function networkOfferingGetSearchParams() { - var moreCriteria = []; - - var searchInput = $("#basic_search").find("#search_input").val(); - if (searchInput != null && searchInput.length > 0) { - moreCriteria.push("&keyword="+todb(searchInput)); - } - - var $advancedSearchPopup = getAdvancedSearchPopupInSearchContainer(); - if ($advancedSearchPopup.length > 0 && $advancedSearchPopup.css("display") != "none" ) { - var availability = $advancedSearchPopup.find("#adv_search_availability").val(); - if (availability!=null && availability.length > 0) - moreCriteria.push("&availability="+todb(availability)); - - var traffictype = $advancedSearchPopup.find("#adv_search_traffictype").val(); - if (traffictype!=null && traffictype.length > 0) - moreCriteria.push("&traffictype="+todb(traffictype)); - - } - + var moreCriteria = []; + + var searchInput = $("#basic_search").find("#search_input").val(); + if (searchInput != null && searchInput.length > 0) { + moreCriteria.push("&keyword="+todb(searchInput)); + } + + var $advancedSearchPopup = getAdvancedSearchPopupInSearchContainer(); + if ($advancedSearchPopup.length > 0 && $advancedSearchPopup.css("display") != "none" ) { + var availability = $advancedSearchPopup.find("#adv_search_availability").val(); + if (availability!=null && availability.length > 0) + moreCriteria.push("&availability="+todb(availability)); + + var traffictype = $advancedSearchPopup.find("#adv_search_traffictype").val(); + if (traffictype!=null && traffictype.length > 0) + moreCriteria.push("&traffictype="+todb(traffictype)); + + } + return moreCriteria.join(""); } -function afterLoadNetworkOfferingJSP() { +function afterLoadNetworkOfferingJSP() { $readonlyFields = $("#tab_content_details").find("#name, #displaytext, #availability"); - $editFields = $("#tab_content_details").find("#name_edit, #displaytext_edit, #availability_edit"); -} - + $editFields = $("#tab_content_details").find("#name_edit, #displaytext_edit, #availability_edit"); +} + function doEditNetworkOffering($actionLink, $detailsTab, $midmenuItem1) { $readonlyFields.hide(); $editFields.show(); @@ -57,8 +57,8 @@ function doEditNetworkOffering($actionLink, $detailsTab, $midmenuItem1) { doEditNetworkOffering2($actionLink, $detailsTab, $midmenuItem1, $readonlyFields, $editFields); return false; }); -} - +} + function doEditNetworkOffering2($actionLink, $detailsTab, $midmenuItem1, $readonlyFields, $editFields) { var jsonObj = $midmenuItem1.data("jsonObj"); var id = jsonObj.id; @@ -92,121 +92,121 @@ function doEditNetworkOffering2($actionLink, $detailsTab, $midmenuItem1, $readon $readonlyFields.show(); $("#save_button, #cancel_button").hide(); } - }); -} - -function networkOfferingToMidmenu(jsonObj, $midmenuItem1) { + }); +} + +function networkOfferingToMidmenu(jsonObj, $midmenuItem1) { $midmenuItem1.attr("id", getMidmenuId(jsonObj)); $midmenuItem1.data("jsonObj", jsonObj); /* - var $iconContainer = $midmenuItem1.find("#icon_container").show(); + var $iconContainer = $midmenuItem1.find("#icon_container").show(); $iconContainer.find("#icon").attr("src", "images/midmenuicon_system_networkOffering.png"); */ - + var firstRowText = fromdb(jsonObj.name); $midmenuItem1.find("#first_row").text(firstRowText); $midmenuItem1.find("#first_row_container").attr("title", firstRowText); var secondRowText = fromdb(jsonObj.availability); $midmenuItem1.find("#second_row").text(secondRowText); - $midmenuItem1.find("#second_row_container").attr("title", secondRowText); -} - -function networkOfferingToRightPanel($midmenuItem1) { - copyActionInfoFromMidMenuToRightPanel($midmenuItem1); - $("#right_panel_content").data("$midmenuItem1", $midmenuItem1); - networkOfferingJsonToDetailsTab(); -} - -function networkOfferingJsonToDetailsTab() { - var $midmenuItem1 = $("#right_panel_content").data("$midmenuItem1"); - if($midmenuItem1 == null) { - networkOfferingClearDetailsTab(); - return; - } - - var jsonObj = $midmenuItem1.data("jsonObj"); - if(jsonObj == null) { - networkOfferingClearDetailsTab(); - return; - } - - var $thisTab = $("#right_panel_content #tab_content_details"); - $thisTab.find("#tab_container").hide(); - $thisTab.find("#tab_spinning_wheel").show(); - - var id = jsonObj.id; - - var jsonObj; - $.ajax({ - data: createURL("command=listNetworkOfferings&id="+id), - dataType: "json", - async: false, - success: function(json) { - var items = json.listnetworkofferingsresponse.networkoffering; - if(items != null && items.length > 0) { - jsonObj = items[0]; - $midmenuItem1.data("jsonObj", jsonObj); - } - } - }); - - $thisTab.find("#id").text(fromdb(jsonObj.id)); - - $thisTab.find("#grid_header_title").text(fromdb(jsonObj.name)); - $thisTab.find("#name").text(fromdb(jsonObj.name)); - $thisTab.find("#name_edit").val(fromdb(jsonObj.name)); - - $thisTab.find("#displaytext").text(fromdb(jsonObj.displaytext)); - $thisTab.find("#displaytext_edit").val(fromdb(jsonObj.displaytext)); - - $thisTab.find("#availability").text(fromdb(jsonObj.availability)); - $thisTab.find("#availability_edit").val(fromdb(jsonObj.availability)); - - setBooleanReadField(jsonObj.isdefault, $thisTab.find("#isdefault")); - setBooleanReadField(jsonObj.specifyvlan, $thisTab.find("#specifyvlan")); + $midmenuItem1.find("#second_row_container").attr("title", secondRowText); +} + +function networkOfferingToRightPanel($midmenuItem1) { + copyActionInfoFromMidMenuToRightPanel($midmenuItem1); + $("#right_panel_content").data("$midmenuItem1", $midmenuItem1); + networkOfferingJsonToDetailsTab(); +} + +function networkOfferingJsonToDetailsTab() { + var $midmenuItem1 = $("#right_panel_content").data("$midmenuItem1"); + if($midmenuItem1 == null) { + networkOfferingClearDetailsTab(); + return; + } + + var jsonObj = $midmenuItem1.data("jsonObj"); + if(jsonObj == null) { + networkOfferingClearDetailsTab(); + return; + } + + var $thisTab = $("#right_panel_content #tab_content_details"); + $thisTab.find("#tab_container").hide(); + $thisTab.find("#tab_spinning_wheel").show(); + + var id = jsonObj.id; + + var jsonObj; + $.ajax({ + data: createURL("command=listNetworkOfferings&id="+id), + dataType: "json", + async: false, + success: function(json) { + var items = json.listnetworkofferingsresponse.networkoffering; + if(items != null && items.length > 0) { + jsonObj = items[0]; + $midmenuItem1.data("jsonObj", jsonObj); + } + } + }); + + $thisTab.find("#id").text(fromdb(jsonObj.id)); + + $thisTab.find("#grid_header_title").text(fromdb(jsonObj.name)); + $thisTab.find("#name").text(fromdb(jsonObj.name)); + $thisTab.find("#name_edit").val(fromdb(jsonObj.name)); + + $thisTab.find("#displaytext").text(fromdb(jsonObj.displaytext)); + $thisTab.find("#displaytext_edit").val(fromdb(jsonObj.displaytext)); + + $thisTab.find("#availability").text(fromdb(jsonObj.availability)); + $thisTab.find("#availability_edit").val(fromdb(jsonObj.availability)); + + setBooleanReadField(jsonObj.isdefault, $thisTab.find("#isdefault")); + setBooleanReadField(jsonObj.specifyvlan, $thisTab.find("#specifyvlan")); var networkRate = jsonObj.networkrate; - if (networkRate == undefined || networkRate == "-1") { + if (networkRate == undefined || networkRate == -1) { $thisTab.find("#rate").text(dictionary["label.unlimited"]); } else { $thisTab.find("#rate").text(fromdb(networkRate) + " Mb/s"); - } - $thisTab.find("#traffictype").text(fromdb(jsonObj.traffictype)); - - //actions *** - var $actionMenu = $("#right_panel_content #tab_content_details #action_link #action_menu"); - $actionMenu.find("#action_list").empty(); - buildActionLinkForTab("label.action.edit.network.offering", networkOfferingActionMap, $actionMenu, $midmenuItem1, $thisTab); - - $thisTab.find("#tab_spinning_wheel").hide(); - $thisTab.find("#tab_container").show(); -} - -function networkOfferingClearRightPanel() { - networkOfferingClearDetailsTab(); -} - -function networkOfferingClearDetailsTab() { - var $thisTab = $("#right_panel_content").find("#tab_content_details"); - $thisTab.find("#id").text(""); - $thisTab.find("#grid_header_title").text(""); - $thisTab.find("#name").text(""); - $thisTab.find("#name_edit").val(""); - $thisTab.find("#displaytext").text(""); - $thisTab.find("#displaytext_edit").val(""); - $thisTab.find("#disksize").text(""); - $thisTab.find("#tags").text(""); - $thisTab.find("#domain").text(""); - - var $actionMenu = $("#right_panel_content #tab_content_details #action_link #action_menu"); - $actionMenu.find("#action_list").empty(); - $actionMenu.find("#action_list").append($("#no_available_actions").clone().show()); -} - + } + $thisTab.find("#traffictype").text(fromdb(jsonObj.traffictype)); + + //actions *** + var $actionMenu = $("#right_panel_content #tab_content_details #action_link #action_menu"); + $actionMenu.find("#action_list").empty(); + buildActionLinkForTab("label.action.edit.network.offering", networkOfferingActionMap, $actionMenu, $midmenuItem1, $thisTab); + + $thisTab.find("#tab_spinning_wheel").hide(); + $thisTab.find("#tab_container").show(); +} + +function networkOfferingClearRightPanel() { + networkOfferingClearDetailsTab(); +} + +function networkOfferingClearDetailsTab() { + var $thisTab = $("#right_panel_content").find("#tab_content_details"); + $thisTab.find("#id").text(""); + $thisTab.find("#grid_header_title").text(""); + $thisTab.find("#name").text(""); + $thisTab.find("#name_edit").val(""); + $thisTab.find("#displaytext").text(""); + $thisTab.find("#displaytext_edit").val(""); + $thisTab.find("#disksize").text(""); + $thisTab.find("#tags").text(""); + $thisTab.find("#domain").text(""); + + var $actionMenu = $("#right_panel_content #tab_content_details #action_link #action_menu"); + $actionMenu.find("#action_list").empty(); + $actionMenu.find("#action_list").append($("#no_available_actions").clone().show()); +} + var networkOfferingActionMap = { "label.action.edit.network.offering": { dialogBeforeActionFn: doEditNetworkOffering } -} \ No newline at end of file +} From 4992ee756fc04327f4b8a0e6832313ddbc94d0d5 Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 29 Mar 2011 18:42:19 -0700 Subject: [PATCH 11/72] kbps means kilotype per secondary, --- .../com/cloud/hypervisor/xen/resource/CitrixResourceBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 245b75eb86c..af5688da357 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -645,7 +645,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe vifr.qosAlgorithmType = "ratelimit"; vifr.qosAlgorithmParams = new HashMap(); // convert mbs to kilobyte per second - vifr.qosAlgorithmParams.put("kbps", Integer.toString(nic.getNetworkRateMbps() * 1024)); + vifr.qosAlgorithmParams.put("kbps", Integer.toString(nic.getNetworkRateMbps() * 128)); } VIF vif = VIF.create(conn, vifr); From c1db5aea31c28f6bf15f74a8259e7937927d479b Mon Sep 17 00:00:00 2001 From: alena Date: Tue, 29 Mar 2011 20:17:49 -0700 Subject: [PATCH 12/72] Fixed NPE in listVirtualMachines command - when search for ROOT volume's storagePool type, assume that corresponding storagePool might be removed. --- server/src/com/cloud/api/ApiDBUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index ac6d848af66..1d99e5ede0b 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -394,7 +394,7 @@ public class ApiDBUtils { } public static StoragePoolVO findStoragePoolById(Long storagePoolId) { - return _storagePoolDao.findById(storagePoolId); + return _storagePoolDao.findByIdIncludingRemoved(storagePoolId); } public static VMTemplateVO findTemplateById(Long templateId) { From e276d3b7fb4459aa47c3e45a9db7e8d1cd6dda43 Mon Sep 17 00:00:00 2001 From: kishan Date: Wed, 30 Mar 2011 11:08:55 +0530 Subject: [PATCH 13/72] bug 7631: Convert unprocessed events to usage_events status 7631: resolved fixed --- .../com/cloud/upgrade/dao/Upgrade218to22.java | 338 ++++++++++++++++++ .../UsageEvents218To224UpgradeTest.java | 90 +++++ 2 files changed, 428 insertions(+) create mode 100644 server/test/com/cloud/upgrade/UsageEvents218To224UpgradeTest.java diff --git a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java index 45f6bd04fd3..249c23453c8 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java @@ -18,18 +18,28 @@ package com.cloud.upgrade.dao; import java.io.File; +import java.io.IOException; +import java.io.StringReader; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.sql.Types; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Properties; +import java.util.TimeZone; import java.util.UUID; import org.apache.log4j.Logger; +import com.cloud.event.EventTypes; +import com.cloud.event.EventVO; +import com.cloud.event.UsageEventVO; +import com.cloud.utils.DateUtil; +import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; import com.cloud.utils.script.Script; @@ -1095,6 +1105,333 @@ public class Upgrade218to22 implements DbUpgrade { } } + private void migrateEvents(Connection conn){ + try { + //get last processed event Id + Long lastProcessedEvent = getMostRecentEvent(conn); + //Events not yet processed + String sql = "SELECT type, description, user_id, account_id, created, level, parameters FROM cloud.event vmevt WHERE vmevt.id > ? and vmevt.state = 'Completed' "; + if (lastProcessedEvent == null) { + System.out.println("no events are processed earlier, copying all events"); + sql = "SELECT type, description, user_id, account_id, created, level, parameters FROM cloud.event vmevt WHERE vmevt.state = 'Completed' "; + } + + PreparedStatement pstmt = null; + + pstmt = conn.prepareStatement(sql); + int i = 1; + if (lastProcessedEvent != null) { + pstmt.setLong(i++, lastProcessedEvent); + } + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + EventVO event = new EventVO(); + event.setType(rs.getString(1)); + event.setDescription(rs.getString(2)); + event.setUserId(rs.getLong(3)); + event.setAccountId(rs.getLong(4)); + event.setCreatedDate(DateUtil.parseDateString(TimeZone.getTimeZone("GMT"), rs.getString(5))); + event.setLevel(rs.getString(6)); + event.setParameters(rs.getString(7)); + convertEvent(event, conn); + } + s_logger.trace("Migrating events completed"); + } catch (Exception e) { + System.out.println("Error: "+e.getMessage()); + throw new CloudRuntimeException("Failed to migrate usage events: ", e); + } + } + + private Long getMostRecentEvent(Connection conn) { + PreparedStatement pstmt = null; + String sql = "SELECT id FROM cloud_usage.event ORDER BY created DESC LIMIT 1"; + try { + pstmt = conn.prepareStatement(sql); + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) { + return rs.getLong(1); + } + } catch (Exception ex) { + throw new CloudRuntimeException("error getting most recent event date: "+ ex.getMessage()); + } + return null; + } + + private void convertEvent(EventVO event, Connection conn) throws IOException, SQLException { + // we only create usage for success cases as error cases mean + // the event didn't happen, so it couldn't result in usage + if (!EventVO.LEVEL_INFO.equals(event.getLevel())) { + return; + } + String eventType = event.getType(); + UsageEventVO usageEvent = null; + if (isVMEvent(eventType)) { + usageEvent= convertVMEvent(event); + } else if (isIPEvent(eventType)) { + usageEvent= convertIPEvent(event); + } else if (isVolumeEvent(eventType)) { + usageEvent = convertVolumeEvent(event); + } else if (isTemplateEvent(eventType)) { + usageEvent = convertTemplateEvent(event); + } else if (isISOEvent(eventType)) { + usageEvent = convertISOEvent(event); + } else if (isSnapshotEvent(eventType)) { + usageEvent = convertSnapshotEvent(event); + } /*else if (isSecurityGrpEvent(eventType)) { + usageEvent = convertSecurityGrpEvent(event); + } else if (isLoadBalancerEvent(eventType)) { + usageEvent = convertLoadBalancerEvent(event); + }*/ + if(usageEvent != null){ + usageEvent.setCreatedDate(event.getCreateDate()); + //update firewall_rules table + PreparedStatement pstmt = null; + pstmt = conn.prepareStatement("INSERT INTO usage_event (usage_event.type, usage_event.created, usage_event.account_id, usage_event.zone_id, usage_event.resource_id, usage_event.resource_name," + + " usage_event.offering_id, usage_event.template_id, usage_event.size) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); + pstmt.setString(1, usageEvent.getType()); + pstmt.setString(2, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usageEvent.getCreateDate())); + pstmt.setLong(3, usageEvent.getAccountId()); + pstmt.setLong(4, usageEvent.getZoneId()); + pstmt.setLong(5, usageEvent.getResourceId()); + pstmt.setString(6, usageEvent.getResourceName()); + if(usageEvent.getOfferingId() != null){ + pstmt.setLong(7, usageEvent.getOfferingId()); + } else { + pstmt.setNull(7, Types.BIGINT); + } + if(usageEvent.getTemplateId() != null){ + pstmt.setLong(8, usageEvent.getTemplateId()); + } else { + pstmt.setNull(8, Types.BIGINT); + } + if(usageEvent.getSize() != null){ + pstmt.setLong(9, usageEvent.getSize()); + } else { + pstmt.setNull(9, Types.BIGINT); + } + //pstmt.setString(10, usageEvent.getResourceType()); + pstmt.executeUpdate(); + pstmt.close(); + } + } + + private boolean isVMEvent(String eventType) { + if (eventType == null) return false; + return eventType.startsWith("VM."); + } + + private boolean isIPEvent(String eventType) { + if (eventType == null) return false; + return eventType.startsWith("NET.IP"); + } + + private boolean isVolumeEvent(String eventType) { + if (eventType == null) return false; + return (eventType.equals(EventTypes.EVENT_VOLUME_CREATE) || + eventType.equals(EventTypes.EVENT_VOLUME_DELETE)); + } + + private boolean isTemplateEvent(String eventType) { + if (eventType == null) return false; + return (eventType.equals(EventTypes.EVENT_TEMPLATE_CREATE) || + eventType.equals(EventTypes.EVENT_TEMPLATE_COPY) || + eventType.equals(EventTypes.EVENT_TEMPLATE_DELETE)); + } + + private boolean isISOEvent(String eventType) { + if (eventType == null) return false; + return (eventType.equals(EventTypes.EVENT_ISO_CREATE) || + eventType.equals(EventTypes.EVENT_ISO_COPY) || + eventType.equals(EventTypes.EVENT_ISO_DELETE)); + } + + private boolean isSnapshotEvent(String eventType) { + if (eventType == null) return false; + return (eventType.equals(EventTypes.EVENT_SNAPSHOT_CREATE) || + eventType.equals(EventTypes.EVENT_SNAPSHOT_DELETE)); + } + + private boolean isLoadBalancerEvent(String eventType) { + if (eventType == null) return false; + return eventType.startsWith("LB."); + } + + private UsageEventVO convertVMEvent(EventVO event) throws IOException { + + Properties vmEventParams = new Properties(); + UsageEventVO usageEvent = null; + long vmId = -1L; + long soId = -1L; // service offering id + long zoneId = -1L; + String eventParams = event.getParameters(); + if (eventParams != null) { + vmEventParams.load(new StringReader(eventParams)); + vmId = Long.parseLong(vmEventParams.getProperty("id")); + soId = Long.parseLong(vmEventParams.getProperty("soId")); + zoneId = Long.parseLong(vmEventParams.getProperty("dcId")); + } + + if (EventTypes.EVENT_VM_START.equals(event.getType())) { + long templateId = 0; + String tId = vmEventParams.getProperty("tId"); + if (tId != null) { + templateId = Long.parseLong(tId); + } + + usageEvent = new UsageEventVO(EventTypes.EVENT_VM_START, event.getAccountId(), zoneId, vmId, vmEventParams.getProperty("vmName"), soId, templateId, ""); + } else if (EventTypes.EVENT_VM_STOP.equals(event.getType())) { + usageEvent = new UsageEventVO(EventTypes.EVENT_VM_STOP, event.getAccountId(), zoneId, vmId, vmEventParams.getProperty("vmName")); + } else if (EventTypes.EVENT_VM_CREATE.equals(event.getType())) { + Long templateId = null; + String tId = vmEventParams.getProperty("tId"); + if (tId != null) { + templateId = new Long(Long.parseLong(tId)); + } + + usageEvent = new UsageEventVO(EventTypes.EVENT_VM_CREATE, event.getAccountId(), zoneId, vmId, vmEventParams.getProperty("vmName"), soId, templateId, ""); + } else if (EventTypes.EVENT_VM_DESTROY.equals(event.getType())) { + + } + return usageEvent; + } + + private UsageEventVO convertIPEvent(EventVO event) throws IOException { + + Properties ipEventParams = new Properties(); + String ipAddress = null; + boolean isSourceNat = false; + UsageEventVO usageEvent = null; + ipEventParams.load(new StringReader(event.getParameters())); + ipAddress = ipEventParams.getProperty("address"); + if (ipAddress == null) { + ipAddress = ipEventParams.getProperty("guestIPaddress"); + if (ipAddress == null) { + // can not find IP address, bail for this event + return null; + } + } + isSourceNat = Boolean.parseBoolean(ipEventParams.getProperty("sourceNat")); + if (isSourceNat) return null; // skip source nat IP addresses as we don't charge for them + + if (EventTypes.EVENT_NET_IP_ASSIGN.equals(event.getType())) { + long zoneId = Long.parseLong(ipEventParams.getProperty("dcId")); + usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, event.getAccountId(), zoneId, 0L, ipAddress, 0L); + } else if (EventTypes.EVENT_NET_IP_RELEASE.equals(event.getType())) { + if (!isSourceNat) { + // at this point it's not a sourceNat IP, so find the usage record with this IP and a null released date, update the released date + usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, event.getAccountId(), 0L, 0L, ipAddress, 0L); + } + } + return usageEvent; + } + + private UsageEventVO convertVolumeEvent(EventVO event) throws IOException { + + Properties volEventParams = new Properties(); + long volId = -1L; + Long doId = -1L; + long zoneId = -1L; + Long templateId = -1L; + long size = -1L; + UsageEventVO usageEvent = null; + volEventParams.load(new StringReader(event.getParameters())); + volId = Long.parseLong(volEventParams.getProperty("id")); + if (EventTypes.EVENT_VOLUME_CREATE.equals(event.getType())) { + doId = Long.parseLong(volEventParams.getProperty("doId")); + zoneId = Long.parseLong(volEventParams.getProperty("dcId")); + templateId = Long.parseLong(volEventParams.getProperty("tId")); + size = Long.parseLong(volEventParams.getProperty("size")); + if(doId == -1){ + doId = null; + } + if(templateId == -1){ + templateId = null; + } + } + + if (EventTypes.EVENT_VOLUME_CREATE.equals(event.getType())) { + usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, event.getAccountId(), zoneId, volId, + "", doId, templateId, size); + } else if (EventTypes.EVENT_VOLUME_DELETE.equals(event.getType())) { + usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_DELETE, event.getAccountId(), 0, volId, + ""); + + } + return usageEvent; + } + + private UsageEventVO convertTemplateEvent(EventVO event) throws IOException { + + Properties templateEventParams = new Properties(); + long templateId = -1L; + long zoneId = -1L; + long templateSize = -1L; + UsageEventVO usageEvent = null; + + templateEventParams.load(new StringReader(event.getParameters())); + templateId = Long.parseLong(templateEventParams.getProperty("id")); + if(templateEventParams.getProperty("dcId") != null){ + zoneId = Long.parseLong(templateEventParams.getProperty("dcId")); + } + if (EventTypes.EVENT_TEMPLATE_CREATE.equals(event.getType()) || EventTypes.EVENT_TEMPLATE_COPY.equals(event.getType())) { + templateSize = Long.parseLong(templateEventParams.getProperty("size")); + if(templateSize < 1){ + return null; + } + if(zoneId == -1L){ + return null; + } + usageEvent = new UsageEventVO(event.getType(), event.getAccountId(), zoneId, templateId, "", null, null , templateSize); + } else if (EventTypes.EVENT_TEMPLATE_DELETE.equals(event.getType())) { + usageEvent = new UsageEventVO(event.getType(), event.getAccountId(), zoneId, templateId, null); + } + return usageEvent; + } + + private UsageEventVO convertISOEvent(EventVO event) throws IOException { + Properties isoEventParams = new Properties(); + long isoId = -1L; + long isoSize = -1L; + long zoneId = -1L; + UsageEventVO usageEvent = null; + + isoEventParams.load(new StringReader(event.getParameters())); + isoId = Long.parseLong(isoEventParams.getProperty("id")); + if(isoEventParams.getProperty("dcId") != null){ + zoneId = Long.parseLong(isoEventParams.getProperty("dcId")); + } + + if (EventTypes.EVENT_ISO_CREATE.equals(event.getType()) || EventTypes.EVENT_ISO_COPY.equals(event.getType())) { + isoSize = Long.parseLong(isoEventParams.getProperty("size")); + usageEvent = new UsageEventVO(event.getType(), event.getAccountId(), zoneId, isoId, "", null, null , isoSize); + } else if (EventTypes.EVENT_ISO_DELETE.equals(event.getType())) { + usageEvent = new UsageEventVO(event.getType(), event.getAccountId(), zoneId, isoId, null); + } + return usageEvent; + } + + private UsageEventVO convertSnapshotEvent(EventVO event) throws IOException { + Properties snapEventParams = new Properties(); + long snapId = -1L; + long snapSize = -1L; + long zoneId = -1L; + UsageEventVO usageEvent = null; + + snapEventParams.load(new StringReader(event.getParameters())); + snapId = Long.parseLong(snapEventParams.getProperty("id")); + + if (EventTypes.EVENT_SNAPSHOT_CREATE.equals(event.getType())) { + snapSize = Long.parseLong(snapEventParams.getProperty("size")); + zoneId = Long.parseLong(snapEventParams.getProperty("dcId")); + + usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_CREATE, event.getAccountId(), zoneId, snapId, "", null, null, snapSize); + } else if (EventTypes.EVENT_SNAPSHOT_DELETE.equals(event.getType())) { + usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_DELETE, event.getAccountId(), zoneId, snapId, "", null, null, 0L); + } + return usageEvent; + } + + @Override public void performDataMigration(Connection conn) { upgradeDataCenter(conn); @@ -1102,6 +1439,7 @@ public class Upgrade218to22 implements DbUpgrade { upgradeInstanceGroups(conn); upgradePortForwardingRules(conn); upgradeLoadBalancingRules(conn); + migrateEvents(conn); } @Override diff --git a/server/test/com/cloud/upgrade/UsageEvents218To224UpgradeTest.java b/server/test/com/cloud/upgrade/UsageEvents218To224UpgradeTest.java new file mode 100644 index 00000000000..15d6f5f7a4c --- /dev/null +++ b/server/test/com/cloud/upgrade/UsageEvents218To224UpgradeTest.java @@ -0,0 +1,90 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package com.cloud.upgrade; + + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import junit.framework.TestCase; + +import org.apache.log4j.Logger; +import org.junit.After; +import org.junit.Before; + +import com.cloud.upgrade.dao.VersionDaoImpl; +import com.cloud.utils.component.ComponentLocator; +import com.cloud.utils.db.DbTestUtils; +import com.cloud.utils.db.Transaction; + +public class UsageEvents218To224UpgradeTest extends TestCase { + private static final Logger s_logger = Logger.getLogger(UsageEvents218To224UpgradeTest.class); + + @Override + @Before + public void setUp() throws Exception { + DbTestUtils.executeScript("PreviousDatabaseSchema/clean-db.sql", false, true); + } + + @Override + @After + public void tearDown() throws Exception { + } + + public void test21to22Upgrade() throws SQLException { + s_logger.debug("Finding sample data from 2.1.8"); + DbTestUtils.executeScript("PreviousDatabaseSchema/2.1.8/2.1.8.sample_usageEvents.sql", false, true); + + Connection conn; + PreparedStatement pstmt; + + VersionDaoImpl dao = ComponentLocator.inject(VersionDaoImpl.class); + DatabaseUpgradeChecker checker = ComponentLocator.inject(DatabaseUpgradeChecker.class); + + String version = dao.getCurrentVersion(); + assert version.equals("2.1.8") : "Version returned is not 2.1.8 but " + version; + + checker.upgrade("2.1.8", "2.2.4"); + + conn = Transaction.getStandaloneConnection(); + try { + pstmt = conn.prepareStatement("SELECT version FROM version ORDER BY id DESC LIMIT 1"); + ResultSet rs = pstmt.executeQuery(); + assert rs.next() : "No version selected"; + assert rs.getString(1).equals("2.2.4") : "VERSION stored is not 2.2.4: " + rs.getString(1); + rs.close(); + pstmt.close(); + + pstmt = conn.prepareStatement("SELECT COUNT(*) FROM usage_event"); + rs = pstmt.executeQuery(); + assert rs.next() : "Unable to get the count of network offerings."; + assert (rs.getInt(1) == 37) : "Didn't find 7 network offerings but found " + rs.getInt(1); + rs.close(); + pstmt.close(); + + } finally { + try { + conn.close(); + } catch (SQLException e) { + } + } + } + +} From a1a2717811c30eb58b31f7827e04d8cf809f4a9a Mon Sep 17 00:00:00 2001 From: alena Date: Tue, 29 Mar 2011 21:30:29 -0700 Subject: [PATCH 14/72] bug 9192: don't query for securityGroups when Vm's zone is security group disabled. status 9192: resolved fixed --- .../src/com/cloud/api/ApiResponseHelper.java | 102 ++++++++++-------- 1 file changed, 59 insertions(+), 43 deletions(-) diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 2f6004b02b2..7c0a2771e08 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -1034,22 +1034,27 @@ public class ApiResponseHelper implements ResponseGenerator { } // Data Center Info - if (!dataCenters.containsKey(userVm.getDataCenterId())) { - dataCenters.put(userVm.getDataCenterId(), ApiDBUtils.findZoneById(userVm.getDataCenterId())); - } - userVmResponse.setZoneId(userVm.getDataCenterId()); - userVmResponse.setZoneName(dataCenters.get(userVm.getDataCenterId()).getName()); + DataCenter zone = dataCenters.get(userVm.getDataCenterId()); + if (zone == null) { + zone = ApiDBUtils.findZoneById(userVm.getDataCenterId()); + dataCenters.put(zone.getId(), zone); + } + + userVmResponse.setZoneId(zone.getId()); + userVmResponse.setZoneName(zone.getName()); // if user is an admin, display host id if (((caller == null) || (caller.getType() == Account.ACCOUNT_TYPE_ADMIN)) && (userVm.getHostId() != null)) { - Long hostId = userVm.getHostId(); - if (!hosts.containsKey(hostId)) { - hosts.put(hostId, ApiDBUtils.findHostById(hostId)); + Host host = hosts.get(userVm.getHostId()); + + if (host == null) { + host = ApiDBUtils.findHostById(userVm.getHostId()); + hosts.put(host.getId(), host); } - userVmResponse.setHostId(hostId); - userVmResponse.setHostName(hosts.get(hostId).getName()); + userVmResponse.setHostId(host.getId()); + userVmResponse.setHostName(host.getName()); } if(userVm.getHypervisorType() != null){ @@ -1057,11 +1062,14 @@ public class ApiResponseHelper implements ResponseGenerator { } // Template Info - if (!templates.containsKey(userVm.getTemplateId())) { - templates.put(userVm.getTemplateId(),ApiDBUtils.findTemplateById(userVm.getTemplateId())); + VMTemplateVO template = templates.get(userVm.getTemplateId()); + if (template == null) { + template = ApiDBUtils.findTemplateById(userVm.getTemplateId()); + if (template != null) { + templates.put(template.getId(), template); + } } - VMTemplateVO template = templates.get(userVm.getTemplateId()); if (template != null) { userVmResponse.setTemplateId(userVm.getTemplateId()); userVmResponse.setTemplateName(template.getName()); @@ -1079,23 +1087,28 @@ public class ApiResponseHelper implements ResponseGenerator { } // ISO Info - Long isoId = userVm.getIsoId(); - if (isoId != null) { - if (!templates.containsKey(isoId)) { - templates.put(isoId,ApiDBUtils.findTemplateById(isoId)); - } - userVmResponse.setIsoId(isoId); - userVmResponse.setIsoName(templates.get(isoId).getName()); + VMTemplateVO iso = templates.get(userVm.getIsoId()); + if (iso == null) { + iso = ApiDBUtils.findTemplateById(userVm.getIsoId()); + if (iso != null) { + templates.put(iso.getId(), iso); + } + } + + if (iso != null) { + userVmResponse.setIsoId(iso.getId()); + userVmResponse.setIsoName(iso.getName()); } // Service Offering Info - Long soId = userVm.getServiceOfferingId(); - if (!serviceOfferings.containsKey(soId)) { - serviceOfferings.put(soId, ApiDBUtils.findServiceOfferingById(userVm.getServiceOfferingId())); + ServiceOffering offering = serviceOfferings.get(userVm.getServiceOfferingId()); + + if (offering == null) { + offering = ApiDBUtils.findServiceOfferingById(userVm.getServiceOfferingId()); + serviceOfferings.put(offering.getId(), offering); } - - ServiceOffering offering = serviceOfferings.get(soId); - userVmResponse.setServiceOfferingId(userVm.getServiceOfferingId()); + + userVmResponse.setServiceOfferingId(offering.getId()); userVmResponse.setServiceOfferingName(offering.getName()); userVmResponse.setCpuNumber(offering.getCpu()); userVmResponse.setCpuSpeed(offering.getSpeed()); @@ -1129,20 +1142,22 @@ public class ApiResponseHelper implements ResponseGenerator { } userVmResponse.setGuestOsId(userVm.getGuestOSId()); - // security groups - List securityGroups = ApiDBUtils.getSecurityGroupsForVm(userVm.getId()); - List securityGroupResponse = new ArrayList(); - for(SecurityGroupVO grp : securityGroups) { - SecurityGroupResponse resp = new SecurityGroupResponse(); - resp.setId(grp.getId()); - resp.setName(grp.getName()); - resp.setDescription(grp.getDescription()); - resp.setObjectName("securitygroup"); - securityGroupResponse.add(resp); + // security groups - list only when zone is security group enabled + if (zone.isSecurityGroupEnabled()) { + List securityGroups = ApiDBUtils.getSecurityGroupsForVm(userVm.getId()); + List securityGroupResponse = new ArrayList(); + for(SecurityGroupVO grp : securityGroups) { + SecurityGroupResponse resp = new SecurityGroupResponse(); + resp.setId(grp.getId()); + resp.setName(grp.getName()); + resp.setDescription(grp.getDescription()); + resp.setObjectName("securitygroup"); + securityGroupResponse.add(resp); + } + + userVmResponse.setSecurityGroupList(securityGroupResponse); } - userVmResponse.setSecurityGroupList(securityGroupResponse); - List nicProfiles = ApiDBUtils.getNics(userVm); List nicResponses = new ArrayList(); for (NicProfile singleNicProfile : nicProfiles) { @@ -1161,12 +1176,13 @@ public class ApiResponseHelper implements ResponseGenerator { } } - Long networkId = singleNicProfile.getNetworkId(); - if (!networks.containsKey(networkId)) { - networks.put(networkId, ApiDBUtils.findNetworkById(networkId)); + //Long networkId = singleNicProfile.getNetworkId(); + Network network = networks.get(singleNicProfile.getNetworkId()); + if (network == null) { + network = ApiDBUtils.findNetworkById(singleNicProfile.getNetworkId()); + networks.put(singleNicProfile.getNetworkId(), network); } - - Network network = networks.get(networkId); + nicResponse.setTrafficType(network.getTrafficType().toString()); nicResponse.setType(network.getGuestType().toString()); nicResponse.setIsDefault(singleNicProfile.isDefaultNic()); From 6d005313bc9a21bb3f190833204f90a9aee2dc1d Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 30 Mar 2011 12:14:42 -0700 Subject: [PATCH 15/72] Move schema files to setup/db directory in line with DB upgrade code --- cloud.spec | 1 + setup/db/{ => db}/schema-20to21.sql | 0 setup/db/{ => db}/schema-217to218.sql | 0 setup/db/{ => db}/schema-21to22-cleanup.sql | 0 setup/db/{ => db}/schema-21to22.sql | 0 setup/db/{ => db}/schema-221to222-cleanup.sql | 0 setup/db/{ => db}/schema-221to222.sql | 0 setup/db/{ => db}/schema-222to224-cleanup.sql | 0 setup/db/{ => db}/schema-222to224.sql | 0 setup/db/{ => db}/schema-22beta1to22beta2.sql | 0 setup/db/{ => db}/schema-22beta3to22beta4.sql | 0 setup/db/{ => db}/schema-level.sql | 0 setup/db/{ => db}/schema-snapshot-217to223.sql | 0 13 files changed, 1 insertion(+) rename setup/db/{ => db}/schema-20to21.sql (100%) rename setup/db/{ => db}/schema-217to218.sql (100%) rename setup/db/{ => db}/schema-21to22-cleanup.sql (100%) rename setup/db/{ => db}/schema-21to22.sql (100%) rename setup/db/{ => db}/schema-221to222-cleanup.sql (100%) rename setup/db/{ => db}/schema-221to222.sql (100%) rename setup/db/{ => db}/schema-222to224-cleanup.sql (100%) rename setup/db/{ => db}/schema-222to224.sql (100%) rename setup/db/{ => db}/schema-22beta1to22beta2.sql (100%) rename setup/db/{ => db}/schema-22beta3to22beta4.sql (100%) rename setup/db/{ => db}/schema-level.sql (100%) rename setup/db/{ => db}/schema-snapshot-217to223.sql (100%) diff --git a/cloud.spec b/cloud.spec index f3af1a28373..e91fcae696f 100644 --- a/cloud.spec +++ b/cloud.spec @@ -523,6 +523,7 @@ fi %attr(0755,root,root) %{_bindir}/%{name}-set-guest-sshkey %dir %{_datadir}/%{name}/setup %{_datadir}/%{name}/setup/*.sql +%{_datadir}/%{name}/setup/db/*.sql %{_datadir}/%{name}/setup/*.sh %{_datadir}/%{name}/setup/server-setup.xml diff --git a/setup/db/schema-20to21.sql b/setup/db/db/schema-20to21.sql similarity index 100% rename from setup/db/schema-20to21.sql rename to setup/db/db/schema-20to21.sql diff --git a/setup/db/schema-217to218.sql b/setup/db/db/schema-217to218.sql similarity index 100% rename from setup/db/schema-217to218.sql rename to setup/db/db/schema-217to218.sql diff --git a/setup/db/schema-21to22-cleanup.sql b/setup/db/db/schema-21to22-cleanup.sql similarity index 100% rename from setup/db/schema-21to22-cleanup.sql rename to setup/db/db/schema-21to22-cleanup.sql diff --git a/setup/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql similarity index 100% rename from setup/db/schema-21to22.sql rename to setup/db/db/schema-21to22.sql diff --git a/setup/db/schema-221to222-cleanup.sql b/setup/db/db/schema-221to222-cleanup.sql similarity index 100% rename from setup/db/schema-221to222-cleanup.sql rename to setup/db/db/schema-221to222-cleanup.sql diff --git a/setup/db/schema-221to222.sql b/setup/db/db/schema-221to222.sql similarity index 100% rename from setup/db/schema-221to222.sql rename to setup/db/db/schema-221to222.sql diff --git a/setup/db/schema-222to224-cleanup.sql b/setup/db/db/schema-222to224-cleanup.sql similarity index 100% rename from setup/db/schema-222to224-cleanup.sql rename to setup/db/db/schema-222to224-cleanup.sql diff --git a/setup/db/schema-222to224.sql b/setup/db/db/schema-222to224.sql similarity index 100% rename from setup/db/schema-222to224.sql rename to setup/db/db/schema-222to224.sql diff --git a/setup/db/schema-22beta1to22beta2.sql b/setup/db/db/schema-22beta1to22beta2.sql similarity index 100% rename from setup/db/schema-22beta1to22beta2.sql rename to setup/db/db/schema-22beta1to22beta2.sql diff --git a/setup/db/schema-22beta3to22beta4.sql b/setup/db/db/schema-22beta3to22beta4.sql similarity index 100% rename from setup/db/schema-22beta3to22beta4.sql rename to setup/db/db/schema-22beta3to22beta4.sql diff --git a/setup/db/schema-level.sql b/setup/db/db/schema-level.sql similarity index 100% rename from setup/db/schema-level.sql rename to setup/db/db/schema-level.sql diff --git a/setup/db/schema-snapshot-217to223.sql b/setup/db/db/schema-snapshot-217to223.sql similarity index 100% rename from setup/db/schema-snapshot-217to223.sql rename to setup/db/db/schema-snapshot-217to223.sql From bf13d2cbecb3667b4b500f67f83d48feca907ade Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Wed, 30 Mar 2011 12:17:02 -0700 Subject: [PATCH 16/72] added missing changes from schema changes previously --- api/src/com/cloud/storage/Volume.java | 2 + core/src/com/cloud/storage/VolumeVO.java | 59 ++++++------------------ setup/db/data-21to22.sql | 31 ------------- setup/db/db/schema-21to22.sql | 50 ++++++++++++++++++-- setup/db/index-21to22.sql | 13 ------ 5 files changed, 64 insertions(+), 91 deletions(-) delete mode 100644 setup/db/data-21to22.sql delete mode 100644 setup/db/index-21to22.sql diff --git a/api/src/com/cloud/storage/Volume.java b/api/src/com/cloud/storage/Volume.java index 7f0a8eca1c9..ab6c5b0cccd 100755 --- a/api/src/com/cloud/storage/Volume.java +++ b/api/src/com/cloud/storage/Volume.java @@ -135,4 +135,6 @@ public interface Volume extends ControlledEntity, BasedOn { long getDiskOfferingId(); String getChainInfo(); + + boolean isRecreatable(); } diff --git a/core/src/com/cloud/storage/VolumeVO.java b/core/src/com/cloud/storage/VolumeVO.java index 1bb5c60cbd0..dd00f0174e9 100755 --- a/core/src/com/cloud/storage/VolumeVO.java +++ b/core/src/com/cloud/storage/VolumeVO.java @@ -125,31 +125,6 @@ public class VolumeVO implements Volume { @Column(name="chain_info") String chainInfo; - /** - * Constructor for data disk. - * @param type - * @param instanceId - * @param name - * @param dcId - * @param podId - * @param accountId - * @param domainId - * @param size - */ - public VolumeVO(Type type, long instanceId, String name, long dcId, long podId, long accountId, long domainId, long size) { - this.volumeType = type; - this.name = name; - this.dataCenterId = dcId; - this.podId = podId; - this.accountId = accountId; - this.domainId = domainId; - this.instanceId = instanceId; - this.size = size; - this.templateId = null; - this.storageResourceType = Storage.StorageResourceType.STORAGE_POOL; - this.poolType = null; - } - // Real Constructor public VolumeVO(Type type, String name, long dcId, long domainId, long accountId, long diskOfferingId, long size) { this.volumeType = type; @@ -162,25 +137,6 @@ public class VolumeVO implements Volume { this.state = State.Allocated; } - /** - * Constructor for volume based on a template. - * - * @param type - * @param instanceId - * @param templateId - * @param name - * @param dcId - * @param podId - * @param accountId - * @param domainId - */ - public VolumeVO(Type type, long instanceId, long templateId, String name, long dcId, long podId, long accountId, long domainId, boolean recreatable) { - this(type, instanceId, name, dcId, podId, accountId, domainId, 0l); - this.templateId = templateId; - this.recreatable = recreatable; - } - - public VolumeVO(String name, long dcId, long podId, long accountId, long domainId, Long instanceId, String folder, String path, long size, Volume.Type vType) { this.name = name; this.accountId = accountId; @@ -195,7 +151,22 @@ public class VolumeVO implements Volume { this.recreatable = false; } + // Copy Constructor + public VolumeVO(Volume that) { + this(that.getName(), that.getDataCenterId(), that.getPodId(), that.getAccountId(), that.getDomainId(), that.getInstanceId(), that.getFolder(), that.getPath(), that.getSize(), that.getVolumeType()); + this.recreatable = that.isRecreatable(); + this.state = that.getState(); + this.size = that.getSize(); + this.diskOfferingId = that.getDiskOfferingId(); + this.poolId = that.getPoolId(); + this.storageResourceType = that.getStorageResourceType(); + this.attached = that.getAttached(); + this.chainInfo = that.getChainInfo(); + this.templateId = that.getTemplateId(); + this.deviceId = that.getDeviceId(); + } + @Override public boolean isRecreatable() { return recreatable; } diff --git a/setup/db/data-21to22.sql b/setup/db/data-21to22.sql deleted file mode 100644 index 512b2a1c761..00000000000 --- a/setup/db/data-21to22.sql +++ /dev/null @@ -1,31 +0,0 @@ ---data upgrade from 21 to 22 -use cloud; - -START TRANSACTION; -DELETE FROM template_host_ref WHERE install_path LIKE '%xs-tools%' -DELETE FROM configuration where name='upgrade.url'; -DELETE FROM configuration where name='router.template.id'; -INSERT INTO configuration (category, instance, component, name, value, description) - VALUES ('Network', 'DEFAULT', 'AgentManager', 'remote.access.vpn.client.iprange', '10.1.2.1-10.1.2.8', 'The range of ips to be allocated to remote access vpn clients. The first ip in the range is used by the VPN server'); -INSERT INTO configuration (category, instance, component, name, value, description) - VALUES ('Network', 'DEFAULT', 'AgentManager', 'remote.access.vpn.psk.length', '48', 'The length of the ipsec preshared key (minimum 8, maximum 256)'); -INSERT INTO configuration (category, instance, component, name, value, description) - VALUES ('Network', 'DEFAULT', 'AgentManager', 'remote.access.vpn.user.limit', '8', 'The maximum number of VPN users that can be created per account'); -INSERT INTO configuration (category, instance, component, name, value, description) - VALUES ('Advanced', 'DEFAULT', 'management-server', 'management-server', NULL, 'The cidr of management server network'); -UPDATE vm_template set unique_name='routing_old' where id=1; -INSERT INTO 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 (10, 'routing', 'SystemVM Template', 0, now(), 'ext3', 0, 64, 1, 'http://download.cloud.com/releases/2.2/systemvm.vhd.bz2', 'bcc7f290f4c27ab4d0fe95d1012829ea', 0, 'SystemVM Template', 'VHD', 15, 0, 1); -Update configuration set name='storage.max.volume.size' where name='max.volume.size.mb'; -INSERT INTO sequence (name, value) - VALUES ('snapshots_seq', '1') -UPDATE cloud.sequence SET value=IF((SELECT COUNT(*) FROM cloud.snapshots) > 0, (SELECT max(id) FROM cloud.snapshots) + 1, 1) WHERE name='snapshots_seq' -UPDATE configuration set name='direct.attach.security.groups.enabled' where name='direct.attach.network.groups.enabled'; -UPDATE configuration set name='guest.domain.suffix' where name='domain.suffix'; -INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (132, 2, 'Debian GNU/Linux 6(32-bit)'); -INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (133, 2, 'Debian GNU/Linux 6(64-bit)'); -INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (134, 3, 'Oracle Enterprise Linux 5.5 (32-bit)'); -INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (135, 3, 'Oracle Enterprise Linux 5.5 (64-bit)'); -INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (136, 4, 'Red Hat Enterprise Linux 6.0 (32-bit)'); -INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (137, 4, 'Red Hat Enterprise Linux 6.0 (64-bit)'); -COMMIT; diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index f5590b01f5f..cfd9f4e8bfd 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -74,7 +74,8 @@ CREATE TABLE `cloud`.`network_offerings` ( `userdata_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if network offering provides user data service', `vpn_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if network offering provides vpn service', `dhcp_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if network offering provides dhcp service', - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), + INDEX `i_network_offerings__removed`(`removed`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `cloud`.`networks` ( @@ -110,7 +111,8 @@ CREATE TABLE `cloud`.`networks` ( CONSTRAINT `fk_networks__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`), CONSTRAINT `fk_networks__related` FOREIGN KEY(`related`) REFERENCES `networks`(`id`), CONSTRAINT `fk_networks__account_id` FOREIGN KEY(`account_id`) REFERENCES `account`(`id`), - CONSTRAINT `fk_networks__domain_id` FOREIGN KEY(`domain_id`) REFERENCES `domain`(`id`) + CONSTRAINT `fk_networks__domain_id` FOREIGN KEY(`domain_id`) REFERENCES `domain`(`id`), + INDEX `i_networks__removed`(`removed`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `cloud`.`op_networks`( @@ -167,7 +169,8 @@ CREATE TABLE `cloud`.`nics` ( `removed` datetime COMMENT 'date removed if not null', PRIMARY KEY (`id`), CONSTRAINT `fk_nics__instance_id` FOREIGN KEY `fk_nics__instance_id`(`instance_id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE, - CONSTRAINT `fk_nics__networks_id` FOREIGN KEY `fk_nics__networks_id`(`network_id`) REFERENCES `networks`(`id`) + CONSTRAINT `fk_nics__networks_id` FOREIGN KEY `fk_nics__networks_id`(`network_id`) REFERENCES `networks`(`id`), + INDEX `i_nics__removed`(`removed`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; INSERT INTO `network_offerings` VALUES (1,'System-Public-Network','System Offering for System-Public-Network',NULL,NULL,NULL,'Public',NULL,1,0,NULL,now(),NULL,0,'Required',0,0,0,0,0,0,0),(2,'System-Management-Network','System Offering for System-Management-Network',NULL,NULL,NULL,'Management',NULL,1,0,NULL,now(),NULL,0,'Required',0,0,0,0,0,0,0),(3,'System-Control-Network','System Offering for System-Control-Network',NULL,NULL,NULL,'Control',NULL,1,0,NULL,now(),NULL,0,'Required',0,0,0,0,0,0,0),(4,'System-Storage-Network','System Offering for System-Storage-Network',NULL,NULL,NULL,'Storage',NULL,1,0,NULL,now(),NULL,0,'Required',0,0,0,0,0,0,0),(5,'System-Guest-Network','System-Guest-Network',NULL,NULL,NULL,'Guest',NULL,1,0,NULL,now(),NULL,1,'Required',1,0,0,0,1,0,1),(6,'DefaultVirtualizedNetworkOffering','Virtual Vlan',NULL,NULL,NULL,'Guest',NULL,0,0,NULL,now(),NULL,1,'Required',1,1,1,1,1,1,1),(7,'DefaultDirectNetworkOffering','Direct',NULL,NULL,NULL,'Public',NULL,0,0,NULL,now(),NULL,1,'Required',1,0,0,0,1,0,1); @@ -565,3 +568,44 @@ DELETE FROM `cloud`.`sync_queue`; DELETE FROM `cloud`.`sync_queue_item`; DELETE FROM `cloud`.`async_job`; UPDATE `cloud`.`vm_template` SET unique_name='routing-xenserver-2.4',type='SYSTEM' WHERE name='systemvm-xenserver-2.4'; +DELETE FROM template_host_ref WHERE install_path LIKE '%xs-tools%' +DELETE FROM configuration where name='upgrade.url'; +DELETE FROM configuration where name='router.template.id'; +INSERT INTO configuration (category, instance, component, name, value, description) + VALUES ('Network', 'DEFAULT', 'AgentManager', 'remote.access.vpn.client.iprange', '10.1.2.1-10.1.2.8', 'The range of ips to be allocated to remote access vpn clients. The first ip in the range is used by the VPN server'); +INSERT INTO configuration (category, instance, component, name, value, description) + VALUES ('Network', 'DEFAULT', 'AgentManager', 'remote.access.vpn.psk.length', '48', 'The length of the ipsec preshared key (minimum 8, maximum 256)'); +INSERT INTO configuration (category, instance, component, name, value, description) + VALUES ('Network', 'DEFAULT', 'AgentManager', 'remote.access.vpn.user.limit', '8', 'The maximum number of VPN users that can be created per account'); +INSERT INTO configuration (category, instance, component, name, value, description) + VALUES ('Advanced', 'DEFAULT', 'management-server', 'management-server', NULL, 'The cidr of management server network'); +UPDATE vm_template set unique_name='routing_old' where id=1; +INSERT INTO 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 (10, 'routing', 'SystemVM Template', 0, now(), 'ext3', 0, 64, 1, 'http://download.cloud.com/releases/2.2/systemvm.vhd.bz2', 'bcc7f290f4c27ab4d0fe95d1012829ea', 0, 'SystemVM Template', 'VHD', 15, 0, 1); +Update configuration set name='storage.max.volume.size' where name='max.volume.size.mb'; +INSERT INTO sequence (name, value) + VALUES ('snapshots_seq', '1') +UPDATE cloud.sequence SET value=IF((SELECT COUNT(*) FROM cloud.snapshots) > 0, (SELECT max(id) FROM cloud.snapshots) + 1, 1) WHERE name='snapshots_seq' +UPDATE configuration set name='direct.attach.security.groups.enabled' where name='direct.attach.network.groups.enabled'; +UPDATE configuration set name='guest.domain.suffix' where name='domain.suffix'; + +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (132, 2, 'Debian GNU/Linux 6(32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (133, 2, 'Debian GNU/Linux 6(64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (134, 3, 'Oracle Enterprise Linux 5.5 (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (135, 3, 'Oracle Enterprise Linux 5.5 (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (136, 4, 'Red Hat Enterprise Linux 6.0 (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (137, 4, 'Red Hat Enterprise Linux 6.0 (64-bit)'); + +ALTER TABLE `cloud`.`instance_group` ADD CONSTRAINT `fk_instance_group__account_id` FOREIGN KEY `fk_instance_group__account_id` (`account_id`) REFERENCES `account` (`id`); + +ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___group_id` FOREIGN KEY `fk_instance_group_vm_map___group_id` (`group_id`) REFERENCES `instance_group` (`id`) ON DELETE CASCADE; +ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___instance_id` FOREIGN KEY `fk_instance_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE; + +ALTER TABLE `cloud`.`remote_access_vpn` ADD CONSTRAINT `fk_remote_access_vpn___account_id` FOREIGN KEY `fk_remote_access_vpn__account_id` (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE; +ALTER TABLE `cloud`.`remote_access_vpn` ADD CONSTRAINT `fk_remote_access_vpn__zone_id` FOREIGN KEY `fk_remote_access_vpn__zone_id` (`zone_id`) REFERENCES `data_center` (`id`); +ALTER TABLE `cloud`.`remote_access_vpn` ADD CONSTRAINT `fk_remote_access_vpn__server_addr` FOREIGN KEY `fk_remote_access_vpn__server_addr` (`vpn_server_addr`) REFERENCES `user_ip_address` (`public_ip_address`); +ALTER TABLE `cloud`.`remote_access_vpn` ADD INDEX `i_remote_access_vpn_addr`(`vpn_server_addr`); + +ALTER TABLE `cloud`.`vpn_users` ADD CONSTRAINT `fk_vpn_users___account_id` FOREIGN KEY `fk_vpn_users__account_id` (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE; +ALTER TABLE `cloud`.`vpn_users` ADD INDEX `i_vpn_users_username`(`username`); +ALTER TABLE `cloud`.`vpn_users` ADD UNIQUE `i_vpn_users__account_id__username`(`account_id`, `username`); \ No newline at end of file diff --git a/setup/db/index-21to22.sql b/setup/db/index-21to22.sql deleted file mode 100644 index 8d276e27730..00000000000 --- a/setup/db/index-21to22.sql +++ /dev/null @@ -1,13 +0,0 @@ -ALTER TABLE `cloud`.`instance_group` ADD CONSTRAINT `fk_instance_group__account_id` FOREIGN KEY `fk_instance_group__account_id` (`account_id`) REFERENCES `account` (`id`); - -ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___group_id` FOREIGN KEY `fk_instance_group_vm_map___group_id` (`group_id`) REFERENCES `instance_group` (`id`) ON DELETE CASCADE; -ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___instance_id` FOREIGN KEY `fk_instance_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE; - -ALTER TABLE `cloud`.`remote_access_vpn` ADD CONSTRAINT `fk_remote_access_vpn___account_id` FOREIGN KEY `fk_remote_access_vpn__account_id` (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE; -ALTER TABLE `cloud`.`remote_access_vpn` ADD CONSTRAINT `fk_remote_access_vpn__zone_id` FOREIGN KEY `fk_remote_access_vpn__zone_id` (`zone_id`) REFERENCES `data_center` (`id`); -ALTER TABLE `cloud`.`remote_access_vpn` ADD CONSTRAINT `fk_remote_access_vpn__server_addr` FOREIGN KEY `fk_remote_access_vpn__server_addr` (`vpn_server_addr`) REFERENCES `user_ip_address` (`public_ip_address`); -ALTER TABLE `cloud`.`remote_access_vpn` ADD INDEX `i_remote_access_vpn_addr`(`vpn_server_addr`); - -ALTER TABLE `cloud`.`vpn_users` ADD CONSTRAINT `fk_vpn_users___account_id` FOREIGN KEY `fk_vpn_users__account_id` (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE; -ALTER TABLE `cloud`.`vpn_users` ADD INDEX `i_vpn_users_username`(`username`); -ALTER TABLE `cloud`.`vpn_users` ADD UNIQUE `i_vpn_users__account_id__username`(`account_id`, `username`); From 6d7f3da46abb957afbdaf2c8ad8e4e1e7702acc8 Mon Sep 17 00:00:00 2001 From: alena Date: Wed, 30 Mar 2011 14:48:21 -0700 Subject: [PATCH 17/72] For VirtualRouter apply networkThrottling rate of the GuestNetworkOffering to both Guest and Public networks. --- .../cloud/configuration/ConfigurationService.java | 4 +++- server/src/com/cloud/api/ApiDBUtils.java | 2 +- .../configuration/ConfigurationManagerImpl.java | 13 ++++++++++++- .../src/com/cloud/network/NetworkManagerImpl.java | 10 +++++----- .../router/VirtualNetworkApplianceManagerImpl.java | 2 +- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/api/src/com/cloud/configuration/ConfigurationService.java b/api/src/com/cloud/configuration/ConfigurationService.java index f5b3c71aea5..426b759d56d 100644 --- a/api/src/com/cloud/configuration/ConfigurationService.java +++ b/api/src/com/cloud/configuration/ConfigurationService.java @@ -34,6 +34,8 @@ import com.cloud.offering.DiskOffering; import com.cloud.offering.NetworkOffering; import com.cloud.offering.ServiceOffering; import com.cloud.user.Account; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.Type; public interface ConfigurationService { @@ -182,7 +184,7 @@ public interface ConfigurationService { NetworkOffering getNetworkOffering(long id); - Integer getNetworkRate(long networkOfferingId); + Integer getNetworkRate(long networkOfferingId, Type vmType); Account getVlanAccount(long vlanId); diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 1d99e5ede0b..987b13a84ae 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -524,7 +524,7 @@ public class ApiDBUtils { } public static Integer getNetworkRate(long networkOfferingId) { - return _configMgr.getNetworkRate(networkOfferingId); + return _configMgr.getNetworkRate(networkOfferingId, null); } public static Account getVlanAccount(long vlanId) { diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 8ded152d2a0..6529ea963b7 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -127,6 +127,8 @@ import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.Type; import com.cloud.vm.dao.ConsoleProxyDao; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.SecondaryStorageVmDao; @@ -2779,7 +2781,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } @Override - public Integer getNetworkRate(long networkOfferingId) { + public Integer getNetworkRate(long networkOfferingId, Type vmType) { //validate network offering information NetworkOffering no = getNetworkOffering(networkOfferingId); @@ -2787,6 +2789,15 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura throw new InvalidParameterValueException("Unable to find network offering by id=" + networkOfferingId); } + //For router's public network we use networkRate from guestNetworkOffering + if (vmType != null && vmType == VirtualMachine.Type.DomainRouter && no.getTrafficType() == TrafficType.Public && no.getGuestType() == null) { + List guestOfferings = _networkOfferingDao.listByTrafficTypeAndGuestType(false, TrafficType.Guest, GuestIpType.Virtual); + if (!guestOfferings.isEmpty()) { + //We have one default guest virtual network offering now + no = guestOfferings.get(0); + } + } + Integer networkRate; if (no.getRateMbps() != null) { networkRate = no.getRateMbps(); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 7ac676bc754..b3dfd7e56bd 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -982,7 +982,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag nics.add(vo); NetworkOffering no = _configMgr.getNetworkOffering(config.getNetworkOfferingId()); - Integer networkRate = _configMgr.getNetworkRate(no.getId()); + Integer networkRate = _configMgr.getNetworkRate(no.getId(), vm.getType()); vm.addNic(new NicProfile(vo, network.first(), vo.getBroadcastUri(), vo.getIsolationUri(), networkRate)); } @@ -1075,7 +1075,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag to.setDns2(profile.getDns2()); } - Integer networkRate = _configMgr.getNetworkRate(config.getNetworkOfferingId()); + Integer networkRate = _configMgr.getNetworkRate(config.getNetworkOfferingId(), null); to.setNetworkRateMbps(networkRate); return to; @@ -1196,7 +1196,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkGuru guru = implemented.first(); NetworkVO network = implemented.second(); NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); - Integer networkRate = _configMgr.getNetworkRate(no.getId()); + Integer networkRate = _configMgr.getNetworkRate(no.getId(), vmProfile.getType()); NicProfile profile = null; if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { nic.setState(Nic.State.Reserving); @@ -1246,7 +1246,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag for (NicVO nic : nics) { NetworkVO network = _networksDao.findById(nic.getNetworkId()); NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); - Integer networkRate = _configMgr.getNetworkRate(no.getId()); + Integer networkRate = _configMgr.getNetworkRate(no.getId(), vm.getType()); NetworkGuru guru = _networkGurus.get(network.getGuruName()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate); @@ -1303,7 +1303,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag for (Nic nic : nics) { NetworkVO network = _networksDao.findById(nic.getNetworkId()); NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); - Integer networkRate = _configMgr.getNetworkRate(no.getId()); + Integer networkRate = _configMgr.getNetworkRate(no.getId(), vm.getType()); NetworkGuru guru = _networkGurus.get(network.getGuruName()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate); diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 93e38226b1f..3b854fc36f9 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1417,7 +1417,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //Get network rate - required for IpAssoc Network network = _networkMgr.getNetwork(ipAddr.getNetworkId()); NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); - Integer networkRate = _configMgr.getNetworkRate(no.getId()); + Integer networkRate = _configMgr.getNetworkRate(no.getId(), null); IpAddressTO ip = new IpAddressTO(ipAddr.getAddress().addr(), add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, vmGuestAddress, networkRate); ipsToSend[i++] = ip; From 344d1924a6811689fb51e471eec4349be982e346 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Wed, 30 Mar 2011 19:08:54 -0400 Subject: [PATCH 18/72] bug 8459: add nic hotplug support --- .../computing/LibvirtComputingResource.java | 177 ++++++++++++------ .../computing/LibvirtDomainXMLParser.java | 7 + .../VirtualRoutingResource.java | 40 +++- 3 files changed, 165 insertions(+), 59 deletions(-) diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java index bf559ab5276..5622287359d 100644 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java +++ b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java @@ -134,6 +134,8 @@ import com.cloud.agent.api.check.CheckSshCommand; import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand; import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer; import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand; +import com.cloud.agent.api.routing.IPAssocCommand; +import com.cloud.agent.api.routing.IpAssocAnswer; import com.cloud.agent.api.routing.NetworkElementCommand; import com.cloud.agent.api.storage.CreateAnswer; import com.cloud.agent.api.storage.CreateCommand; @@ -141,6 +143,7 @@ import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer; import com.cloud.agent.api.storage.DestroyCommand; import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer; import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand; +import com.cloud.agent.api.to.IpAddressTO; import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.StorageFilerTO; import com.cloud.agent.api.to.VirtualMachineTO; @@ -160,6 +163,7 @@ import com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef.hostNicType; import com.cloud.agent.resource.computing.LibvirtVMDef.SerialDef; import com.cloud.agent.resource.computing.LibvirtVMDef.TermPolicy; import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource; +import com.cloud.dc.Vlan; import com.cloud.exception.InternalErrorException; import com.cloud.host.Host.Type; import com.cloud.hypervisor.Hypervisor.HypervisorType; @@ -863,7 +867,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return execute((FenceCommand) cmd); } else if (cmd instanceof StartCommand ) { return execute((StartCommand) cmd); - } else if (cmd instanceof NetworkElementCommand) { + } else if (cmd instanceof IPAssocCommand) { + return execute((IPAssocCommand)cmd); + }else if (cmd instanceof NetworkElementCommand) { return _virtRouterResource.executeRequest(cmd); } else if (cmd instanceof CheckSshCommand) { return execute((CheckSshCommand) cmd); @@ -983,6 +989,86 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } } + private String getVlanIdFromBridge(String brName) { + OutputInterpreter.OneLineParser vlanIdParser = new OutputInterpreter.OneLineParser(); + final Script cmd = new Script("/bin/bash", s_logger); + cmd.add("-c"); + cmd.add("vlanid=$(brctl show |grep " + brName + " |awk '{print $4}' | cut -d. -f 2);echo $vlanid"); + if (cmd.execute(vlanIdParser) != null) { + return null; + } + return vlanIdParser.getLine(); + } + + private void VifHotPlug(Connect conn, String vmName, String vlanId, String macAddr) throws InternalErrorException, LibvirtException { + NicTO nicTO = new NicTO(); + nicTO.setMac(macAddr); + nicTO.setType(TrafficType.Public); + if (vlanId == null) { + nicTO.setBroadcastType(BroadcastDomainType.Native); + } else { + nicTO.setBroadcastType(BroadcastDomainType.Vlan); + nicTO.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vlanId)); + } + + InterfaceDef nic = createVif(conn, nicTO, InterfaceDef.nicModel.VIRTIO); + Domain vm = getDomain(conn, vmName); + vm.attachDevice(nic.toString()); + } + + public Answer execute(IPAssocCommand cmd) { + String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); + String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); + String[] results = new String[cmd.getIpAddresses().length]; + Connect conn; + try { + conn = LibvirtConnection.getConnection(); + List nics = getInterfaces(conn, routerName); + Map vlanAllocatedToVM = new HashMap(); + Integer nicPos = 0; + for (InterfaceDef nic : nics) { + if (nic.getBrName().equalsIgnoreCase(_linkLocalBridgeName)) { + vlanAllocatedToVM.put("LinkLocal", nicPos); + } else { + String vlanId = getVlanIdFromBridge(nic.getBrName()); + if (vlanId != null) { + vlanAllocatedToVM.put(vlanId, nicPos); + } else { + vlanAllocatedToVM.put(Vlan.UNTAGGED, nicPos); + } + } + nicPos++; + } + IpAddressTO[] ips = cmd.getIpAddresses(); + int i = 0; + String result = null; + int nicNum = 0; + for (IpAddressTO ip : ips) { + if (!vlanAllocatedToVM.containsKey(ip.getVlanId())) { + /*plug a vif into router*/ + VifHotPlug(conn, routerName, ip.getVlanId(), ip.getVifMacAddress()); + vlanAllocatedToVM.put(ip.getVlanId(), nicPos++); + } + nicNum = vlanAllocatedToVM.get(ip.getVlanId()); + result = _virtRouterResource.assignPublicIpAddress(routerName, routerIp, ip.getPublicIp(), ip.isAdd(), + ip.isFirstIP(), ip.isSourceNat(), + ip.getVlanId(), ip.getVlanGateway(), ip.getVlanNetmask(), + ip.getVifMacAddress(), ip.getGuestIp(), nicNum); + + if (result != null) { + results[i++] = IpAssocAnswer.errorResult; + } else { + results[i++] = ip.getPublicIp() + " - success";; + } + } + return new IpAssocAnswer(cmd, results); + } catch (LibvirtException e) { + return new ManageSnapshotAnswer(cmd, false, e.toString()); + } catch (InternalErrorException e) { + return new ManageSnapshotAnswer(cmd, false, e.toString()); + } + } + protected ManageSnapshotAnswer execute(final ManageSnapshotCommand cmd) { String snapshotName = cmd.getSnapshotName(); String VolPath = cmd.getVolumePath(); @@ -2196,42 +2282,43 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv createVnet(vlanId, nic); return brName; } + + private InterfaceDef createVif(Connect conn, NicTO nic, InterfaceDef.nicModel model) throws InternalErrorException, LibvirtException { + InterfaceDef intf = new InterfaceDef(); - private InterfaceDef createVif(Connect conn, LibvirtVMDef vm, NicTO nic) throws InternalErrorException, LibvirtException { - InterfaceDef intf = new InterfaceDef(); + String vlanId = null; + if (nic.getBroadcastType() == BroadcastDomainType.Vlan) { + URI broadcastUri = nic.getBroadcastUri(); + vlanId = broadcastUri.getHost(); + } - String vlanId = null; - if (nic.getBroadcastType() == BroadcastDomainType.Vlan) { - URI broadcastUri = nic.getBroadcastUri(); - vlanId = broadcastUri.getHost(); - s_logger.debug("vlanId: " + vlanId); - } - InterfaceDef.nicModel model = getGuestNicModel(vm.getGuestOSType()); + if (nic.getType() == TrafficType.Guest) { + if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")){ + String brName = createVlanBr(vlanId, _pifs.first()); + intf.defBridgeNet(brName, null, nic.getMac(), model); + } else { + intf.defBridgeNet(_guestBridgeName, null, nic.getMac(), model); + } + } else if (nic.getType() == TrafficType.Control) { + /*Make sure the network is still there*/ + createControlNetwork(conn); + intf.defBridgeNet(_linkLocalBridgeName, null, nic.getMac(), model); + } else if (nic.getType() == TrafficType.Public) { + if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")) { + String brName = createVlanBr(vlanId, _pifs.second()); + intf.defBridgeNet(brName, null, nic.getMac(), model); + } else { + intf.defBridgeNet(_publicBridgeName, null, nic.getMac(), model); + } + } else if (nic.getType() == TrafficType.Management) { + intf.defBridgeNet(_privBridgeName, null, nic.getMac(), model); + } - if (nic.getType() == TrafficType.Guest) { - if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")){ - String brName = createVlanBr(vlanId, _pifs.first()); - intf.defBridgeNet(brName, null, nic.getMac(), model); - } else { - intf.defBridgeNet(_privBridgeName, null, nic.getMac(), model); - } - } else if (nic.getType() == TrafficType.Control) { - /*Make sure the network is still there*/ - createControlNetwork(conn); - intf.defPrivateNet(_privNwName, null, nic.getMac(), model); - } else if (nic.getType() == TrafficType.Public) { - if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")) { - String brName = createVlanBr(vlanId, _pifs.second()); - intf.defBridgeNet(brName, null, nic.getMac(), model); - } else { - intf.defBridgeNet(_publicBridgeName, null, nic.getMac(), model); - } - } else if (nic.getType() == TrafficType.Management) { - intf.defBridgeNet(_privBridgeName, null, nic.getMac(), model); - } + return intf; + } - vm.getDevices().addDevice(intf); - return intf; + private void createVif(Connect conn, LibvirtVMDef vm, NicTO nic) throws InternalErrorException, LibvirtException { + vm.getDevices().addDevice(createVif(conn, nic, getGuestNicModel(vm.getGuestOSType()))); } @@ -3018,6 +3105,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } private String setVnetBrName(String vnetId) { + if (vnetId.equalsIgnoreCase(Vlan.UNTAGGED)) { + return _guestBridgeName; + } return "cloudVirBr" + vnetId; } private String getVnetIdFromBrName(String vnetBrName) { @@ -3356,28 +3446,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } private void createControlNetwork(Connect conn) throws LibvirtException { - Network vmopsNw = null; - - try { - vmopsNw = conn.networkLookupByName(_privNwName); - } catch (LibvirtException e) { - - } - - if (vmopsNw == null) { - deletExitingLinkLocalRoutTable(_linkLocalBridgeName); - _virtRouterResource.cleanupPrivateNetwork(_privNwName, _linkLocalBridgeName); - LibvirtNetworkDef networkDef = new LibvirtNetworkDef(_privNwName, null, null); - networkDef.defLocalNetwork(_linkLocalBridgeName, false, 0, NetUtils.getLinkLocalGateway(), NetUtils.getLinkLocalNetMask()); - - String nwXML = networkDef.toString(); - s_logger.debug(nwXML); - vmopsNw = conn.networkCreateXML(nwXML); - } + _virtRouterResource.createControlNetwork(_linkLocalBridgeName); } - - private Answer execute(NetworkRulesSystemVmCommand cmd) { boolean success = false; Connect conn; diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtDomainXMLParser.java b/agent/src/com/cloud/agent/resource/computing/LibvirtDomainXMLParser.java index 59a7c99face..2e5e8e1c276 100644 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtDomainXMLParser.java +++ b/agent/src/com/cloud/agent/resource/computing/LibvirtDomainXMLParser.java @@ -240,6 +240,13 @@ public class LibvirtDomainXMLParser { } System.out.println(parser.getVncPort()); System.out.println(parser.getDescription()); + + List test = new ArrayList(1); + test.add("1"); + test.add("2"); + if (test.contains("1")) { + System.out.print("fdf"); + } } } diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java index efeb76225a1..e0056586ab0 100755 --- a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java @@ -274,7 +274,7 @@ public class VirtualRoutingResource implements Manager { for (IpAddressTO ip : ips) { result = assignPublicIpAddress(routerName, routerIp, ip.getPublicIp(), ip.isAdd(), ip.isFirstIP(), ip.isSourceNat(), ip.getVlanId(), ip.getVlanGateway(), ip.getVlanNetmask(), - ip.getVifMacAddress(), ip.getGuestIp()); + ip.getVifMacAddress(), ip.getGuestIp(), 2); if (result != null) { results[i++] = IpAssocAnswer.errorResult; } else { @@ -415,11 +415,11 @@ public class VirtualRoutingResource implements Manager { return command.execute(); } - protected String assignPublicIpAddress(final String vmName, + public String assignPublicIpAddress(final String vmName, final String privateIpAddress, final String publicIpAddress, final boolean add, final boolean firstIP, final boolean sourceNat, final String vlanId, final String vlanGateway, - final String vlanNetmask, final String vifMacAddress, String guestIp){ + final String vlanNetmask, final String vifMacAddress, String guestIp, int nicNum){ final Script command = new Script(_ipassocPath, _timeout, s_logger); command.add( privateIpAddress); @@ -439,13 +439,41 @@ public class VirtualRoutingResource implements Manager { command.add("-l", publicIpAddress); } - //FIXME: figure out the right interface - command.add("-c", "eth2"); + String publicNic = "eth" + nicNum; + command.add("-c", publicNic); return command.execute(); } - + private void deletExitingLinkLocalRoutTable(String linkLocalBr) { + Script command = new Script("/bin/bash", _timeout); + command.add("-c"); + command.add("ip route | grep " + NetUtils.getLinkLocalCIDR()); + OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); + String result = command.execute(parser); + boolean foundLinkLocalBr = false; + if (result == null && parser.getLines() != null) { + String[] lines = parser.getLines().split("\\n"); + for (String line : lines) { + String[] tokens = line.split(" "); + if (!tokens[2].equalsIgnoreCase(linkLocalBr)) { + Script.runSimpleBashScript("ip route del " + NetUtils.getLinkLocalCIDR()); + } else { + foundLinkLocalBr = true; + } + } + } + if (!foundLinkLocalBr) { + Script.runSimpleBashScript("ip route add " + NetUtils.getLinkLocalCIDR() + " dev " + linkLocalBr + " src " + NetUtils.getLinkLocalGateway()); + } + } + + public void createControlNetwork(String privBrName) { + deletExitingLinkLocalRoutTable(privBrName); + if (!isBridgeExists(privBrName)) { + Script.runSimpleBashScript("brctl addbr " + privBrName + "; ifconfig " + privBrName + " up;", _timeout); + } + } private boolean isBridgeExists(String bridgeName) { Script command = new Script("/bin/sh", _timeout); From cf7fd7447a115edc3ca1431cf8b15226946d78ee Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 31 Mar 2011 09:45:57 -0700 Subject: [PATCH 19/72] Bug 9218 - service cloud-management restart OR stop FAILED Resloved: Fixed --- .../rc.d/init.d/cloud-management.in | 24 ++++++++++++++++++- .../rc.d/init.d/cloud-management.in | 24 ++++++++++++++++++- .../rc.d/init.d/cloud-management.in | 24 ++++++++++++++++++- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/client/distro/centos/SYSCONFDIR/rc.d/init.d/cloud-management.in b/client/distro/centos/SYSCONFDIR/rc.d/init.d/cloud-management.in index d61cb7b8088..562b561ab9c 100755 --- a/client/distro/centos/SYSCONFDIR/rc.d/init.d/cloud-management.in +++ b/client/distro/centos/SYSCONFDIR/rc.d/init.d/cloud-management.in @@ -34,7 +34,29 @@ case "$1" in status ${NAME} RETVAL=$? ;; - *) + stop) + SHUTDOWN_WAIT="30" + count="0" + if [ -f /var/run/cloud-management.pid ]; then + pid=`cat /var/run/cloud-management.pid` + kill $pid &>/dev/null + until [ "$(ps --pid $pid | grep -c $pid)" -eq "0" ] || \ + [ "$count" -gt "$SHUTDOWN_WAIT" ] + do + sleep 1 + let count="${count}+1" + done + if [ "$(ps --pid $pid | grep -c $pid)" -eq "0" ]; then + log_success_msg "Stopping Cloud-management" + else + log_failure_msg "Stopping Cloud-management" + fi + else + echo "Cannot find PID file of Cloud-management" + log_failure_msg "Stopping Cloud-management" + fi + ;; + *) . /etc/rc.d/init.d/tomcat6 esac diff --git a/client/distro/fedora/SYSCONFDIR/rc.d/init.d/cloud-management.in b/client/distro/fedora/SYSCONFDIR/rc.d/init.d/cloud-management.in index d61cb7b8088..562b561ab9c 100755 --- a/client/distro/fedora/SYSCONFDIR/rc.d/init.d/cloud-management.in +++ b/client/distro/fedora/SYSCONFDIR/rc.d/init.d/cloud-management.in @@ -34,7 +34,29 @@ case "$1" in status ${NAME} RETVAL=$? ;; - *) + stop) + SHUTDOWN_WAIT="30" + count="0" + if [ -f /var/run/cloud-management.pid ]; then + pid=`cat /var/run/cloud-management.pid` + kill $pid &>/dev/null + until [ "$(ps --pid $pid | grep -c $pid)" -eq "0" ] || \ + [ "$count" -gt "$SHUTDOWN_WAIT" ] + do + sleep 1 + let count="${count}+1" + done + if [ "$(ps --pid $pid | grep -c $pid)" -eq "0" ]; then + log_success_msg "Stopping Cloud-management" + else + log_failure_msg "Stopping Cloud-management" + fi + else + echo "Cannot find PID file of Cloud-management" + log_failure_msg "Stopping Cloud-management" + fi + ;; + *) . /etc/rc.d/init.d/tomcat6 esac diff --git a/client/distro/rhel/SYSCONFDIR/rc.d/init.d/cloud-management.in b/client/distro/rhel/SYSCONFDIR/rc.d/init.d/cloud-management.in index d61cb7b8088..562b561ab9c 100644 --- a/client/distro/rhel/SYSCONFDIR/rc.d/init.d/cloud-management.in +++ b/client/distro/rhel/SYSCONFDIR/rc.d/init.d/cloud-management.in @@ -34,7 +34,29 @@ case "$1" in status ${NAME} RETVAL=$? ;; - *) + stop) + SHUTDOWN_WAIT="30" + count="0" + if [ -f /var/run/cloud-management.pid ]; then + pid=`cat /var/run/cloud-management.pid` + kill $pid &>/dev/null + until [ "$(ps --pid $pid | grep -c $pid)" -eq "0" ] || \ + [ "$count" -gt "$SHUTDOWN_WAIT" ] + do + sleep 1 + let count="${count}+1" + done + if [ "$(ps --pid $pid | grep -c $pid)" -eq "0" ]; then + log_success_msg "Stopping Cloud-management" + else + log_failure_msg "Stopping Cloud-management" + fi + else + echo "Cannot find PID file of Cloud-management" + log_failure_msg "Stopping Cloud-management" + fi + ;; + *) . /etc/rc.d/init.d/tomcat6 esac From db351f8cbad8c06a9af59dec024c7b178b79e769 Mon Sep 17 00:00:00 2001 From: anthony Date: Thu, 31 Mar 2011 13:51:09 -0700 Subject: [PATCH 20/72] bug 9249: use interval type , not snapshot type status 9249: resolved fixed --- server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index 280ddbe0eb2..430fe3ed012 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -1011,7 +1011,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma policy = _snapshotPolicyDao.acquireInLockTable(policy.getId()); policy.setSchedule(cmd.getSchedule()); policy.setTimezone(timezoneId); - policy.setInterval((short) type.ordinal()); + policy.setInterval((short)intvType.ordinal()); policy.setMaxSnaps(cmd.getMaxSnaps()); policy.setActive(true); _snapshotPolicyDao.update(policy.getId(), policy); From 7e7c647dea15441f12ef50c581312c0bb5f12066 Mon Sep 17 00:00:00 2001 From: alena Date: Thu, 31 Mar 2011 15:19:51 -0700 Subject: [PATCH 21/72] bug 9245: save ownerAccountId (instead of callerAccountId) to account_id field in async_job table. We already save caller info to user_id field status 9245: resolved fixed --- server/src/com/cloud/api/ApiServer.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index 52ed597c4c8..f8ce0a295f1 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -408,14 +408,8 @@ public class ApiServer implements HttpRequestHandler { job.setInstanceId((objectId == null) ? asyncCmd.getInstanceId() : objectId); job.setInstanceType(asyncCmd.getInstanceType()); job.setUserId(userId); - if (account != null) { - job.setAccountId(ctx.getCaller().getId()); - } else { - // Just have SYSTEM own the job for now. Users won't be able to see this job, - // but in an admin case (like domain admin) they won't be able to see it anyway - // so no loss of service. - job.setAccountId(1L); - } + job.setAccountId(asyncCmd.getEntityOwnerId()); + job.setCmd(cmdObj.getClass().getName()); job.setCmdInfo(ApiGsonHelper.getBuilder().create().toJson(params)); From 31b22bf806b8d91a2acecd74a37ac3419f57d781 Mon Sep 17 00:00:00 2001 From: will Date: Thu, 31 Mar 2011 16:08:16 -0700 Subject: [PATCH 22/72] bug 9118: Updated snapshot UI to support multiple recurring snapshot policy --- .../classes/resources/messages.properties | 2 + ui/jsp/volume.jsp | 21 +++-- ui/scripts/cloud.core.volume.js | 85 ++++++++++++------- 3 files changed, 70 insertions(+), 38 deletions(-) diff --git a/client/WEB-INF/classes/resources/messages.properties b/client/WEB-INF/classes/resources/messages.properties index 2fdd1e50ea2..b4e3f1d8d5b 100644 --- a/client/WEB-INF/classes/resources/messages.properties +++ b/client/WEB-INF/classes/resources/messages.properties @@ -731,6 +731,8 @@ message.volume.create.template.confirm=Please confirm that you wish to create a message.zone.step.1.desc=Please select a network model for your zone. message.zone.step.2.desc=Please enter the following info to add a new zone message.zone.step.3.desc=Please enter the following info to add a new pod +message.apply.snapshot.policy=You have successfully updated your current snapshot policy. +message.disable.snapshot.policy=You have successfully disabled your current snapshot policy. #Errors error.login=Your username/password does not match our records. diff --git a/ui/jsp/volume.jsp b/ui/jsp/volume.jsp index d7263ffbde6..b34fd9de6e1 100644 --- a/ui/jsp/volume.jsp +++ b/ui/jsp/volume.jsp @@ -26,7 +26,9 @@ dictionary = { 'label.action.delete.snapshot' : '', 'label.action.delete.snapshot.processing' : '', 'message.action.delete.snapshot' : '', - 'message.download.volume' : '' + 'message.download.volume' : '', + 'message.disable.snapshot.policy' : '', + 'message.apply.snapshot.policy' : '' }; @@ -308,12 +310,11 @@ dictionary = {
 :   
+ + + + + : Enabled
@@ -541,6 +542,12 @@ dictionary = {
+ diff --git a/ui/scripts/cloud.core.volume.js b/ui/scripts/cloud.core.volume.js index 5f5cea11826..5d225e5c2dd 100644 --- a/ui/scripts/cloud.core.volume.js +++ b/ui/scripts/cloud.core.volume.js @@ -226,12 +226,16 @@ function afterLoadVolumeJSP() { $("#snapshot_interval").change(function(event) { var thisElement = $(this); var snapshotInterval = thisElement.val(); - var jsonObj = thisElement.data("jsonObj"); + var $snapshotIntervalOption = thisElement.find("#snapshot_interval_"+snapshotInterval); + var jsonObj = $snapshotIntervalOption.data("jsonObj"); var $dialog = $("#dialog_recurring_snapshot"); + if (jsonObj == undefined || jsonObj == null) { + $dialog.find("#policy_enabled").text("Disabled"); + } else { + $dialog.find("#policy_enabled").text("Enabled"); + } + $dialog.find("#info_container").hide(); switch (snapshotInterval) { - case "-1": - $dialog.find("#snapshot_form").hide(); - break; case "0": $dialog.find("#edit_time_colon, #edit_hour_container, #edit_meridiem_container, #edit_day_of_week_container, #edit_day_of_month_container").hide(); $dialog.find("#edit_past_the_hour, #edit_minute_container").show(); @@ -239,6 +243,10 @@ function afterLoadVolumeJSP() { $dialog.find("#edit_minute").val(jsonObj.schedule); $dialog.find("#edit_max").val(jsonObj.maxsnaps); $dialog.find("#edit_timezone").val(jsonObj.timezone); + } else { + $dialog.find("#edit_minute").val(""); + $dialog.find("#edit_max").val(""); + $dialog.find("#edit_timezone").val(""); } $dialog.find("#snapshot_form").show(); break; @@ -266,7 +274,13 @@ function afterLoadVolumeJSP() { $dialog.find("#edit_meridiem").val(meridiem); $dialog.find("#edit_max").val(jsonObj.maxsnaps); $dialog.find("#edit_timezone").val(jsonObj.timezone); - } + } else { + $dialog.find("#edit_minute").val(""); + $dialog.find("#edit_hour").val(""); + $dialog.find("#edit_meridiem").val(""); + $dialog.find("#edit_max").val(""); + $dialog.find("#edit_timezone").val(""); + } $dialog.find("#snapshot_form").show(); break; case "2": @@ -294,6 +308,13 @@ function afterLoadVolumeJSP() { $dialog.find("#edit_day_of_week").val(parts[2]); $dialog.find("#edit_max").val(jsonObj.maxsnaps); $dialog.find("#edit_timezone").val(jsonObj.timezone); + } else { + $dialog.find("#edit_minute").val(""); + $dialog.find("#edit_hour").val(""); + $dialog.find("#edit_meridiem").val(""); + $dialog.find("#edit_day_of_week").val(""); + $dialog.find("#edit_max").val(""); + $dialog.find("#edit_timezone").val(""); } $dialog.find("#snapshot_form").show(); break; @@ -321,6 +342,13 @@ function afterLoadVolumeJSP() { $dialog.find("#edit_day_of_month").val(parts[2]); $dialog.find("#edit_max").val(jsonObj.maxsnaps); $dialog.find("#edit_timezone").val(jsonObj.timezone); + } else { + $dialog.find("#edit_minute").val(""); + $dialog.find("#edit_hour").val(""); + $dialog.find("#edit_meridiem").val(""); + $dialog.find("#edit_day_of_month").val(""); + $dialog.find("#edit_max").val(""); + $dialog.find("#edit_timezone").val(""); } $dialog.find("#snapshot_form").show(); break; @@ -806,12 +834,15 @@ function doRecurringSnapshot($actionLink, $detailsTab, $midmenuItem1) { var items = json.listsnapshotpoliciesresponse.snapshotpolicy; var $snapInterval = dialogBox.find("#snapshot_interval"); if(items!=null && items.length>0) { - var item = items[0]; // We only expect a single policy. - $snapInterval.val(item.intervaltype).data("jsonObj", item); + for (var i = 0; i < items.length; i++) { + var item = items[i]; + $snapInterval.find("#snapshot_interval_"+item.intervaltype).data("jsonObj", item); + } } else { - $snapInterval.val("-1").data("jsonObj", null); + // Maybe use a different message } clearBottomPanel(); + $snapInterval.val("0"); //default to hourly $snapInterval.change(); dialogBox.dialog('option', 'buttons', { @@ -823,23 +854,6 @@ function doRecurringSnapshot($actionLink, $detailsTab, $midmenuItem1) { var intervalType = thisDialog.find("#snapshot_interval").val(); var minute, hour12, hour24, meridiem, dayOfWeek, dayOfWeekString, dayOfMonth, schedule, max, timezone; switch(intervalType) { - case "-1": - var $snapshotInterval = $(this).find("#snapshot_interval"); - var jsonObj = $snapshotInterval.data("jsonObj"); - if(jsonObj != null) { - $.ajax({ - data: createURL("command=deleteSnapshotPolicies&id="+jsonObj.id), - dataType: "json", - success: function(json) { - $snapshotInterval.val("-1"); - }, - error: function(XMLHttpResponse) { - handleError(XMLHttpResponse); - } - }); - } - thisDialog.dialog("close"); - return false; case "0": var isValid = true; isValid &= validateInteger("Keep # of snapshots", bottomPanel.find("#edit_max"), bottomPanel.find("#edit_max_errormsg")); @@ -906,11 +920,16 @@ function doRecurringSnapshot($actionLink, $detailsTab, $midmenuItem1) { break; } var thisLink; + var $snapshotInterval = thisDialog.find("#snapshot_interval"); + var $snapshotIntervalOption = thisDialog.find("#snapshot_interval_"+$snapshotInterval.val()); $.ajax({ data: createURL("command=createSnapshotPolicy&intervaltype="+intervalType+"&schedule="+schedule+"&volumeid="+volumeId+"&maxsnaps="+max+"&timezone="+todb(timezone)), dataType: "json", success: function(json) { - thisDialog.dialog("close"); + $snapshotIntervalOption.data("jsonObj", json.createsnapshotpolicyresponse.snapshotpolicy); + $snapshotInterval.change(); + thisDialog.find("#info").text(dictionary[message.apply.snapshot.policy]); + thisDialog.find("#info_container").show(); }, error: function(XMLHttpResponse) { handleError(XMLHttpResponse); @@ -918,21 +937,25 @@ function doRecurringSnapshot($actionLink, $detailsTab, $midmenuItem1) { }); }, "Disable": function() { - var $snapshotInterval = $(this).find("#snapshot_interval"); - var jsonObj = $snapshotInterval.data("jsonObj"); + var thisDialog = $(this); + var $snapshotInterval = thisDialog.find("#snapshot_interval"); + var $snapshotIntervalOption = thisDialog.find("#snapshot_interval_"+$snapshotInterval.val()); + var jsonObj = $snapshotIntervalOption.data("jsonObj"); if(jsonObj != null) { $.ajax({ data: createURL("command=deleteSnapshotPolicies&id="+jsonObj.id), dataType: "json", - success: function(json) { - $snapshotInterval.val("-1"); + success: function(json) { + $snapshotIntervalOption.data("jsonObj", null); + $snapshotInterval.change(); + thisDialog.find("#info").text(dictionary[message.disable.snapshot.policy]); + thisDialog.find("#info_container").show(); }, error: function(XMLHttpResponse) { handleError(XMLHttpResponse); } }); } - $(this).dialog("close"); }, "Close": function() { $(this).dialog("close"); From b192d1cb766a4f33189c92601107bf66912e94cd Mon Sep 17 00:00:00 2001 From: will Date: Thu, 31 Mar 2011 16:28:13 -0700 Subject: [PATCH 23/72] bug 9118: Updated snapshot UI to support multiple recurring snapshot policy --- client/WEB-INF/classes/resources/messages.properties | 2 +- client/WEB-INF/classes/resources/messages_es.properties | 4 +++- client/WEB-INF/classes/resources/messages_ja.properties | 4 +++- client/WEB-INF/classes/resources/messages_zh_CN.properties | 4 +++- ui/css/main.css | 2 +- ui/scripts/cloud.core.volume.js | 4 ++-- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/client/WEB-INF/classes/resources/messages.properties b/client/WEB-INF/classes/resources/messages.properties index b4e3f1d8d5b..b3729acd472 100644 --- a/client/WEB-INF/classes/resources/messages.properties +++ b/client/WEB-INF/classes/resources/messages.properties @@ -715,7 +715,7 @@ message.number.zones=

# of Zones

message.remove.vpn.access=Please confirm that you want to remove VPN access from the following user. message.restart.mgmt.server=Please restart your management server(s) for your new settings to take effect. message.security.group.usage=(Use Ctrl-click to select all applicable security groups) -message.snapshot.schedule=Your snapshot schedule is currently set to +message.snapshot.schedule=You can setup recurring snapshot schedules by selecting from the available options below and applying your policy preference message.step.1.continue=Please select a template or ISO to continue message.step.1.desc=Please select a template for your new virtual instance. You can also choose to select a blank template from which an ISO image can be installed onto. message.step.2.continue=Please select a service offering to continue diff --git a/client/WEB-INF/classes/resources/messages_es.properties b/client/WEB-INF/classes/resources/messages_es.properties index 310912df12d..fa11c3d2ac7 100644 --- a/client/WEB-INF/classes/resources/messages_es.properties +++ b/client/WEB-INF/classes/resources/messages_es.properties @@ -715,7 +715,7 @@ message.number.zones =

# de Zonas

message.remove.vpn.access = Por favor, confirme que desea eliminar el acceso VPN desde el siguiente usuario message.restart.mgmt.server = Por favor, reinicie el servidor de administración (s) para la nueva configuración surta efecto. message.security.group.usage = (Uso pulse Ctrl para seleccionar todos los grupos de seguridad se aplica) -message.snapshot.schedule = Su programación de instantáneas está configurado para +message.snapshot.schedule = Puede horarios de configuración recurrente instantáneas mediante la selección de las opciones disponibles a continuación y la aplicación de su preferencia política message.step.1.continue = Por favor seleccione una plantilla o ISO para continuar message.step.1.desc = Por favor seleccione una plantilla para la instancia virtual. También puede optar por seleccionar una plantilla en blanco desde el que puede ser una imagen ISO instalado en. message.step.2.continue = Por favor seleccione una oferta de servicio para continuar @@ -731,6 +731,8 @@ message.volume.create.template.confirm = Por favor, confirme que desea crear una message.zone.step.1.desc = Por favor seleccione un modelo de red para su zona. message.zone.step.2.desc = Por favor ingrese los siguientes datos para agregar una nueva zona message.zone.step.3.desc = Por favor ingrese los siguientes datos para agregar una vaina nueva +message.apply.snapshot.policy = Ha actualizado su política instantánea actual. +message.disable.snapshot.policy = Ha desactivado su política instantánea actual. #Errors diff --git a/client/WEB-INF/classes/resources/messages_ja.properties b/client/WEB-INF/classes/resources/messages_ja.properties index ffb2aea15bc..56cad27f631 100644 --- a/client/WEB-INF/classes/resources/messages_ja.properties +++ b/client/WEB-INF/classes/resources/messages_ja.properties @@ -715,7 +715,7 @@ message.number.zones=

# -- Zone

message.remove.vpn.access=次のユーザからのVPNアクセスを削除してもよろしいですか? message.restart.mgmt.server=新しい設定を有効にするために、管理サーバ(複数可)を再起動してください。 message.security.group.usage=全ての該当するセキュリティグループを選択するには、 Ctrlキーを押しながらクリックしてください。 -message.snapshot.schedule =スナップショットスケジュールは現在設定されています。 +message.snapshot.schedule =あなたは以下のオプションから選択し、適用、ポリシー設定をすることにより、セットアップ定期的なスナップショットをスケジュールすることができます message.step.1.continue=テンプレートまたはISOイメージを選択して続行してください message.step.1.desc=新しい仮想インスタンス用のテンプレートを選択してください。ISOイメージがインストールされているブランクのテンプレートを選択することもできます。 message.step.2.continue=サービスオファリングを選択して続行してください @@ -731,6 +731,8 @@ message.volume.create.template.confirm=このディスクボリューム用の message.zone.step.1.desc=Zoneのネットワークモデルを選択してください。 message.zone.step.2.desc=新しいZoneを追加するために、次の情報を入力してください。 message.zone.step.3.desc=新しいPodを追加するために、次の情報を入力してください。 +message.apply.snapshot.policy=あなたが正常に現在のスナップショットのポリシーを更新している。 +message.disable.snapshot.policy=あなたが正常に現在のスナップショットのポリシーを無効にしている。 #Errors error.login=ユーザ名/パスワードが記録と一致しません diff --git a/client/WEB-INF/classes/resources/messages_zh_CN.properties b/client/WEB-INF/classes/resources/messages_zh_CN.properties index 825103c79a6..7496f20fbf3 100644 --- a/client/WEB-INF/classes/resources/messages_zh_CN.properties +++ b/client/WEB-INF/classes/resources/messages_zh_CN.properties @@ -715,7 +715,7 @@ message.number.zones =

# of Zones

message.remove.vpn.access =请确认您要删除来自下列用户VPN接入 message.restart.mgmt.server =请重新启动管理服务器,以使您的新设置生效。 message.security.group.usage =(使用 Ctrl-click 来选者所有可应用的安全组) -message.snapshot.schedule =您的快照的日程目前设定为 +message.snapshot.schedule =你可以从下面选择可用的选项和应用的政策优惠设置重复快照计划 message.step.1.continue =请选择一个模板或光盘以继续 message.step.1.desc =请为您的新虚拟机选择一个模板。您也可以选择选择一个空白模板,一个光盘可以被安装到这个模板之上。 message.step.2.continue =请选择服务Offering以继续 @@ -731,6 +731,8 @@ message.volume.create.template.confirm =请确认您希望从该卷上创建模 message.zone.step.1.desc =请为您的Zone,选择网络模型。 message.zone.step.2.desc =请输入下面的信息以添加一个新的Zone message.zone.step.3.desc =请输入下面的信息以添加一个新的Pod +message.apply.snapshot.policy=您已成功更新您的当前快照的政策。 +message.disable.snapshot.policy=你已经成功停用了您的当前快照的政策。 #Errors error.login=您的用户名/密码与我们的记录不匹配。 diff --git a/ui/css/main.css b/ui/css/main.css index ffa49be2a48..5bffeb8969b 100644 --- a/ui/css/main.css +++ b/ui/css/main.css @@ -5372,7 +5372,7 @@ a:hover.search_button { .dialog_snapshotleft_actions a:link {width:auto; height:auto; margin:0 5px 0 0; padding:0; color:#2c8bbc; text-decoration:none; font-size:11px;} .dialog_snapshotleft_actions a:visited {width:auto; height:auto; margin:0 5px 0 0; padding:0; color:#2c8bbc; text-decoration:none; font-size:11px;} .dialog_snapshotleft_actions a:hover {width:auto; height:auto; margin:0 5px 0 0; padding:0; color:#2c8bbc; text-decoration:underline; font-size:11px;} -.dialog_snapshotright {width:400px; height:150px; float:left; margin:0; padding:15px 0 0 0; } +.dialog_snapshotright {width:400px; height:150px; float:left; margin:0; padding:30px 0 0 0; } .dialog_snapshotright_infotext{width:360px; height:160px; float:left; display:none; margin:0; padding:0; font-size:15px; font-family:Arial, Helvetica, sans-serif; font-size:normal; text-align:left; margin:10px; color:#333;} .dialog_snapshots_editcontent {width:350px; height:auto; float:left; margin:0; padding:0;} .dialog_snapshots_editcontent_title {width:280px; height:auto; float:left; margin:0; padding:0;} diff --git a/ui/scripts/cloud.core.volume.js b/ui/scripts/cloud.core.volume.js index 5d225e5c2dd..bb77b89b5e4 100644 --- a/ui/scripts/cloud.core.volume.js +++ b/ui/scripts/cloud.core.volume.js @@ -928,7 +928,7 @@ function doRecurringSnapshot($actionLink, $detailsTab, $midmenuItem1) { success: function(json) { $snapshotIntervalOption.data("jsonObj", json.createsnapshotpolicyresponse.snapshotpolicy); $snapshotInterval.change(); - thisDialog.find("#info").text(dictionary[message.apply.snapshot.policy]); + thisDialog.find("#info").text(dictionary["message.apply.snapshot.policy"]); thisDialog.find("#info_container").show(); }, error: function(XMLHttpResponse) { @@ -948,7 +948,7 @@ function doRecurringSnapshot($actionLink, $detailsTab, $midmenuItem1) { success: function(json) { $snapshotIntervalOption.data("jsonObj", null); $snapshotInterval.change(); - thisDialog.find("#info").text(dictionary[message.disable.snapshot.policy]); + thisDialog.find("#info").text(dictionary["message.disable.snapshot.policy"]); thisDialog.find("#info_container").show(); }, error: function(XMLHttpResponse) { From 703537d2223fcffc525c0cdb22dfadfce34855e1 Mon Sep 17 00:00:00 2001 From: alena Date: Thu, 31 Mar 2011 16:28:52 -0700 Subject: [PATCH 24/72] bug 9248: generate events on service/diskOffering create/update/delete status 9248: resolved fixed --- .../ConfigurationManagerImpl.java | 3528 +++++++++-------- 1 file changed, 1785 insertions(+), 1743 deletions(-) diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 6529ea963b7..3d67d10ae22 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -134,62 +134,86 @@ import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.SecondaryStorageVmDao; import com.cloud.vm.dao.VMInstanceDao; -@Local(value={ConfigurationManager.class, ConfigurationService.class}) +@Local(value = { ConfigurationManager.class, ConfigurationService.class }) public class ConfigurationManagerImpl implements ConfigurationManager, ConfigurationService { public static final Logger s_logger = Logger.getLogger(ConfigurationManagerImpl.class.getName()); - String _name; - @Inject ConfigurationDao _configDao; - @Inject HostPodDao _podDao; - @Inject AccountVlanMapDao _accountVlanMapDao; - @Inject PodVlanMapDao _podVlanMapDao; - @Inject DataCenterDao _zoneDao; - @Inject DomainRouterDao _domrDao; - @Inject DomainDao _domainDao; - @Inject ServiceOfferingDao _serviceOfferingDao; - @Inject DiskOfferingDao _diskOfferingDao; - @Inject NetworkOfferingDao _networkOfferingDao; - @Inject VlanDao _vlanDao; - @Inject IPAddressDao _publicIpAddressDao; - @Inject DataCenterIpAddressDao _privateIpAddressDao; - @Inject VMInstanceDao _vmInstanceDao; - @Inject AccountDao _accountDao; - @Inject EventDao _eventDao; - @Inject UserDao _userDao; - @Inject NetworkDao _networkDao; - @Inject ConsoleProxyDao _consoleDao; - @Inject SecondaryStorageVmDao _secStorageDao; - @Inject AccountManager _accountMgr; - @Inject NetworkManager _networkMgr; - @Inject ClusterDao _clusterDao; - @Inject AlertManager _alertMgr; - @Inject(adapter=SecurityChecker.class) + String _name; + @Inject + ConfigurationDao _configDao; + @Inject + HostPodDao _podDao; + @Inject + AccountVlanMapDao _accountVlanMapDao; + @Inject + PodVlanMapDao _podVlanMapDao; + @Inject + DataCenterDao _zoneDao; + @Inject + DomainRouterDao _domrDao; + @Inject + DomainDao _domainDao; + @Inject + ServiceOfferingDao _serviceOfferingDao; + @Inject + DiskOfferingDao _diskOfferingDao; + @Inject + NetworkOfferingDao _networkOfferingDao; + @Inject + VlanDao _vlanDao; + @Inject + IPAddressDao _publicIpAddressDao; + @Inject + DataCenterIpAddressDao _privateIpAddressDao; + @Inject + VMInstanceDao _vmInstanceDao; + @Inject + AccountDao _accountDao; + @Inject + EventDao _eventDao; + @Inject + UserDao _userDao; + @Inject + NetworkDao _networkDao; + @Inject + ConsoleProxyDao _consoleDao; + @Inject + SecondaryStorageVmDao _secStorageDao; + @Inject + AccountManager _accountMgr; + @Inject + NetworkManager _networkMgr; + @Inject + ClusterDao _clusterDao; + @Inject + AlertManager _alertMgr; + @Inject(adapter = SecurityChecker.class) Adapters _secChecker; - - //FIXME - why don't we have interface for DataCenterLinkLocalIpAddressDao? - protected static final DataCenterLinkLocalIpAddressDaoImpl _LinkLocalIpAllocDao = ComponentLocator.inject(DataCenterLinkLocalIpAddressDaoImpl.class); + + // FIXME - why don't we have interface for DataCenterLinkLocalIpAddressDao? + protected static final DataCenterLinkLocalIpAddressDaoImpl _LinkLocalIpAllocDao = ComponentLocator.inject(DataCenterLinkLocalIpAddressDaoImpl.class); private int _maxVolumeSizeInGb; private long _defaultPageSize; protected Set configValuesForValidation; - + @Override public boolean configure(final String name, final Map params) throws ConfigurationException { - _name = name; + _name = name; String maxVolumeSizeInGbString = _configDao.getValue("storage.max.volume.size"); _maxVolumeSizeInGb = NumbersUtil.parseInt(maxVolumeSizeInGbString, 2000); - + String defaultPageSizeString = _configDao.getValue("default.page.size"); _defaultPageSize = NumbersUtil.parseLong(defaultPageSizeString, 500L); - populateConfigValuesForValidationSet(); - return true; + populateConfigValuesForValidationSet(); + return true; } - - private void populateConfigValuesForValidationSet(){ - configValuesForValidation = new HashSet(); - configValuesForValidation.add("account.cleanup.interval"); + + private void populateConfigValuesForValidationSet() { + configValuesForValidation = new HashSet(); + configValuesForValidation.add("account.cleanup.interval"); configValuesForValidation.add("alert.wait"); configValuesForValidation.add("consoleproxy.capacityscan.interval"); configValuesForValidation.add("consoleproxy.loadscan.interval"); @@ -204,38 +228,37 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura configValuesForValidation.add("stop.retry.interval"); configValuesForValidation.add("storage.stats.interval"); configValuesForValidation.add("storage.cleanup.interval"); - configValuesForValidation.add("wait"); + configValuesForValidation.add("wait"); configValuesForValidation.add("xen.heartbeat.interval"); } - + @Override public String getName() { return _name; } - + @Override public boolean start() { - // TODO : this may not be a good place to do integrity check here, we put it here as we need _alertMgr to be properly configured - // before we can use it - - // As it is so common for people to forget about configuring management.network.cidr, - String mgtCidr = _configDao.getValue(Config.ManagementNetwork.key()); - if(mgtCidr == null || mgtCidr.trim().isEmpty()) { - String[] localCidrs = NetUtils.getLocalCidrs(); - if(localCidrs.length > 0) { - s_logger.warn("Management network CIDR is not configured originally. Set it default to " + localCidrs[0]); - - _alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), - "Management network CIDR is not configured originally. Set it default to " + localCidrs[0], ""); - _configDao.update(Config.ManagementNetwork.key(), localCidrs[0]); - } else { - s_logger.warn("Management network CIDR is not properly configured and we are not able to find a default setting"); - _alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), - "Management network CIDR is not properly configured and we are not able to find a default setting", ""); - } - } - + // TODO : this may not be a good place to do integrity check here, we put it here as we need _alertMgr to be properly + // configured + // before we can use it + + // As it is so common for people to forget about configuring management.network.cidr, + String mgtCidr = _configDao.getValue(Config.ManagementNetwork.key()); + if (mgtCidr == null || mgtCidr.trim().isEmpty()) { + String[] localCidrs = NetUtils.getLocalCidrs(); + if (localCidrs.length > 0) { + s_logger.warn("Management network CIDR is not configured originally. Set it default to " + localCidrs[0]); + + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), "Management network CIDR is not configured originally. Set it default to " + localCidrs[0], ""); + _configDao.update(Config.ManagementNetwork.key(), localCidrs[0]); + } else { + s_logger.warn("Management network CIDR is not properly configured and we are not able to find a default setting"); + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), "Management network CIDR is not properly configured and we are not able to find a default setting", ""); + } + } + return true; } @@ -243,493 +266,488 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura public boolean stop() { return true; } - + @Override - public void updateConfiguration(long userId, String name, String value) { - if (value != null && (value.trim().isEmpty() || value.equals("null"))) { - value = null; - } - - String validationMsg = validateConfigurationValue(name, value); - - if (validationMsg != null) { - s_logger.error("Invalid configuration option, name: " + name + ", value:" + value); - throw new InvalidParameterValueException(validationMsg); - } - - if (!_configDao.update(name, value)) { - s_logger.error("Failed to update configuration option, name: " + name + ", value:" + value); - throw new CloudRuntimeException("Failed to update configuration value. Please contact Cloud Support."); - } - + public void updateConfiguration(long userId, String name, String value) { + if (value != null && (value.trim().isEmpty() || value.equals("null"))) { + value = null; + } + + String validationMsg = validateConfigurationValue(name, value); + + if (validationMsg != null) { + s_logger.error("Invalid configuration option, name: " + name + ", value:" + value); + throw new InvalidParameterValueException(validationMsg); + } + + if (!_configDao.update(name, value)) { + s_logger.error("Failed to update configuration option, name: " + name + ", value:" + value); + throw new CloudRuntimeException("Failed to update configuration value. Please contact Cloud Support."); + } + } - + @Override - public Configuration updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException{ - Long userId = UserContext.current().getCallerUserId(); - String name = cmd.getCfgName(); - String value = cmd.getValue(); - - //check if config value exists - if (_configDao.findByName(name) == null) { + public Configuration updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException { + Long userId = UserContext.current().getCallerUserId(); + String name = cmd.getCfgName(); + String value = cmd.getValue(); + + // check if config value exists + if (_configDao.findByName(name) == null) { throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist"); } - - if (value == null) { + + if (value == null) { return _configDao.findByName(name); } - - updateConfiguration (userId, name, value); - if (_configDao.getValue(name).equalsIgnoreCase(value)) { + + updateConfiguration(userId, name, value); + if (_configDao.getValue(name).equalsIgnoreCase(value)) { return _configDao.findByName(name); } else { throw new CloudRuntimeException("Unable to update configuration parameter " + name); } } - - + private String validateConfigurationValue(String name, String value) throws InvalidParameterValueException { - if (value == null) { - return null; - } - - Config c = Config.getConfig(name); - value = value.trim(); - - if (c == null) { - s_logger.error("Missing configuration variable " + name + " in configuration table"); - return "Invalid configuration variable."; - } - - Class type = c.getType(); - if (type.equals(Boolean.class)) { - if (!(value.equals("true") || value.equals("false"))) { - s_logger.error("Configuration variable " + name + " is expecting true or false in stead of " + value); - return "Please enter either 'true' or 'false'."; - } - return null; - } - - if(type.equals(Integer.class) && configValuesForValidation.contains(name)) { - try { - int val = Integer.parseInt(value); - if(val <= 0){ - throw new InvalidParameterValueException("Please enter a positive value for the configuration parameter:"+name); - } - } catch (NumberFormatException e) { - s_logger.error("There was an error trying to parse the integer value for:"+name); - throw new InvalidParameterValueException("There was an error trying to parse the integer value for:"+name); - } - } - - String range = c.getRange(); - if (range == null) { - return null; - } - - if(type.equals(String.class)) { - if (range.equals("privateip")) - { - try { - if (!NetUtils.isSiteLocalAddress(value)) { - s_logger.error("privateip range " + value - + " is not a site local address for configuration variable " + name); - return "Please enter a site local IP address."; - } - } catch (NullPointerException e) - { - s_logger.error("Error parsing ip address for " + name); - throw new InvalidParameterValueException("Error parsing ip address"); - } - } else if (range.equals("netmask")) { - if (!NetUtils.isValidNetmask(value)) { - s_logger.error("netmask " + value + " is not a valid net mask for configuration variable " + name); - return "Please enter a valid netmask."; - } - } else if (range.equals("hypervisorList")) { - String [] hypervisors = value.split(","); - if (hypervisors == null) { - return "Please enter hypervisor list, seperated by comma"; - } - for (String hypervisor : hypervisors) { - if (HypervisorType.getType(hypervisor) == HypervisorType.Any || - HypervisorType.getType(hypervisor) == HypervisorType.None) { - return "Please enter valid hypervisor type"; - } - } - } else { - String [] options = range.split(","); - for( String option : options) { - if( option.trim().equals(value) ) { - return null; - } - } - s_logger.error("configuration value for " + name + " is invalid"); - return "Please enter : " + range; - - } - }else if(type.equals(Integer.class)) { - String [] options = range.split("-"); - if( options.length != 2 ) { - String msg = "configuration range " + range + " for " + name + " is invalid"; - s_logger.error(msg); - return msg; - } - int min = Integer.parseInt(options[0]); - int max = Integer.parseInt(options[1]); - int val = Integer.parseInt(value); - if( val < min || val > max ) { - s_logger.error("configuration value for " + name + " is invalid"); - return "Please enter : " + range; - } - } - return null; + if (value == null) { + return null; + } + + Config c = Config.getConfig(name); + value = value.trim(); + + if (c == null) { + s_logger.error("Missing configuration variable " + name + " in configuration table"); + return "Invalid configuration variable."; + } + + Class type = c.getType(); + if (type.equals(Boolean.class)) { + if (!(value.equals("true") || value.equals("false"))) { + s_logger.error("Configuration variable " + name + " is expecting true or false in stead of " + value); + return "Please enter either 'true' or 'false'."; + } + return null; + } + + if (type.equals(Integer.class) && configValuesForValidation.contains(name)) { + try { + int val = Integer.parseInt(value); + if (val <= 0) { + throw new InvalidParameterValueException("Please enter a positive value for the configuration parameter:" + name); + } + } catch (NumberFormatException e) { + s_logger.error("There was an error trying to parse the integer value for:" + name); + throw new InvalidParameterValueException("There was an error trying to parse the integer value for:" + name); + } + } + + String range = c.getRange(); + if (range == null) { + return null; + } + + if (type.equals(String.class)) { + if (range.equals("privateip")) { + try { + if (!NetUtils.isSiteLocalAddress(value)) { + s_logger.error("privateip range " + value + " is not a site local address for configuration variable " + name); + return "Please enter a site local IP address."; + } + } catch (NullPointerException e) { + s_logger.error("Error parsing ip address for " + name); + throw new InvalidParameterValueException("Error parsing ip address"); + } + } else if (range.equals("netmask")) { + if (!NetUtils.isValidNetmask(value)) { + s_logger.error("netmask " + value + " is not a valid net mask for configuration variable " + name); + return "Please enter a valid netmask."; + } + } else if (range.equals("hypervisorList")) { + String[] hypervisors = value.split(","); + if (hypervisors == null) { + return "Please enter hypervisor list, seperated by comma"; + } + for (String hypervisor : hypervisors) { + if (HypervisorType.getType(hypervisor) == HypervisorType.Any || HypervisorType.getType(hypervisor) == HypervisorType.None) { + return "Please enter valid hypervisor type"; + } + } + } else { + String[] options = range.split(","); + for (String option : options) { + if (option.trim().equals(value)) { + return null; + } + } + s_logger.error("configuration value for " + name + " is invalid"); + return "Please enter : " + range; + + } + } else if (type.equals(Integer.class)) { + String[] options = range.split("-"); + if (options.length != 2) { + String msg = "configuration range " + range + " for " + name + " is invalid"; + s_logger.error(msg); + return msg; + } + int min = Integer.parseInt(options[0]); + int max = Integer.parseInt(options[1]); + int val = Integer.parseInt(value); + if (val < min || val > max) { + s_logger.error("configuration value for " + name + " is invalid"); + return "Please enter : " + range; + } + } + return null; } - + private boolean podHasAllocatedPrivateIPs(long podId) { - HostPodVO pod = _podDao.findById(podId); - int count = _privateIpAddressDao.countIPs(podId, pod.getDataCenterId(), true); - return (count > 0); + HostPodVO pod = _podDao.findById(podId); + int count = _privateIpAddressDao.countIPs(podId, pod.getDataCenterId(), true); + return (count > 0); } - + @DB - protected void checkIfPodIsDeletable(long podId) { - List> tablesToCheck = new ArrayList>(); - - HostPodVO pod = _podDao.findById(podId); - - // Check if there are allocated private IP addresses in the pod - if (_privateIpAddressDao.countIPs(podId, pod.getDataCenterId(), true) != 0) { - throw new CloudRuntimeException("There are private IP addresses allocated for this pod"); - } + protected void checkIfPodIsDeletable(long podId) { + List> tablesToCheck = new ArrayList>(); - List volumes = new ArrayList(); - volumes.add(0, "volumes"); - volumes.add(1, "pod_id"); - volumes.add(2, "there are storage volumes for this pod"); - tablesToCheck.add(volumes); - - List host = new ArrayList(); - host.add(0, "host"); - host.add(1, "pod_id"); - host.add(2, "there are servers running in this pod"); - tablesToCheck.add(host); - - List vmInstance = new ArrayList(); - vmInstance.add(0, "vm_instance"); - vmInstance.add(1, "pod_id"); - vmInstance.add(2, "there are virtual machines running in this pod"); - tablesToCheck.add(vmInstance); - - List cluster = new ArrayList(); - cluster.add(0, "cluster"); - cluster.add(1, "pod_id"); - cluster.add(2, "there are clusters in this pod"); + HostPodVO pod = _podDao.findById(podId); + + // Check if there are allocated private IP addresses in the pod + if (_privateIpAddressDao.countIPs(podId, pod.getDataCenterId(), true) != 0) { + throw new CloudRuntimeException("There are private IP addresses allocated for this pod"); + } + + List volumes = new ArrayList(); + volumes.add(0, "volumes"); + volumes.add(1, "pod_id"); + volumes.add(2, "there are storage volumes for this pod"); + tablesToCheck.add(volumes); + + List host = new ArrayList(); + host.add(0, "host"); + host.add(1, "pod_id"); + host.add(2, "there are servers running in this pod"); + tablesToCheck.add(host); + + List vmInstance = new ArrayList(); + vmInstance.add(0, "vm_instance"); + vmInstance.add(1, "pod_id"); + vmInstance.add(2, "there are virtual machines running in this pod"); + tablesToCheck.add(vmInstance); + + List cluster = new ArrayList(); + cluster.add(0, "cluster"); + cluster.add(1, "pod_id"); + cluster.add(2, "there are clusters in this pod"); tablesToCheck.add(cluster); - - for (List table : tablesToCheck) { - String tableName = table.get(0); - String column = table.get(1); - String errorMsg = table.get(2); - - String dbName; - if (tableName.equals("event") || tableName.equals("cloud_usage") || tableName.equals("usage_vm_instance") || - tableName.equals("usage_ip_address") || tableName.equals("usage_network") || tableName.equals("usage_job") || - tableName.equals("account") || tableName.equals("user_statistics")) { - dbName = "cloud_usage"; - } else { - dbName = "cloud"; - } - - String selectSql = "SELECT * FROM `" + dbName + "`.`" + tableName + "` WHERE " + column + " = ?"; - if(tableName.equals("host")){ - selectSql += " and removed IS NULL"; - } - + for (List table : tablesToCheck) { + String tableName = table.get(0); + String column = table.get(1); + String errorMsg = table.get(2); + + String dbName; + if (tableName.equals("event") || tableName.equals("cloud_usage") || tableName.equals("usage_vm_instance") || tableName.equals("usage_ip_address") || tableName.equals("usage_network") || tableName.equals("usage_job") + || tableName.equals("account") || tableName.equals("user_statistics")) { + dbName = "cloud_usage"; + } else { + dbName = "cloud"; + } + + String selectSql = "SELECT * FROM `" + dbName + "`.`" + tableName + "` WHERE " + column + " = ?"; + + if (tableName.equals("host")) { + selectSql += " and removed IS NULL"; + } + Transaction txn = Transaction.currentTxn(); - try { + try { PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql); stmt.setLong(1, podId); ResultSet rs = stmt.executeQuery(); if (rs != null && rs.next()) { - throw new CloudRuntimeException("The pod cannot be deleted because " + errorMsg); + throw new CloudRuntimeException("The pod cannot be deleted because " + errorMsg); } } catch (SQLException ex) { throw new CloudRuntimeException("The Management Server failed to detect if pod is deletable. Please contact Cloud Support."); } - } + } } - - private void checkPodAttributes(long podId, String podName, long zoneId, String gateway, String cidr, String startIp, String endIp, String allocationStateStr, boolean checkForDuplicates) throws InvalidParameterValueException { - if (checkForDuplicates) { - // Check if the pod already exists - if (validPod(podName, zoneId)) { - throw new InvalidParameterValueException("A pod with name: " + podName + " already exists in zone " + zoneId + ". Please specify a different pod name. "); - } - } - - String cidrAddress; - long cidrSize; - // Get the individual cidrAddress and cidrSize values, if the CIDR is valid. If it's not valid, return an error. - if (NetUtils.isValidCIDR(cidr)) { - cidrAddress = getCidrAddress(cidr); - cidrSize = getCidrSize(cidr); - } else { - throw new InvalidParameterValueException("Please enter a valid CIDR for pod: " + podName); - } - - // Check if the IP range is valid - if (startIp != null || endIp != null) { - checkIpRange(startIp, endIp, cidrAddress, cidrSize); - } - - // Check if the gateway is a valid IP address - if (!NetUtils.isValidIp(gateway)) { - throw new InvalidParameterValueException("The gateway is not a valid IP address."); - } - - // Check if the gateway is in the CIDR subnet - if (!NetUtils.getCidrSubNet(gateway, cidrSize).equalsIgnoreCase(NetUtils.getCidrSubNet(cidrAddress, cidrSize))) { - throw new InvalidParameterValueException("The gateway is not in the CIDR subnet."); - } - - //Don't allow gateway to overlap with start/endIp - if (NetUtils.ipRangesOverlap(startIp, endIp, gateway, gateway)) { - throw new InvalidParameterValueException("The gateway shouldn't overlap start/end ip addresses"); - } - String checkPodCIDRs = _configDao.getValue("check.pod.cidrs"); - if (checkPodCIDRs == null || checkPodCIDRs.trim().isEmpty() || Boolean.parseBoolean(checkPodCIDRs)) { - // Check if the CIDR conflicts with the Guest Network or other pods - HashMap> currentPodCidrSubnets = _podDao.getCurrentPodCidrSubnets(zoneId, podId); - List newCidrPair = new ArrayList(); - newCidrPair.add(0, cidrAddress); - newCidrPair.add(1, new Long(cidrSize)); - currentPodCidrSubnets.put(new Long(-1), newCidrPair); - checkPodCidrSubnets(zoneId, currentPodCidrSubnets); - - //Prevent using the same CIDR for POD and virtual networking - List vlans = _vlanDao.listByZoneAndType(zoneId, VlanType.VirtualNetwork); - for (VlanVO vlan : vlans) { - String vlanCidr = NetUtils.ipAndNetMaskToCidr(vlan.getVlanGateway(), vlan.getVlanNetmask()); - String[] cidrPairVlan = vlanCidr.split("\\/"); - String[] vlanIpRange = NetUtils.getIpRangeFromCidr(cidrPairVlan[0], Long.valueOf(cidrPairVlan[1])); - - String[] cidrPairPod = cidr.split("\\/"); - String[] podIpRange = NetUtils.getIpRangeFromCidr(cidrPairPod[0], Long.valueOf(cidrPairPod[1])); - - if (NetUtils.ipRangesOverlap(vlanIpRange[0], vlanIpRange[1], podIpRange[0], podIpRange[1])) { - throw new InvalidParameterValueException("Pod's cidr conflicts with cidr of virtual network in zone id=" + zoneId); - } - } - } - - Grouping.AllocationState allocationState = null; - if (allocationStateStr != null && !allocationStateStr.isEmpty()) { - try{ - allocationState = Grouping.AllocationState.valueOf(allocationStateStr); - }catch(IllegalArgumentException ex){ - throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr + "' to a supported state"); - } - } + private void checkPodAttributes(long podId, String podName, long zoneId, String gateway, String cidr, String startIp, String endIp, String allocationStateStr, boolean checkForDuplicates) throws InvalidParameterValueException { + if (checkForDuplicates) { + // Check if the pod already exists + if (validPod(podName, zoneId)) { + throw new InvalidParameterValueException("A pod with name: " + podName + " already exists in zone " + zoneId + ". Please specify a different pod name. "); + } + } + + String cidrAddress; + long cidrSize; + // Get the individual cidrAddress and cidrSize values, if the CIDR is valid. If it's not valid, return an error. + if (NetUtils.isValidCIDR(cidr)) { + cidrAddress = getCidrAddress(cidr); + cidrSize = getCidrSize(cidr); + } else { + throw new InvalidParameterValueException("Please enter a valid CIDR for pod: " + podName); + } + + // Check if the IP range is valid + if (startIp != null || endIp != null) { + checkIpRange(startIp, endIp, cidrAddress, cidrSize); + } + + // Check if the gateway is a valid IP address + if (!NetUtils.isValidIp(gateway)) { + throw new InvalidParameterValueException("The gateway is not a valid IP address."); + } + + // Check if the gateway is in the CIDR subnet + if (!NetUtils.getCidrSubNet(gateway, cidrSize).equalsIgnoreCase(NetUtils.getCidrSubNet(cidrAddress, cidrSize))) { + throw new InvalidParameterValueException("The gateway is not in the CIDR subnet."); + } + + // Don't allow gateway to overlap with start/endIp + if (NetUtils.ipRangesOverlap(startIp, endIp, gateway, gateway)) { + throw new InvalidParameterValueException("The gateway shouldn't overlap start/end ip addresses"); + } + + String checkPodCIDRs = _configDao.getValue("check.pod.cidrs"); + if (checkPodCIDRs == null || checkPodCIDRs.trim().isEmpty() || Boolean.parseBoolean(checkPodCIDRs)) { + // Check if the CIDR conflicts with the Guest Network or other pods + HashMap> currentPodCidrSubnets = _podDao.getCurrentPodCidrSubnets(zoneId, podId); + List newCidrPair = new ArrayList(); + newCidrPair.add(0, cidrAddress); + newCidrPair.add(1, new Long(cidrSize)); + currentPodCidrSubnets.put(new Long(-1), newCidrPair); + checkPodCidrSubnets(zoneId, currentPodCidrSubnets); + + // Prevent using the same CIDR for POD and virtual networking + List vlans = _vlanDao.listByZoneAndType(zoneId, VlanType.VirtualNetwork); + for (VlanVO vlan : vlans) { + String vlanCidr = NetUtils.ipAndNetMaskToCidr(vlan.getVlanGateway(), vlan.getVlanNetmask()); + String[] cidrPairVlan = vlanCidr.split("\\/"); + String[] vlanIpRange = NetUtils.getIpRangeFromCidr(cidrPairVlan[0], Long.valueOf(cidrPairVlan[1])); + + String[] cidrPairPod = cidr.split("\\/"); + String[] podIpRange = NetUtils.getIpRangeFromCidr(cidrPairPod[0], Long.valueOf(cidrPairPod[1])); + + if (NetUtils.ipRangesOverlap(vlanIpRange[0], vlanIpRange[1], podIpRange[0], podIpRange[1])) { + throw new InvalidParameterValueException("Pod's cidr conflicts with cidr of virtual network in zone id=" + zoneId); + } + } + } + + Grouping.AllocationState allocationState = null; + if (allocationStateStr != null && !allocationStateStr.isEmpty()) { + try { + allocationState = Grouping.AllocationState.valueOf(allocationStateStr); + } catch (IllegalArgumentException ex) { + throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr + "' to a supported state"); + } + } } - + @Override @DB - public boolean deletePod(DeletePodCmd cmd) { - Long podId = cmd.getId(); - - // Make sure the pod exists - if (!validPod(podId)) { - throw new InvalidParameterValueException("A pod with ID: " + podId + " does not exist."); - } + public boolean deletePod(DeletePodCmd cmd) { + Long podId = cmd.getId(); - checkIfPodIsDeletable(podId); + // Make sure the pod exists + if (!validPod(podId)) { + throw new InvalidParameterValueException("A pod with ID: " + podId + " does not exist."); + } - HostPodVO pod = _podDao.findById(podId); - - //Delete private ip addresses for the pod if there are any - List privateIps = _privateIpAddressDao.listByPodIdDcId(Long.valueOf(podId), pod.getDataCenterId()); - if (privateIps != null && privateIps.size() != 0) { - if (!(_privateIpAddressDao.deleteIpAddressByPod(podId))) { - throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId); - } - } - - //Delete link local ip addresses for the pod - List localIps = _LinkLocalIpAllocDao.listByPodIdDcId(podId, pod.getDataCenterId()); - if (!localIps.isEmpty()) { - if (!(_LinkLocalIpAllocDao.deleteIpAddressByPod(podId))) { - throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId); - } - } - - //Delete vlans associated with the pod - List vlans = _networkMgr.listPodVlans(podId); - if (vlans != null && !vlans.isEmpty()) { - for (Vlan vlan: vlans) { + checkIfPodIsDeletable(podId); + + HostPodVO pod = _podDao.findById(podId); + + // Delete private ip addresses for the pod if there are any + List privateIps = _privateIpAddressDao.listByPodIdDcId(Long.valueOf(podId), pod.getDataCenterId()); + if (privateIps != null && privateIps.size() != 0) { + if (!(_privateIpAddressDao.deleteIpAddressByPod(podId))) { + throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId); + } + } + + // Delete link local ip addresses for the pod + List localIps = _LinkLocalIpAllocDao.listByPodIdDcId(podId, pod.getDataCenterId()); + if (!localIps.isEmpty()) { + if (!(_LinkLocalIpAllocDao.deleteIpAddressByPod(podId))) { + throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId); + } + } + + // Delete vlans associated with the pod + List vlans = _networkMgr.listPodVlans(podId); + if (vlans != null && !vlans.isEmpty()) { + for (Vlan vlan : vlans) { _vlanDao.remove(vlan.getId()); } - } - - //Delete the pod - if (!(_podDao.expunge(podId))) { - throw new CloudRuntimeException("Failed to delete pod " + podId); - } - - return true; + } + + // Delete the pod + if (!(_podDao.expunge(podId))) { + throw new CloudRuntimeException("Failed to delete pod " + podId); + } + + return true; } - + @Override - public Pod editPod(UpdatePodCmd cmd){ + public Pod editPod(UpdatePodCmd cmd) { return editPod(cmd.getId(), cmd.getPodName(), cmd.getStartIp(), cmd.getEndIp(), cmd.getGateway(), cmd.getNetmask(), cmd.getAllocationState()); } - @Override @DB - public Pod editPod(long id, String name, String startIp, String endIp, String gateway, String netmask, String allocationStateStr){ - - //verify parameters - HostPodVO pod = _podDao.findById(id);; + @Override + @DB + public Pod editPod(long id, String name, String startIp, String endIp, String gateway, String netmask, String allocationStateStr) { + + // verify parameters + HostPodVO pod = _podDao.findById(id); + ; if (pod == null) { throw new InvalidParameterValueException("Unable to find pod by id " + id); } - - String[] existingPodIpRange = pod.getDescription().split("-"); + + String[] existingPodIpRange = pod.getDescription().split("-"); String[] leftRangeToAdd = null; String[] rightRangeToAdd = null; boolean allowToDownsize = false; - - // If the gateway, CIDR, private IP range is being changed, check if the pod has allocated private IP addresses - if (podHasAllocatedPrivateIPs(id)) { - - if (netmask != null) { + + // If the gateway, CIDR, private IP range is being changed, check if the pod has allocated private IP addresses + if (podHasAllocatedPrivateIPs(id)) { + + if (netmask != null) { long newCidr = NetUtils.getCidrSize(netmask); long oldCidr = pod.getCidrSize(); - + if (newCidr > oldCidr) { throw new CloudRuntimeException("The specified pod has allocated private IP addresses, so its IP address range can be extended only"); } } - - if (startIp != null && !startIp.equals(existingPodIpRange[0])) { - if (NetUtils.ipRangesOverlap(startIp, null, existingPodIpRange[0], existingPodIpRange[1])) { - throw new CloudRuntimeException("The specified pod has allocated private IP addresses, so its IP address range can be extended only"); - } else { - leftRangeToAdd = new String[2]; - long endIpForUpdate = NetUtils.ip2Long(existingPodIpRange[0]) - 1; - leftRangeToAdd[0] = startIp; - leftRangeToAdd[1] = NetUtils.long2Ip(endIpForUpdate); - } - } - - if (endIp != null && !endIp.equals(existingPodIpRange[1])) { - if (NetUtils.ipRangesOverlap(endIp, endIp, existingPodIpRange[0], existingPodIpRange[1])) { + + if (startIp != null && !startIp.equals(existingPodIpRange[0])) { + if (NetUtils.ipRangesOverlap(startIp, null, existingPodIpRange[0], existingPodIpRange[1])) { + throw new CloudRuntimeException("The specified pod has allocated private IP addresses, so its IP address range can be extended only"); + } else { + leftRangeToAdd = new String[2]; + long endIpForUpdate = NetUtils.ip2Long(existingPodIpRange[0]) - 1; + leftRangeToAdd[0] = startIp; + leftRangeToAdd[1] = NetUtils.long2Ip(endIpForUpdate); + } + } + + if (endIp != null && !endIp.equals(existingPodIpRange[1])) { + if (NetUtils.ipRangesOverlap(endIp, endIp, existingPodIpRange[0], existingPodIpRange[1])) { throw new CloudRuntimeException("The specified pod has allocated private IP addresses, so its IP address range can be extended only"); } else { rightRangeToAdd = new String[2]; - long startIpForUpdate = NetUtils.ip2Long(existingPodIpRange[1]) + 1; + long startIpForUpdate = NetUtils.ip2Long(existingPodIpRange[1]) + 1; rightRangeToAdd[0] = NetUtils.long2Ip(startIpForUpdate); rightRangeToAdd[1] = endIp; } - } + } - } else { - allowToDownsize = true; - } - - if (gateway == null) { - gateway = pod.getGateway(); - } - - if (netmask == null) { + } else { + allowToDownsize = true; + } + + if (gateway == null) { + gateway = pod.getGateway(); + } + + if (netmask == null) { netmask = NetUtils.getCidrNetmask(pod.getCidrSize()); } - - String oldPodName = pod.getName(); - if (name == null) { - name = oldPodName; - } - - if (gateway == null) { - gateway = pod.getGateway(); - } - - if (startIp == null) { - startIp = existingPodIpRange[0]; - } - - if (endIp == null) { - endIp = existingPodIpRange[1]; - } - - if(allocationStateStr == null){ - allocationStateStr = pod.getAllocationState().toString(); - } - //Verify pod's attributes - String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask); - boolean checkForDuplicates = !oldPodName.equals(name); - checkPodAttributes(id, name, pod.getDataCenterId(), gateway, cidr, startIp, endIp, allocationStateStr, checkForDuplicates); - - Transaction txn = Transaction.currentTxn(); - try { - txn.start(); - long zoneId = pod.getDataCenterId(); - - if (!allowToDownsize) { - if (leftRangeToAdd != null) { - _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), leftRangeToAdd[0], leftRangeToAdd[1]); - } - - if (rightRangeToAdd != null) { - _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), rightRangeToAdd[0], rightRangeToAdd[1]); - } - - } else { - //delete the old range - _zoneDao.deletePrivateIpAddressByPod(pod.getId()); - - //add the new one - if (startIp == null) { - startIp = existingPodIpRange[0]; - } - - if (endIp == null) { - endIp = existingPodIpRange[1]; - } - - _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), startIp, endIp); - } - - - pod.setName(name); - pod.setDataCenterId(zoneId); - pod.setGateway(gateway); - pod.setCidrAddress(getCidrAddress(cidr)); - pod.setCidrSize(getCidrSize(cidr)); - - String ipRange = startIp + "-" + endIp; - pod.setDescription(ipRange); - Grouping.AllocationState allocationState = null; - if (allocationStateStr != null && !allocationStateStr.isEmpty()) { - allocationState = Grouping.AllocationState.valueOf(allocationStateStr); - pod.setAllocationState(allocationState); - } - - _podDao.update(id, pod); - - txn.commit(); - } catch(Exception e) { - s_logger.error("Unable to edit pod due to " + e.getMessage(), e); - throw new CloudRuntimeException("Failed to edit pod. Please contact Cloud Support."); - } - - return pod; + String oldPodName = pod.getName(); + if (name == null) { + name = oldPodName; + } + + if (gateway == null) { + gateway = pod.getGateway(); + } + + if (startIp == null) { + startIp = existingPodIpRange[0]; + } + + if (endIp == null) { + endIp = existingPodIpRange[1]; + } + + if (allocationStateStr == null) { + allocationStateStr = pod.getAllocationState().toString(); + } + + // Verify pod's attributes + String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask); + boolean checkForDuplicates = !oldPodName.equals(name); + checkPodAttributes(id, name, pod.getDataCenterId(), gateway, cidr, startIp, endIp, allocationStateStr, checkForDuplicates); + + Transaction txn = Transaction.currentTxn(); + try { + txn.start(); + long zoneId = pod.getDataCenterId(); + + if (!allowToDownsize) { + if (leftRangeToAdd != null) { + _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), leftRangeToAdd[0], leftRangeToAdd[1]); + } + + if (rightRangeToAdd != null) { + _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), rightRangeToAdd[0], rightRangeToAdd[1]); + } + + } else { + // delete the old range + _zoneDao.deletePrivateIpAddressByPod(pod.getId()); + + // add the new one + if (startIp == null) { + startIp = existingPodIpRange[0]; + } + + if (endIp == null) { + endIp = existingPodIpRange[1]; + } + + _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), startIp, endIp); + } + + pod.setName(name); + pod.setDataCenterId(zoneId); + pod.setGateway(gateway); + pod.setCidrAddress(getCidrAddress(cidr)); + pod.setCidrSize(getCidrSize(cidr)); + + String ipRange = startIp + "-" + endIp; + pod.setDescription(ipRange); + Grouping.AllocationState allocationState = null; + if (allocationStateStr != null && !allocationStateStr.isEmpty()) { + allocationState = Grouping.AllocationState.valueOf(allocationStateStr); + pod.setAllocationState(allocationState); + } + + _podDao.update(id, pod); + + txn.commit(); + } catch (Exception e) { + s_logger.error("Unable to edit pod due to " + e.getMessage(), e); + throw new CloudRuntimeException("Failed to edit pod. Please contact Cloud Support."); + } + + return pod; } @Override - public Pod createPod(CreatePodCmd cmd) { + public Pod createPod(CreatePodCmd cmd) { String endIp = cmd.getEndIp(); String gateway = cmd.getGateway(); String name = cmd.getPodName(); @@ -739,459 +757,471 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask); Long userId = UserContext.current().getCallerUserId(); String allocationState = cmd.getAllocationState(); - - if(allocationState == null){ - allocationState = Grouping.AllocationState.Enabled.toString(); + + if (allocationState == null) { + allocationState = Grouping.AllocationState.Enabled.toString(); } return createPod(userId.longValue(), name, zoneId, gateway, cidr, startIp, endIp, allocationState); } - @Override @DB - public HostPodVO createPod(long userId, String podName, long zoneId, String gateway, String cidr, String startIp, String endIp, String allocationStateStr) { - + @Override + @DB + public HostPodVO createPod(long userId, String podName, long zoneId, String gateway, String cidr, String startIp, String endIp, String allocationStateStr) { + // Check if the zone is valid if (!validZone(zoneId)) { throw new InvalidParameterValueException("Please specify a valid zone."); } - + // Check if zone is disabled - DataCenterVO zone = _zoneDao.findById(zoneId); - Account account = UserContext.current().getCaller(); - if(Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())){ - throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: "+ zoneId ); - } - + DataCenterVO zone = _zoneDao.findById(zoneId); + Account account = UserContext.current().getCaller(); + if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) { + throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId); + } + String cidrAddress = getCidrAddress(cidr); int cidrSize = getCidrSize(cidr); - - //endIp is an optional parameter; if not specified - default it to the end ip of the pod's cidr + + // endIp is an optional parameter; if not specified - default it to the end ip of the pod's cidr if (startIp != null) { if (endIp == null) { endIp = NetUtils.getIpRangeEndIpFromCidr(cidrAddress, cidrSize); } } - - //Validate new pod settings + + // Validate new pod settings checkPodAttributes(-1, podName, zoneId, gateway, cidr, startIp, endIp, allocationStateStr, true); - - // Create the new pod in the database - String ipRange; - if (startIp != null) { - ipRange = startIp + "-" + endIp; - } else { - throw new InvalidParameterValueException("Start ip is required parameter"); - } - - HostPodVO pod = new HostPodVO(podName, zoneId, gateway, cidrAddress, cidrSize, ipRange); - Grouping.AllocationState allocationState = null; - if (allocationStateStr != null && !allocationStateStr.isEmpty()) { - allocationState = Grouping.AllocationState.valueOf(allocationStateStr); - pod.setAllocationState(allocationState); - } + // Create the new pod in the database + String ipRange; + if (startIp != null) { + ipRange = startIp + "-" + endIp; + } else { + throw new InvalidParameterValueException("Start ip is required parameter"); + } - Transaction txn = Transaction.currentTxn(); - txn.start(); - - pod = _podDao.persist(pod); - - if (startIp != null) { - _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), startIp, endIp); - } - - String[] linkLocalIpRanges = getLinkLocalIPRange(); - if (linkLocalIpRanges != null) { - _zoneDao.addLinkLocalIpAddress(zoneId, pod.getId(), linkLocalIpRanges[0], linkLocalIpRanges[1]); - } + HostPodVO pod = new HostPodVO(podName, zoneId, gateway, cidrAddress, cidrSize, ipRange); - txn.commit(); - - return pod; + Grouping.AllocationState allocationState = null; + if (allocationStateStr != null && !allocationStateStr.isEmpty()) { + allocationState = Grouping.AllocationState.valueOf(allocationStateStr); + pod.setAllocationState(allocationState); + } + + Transaction txn = Transaction.currentTxn(); + txn.start(); + + pod = _podDao.persist(pod); + + if (startIp != null) { + _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), startIp, endIp); + } + + String[] linkLocalIpRanges = getLinkLocalIPRange(); + if (linkLocalIpRanges != null) { + _zoneDao.addLinkLocalIpAddress(zoneId, pod.getId(), linkLocalIpRanges[0], linkLocalIpRanges[1]); + } + + txn.commit(); + + return pod; } - + private boolean zoneHasVMs(long zoneId) { - List vmInstances = _vmInstanceDao.listByZoneId(zoneId); - return !vmInstances.isEmpty(); + List vmInstances = _vmInstanceDao.listByZoneId(zoneId); + return !vmInstances.isEmpty(); } - - private boolean zoneHasAllocatedVnets(long zoneId) { - return !_zoneDao.listAllocatedVnets(zoneId).isEmpty(); - } - - @DB - protected void checkIfZoneIsDeletable(long zoneId) { - List> tablesToCheck = new ArrayList>(); - - List host = new ArrayList(); - host.add(0, "host"); - host.add(1, "data_center_id"); - host.add(2, "there are servers running in this zone"); - tablesToCheck.add(host); - - List hostPodRef = new ArrayList(); - hostPodRef.add(0, "host_pod_ref"); - hostPodRef.add(1, "data_center_id"); - hostPodRef.add(2, "there are pods in this zone"); - tablesToCheck.add(hostPodRef); - - List privateIP = new ArrayList(); - privateIP.add(0, "op_dc_ip_address_alloc"); - privateIP.add(1, "data_center_id"); - privateIP.add(2, "there are private IP addresses allocated for this zone"); - tablesToCheck.add(privateIP); - - List publicIP = new ArrayList(); - publicIP.add(0, "user_ip_address"); - publicIP.add(1, "data_center_id"); - publicIP.add(2, "there are public IP addresses allocated for this zone"); - tablesToCheck.add(publicIP); - - List vmInstance = new ArrayList(); - vmInstance.add(0, "vm_instance"); - vmInstance.add(1, "data_center_id"); - vmInstance.add(2, "there are virtual machines running in this zone"); - tablesToCheck.add(vmInstance); - - List volumes = new ArrayList(); - volumes.add(0, "volumes"); - volumes.add(1, "data_center_id"); - volumes.add(2, "there are storage volumes for this zone"); - tablesToCheck.add(volumes); - - List vnet = new ArrayList(); - vnet.add(0, "op_dc_vnet_alloc"); - vnet.add(1, "data_center_id"); - vnet.add(2, "there are allocated vnets for this zone"); - tablesToCheck.add(vnet); - for (List table : tablesToCheck) { - String tableName = table.get(0); - String column = table.get(1); - String errorMsg = table.get(2); - - String dbName = "cloud"; - - String selectSql = "SELECT * FROM `" + dbName + "`.`" + tableName + "` WHERE " + column + " = ?"; - - if (tableName.equals("op_dc_vnet_alloc")) { - selectSql += " AND taken IS NOT NULL"; - } - - if(tableName.equals("user_ip_address")){ - selectSql += " AND state!='Free'"; - } - - if (tableName.equals("op_dc_ip_address_alloc")) { - selectSql += " AND taken IS NOT NULL"; - } - + private boolean zoneHasAllocatedVnets(long zoneId) { + return !_zoneDao.listAllocatedVnets(zoneId).isEmpty(); + } + + @DB + protected void checkIfZoneIsDeletable(long zoneId) { + List> tablesToCheck = new ArrayList>(); + + List host = new ArrayList(); + host.add(0, "host"); + host.add(1, "data_center_id"); + host.add(2, "there are servers running in this zone"); + tablesToCheck.add(host); + + List hostPodRef = new ArrayList(); + hostPodRef.add(0, "host_pod_ref"); + hostPodRef.add(1, "data_center_id"); + hostPodRef.add(2, "there are pods in this zone"); + tablesToCheck.add(hostPodRef); + + List privateIP = new ArrayList(); + privateIP.add(0, "op_dc_ip_address_alloc"); + privateIP.add(1, "data_center_id"); + privateIP.add(2, "there are private IP addresses allocated for this zone"); + tablesToCheck.add(privateIP); + + List publicIP = new ArrayList(); + publicIP.add(0, "user_ip_address"); + publicIP.add(1, "data_center_id"); + publicIP.add(2, "there are public IP addresses allocated for this zone"); + tablesToCheck.add(publicIP); + + List vmInstance = new ArrayList(); + vmInstance.add(0, "vm_instance"); + vmInstance.add(1, "data_center_id"); + vmInstance.add(2, "there are virtual machines running in this zone"); + tablesToCheck.add(vmInstance); + + List volumes = new ArrayList(); + volumes.add(0, "volumes"); + volumes.add(1, "data_center_id"); + volumes.add(2, "there are storage volumes for this zone"); + tablesToCheck.add(volumes); + + List vnet = new ArrayList(); + vnet.add(0, "op_dc_vnet_alloc"); + vnet.add(1, "data_center_id"); + vnet.add(2, "there are allocated vnets for this zone"); + tablesToCheck.add(vnet); + + for (List table : tablesToCheck) { + String tableName = table.get(0); + String column = table.get(1); + String errorMsg = table.get(2); + + String dbName = "cloud"; + + String selectSql = "SELECT * FROM `" + dbName + "`.`" + tableName + "` WHERE " + column + " = ?"; + + if (tableName.equals("op_dc_vnet_alloc")) { + selectSql += " AND taken IS NOT NULL"; + } + + if (tableName.equals("user_ip_address")) { + selectSql += " AND state!='Free'"; + } + + if (tableName.equals("op_dc_ip_address_alloc")) { + selectSql += " AND taken IS NOT NULL"; + } + Transaction txn = Transaction.currentTxn(); - try { + try { PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql); stmt.setLong(1, zoneId); ResultSet rs = stmt.executeQuery(); if (rs != null && rs.next()) { - throw new CloudRuntimeException("The zone is not deletable because " + errorMsg); + throw new CloudRuntimeException("The zone is not deletable because " + errorMsg); } } catch (SQLException ex) { - throw new CloudRuntimeException("The Management Server failed to detect if zone is deletable. Please contact Cloud Support."); + throw new CloudRuntimeException("The Management Server failed to detect if zone is deletable. Please contact Cloud Support."); } - } - + } + } - + private void checkZoneParameters(String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, boolean checkForDuplicates, Long domainId, String allocationStateStr) throws InvalidParameterValueException { - if (checkForDuplicates) { - // Check if a zone with the specified name already exists - if (validZone(zoneName)) { - throw new InvalidParameterValueException("A zone with that name already exists. Please specify a unique zone name."); - } - } - - //check if valid domain - if(domainId != null){ - DomainVO domain = _domainDao.findById(domainId); - - if(domain == null) { + if (checkForDuplicates) { + // Check if a zone with the specified name already exists + if (validZone(zoneName)) { + throw new InvalidParameterValueException("A zone with that name already exists. Please specify a unique zone name."); + } + } + + // check if valid domain + if (domainId != null) { + DomainVO domain = _domainDao.findById(domainId); + + if (domain == null) { throw new InvalidParameterValueException("Please specify a valid domain id"); } - } - - // Check IP validity for DNS addresses - // Empty strings is a valid input -- hence the length check - if (dns1 != null && dns1.length() > 0 && !NetUtils.isValidIp(dns1)) { - throw new InvalidParameterValueException("Please enter a valid IP address for DNS1"); - } - - if (dns2 != null && dns2.length() > 0 && !NetUtils.isValidIp(dns2)) { - throw new InvalidParameterValueException("Please enter a valid IP address for DNS2"); - } - - if ((internalDns1 != null && internalDns1.length() > 0 && !NetUtils.isValidIp(internalDns1))) { - throw new InvalidParameterValueException("Please enter a valid IP address for internal DNS1"); - } - - if (internalDns2 != null && internalDns2.length() > 0 && !NetUtils.isValidIp(internalDns2)) { - throw new InvalidParameterValueException("Please enter a valid IP address for internal DNS2"); - } - - Grouping.AllocationState allocationState = null; - if (allocationStateStr != null && !allocationStateStr.isEmpty()) { - try{ - allocationState = Grouping.AllocationState.valueOf(allocationStateStr); - }catch(IllegalArgumentException ex){ - throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr + "' to a supported state"); - } - } + } + + // Check IP validity for DNS addresses + // Empty strings is a valid input -- hence the length check + if (dns1 != null && dns1.length() > 0 && !NetUtils.isValidIp(dns1)) { + throw new InvalidParameterValueException("Please enter a valid IP address for DNS1"); + } + + if (dns2 != null && dns2.length() > 0 && !NetUtils.isValidIp(dns2)) { + throw new InvalidParameterValueException("Please enter a valid IP address for DNS2"); + } + + if ((internalDns1 != null && internalDns1.length() > 0 && !NetUtils.isValidIp(internalDns1))) { + throw new InvalidParameterValueException("Please enter a valid IP address for internal DNS1"); + } + + if (internalDns2 != null && internalDns2.length() > 0 && !NetUtils.isValidIp(internalDns2)) { + throw new InvalidParameterValueException("Please enter a valid IP address for internal DNS2"); + } + + Grouping.AllocationState allocationState = null; + if (allocationStateStr != null && !allocationStateStr.isEmpty()) { + try { + allocationState = Grouping.AllocationState.valueOf(allocationStateStr); + } catch (IllegalArgumentException ex) { + throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationStateStr + "' to a supported state"); + } + } } - + private void checkIpRange(String startIp, String endIp, String cidrAddress, long cidrSize) throws InvalidParameterValueException { - if (!NetUtils.isValidIp(startIp)) { - throw new InvalidParameterValueException("The start address of the IP range is not a valid IP address."); - } - - if (endIp != null && !NetUtils.isValidIp(endIp)) { - throw new InvalidParameterValueException("The end address of the IP range is not a valid IP address."); - } - - if (!NetUtils.getCidrSubNet(startIp, cidrSize).equalsIgnoreCase(NetUtils.getCidrSubNet(cidrAddress, cidrSize))) { - throw new InvalidParameterValueException("The start address of the IP range is not in the CIDR subnet."); - } - - if (endIp != null && !NetUtils.getCidrSubNet(endIp, cidrSize).equalsIgnoreCase(NetUtils.getCidrSubNet(cidrAddress, cidrSize))) { - throw new InvalidParameterValueException("The end address of the IP range is not in the CIDR subnet."); - } - - if (endIp != null && NetUtils.ip2Long(startIp) > NetUtils.ip2Long(endIp)) { - throw new InvalidParameterValueException("The start IP address must have a lower value than the end IP address."); - } - + if (!NetUtils.isValidIp(startIp)) { + throw new InvalidParameterValueException("The start address of the IP range is not a valid IP address."); + } + + if (endIp != null && !NetUtils.isValidIp(endIp)) { + throw new InvalidParameterValueException("The end address of the IP range is not a valid IP address."); + } + + if (!NetUtils.getCidrSubNet(startIp, cidrSize).equalsIgnoreCase(NetUtils.getCidrSubNet(cidrAddress, cidrSize))) { + throw new InvalidParameterValueException("The start address of the IP range is not in the CIDR subnet."); + } + + if (endIp != null && !NetUtils.getCidrSubNet(endIp, cidrSize).equalsIgnoreCase(NetUtils.getCidrSubNet(cidrAddress, cidrSize))) { + throw new InvalidParameterValueException("The end address of the IP range is not in the CIDR subnet."); + } + + if (endIp != null && NetUtils.ip2Long(startIp) > NetUtils.ip2Long(endIp)) { + throw new InvalidParameterValueException("The start IP address must have a lower value than the end IP address."); + } + } - - @Override @DB + + @Override + @DB public boolean deleteZone(DeleteZoneCmd cmd) { - + Transaction txn = Transaction.currentTxn(); boolean success = false; - - Long userId = UserContext.current().getCallerUserId(); - Long zoneId = cmd.getId(); - - if (userId == null) { - userId = Long.valueOf(User.UID_SYSTEM); - } - - // Make sure the zone exists - if (!validZone(zoneId)) { - throw new InvalidParameterValueException("A zone with ID: " + zoneId + " does not exist."); - } - - checkIfZoneIsDeletable(zoneId); - - txn.start(); - - // Delete vNet + + Long userId = UserContext.current().getCallerUserId(); + Long zoneId = cmd.getId(); + + if (userId == null) { + userId = Long.valueOf(User.UID_SYSTEM); + } + + // Make sure the zone exists + if (!validZone(zoneId)) { + throw new InvalidParameterValueException("A zone with ID: " + zoneId + " does not exist."); + } + + checkIfZoneIsDeletable(zoneId); + + txn.start(); + + // Delete vNet _zoneDao.deleteVnet(zoneId); - - //delete vlans for this zone + + // delete vlans for this zone List vlans = _vlanDao.listByZone(zoneId); - for(VlanVO vlan : vlans) { + for (VlanVO vlan : vlans) { _vlanDao.remove(vlan.getId()); } - - //Delete networks + + // Delete networks List networks = _networkDao.listByZoneIncludingRemoved(zoneId); if (networks != null && !networks.isEmpty()) { for (NetworkVO network : networks) { _networkDao.expunge(network.getId()); } } - + success = _zoneDao.expunge(zoneId); - - txn.commit(); - + + txn.commit(); + return success; - + } - + @Override public DataCenter editZone(UpdateZoneCmd cmd) { - //Parameter validation as from execute() method in V1 - Long zoneId = cmd.getId(); - String zoneName = cmd.getZoneName(); - String dns1 = cmd.getDns1(); - String dns2 = cmd.getDns2(); - String internalDns1 = cmd.getInternalDns1(); - String internalDns2 = cmd.getInternalDns2(); - String vnetRange = cmd.getVlan(); - String guestCidr = cmd.getGuestCidrAddress(); - Long userId = UserContext.current().getCallerUserId(); - int startVnetRange = 0; - int stopVnetRange = 0; - Boolean isPublic = cmd.isPublic(); - String allocationStateStr = cmd.getAllocationState(); - - if (userId == null) { + // Parameter validation as from execute() method in V1 + Long zoneId = cmd.getId(); + String zoneName = cmd.getZoneName(); + String dns1 = cmd.getDns1(); + String dns2 = cmd.getDns2(); + String internalDns1 = cmd.getInternalDns1(); + String internalDns2 = cmd.getInternalDns2(); + String vnetRange = cmd.getVlan(); + String guestCidr = cmd.getGuestCidrAddress(); + Long userId = UserContext.current().getCallerUserId(); + int startVnetRange = 0; + int stopVnetRange = 0; + Boolean isPublic = cmd.isPublic(); + String allocationStateStr = cmd.getAllocationState(); + + if (userId == null) { userId = Long.valueOf(User.UID_SYSTEM); } - DataCenterVO zone = _zoneDao.findById(zoneId); - if (zone == null) { - throw new InvalidParameterValueException("unable to find zone by id " + zoneId); - } - - if (zoneName == null) { - zoneName = zone.getName(); - } - - //if zone is of Basic type, don't allow to add vnet range and cidr - if (zone.getNetworkType() == NetworkType.Basic) { - if (vnetRange != null) { - throw new InvalidParameterValueException("Can't add vnet range for the zone that supports " + zone.getNetworkType() + " network"); - } else if (guestCidr != null) { - throw new InvalidParameterValueException("Can't add cidr for the zone that supports " + zone.getNetworkType() + " network"); - } - } - - if ((guestCidr != null) && !NetUtils.validateGuestCidr(guestCidr)) { - throw new InvalidParameterValueException("Please enter a valid guest cidr"); - } + DataCenterVO zone = _zoneDao.findById(zoneId); + if (zone == null) { + throw new InvalidParameterValueException("unable to find zone by id " + zoneId); + } - // Make sure the zone exists - if (!validZone(zoneId)) { - throw new InvalidParameterValueException("A zone with ID: " + zoneId + " does not exist."); - } + if (zoneName == null) { + zoneName = zone.getName(); + } - // If the Vnet range is being changed, make sure there are no allocated VNets - if (vnetRange != null) { - if (zoneHasAllocatedVnets(zoneId)) { - throw new CloudRuntimeException("The vlan range is not editable because there are allocated vlans."); - } - - String[] startStopRange = new String[2]; - startStopRange = vnetRange.split("-"); - - if(startStopRange.length == 1) { - throw new InvalidParameterValueException("Please provide valid vnet range between 0-4096"); - } - - if(startStopRange[0] == null || startStopRange[1] == null) { - throw new InvalidParameterValueException("Please provide valid vnet range between 0-4096"); - } - - try { - startVnetRange = Integer.parseInt(startStopRange[0]); - stopVnetRange = Integer.parseInt(startStopRange[1]); - } catch (NumberFormatException e) { - s_logger.warn("Unable to parse vnet range:",e); - throw new InvalidParameterValueException("Please provide valid vnet range between 0-4096"); - } - - if(startVnetRange < 0 || stopVnetRange > 4096) { - throw new InvalidParameterValueException("Vnet range has to be between 0-4096"); - } - - if(startVnetRange > stopVnetRange) { - throw new InvalidParameterValueException("Vnet range has to be between 0-4096 and start range should be lesser than or equal to stop range"); - } - } + // if zone is of Basic type, don't allow to add vnet range and cidr + if (zone.getNetworkType() == NetworkType.Basic) { + if (vnetRange != null) { + throw new InvalidParameterValueException("Can't add vnet range for the zone that supports " + zone.getNetworkType() + " network"); + } else if (guestCidr != null) { + throw new InvalidParameterValueException("Can't add cidr for the zone that supports " + zone.getNetworkType() + " network"); + } + } - String oldZoneName = zone.getName(); - - if (zoneName == null) { - zoneName = oldZoneName; - } - - boolean dnsUpdate = false; - - if(dns1 != null || dns2 != null){ - dnsUpdate = true; - } - - if (dns1 == null) { - dns1 = zone.getDns1(); - } - - if (dns2 == null) { - dns2 = zone.getDns2(); - } - - if(internalDns1 == null) - { - internalDns1 = zone.getInternalDns1(); - } + if ((guestCidr != null) && !NetUtils.validateGuestCidr(guestCidr)) { + throw new InvalidParameterValueException("Please enter a valid guest cidr"); + } - if(guestCidr == null) { + // Make sure the zone exists + if (!validZone(zoneId)) { + throw new InvalidParameterValueException("A zone with ID: " + zoneId + " does not exist."); + } + + // If the Vnet range is being changed, make sure there are no allocated VNets + if (vnetRange != null) { + if (zoneHasAllocatedVnets(zoneId)) { + throw new CloudRuntimeException("The vlan range is not editable because there are allocated vlans."); + } + + String[] startStopRange = new String[2]; + startStopRange = vnetRange.split("-"); + + if (startStopRange.length == 1) { + throw new InvalidParameterValueException("Please provide valid vnet range between 0-4096"); + } + + if (startStopRange[0] == null || startStopRange[1] == null) { + throw new InvalidParameterValueException("Please provide valid vnet range between 0-4096"); + } + + try { + startVnetRange = Integer.parseInt(startStopRange[0]); + stopVnetRange = Integer.parseInt(startStopRange[1]); + } catch (NumberFormatException e) { + s_logger.warn("Unable to parse vnet range:", e); + throw new InvalidParameterValueException("Please provide valid vnet range between 0-4096"); + } + + if (startVnetRange < 0 || stopVnetRange > 4096) { + throw new InvalidParameterValueException("Vnet range has to be between 0-4096"); + } + + if (startVnetRange > stopVnetRange) { + throw new InvalidParameterValueException("Vnet range has to be between 0-4096 and start range should be lesser than or equal to stop range"); + } + } + + String oldZoneName = zone.getName(); + + if (zoneName == null) { + zoneName = oldZoneName; + } + + boolean dnsUpdate = false; + + if (dns1 != null || dns2 != null) { + dnsUpdate = true; + } + + if (dns1 == null) { + dns1 = zone.getDns1(); + } + + if (dns2 == null) { + dns2 = zone.getDns2(); + } + + if (internalDns1 == null) { + internalDns1 = zone.getInternalDns1(); + } + + if (guestCidr == null) { guestCidr = zone.getGuestNetworkCidr(); - } - - boolean checkForDuplicates = !zoneName.equals(oldZoneName); - checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, checkForDuplicates, null, allocationStateStr);//not allowing updating domain associated with a zone, once created + } - zone.setName(zoneName); - zone.setDns1(dns1); - zone.setDns2(dns2); - zone.setInternalDns1(internalDns1); - zone.setInternalDns2(internalDns2); - zone.setGuestNetworkCidr(guestCidr); - - if (vnetRange != null) { - zone.setVnet(vnetRange); - } - - //update a private zone to public; not vice versa - if(isPublic != null && isPublic) { - zone.setDomainId(null); - zone.setDomain(null); - } - - if (allocationStateStr != null && !allocationStateStr.isEmpty()) { - Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr); - zone.setAllocationState(allocationState); - } - - if (!_zoneDao.update(zoneId, zone)) { - throw new CloudRuntimeException("Failed to edit zone. Please contact Cloud Support."); - } - - if (vnetRange != null) { - String[] tokens = vnetRange.split("-"); - int begin = Integer.parseInt(tokens[0]); - int end = tokens.length == 1 ? (begin) : Integer.parseInt(tokens[1]); - - _zoneDao.deleteVnet(zoneId); - _zoneDao.addVnet(zone.getId(), begin, end); - } - - return zone; + boolean checkForDuplicates = !zoneName.equals(oldZoneName); + checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, checkForDuplicates, null, allocationStateStr);// not + // allowing + // updating + // domain + // associated + // with + // a + // zone, + // once + // created + + zone.setName(zoneName); + zone.setDns1(dns1); + zone.setDns2(dns2); + zone.setInternalDns1(internalDns1); + zone.setInternalDns2(internalDns2); + zone.setGuestNetworkCidr(guestCidr); + + if (vnetRange != null) { + zone.setVnet(vnetRange); + } + + // update a private zone to public; not vice versa + if (isPublic != null && isPublic) { + zone.setDomainId(null); + zone.setDomain(null); + } + + if (allocationStateStr != null && !allocationStateStr.isEmpty()) { + Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr); + zone.setAllocationState(allocationState); + } + + if (!_zoneDao.update(zoneId, zone)) { + throw new CloudRuntimeException("Failed to edit zone. Please contact Cloud Support."); + } + + if (vnetRange != null) { + String[] tokens = vnetRange.split("-"); + int begin = Integer.parseInt(tokens[0]); + int end = tokens.length == 1 ? (begin) : Integer.parseInt(tokens[1]); + + _zoneDao.deleteVnet(zoneId); + _zoneDao.addVnet(zone.getId(), begin, end); + } + + return zone; } - @Override @DB - public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain, Long domainId, NetworkType zoneType, boolean isSecurityGroupEnabled, String allocationStateStr) { + @Override + @DB + public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain, Long domainId, NetworkType zoneType, boolean isSecurityGroupEnabled, + String allocationStateStr) { int vnetStart = 0; int vnetEnd = 0; if (vnetRange != null) { String[] tokens = vnetRange.split("-"); try { - vnetStart = Integer.parseInt(tokens[0]); - if (tokens.length == 1) { - vnetEnd = vnetStart; - } else { - vnetEnd = Integer.parseInt(tokens[1]); - } + vnetStart = Integer.parseInt(tokens[0]); + if (tokens.length == 1) { + vnetEnd = vnetStart; + } else { + vnetEnd = Integer.parseInt(tokens[1]); + } } catch (NumberFormatException e) { throw new InvalidParameterValueException("Please specify valid integers for the vlan range."); } - - if((vnetStart > vnetEnd) || (vnetStart < 0) || (vnetEnd > 4096)) { - s_logger.warn("Invalid vnet range: start range:"+vnetStart+" end range:"+vnetEnd); - throw new InvalidParameterValueException("Vnet range should be between 0-4096 and start range should be lesser than or equal to end range"); + + if ((vnetStart > vnetEnd) || (vnetStart < 0) || (vnetEnd > 4096)) { + s_logger.warn("Invalid vnet range: start range:" + vnetStart + " end range:" + vnetEnd); + throw new InvalidParameterValueException("Vnet range should be between 0-4096 and start range should be lesser than or equal to end range"); } - } - - //checking the following params outside checkzoneparams method as we do not use these params for updatezone - //hence the method below is generic to check for common params + } + + // checking the following params outside checkzoneparams method as we do not use these params for updatezone + // hence the method below is generic to check for common params if ((guestCidr != null) && !NetUtils.validateGuestCidr(guestCidr)) { throw new InvalidParameterValueException("Please enter a valid guest cidr"); } @@ -1203,43 +1233,43 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura txn.start(); // Create the new zone in the database DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domain, domainId, zoneType, isSecurityGroupEnabled); - if (allocationStateStr != null && !allocationStateStr.isEmpty()) { - Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr); - zone.setAllocationState(allocationState); - } + if (allocationStateStr != null && !allocationStateStr.isEmpty()) { + Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr); + zone.setAllocationState(allocationState); + } zone = _zoneDao.persist(zone); // Add vnet entries for the new zone if zone type is Advanced if (vnetRange != null) { _zoneDao.addVnet(zone.getId(), vnetStart, vnetEnd); } - - //Create deafult networks + + // Create deafult networks createDefaultNetworks(zone.getId(), isSecurityGroupEnabled); txn.commit(); return zone; } catch (Exception ex) { txn.rollback(); s_logger.warn("Exception: ", ex); - throw new CloudRuntimeException("Fail to create a network"); - }finally { + throw new CloudRuntimeException("Fail to create a network"); + } finally { txn.close(); } } - + @Override - public void createDefaultNetworks(long zoneId, boolean isSecurityGroupEnabled) throws ConcurrentOperationException{ + public void createDefaultNetworks(long zoneId, boolean isSecurityGroupEnabled) throws ConcurrentOperationException { DataCenterVO zone = _zoneDao.findById(zoneId); - //Create public, management, control and storage networks as a part of the zone creation + // Create public, management, control and storage networks as a part of the zone creation if (zone != null) { List ntwkOff = _networkOfferingDao.listSystemNetworkOfferings(); - + for (NetworkOfferingVO offering : ntwkOff) { DataCenterDeployment plan = new DataCenterDeployment(zone.getId(), null, null, null, null); NetworkVO userNetwork = new NetworkVO(); Account systemAccount = _accountDao.findById(Account.ACCOUNT_ID_SYSTEM); - + BroadcastDomainType broadcastDomainType = null; boolean isNetworkDefault = false; if (offering.getTrafficType() == TrafficType.Management) { @@ -1265,13 +1295,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } } userNetwork.setBroadcastDomainType(broadcastDomainType); - _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, true, isNetworkDefault, false, null); + _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, true, isNetworkDefault, false, null); } } } @Override - public DataCenter createZone(CreateZoneCmd cmd) { + public DataCenter createZone(CreateZoneCmd cmd) { // grab parameters from the command Long userId = UserContext.current().getCallerUserId(); String zoneName = cmd.getZoneName(); @@ -1285,52 +1315,51 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura String type = cmd.getNetworkType(); Boolean isBasic = false; String allocationState = cmd.getAllocationState(); - if (allocationState == null) { - allocationState = Grouping.AllocationState.Enabled.toString(); - } - + if (allocationState == null) { + allocationState = Grouping.AllocationState.Enabled.toString(); + } + if (!(type.equalsIgnoreCase(NetworkType.Basic.toString())) && !(type.equalsIgnoreCase(NetworkType.Advanced.toString()))) { throw new InvalidParameterValueException("Invalid zone type; only Advanced and Basic values are supported"); } else if (type.equalsIgnoreCase(NetworkType.Basic.toString())) { isBasic = true; } - + Boolean securityGroupEnabled = cmd.isSecurityGroupEnabled(); - NetworkType zoneType = isBasic ? NetworkType.Basic : NetworkType.Advanced; - - //Guest cidr is required for Advanced zone creation; error out when the parameter specified for Basic zone + + // Guest cidr is required for Advanced zone creation; error out when the parameter specified for Basic zone if (zoneType == NetworkType.Advanced && guestCidr == null && !securityGroupEnabled) { throw new InvalidParameterValueException("guestCidrAddress parameter is required for Advanced zone creation"); } else if (zoneType == NetworkType.Basic && guestCidr != null) { throw new InvalidParameterValueException("guestCidrAddress parameter is not supported for Basic zone"); } - + DomainVO domainVO = null; - + if (userId == null) { userId = User.UID_SYSTEM; } - if(domainId != null){ - domainVO = _domainDao.findById(domainId); + if (domainId != null) { + domainVO = _domainDao.findById(domainId); } - - //Verify zone type + + // Verify zone type if (zoneType == NetworkType.Basic && vnetRange != null) { vnetRange = null; } - + if (zoneType == NetworkType.Basic) { securityGroupEnabled = true; } - - return createZone(userId, zoneName, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domainVO != null ? domainVO.getName() : null, domainId, zoneType, securityGroupEnabled, allocationState); + + return createZone(userId, zoneName, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domainVO != null ? domainVO.getName() : null, domainId, zoneType, securityGroupEnabled, allocationState); } @Override - public ServiceOffering createServiceOffering(CreateServiceOfferingCmd cmd){ + public ServiceOffering createServiceOffering(CreateServiceOfferingCmd cmd) { Long userId = UserContext.current().getCallerUserId(); if (userId == null) { userId = User.UID_SYSTEM; @@ -1361,14 +1390,14 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the memory value between 1 and 2147483647"); } - //check if valid domain - if(cmd.getDomainId() != null){ - DomainVO domain = _domainDao.findById(cmd.getDomainId()); - if(domain == null) { + // check if valid domain + if (cmd.getDomainId() != null) { + DomainVO domain = _domainDao.findById(cmd.getDomainId()); + if (domain == null) { throw new InvalidParameterValueException("Please specify a valid domain id"); } - } - + } + boolean localStorageRequired = false; String storageType = cmd.getStorageType(); if (storageType == null) { @@ -1386,249 +1415,262 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura offerHA = false; } - return createServiceOffering(userId, cmd.getServiceOfferingName(), cpuNumber.intValue(), memory.intValue(), cpuSpeed.intValue(), cmd.getDisplayText(), - localStorageRequired, offerHA, cmd.getTags(),cmd.getDomainId(), cmd.getHostTag()); + return createServiceOffering(userId, cmd.getServiceOfferingName(), cpuNumber.intValue(), memory.intValue(), cpuSpeed.intValue(), cmd.getDisplayText(), localStorageRequired, offerHA, cmd.getTags(), cmd.getDomainId(), cmd.getHostTag()); } - @Override + @Override @ActionEvent (eventType=EventTypes.EVENT_SERVICE_OFFERING_CREATE, eventDescription="creating service offering") public ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, String tags, Long domainId, String hostTag) { - String networkRateStr = _configDao.getValue("network.throttling.rate"); - String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); - int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr)); - int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); - tags = cleanupTags(tags); - ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, multicastRate, offerHA, displayText, localStorageRequired, false, tags, false,domainId, hostTag); - - if ((offering = _serviceOfferingDao.persist(offering)) != null) { - return offering; - } else { - return null; - } + String networkRateStr = _configDao.getValue("network.throttling.rate"); + String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); + int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr)); + int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); + tags = cleanupTags(tags); + ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, multicastRate, offerHA, displayText, localStorageRequired, false, tags, false, domainId, hostTag); + + if ((offering = _serviceOfferingDao.persist(offering)) != null) { + UserContext.current().setEventDetails("Service offering id=" + offering.getId()); + return offering; + } else { + return null; + } } - - @Override + + @Override @ActionEvent (eventType=EventTypes.EVENT_SERVICE_OFFERING_EDIT, eventDescription="updating service offering") public ServiceOffering updateServiceOffering(UpdateServiceOfferingCmd cmd) { - String displayText = cmd.getDisplayText(); - Long id = cmd.getId(); - String name = cmd.getServiceOfferingName(); - Long userId = UserContext.current().getCallerUserId(); - + String displayText = cmd.getDisplayText(); + Long id = cmd.getId(); + String name = cmd.getServiceOfferingName(); + Long userId = UserContext.current().getCallerUserId(); + if (userId == null) { userId = Long.valueOf(User.UID_SYSTEM); } - + // Verify input parameters - ServiceOfferingVO offeringHandle = _serviceOfferingDao.findById(id);; - if (offeringHandle == null) { - throw new InvalidParameterValueException("unable to find service offering " + id); - } - - boolean updateNeeded = (name != null || displayText != null); - if (!updateNeeded) { - return _serviceOfferingDao.findById(id); - } - + ServiceOfferingVO offeringHandle = _serviceOfferingDao.findById(id); + ; + if (offeringHandle == null) { + throw new InvalidParameterValueException("unable to find service offering " + id); + } + + boolean updateNeeded = (name != null || displayText != null); + if (!updateNeeded) { + return _serviceOfferingDao.findById(id); + } + ServiceOfferingVO offering = _serviceOfferingDao.createForUpdate(id); - + if (name != null) { - offering.setName(name); + offering.setName(name); } - + if (displayText != null) { - offering.setDisplayText(displayText); + offering.setDisplayText(displayText); } - -//Note: tag editing commented out for now; keeping the code intact, might need to re-enable in next releases -// if (tags != null) -// { -// if (tags.trim().isEmpty() && offeringHandle.getTags() == null) -// { -// //no new tags; no existing tags -// offering.setTagsArray(csvTagsToList(null)); -// } -// else if (!tags.trim().isEmpty() && offeringHandle.getTags() != null) -// { -// //new tags + existing tags -// List oldTags = csvTagsToList(offeringHandle.getTags()); -// List newTags = csvTagsToList(tags); -// oldTags.addAll(newTags); -// offering.setTagsArray(oldTags); -// } -// else if(!tags.trim().isEmpty()) -// { -// //new tags; NO existing tags -// offering.setTagsArray(csvTagsToList(tags)); -// } -// } - + + // Note: tag editing commented out for now; keeping the code intact, might need to re-enable in next releases + // if (tags != null) + // { + // if (tags.trim().isEmpty() && offeringHandle.getTags() == null) + // { + // //no new tags; no existing tags + // offering.setTagsArray(csvTagsToList(null)); + // } + // else if (!tags.trim().isEmpty() && offeringHandle.getTags() != null) + // { + // //new tags + existing tags + // List oldTags = csvTagsToList(offeringHandle.getTags()); + // List newTags = csvTagsToList(tags); + // oldTags.addAll(newTags); + // offering.setTagsArray(oldTags); + // } + // else if(!tags.trim().isEmpty()) + // { + // //new tags; NO existing tags + // offering.setTagsArray(csvTagsToList(tags)); + // } + // } + if (_serviceOfferingDao.update(id, offering)) { - offering = _serviceOfferingDao.findById(id); - return offering; + offering = _serviceOfferingDao.findById(id); + UserContext.current().setEventDetails("Service offering id=" + offering.getId()); + return offering; } else { - return null; + return null; } } - @Override + @Override @ActionEvent (eventType=EventTypes.EVENT_DISK_OFFERING_CREATE, eventDescription="creating disk offering") public DiskOfferingVO createDiskOffering(Long domainId, String name, String description, Long numGibibytes, String tags, boolean isCustomized) throws InvalidParameterValueException { - long diskSize = 0;//special case for custom disk offerings - if (numGibibytes != null && (numGibibytes <= 0)) { + long diskSize = 0;// special case for custom disk offerings + if (numGibibytes != null && (numGibibytes <= 0)) { throw new InvalidParameterValueException("Please specify a disk size of at least 1 Gb."); } else if (numGibibytes != null && (numGibibytes > _maxVolumeSizeInGb)) { throw new InvalidParameterValueException("The maximum size for a disk is " + _maxVolumeSizeInGb + " Gb."); } - if(numGibibytes != null){ - diskSize = numGibibytes * 1024; - } - - if(diskSize == 0){ - isCustomized = true; - } - + if (numGibibytes != null) { + diskSize = numGibibytes * 1024; + } + + if (diskSize == 0) { + isCustomized = true; + } + tags = cleanupTags(tags); - DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize,tags, isCustomized); - return _diskOfferingDao.persist(newDiskOffering); + DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize, tags, isCustomized); + UserContext.current().setEventDetails("Disk offering id=" + newDiskOffering.getId()); + DiskOfferingVO offering = _diskOfferingDao.persist(newDiskOffering); + if (offering != null) { + UserContext.current().setEventDetails("Disk offering id=" + newDiskOffering.getId()); + return offering; + } else { + return null; + } } - @Override + @Override public DiskOffering createDiskOffering(CreateDiskOfferingCmd cmd) throws InvalidParameterValueException { String name = cmd.getOfferingName(); String description = cmd.getDisplayText(); Long numGibibytes = cmd.getDiskSize(); - boolean isCustomized = cmd.isCustomized() != null ? cmd.isCustomized() : false; //false by default - String tags = cmd.getTags(); - //Long domainId = cmd.getDomainId() != null ? cmd.getDomainId() : Long.valueOf(DomainVO.ROOT_DOMAIN); // disk offering always gets created under the root domain.Bug # 6055 if not passed in cmd + boolean isCustomized = cmd.isCustomized() != null ? cmd.isCustomized() : false; // false by default + String tags = cmd.getTags(); + // Long domainId = cmd.getDomainId() != null ? cmd.getDomainId() : Long.valueOf(DomainVO.ROOT_DOMAIN); // disk offering + // always gets created under the root domain.Bug # 6055 if not passed in cmd Long domainId = cmd.getDomainId(); - - if(!isCustomized && numGibibytes == null){ - throw new InvalidParameterValueException("Disksize is required for non-customized disk offering"); + + if (!isCustomized && numGibibytes == null) { + throw new InvalidParameterValueException("Disksize is required for non-customized disk offering"); } - + return createDiskOffering(domainId, name, description, numGibibytes, tags, isCustomized); } - @Override - public DiskOffering updateDiskOffering(UpdateDiskOfferingCmd cmd) throws InvalidParameterValueException{ - Long diskOfferingId = cmd.getId(); - String name = cmd.getDiskOfferingName(); - String displayText = cmd.getDisplayText(); - - //Check if diskOffering exists - DiskOfferingVO diskOfferingHandle = _diskOfferingDao.findById(diskOfferingId); - - if (diskOfferingHandle == null) { - throw new InvalidParameterValueException("Unable to find disk offering by id " + diskOfferingId); - } - - boolean updateNeeded = (name != null || displayText != null); - if (!updateNeeded) { - return _diskOfferingDao.findById(diskOfferingId); - } - - DiskOfferingVO diskOffering = _diskOfferingDao.createForUpdate(diskOfferingId); - - if (name != null) { - diskOffering.setName(name); - } - - if (displayText != null) { - diskOffering.setDisplayText(displayText); - } - - -//Note: tag editing commented out for now;keeping the code intact, might need to re-enable in next releases -// if (tags != null) -// { -// if (tags.trim().isEmpty() && diskOfferingHandle.getTags() == null) -// { -// //no new tags; no existing tags -// diskOffering.setTagsArray(csvTagsToList(null)); -// } -// else if (!tags.trim().isEmpty() && diskOfferingHandle.getTags() != null) -// { -// //new tags + existing tags -// List oldTags = csvTagsToList(diskOfferingHandle.getTags()); -// List newTags = csvTagsToList(tags); -// oldTags.addAll(newTags); -// diskOffering.setTagsArray(oldTags); -// } -// else if(!tags.trim().isEmpty()) -// { -// //new tags; NO existing tags -// diskOffering.setTagsArray(csvTagsToList(tags)); -// } -// } + @Override @ActionEvent (eventType=EventTypes.EVENT_DISK_OFFERING_EDIT, eventDescription="updating disk offering") + public DiskOffering updateDiskOffering(UpdateDiskOfferingCmd cmd) throws InvalidParameterValueException { + Long diskOfferingId = cmd.getId(); + String name = cmd.getDiskOfferingName(); + String displayText = cmd.getDisplayText(); - if (_diskOfferingDao.update(diskOfferingId, diskOffering)) { - return _diskOfferingDao.findById(diskOfferingId); - } else { - return null; - } + // Check if diskOffering exists + DiskOfferingVO diskOfferingHandle = _diskOfferingDao.findById(diskOfferingId); + + if (diskOfferingHandle == null) { + throw new InvalidParameterValueException("Unable to find disk offering by id " + diskOfferingId); + } + + boolean updateNeeded = (name != null || displayText != null); + if (!updateNeeded) { + return _diskOfferingDao.findById(diskOfferingId); + } + + DiskOfferingVO diskOffering = _diskOfferingDao.createForUpdate(diskOfferingId); + + if (name != null) { + diskOffering.setName(name); + } + + if (displayText != null) { + diskOffering.setDisplayText(displayText); + } + + // Note: tag editing commented out for now;keeping the code intact, might need to re-enable in next releases + // if (tags != null) + // { + // if (tags.trim().isEmpty() && diskOfferingHandle.getTags() == null) + // { + // //no new tags; no existing tags + // diskOffering.setTagsArray(csvTagsToList(null)); + // } + // else if (!tags.trim().isEmpty() && diskOfferingHandle.getTags() != null) + // { + // //new tags + existing tags + // List oldTags = csvTagsToList(diskOfferingHandle.getTags()); + // List newTags = csvTagsToList(tags); + // oldTags.addAll(newTags); + // diskOffering.setTagsArray(oldTags); + // } + // else if(!tags.trim().isEmpty()) + // { + // //new tags; NO existing tags + // diskOffering.setTagsArray(csvTagsToList(tags)); + // } + // } + + if (_diskOfferingDao.update(diskOfferingId, diskOffering)) { + UserContext.current().setEventDetails("Disk offering id=" + diskOffering.getId()); + return _diskOfferingDao.findById(diskOfferingId); + } else { + return null; + } } - @Override - public boolean deleteDiskOffering(DeleteDiskOfferingCmd cmd) throws InvalidParameterValueException{ - Long diskOfferingId = cmd.getId(); - - DiskOfferingVO offering = _diskOfferingDao.findById(diskOfferingId); - - if (offering == null) { - throw new InvalidParameterValueException("Unable to find disk offering by id " + diskOfferingId); - } - - if (_diskOfferingDao.remove(diskOfferingId)) { - return true; - } else { - return false; - } + @Override @ActionEvent (eventType=EventTypes.EVENT_DISK_OFFERING_DELETE, eventDescription="deleting disk offering") + public boolean deleteDiskOffering(DeleteDiskOfferingCmd cmd) throws InvalidParameterValueException { + Long diskOfferingId = cmd.getId(); + + DiskOfferingVO offering = _diskOfferingDao.findById(diskOfferingId); + + if (offering == null) { + throw new InvalidParameterValueException("Unable to find disk offering by id " + diskOfferingId); + } + + if (_diskOfferingDao.remove(diskOfferingId)) { + UserContext.current().setEventDetails("Disk offering id=" + diskOfferingId); + return true; + } else { + return false; + } } - @Override - public boolean deleteServiceOffering(DeleteServiceOfferingCmd cmd) throws InvalidParameterValueException{ - + @Override @ActionEvent (eventType=EventTypes.EVENT_SERVICE_OFFERING_DELETE, eventDescription="deleting service offering") + public boolean deleteServiceOffering(DeleteServiceOfferingCmd cmd) throws InvalidParameterValueException { + Long offeringId = cmd.getId(); Long userId = UserContext.current().getCallerUserId(); - + if (userId == null) { userId = Long.valueOf(User.UID_SYSTEM); } - - //Verify service offering id + + // Verify service offering id ServiceOfferingVO offering = _serviceOfferingDao.findById(offeringId); - if (offering == null) { - throw new InvalidParameterValueException("unable to find service offering " + offeringId); - } else if (offering.getRemoved() != null) { - throw new InvalidParameterValueException("unable to find service offering " + offeringId); - } - - if (_serviceOfferingDao.remove(offeringId)) { - return true; - } else { - return false; - } + if (offering == null) { + throw new InvalidParameterValueException("unable to find service offering " + offeringId); + } else if (offering.getRemoved() != null) { + throw new InvalidParameterValueException("unable to find service offering " + offeringId); + } + + if (_serviceOfferingDao.remove(offeringId)) { + UserContext.current().setEventDetails("Service offering id=" + offeringId); + return true; + } else { + return false; + } } @Override public String changePrivateIPRange(boolean add, long podId, String startIP, String endIP) throws InvalidParameterValueException { - checkPrivateIpRangeErrors(podId, startIP, endIP); - - long zoneId = _podDao.findById(podId).getDataCenterId(); - List problemIPs = null; - if (add) { - problemIPs = savePrivateIPRange(startIP, endIP, podId, zoneId); - } else { - problemIPs = deletePrivateIPRange(startIP, endIP, podId, zoneId); - } - - if (problemIPs == null) { - throw new InvalidParameterValueException ("Failed to change private IP range. Please contact Cloud Support."); - } else { - return genChangeRangeSuccessString(problemIPs, add); - } + checkPrivateIpRangeErrors(podId, startIP, endIP); + + long zoneId = _podDao.findById(podId).getDataCenterId(); + List problemIPs = null; + if (add) { + problemIPs = savePrivateIPRange(startIP, endIP, podId, zoneId); + } else { + problemIPs = deletePrivateIPRange(startIP, endIP, podId, zoneId); + } + + if (problemIPs == null) { + throw new InvalidParameterValueException("Failed to change private IP range. Please contact Cloud Support."); + } else { + return genChangeRangeSuccessString(problemIPs, add); + } } - - @Override @DB + + @Override + @DB @ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_CREATE, eventDescription = "creating vlan ip range", async = false) public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { Long zoneId = cmd.getZoneId(); @@ -1642,7 +1684,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura Boolean forVirtualNetwork = cmd.isForVirtualNetwork(); Long networkId = cmd.getNetworkID(); String networkVlanId = null; - + // If an account name and domain ID are specified, look up the account String accountName = cmd.getAccountName(); Long domainId = cmd.getDomainId(); @@ -1654,8 +1696,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } } - //Verify that network exists - Network network = null; + // Verify that network exists + Network network = null; if (networkId != null) { network = _networkDao.findById(networkId); if (network == null) { @@ -1663,30 +1705,30 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } else { zoneId = network.getDataCenterId(); } - } - - //Verify that zone exists + } + + // Verify that zone exists DataCenterVO zone = _zoneDao.findById(zoneId); if (zone == null) { throw new InvalidParameterValueException("Unable to find zone by id " + zoneId); } - + // Check if zone is disabled - Account caller = UserContext.current().getCaller(); - if(Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())){ - throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: "+ zoneId ); - } - + Account caller = UserContext.current().getCaller(); + if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) { + throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId); + } + if (zone.isSecurityGroupEnabled() && zone.getNetworkType() != DataCenter.NetworkType.Basic && forVirtualNetwork) { throw new InvalidParameterValueException("Can't add virtual network into a zone with security group enabled"); } - - //If networkId is not specified, and vlan is Virtual or Direct Untagged, try to locate default networks - if (forVirtualNetwork){ + + // If networkId is not specified, and vlan is Virtual or Direct Untagged, try to locate default networks + if (forVirtualNetwork) { if (network == null) { - //find default public network in the zone + // find default public network in the zone networkId = _networkMgr.getSystemNetworkByZoneAndTrafficType(zoneId, TrafficType.Public).getId(); - } else if (network.getGuestType() != null || network.getTrafficType() != TrafficType.Public){ + } else if (network.getGuestType() != null || network.getTrafficType() != TrafficType.Public) { throw new InvalidParameterValueException("Can't find Public network by id=" + networkId); } } else { @@ -1703,14 +1745,14 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } else if (network.getGuestType() == null || network.getGuestType() == GuestIpType.Virtual) { throw new InvalidParameterValueException("Can't create direct vlan for network id=" + networkId + " with GuestType: " + network.getGuestType()); } - } - - //if end ip is not specified, default it to startIp + } + + // if end ip is not specified, default it to startIp if (endIP == null && startIP != null) { endIP = startIP; } - - //if vlan is specified, throw an error if it's not equal to network's vlanId + + // if vlan is specified, throw an error if it's not equal to network's vlanId if (network != null) { URI uri = network.getBroadcastUri(); if (uri != null) { @@ -1718,67 +1760,67 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura networkVlanId = vlan[1]; } } - + if (vlanId != null && networkVlanId != null && !networkVlanId.equalsIgnoreCase(vlanId)) { throw new InvalidParameterValueException("Vlan doesn't match vlan of the network"); } - + if (forVirtualNetwork || zone.getNetworkType() == DataCenter.NetworkType.Basic || network.isSecurityGroupEnabled()) { if (vlanGateway == null || vlanNetmask == null || zoneId == null) { throw new InvalidParameterValueException("Gateway, netmask and zoneId have to be passed in for virtual and direct untagged networks"); } } else { - //check if startIp and endIp belong to network Cidr + // check if startIp and endIp belong to network Cidr String networkCidr = network.getCidr(); String networkGateway = network.getGateway(); Long networkZoneId = network.getDataCenterId(); String networkNetmask = NetUtils.getCidrNetmask(networkCidr); - - //Check if ip addresses are in network range + + // Check if ip addresses are in network range if (!NetUtils.sameSubnet(startIP, networkGateway, networkNetmask)) { throw new InvalidParameterValueException("Start ip is not in network cidr: " + networkCidr); - } - + } + if (endIP != null) { if (!NetUtils.sameSubnet(endIP, networkGateway, networkNetmask)) { throw new InvalidParameterValueException("End ip is not in network cidr: " + networkCidr); - } + } } - - //set gateway, netmask, zone from network object + + // set gateway, netmask, zone from network object vlanGateway = networkGateway; vlanNetmask = networkNetmask; zoneId = networkZoneId; - - //set vlanId if it's not null for the network + + // set vlanId if it's not null for the network if (networkVlanId != null) { vlanId = networkVlanId; } } - - //if it's an account specific range, associate ip address list to the account + + // if it's an account specific range, associate ip address list to the account boolean associateIpRangeToAccount = false; - + if (forVirtualNetwork) { if (account != null) { // verify resource limits - long ipResourceLimit = _accountMgr.findCorrectResourceLimit((AccountVO)account, ResourceType.public_ip); - long accountIpRange = NetUtils.ip2Long(endIP) - NetUtils.ip2Long(startIP) + 1; + long ipResourceLimit = _accountMgr.findCorrectResourceLimit((AccountVO) account, ResourceType.public_ip); + long accountIpRange = NetUtils.ip2Long(endIP) - NetUtils.ip2Long(startIP) + 1; if (s_logger.isDebugEnabled()) { - s_logger.debug(" IPResourceLimit " +ipResourceLimit + " accountIpRange " + accountIpRange); + s_logger.debug(" IPResourceLimit " + ipResourceLimit + " accountIpRange " + accountIpRange); } - if (ipResourceLimit != -1 && accountIpRange > ipResourceLimit){ // -1 means infinite + if (ipResourceLimit != -1 && accountIpRange > ipResourceLimit) { // -1 means infinite throw new InvalidParameterValueException(" Public IP Resource Limit is set to " + ipResourceLimit + " which is less than the IP range of " + accountIpRange + " provided"); } associateIpRangeToAccount = true; } } - + Transaction txn = Transaction.currentTxn(); txn.start(); - + Vlan vlan = createVlanAndPublicIpRange(userId, zoneId, podId, startIP, endIP, vlanGateway, vlanNetmask, forVirtualNetwork, vlanId, account, networkId); - + if (associateIpRangeToAccount) { _networkMgr.associateIpAddressListToAccount(userId, account.getId(), zoneId, vlan.getId(), network); if (network == null) { @@ -1790,8 +1832,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } } txn.commit(); - - //Associate ips to the network + + // Associate ips to the network if (associateIpRangeToAccount) { if (network.getState() == Network.State.Implemented) { s_logger.debug("Applying ip associations for vlan id=" + vlanId + " in network " + network); @@ -1802,13 +1844,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura s_logger.trace("Network id=" + network.getId() + " is not Implemented, no need to apply ipAssociations"); } } - + return vlan; } - - @Override @DB - public Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, Long networkId){ + @Override + @DB + public Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, Long networkId) { // Check that the pod ID is valid if (podId != null && ((_podDao.findById(podId)) == null)) { throw new InvalidParameterValueException("Please specify a valid pod."); @@ -1821,229 +1863,234 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (vlanId == null) { vlanId = Vlan.UNTAGGED; } - + DataCenterVO zone; if (zoneId == null || ((zone = _zoneDao.findById(zoneId)) == null)) { throw new InvalidParameterValueException("Please specify a valid zone."); } - - //Allow adding untagged direct vlan only for Basic zone + + // Allow adding untagged direct vlan only for Basic zone if (zone.getNetworkType() == NetworkType.Advanced && vlanId.equals(Vlan.UNTAGGED) && (!forVirtualNetwork || zone.isSecurityGroupEnabled())) { throw new InvalidParameterValueException("Direct untagged network is not supported for the zone " + zone.getId() + " of type " + zone.getNetworkType()); } else if (zone.getNetworkType() == NetworkType.Basic && !(vlanId.equals(Vlan.UNTAGGED) && !forVirtualNetwork)) { throw new InvalidParameterValueException("Only direct untagged network is supported in the zone " + zone.getId() + " of type " + zone.getNetworkType()); } - - //don't allow to create a virtual vlan when zone's vnet is NULL + + // don't allow to create a virtual vlan when zone's vnet is NULL if (zone.getVnet() == null && forVirtualNetwork) { throw new InvalidParameterValueException("Can't add virtual network to the zone id=" + zone.getId() + " as zone doesn't have guest vlan configured"); } VlanType vlanType = forVirtualNetwork ? VlanType.VirtualNetwork : VlanType.DirectAttached; - - //ACL check + + // ACL check checkAccess(account, zone); - - if (vlanType.equals(VlanType.DirectAttached)) { - if (account != null) { - // VLANs for an account must be tagged - if (vlanId.equals(Vlan.UNTAGGED)) { - throw new InvalidParameterValueException("Direct Attached IP ranges for an account must be tagged."); - } + if (vlanType.equals(VlanType.DirectAttached)) { + if (account != null) { + // VLANs for an account must be tagged + if (vlanId.equals(Vlan.UNTAGGED)) { + throw new InvalidParameterValueException("Direct Attached IP ranges for an account must be tagged."); + } - // Make sure there aren't any pod VLANs in this zone - List podsInZone = _podDao.listByDataCenterId(zone.getId()); - for (HostPodVO pod : podsInZone) { - if (_podVlanMapDao.listPodVlanMapsByPod(pod.getId()).size() > 0) { - throw new InvalidParameterValueException("Zone " + zone.getName() + " already has pod-wide IP ranges. A zone may contain either pod-wide IP ranges or account-wide IP ranges, but not both."); - } - } - } else if (podId != null) { - // Pod-wide VLANs must be untagged - if (!vlanId.equals(Vlan.UNTAGGED)) { - throw new InvalidParameterValueException("Direct Attached IP ranges for a pod must be untagged."); - } + // Make sure there aren't any pod VLANs in this zone + List podsInZone = _podDao.listByDataCenterId(zone.getId()); + for (HostPodVO pod : podsInZone) { + if (_podVlanMapDao.listPodVlanMapsByPod(pod.getId()).size() > 0) { + throw new InvalidParameterValueException("Zone " + zone.getName() + " already has pod-wide IP ranges. A zone may contain either pod-wide IP ranges or account-wide IP ranges, but not both."); + } + } + } else if (podId != null) { + // Pod-wide VLANs must be untagged + if (!vlanId.equals(Vlan.UNTAGGED)) { + throw new InvalidParameterValueException("Direct Attached IP ranges for a pod must be untagged."); + } - // Make sure there aren't any account VLANs in this zone - List accountVlanMaps = _accountVlanMapDao.listAllIncludingRemoved(); - for (AccountVlanMapVO accountVlanMap : accountVlanMaps) { - VlanVO vlan = _vlanDao.findById(accountVlanMap.getVlanDbId()); - if (vlan.getDataCenterId() == zone.getId()) { - throw new InvalidParameterValueException("Zone " + zone.getName() + " already has account-wide IP ranges. A zone may contain either pod-wide IP ranges or account-wide IP ranges, but not both."); - } - } - } - } + // Make sure there aren't any account VLANs in this zone + List accountVlanMaps = _accountVlanMapDao.listAllIncludingRemoved(); + for (AccountVlanMapVO accountVlanMap : accountVlanMaps) { + VlanVO vlan = _vlanDao.findById(accountVlanMap.getVlanDbId()); + if (vlan.getDataCenterId() == zone.getId()) { + throw new InvalidParameterValueException("Zone " + zone.getName() + " already has account-wide IP ranges. A zone may contain either pod-wide IP ranges or account-wide IP ranges, but not both."); + } + } + } + } - // Make sure the gateway is valid - if (!NetUtils.isValidIp(vlanGateway)) { - throw new InvalidParameterValueException("Please specify a valid gateway"); - } + // Make sure the gateway is valid + if (!NetUtils.isValidIp(vlanGateway)) { + throw new InvalidParameterValueException("Please specify a valid gateway"); + } - // Make sure the netmask is valid - if (!NetUtils.isValidIp(vlanNetmask)) { - throw new InvalidParameterValueException("Please specify a valid netmask"); - } + // Make sure the netmask is valid + if (!NetUtils.isValidIp(vlanNetmask)) { + throw new InvalidParameterValueException("Please specify a valid netmask"); + } - String newVlanSubnet = NetUtils.getSubNet(vlanGateway, vlanNetmask); - - // Check if the new VLAN's subnet conflicts with the guest network in the specified zone (guestCidr is null for basic zone) - String guestNetworkCidr = zone.getGuestNetworkCidr(); - if (guestNetworkCidr != null) { - String[] cidrPair = guestNetworkCidr.split("\\/"); - String guestIpNetwork = NetUtils.getIpRangeStartIpFromCidr(cidrPair[0],Long.parseLong(cidrPair[1])); - long guestCidrSize = Long.parseLong(cidrPair[1]); - long vlanCidrSize = NetUtils.getCidrSize(vlanNetmask); + String newVlanSubnet = NetUtils.getSubNet(vlanGateway, vlanNetmask); - long cidrSizeToUse = -1; - if (vlanCidrSize < guestCidrSize) { - cidrSizeToUse = vlanCidrSize; - } else { - cidrSizeToUse = guestCidrSize; - } + // Check if the new VLAN's subnet conflicts with the guest network in the specified zone (guestCidr is null for basic + // zone) + String guestNetworkCidr = zone.getGuestNetworkCidr(); + if (guestNetworkCidr != null) { + String[] cidrPair = guestNetworkCidr.split("\\/"); + String guestIpNetwork = NetUtils.getIpRangeStartIpFromCidr(cidrPair[0], Long.parseLong(cidrPair[1])); + long guestCidrSize = Long.parseLong(cidrPair[1]); + long vlanCidrSize = NetUtils.getCidrSize(vlanNetmask); - String guestSubnet = NetUtils.getCidrSubNet(guestIpNetwork, cidrSizeToUse); + long cidrSizeToUse = -1; + if (vlanCidrSize < guestCidrSize) { + cidrSizeToUse = vlanCidrSize; + } else { + cidrSizeToUse = guestCidrSize; + } - if (newVlanSubnet.equals(guestSubnet)) { - throw new InvalidParameterValueException("The new IP range you have specified has the same subnet as the guest network in zone: " + zone.getName() + ". Please specify a different gateway/netmask."); - } - } + String guestSubnet = NetUtils.getCidrSubNet(guestIpNetwork, cidrSizeToUse); - // Check if there are any errors with the IP range - checkPublicIpRangeErrors(zoneId, vlanId, vlanGateway, vlanNetmask, startIP, endIP); + if (newVlanSubnet.equals(guestSubnet)) { + throw new InvalidParameterValueException("The new IP range you have specified has the same subnet as the guest network in zone: " + zone.getName() + ". Please specify a different gateway/netmask."); + } + } - // Throw an exception if any of the following is true: - // 1. Another VLAN in the same zone has a different tag but the same subnet as the new VLAN. Make an exception for the case when both vlans are Direct. - // 2. Another VLAN in the same zone that has the same tag and subnet as the new VLAN has IPs that overlap with the IPs being added - // 3. Another VLAN in the same zone that has the same tag and subnet as the new VLAN has a different gateway than the new VLAN - List vlans = _vlanDao.listByZone(zone.getId()); - for (VlanVO vlan : vlans) { - String otherVlanGateway = vlan.getVlanGateway(); - String otherVlanSubnet = NetUtils.getSubNet(vlan.getVlanGateway(), vlan.getVlanNetmask()); - String[] otherVlanIpRange = vlan.getIpRange().split("\\-"); - String otherVlanStartIP = otherVlanIpRange[0]; - String otherVlanEndIP = null; - if (otherVlanIpRange.length > 1) { - otherVlanEndIP = otherVlanIpRange[1]; - } - - if (!vlanId.equals(vlan.getVlanTag()) && newVlanSubnet.equals(otherVlanSubnet) && !allowIpRangeOverlap(vlan, forVirtualNetwork, networkId)) { - throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " in zone " + zone.getName() + " has the same subnet. Please specify a different gateway/netmask."); - } - - if (vlanId.equals(vlan.getVlanTag()) && newVlanSubnet.equals(otherVlanSubnet)) { - if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) { - throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " already has IPs that overlap with the new range. Please specify a different start IP/end IP."); - } - - if (!vlanGateway.equals(otherVlanGateway)) { - throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " has already been added with gateway " + otherVlanGateway + ". Please specify a different tag."); - } - } - } - - // Check if a guest VLAN is using the same tag - if (_zoneDao.findVnet(zoneId, vlanId).size() > 0) { - throw new InvalidParameterValueException("The VLAN tag " + vlanId + " is already being used for the guest network in zone " + zone.getName()); - } - - //For untagged vlan check if vlan per pod already exists. If yes, verify that new vlan range has the same netmask and gateway - if (zone.getNetworkType() == NetworkType.Basic && vlanId.equalsIgnoreCase(Vlan.UNTAGGED) && podId != null){ - List podVlans = _vlanDao.listVlansForPodByType(podId, VlanType.DirectAttached); - if (podVlans != null && !podVlans.isEmpty()) { - VlanVO podVlan = podVlans.get(0); - if (!podVlan.getVlanNetmask().equals(vlanNetmask)) { - throw new InvalidParameterValueException("Vlan netmask is different from the netmask of Untagged vlan id=" + podVlan.getId() + " existing in the pod " + podId); - } else if (!podVlan.getVlanGateway().equals(vlanGateway)) { - throw new InvalidParameterValueException("Vlan gateway is different from the gateway of Untagged vlan id=" + podVlan.getId() + " existing in the pod " + podId); - } - } - } + // Check if there are any errors with the IP range + checkPublicIpRangeErrors(zoneId, vlanId, vlanGateway, vlanNetmask, startIP, endIP); - String ipRange = startIP; - if (endIP != null) { - ipRange += "-" + endIP; - } - - // Everything was fine, so persist the VLAN + // Throw an exception if any of the following is true: + // 1. Another VLAN in the same zone has a different tag but the same subnet as the new VLAN. Make an exception for the + // case when both vlans are Direct. + // 2. Another VLAN in the same zone that has the same tag and subnet as the new VLAN has IPs that overlap with the IPs + // being added + // 3. Another VLAN in the same zone that has the same tag and subnet as the new VLAN has a different gateway than the + // new VLAN + List vlans = _vlanDao.listByZone(zone.getId()); + for (VlanVO vlan : vlans) { + String otherVlanGateway = vlan.getVlanGateway(); + String otherVlanSubnet = NetUtils.getSubNet(vlan.getVlanGateway(), vlan.getVlanNetmask()); + String[] otherVlanIpRange = vlan.getIpRange().split("\\-"); + String otherVlanStartIP = otherVlanIpRange[0]; + String otherVlanEndIP = null; + if (otherVlanIpRange.length > 1) { + otherVlanEndIP = otherVlanIpRange[1]; + } + + if (!vlanId.equals(vlan.getVlanTag()) && newVlanSubnet.equals(otherVlanSubnet) && !allowIpRangeOverlap(vlan, forVirtualNetwork, networkId)) { + throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " in zone " + zone.getName() + " has the same subnet. Please specify a different gateway/netmask."); + } + + if (vlanId.equals(vlan.getVlanTag()) && newVlanSubnet.equals(otherVlanSubnet)) { + if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) { + throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " already has IPs that overlap with the new range. Please specify a different start IP/end IP."); + } + + if (!vlanGateway.equals(otherVlanGateway)) { + throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " has already been added with gateway " + otherVlanGateway + ". Please specify a different tag."); + } + } + } + + // Check if a guest VLAN is using the same tag + if (_zoneDao.findVnet(zoneId, vlanId).size() > 0) { + throw new InvalidParameterValueException("The VLAN tag " + vlanId + " is already being used for the guest network in zone " + zone.getName()); + } + + // For untagged vlan check if vlan per pod already exists. If yes, verify that new vlan range has the same netmask and + // gateway + if (zone.getNetworkType() == NetworkType.Basic && vlanId.equalsIgnoreCase(Vlan.UNTAGGED) && podId != null) { + List podVlans = _vlanDao.listVlansForPodByType(podId, VlanType.DirectAttached); + if (podVlans != null && !podVlans.isEmpty()) { + VlanVO podVlan = podVlans.get(0); + if (!podVlan.getVlanNetmask().equals(vlanNetmask)) { + throw new InvalidParameterValueException("Vlan netmask is different from the netmask of Untagged vlan id=" + podVlan.getId() + " existing in the pod " + podId); + } else if (!podVlan.getVlanGateway().equals(vlanGateway)) { + throw new InvalidParameterValueException("Vlan gateway is different from the gateway of Untagged vlan id=" + podVlan.getId() + " existing in the pod " + podId); + } + } + } + + String ipRange = startIP; + if (endIP != null) { + ipRange += "-" + endIP; + } + + // Everything was fine, so persist the VLAN Transaction txn = Transaction.currentTxn(); - txn.start(); - - VlanVO vlan = new VlanVO(vlanType, vlanId, vlanGateway, vlanNetmask, zone.getId(), ipRange, networkId); - vlan = _vlanDao.persist(vlan); - - if (!savePublicIPRange(startIP, endIP, zoneId, vlan.getId(), networkId)) { - throw new CloudRuntimeException("Failed to save IP range. Please contact Cloud Support."); //It can be Direct IP or Public IP. - } - - if (account != null) { - // This VLAN is account-specific, so create an AccountVlanMapVO entry - AccountVlanMapVO accountVlanMapVO = new AccountVlanMapVO(account.getId(), vlan.getId()); - _accountVlanMapDao.persist(accountVlanMapVO); - } else if (podId != null) { - // This VLAN is pod-wide, so create a PodVlanMapVO entry - PodVlanMapVO podVlanMapVO = new PodVlanMapVO(podId, vlan.getId()); - _podVlanMapDao.persist(podVlanMapVO); - } - - txn.commit(); + txn.start(); - return vlan; + VlanVO vlan = new VlanVO(vlanType, vlanId, vlanGateway, vlanNetmask, zone.getId(), ipRange, networkId); + vlan = _vlanDao.persist(vlan); + + if (!savePublicIPRange(startIP, endIP, zoneId, vlan.getId(), networkId)) { + throw new CloudRuntimeException("Failed to save IP range. Please contact Cloud Support."); // It can be Direct IP or + // Public IP. + } + + if (account != null) { + // This VLAN is account-specific, so create an AccountVlanMapVO entry + AccountVlanMapVO accountVlanMapVO = new AccountVlanMapVO(account.getId(), vlan.getId()); + _accountVlanMapDao.persist(accountVlanMapVO); + } else if (podId != null) { + // This VLAN is pod-wide, so create a PodVlanMapVO entry + PodVlanMapVO podVlanMapVO = new PodVlanMapVO(podId, vlan.getId()); + _podVlanMapDao.persist(podVlanMapVO); + } + + txn.commit(); + + return vlan; } - + @Override public boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId) throws InvalidParameterValueException { - VlanVO vlan = _vlanDao.findById(vlanDbId); - if (vlan == null) { - throw new InvalidParameterValueException("Please specify a valid IP range id."); - } - - // Check if the VLAN has any allocated public IPs + VlanVO vlan = _vlanDao.findById(vlanDbId); + if (vlan == null) { + throw new InvalidParameterValueException("Please specify a valid IP range id."); + } + + // Check if the VLAN has any allocated public IPs if (_publicIpAddressDao.countIPs(vlan.getDataCenterId(), vlanDbId, true) > 0) { throw new InvalidParameterValueException("The IP range can't be deleted because it has allocated public IP addresses."); } - // Delete all public IPs in the VLAN - if (!deletePublicIPRange(vlanDbId)) { - return false; - } - - // Delete the VLAN - return _vlanDao.expunge(vlanDbId); + // Delete all public IPs in the VLAN + if (!deletePublicIPRange(vlanDbId)) { + return false; + } + + // Delete the VLAN + return _vlanDao.expunge(vlanDbId); } - + @Override public List csvTagsToList(String tags) { - List tagsList = new ArrayList(); - - if (tags != null) { + List tagsList = new ArrayList(); + + if (tags != null) { String[] tokens = tags.split(","); for (int i = 0; i < tokens.length; i++) { tagsList.add(tokens[i].trim()); } } - - return tagsList; + + return tagsList; } - + @Override public String listToCsvTags(List tagsList) { - String tags = ""; - if (tagsList.size() > 0) { - for (int i = 0; i < tagsList.size(); i++) { - tags += tagsList.get(i); - if (i != tagsList.size() - 1) { - tags += ","; - } - } - } - - return tags; + String tags = ""; + if (tagsList.size() > 0) { + for (int i = 0; i < tagsList.size(); i++) { + tags += tagsList.get(i); + if (i != tagsList.size() - 1) { + tags += ","; + } + } + } + + return tags; } - + private String cleanupTags(String tags) { - if (tags != null) { + if (tags != null) { String[] tokens = tags.split(","); StringBuilder t = new StringBuilder(); for (int i = 0; i < tokens.length; i++) { @@ -2052,409 +2099,406 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura t.delete(t.length() - 1, t.length()); tags = t.toString(); } - - return tags; + + return tags; } - - private boolean isPrivateIPAllocated(String ip, long podId, long zoneId, PreparedStatement stmt) { - try { - stmt.clearParameters(); - stmt.setString(1, ip); - stmt.setLong(2, zoneId); - stmt.setLong(3, podId); - ResultSet rs = stmt.executeQuery(); - if (rs.next()) { + + private boolean isPrivateIPAllocated(String ip, long podId, long zoneId, PreparedStatement stmt) { + try { + stmt.clearParameters(); + stmt.setString(1, ip); + stmt.setLong(2, zoneId); + stmt.setLong(3, podId); + ResultSet rs = stmt.executeQuery(); + if (rs.next()) { return (rs.getString("taken") != null); } else { return false; } } catch (SQLException ex) { - System.out.println(ex.getMessage()); + System.out.println(ex.getMessage()); return true; } - } - - @DB - protected boolean deletePublicIPRange(long vlanDbId) { - Transaction txn = Transaction.currentTxn(); - String deleteSql = "DELETE FROM `cloud`.`user_ip_address` WHERE vlan_db_id = ?"; + } + + @DB + protected boolean deletePublicIPRange(long vlanDbId) { + Transaction txn = Transaction.currentTxn(); + String deleteSql = "DELETE FROM `cloud`.`user_ip_address` WHERE vlan_db_id = ?"; + + txn.start(); + try { + PreparedStatement stmt = txn.prepareAutoCloseStatement(deleteSql); + stmt.setLong(1, vlanDbId); + stmt.executeUpdate(); + } catch (Exception ex) { + return false; + } + txn.commit(); - txn.start(); - try { - PreparedStatement stmt = txn.prepareAutoCloseStatement(deleteSql); - stmt.setLong(1, vlanDbId); - stmt.executeUpdate(); - } catch (Exception ex) { - return false; - } - txn.commit(); - return true; - } - - @DB - protected List deletePrivateIPRange(String startIP, String endIP, long podId, long zoneId) { - long startIPLong = NetUtils.ip2Long(startIP); - long endIPLong = NetUtils.ip2Long(endIP); - Transaction txn = Transaction.currentTxn(); - String deleteSql = "DELETE FROM `cloud`.`op_dc_ip_address_alloc` WHERE ip_address = ? AND pod_id = ? AND data_center_id = ?"; - String isPrivateIPAllocatedSelectSql = "SELECT * FROM `cloud`.`op_dc_ip_address_alloc` WHERE ip_address = ? AND data_center_id = ? AND pod_id = ?"; - - List problemIPs = new ArrayList(); - PreparedStatement deleteIPStmt = null; - PreparedStatement isAllocatedStmt = null; - - txn.start(); - try { - deleteIPStmt = txn.prepareAutoCloseStatement(deleteSql); - isAllocatedStmt = txn.prepareAutoCloseStatement(isPrivateIPAllocatedSelectSql); - } catch (SQLException e) { - return null; - } - - while (startIPLong <= endIPLong) { - if (!isPrivateIPAllocated(NetUtils.long2Ip(startIPLong), podId, zoneId, isAllocatedStmt)) { - try { - deleteIPStmt.clearParameters(); - deleteIPStmt.setString(1, NetUtils.long2Ip(startIPLong)); - deleteIPStmt.setLong(2, podId); - deleteIPStmt.setLong(3, zoneId); - deleteIPStmt.executeUpdate(); - } catch (Exception ex) { - } - } else { - problemIPs.add(NetUtils.long2Ip(startIPLong)); - } - startIPLong += 1; - } - txn.commit(); + } + + @DB + protected List deletePrivateIPRange(String startIP, String endIP, long podId, long zoneId) { + long startIPLong = NetUtils.ip2Long(startIP); + long endIPLong = NetUtils.ip2Long(endIP); + Transaction txn = Transaction.currentTxn(); + String deleteSql = "DELETE FROM `cloud`.`op_dc_ip_address_alloc` WHERE ip_address = ? AND pod_id = ? AND data_center_id = ?"; + String isPrivateIPAllocatedSelectSql = "SELECT * FROM `cloud`.`op_dc_ip_address_alloc` WHERE ip_address = ? AND data_center_id = ? AND pod_id = ?"; + + List problemIPs = new ArrayList(); + PreparedStatement deleteIPStmt = null; + PreparedStatement isAllocatedStmt = null; + + txn.start(); + try { + deleteIPStmt = txn.prepareAutoCloseStatement(deleteSql); + isAllocatedStmt = txn.prepareAutoCloseStatement(isPrivateIPAllocatedSelectSql); + } catch (SQLException e) { + return null; + } + + while (startIPLong <= endIPLong) { + if (!isPrivateIPAllocated(NetUtils.long2Ip(startIPLong), podId, zoneId, isAllocatedStmt)) { + try { + deleteIPStmt.clearParameters(); + deleteIPStmt.setString(1, NetUtils.long2Ip(startIPLong)); + deleteIPStmt.setLong(2, podId); + deleteIPStmt.setLong(3, zoneId); + deleteIPStmt.executeUpdate(); + } catch (Exception ex) { + } + } else { + problemIPs.add(NetUtils.long2Ip(startIPLong)); + } + startIPLong += 1; + } + txn.commit(); return problemIPs; - } - - @DB + } + + @DB protected boolean savePublicIPRange(String startIP, String endIP, long zoneId, long vlanDbId, long sourceNetworkid) { long startIPLong = NetUtils.ip2Long(startIP); long endIPLong = NetUtils.ip2Long(endIP); - Transaction txn = Transaction.currentTxn(); - txn.start(); - IPRangeConfig config = new IPRangeConfig(); - config.savePublicIPRange(txn, startIPLong, endIPLong, zoneId, vlanDbId, sourceNetworkid); - txn.commit(); - return true; - } - - @DB - protected List savePrivateIPRange(String startIP, String endIP, long podId, long zoneId) { - Transaction txn = Transaction.currentTxn(); - IPRangeConfig config = new IPRangeConfig(); - txn.start(); - List ips = config.savePrivateIPRange(txn, NetUtils.ip2Long(startIP), NetUtils.ip2Long(endIP), podId, zoneId); - txn.commit(); - return ips; - } - - private String genChangeRangeSuccessString(List problemIPs, boolean add) { - if (problemIPs == null) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + IPRangeConfig config = new IPRangeConfig(); + config.savePublicIPRange(txn, startIPLong, endIPLong, zoneId, vlanDbId, sourceNetworkid); + txn.commit(); + return true; + } + + @DB + protected List savePrivateIPRange(String startIP, String endIP, long podId, long zoneId) { + Transaction txn = Transaction.currentTxn(); + IPRangeConfig config = new IPRangeConfig(); + txn.start(); + List ips = config.savePrivateIPRange(txn, NetUtils.ip2Long(startIP), NetUtils.ip2Long(endIP), podId, zoneId); + txn.commit(); + return ips; + } + + private String genChangeRangeSuccessString(List problemIPs, boolean add) { + if (problemIPs == null) { return ""; } - - if (problemIPs.size() == 0) { - if (add) { + + if (problemIPs.size() == 0) { + if (add) { return "Successfully added all IPs in the specified range."; } else { return "Successfully deleted all IPs in the specified range."; } - } else { - String successString = ""; - if (add) { + } else { + String successString = ""; + if (add) { successString += "Failed to add the following IPs, because they are already in the database: "; } else { successString += "Failed to delete the following IPs, because they are in use: "; } - - for (int i = 0; i < problemIPs.size(); i++) { - successString += problemIPs.get(i); - if (i != (problemIPs.size() - 1)) { + + for (int i = 0; i < problemIPs.size(); i++) { + successString += problemIPs.get(i); + if (i != (problemIPs.size() - 1)) { successString += ", "; } - } - - successString += ". "; - - if (add) { + } + + successString += ". "; + + if (add) { successString += "Successfully added all other IPs in the specified range."; } else { successString += "Successfully deleted all other IPs in the specified range."; } - - return successString; - } - } - - private void checkPublicIpRangeErrors(long zoneId, String vlanId, String vlanGateway, String vlanNetmask, String startIP, String endIP) throws InvalidParameterValueException { - // Check that the start and end IPs are valid - if (!NetUtils.isValidIp(startIP)) { - throw new InvalidParameterValueException("Please specify a valid start IP"); - } - - if (endIP != null && !NetUtils.isValidIp(endIP)) { - throw new InvalidParameterValueException("Please specify a valid end IP"); - } - - if (endIP != null && !NetUtils.validIpRange(startIP, endIP)) { - throw new InvalidParameterValueException("Please specify a valid IP range."); - } - - // Check that the IPs that are being added are compatible with the VLAN's gateway and netmask - if (vlanNetmask == null) { - throw new InvalidParameterValueException("Please ensure that your IP range's netmask is specified"); - } - - if (endIP != null && !NetUtils.sameSubnet(startIP, endIP, vlanNetmask)) { - throw new InvalidParameterValueException("Please ensure that your start IP and end IP are in the same subnet, as per the IP range's netmask."); - } - - if (!NetUtils.sameSubnet(startIP, vlanGateway, vlanNetmask)) { - throw new InvalidParameterValueException("Please ensure that your start IP is in the same subnet as your IP range's gateway, as per the IP range's netmask."); - } - - if (endIP != null && !NetUtils.sameSubnet(endIP, vlanGateway, vlanNetmask)) { - throw new InvalidParameterValueException("Please ensure that your end IP is in the same subnet as your IP range's gateway, as per the IP range's netmask."); - } - } - - private void checkPrivateIpRangeErrors(Long podId, String startIP, String endIP) throws InvalidParameterValueException { - HostPodVO pod = _podDao.findById(podId); - if (pod == null) { - throw new InvalidParameterValueException("Please specify a valid pod."); - } - - // Check that the start and end IPs are valid - if (!NetUtils.isValidIp(startIP)) { - throw new InvalidParameterValueException("Please specify a valid start IP"); - } - - if (endIP != null && !NetUtils.isValidIp(endIP)) { - throw new InvalidParameterValueException("Please specify a valid end IP"); - } - - if (endIP != null && !NetUtils.validIpRange(startIP, endIP)) { - throw new InvalidParameterValueException("Please specify a valid IP range."); - } - - // Check that the IPs that are being added are compatible with the pod's CIDR - String cidrAddress = getCidrAddress(podId); - long cidrSize = getCidrSize(podId); - if (endIP != null && !NetUtils.sameSubnetCIDR(startIP, endIP, cidrSize)) { - throw new InvalidParameterValueException("Please ensure that your start IP and end IP are in the same subnet, as per the pod's CIDR size."); - } - - if (!NetUtils.sameSubnetCIDR(startIP, cidrAddress, cidrSize)) { - throw new InvalidParameterValueException("Please ensure that your start IP is in the same subnet as the pod's CIDR address."); - } - - if (endIP != null && !NetUtils.sameSubnetCIDR(endIP, cidrAddress, cidrSize)) { - throw new InvalidParameterValueException("Please ensure that your end IP is in the same subnet as the pod's CIDR address."); - } - } - - private String getCidrAddress(String cidr) { - String[] cidrPair = cidr.split("\\/"); - return cidrPair[0]; - } - - private int getCidrSize(String cidr) { - String[] cidrPair = cidr.split("\\/"); - return Integer.parseInt(cidrPair[1]); - } - - private String getCidrAddress(long podId) { - HostPodVO pod = _podDao.findById(podId); - return pod.getCidrAddress(); - } - - private long getCidrSize(long podId) { - HostPodVO pod = _podDao.findById(podId); - return pod.getCidrSize(); - } - - private void checkPodCidrSubnets(long dcId, HashMap> currentPodCidrSubnets) throws InvalidParameterValueException { - // For each pod, return an error if any of the following is true: - // 1. The pod's CIDR subnet conflicts with the guest network subnet - // 2. The pod's CIDR subnet conflicts with the CIDR subnet of any other pod - DataCenterVO dcVo = _zoneDao.findById(dcId); - String guestNetworkCidr = dcVo.getGuestNetworkCidr(); - - //Guest cidr can be null for Basic zone - String guestIpNetwork = null; - Long guestCidrSize = null; - if (guestNetworkCidr != null) { - String[] cidrTuple = guestNetworkCidr.split("\\/"); - guestIpNetwork = NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0],Long.parseLong(cidrTuple[1])); - guestCidrSize = Long.parseLong(cidrTuple[1]); - } + return successString; + } + } - String zoneName = getZoneName(dcId); + private void checkPublicIpRangeErrors(long zoneId, String vlanId, String vlanGateway, String vlanNetmask, String startIP, String endIP) throws InvalidParameterValueException { + // Check that the start and end IPs are valid + if (!NetUtils.isValidIp(startIP)) { + throw new InvalidParameterValueException("Please specify a valid start IP"); + } - // Iterate through all pods in this zone - for (Long podId : currentPodCidrSubnets.keySet()) { - String podName; - if (podId.longValue() == -1) { + if (endIP != null && !NetUtils.isValidIp(endIP)) { + throw new InvalidParameterValueException("Please specify a valid end IP"); + } + + if (endIP != null && !NetUtils.validIpRange(startIP, endIP)) { + throw new InvalidParameterValueException("Please specify a valid IP range."); + } + + // Check that the IPs that are being added are compatible with the VLAN's gateway and netmask + if (vlanNetmask == null) { + throw new InvalidParameterValueException("Please ensure that your IP range's netmask is specified"); + } + + if (endIP != null && !NetUtils.sameSubnet(startIP, endIP, vlanNetmask)) { + throw new InvalidParameterValueException("Please ensure that your start IP and end IP are in the same subnet, as per the IP range's netmask."); + } + + if (!NetUtils.sameSubnet(startIP, vlanGateway, vlanNetmask)) { + throw new InvalidParameterValueException("Please ensure that your start IP is in the same subnet as your IP range's gateway, as per the IP range's netmask."); + } + + if (endIP != null && !NetUtils.sameSubnet(endIP, vlanGateway, vlanNetmask)) { + throw new InvalidParameterValueException("Please ensure that your end IP is in the same subnet as your IP range's gateway, as per the IP range's netmask."); + } + } + + private void checkPrivateIpRangeErrors(Long podId, String startIP, String endIP) throws InvalidParameterValueException { + HostPodVO pod = _podDao.findById(podId); + if (pod == null) { + throw new InvalidParameterValueException("Please specify a valid pod."); + } + + // Check that the start and end IPs are valid + if (!NetUtils.isValidIp(startIP)) { + throw new InvalidParameterValueException("Please specify a valid start IP"); + } + + if (endIP != null && !NetUtils.isValidIp(endIP)) { + throw new InvalidParameterValueException("Please specify a valid end IP"); + } + + if (endIP != null && !NetUtils.validIpRange(startIP, endIP)) { + throw new InvalidParameterValueException("Please specify a valid IP range."); + } + + // Check that the IPs that are being added are compatible with the pod's CIDR + String cidrAddress = getCidrAddress(podId); + long cidrSize = getCidrSize(podId); + + if (endIP != null && !NetUtils.sameSubnetCIDR(startIP, endIP, cidrSize)) { + throw new InvalidParameterValueException("Please ensure that your start IP and end IP are in the same subnet, as per the pod's CIDR size."); + } + + if (!NetUtils.sameSubnetCIDR(startIP, cidrAddress, cidrSize)) { + throw new InvalidParameterValueException("Please ensure that your start IP is in the same subnet as the pod's CIDR address."); + } + + if (endIP != null && !NetUtils.sameSubnetCIDR(endIP, cidrAddress, cidrSize)) { + throw new InvalidParameterValueException("Please ensure that your end IP is in the same subnet as the pod's CIDR address."); + } + } + + private String getCidrAddress(String cidr) { + String[] cidrPair = cidr.split("\\/"); + return cidrPair[0]; + } + + private int getCidrSize(String cidr) { + String[] cidrPair = cidr.split("\\/"); + return Integer.parseInt(cidrPair[1]); + } + + private String getCidrAddress(long podId) { + HostPodVO pod = _podDao.findById(podId); + return pod.getCidrAddress(); + } + + private long getCidrSize(long podId) { + HostPodVO pod = _podDao.findById(podId); + return pod.getCidrSize(); + } + + private void checkPodCidrSubnets(long dcId, HashMap> currentPodCidrSubnets) throws InvalidParameterValueException { + // For each pod, return an error if any of the following is true: + // 1. The pod's CIDR subnet conflicts with the guest network subnet + // 2. The pod's CIDR subnet conflicts with the CIDR subnet of any other pod + DataCenterVO dcVo = _zoneDao.findById(dcId); + String guestNetworkCidr = dcVo.getGuestNetworkCidr(); + + // Guest cidr can be null for Basic zone + String guestIpNetwork = null; + Long guestCidrSize = null; + if (guestNetworkCidr != null) { + String[] cidrTuple = guestNetworkCidr.split("\\/"); + guestIpNetwork = NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1])); + guestCidrSize = Long.parseLong(cidrTuple[1]); + } + + String zoneName = getZoneName(dcId); + + // Iterate through all pods in this zone + for (Long podId : currentPodCidrSubnets.keySet()) { + String podName; + if (podId.longValue() == -1) { podName = "newPod"; } else { podName = getPodName(podId.longValue()); } - - List cidrPair = currentPodCidrSubnets.get(podId); - String cidrAddress = (String) cidrPair.get(0); - long cidrSize = ((Long) cidrPair.get(1)).longValue(); - - long cidrSizeToUse = -1; - if (guestCidrSize == null || cidrSize < guestCidrSize) { + + List cidrPair = currentPodCidrSubnets.get(podId); + String cidrAddress = (String) cidrPair.get(0); + long cidrSize = ((Long) cidrPair.get(1)).longValue(); + + long cidrSizeToUse = -1; + if (guestCidrSize == null || cidrSize < guestCidrSize) { cidrSizeToUse = cidrSize; } else { cidrSizeToUse = guestCidrSize; } - - String cidrSubnet = NetUtils.getCidrSubNet(cidrAddress, cidrSizeToUse); - - if (guestNetworkCidr != null) { - String guestSubnet = NetUtils.getCidrSubNet(guestIpNetwork, cidrSizeToUse); - // Check that cidrSubnet does not equal guestSubnet - if (cidrSubnet.equals(guestSubnet)) { - if (podName.equals("newPod")) { - throw new InvalidParameterValueException("The subnet of the pod you are adding conflicts with the subnet of the Guest IP Network. Please specify a different CIDR."); - } else { - throw new InvalidParameterValueException("Warning: The subnet of pod " + podName + " in zone " + zoneName + " conflicts with the subnet of the Guest IP Network. Please change either the pod's CIDR or the Guest IP Network's subnet, and re-run install-vmops-management."); - } - } - } - - - // Iterate through the rest of the pods - for (Long otherPodId : currentPodCidrSubnets.keySet()) { - if (podId.equals(otherPodId)) { + + String cidrSubnet = NetUtils.getCidrSubNet(cidrAddress, cidrSizeToUse); + + if (guestNetworkCidr != null) { + String guestSubnet = NetUtils.getCidrSubNet(guestIpNetwork, cidrSizeToUse); + // Check that cidrSubnet does not equal guestSubnet + if (cidrSubnet.equals(guestSubnet)) { + if (podName.equals("newPod")) { + throw new InvalidParameterValueException("The subnet of the pod you are adding conflicts with the subnet of the Guest IP Network. Please specify a different CIDR."); + } else { + throw new InvalidParameterValueException("Warning: The subnet of pod " + podName + " in zone " + zoneName + + " conflicts with the subnet of the Guest IP Network. Please change either the pod's CIDR or the Guest IP Network's subnet, and re-run install-vmops-management."); + } + } + } + + // Iterate through the rest of the pods + for (Long otherPodId : currentPodCidrSubnets.keySet()) { + if (podId.equals(otherPodId)) { continue; } - - // Check that cidrSubnet does not equal otherCidrSubnet - List otherCidrPair = currentPodCidrSubnets.get(otherPodId); - String otherCidrAddress = (String) otherCidrPair.get(0); - long otherCidrSize = ((Long) otherCidrPair.get(1)).longValue(); - - if (cidrSize < otherCidrSize) { + + // Check that cidrSubnet does not equal otherCidrSubnet + List otherCidrPair = currentPodCidrSubnets.get(otherPodId); + String otherCidrAddress = (String) otherCidrPair.get(0); + long otherCidrSize = ((Long) otherCidrPair.get(1)).longValue(); + + if (cidrSize < otherCidrSize) { cidrSizeToUse = cidrSize; } else { cidrSizeToUse = otherCidrSize; } - - cidrSubnet = NetUtils.getCidrSubNet(cidrAddress, cidrSizeToUse); - String otherCidrSubnet = NetUtils.getCidrSubNet(otherCidrAddress, cidrSizeToUse); - - if (cidrSubnet.equals(otherCidrSubnet)) { - String otherPodName = getPodName(otherPodId.longValue()); - if (podName.equals("newPod")) { - throw new InvalidParameterValueException("The subnet of the pod you are adding conflicts with the subnet of pod " + otherPodName + " in zone " + zoneName + ". Please specify a different CIDR."); - } else { - throw new InvalidParameterValueException("Warning: The pods " + podName + " and " + otherPodName + " in zone " + zoneName + " have conflicting CIDR subnets. Please change the CIDR of one of these pods."); - } - } - } - } - - } - - private boolean validPod(long podId) { - return (_podDao.findById(podId) != null); - } - + + cidrSubnet = NetUtils.getCidrSubNet(cidrAddress, cidrSizeToUse); + String otherCidrSubnet = NetUtils.getCidrSubNet(otherCidrAddress, cidrSizeToUse); + + if (cidrSubnet.equals(otherCidrSubnet)) { + String otherPodName = getPodName(otherPodId.longValue()); + if (podName.equals("newPod")) { + throw new InvalidParameterValueException("The subnet of the pod you are adding conflicts with the subnet of pod " + otherPodName + " in zone " + zoneName + ". Please specify a different CIDR."); + } else { + throw new InvalidParameterValueException("Warning: The pods " + podName + " and " + otherPodName + " in zone " + zoneName + " have conflicting CIDR subnets. Please change the CIDR of one of these pods."); + } + } + } + } + + } + + private boolean validPod(long podId) { + return (_podDao.findById(podId) != null); + } + private boolean validPod(String podName, long zoneId) { - if (!validZone(zoneId)) { - return false; - } - - return (_podDao.findByName(podName, zoneId) != null); - } - + if (!validZone(zoneId)) { + return false; + } + + return (_podDao.findByName(podName, zoneId) != null); + } + private String getPodName(long podId) { - return _podDao.findById(new Long(podId)).getName(); + return _podDao.findById(new Long(podId)).getName(); } - + private boolean validZone(String zoneName) { - return(_zoneDao.findByName(zoneName) != null); + return (_zoneDao.findByName(zoneName) != null); } - + private boolean validZone(long zoneId) { - return (_zoneDao.findById(zoneId) != null); + return (_zoneDao.findById(zoneId) != null); } - + private String getZoneName(long zoneId) { - DataCenterVO zone = _zoneDao.findById(new Long(zoneId)); - if (zone != null) { + DataCenterVO zone = _zoneDao.findById(new Long(zoneId)); + if (zone != null) { return zone.getName(); } else { return null; } } - + private String[] getLinkLocalIPRange() throws InvalidParameterValueException { - String ipNums = _configDao.getValue("linkLocalIp.nums"); - int nums = Integer.parseInt(ipNums); - if (nums > 16 || nums <= 0) { - throw new InvalidParameterValueException("The linkLocalIp.nums: " + nums + "is wrong, should be 1~16"); - } - /*local link ip address starts from 169.254.0.2 - 169.254.(nums)*/ - String[] ipRanges = NetUtils.getLinkLocalIPRange(nums); - if (ipRanges == null) { + String ipNums = _configDao.getValue("linkLocalIp.nums"); + int nums = Integer.parseInt(ipNums); + if (nums > 16 || nums <= 0) { + throw new InvalidParameterValueException("The linkLocalIp.nums: " + nums + "is wrong, should be 1~16"); + } + /* local link ip address starts from 169.254.0.2 - 169.254.(nums) */ + String[] ipRanges = NetUtils.getLinkLocalIPRange(nums); + if (ipRanges == null) { throw new InvalidParameterValueException("The linkLocalIp.nums: " + nums + "may be wrong, should be 1~16"); } - return ipRanges; + return ipRanges; } - @Override - public Configuration addConfig(CreateCfgCmd cmd){ - String category = cmd.getCategory(); - String instance = cmd.getInstance(); - String component = cmd.getComponent(); - String name = cmd.getConfigPropName(); - String value = cmd.getValue(); - String description = cmd.getDescription(); - try - { - ConfigurationVO entity = new ConfigurationVO(category, instance, component, name, value, description); - _configDao.persist(entity); - s_logger.info("Successfully added configuration value into db: category:"+category+" instance:"+instance+" component:"+component+" name:"+name+" value:"+value); - return _configDao.findByName(name); - } - catch(Exception ex) - { - s_logger.error("Unable to add the new config entry:",ex); - throw new CloudRuntimeException("Unable to add configuration parameter " + name); - } - } + @Override + public Configuration addConfig(CreateCfgCmd cmd) { + String category = cmd.getCategory(); + String instance = cmd.getInstance(); + String component = cmd.getComponent(); + String name = cmd.getConfigPropName(); + String value = cmd.getValue(); + String description = cmd.getDescription(); + try { + ConfigurationVO entity = new ConfigurationVO(category, instance, component, name, value, description); + _configDao.persist(entity); + s_logger.info("Successfully added configuration value into db: category:" + category + " instance:" + instance + " component:" + component + " name:" + name + " value:" + value); + return _configDao.findByName(name); + } catch (Exception ex) { + s_logger.error("Unable to add the new config entry:", ex); + throw new CloudRuntimeException("Unable to add configuration parameter " + name); + } + } - @Override - @ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_DELETE, eventDescription = "deleting vlan ip range", async = false) - public boolean deleteVlanIpRange(DeleteVlanIpRangeCmd cmd) throws InvalidParameterValueException { - Long vlanDbId = cmd.getId(); - Long userId = UserContext.current().getCallerUserId(); - - if (userId == null) { + @Override + @ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_DELETE, eventDescription = "deleting vlan ip range", async = false) + public boolean deleteVlanIpRange(DeleteVlanIpRangeCmd cmd) throws InvalidParameterValueException { + Long vlanDbId = cmd.getId(); + Long userId = UserContext.current().getCallerUserId(); + + if (userId == null) { userId = Long.valueOf(User.UID_SYSTEM); } - - VlanVO vlan = _vlanDao.findById(vlanDbId); + + VlanVO vlan = _vlanDao.findById(vlanDbId); if (vlan == null) { throw new InvalidParameterValueException("Please specify a valid IP range id."); } - return deleteVlanAndPublicIpRange(userId, vlanDbId); - - } + return deleteVlanAndPublicIpRange(userId, vlanDbId); - @Override + } + + @Override public void checkDiskOfferingAccess(Account caller, DiskOffering dof) throws PermissionDeniedException { for (SecurityChecker checker : _secChecker) { if (checker.checkAccess(caller, dof)) { @@ -2462,16 +2506,16 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura s_logger.debug("Access granted to " + caller + " to disk offering:" + dof.getId() + " by " + checker.getName()); } return; - }else{ - throw new PermissionDeniedException("Access denied to "+caller+" by "+checker.getName()); + } else { + throw new PermissionDeniedException("Access denied to " + caller + " by " + checker.getName()); } } - + assert false : "How can all of the security checkers pass on checking this caller?"; throw new PermissionDeniedException("There's no way to confirm " + caller + " has access to disk offering:" + dof.getId()); } - - @Override + + @Override public void checkServiceOfferingAccess(Account caller, ServiceOffering so) throws PermissionDeniedException { for (SecurityChecker checker : _secChecker) { if (checker.checkAccess(caller, so)) { @@ -2479,16 +2523,16 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura s_logger.debug("Access granted to " + caller + " to service offering:" + so.getId() + " by " + checker.getName()); } return; - }else{ - throw new PermissionDeniedException("Access denied to "+caller+" by "+checker.getName()); + } else { + throw new PermissionDeniedException("Access denied to " + caller + " by " + checker.getName()); } } - + assert false : "How can all of the security checkers pass on checking this caller?"; throw new PermissionDeniedException("There's no way to confirm " + caller + " has access to service offering:" + so.getId()); } - @Override + @Override public void checkAccess(Account caller, DataCenter zone) throws PermissionDeniedException { for (SecurityChecker checker : _secChecker) { if (checker.checkAccess(caller, zone)) { @@ -2496,17 +2540,15 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura s_logger.debug("Access granted to " + caller + " to zone:" + zone.getId() + " by " + checker.getName()); } return; - }else{ - throw new PermissionDeniedException("Access denied to "+caller+" by "+checker.getName()); + } else { + throw new PermissionDeniedException("Access denied to " + caller + " by " + checker.getName()); } } - + assert false : "How can all of the security checkers pass on checking this caller?"; throw new PermissionDeniedException("There's no way to confirm " + caller + " has access to zone:" + zone.getId()); } - - - + @Override public NetworkOffering createNetworkOffering(CreateNetworkOfferingCmd cmd) throws InvalidParameterValueException { Long userId = UserContext.current().getCallerUserId(); @@ -2517,13 +2559,12 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura Boolean specifyVlan = cmd.getSpecifyVlan(); String availabilityStr = cmd.getAvailability(); String guestIpTypeString = cmd.getGuestIpType(); - + TrafficType trafficType = null; GuestIpType guestIpType = null; Availability availability = null; - - - //Verify traffic type + + // Verify traffic type for (TrafficType tType : TrafficType.values()) { if (tType.name().equalsIgnoreCase(trafficTypeString)) { trafficType = tType; @@ -2533,28 +2574,26 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (trafficType == null) { throw new InvalidParameterValueException("Invalid value for traffictype. Supported traffic types: Public, Management, Control, Guest, Vlan or Storage"); } - - - //Verify guest ip type + + // Verify guest ip type for (GuestIpType gType : GuestIpType.values()) { if (gType.name().equalsIgnoreCase(guestIpTypeString)) { guestIpType = gType; break; } } - + if (guestIpType == null) { throw new InvalidParameterValueException("Invalid guest IP type; can have Direct or Virtual value"); } - - - //Verify availability + + // Verify availability for (Availability avlb : Availability.values()) { if (avlb.name().equalsIgnoreCase(availabilityStr)) { availability = avlb; } } - + if (availability == null) { throw new InvalidParameterValueException("Invalid value for Availability. Supported types: " + Availability.Required + ", " + Availability.Optional + ", " + Availability.Unavailable); } @@ -2562,41 +2601,42 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura Integer maxConnections = cmd.getMaxconnections(); return createNetworkOffering(userId, name, displayText, trafficType, tags, maxConnections, specifyVlan, availability, guestIpType); } - + @Override public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, Availability availability, GuestIpType guestIpType) { String networkRateStr = _configDao.getValue("network.throttling.rate"); String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr)); - int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); + int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); tags = cleanupTags(tags); - + boolean firewallService = false; boolean lbService = false; boolean vpnService = false; boolean gatewayService = false; - + if (trafficType == TrafficType.Guest) { firewallService = true; lbService = true; vpnService = true; gatewayService = true; } - - NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, false, specifyVlan, networkRate, multicastRate, maxConnections, false, availability, true, true, true, gatewayService, firewallService, lbService, vpnService, guestIpType); - + + NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, false, specifyVlan, networkRate, multicastRate, maxConnections, false, availability, true, true, true, gatewayService, firewallService, lbService, vpnService, + guestIpType); + if ((offering = _networkOfferingDao.persist(offering)) != null) { return offering; } else { return null; } } - + @Override public List searchForNetworkOfferings(ListNetworkOfferingsCmd cmd) { Filter searchFilter = new Filter(NetworkOfferingVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal()); SearchCriteria sc = _networkOfferingDao.createSearchCriteria(); - + Object id = cmd.getId(); Object name = cmd.getNetworkOfferingName(); Object displayText = cmd.getDisplayText(); @@ -2608,11 +2648,11 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura Object guestIpType = cmd.getGuestIpType(); Long zoneId = cmd.getZoneId(); DataCenter zone = null; - + if (zoneId != null) { zone = getZone(zoneId); } - + Object keyword = cmd.getKeyword(); if (keyword != null) { @@ -2621,82 +2661,82 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); sc.addAnd("name", SearchCriteria.Op.SC, ssc); - } + } if (id != null) { sc.addAnd("id", SearchCriteria.Op.EQ, id); } - + if (guestIpType != null) { sc.addAnd("guestType", SearchCriteria.Op.EQ, guestIpType); } - + if (name != null) { sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%"); } if (displayText != null) { sc.addAnd("displayText", SearchCriteria.Op.LIKE, "%" + displayText + "%"); } - + if (trafficType != null) { sc.addAnd("trafficType", SearchCriteria.Op.EQ, trafficType); } - + if (isDefault != null) { sc.addAnd("isDefault", SearchCriteria.Op.EQ, isDefault); } - + if (specifyVlan != null) { sc.addAnd("specifyVlan", SearchCriteria.Op.EQ, specifyVlan); } - + if (isShared != null) { sc.addAnd("isShared", SearchCriteria.Op.EQ, isShared); } - + if (availability != null) { sc.addAnd("availability", SearchCriteria.Op.EQ, availability); } - + if (zone != null) { if (zone.getNetworkType() == NetworkType.Basic) { - //return empty list as we don't allow to create networks in basic zone, and shouldn't display networkOfferings + // return empty list as we don't allow to create networks in basic zone, and shouldn't display networkOfferings return new ArrayList(); - } else if (zone.isSecurityGroupEnabled()){ + } else if (zone.isSecurityGroupEnabled()) { sc.addAnd("guestType", SearchCriteria.Op.EQ, GuestIpType.Direct); } } - - //Don't return system network offerings to the user + + // Don't return system network offerings to the user sc.addAnd("systemOnly", SearchCriteria.Op.EQ, false); - + return _networkOfferingDao.search(sc, searchFilter); } - + @Override - public boolean deleteNetworkOffering(DeleteNetworkOfferingCmd cmd) throws InvalidParameterValueException{ + public boolean deleteNetworkOffering(DeleteNetworkOfferingCmd cmd) throws InvalidParameterValueException { Long offeringId = cmd.getId(); - //Verify network offering id + // Verify network offering id NetworkOfferingVO offering = _networkOfferingDao.findById(offeringId); if (offering == null) { throw new InvalidParameterValueException("unable to find network offering " + offeringId); } else if (offering.getRemoved() != null || offering.isSystemOnly()) { throw new InvalidParameterValueException("unable to find network offering " + offeringId); } - - //Don't allow to delete default network offerings + + // Don't allow to delete default network offerings if (offering.isDefault() == true) { throw new InvalidParameterValueException("Default network offering can't be deleted"); } - + if (_networkOfferingDao.remove(offeringId)) { return true; } else { return false; } } - + @Override public NetworkOffering updateNetworkOffering(UpdateNetworkOfferingCmd cmd) { String displayText = cmd.getDisplayText(); @@ -2704,19 +2744,19 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura String name = cmd.getNetworkOfferingName(); String availabilityStr = cmd.getAvailability(); Availability availability = null; - + // Verify input parameters NetworkOfferingVO offeringToUpdate = _networkOfferingDao.findById(id); if (offeringToUpdate == null) { throw new InvalidParameterValueException("unable to find network offering " + id); } - - //Don't allow to update system network offering + + // Don't allow to update system network offering if (offeringToUpdate.isSystemOnly()) { throw new InvalidParameterValueException("Can't update system network offerings"); } - - //Don't allow to update default Direct network offering + + // Don't allow to update default Direct network offering if (offeringToUpdate.isDefault() && offeringToUpdate.getGuestType() == GuestIpType.Direct) { throw new InvalidParameterValueException("Can't update Default Direct network offering"); } @@ -2726,12 +2766,12 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (name != null) { offering.setName(name); } - + if (displayText != null) { offering.setDisplayText(displayText); } - //Verify availability + // Verify availability if (availabilityStr != null) { for (Availability avlb : Availability.values()) { if (avlb.name().equalsIgnoreCase(availabilityStr)) { @@ -2743,8 +2783,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } else { offering.setAvailability(availability); } - } - + } + if (_networkOfferingDao.update(id, offering)) { offering = _networkOfferingDao.findById(id); return offering; @@ -2752,11 +2792,11 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura return null; } } - - //Note: This method will be used for entity name validations in the coming releases (place holder for now) - private void validateEntityName(String str) throws InvalidParameterValueException{ - String forbidden = "~!@#$%^&*()+="; - char[] searchChars = forbidden.toCharArray(); + + // Note: This method will be used for entity name validations in the coming releases (place holder for now) + private void validateEntityName(String str) throws InvalidParameterValueException { + String forbidden = "~!@#$%^&*()+="; + char[] searchChars = forbidden.toCharArray(); if (str == null || str.length() == 0 || searchChars == null || searchChars.length == 0) { return; } @@ -2764,80 +2804,81 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura char ch = str.charAt(i); for (int j = 0; j < searchChars.length; j++) { if (searchChars[j] == ch) { - throw new InvalidParameterValueException("Name cannot contain any of the following special characters:"+forbidden); + throw new InvalidParameterValueException("Name cannot contain any of the following special characters:" + forbidden); } } } } - + @Override - public DataCenterVO getZone(long id){ + public DataCenterVO getZone(long id) { return _zoneDao.findById(id); } - + @Override public NetworkOffering getNetworkOffering(long id) { return _networkOfferingDao.findById(id); } - + @Override public Integer getNetworkRate(long networkOfferingId, Type vmType) { - - //validate network offering information + + // validate network offering information NetworkOffering no = getNetworkOffering(networkOfferingId); if (no == null) { throw new InvalidParameterValueException("Unable to find network offering by id=" + networkOfferingId); } - - //For router's public network we use networkRate from guestNetworkOffering + + // For router's public network we use networkRate from guestNetworkOffering if (vmType != null && vmType == VirtualMachine.Type.DomainRouter && no.getTrafficType() == TrafficType.Public && no.getGuestType() == null) { List guestOfferings = _networkOfferingDao.listByTrafficTypeAndGuestType(false, TrafficType.Guest, GuestIpType.Virtual); if (!guestOfferings.isEmpty()) { - //We have one default guest virtual network offering now + // We have one default guest virtual network offering now no = guestOfferings.get(0); } } - + Integer networkRate; if (no.getRateMbps() != null) { networkRate = no.getRateMbps(); } else { networkRate = Integer.parseInt(_configDao.getValue(Config.NetworkThrottlingRate.key())); } - - //networkRate is unsigned int in netowrkOfferings table, and can't be set to -1 - //so 0 means unlimited; we convert it to -1, so we are consistent with all our other resources where -1 means unlimited + + // networkRate is unsigned int in netowrkOfferings table, and can't be set to -1 + // so 0 means unlimited; we convert it to -1, so we are consistent with all our other resources where -1 means unlimited if (networkRate == 0) { networkRate = -1; } - + return networkRate; } - + @Override public Account getVlanAccount(long vlanId) { Vlan vlan = _vlanDao.findById(vlanId); Long accountId = null; - - //if vlan is Virtual Account specific, get vlan information from the accountVlanMap; otherwise get account information from the network + + // if vlan is Virtual Account specific, get vlan information from the accountVlanMap; otherwise get account information + // from the network if (vlan.getVlanType() == VlanType.VirtualNetwork) { List maps = _accountVlanMapDao.listAccountVlanMapsByVlan(vlanId); if (maps != null && !maps.isEmpty()) { return _accountMgr.getAccount(maps.get(0).getAccountId()); } } - + Long networkId = vlan.getNetworkId(); if (networkId != null) { Network network = _networkMgr.getNetwork(networkId); if (network != null) { - accountId = network.getAccountId(); + accountId = network.getAccountId(); } } - + return _accountMgr.getAccount(accountId); } - + @Override public List listNetworkOfferings(TrafficType trafficType, boolean systemOnly) { Filter searchFilter = new Filter(NetworkOfferingVO.class, "created", false, null, null); @@ -2846,11 +2887,12 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura sc.addAnd("trafficType", SearchCriteria.Op.EQ, trafficType); } sc.addAnd("systemOnly", SearchCriteria.Op.EQ, systemOnly); - + return _networkOfferingDao.search(sc, searchFilter); } - - @Override @DB + + @Override + @DB public boolean deleteAccountSpecificVirtualRanges(long accountId) { List maps = _accountVlanMapDao.listAccountVlanMapsByAccount(accountId); boolean result = true; @@ -2861,7 +2903,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (!deleteVlanAndPublicIpRange(_accountMgr.getSystemUser().getId(), map.getVlanDbId())) { result = false; } - } + } if (result) { txn.commit(); } else { @@ -2872,17 +2914,17 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } return result; } - + @Override public HostPodVO getPod(long id) { return _podDao.findById(id); } - + @Override public ClusterVO getCluster(long id) { return _clusterDao.findById(id); } - + private boolean allowIpRangeOverlap(VlanVO vlan, boolean forVirtualNetwork, long networkId) { Network vlanNetwork = _networkMgr.getNetwork(vlan.getNetworkId()); Network network = _networkMgr.getNetwork(networkId); @@ -2892,12 +2934,12 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura return false; } } - + @Override public ServiceOffering getServiceOffering(long serviceOfferingId) { return _serviceOfferingDao.findById(serviceOfferingId); } - + @Override public Long getDefaultPageSize() { return _defaultPageSize; From afd7adc77589f146089d7ac795fe60657362ed02 Mon Sep 17 00:00:00 2001 From: anthony Date: Thu, 31 Mar 2011 18:01:42 -0700 Subject: [PATCH 25/72] bug 9161: findByOutstandingWork means find all works with step not equal Done --- server/src/com/cloud/vm/ItWorkDaoImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/com/cloud/vm/ItWorkDaoImpl.java b/server/src/com/cloud/vm/ItWorkDaoImpl.java index 7168b0cd9ff..75987208e76 100644 --- a/server/src/com/cloud/vm/ItWorkDaoImpl.java +++ b/server/src/com/cloud/vm/ItWorkDaoImpl.java @@ -42,7 +42,7 @@ public class ItWorkDaoImpl extends GenericDaoBase implements I AllFieldsSearch = createSearchBuilder(); AllFieldsSearch.and("instance", AllFieldsSearch.entity().getInstanceId(), Op.EQ); AllFieldsSearch.and("op", AllFieldsSearch.entity().getType(), Op.EQ); - AllFieldsSearch.and("step", AllFieldsSearch.entity().getStep(), Op.EQ); + AllFieldsSearch.and("step", AllFieldsSearch.entity().getStep(), Op.NEQ); AllFieldsSearch.done(); CleanupSearch = createSearchBuilder(); From 2c8509231649c437c2cba9d08679034e77a03313 Mon Sep 17 00:00:00 2001 From: anthony Date: Thu, 31 Mar 2011 18:23:32 -0700 Subject: [PATCH 26/72] bug 9161: better fix --- server/src/com/cloud/vm/ItWorkDaoImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/com/cloud/vm/ItWorkDaoImpl.java b/server/src/com/cloud/vm/ItWorkDaoImpl.java index 75987208e76..a36c373ebda 100644 --- a/server/src/com/cloud/vm/ItWorkDaoImpl.java +++ b/server/src/com/cloud/vm/ItWorkDaoImpl.java @@ -42,7 +42,7 @@ public class ItWorkDaoImpl extends GenericDaoBase implements I AllFieldsSearch = createSearchBuilder(); AllFieldsSearch.and("instance", AllFieldsSearch.entity().getInstanceId(), Op.EQ); AllFieldsSearch.and("op", AllFieldsSearch.entity().getType(), Op.EQ); - AllFieldsSearch.and("step", AllFieldsSearch.entity().getStep(), Op.NEQ); + AllFieldsSearch.and("step", AllFieldsSearch.entity().getStep(), Op.EQ); AllFieldsSearch.done(); CleanupSearch = createSearchBuilder(); @@ -64,7 +64,7 @@ public class ItWorkDaoImpl extends GenericDaoBase implements I @Override public ItWorkVO findByOutstandingWork(long instanceId, State state) { - SearchCriteria sc = AllFieldsSearch.create(); + SearchCriteria sc = OutstandingWorkSearch.create(); sc.setParameters("instance", instanceId); sc.setParameters("op", state); sc.setParameters("step", Step.Done); From f3a5201ec83bd9f71f98f780e619536def880be4 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Thu, 31 Mar 2011 11:46:53 -0400 Subject: [PATCH 27/72] bug 8459: acpiphp and pci_hotplug modules need to be auto loaded in domr status 8459: resolved fixed --- .../debian/config/opt/cloud/bin/patchsystemvm.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/patches/systemvm/debian/config/opt/cloud/bin/patchsystemvm.sh b/patches/systemvm/debian/config/opt/cloud/bin/patchsystemvm.sh index 234c56940a6..70e7dce752e 100755 --- a/patches/systemvm/debian/config/opt/cloud/bin/patchsystemvm.sh +++ b/patches/systemvm/debian/config/opt/cloud/bin/patchsystemvm.sh @@ -69,6 +69,13 @@ dhcpsrvr_svcs() { echo "cloud nfs-common haproxy portmap" > /var/cache/cloud/disabled_svcs } +enable_pcihotplug() { + sed -i -e "/acpiphp/d" /etc/modules + sed -i -e "/pci_hotplug/d" /etc/modules + echo acpiphp >> /etc/modules + echo pci_hotplug >> /etc/modules +} + CMDLINE=$(cat /var/cache/cloud/cmdline) TYPE="router" PATCH_MOUNT=$1 @@ -101,6 +108,8 @@ fi #empty known hosts echo "" > /root/.ssh/known_hosts +enable_pcihotplug + if [ "$TYPE" == "router" ] then routing_svcs From bc54c68da68ce9980a128000338523f07d101cab Mon Sep 17 00:00:00 2001 From: Edison Su Date: Thu, 31 Mar 2011 18:48:53 -0400 Subject: [PATCH 28/72] enable serial console for system vm, to make debug easier --- .../config/etc/init.d/cloud-early-config | 3 ++- .../config/opt/cloud/bin/patchsystemvm.sh | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/patches/systemvm/debian/config/etc/init.d/cloud-early-config b/patches/systemvm/debian/config/etc/init.d/cloud-early-config index 7b402ec6755..ead55838a01 100755 --- a/patches/systemvm/debian/config/etc/init.d/cloud-early-config +++ b/patches/systemvm/debian/config/etc/init.d/cloud-early-config @@ -107,7 +107,8 @@ patch() { echo ${newmd5} > ${md5file} fi log_it "Patching cloud service" - /opt/cloud/bin/patchsystemvm.sh $PATCH_MOUNT + hyperVisor=$(hypervisor) + /opt/cloud/bin/patchsystemvm.sh $PATCH_MOUNT $hyperVisor umount $PATCH_MOUNT if [ "$shouldpatch" == "true" ] then diff --git a/patches/systemvm/debian/config/opt/cloud/bin/patchsystemvm.sh b/patches/systemvm/debian/config/opt/cloud/bin/patchsystemvm.sh index 70e7dce752e..9d9f3ed2768 100755 --- a/patches/systemvm/debian/config/opt/cloud/bin/patchsystemvm.sh +++ b/patches/systemvm/debian/config/opt/cloud/bin/patchsystemvm.sh @@ -76,9 +76,21 @@ enable_pcihotplug() { echo pci_hotplug >> /etc/modules } +enable_serial_console() { + sed -i -e "/^serial.*/d" /boot/grub/grub.conf + sed -i -e "/^terminal.*/d" /boot/grub/grub.conf + sed -i -e "/^default.*/a\serial --unit=0 --speed=115200 --parity=no --stop=1" /boot/grub/grub.conf + sed -i -e "/^serial.*/a\terminal --timeout=0 serial console" /boot/grub/grub.conf + sed -i -e "s/\(^kernel.* ro\) \(console.*\)/\1 console=tty0 console=ttyS0,115200n8/" /boot/grub/grub.conf + sed -i -e "/^s0:2345:respawn.*/d" /etc/inittab + sed -i -e "/6:23:respawn/a\s0:2345:respawn:/sbin/getty -L 115200 ttyS0 vt102" /etc/inittab +} + + CMDLINE=$(cat /var/cache/cloud/cmdline) TYPE="router" PATCH_MOUNT=$1 +Hypervisor=$2 for i in $CMDLINE do @@ -108,7 +120,11 @@ fi #empty known hosts echo "" > /root/.ssh/known_hosts -enable_pcihotplug +if [ "$Hypervisor" == "kvm" ] +then + enable_pcihotplug + enable_serial_console +fi if [ "$TYPE" == "router" ] then From 04626d820213a8f1130f77cd234145b6020516d5 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Thu, 31 Mar 2011 19:08:14 -0400 Subject: [PATCH 29/72] bug 9242: add vlan dependence for ubuntu, and set name type to DEV_PLUS_VID_NO_PAD, before creating vlan status 9242: resolved fixed --- debian/control | 2 +- scripts/vm/network/vnet/modifyvlan.sh | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/debian/control b/debian/control index fcca22abc28..04f89d07f5e 100644 --- a/debian/control +++ b/debian/control @@ -141,7 +141,7 @@ Provides: vmops-agent Conflicts: vmops-agent Replaces: vmops-agent Architecture: any -Depends: openjdk-6-jre, cloud-utils (= ${source:Version}), cloud-core (= ${source:Version}), cloud-deps (= ${source:Version}), python, cloud-python (= ${source:Version}), cloud-agent-libs (= ${source:Version}), cloud-agent-scripts (= ${source:Version}), libcommons-httpclient-java, libcommons-collections-java, libcommons-dbcp-java, libcommons-pool-java, libcommons-logging-java, libvirt0, cloud-daemonize, sysvinit-utils, chkconfig, qemu-kvm, libvirt-bin, cgroup-bin, augeas-tools, uuid-runtime, rsync, grep, iproute +Depends: openjdk-6-jre, cloud-utils (= ${source:Version}), cloud-core (= ${source:Version}), cloud-deps (= ${source:Version}), python, cloud-python (= ${source:Version}), cloud-agent-libs (= ${source:Version}), cloud-agent-scripts (= ${source:Version}), libcommons-httpclient-java, libcommons-collections-java, libcommons-dbcp-java, libcommons-pool-java, libcommons-logging-java, libvirt0, cloud-daemonize, sysvinit-utils, chkconfig, qemu-kvm, libvirt-bin, cgroup-bin, augeas-tools, uuid-runtime, rsync, grep, iproute, vlan Description: Cloud.com agent The Cloud.com agent is in charge of managing shared computing resources in a Cloud.com Cloud Stack-powered cloud. Install this package if this computer diff --git a/scripts/vm/network/vnet/modifyvlan.sh b/scripts/vm/network/vnet/modifyvlan.sh index 9396dc60b81..8a843ae9129 100755 --- a/scripts/vm/network/vnet/modifyvlan.sh +++ b/scripts/vm/network/vnet/modifyvlan.sh @@ -15,19 +15,21 @@ addVlan() { local pif=$2 local vlanDev=$pif.$vlanId local vlanBr=$VIRBR$vlanId - + + vconfig set_name_type DEV_PLUS_VID_NO_PAD + if [ ! -d /sys/class/net/$vlanDev ] then vconfig add $pif $vlanId > /dev/null if [ $? -gt 0 ] then - # race condition that someone already creates the vlan + # race condition that someone already creates the vlan if [ ! -d /sys/class/net/$vlanDev ] - then - printf "Failed to create vlan $vlanId on pif: $pif." - return 1 - fi + then + printf "Failed to create vlan $vlanId on pif: $pif." + return 1 + fi fi fi From 492dd78f1ca94e848c9e7cf850f420ad229868f4 Mon Sep 17 00:00:00 2001 From: prachi Date: Thu, 31 Mar 2011 23:04:17 -0700 Subject: [PATCH 30/72] Bug 9180 - Default local SR on XenServer won't be used - Update the diskoffering for system VMs to change the value of use_local_storage, when the global config 'system.vm.use.local.storage' is changed. --- .../ConfigurationManagerImpl.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 3d67d10ae22..2a519d01083 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -284,6 +284,36 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura s_logger.error("Failed to update configuration option, name: " + name + ", value:" + value); throw new CloudRuntimeException("Failed to update configuration value. Please contact Cloud Support."); } + + if(Config.SystemVMUseLocalStorage.key().equalsIgnoreCase(name)){ + if(s_logger.isDebugEnabled()){ + s_logger.debug("Config 'system.vm.use.local.storage' changed to value:" + value + ", need to update System VM offerings"); + } + boolean useLocalStorage = Boolean.parseBoolean(_configDao.getValue(Config.SystemVMUseLocalStorage.key())); + ServiceOfferingVO serviceOffering = _serviceOfferingDao.findByName("Cloud.com-ConsoleProxy"); + if(serviceOffering != null){ + serviceOffering.setUseLocalStorage(useLocalStorage); + if(!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)){ + s_logger.error("Failed to update ConsoleProxy offering's use_local_storage option to value:" + useLocalStorage); + } + } + + serviceOffering = _serviceOfferingDao.findByName("Cloud.Com-SoftwareRouter"); + if(serviceOffering != null){ + serviceOffering.setUseLocalStorage(useLocalStorage); + if(!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)){ + s_logger.error("Failed to update SoftwareRouter offering's use_local_storage option to value:" + useLocalStorage); + } + } + + serviceOffering = _serviceOfferingDao.findByName("Cloud.com-SecondaryStorage"); + if(serviceOffering != null){ + serviceOffering.setUseLocalStorage(useLocalStorage); + if(!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)){ + s_logger.error("Failed to update SecondaryStorage offering's use_local_storage option to value:" + useLocalStorage); + } + } + } } From 7f08061e7267b69b51b12a646064de6f8ab153b9 Mon Sep 17 00:00:00 2001 From: kishan Date: Thu, 31 Mar 2011 18:16:44 +0530 Subject: [PATCH 31/72] Added missing semi-colon and corrected usage unit test error messages --- .../com/cloud/upgrade/UsageEvents218To224UpgradeTest.java | 4 ++-- setup/db/db/schema-21to22.sql | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/test/com/cloud/upgrade/UsageEvents218To224UpgradeTest.java b/server/test/com/cloud/upgrade/UsageEvents218To224UpgradeTest.java index 15d6f5f7a4c..7f72559d5d8 100644 --- a/server/test/com/cloud/upgrade/UsageEvents218To224UpgradeTest.java +++ b/server/test/com/cloud/upgrade/UsageEvents218To224UpgradeTest.java @@ -74,8 +74,8 @@ public class UsageEvents218To224UpgradeTest extends TestCase { pstmt = conn.prepareStatement("SELECT COUNT(*) FROM usage_event"); rs = pstmt.executeQuery(); - assert rs.next() : "Unable to get the count of network offerings."; - assert (rs.getInt(1) == 37) : "Didn't find 7 network offerings but found " + rs.getInt(1); + assert rs.next() : "Unable to get the count of usage events"; + assert (rs.getInt(1) == 37) : "Didn't find 37 usage events but found " + rs.getInt(1); rs.close(); pstmt.close(); diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index cfd9f4e8bfd..b9e6bdd1680 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -568,7 +568,7 @@ DELETE FROM `cloud`.`sync_queue`; DELETE FROM `cloud`.`sync_queue_item`; DELETE FROM `cloud`.`async_job`; UPDATE `cloud`.`vm_template` SET unique_name='routing-xenserver-2.4',type='SYSTEM' WHERE name='systemvm-xenserver-2.4'; -DELETE FROM template_host_ref WHERE install_path LIKE '%xs-tools%' +DELETE FROM template_host_ref WHERE install_path LIKE '%xs-tools%'; DELETE FROM configuration where name='upgrade.url'; DELETE FROM configuration where name='router.template.id'; INSERT INTO configuration (category, instance, component, name, value, description) @@ -584,8 +584,8 @@ INSERT INTO vm_template (id, unique_name, name, public, created, type, hvm, bits VALUES (10, 'routing', 'SystemVM Template', 0, now(), 'ext3', 0, 64, 1, 'http://download.cloud.com/releases/2.2/systemvm.vhd.bz2', 'bcc7f290f4c27ab4d0fe95d1012829ea', 0, 'SystemVM Template', 'VHD', 15, 0, 1); Update configuration set name='storage.max.volume.size' where name='max.volume.size.mb'; INSERT INTO sequence (name, value) - VALUES ('snapshots_seq', '1') -UPDATE cloud.sequence SET value=IF((SELECT COUNT(*) FROM cloud.snapshots) > 0, (SELECT max(id) FROM cloud.snapshots) + 1, 1) WHERE name='snapshots_seq' + VALUES ('snapshots_seq', '1'); +UPDATE cloud.sequence SET value=IF((SELECT COUNT(*) FROM cloud.snapshots) > 0, (SELECT max(id) FROM cloud.snapshots) + 1, 1) WHERE name='snapshots_seq'; UPDATE configuration set name='direct.attach.security.groups.enabled' where name='direct.attach.network.groups.enabled'; UPDATE configuration set name='guest.domain.suffix' where name='domain.suffix'; @@ -608,4 +608,4 @@ ALTER TABLE `cloud`.`remote_access_vpn` ADD INDEX `i_remote_access_vpn_addr`(`vp ALTER TABLE `cloud`.`vpn_users` ADD CONSTRAINT `fk_vpn_users___account_id` FOREIGN KEY `fk_vpn_users__account_id` (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`vpn_users` ADD INDEX `i_vpn_users_username`(`username`); -ALTER TABLE `cloud`.`vpn_users` ADD UNIQUE `i_vpn_users__account_id__username`(`account_id`, `username`); \ No newline at end of file +ALTER TABLE `cloud`.`vpn_users` ADD UNIQUE `i_vpn_users__account_id__username`(`account_id`, `username`); From 7b55b41556c979f8f9bee3950d5f6688d595f688 Mon Sep 17 00:00:00 2001 From: kishan Date: Fri, 1 Apr 2011 15:15:00 +0530 Subject: [PATCH 32/72] bug 9239: Ignore optional zone Id for Snapshot delete events status 9239: resolved fixed --- server/src/com/cloud/upgrade/dao/Upgrade218to22.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java index 249c23453c8..cd8f1da99f2 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java @@ -1112,7 +1112,7 @@ public class Upgrade218to22 implements DbUpgrade { //Events not yet processed String sql = "SELECT type, description, user_id, account_id, created, level, parameters FROM cloud.event vmevt WHERE vmevt.id > ? and vmevt.state = 'Completed' "; if (lastProcessedEvent == null) { - System.out.println("no events are processed earlier, copying all events"); + s_logger.trace("no events are processed earlier, copying all events"); sql = "SELECT type, description, user_id, account_id, created, level, parameters FROM cloud.event vmevt WHERE vmevt.state = 'Completed' "; } @@ -1124,6 +1124,7 @@ public class Upgrade218to22 implements DbUpgrade { pstmt.setLong(i++, lastProcessedEvent); } ResultSet rs = pstmt.executeQuery(); + s_logger.trace("Begin Migrating events"); while (rs.next()) { EventVO event = new EventVO(); event.setType(rs.getString(1)); @@ -1184,6 +1185,9 @@ public class Upgrade218to22 implements DbUpgrade { }*/ if(usageEvent != null){ usageEvent.setCreatedDate(event.getCreateDate()); + if(usageEvent.getZoneId() == -1){ + usageEvent.setZoneId(0); + } //update firewall_rules table PreparedStatement pstmt = null; pstmt = conn.prepareStatement("INSERT INTO usage_event (usage_event.type, usage_event.created, usage_event.account_id, usage_event.zone_id, usage_event.resource_id, usage_event.resource_name," + From a8454ad0eb06ad1bd2577307ea7bc1d9c9c0e1b4 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Fri, 1 Apr 2011 09:33:37 -0700 Subject: [PATCH 33/72] bug 9259: why should destroyed be NULL to begin with. fix upgrade --- setup/db/db/schema-21to22.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index b9e6bdd1680..3539871c1b4 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -261,7 +261,7 @@ ALTER TABLE `cloud`.`volumes` MODIFY COLUMN `volume_type` VARCHAR(64) NOT NULL; ALTER TABLE `cloud`.`volumes` ADD COLUMN `state` VARCHAR(32); UPDATE `cloud`.`volumes` SET state='Destroyed' WHERE removed IS NOT NULL OR destroyed=1 OR status='Creating' OR status='Corrupted' OR status='Failed'; -UPDATE `cloud`.`volumes` SET state='Ready' WHERE removed IS NULL AND destroyed=0 AND status='Created'; +UPDATE `cloud`.`volumes` SET state='Ready' WHERE removed IS NULL AND (destroyed=0 OR destroyed is NULL) AND status='Created'; ALTER TABLE `cloud`.`volumes` MODIFY COLUMN `state` VARCHAR(32) NOT NULL; ALTER TABLE `cloud`.`vlan` ADD COLUMN `network_id` bigint unsigned NOT NULL; From d14b04f9a59870071599b1b94674f4e0b6609c9a Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Fri, 1 Apr 2011 09:41:26 -0700 Subject: [PATCH 34/72] bug 9259: removed some of the extra vpn statements duplicated from my change and chiradeep's change --- setup/db/db/schema-21to22.sql | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index 3539871c1b4..2532e77a309 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -599,13 +599,4 @@ INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (137, 4, ' ALTER TABLE `cloud`.`instance_group` ADD CONSTRAINT `fk_instance_group__account_id` FOREIGN KEY `fk_instance_group__account_id` (`account_id`) REFERENCES `account` (`id`); ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___group_id` FOREIGN KEY `fk_instance_group_vm_map___group_id` (`group_id`) REFERENCES `instance_group` (`id`) ON DELETE CASCADE; -ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___instance_id` FOREIGN KEY `fk_instance_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE; - -ALTER TABLE `cloud`.`remote_access_vpn` ADD CONSTRAINT `fk_remote_access_vpn___account_id` FOREIGN KEY `fk_remote_access_vpn__account_id` (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE; -ALTER TABLE `cloud`.`remote_access_vpn` ADD CONSTRAINT `fk_remote_access_vpn__zone_id` FOREIGN KEY `fk_remote_access_vpn__zone_id` (`zone_id`) REFERENCES `data_center` (`id`); -ALTER TABLE `cloud`.`remote_access_vpn` ADD CONSTRAINT `fk_remote_access_vpn__server_addr` FOREIGN KEY `fk_remote_access_vpn__server_addr` (`vpn_server_addr`) REFERENCES `user_ip_address` (`public_ip_address`); -ALTER TABLE `cloud`.`remote_access_vpn` ADD INDEX `i_remote_access_vpn_addr`(`vpn_server_addr`); - -ALTER TABLE `cloud`.`vpn_users` ADD CONSTRAINT `fk_vpn_users___account_id` FOREIGN KEY `fk_vpn_users__account_id` (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE; -ALTER TABLE `cloud`.`vpn_users` ADD INDEX `i_vpn_users_username`(`username`); -ALTER TABLE `cloud`.`vpn_users` ADD UNIQUE `i_vpn_users__account_id__username`(`account_id`, `username`); +ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___instance_id` FOREIGN KEY `fk_instance_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE; \ No newline at end of file From 420157071bbe7efb719c3ab3e16a64df73dda9d3 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Fri, 1 Apr 2011 09:55:42 -0700 Subject: [PATCH 35/72] bug 9259: added edison's changes as well --- setup/db/data-217to218.sql | 2 -- setup/db/db/schema-21to22.sql | 12 ++++++------ 2 files changed, 6 insertions(+), 8 deletions(-) delete mode 100755 setup/db/data-217to218.sql diff --git a/setup/db/data-217to218.sql b/setup/db/data-217to218.sql deleted file mode 100755 index 4be50209dc3..00000000000 --- a/setup/db/data-217to218.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'default.page.size', '500', 'Default page size for API list* commands'); -DELETE FROM `cloud`.`op_host_capacity` WHERE `capacity_type` in (2,6); diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index 2532e77a309..b706a0bd7c4 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -589,12 +589,12 @@ UPDATE cloud.sequence SET value=IF((SELECT COUNT(*) FROM cloud.snapshots) > 0, UPDATE configuration set name='direct.attach.security.groups.enabled' where name='direct.attach.network.groups.enabled'; UPDATE configuration set name='guest.domain.suffix' where name='domain.suffix'; -INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (132, 2, 'Debian GNU/Linux 6(32-bit)'); -INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (133, 2, 'Debian GNU/Linux 6(64-bit)'); -INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (134, 3, 'Oracle Enterprise Linux 5.5 (32-bit)'); -INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (135, 3, 'Oracle Enterprise Linux 5.5 (64-bit)'); -INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (136, 4, 'Red Hat Enterprise Linux 6.0 (32-bit)'); -INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (137, 4, 'Red Hat Enterprise Linux 6.0 (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (132, 2, 'Debian GNU/Linux 6(32-bit)', 'Debian GNU/Linux 6(32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (133, 2, 'Debian GNU/Linux 6(64-bit)', 'Debian GNU/Linux 6(64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (134, 3, 'Oracle Enterprise Linux 5.5 (32-bit)', 'Oracle Enterprise Linux 5.5 (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (135, 3, 'Oracle Enterprise Linux 5.5 (64-bit)', 'Oracle Enterprise Linux 5.5 (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (136, 4, 'Red Hat Enterprise Linux 6.0 (32-bit)', 'Red Hat Enterprise Linux 6.0 (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (137, 4, 'Red Hat Enterprise Linux 6.0 (64-bit)', 'Red Hat Enterprise Linux 6.0 (64-bit)'); ALTER TABLE `cloud`.`instance_group` ADD CONSTRAINT `fk_instance_group__account_id` FOREIGN KEY `fk_instance_group__account_id` (`account_id`) REFERENCES `account` (`id`); From 8b34065623ae0c48a855153c1eca9df2e723dee4 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Fri, 1 Apr 2011 10:32:23 -0700 Subject: [PATCH 36/72] bug 9259: added upgrade test suite --- .../com/cloud/upgrade/DbUpgrade22Test.java | 27 +++++++++++++++++++ setup/db/db/data-217to218.sql | 2 ++ 2 files changed, 29 insertions(+) create mode 100644 server/test/com/cloud/upgrade/DbUpgrade22Test.java create mode 100755 setup/db/db/data-217to218.sql diff --git a/server/test/com/cloud/upgrade/DbUpgrade22Test.java b/server/test/com/cloud/upgrade/DbUpgrade22Test.java new file mode 100644 index 00000000000..64432348520 --- /dev/null +++ b/server/test/com/cloud/upgrade/DbUpgrade22Test.java @@ -0,0 +1,27 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package com.cloud.upgrade; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({AdvanceZone217To224UpgradeTest.class, PortForwarding218To224UpgradeTest.class, InstanceGroup218To224UpgradeTest.class, BasicZone218To224UpgradeTest.class, UsageEvents218To224UpgradeTest.class}) +public class DbUpgrade22Test { + +} diff --git a/setup/db/db/data-217to218.sql b/setup/db/db/data-217to218.sql new file mode 100755 index 00000000000..4be50209dc3 --- /dev/null +++ b/setup/db/db/data-217to218.sql @@ -0,0 +1,2 @@ +INSERT INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'default.page.size', '500', 'Default page size for API list* commands'); +DELETE FROM `cloud`.`op_host_capacity` WHERE `capacity_type` in (2,6); From de2d650adf7d9762e32922d62d05d372fc793a5b Mon Sep 17 00:00:00 2001 From: Edison Su Date: Fri, 1 Apr 2011 10:58:37 -0400 Subject: [PATCH 37/72] fix db upgrade from 2.1.x to 2.2.1 --- setup/db/db/schema-21to22.sql | 371 +++++++++++++++++++++++++++++++++- 1 file changed, 364 insertions(+), 7 deletions(-) diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index b706a0bd7c4..66462f9750f 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -8,6 +8,8 @@ ALTER TABLE `cloud`.`vm_template` ADD COLUMN `extractable` int(1) unsigned NOT N ALTER TABLE `cloud`.`template_spool_ref` ADD CONSTRAINT `fk_template_spool_ref__template_id` FOREIGN KEY (`template_id`) REFERENCES `vm_template`(`id`); ALTER TABLE `cloud`.`template_spool_ref` ADD CONSTRAINT `fk_template_spool_ref__pool_id` FOREIGN KEY (`pool_id`) REFERENCES `storage_pool`(`id`) ON DELETE CASCADE; +ALTER TABLE `cloud`.`guest_os` modify `name` varchar(255) ; + -- NOTE for tables below; -- these 2 tables were used in 2.1, but are not in 2.2; -- we will need a migration script for these tables when the migration is written; @@ -245,6 +247,14 @@ CREATE TABLE `cloud`.`op_host` ( CONSTRAINT `fk_op_host__id` FOREIGN KEY (`id`) REFERENCES `host`(`id`) ON DELETE CASCADE ) ENGINE = InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `cloud`.`guest_os_hypervisor` ( + `id` bigint unsigned NOT NULL auto_increment, + `hypervisor_type` varchar(32) NOT NULL, + `guest_os_name` varchar(255) NOT NULL, + `guest_os_id` bigint unsigned NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; + INSERT INTO op_host(id, sequence) select id, sequence from host; -- Alter Tables to add Columns; @@ -589,14 +599,361 @@ UPDATE cloud.sequence SET value=IF((SELECT COUNT(*) FROM cloud.snapshots) > 0, UPDATE configuration set name='direct.attach.security.groups.enabled' where name='direct.attach.network.groups.enabled'; UPDATE configuration set name='guest.domain.suffix' where name='domain.suffix'; -INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (132, 2, 'Debian GNU/Linux 6(32-bit)', 'Debian GNU/Linux 6(32-bit)'); -INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (133, 2, 'Debian GNU/Linux 6(64-bit)', 'Debian GNU/Linux 6(64-bit)'); -INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (134, 3, 'Oracle Enterprise Linux 5.5 (32-bit)', 'Oracle Enterprise Linux 5.5 (32-bit)'); -INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (135, 3, 'Oracle Enterprise Linux 5.5 (64-bit)', 'Oracle Enterprise Linux 5.5 (64-bit)'); -INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (136, 4, 'Red Hat Enterprise Linux 6.0 (32-bit)', 'Red Hat Enterprise Linux 6.0 (32-bit)'); -INSERT INTO `cloud`.`guest_os` (id, category_id, name, display_name) VALUES (137, 4, 'Red Hat Enterprise Linux 6.0 (64-bit)', 'Red Hat Enterprise Linux 6.0 (64-bit)'); +INSERT INTO `cloud`.`guest_os_category` (id, name) VALUES (8, 'Novel'); +INSERT INTO `cloud`.`guest_os_category` (id, name) VALUES (9, 'Unix'); +INSERT INTO `cloud`.`guest_os_category` (id, name) VALUES (10, 'Ubuntu'); + +update `cloud`.`guest_os` set display_name = 'Debian GNU/Linux 5.0 (32-bit)' where id=15; +update `cloud`.`guest_os` set display_name = 'Windows Server 2003 (32-bit)' where id=50; +update `cloud`.`guest_os` set display_name = 'Windows Server 2003 (64-bit)' where id=51; +update `cloud`.`guest_os` set display_name = 'Windows Server 2008 (32-bit)' where id=52; +update `cloud`.`guest_os` set display_name = 'Windows Server 2008 (64-bit)' where id=53; +update `cloud`.`guest_os` set display_name = 'Other Ubuntu (32-bit)' where id=59; +update `cloud`.`guest_os` set display_name = 'Other (32-bit)' where id=60; +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (61, 6, 'Windows 2000 Server'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (62, 6, 'Windows 98'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (63, 6, 'Windows 95'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (64, 6, 'Windows NT 4'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (65, 6, 'Windows 3.1'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (66, 4, 'Red Hat Enterprise Linux 3(32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (67, 4, 'Red Hat Enterprise Linux 3(64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (68, 7, 'Open Enterprise Server'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (69, 7, 'Asianux 3(32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (70, 7, 'Asianux 3(64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (72, 2, 'Debian GNU/Linux 5(64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (73, 2, 'Debian GNU/Linux 4(32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (74, 2, 'Debian GNU/Linux 4(64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (75, 7, 'Other 2.6x Linux (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (76, 7, 'Other 2.6x Linux (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (77, 8, 'Novell Netware 6.x'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (78, 8, 'Novell Netware 5.1'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (79, 9, 'Sun Solaris 10(32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (80, 9, 'Sun Solaris 10(64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (81, 9, 'Sun Solaris 9(Experimental)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (82, 9, 'Sun Solaris 8(Experimental)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (83, 9, 'FreeBSD (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (84, 9, 'FreeBSD (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (85, 9, 'SCO OpenServer 5'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (86, 9, 'SCO UnixWare 7'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (87, 6, 'Windows Server 2003 DataCenter Edition(32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (88, 6, 'Windows Server 2003 DataCenter Edition(64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (89, 6, 'Windows Server 2003 Standard Edition(32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (90, 6, 'Windows Server 2003 Standard Edition(64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (91, 6, 'Windows Server 2003 Web Edition'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (92, 6, 'Microsoft Small Bussiness Server 2003'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (93, 6, 'Windows XP (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (94, 6, 'Windows XP (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (95, 6, 'Windows 2000 Advanced Server'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (96, 5, 'SUSE Linux Enterprise 8(32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (97, 5, 'SUSE Linux Enterprise 8(64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (98, 7, 'Other Linux (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (99, 7, 'Other Linux (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (100, 10, 'Other Ubuntu (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (101, 6, 'Windows Vista (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (102, 6, 'DOS'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (103, 7, 'Other (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (104, 7, 'OS/2'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (105, 6, 'Windows 2000 Professional'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (106, 4, 'Red Hat Enterprise Linux 4(64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (107, 5, 'SUSE Linux Enterprise 9(32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (108, 5, 'SUSE Linux Enterprise 9(64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (109, 5, 'SUSE Linux Enterprise 10(32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (110, 5, 'SUSE Linux Enterprise 10(64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (111, 1, 'CentOS 5.5 (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (112, 1, 'CentOS 5.5 (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (113, 4, 'Red Hat Enterprise Linux 5.5 (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (114, 4, 'Red Hat Enterprise Linux 5.5 (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (115, 4, 'Fedora 13'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (116, 4, 'Fedora 12'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (117, 4, 'Fedora 11'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (118, 4, 'Fedora 10'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (119, 4, 'Fedora 9'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (120, 4, 'Fedora 8'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (121, 10, 'Ubuntu 10.04 (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (122, 10, 'Ubuntu 9.10 (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (123, 10, 'Ubuntu 9.04 (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (124, 10, 'Ubuntu 8.10 (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (125, 10, 'Ubuntu 8.04 (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (126, 10, 'Ubuntu 10.04 (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (127, 10, 'Ubuntu 9.10 (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (128, 10, 'Ubuntu 9.04 (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (129, 10, 'Ubuntu 8.10 (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (130, 10, 'Ubuntu 8.04 (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (131, 10, 'Red Hat Enterprise Linux 2'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (132, 2, 'Debian GNU/Linux 6(32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (133, 2, 'Debian GNU/Linux 6(64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (134, 3, 'Oracle Enterprise Linux 5.5 (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (135, 3, 'Oracle Enterprise Linux 5.5 (64-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (136, 4, 'Red Hat Enterprise Linux 6.0 (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (137, 4, 'Red Hat Enterprise Linux 6.0 (64-bit)'); + +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'CentOS 4.5 (32-bit)', 1); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'CentOS 4.6 (32-bit)', 2); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'CentOS 4.7 (32-bit)', 3); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'CentOS 4.8 (32-bit)', 4); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'CentOS 5.0 (32-bit)', 5); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'CentOS 5.0 (64-bit)', 6); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'CentOS 5.1 (32-bit)', 7); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'CentOS 5.1 (32-bit)', 8); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'CentOS 5.2 (32-bit)', 9); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'CentOS 5.2 (64-bit)', 10); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'CentOS 5.3 (32-bit)', 11); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'CentOS 5.3 (64-bit)', 12); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'CentOS 5.4 (32-bit)', 13); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'CentOS 5.4 (64-bit)', 14); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Debian Lenny 5.0 (32-bit)', 15); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Oracle Enterprise Linux 5.0 (32-bit)', 16); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Oracle Enterprise Linux 5.0 (64-bit)', 17); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Oracle Enterprise Linux 5.1 (32-bit)', 18); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Oracle Enterprise Linux 5.1 (64-bit)', 19); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Oracle Enterprise Linux 5.2 (32-bit)', 20); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Oracle Enterprise Linux 5.2 (64-bit)', 21); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Oracle Enterprise Linux 5.3 (32-bit)', 22); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Oracle Enterprise Linux 5.3 (64-bit)', 23); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Oracle Enterprise Linux 5.4 (32-bit)', 24); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Oracle Enterprise Linux 5.4 (64-bit)', 25); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Red Hat Enterprise Linux 4.5 (32-bit)', 26); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Red Hat Enterprise Linux 4.6 (32-bit)', 27); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Red Hat Enterprise Linux 4.7 (32-bit)', 28); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Red Hat Enterprise Linux 4.8 (32-bit)', 29); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Red Hat Enterprise Linux 5.0 (32-bit)', 30); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Red Hat Enterprise Linux 5.0 (64-bit)', 31); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Red Hat Enterprise Linux 5.1 (32-bit)', 32); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Red Hat Enterprise Linux 5.1 (64-bit)', 33); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Red Hat Enterprise Linux 5.2 (32-bit)', 34); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Red Hat Enterprise Linux 5.2 (64-bit)', 35); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Red Hat Enterprise Linux 5.3 (32-bit)', 36); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Red Hat Enterprise Linux 5.3 (64-bit)', 37); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Red Hat Enterprise Linux 5.4 (32-bit)', 38); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Red Hat Enterprise Linux 5.4 (64-bit)', 39); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'SUSE Linux Enterprise Server 9 SP4 (32-bit)', 40); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'SUSE Linux Enterprise Server 10 SP1 (32-bit)', 41); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'SUSE Linux Enterprise Server 10 SP1 (64-bit)', 42); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'SUSE Linux Enterprise Server 10 SP2 (32-bit)', 43); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'SUSE Linux Enterprise Server 10 SP2 (64-bit)', 44); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'SUSE Linux Enterprise Server 10 SP3 (64-bit)', 45); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'SUSE Linux Enterprise Server 11 (32-bit)', 46); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'SUSE Linux Enterprise Server 11 (64-bit)', 47); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Windows 7 (32-bit)', 48); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Windows 7 (64-bit)', 49); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Windows Server 2003 (32-bit)', 50); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Windows Server 2003 (64-bit)', 51); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Windows Server 2008 (32-bit)', 52); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Windows Server 2008 (64-bit)', 53); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Windows Server 2008 R2 (64-bit)', 54); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Windows 2000 SP4 (32-bit)', 55); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Windows Vista (32-bit)', 56); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Windows XP SP2 (32-bit)', 57); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Windows XP SP3 (32-bit)', 58); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Other install media', 59); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Other install media', 100); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Other install media', 60); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("XenServer", 'Other install media', 103); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('XenServer', 'Other install media', 121); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('XenServer', 'Other install media', 126); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('XenServer', 'Other install media', 122); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('XenServer', 'Other install media', 127); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('XenServer', 'Other install media', 123); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('XenServer', 'Other install media', 128); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('XenServer', 'Other install media', 124); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('XenServer', 'Other install media', 129); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('XenServer', 'Other install media', 125); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('XenServer', 'Other install media', 130); + + +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows 7(32-bit)', 48); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows 7(64-bit)', 49); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows Server 2008 R2(64-bit)', 54); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows Server 2008(32-bit)', 52); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows Server 2008(64-bit)', 53); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows Server 2003, Enterprise Edition (32-bit)', 50); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows Server 2003, Enterprise Edition (64-bit)', 51); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows Server 2003, Datacenter Edition (32-bit)', 87); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows Server 2003, Datacenter Edition (64-bit)', 88); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows Server 2003, Standard Edition (32-bit)', 89); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows Server 2003, Standard Edition (64-bit)', 90); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows Server 2003, Web Edition', 91); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Small Bussiness Server 2003', 92); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows Vista (32-bit)', 56); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows Vista (64-bit)', 101); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows XP Professional (32-bit)', 93); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows XP Professional (32-bit)', 57); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows XP Professional (32-bit)', 58); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows XP Professional (64-bit)', 94); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows 2000 Advanced Server', 95); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows 2000 Server', 61); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows 2000 Professional', 105); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows 2000 Server', 55); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows 98', 62); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows 95', 63); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows NT 4', 64); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Microsoft Windows 3.1', 65); + +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 5(32-bit)', 30); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 5(32-bit)', 32); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 5(32-bit)', 34); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 5(32-bit)', 36); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 5(32-bit)', 38); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 5(64-bit)', 31); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 5(64-bit)', 33); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 5(64-bit)', 35); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 5(64-bit)', 37); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 5(64-bit)', 39); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 4(32-bit)', 26); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 4(32-bit)', 27); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 4(32-bit)', 28); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 4(32-bit)', 29); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 4(64-bit)', 106); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 3(32-bit)', 66); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 3(64-bit)', 67); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Red Hat Enterprise Linux 2', 131); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Suse Linux Enterprise 11(32-bit)', 46); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Suse Linux Enterprise 11(64-bit)', 47); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Suse Linux Enterprise 10(32-bit)', 41); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Suse Linux Enterprise 10(32-bit)', 43); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Suse Linux Enterprise 10(64-bit)', 42); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Suse Linux Enterprise 10(64-bit)', 44); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Suse Linux Enterprise 10(64-bit)', 45); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Suse Linux Enterprise 10(32-bit)', 109); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Suse Linux Enterprise 10(64-bit)', 110); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Suse Linux Enterprise 8/9(32-bit)', 40); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Suse Linux Enterprise 8/9(32-bit)', 96); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Suse Linux Enterprise 8/9(64-bit)', 97); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Suse Linux Enterprise 8/9(32-bit)', 107); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Suse Linux Enterprise 8/9(64-bit)', 108); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Open Enterprise Server', 68); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Asianux 3(32-bit)', 69); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Asianux 3(64-bit)', 70); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Debian GNU/Linux 5(32-bit)', 15); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Debian GNU/Linux 5(64-bit)', 72); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Debian GNU/Linux 4(32-bit)', 73); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Debian GNU/Linux 4(64-bit)', 74); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Ubuntu Linux (32-bit)', 59); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Ubuntu Linux (32-bit)', 121); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Ubuntu Linux (32-bit)', 122); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Ubuntu Linux (32-bit)', 123); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Ubuntu Linux (32-bit)', 124); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Ubuntu Linux (32-bit)', 125); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Ubuntu Linux (64-bit)', 100); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Ubuntu Linux (64-bit)', 126); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Ubuntu Linux (64-bit)', 127); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Ubuntu Linux (64-bit)', 128); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Ubuntu Linux (64-bit)', 129); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Ubuntu Linux (64-bit)', 130); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Other 2.6x Linux (32-bit)', 75); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Other 2.6x Linux (64-bit)', 76); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Other Linux (32-bit)', 98); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Other Linux (64-bit)', 99); + +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Novell Netware 6.x', 77); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Novell Netware 5.1', 78); + +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Sun Solaris 10(32-bit)', 79); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Sun Solaris 10(64-bit)', 80); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Sun Solaris 9(Experimental)', 81); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Sun Solaris 8(Experimental)', 82); + +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'FreeBSD (32-bit)', 83); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'FreeBSD (64-bit)', 84); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'OS/2', 104); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'SCO OpenServer 5', 85); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'SCO UnixWare 7', 86); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'DOS', 102); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Other (32-bit)', 60); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ("VmWare", 'Other (64-bit)', 103); + + + +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'CentOS 4.5', 1); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'CentOS 4.6', 2); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'CentOS 4.7', 3); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'CentOS 4.8', 4); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'CentOS 5.0', 5); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'CentOS 5.0', 6); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'CentOS 5.1', 7); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'CentOS 5.1', 8); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'CentOS 5.2', 9); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'CentOS 5.2', 10); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'CentOS 5.3', 11); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'CentOS 5.3', 12); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'CentOS 5.4', 13); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'CentOS 5.4', 14); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'CentOS 5.5', 111); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'CentOS 5.5', 112); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 4.5', 26); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 4.6', 27); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 4.7', 28); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 4.8', 29); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 5.0', 30); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 5.0', 31); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 5.1', 32); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 5.1', 33); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 5.2', 34); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 5.2', 35); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 5.3', 36); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 5.3', 37); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 5.4', 38); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 5.4', 39); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 5.5', 113); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 5.5', 114); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 4', 106); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 3', 66); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 3', 67); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Red Hat Enterprise Linux 2', 131); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Fedora 13', 115); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Fedora 12', 116); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Fedora 11', 117); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Fedora 10', 118); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Fedora 9', 119); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Fedora 8', 120); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Ubuntu 10.04', 121); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Ubuntu 10.04', 126); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Ubuntu 9.10', 122); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Ubuntu 9.10', 127); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Ubuntu 9.04', 123); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Ubuntu 9.04', 128); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Ubuntu 8.10', 124); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Ubuntu 8.10', 129); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Ubuntu 8.04', 125); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Ubuntu 8.04', 130); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Debian GNU/Linux 5', 15); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Debian GNU/Linux 5', 72); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Debian GNU/Linux 4', 73); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Debian GNU/Linux 4', 74); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Other Linux 2.6x', 75); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Other Linux 2.6x', 76); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Other Ubuntu', 59); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Other Ubuntu', 100); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Other Linux', 98); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Other Linux', 99); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows 7', 48); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows 7', 49); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows Server 2003', 50); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows Server 2003', 51); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows Server 2003', 87); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows Server 2003', 88); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows Server 2003', 89); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows Server 2003', 90); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows Server 2003', 91); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows Server 2003', 92); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows Server 2008', 52); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows Server 2008', 53); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows 2000', 55); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows 2000', 61); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows 2000', 95); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows 98', 62); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows Vista', 56); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows Vista', 101); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows XP SP2', 57); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows XP SP3', 58); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows XP ', 93); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Windows XP ', 94); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'DOS', 102); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Other', 60); +INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Other', 103); + ALTER TABLE `cloud`.`instance_group` ADD CONSTRAINT `fk_instance_group__account_id` FOREIGN KEY `fk_instance_group__account_id` (`account_id`) REFERENCES `account` (`id`); ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___group_id` FOREIGN KEY `fk_instance_group_vm_map___group_id` (`group_id`) REFERENCES `instance_group` (`id`) ON DELETE CASCADE; -ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___instance_id` FOREIGN KEY `fk_instance_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE; \ No newline at end of file +ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___instance_id` FOREIGN KEY `fk_instance_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE; From f14be911678d9e6488f800593bf66c32ae0197c6 Mon Sep 17 00:00:00 2001 From: Kelven Yang Date: Fri, 1 Apr 2011 14:13:17 -0700 Subject: [PATCH 38/72] Apply changes in FOSS because of prioprietary merges --- .../com/cloud/utils/exception/ExceptionUtil.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/utils/src/com/cloud/utils/exception/ExceptionUtil.java b/utils/src/com/cloud/utils/exception/ExceptionUtil.java index 9c494a249a7..7a85901acc5 100644 --- a/utils/src/com/cloud/utils/exception/ExceptionUtil.java +++ b/utils/src/com/cloud/utils/exception/ExceptionUtil.java @@ -22,12 +22,19 @@ import java.io.StringWriter; public class ExceptionUtil { public static String toString(Throwable th) { + return toString(th, true); + } + + public static String toString(Throwable th, boolean printStack) { final StringWriter writer = new StringWriter(); writer.append("Exception: " + th.getClass().getName() + "\n"); writer.append("Message: "); - writer.append(th.getMessage()); - writer.append("\n Stack: "); - th.printStackTrace(new PrintWriter(writer)); + writer.append(th.getMessage()).append("\n"); + + if(printStack) { + writer.append("Stack: "); + th.printStackTrace(new PrintWriter(writer)); + } return writer.toString(); } } From 8161964bc2007c9ba7e0691f31a7a29137d03aa0 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Fri, 1 Apr 2011 14:21:19 -0400 Subject: [PATCH 39/72] fix db upgrade error --- setup/db/db/schema-21to22.sql | 8 -------- 1 file changed, 8 deletions(-) diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index 66462f9750f..cb34fe53dbd 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -409,14 +409,6 @@ CREATE TABLE `cloud`.`vpn_users` ( ALTER TABLE `cloud`.`storage_pool` ADD COLUMN `status` varchar(32); -CREATE TABLE `cloud`.`guest_os_hypervisor` ( - `id` bigint unsigned NOT NULL auto_increment, - `hypervisor_type` varchar(32) NOT NULL, - `guest_os_name` varchar(255) NOT NULL, - `guest_os_id` bigint unsigned NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; - --drop network group related constraints/indexes; ALTER TABLE `cloud`.`network_group` drop foreign key `fk_network_group__domain_id`; alter table `cloud`.`network_group` drop index `i_network_group_name`; From ab862026d6b604e49b50bed663bbfee80593de14 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Fri, 1 Apr 2011 17:15:05 -0400 Subject: [PATCH 40/72] fix link local setup; --- .../agent/resource/virtualnetwork/VirtualRoutingResource.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java index e0056586ab0..314f26c0064 100755 --- a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java @@ -464,14 +464,14 @@ public class VirtualRoutingResource implements Manager { } } if (!foundLinkLocalBr) { - Script.runSimpleBashScript("ip route add " + NetUtils.getLinkLocalCIDR() + " dev " + linkLocalBr + " src " + NetUtils.getLinkLocalGateway()); + Script.runSimpleBashScript("ifconfig " + linkLocalBr + " 169.254.0.1;" + "ip route add " + NetUtils.getLinkLocalCIDR() + " dev " + linkLocalBr + " src " + NetUtils.getLinkLocalGateway()); } } public void createControlNetwork(String privBrName) { deletExitingLinkLocalRoutTable(privBrName); if (!isBridgeExists(privBrName)) { - Script.runSimpleBashScript("brctl addbr " + privBrName + "; ifconfig " + privBrName + " up;", _timeout); + Script.runSimpleBashScript("brctl addbr " + privBrName + "; ifconfig " + privBrName + " up; ifconfig " + privBrName + " 169.254.0.1", _timeout); } } From 29bfde9da41a8a854c3998eb1be75e443615b907 Mon Sep 17 00:00:00 2001 From: alena Date: Fri, 1 Apr 2011 17:53:06 -0700 Subject: [PATCH 41/72] Revert "bug 8898: allow service offering upgrade for Running vm" This reverts commit 7668e1878acea6f380e167338248f1f3f8affca0. --- server/src/com/cloud/vm/UserVmManagerImpl.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 266c29cda2f..99f16afc1ca 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -842,10 +842,10 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager throw new InvalidParameterValueException("Unable to find a service offering with id " + serviceOfferingId); } - // Check that the VM is stopped or running - if (!(vmInstance.getState().equals(State.Stopped) || vmInstance.getState().equals(State.Running))) { + // Check that the VM is stopped + if (!vmInstance.getState().equals(State.Stopped)) { s_logger.warn("Unable to upgrade virtual machine " + vmInstance.toString() + " in state " + vmInstance.getState()); - throw new InvalidParameterValueException("Unable to upgrade virtual machine " + vmInstance.toString() + " in state " + vmInstance.getState() + "; make sure the virtual machine is in Stopped or Running state before upgrading."); + throw new InvalidParameterValueException("Unable to upgrade virtual machine " + vmInstance.toString() + " in state " + vmInstance.getState() + "; make sure the virtual machine is stopped and not in an error state before upgrading."); } // Check if the service offering being upgraded to is what the VM is already running with @@ -2527,9 +2527,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager UserVO user = _userDao.findById(userId); try { - if (!_itMgr.advanceStop(vm, forced, user, caller)) { - throw new CloudRuntimeException("Unable to stop vm " + vm); - } + _itMgr.advanceStop(vm, forced, user, caller); } catch (ResourceUnavailableException e) { throw new CloudRuntimeException("Unable to contact the agent to stop the virtual machine " + vm, e); } catch (OperationTimedoutException e) { From 4f97d4652d21536887bb1b26edcc24af3f35bd9b Mon Sep 17 00:00:00 2001 From: kishan Date: Mon, 4 Apr 2011 18:30:16 +0530 Subject: [PATCH 42/72] Skip event migration when usage db doesn't exist --- .../com/cloud/upgrade/dao/Upgrade218to22.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java index cd8f1da99f2..c9d1df42221 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java @@ -1107,16 +1107,23 @@ public class Upgrade218to22 implements DbUpgrade { private void migrateEvents(Connection conn){ try { - //get last processed event Id - Long lastProcessedEvent = getMostRecentEvent(conn); - //Events not yet processed - String sql = "SELECT type, description, user_id, account_id, created, level, parameters FROM cloud.event vmevt WHERE vmevt.id > ? and vmevt.state = 'Completed' "; - if (lastProcessedEvent == null) { - s_logger.trace("no events are processed earlier, copying all events"); - sql = "SELECT type, description, user_id, account_id, created, level, parameters FROM cloud.event vmevt WHERE vmevt.state = 'Completed' "; - } + PreparedStatement pstmt1 = conn.prepareStatement("SHOW DATABASES LIKE 'cloud_usage'"); + ResultSet rs1 = pstmt1.executeQuery(); + if (!rs1.next()) { + s_logger.debug("cloud_usage db doesn't exist. Skipping events migration"); + return; + } - PreparedStatement pstmt = null; + //get last processed event Id + Long lastProcessedEvent = getMostRecentEvent(conn); + //Events not yet processed + String sql = "SELECT type, description, user_id, account_id, created, level, parameters FROM cloud.event vmevt WHERE vmevt.id > ? and vmevt.state = 'Completed' "; + if (lastProcessedEvent == null) { + s_logger.trace("no events are processed earlier, copying all events"); + sql = "SELECT type, description, user_id, account_id, created, level, parameters FROM cloud.event vmevt WHERE vmevt.state = 'Completed' "; + } + + PreparedStatement pstmt = null; pstmt = conn.prepareStatement(sql); int i = 1; @@ -1124,7 +1131,7 @@ public class Upgrade218to22 implements DbUpgrade { pstmt.setLong(i++, lastProcessedEvent); } ResultSet rs = pstmt.executeQuery(); - s_logger.trace("Begin Migrating events"); + s_logger.debug("Begin Migrating events"); while (rs.next()) { EventVO event = new EventVO(); event.setType(rs.getString(1)); @@ -1136,9 +1143,8 @@ public class Upgrade218to22 implements DbUpgrade { event.setParameters(rs.getString(7)); convertEvent(event, conn); } - s_logger.trace("Migrating events completed"); + s_logger.debug("Migrating events completed"); } catch (Exception e) { - System.out.println("Error: "+e.getMessage()); throw new CloudRuntimeException("Failed to migrate usage events: ", e); } } From 380c275d54f51dcb404f120512a71eb4ee01b0d5 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 4 Apr 2011 09:26:42 -0700 Subject: [PATCH 43/72] bug 9290: fixed default to be 0 bug 9289: dropped domain column --- setup/db/db/schema-21to22-cleanup.sql | 1 + setup/db/db/schema-21to22.sql | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/setup/db/db/schema-21to22-cleanup.sql b/setup/db/db/schema-21to22-cleanup.sql index 045caec3879..a595fa09e85 100644 --- a/setup/db/db/schema-21to22-cleanup.sql +++ b/setup/db/db/schema-21to22-cleanup.sql @@ -62,6 +62,7 @@ ALTER TABLE `cloud`.`domain_router` DROP COLUMN `vlan_id`; ALTER TABLE `cloud`.`domain_router` DROP COLUMN `domain_id`; ALTER TABLE `cloud`.`domain_router` DROP COLUMN `account_id`; ALTER TABLE `cloud`.`domain_router` DROP COLUMN `dhcp_ip_address`; +ALTER TABLE `cloud`.`domain_router` DROP COLUMN `domain`; ALTER TABLE `cloud`.`console_proxy` DROP FOREIGN KEY `fk_console_proxy__vlan_id`; ALTER TABLE `cloud`.`console_proxy` DROP INDEX `i_console_proxy__vlan_id`; diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index cb34fe53dbd..d15112c8753 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -339,7 +339,7 @@ CREATE TABLE `cloud`.`user_vm_details` ( ALTER TABLE `cloud`.`domain_router` MODIFY COLUMN `guest_netmask` varchar(15); ALTER TABLE `cloud`.`domain_router` MODIFY COLUMN `guest_ip_address` varchar(15); -ALTER TABLE `cloud`.`domain_router` ADD COLUMN `network_id` bigint unsigned NOT NULL; +ALTER TABLE `cloud`.`domain_router` ADD COLUMN `network_id` bigint unsigned NOT NULL DEFAULT 0; CREATE TABLE `cloud`.`upload` ( `id` bigint unsigned NOT NULL auto_increment, From 2dc5616766efb54f1edd9dd429165f125a9cf1f9 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 4 Apr 2011 09:39:08 -0700 Subject: [PATCH 44/72] =?UTF-8?q?bug=209287=EF=BC=9A=20change=20the=20name?= =?UTF-8?q?s=20of=20the=20system=20service=20offerings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup/db/db/schema-21to22.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index d15112c8753..401678bc4f2 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -372,6 +372,9 @@ ALTER TABLE `cloud`.`disk_offering` ADD COLUMN `system_use` tinyint(1) unsigned ALTER TABLE `cloud`.`disk_offering` ADD COLUMN `customized` tinyint(1) unsigned NOT NULL DEFAULT 0; update `cloud`.`disk_offering` set system_use=1, removed=null WHERE unique_name like 'Cloud.Com-%'; +update `cloud`.`disk_offering` set name='System Offering For Console Proxy' where name='Fake Offering For DomP' and system_use=1; +update `cloud`.`disk_offering` set name='System Offering For Software Router' where name='Fake Offering For DomR' and system_use=1; +update `cloud`.`disk_offering` set name='System Offering For Secondary Storage VM' where name='Fake Offering For Secondary Storage VM' and system_use=1; ALTER TABLE `cloud`.`user_statistics` ADD COLUMN `public_ip_address` varchar(15) DEFAULT NULL; ALTER TABLE `cloud`.`user_statistics` ADD COLUMN `device_id` bigint unsigned NOT NULL; From 5a6d3dc55c5487c4a1c03c50961e313fb556fc6c Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 4 Apr 2011 09:50:16 -0700 Subject: [PATCH 45/72] bug 9280: added gateway and cidr for control network --- .../com/cloud/upgrade/dao/Upgrade218to22.java | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java index c9d1df42221..f89401ee829 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java @@ -39,7 +39,6 @@ import com.cloud.event.EventTypes; import com.cloud.event.EventVO; import com.cloud.event.UsageEventVO; import com.cloud.utils.DateUtil; -import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; import com.cloud.utils.script.Script; @@ -728,7 +727,7 @@ public class Upgrade218to22 implements DbUpgrade { Long dcId = (Long)dc[0]; long mgmtNetworkId = insertNetwork(conn, "ManagementNetwork" + dcId, "Management Network created for Zone " + dcId, "Management", "Native", null, null, null, "Static", managementNetworkOfferingId, dcId, "PodBasedNetworkGuru", "Setup", 1, 1, null, null, null, true, null, false, null); long storageNetworkId = insertNetwork(conn, "StorageNetwork" + dcId, "Storage Network created for Zone " + dcId, "Storage", "Native", null, null, null, "Static", storageNetworkOfferingId, dcId, "PodBasedNetworkGuru", "Setup", 1, 1, null, null, null, true, null, false, null); - long controlNetworkId = insertNetwork(conn, "ControlNetwork" + dcId, "Control Network created for Zone " + dcId, "Control", "Native", null, null, null, "Static", controlNetworkOfferingId, dcId, "ControlNetworkGuru", "Setup", 1, 1, null, null, null, true, null, false, null); + long controlNetworkId = insertNetwork(conn, "ControlNetwork" + dcId, "Control Network created for Zone " + dcId, "Control", "Native", null, NetUtils.getLinkLocalGateway(), NetUtils.getLinkLocalCIDR(), "Static", controlNetworkOfferingId, dcId, "ControlNetworkGuru", "Setup", 1, 1, null, null, null, true, null, false, null); upgradeManagementIpAddress(conn, dcId); long basicDefaultDirectNetworkId = insertNetwork(conn, "BasicZoneDirectNetwork" + dcId, "Basic Zone Direct Network created for Zone " + dcId, "Guest", "Native", null, null, null, "Dhcp", 5, dcId, "DirectPodBasedNetworkGuru", "Setup", 1, 1, null, null, "Direct", true, null, true, null); @@ -1226,43 +1225,57 @@ public class Upgrade218to22 implements DbUpgrade { } private boolean isVMEvent(String eventType) { - if (eventType == null) return false; + if (eventType == null) { + return false; + } return eventType.startsWith("VM."); } private boolean isIPEvent(String eventType) { - if (eventType == null) return false; + if (eventType == null) { + return false; + } return eventType.startsWith("NET.IP"); } private boolean isVolumeEvent(String eventType) { - if (eventType == null) return false; + if (eventType == null) { + return false; + } return (eventType.equals(EventTypes.EVENT_VOLUME_CREATE) || eventType.equals(EventTypes.EVENT_VOLUME_DELETE)); } private boolean isTemplateEvent(String eventType) { - if (eventType == null) return false; + if (eventType == null) { + return false; + } return (eventType.equals(EventTypes.EVENT_TEMPLATE_CREATE) || eventType.equals(EventTypes.EVENT_TEMPLATE_COPY) || eventType.equals(EventTypes.EVENT_TEMPLATE_DELETE)); } private boolean isISOEvent(String eventType) { - if (eventType == null) return false; + if (eventType == null) { + return false; + } return (eventType.equals(EventTypes.EVENT_ISO_CREATE) || eventType.equals(EventTypes.EVENT_ISO_COPY) || eventType.equals(EventTypes.EVENT_ISO_DELETE)); } private boolean isSnapshotEvent(String eventType) { - if (eventType == null) return false; + if (eventType == null) { + return false; + } return (eventType.equals(EventTypes.EVENT_SNAPSHOT_CREATE) || eventType.equals(EventTypes.EVENT_SNAPSHOT_DELETE)); } private boolean isLoadBalancerEvent(String eventType) { - if (eventType == null) return false; + if (eventType == null) { + return false; + } return eventType.startsWith("LB."); } @@ -1321,7 +1334,10 @@ public class Upgrade218to22 implements DbUpgrade { } } isSourceNat = Boolean.parseBoolean(ipEventParams.getProperty("sourceNat")); - if (isSourceNat) return null; // skip source nat IP addresses as we don't charge for them + if (isSourceNat) + { + return null; // skip source nat IP addresses as we don't charge for them + } if (EventTypes.EVENT_NET_IP_ASSIGN.equals(event.getType())) { long zoneId = Long.parseLong(ipEventParams.getProperty("dcId")); From a93ebd21d225d0aa7243e262bc889381ab0e535f Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 4 Apr 2011 09:53:36 -0700 Subject: [PATCH 46/72] bug 9281: fixed account_id can be null in db --- setup/db/db/schema-21to22-cleanup.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup/db/db/schema-21to22-cleanup.sql b/setup/db/db/schema-21to22-cleanup.sql index a595fa09e85..bccdd1b1f33 100644 --- a/setup/db/db/schema-21to22-cleanup.sql +++ b/setup/db/db/schema-21to22-cleanup.sql @@ -99,3 +99,5 @@ ALTER TABLE `cloud`.`service_offering` DROP COLUMN `guest_ip_type`; ALTER TABLE `cloud`.`load_balancer_vm_map` DROP COLUMN `pending`; +ALTER TABLE `cloud`.`account_vlan_map` ALTER COLUMN `account_id` bigint unsigned NOT NULL; + From fc7f52609015cc8a40b210008c37f2573c414536 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 4 Apr 2011 09:56:56 -0700 Subject: [PATCH 47/72] bug 9282: changed the broadcast domain type for control and public network --- server/src/com/cloud/upgrade/dao/Upgrade218to22.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java index f89401ee829..e9017ba50d7 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java @@ -727,7 +727,7 @@ public class Upgrade218to22 implements DbUpgrade { Long dcId = (Long)dc[0]; long mgmtNetworkId = insertNetwork(conn, "ManagementNetwork" + dcId, "Management Network created for Zone " + dcId, "Management", "Native", null, null, null, "Static", managementNetworkOfferingId, dcId, "PodBasedNetworkGuru", "Setup", 1, 1, null, null, null, true, null, false, null); long storageNetworkId = insertNetwork(conn, "StorageNetwork" + dcId, "Storage Network created for Zone " + dcId, "Storage", "Native", null, null, null, "Static", storageNetworkOfferingId, dcId, "PodBasedNetworkGuru", "Setup", 1, 1, null, null, null, true, null, false, null); - long controlNetworkId = insertNetwork(conn, "ControlNetwork" + dcId, "Control Network created for Zone " + dcId, "Control", "Native", null, NetUtils.getLinkLocalGateway(), NetUtils.getLinkLocalCIDR(), "Static", controlNetworkOfferingId, dcId, "ControlNetworkGuru", "Setup", 1, 1, null, null, null, true, null, false, null); + long controlNetworkId = insertNetwork(conn, "ControlNetwork" + dcId, "Control Network created for Zone " + dcId, "Control", "LinkLocal", null, NetUtils.getLinkLocalGateway(), NetUtils.getLinkLocalCIDR(), "Static", controlNetworkOfferingId, dcId, "ControlNetworkGuru", "Setup", 1, 1, null, null, null, true, null, false, null); upgradeManagementIpAddress(conn, dcId); long basicDefaultDirectNetworkId = insertNetwork(conn, "BasicZoneDirectNetwork" + dcId, "Basic Zone Direct Network created for Zone " + dcId, "Guest", "Native", null, null, null, "Dhcp", 5, dcId, "DirectPodBasedNetworkGuru", "Setup", 1, 1, null, null, "Direct", true, null, true, null); @@ -790,7 +790,7 @@ public class Upgrade218to22 implements DbUpgrade { long storageNetworkId = insertNetwork(conn, "StorageNetwork" + dcId, "Storage Network created for Zone " + dcId, "Storage", "Native", null, null, null, "Static", storageNetworkOfferingId, dcId, "PodBasedNetworkGuru", "Setup", 1, 1, null, null, null, true, null, false, null); long controlNetworkId = insertNetwork(conn, "ControlNetwork" + dcId, "Control Network created for Zone " + dcId, "Control", "Native", null, null, null, "Static", controlNetworkOfferingId, dcId, "ControlNetworkGuru", "Setup", 1, 1, null, null, null, true, null, false, null); upgradeManagementIpAddress(conn, dcId); - long publicNetworkId = insertNetwork(conn, "PublicNetwork" + dcId, "Public Network Created for Zone " + dcId, "Public", "Native", null, null, null, "Static", publicNetworkOfferingId, dcId, "PublicNetworkGuru", "Setup", 1,1, null, null, null, true, null, false, null); + long publicNetworkId = insertNetwork(conn, "PublicNetwork" + dcId, "Public Network Created for Zone " + dcId, "Public", "Vlan", null, null, null, "Static", publicNetworkOfferingId, dcId, "PublicNetworkGuru", "Setup", 1,1, null, null, null, true, null, false, null); pstmt = conn.prepareStatement("SELECT vm_instance.id, vm_instance.domain_id, vm_instance.account_id, domain_router.guest_ip_address, domain_router.domain, domain_router.dns1, domain_router.dns2, domain_router.vnet FROM vm_instance INNER JOIN domain_router ON vm_instance.id=domain_router.id WHERE vm_instance.removed IS NULL AND vm_instance.type='DomainRouter' AND vm_instance.data_center_id=?"); pstmt.setLong(1, dcId); From 90dd395cf70a27f20f465fdf7cd0bcbf2b5e85d6 Mon Sep 17 00:00:00 2001 From: will Date: Mon, 4 Apr 2011 10:02:36 -0700 Subject: [PATCH 48/72] bug 8816: Added link local IP to the system VM UI merge from master --- client/WEB-INF/classes/resources/messages.properties | 1 + .../WEB-INF/classes/resources/messages_es.properties | 1 + .../WEB-INF/classes/resources/messages_ja.properties | 3 ++- .../classes/resources/messages_zh_CN.properties | 3 ++- ui/jsp/host.jsp | 12 +++++++++++- ui/jsp/systemvm.jsp | 10 ++++++++++ ui/scripts/cloud.core.host.js | 3 ++- ui/scripts/cloud.core.systemvm.js | 6 ++++-- 8 files changed, 33 insertions(+), 6 deletions(-) diff --git a/client/WEB-INF/classes/resources/messages.properties b/client/WEB-INF/classes/resources/messages.properties index b3729acd472..d410e88da1d 100644 --- a/client/WEB-INF/classes/resources/messages.properties +++ b/client/WEB-INF/classes/resources/messages.properties @@ -347,6 +347,7 @@ label.lang.spanish=Spanish label.last.disconnected=Last Disconnected label.last.name=Last Name label.level=Level +label.linklocal.ip=Link Local IP Adddress label.load.balancer=Load Balancer label.loading=Loading label.local=Local diff --git a/client/WEB-INF/classes/resources/messages_es.properties b/client/WEB-INF/classes/resources/messages_es.properties index fa11c3d2ac7..bc3d0428b71 100644 --- a/client/WEB-INF/classes/resources/messages_es.properties +++ b/client/WEB-INF/classes/resources/messages_es.properties @@ -347,6 +347,7 @@ label.lang.spanish = Español label.last.disconnected = Última Desconectado label.last.name = Apellido label.level = Nivel +lable.linklocal.ip=Enlace adddress IP local label.load.balancer = equilibrador de carga label.loading = Carga label.local = local diff --git a/client/WEB-INF/classes/resources/messages_ja.properties b/client/WEB-INF/classes/resources/messages_ja.properties index 56cad27f631..20b9c98081b 100644 --- a/client/WEB-INF/classes/resources/messages_ja.properties +++ b/client/WEB-INF/classes/resources/messages_ja.properties @@ -346,7 +346,8 @@ label.lang.japanese=日本語 label.lang.spanish=スペイン語 label.last.disconnected =最終接続 label.last.name =姓 -label.level =レベル +label.level =レベル +label.linklocal.ip=リンクローカルIP Adddress label.load.balancer = ロードバランサ label.loading =読み込んでいます label.local =ローカル diff --git a/client/WEB-INF/classes/resources/messages_zh_CN.properties b/client/WEB-INF/classes/resources/messages_zh_CN.properties index 7496f20fbf3..87855d04600 100644 --- a/client/WEB-INF/classes/resources/messages_zh_CN.properties +++ b/client/WEB-INF/classes/resources/messages_zh_CN.properties @@ -346,7 +346,8 @@ label.lang.japanese=日本 label.lang.spanish=西班牙 label.last.disconnected =上次断开 label.last.name =姓氏 -label.level =等级 +label.level =等级 +label.linklocal.ip=链路本地的IP Adddress label.load.balancer =负载平衡器 label.loading =载入 label.local =本地 diff --git a/ui/jsp/host.jsp b/ui/jsp/host.jsp index bfef9257a8d..0b30e568efe 100644 --- a/ui/jsp/host.jsp +++ b/ui/jsp/host.jsp @@ -684,7 +684,17 @@ dictionary = {
- + +
+
+
+ :
+
+
+
+
+
+
diff --git a/ui/jsp/systemvm.jsp b/ui/jsp/systemvm.jsp index 928ca97463d..0065263ef8c 100644 --- a/ui/jsp/systemvm.jsp +++ b/ui/jsp/systemvm.jsp @@ -147,6 +147,16 @@ dictionary = {
+
+
+
+
+ :
+
+
+
+
+
diff --git a/ui/scripts/cloud.core.host.js b/ui/scripts/cloud.core.host.js index 45188f968b3..a9be21907c6 100644 --- a/ui/scripts/cloud.core.host.js +++ b/ui/scripts/cloud.core.host.js @@ -484,7 +484,8 @@ function hostSystemvmJSONToTemplate(jsonObj, template) { template.find("#name").text(fromdb(jsonObj.name)); template.find("#systemvmtype").text(toSystemVMTypeText(jsonObj.systemvmtype)); template.find("#publicip").text(fromdb(jsonObj.publicip)); - template.find("#privateip").text(fromdb(jsonObj.privateip)); + template.find("#privateip").text(fromdb(jsonObj.privateip)); + template.find("#linklocalip").text(fromdb(jsonObj.linklocalip)); setDateField(jsonObj.created, template.find("#created")); } diff --git a/ui/scripts/cloud.core.systemvm.js b/ui/scripts/cloud.core.systemvm.js index aa5d7816c22..ce9c697aa93 100644 --- a/ui/scripts/cloud.core.systemvm.js +++ b/ui/scripts/cloud.core.systemvm.js @@ -150,7 +150,8 @@ function systemvmJsonToDetailsTab() { $thisTab.find("#id").text(fromdb(jsonObj.id)); $thisTab.find("#name").text(fromdb(jsonObj.name)); $thisTab.find("#publicip").text(fromdb(jsonObj.publicip)); - $thisTab.find("#privateip").text(fromdb(jsonObj.privateip)); + $thisTab.find("#privateip").text(fromdb(jsonObj.privateip)); + $thisTab.find("#linklocalip").text(fromdb(jsonObj.linklocalip)); $thisTab.find("#hostname").text(fromdb(jsonObj.hostname)); $thisTab.find("#gateway").text(fromdb(jsonObj.gateway)); $thisTab.find("#created").text(fromdb(jsonObj.created)); @@ -213,7 +214,8 @@ function systemvmClearDetailsTab() { $thisTab.find("#id").text(fromdb(jsonObj.id)); $thisTab.find("#name").text(fromdb(jsonObj.name)); $thisTab.find("#publicip").text(fromdb(jsonObj.publicip)); - $thisTab.find("#privateip").text(fromdb(jsonObj.privateip)); + $thisTab.find("#privateip").text(fromdb(jsonObj.privateip)); + $thisTab.find("#linklocalip").text(fromdb(jsonObj.linklocalip)); $thisTab.find("#hostname").text(fromdb(jsonObj.hostname)); $thisTab.find("#gateway").text(fromdb(jsonObj.gateway)); $thisTab.find("#created").text(fromdb(jsonObj.created)); From 01a0f75491621559c5b4b10b577c8066c9a72c2d Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 4 Apr 2011 10:03:57 -0700 Subject: [PATCH 49/72] bug 9286: added constraint for domain id in data_center --- setup/db/db/schema-21to22.sql | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index 401678bc4f2..6b1d5a6b78b 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -289,23 +289,19 @@ ALTER TABLE `cloud`.`data_center` ADD COLUMN `vpn_provider` char(64) DEFAULT 'Vi ALTER TABLE `cloud`.`data_center` ADD COLUMN `userdata_provider` char(64) DEFAULT 'VirtualRouter'; ALTER TABLE `cloud`.`data_center` ADD COLUMN `enable` tinyint NOT NULL DEFAULT 1; -#TODO: We need something to adjust the networktype for all of the existing data centers. How to tell if it is Basic/Advance?; +ALTER TABLE `cloud`.`data_center` ADD CONSTRAINT `fk_data_center__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain`(`id`); ALTER TABLE `cloud`.`op_dc_ip_address_alloc` ADD COLUMN `reservation_id` char(40) NULL; ALTER TABLE `cloud`.`op_dc_ip_address_alloc` ADD COLUMN `mac_address` bigint unsigned NOT NULL; UPDATE `cloud`.`op_dc_ip_address_alloc` SET reservation_id=concat(cast(instance_id as CHAR), ip_address) WHERE taken is NOT NULL; -#UPDATE `cloud`.`op_dc_ip_address_alloc` as alloc1 SET mac_address=id-(SELECT min(alloc2.id) from op_dc_ip_address_alloc as alloc2 WHERE alloc2.data_center_id=alloc1.data_center_id)+1; ALTER TABLE `cloud`.`op_dc_link_local_ip_address_alloc` ADD COLUMN `reservation_id` char(40) NULL; UPDATE `cloud`.`op_dc_link_local_ip_address_alloc` SET reservation_id=concat(cast(instance_id as CHAR),ip_address) WHERE taken is NOT NULL; -#TODO: Set the Reservation id for this table?; - ALTER TABLE `cloud`.`host_pod_ref` ADD COLUMN `enabled` tinyint NOT NULL DEFAULT 1; ALTER TABLE `cloud`.`op_dc_vnet_alloc` ADD COLUMN `reservation_id` char(40) NULL; UPDATE op_dc_vnet_alloc set reservation_id=concat(cast(data_center_id as CHAR), concat("-", vnet)) WHERE taken is NOT NULL; -#TODO: Set the Reservation id for this table; ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `service_offering_id` bigint unsigned NOT NULL; ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `reservation_id` char(40); From f8b8da1fa1dbb3e19884eb8b07c173818f28acbc Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 4 Apr 2011 10:07:35 -0700 Subject: [PATCH 50/72] bug 9277: added table data_center_details --- setup/db/db/schema-222to224.sql | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/setup/db/db/schema-222to224.sql b/setup/db/db/schema-222to224.sql index c5dc4c636b8..65bfa1dfcd7 100644 --- a/setup/db/db/schema-222to224.sql +++ b/setup/db/db/schema-222to224.sql @@ -61,3 +61,11 @@ ALTER TABLE `cloud`.`host` ADD INDEX `i_host__allocation_state`(`allocation_stat ALTER TABLE `cloud`.`domain` ADD INDEX `i_domain__path`(`path`); +CREATE TABLE `cloud`.`data_center_details` ( + `id` bigint unsigned NOT NULL auto_increment, + `dc_id` bigint unsigned NOT NULL COMMENT 'dc id', + `name` varchar(255) NOT NULL, + `value` varchar(255) NOT NULL, + PRIMARY KEY (`id`), + CONSTRAINT `fk_dc_details__dc_id` FOREIGN KEY (`dc_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; From 1eba5ea7a79860a59a2528509106a0cbb7a679f5 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 4 Apr 2011 10:32:15 -0700 Subject: [PATCH 51/72] unittest failures fixed --- setup/db/db/schema-21to22-cleanup.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/db/db/schema-21to22-cleanup.sql b/setup/db/db/schema-21to22-cleanup.sql index bccdd1b1f33..8a62d337976 100644 --- a/setup/db/db/schema-21to22-cleanup.sql +++ b/setup/db/db/schema-21to22-cleanup.sql @@ -99,5 +99,5 @@ ALTER TABLE `cloud`.`service_offering` DROP COLUMN `guest_ip_type`; ALTER TABLE `cloud`.`load_balancer_vm_map` DROP COLUMN `pending`; -ALTER TABLE `cloud`.`account_vlan_map` ALTER COLUMN `account_id` bigint unsigned NOT NULL; +ALTER TABLE `cloud`.`account_vlan_map` MODIFY COLUMN `account_id` bigint unsigned NOT NULL; From f8c5a56d03fbc544940b477eecdc1ef17c96949e Mon Sep 17 00:00:00 2001 From: will Date: Mon, 4 Apr 2011 10:42:28 -0700 Subject: [PATCH 52/72] bug 8898: Change Service and Reset Password will now be always visible when VM is running. However, we will now prompt a dialog that explains that the VM must first be stopped before allowing this. Merge from master --- .../classes/resources/messages.properties | 3 ++ .../classes/resources/messages_es.properties | 3 ++ .../classes/resources/messages_ja.properties | 3 ++ .../resources/messages_zh_CN.properties | 3 ++ ui/jsp/instance.jsp | 5 ++- ui/scripts/cloud.core.instance.js | 41 +++++++++++++++++-- 6 files changed, 53 insertions(+), 5 deletions(-) diff --git a/client/WEB-INF/classes/resources/messages.properties b/client/WEB-INF/classes/resources/messages.properties index d410e88da1d..555bbc8f929 100644 --- a/client/WEB-INF/classes/resources/messages.properties +++ b/client/WEB-INF/classes/resources/messages.properties @@ -734,6 +734,9 @@ message.zone.step.2.desc=Please enter the following info to add a new zone message.zone.step.3.desc=Please enter the following info to add a new pod message.apply.snapshot.policy=You have successfully updated your current snapshot policy. message.disable.snapshot.policy=You have successfully disabled your current snapshot policy. +message.action.change.service.warning=Your instance must be stopped before attempting to change its current service offering. +message.action.reset.password.warning=Your instance must be stopped before attempting to change its current password. +message.action.reset.password.off=Your instance currently does not support this feature. #Errors error.login=Your username/password does not match our records. diff --git a/client/WEB-INF/classes/resources/messages_es.properties b/client/WEB-INF/classes/resources/messages_es.properties index bc3d0428b71..0e91d78681f 100644 --- a/client/WEB-INF/classes/resources/messages_es.properties +++ b/client/WEB-INF/classes/resources/messages_es.properties @@ -734,6 +734,9 @@ message.zone.step.2.desc = Por favor ingrese los siguientes datos para agregar u message.zone.step.3.desc = Por favor ingrese los siguientes datos para agregar una vaina nueva message.apply.snapshot.policy = Ha actualizado su política instantánea actual. message.disable.snapshot.policy = Ha desactivado su política instantánea actual. +message.action.change.service.warning = Su ejemplo debe ser detenido antes de intentar cambiar su oferta de servicios actual. +message.action.reset.password.warning = Su ejemplo debe ser detenido antes de intentar cambiar su contraseña actual. +message.action.reset.password.off = Su ejemplo en la actualidad no es compatible con esta función. #Errors diff --git a/client/WEB-INF/classes/resources/messages_ja.properties b/client/WEB-INF/classes/resources/messages_ja.properties index 20b9c98081b..e4849fbc70f 100644 --- a/client/WEB-INF/classes/resources/messages_ja.properties +++ b/client/WEB-INF/classes/resources/messages_ja.properties @@ -734,6 +734,9 @@ message.zone.step.2.desc=新しいZoneを追加するために、次の情報を message.zone.step.3.desc=新しいPodを追加するために、次の情報を入力してください。 message.apply.snapshot.policy=あなたが正常に現在のスナップショットのポリシーを更新している。 message.disable.snapshot.policy=あなたが正常に現在のスナップショットのポリシーを無効にしている。 +message.action.change.service.warning=あなたのインスタンスは、現在のサービスの提供を変更する前に停止する必要があります。 +message.action.reset.password.warning=あなたのインスタンスは、その現在のパスワードを変更しようとする前に停止する必要があります。 +message.action.reset.password.off=あなたのインスタンスは、現在この機能をサポートしていません。 #Errors error.login=ユーザ名/パスワードが記録と一致しません diff --git a/client/WEB-INF/classes/resources/messages_zh_CN.properties b/client/WEB-INF/classes/resources/messages_zh_CN.properties index 87855d04600..2a3847806cf 100644 --- a/client/WEB-INF/classes/resources/messages_zh_CN.properties +++ b/client/WEB-INF/classes/resources/messages_zh_CN.properties @@ -734,6 +734,9 @@ message.zone.step.2.desc =请输入下面的信息以添加一个新的Zone message.zone.step.3.desc =请输入下面的信息以添加一个新的Pod message.apply.snapshot.policy=您已成功更新您的当前快照的政策。 message.disable.snapshot.policy=你已经成功停用了您的当前快照的政策。 +message.action.change.service.warning=您的实例之前,必须停止试图改变其目前提供的服务。 +message.action.reset.password.warning=您的实例之前,必须停止试图改变其目前的密码。 +message.action.reset.password.off=您的实例目前不支持此功能。 #Errors error.login=您的用户名/密码与我们的记录不匹配。 diff --git a/ui/jsp/instance.jsp b/ui/jsp/instance.jsp index 9c02f1a4fea..070a5bafa41 100644 --- a/ui/jsp/instance.jsp +++ b/ui/jsp/instance.jsp @@ -46,7 +46,10 @@ dictionary = { 'label.root.disk.offering': '', 'label.full': '', 'label.available': '', - 'message.launch.vm.on.private.network': '' + 'message.launch.vm.on.private.network': '', + 'message.action.change.service.warning': '', + 'message.action.reset.password.warning': '', + 'message.action.reset.password.off': '' }; diff --git a/ui/scripts/cloud.core.instance.js b/ui/scripts/cloud.core.instance.js index 98e9539df44..112d547f4db 100644 --- a/ui/scripts/cloud.core.instance.js +++ b/ui/scripts/cloud.core.instance.js @@ -1606,14 +1606,35 @@ function doDetachISO($actionLink, $detailsTab, $midmenuItem1) { }).dialog("open"); } -function doResetPassword($actionLink, $detailsTab, $midmenuItem1) { +function doResetPassword($actionLink, $detailsTab, $midmenuItem1) { + var jsonObj = $midmenuItem1.data("jsonObj"); + + if (jsonObj.passwordenabled == false) { + $("#dialog_info") + .text(dictionary["message.action.reset.password.off"]) + .dialog('option', 'buttons', { + "OK": function() { + $(this).dialog("close"); + } + }).dialog("open"); + return; + } else if (jsonObj.state != 'Stopped') { + $("#dialog_info") + .text(dictionary["message.action.reset.password.warning"]) + .dialog('option', 'buttons', { + "OK": function() { + $(this).dialog("close"); + } + }).dialog("open"); + return; + } + $("#dialog_confirmation") .text(dictionary["message.action.instance.reset.password"]) .dialog('option', 'buttons', { "Yes": function() { $(this).dialog("close"); - var jsonObj = $midmenuItem1.data("jsonObj"); if(jsonObj.passwordenabled != true) { var $afterActionInfoContainer = $("#right_panel_content #after_action_info_container_on_top"); $afterActionInfoContainer.find("#after_action_info").text("Reset password failed. Reason: This instance is not using a template that has the password reset feature enabled. If you have forgotten your root password, please contact support."); @@ -1633,7 +1654,18 @@ function doResetPassword($actionLink, $detailsTab, $midmenuItem1) { function doChangeService($actionLink, $detailsTab, $midmenuItem1) { var jsonObj = $midmenuItem1.data("jsonObj"); - var id = jsonObj.id; + var id = jsonObj.id; + + if (jsonObj.state != 'Stopped') { + $("#dialog_info") + .text(dictionary['message.action.change.service.warning']) + .dialog('option', 'buttons', { + "OK": function() { + $(this).dialog("close"); + } + }).dialog("open"); + return; + } $.ajax({ data: createURL("command=listServiceOfferings&VirtualMachineId="+id), @@ -1904,7 +1936,8 @@ function vmBuildActionMenu(jsonObj, $thisTab, $midmenuItem1) { else buildActionLinkForTab("label.action.detach.iso", vmActionMap, $actionMenu, $midmenuItem1, $thisTab); - buildActionLinkForTab("label.action.reset.password", vmActionMap, $actionMenu, $midmenuItem1, $thisTab); + buildActionLinkForTab("label.action.reset.password", vmActionMap, $actionMenu, $midmenuItem1, $thisTab); + buildActionLinkForTab("label.action.change.service", vmActionMap, $actionMenu, $midmenuItem1, $thisTab); noAvailableActions = false; } else if (jsonObj.state == 'Stopped') { From 040c18613f5837987f0125d5ee39a4165cb99310 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Mon, 4 Apr 2011 11:39:54 -0400 Subject: [PATCH 53/72] bug 9291: set name = display_name status 9291: resolved fixed --- setup/db/db/schema-21to22.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index 6b1d5a6b78b..e8e2e4c6b45 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -943,8 +943,9 @@ INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Other', 60); INSERT INTO `cloud`.`guest_os_hypervisor` (hypervisor_type, guest_os_name, guest_os_id) VALUES ('KVM', 'Other', 103); +update `cloud`.`guest_os` set name = display_name; ALTER TABLE `cloud`.`instance_group` ADD CONSTRAINT `fk_instance_group__account_id` FOREIGN KEY `fk_instance_group__account_id` (`account_id`) REFERENCES `account` (`id`); ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___group_id` FOREIGN KEY `fk_instance_group_vm_map___group_id` (`group_id`) REFERENCES `instance_group` (`id`) ON DELETE CASCADE; -ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___instance_id` FOREIGN KEY `fk_instance_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE; +ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___instance_id` FOREIGN KEY `fk_instance_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE; From e8720cc1f75080ea347ebac73295910dcf0be912 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 4 Apr 2011 13:52:38 -0700 Subject: [PATCH 54/72] bug 9300: changed the network id to management from storage for ssvm --- server/src/com/cloud/upgrade/dao/Upgrade218to22.java | 4 ++-- setup/db/create-schema.sql | 3 ++- setup/db/db/schema-21to22.sql | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java index e9017ba50d7..9f2c18ae5e9 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java @@ -773,7 +773,7 @@ public class Upgrade218to22 implements DbUpgrade { upgradeDomR(conn, (Long)router[0], null, basicDefaultDirectNetworkId, controlNetworkId, "Basic"); } - upgradeSsvm(conn, dcId, basicDefaultDirectNetworkId, storageNetworkId, controlNetworkId, "Basic"); + upgradeSsvm(conn, dcId, basicDefaultDirectNetworkId, mgmtNetworkId, controlNetworkId, "Basic"); pstmt = conn.prepareStatement("SELECT vm_instance.id FROM vm_instance WHERE removed IS NULL AND type='ConsoleProxy' AND data_center_id=?"); pstmt.setLong(1, dcId); @@ -880,7 +880,7 @@ public class Upgrade218to22 implements DbUpgrade { upgradeDirectUserIpAddress(conn, dcId, vlanNetworkMap.get(tag), "DirectAttached"); } - upgradeSsvm(conn, dcId, publicNetworkId, storageNetworkId, controlNetworkId, "Advanced"); + upgradeSsvm(conn, dcId, publicNetworkId, mgmtNetworkId, controlNetworkId, "Advanced"); pstmt = conn.prepareStatement("SELECT vm_instance.id FROM vm_instance WHERE removed IS NULL AND type='ConsoleProxy' AND data_center_id=?"); pstmt.setLong(1, dcId); diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 73869d5fba1..8b8a3cf9dd7 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -492,6 +492,7 @@ CREATE TABLE `cloud`.`data_center` ( `allocation_state` varchar(32) NOT NULL DEFAULT 'Enabled' COMMENT 'Is this data center enabled for allocation for new resources', PRIMARY KEY (`id`), CONSTRAINT `fk_data_center__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain`(`id`), + INDEX `i_data_center__domain_id`(`domain_id`), INDEX `i_data_center__allocation_state`(`allocation_state`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -960,7 +961,7 @@ CREATE TABLE `cloud`.`domain` ( `parent` bigint unsigned, `name` varchar(255), `owner` bigint unsigned NOT NULL, - `path` varchar(255), + `path` varchar(255) UNIQUE NOT NULL, `level` int(10) NOT NULL DEFAULT 0, `child_count` int(10) NOT NULL DEFAULT 0, `next_child_seq` bigint unsigned NOT NULL DEFAULT 1, diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index e8e2e4c6b45..93d7bef2c46 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -949,3 +949,4 @@ ALTER TABLE `cloud`.`instance_group` ADD CONSTRAINT `fk_instance_group__account_ ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___group_id` FOREIGN KEY `fk_instance_group_vm_map___group_id` (`group_id`) REFERENCES `instance_group` (`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___instance_id` FOREIGN KEY `fk_instance_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE; +ALTER TABLE `cloud`.`domain` MODIFY COLUMN `path` varchar(255) UNIQUE NOT NULL; From aba5395f961d41d455c729095a9d641b288019e6 Mon Sep 17 00:00:00 2001 From: alena Date: Mon, 4 Apr 2011 13:48:14 -0700 Subject: [PATCH 55/72] bug 9293: 21 to 22 db upgrade - added missing constraints to load_balancer_vm_map status 9293: resolved fixed --- setup/db/db/schema-21to22-cleanup.sql | 4 ++++ setup/db/db/schema-21to22.sql | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/setup/db/db/schema-21to22-cleanup.sql b/setup/db/db/schema-21to22-cleanup.sql index 8a62d337976..468e6ed8f9b 100644 --- a/setup/db/db/schema-21to22-cleanup.sql +++ b/setup/db/db/schema-21to22-cleanup.sql @@ -101,3 +101,7 @@ ALTER TABLE `cloud`.`load_balancer_vm_map` DROP COLUMN `pending`; ALTER TABLE `cloud`.`account_vlan_map` MODIFY COLUMN `account_id` bigint unsigned NOT NULL; +ALTER TABLE `cloud`.`load_balancer_vm_map` ADD UNIQUE KEY (`load_balancer_id`, `instance_id`); +ALTER TABLE `cloud`.`load_balancer_vm_map` ADD CONSTRAINT `fk_load_balancer_vm_map__load_balancer_id` FOREIGN KEY(`load_balancer_id`) REFERENCES `load_balancing_rules`(`id`) ON DELETE CASCADE; +ALTER TABLE `cloud`.`load_balancer_vm_map` ADD CONSTRAINT `fk_load_balancer_vm_map__instance_id` FOREIGN KEY(`instance_id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE; + diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index 93d7bef2c46..6fa840bd3e6 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -949,4 +949,5 @@ ALTER TABLE `cloud`.`instance_group` ADD CONSTRAINT `fk_instance_group__account_ ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___group_id` FOREIGN KEY `fk_instance_group_vm_map___group_id` (`group_id`) REFERENCES `instance_group` (`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___instance_id` FOREIGN KEY `fk_instance_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE; -ALTER TABLE `cloud`.`domain` MODIFY COLUMN `path` varchar(255) UNIQUE NOT NULL; +ALTER TABLE `cloud`.`domain` MODIFY COLUMN `path` varchar(255) UNIQUE NOT NULL; + From 6af0a1e9be086be514bbfd2ff101db29fdabddac Mon Sep 17 00:00:00 2001 From: alena Date: Mon, 4 Apr 2011 14:11:20 -0700 Subject: [PATCH 56/72] bug 9298: vm_type can be NULL in "nics" table (for placeholder nics) status 9298: resolved fixed --- setup/db/221to222.sql | 5 +---- setup/db/db/schema-221to222.sql | 4 +++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/setup/db/221to222.sql b/setup/db/221to222.sql index d4798fdd47a..76dba6bd91a 100644 --- a/setup/db/221to222.sql +++ b/setup/db/221to222.sql @@ -7,12 +7,11 @@ update network_offerings set firewall_service=1, lb_service=1,vpn_service=1,gate alter table domain add column `state` char(32) NOT NULL default 'Active' COMMENT 'state of the domain'; alter table nics add column `vm_type` char(32); update nics set vm_type=(select type from vm_instance where vm_instance.id=nics.instance_id); -delete from configuration where name='router.cleanup'; INSERT INTO configuration (`category`, `instance`, `component`, `name`, `value`, `description`) VALUES ('Network','DEFAULT','none','network.guest.cidr.limit','22','size limit for guest cidr; cant be less than this value'); alter table user_statistics add column `network_id` bigint unsigned; update op_networks set nics_count=(nics_count-1) where id in (select d.network_id from domain_router d, vm_instance i where i.state='Running' and i.id=d.id); update network_offerings set traffic_type='Guest' where system_only=0; -alter table network_offerings add column `guest_type` char(32) NOT NULL; +alter table network_offerings add column `guest_type` char(32); update network_offerings set guest_type='Direct' where id=5; update network_offerings set guest_type='Virtual' where id=6; update network_offerings set guest_type='Direct' where id=7; @@ -29,5 +28,3 @@ update network_offerings set availability='Optional' where id=7; delete from configuration where name='router.cleanup.interval'; INSERT INTO configuration (category, instance, component, name, value, description) VALUES ('Advanced', 'DEFAULT', 'management-server', 'management.network.cidr', NULL, 'The cidr of management server network'); - - diff --git a/setup/db/db/schema-221to222.sql b/setup/db/db/schema-221to222.sql index f27b93cd28f..db9a1f3003f 100644 --- a/setup/db/db/schema-221to222.sql +++ b/setup/db/db/schema-221to222.sql @@ -4,7 +4,7 @@ update network_offerings set system_only=1 where name='System-Guest-Network'; update network_offerings set dns_service=1,userdata_service=1,dhcp_service=1 where system_only=0; update network_offerings set firewall_service=1, lb_service=1,vpn_service=1,gateway_service=1 where traffic_type='guest' and system_only=0; alter table domain add column `state` char(32) NOT NULL default 'Active' COMMENT 'state of the domain'; -alter table nics add column `vm_type` char(32) NOT NULL; +alter table nics add column `vm_type` char(32); update nics set vm_type=(select type from vm_instance where vm_instance.id=nics.instance_id); INSERT INTO configuration (`category`, `instance`, `component`, `name`, `value`, `description`) VALUES ('Network','DEFAULT','none','network.guest.cidr.limit','22','size limit for guest cidr; cant be less than this value'); alter table user_statistics add column `network_id` bigint unsigned; @@ -25,3 +25,5 @@ update network_offerings set specify_vlan=1 where system_only=0 and guest_type=' update networks set traffic_type='Guest' where network_offering_id in (select id from network_offerings where system_only=0); update network_offerings set availability='Optional' where id=7; delete from configuration where name='router.cleanup.interval'; +INSERT INTO configuration (category, instance, component, name, value, description) + VALUES ('Advanced', 'DEFAULT', 'management-server', 'management.network.cidr', NULL, 'The cidr of management server network'); From 68d1cbcfbc3f73badb47bab5b85af46318999909 Mon Sep 17 00:00:00 2001 From: keshav Date: Mon, 4 Apr 2011 14:27:04 -0700 Subject: [PATCH 57/72] Added configuration table modifications to upgrade sql. --- setup/db/db/schema-222to224-cleanup.sql | 3 +- setup/db/db/schema-222to224.sql | 46 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/setup/db/db/schema-222to224-cleanup.sql b/setup/db/db/schema-222to224-cleanup.sql index 650482bb563..3066b580a17 100644 --- a/setup/db/db/schema-222to224-cleanup.sql +++ b/setup/db/db/schema-222to224-cleanup.sql @@ -2,4 +2,5 @@ ALTER TABLE `cloud`.`account_vlan_map` DROP FOREIGN KEY `fk_account_vlan_map__do ALTER TABLE `cloud`.`account_vlan_map` DROP COLUMN `domain_id`; DELETE FROM `cloud`.`account_vlan_map` WHERE account_id IS NULL; ALTER TABLE `cloud`.`data_center` DROP COLUMN `enable`; -ALTER TABLE `cloud`.`host_pod_ref` DROP COLUMN `enabled`; \ No newline at end of file +ALTER TABLE `cloud`.`host_pod_ref` DROP COLUMN `enabled`; +DELETE FROM `cloud`.`configuration` WHERE name in ('direct.attach.security.groups.enabled', 'direct.attach.untagged.vlan.enabled', 'hypervisor.type', 'management-server', 'max.volume.size.gb', 'multicast.throttling.rate', 'network.type', 'xen.preallocated.lun.size.range'); diff --git a/setup/db/db/schema-222to224.sql b/setup/db/db/schema-222to224.sql index 65bfa1dfcd7..9a6686ccec4 100644 --- a/setup/db/db/schema-222to224.sql +++ b/setup/db/db/schema-222to224.sql @@ -69,3 +69,49 @@ CREATE TABLE `cloud`.`data_center_details` ( PRIMARY KEY (`id`), CONSTRAINT `fk_dc_details__dc_id` FOREIGN KEY (`dc_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO `configuration` VALUES +('Advanced','DEFAULT','management-server','control.cidr','169.254.0.0/16','Changes the cidr for the control network traffic. Defaults to using link local. Must be unique within pods'), +('Advanced','DEFAULT','management-server','control.gateway','169.254.0.1','gateway for the control network traffic'), +('Advanced','DEFAULT','AgentManager','cmd.wait','7200','Time (in seconds) to wait for some heavy time-consuming commands'), +('Console Proxy','DEFAULT','AgentManager','consoleproxy.cpu.mhz','500','CPU speed (in MHz) used to create new console proxy VMs'), +('Console Proxy','DEFAULT','AgentManager','consoleproxy.disable.rpfilter','true','disable rp_filter on console proxy VM public interface'), +('Console Proxy','DEFAULT','AgentManager','consoleproxy.launch.max','10','maximum number of console proxy instances per zone can be launched'), +('Console Proxy','DEFAULT','AgentManager','consoleproxy.restart','true','Console proxy restart flag, defaulted to true'), +('Console Proxy','DEFAULT','AgentManager','consoleproxy.url.domain','realhostip.com','Console proxy url domain'), +('Advanced','DEFAULT','management-server','extract.url.cleanup.interval','120','The interval (in seconds) to wait before cleaning up the extract URL\'s '), +('Network','DEFAULT','AgentManager','guest.domain.suffix','cloud.internal','Default domain name for vms inside virtualized networks fronted by router'), +('Network','DEFAULT','AgentManager','guest.ip.network','10.1.1.1','The network address of the guest virtual network. Virtual machines will be assigned an IP in this subnet.'), +('Network','DEFAULT','AgentManager','guest.netmask','255.255.255.0','The netmask of the guest virtual network.'), +('Network','DEFAULT','management-server','guest.vlan.bits','12','The number of bits to reserve for the VLAN identifier in the guest subnet.'), +('Advanced','DEFAULT','management-server','host.capacity.checker.interval','3600','Time (in seconds) to wait before recalculating host\'s capacity'), +('Advanced','DEFAULT','management-server','host.capacity.checker.wait','3600','Time (in seconds) to wait before starting host capacity background checker'), +('Advanced','DEFAULT','management-server','host.capacityType.to.order.clusters','CPU','The host capacity type (CPU or RAM) is used by deployment planner to order clusters during VM resource allocation'), +('Advanced','DEFAULT','management-server','job.cancel.threshold.minutes','60','Time (in minutes) for async-jobs to be forcely cancelled if it has been in process for long'), +('Advanced','DEFAULT','management-server','kvm.private.network.device',NULL,'Specify the private bridge on host for private network'), +('Advanced','DEFAULT','management-server','kvm.public.network.device',NULL,'Specify the public bridge on host for public network'), +('Advanced','DEFAULT','management-server','management.network.cidr','192.168.130.0/24','The cidr of management server network'), +('Advanced','DEFAULT','management-server','network.gc.interval','600','Seconds to wait before checking for networks to shutdown'), +('Advanced','DEFAULT','management-server','network.gc.wait','600','Time (in seconds) to wait before shutting down a network that\'s not in used'), +('Network','DEFAULT','management-server','open.vswitch.tunnel.network','false','enable/disable open vswitch tunnel network(no vlan)'), +('Network','DEFAULT','management-server','open.vswitch.vlan.network','false','enable/disable vlan remapping of open vswitch network'), +('Advanced','DEFAULT','none','router.cpu.mhz','500','Default CPU speed (MHz) for router VM.'), +('Advanced','DEFAULT','none','router.template.id','1','Default ID for template.'), +('Advanced','DEFAULT','AgentManager','secstorage.vm.cpu.mhz','500','CPU speed (in MHz) used to create new secondary storage vms'), +('Snapshots','DEFAULT','none','snapshot.delta.max','16','max delta snapshots between two full snapshots.'), +('Storage','DEFAULT','management-server','storage.max.volume.size','2000','The maximum size for a volume (in GB).'), +('Advanced','DEFAULT','management-server','system.vm.auto.reserve.capacity','true','Indicates whether or not to automatically reserver system VM standby capacity.'), +('Advanced','DEFAULT','management-server','use.user.concentrated.pod.allocation','true','If true, deployment planner applies the user concentration heuristic during VM resource allocation'), +('Advanced','DEFAULT','management-server','vm.op.cancel.interval','3600','Time (in seconds) to wait before cancelling a operation'), +('Advanced','DEFAULT','management-server','vm.op.cleanup.interval','86400','Interval to run the thread that cleans up the vm operations (in seconds)'), +('Advanced','DEFAULT','management-server','vm.op.cleanup.wait','3600','Time (in seconds) to wait before cleanuping up any vm work items'), +('Advanced','DEFAULT','management-server','vm.op.lock.state.retry','5','Times to retry locking the state of a VM for operations'), +('Advanced','DEFAULT','management-server','vm.op.wait.interval','120','Time (in seconds) to wait before checking if a previous operation has succeeded'), +('Advanced','DEFAULT','management-server','vm.stats.interval','60000','The interval (in milliseconds) when vm stats are retrieved from agents.'), +('Advanced','DEFAULT','management-server','vm.tranisition.wait.interval','3600','Time (in seconds) to wait before taking over a VM in transition state'), +('Advanced','DEFAULT','management-server','vmware.guest.vswitch',NULL,'Specify the vSwitch on host for guest network'), +('Advanced','DEFAULT','management-server','vmware.private.vswitch',NULL,'Specify the vSwitch on host for private network'), +('Advanced','DEFAULT','management-server','vmware.public.vswitch',NULL,'Specify the vSwitch on host for public network'), +('Advanced','DEFAULT','management-server','vmware.service.console','Service Console','Specify the service console network name (ESX host only)'), +('Advanced','DEFAULT','AgentManager','xapiwait','600','Time (in seconds) to wait for XAPI to return'); + From bf3c2b73e179c31ddfa3f830e42be46c4243a345 Mon Sep 17 00:00:00 2001 From: keshav Date: Mon, 4 Apr 2011 15:13:53 -0700 Subject: [PATCH 58/72] Removed some configuration table inserts. --- setup/db/db/schema-222to224.sql | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup/db/db/schema-222to224.sql b/setup/db/db/schema-222to224.sql index 9a6686ccec4..4f14166688b 100644 --- a/setup/db/db/schema-222to224.sql +++ b/setup/db/db/schema-222to224.sql @@ -70,7 +70,7 @@ CREATE TABLE `cloud`.`data_center_details` ( CONSTRAINT `fk_dc_details__dc_id` FOREIGN KEY (`dc_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -INSERT INTO `configuration` VALUES +INSERT INTO `cloud`.`configuration` VALUES ('Advanced','DEFAULT','management-server','control.cidr','169.254.0.0/16','Changes the cidr for the control network traffic. Defaults to using link local. Must be unique within pods'), ('Advanced','DEFAULT','management-server','control.gateway','169.254.0.1','gateway for the control network traffic'), ('Advanced','DEFAULT','AgentManager','cmd.wait','7200','Time (in seconds) to wait for some heavy time-consuming commands'), @@ -80,7 +80,6 @@ INSERT INTO `configuration` VALUES ('Console Proxy','DEFAULT','AgentManager','consoleproxy.restart','true','Console proxy restart flag, defaulted to true'), ('Console Proxy','DEFAULT','AgentManager','consoleproxy.url.domain','realhostip.com','Console proxy url domain'), ('Advanced','DEFAULT','management-server','extract.url.cleanup.interval','120','The interval (in seconds) to wait before cleaning up the extract URL\'s '), -('Network','DEFAULT','AgentManager','guest.domain.suffix','cloud.internal','Default domain name for vms inside virtualized networks fronted by router'), ('Network','DEFAULT','AgentManager','guest.ip.network','10.1.1.1','The network address of the guest virtual network. Virtual machines will be assigned an IP in this subnet.'), ('Network','DEFAULT','AgentManager','guest.netmask','255.255.255.0','The netmask of the guest virtual network.'), ('Network','DEFAULT','management-server','guest.vlan.bits','12','The number of bits to reserve for the VLAN identifier in the guest subnet.'), @@ -99,7 +98,6 @@ INSERT INTO `configuration` VALUES ('Advanced','DEFAULT','none','router.template.id','1','Default ID for template.'), ('Advanced','DEFAULT','AgentManager','secstorage.vm.cpu.mhz','500','CPU speed (in MHz) used to create new secondary storage vms'), ('Snapshots','DEFAULT','none','snapshot.delta.max','16','max delta snapshots between two full snapshots.'), -('Storage','DEFAULT','management-server','storage.max.volume.size','2000','The maximum size for a volume (in GB).'), ('Advanced','DEFAULT','management-server','system.vm.auto.reserve.capacity','true','Indicates whether or not to automatically reserver system VM standby capacity.'), ('Advanced','DEFAULT','management-server','use.user.concentrated.pod.allocation','true','If true, deployment planner applies the user concentration heuristic during VM resource allocation'), ('Advanced','DEFAULT','management-server','vm.op.cancel.interval','3600','Time (in seconds) to wait before cancelling a operation'), From 10e2dba837b1100350485240daa7e967a033b3e8 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 4 Apr 2011 15:28:07 -0700 Subject: [PATCH 59/72] bug 9301: added missing constraint --- setup/db/db/schema-21to22.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index 6fa840bd3e6..5c098952b73 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -950,4 +950,4 @@ ALTER TABLE `cloud`.`instance_group` ADD CONSTRAINT `fk_instance_group__account_ ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___group_id` FOREIGN KEY `fk_instance_group_vm_map___group_id` (`group_id`) REFERENCES `instance_group` (`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___instance_id` FOREIGN KEY `fk_instance_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`domain` MODIFY COLUMN `path` varchar(255) UNIQUE NOT NULL; - +ALTER TABLE op_dc_ip_address_alloc ADD CONSTRAINT `fk_op_dc_ip_address_alloc__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE; From f2921b7f152fd07b9178dfc30147d1802cda9e83 Mon Sep 17 00:00:00 2001 From: alena Date: Mon, 4 Apr 2011 15:15:21 -0700 Subject: [PATCH 60/72] bug 9272: fixed the race condition bug when we tried to remove vm from SG after it was expunged (expunge interval was really small, 60 sec). status 9272: resolved fixed When do search for vm, do includingRemoved search. --- .../com/cloud/network/security/SecurityGroupManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java b/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java index f4e723296d0..d18387787ce 100644 --- a/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java +++ b/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java @@ -1337,7 +1337,7 @@ public class SecurityGroupManagerImpl implements SecurityGroupManager, SecurityG @Override public boolean isVmSecurityGroupEnabled(Long vmId) { - VirtualMachine vm = _vmDao.findById(vmId); + VirtualMachine vm = _vmDao.findByIdIncludingRemoved(vmId); List nics = _networkMgr.getNicProfiles(vm); for (NicProfile nic : nics) { if (nic.isSecurityGroupEnabled() && vm.getHypervisorType() != HypervisorType.VMware) { From f8fce16cace63e8dee8b515c13d016093a5b600b Mon Sep 17 00:00:00 2001 From: alena Date: Mon, 4 Apr 2011 15:40:31 -0700 Subject: [PATCH 61/72] bug 9274: listPublicIpAddresses - don't list Direct ip addresses by default; list them only when "forVirtualNetwork=false" is specified in the request. status 9274: resolved fixed --- .../com/cloud/server/ManagementServerImpl.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 89bc7318f4a..28ef0ae7baf 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -2584,11 +2584,9 @@ public class ManagementServerImpl implements ManagementServer { sb.and("addressLIKE", sb.entity().getAddress(), SearchCriteria.Op.LIKE); } - if (forVirtualNetwork != null) { - SearchBuilder vlanSearch = _vlanDao.createSearchBuilder(); - vlanSearch.and("vlanType", vlanSearch.entity().getVlanType(), SearchCriteria.Op.EQ); - sb.join("vlanSearch", vlanSearch, sb.entity().getVlanId(), vlanSearch.entity().getId(), JoinBuilder.JoinType.INNER); - } + SearchBuilder vlanSearch = _vlanDao.createSearchBuilder(); + vlanSearch.and("vlanType", vlanSearch.entity().getVlanType(), SearchCriteria.Op.EQ); + sb.join("vlanSearch", vlanSearch, sb.entity().getVlanId(), vlanSearch.entity().getId(), JoinBuilder.JoinType.INNER); if ((isAllocated != null) && (isAllocated == true)) { sb.and("allocated", sb.entity().getAllocatedTime(), SearchCriteria.Op.NNULL); @@ -2602,10 +2600,14 @@ public class ManagementServerImpl implements ManagementServer { sc.setJoinParameters("domainSearch", "path", domain.getPath() + "%"); } + VlanType vlanType = null; if (forVirtualNetwork != null) { - VlanType vlanType = (Boolean) forVirtualNetwork ? VlanType.VirtualNetwork : VlanType.DirectAttached; - sc.setJoinParameters("vlanSearch", "vlanType", vlanType); + vlanType = (Boolean) forVirtualNetwork ? VlanType.VirtualNetwork : VlanType.DirectAttached; + } else { + vlanType = VlanType.VirtualNetwork; } + + sc.setJoinParameters("vlanSearch", "vlanType", vlanType); if (zone != null) { sc.setParameters("dataCenterId", zone); From b2cab48e0c5f34c638bf991df14fade8655d0aba Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 4 Apr 2011 16:59:00 -0700 Subject: [PATCH 62/72] bug 9308: changed instance_id to nic_id --- .../com/cloud/dc/DataCenterIpAddressVO.java | 2 +- .../com/cloud/upgrade/dao/Upgrade218to22.java | 38 +++++++++++++++---- setup/db/create-schema.sql | 4 +- setup/db/db/schema-21to22.sql | 3 +- setup/db/db/schema-222to224.sql | 2 +- 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/server/src/com/cloud/dc/DataCenterIpAddressVO.java b/server/src/com/cloud/dc/DataCenterIpAddressVO.java index 9ae0c9cbd63..9688051b412 100755 --- a/server/src/com/cloud/dc/DataCenterIpAddressVO.java +++ b/server/src/com/cloud/dc/DataCenterIpAddressVO.java @@ -53,7 +53,7 @@ public class DataCenterIpAddressVO { @Column(name="reservation_id") String reservationId; - @Column(name="instance_id") + @Column(name="nic_id") private Long instanceId; @Column(name="mac_address") diff --git a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java index 9f2c18ae5e9..25b62734c51 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java @@ -167,10 +167,10 @@ public class Upgrade218to22 implements DbUpgrade { pstmt.close(); } - protected void insertNic(Connection conn, long networkId, long instanceId, boolean running, String macAddress, String ipAddress, String netmask, String strategy, String gateway, String vnet, String guru, boolean defNic, int deviceId, String mode, String reservationId) throws SQLException { + protected long insertNic(Connection conn, long networkId, long instanceId, boolean running, String macAddress, String ipAddress, String netmask, String strategy, String gateway, String vnet, String guru, boolean defNic, int deviceId, String mode, String reservationId) throws SQLException { PreparedStatement pstmt = conn.prepareStatement( "INSERT INTO nics (instance_id, network_id, mac_address, ip4_address, netmask, strategy, ip_type, broadcast_uri, mode, reserver_name, reservation_id, device_id, update_time, isolation_uri, ip6_address, default_nic, created, removed, state, gateway) " + - "VALUES (?, ?, ?, ?, ?, ?, 'Ip4', ?, ?, ?, ?, ?, now(), ?, NULL, ?, now(), NULL, ?, ?)"); + "VALUES (?, ?, ?, ?, ?, ?, 'Ip4', ?, ?, ?, ?, ?, now(), ?, NULL, ?, now(), NULL, ?, ?)", Statement.RETURN_GENERATED_KEYS); int i = 1; String isolationUri = null; @@ -199,7 +199,15 @@ public class Upgrade218to22 implements DbUpgrade { pstmt.setString(i++, running ? "Reserved" : "Allocated"); pstmt.setString(i++, gateway); pstmt.executeUpdate(); + ResultSet rs = pstmt.getGeneratedKeys(); + long nicId = 0; + if (!rs.next()) { + throw new CloudRuntimeException("Unable to get id for nic"); + } + nicId = rs.getLong(1); + rs.close(); pstmt.close(); + return nicId; } protected void upgradeDomR(Connection conn, long domrId, Long publicNetworkId, long guestNetworkId, long controlNetworkId, String zoneType) throws SQLException { @@ -293,10 +301,18 @@ public class Upgrade218to22 implements DbUpgrade { } insertNic(conn, controlNetworkId, ssvmId, running, guestMac, guestIp, guestNetmask, "Start", "169.254.0.1", null, "ControlNetworkGuru", false, 0, "Static", guestIp != null ? (ssvmId + guestIp) : null); - insertNic(conn, managementNetworkId, ssvmId, running, privateMac, privateIp, privateNetmask, "Start", podGateway, null, "PodBasedNetworkGuru", false, 1, "Static", null); + long mgmtNicId = insertNic(conn, managementNetworkId, ssvmId, running, privateMac, privateIp, privateNetmask, "Start", podGateway, null, "PodBasedNetworkGuru", false, 1, "Static", null); + if (privateIp != null) { + pstmt = conn.prepareStatement("UPDATE op_dc_ip_address_alloc SET nic_id=? WHERE ip_address=? AND data_center_id=?"); + pstmt.setLong(1, mgmtNicId); + pstmt.setString(2, privateIp); + pstmt.setLong(3, dataCenterId); + pstmt.executeUpdate(); + pstmt.close(); + } } - protected void upgradeConsoleProxy(Connection conn, long cpId, long publicNetworkId, long managementNetworkId, long controlNetworkId, String zoneType) throws SQLException { + protected void upgradeConsoleProxy(Connection conn, long dcId, long cpId, long publicNetworkId, long managementNetworkId, long controlNetworkId, String zoneType) throws SQLException { s_logger.debug("Upgrading cp" + cpId); PreparedStatement pstmt = conn.prepareStatement("SELECT vm_instance.id, vm_instance.state, vm_instance.private_mac_address, vm_instance.private_ip_address, vm_instance.private_netmask, console_proxy.public_mac_address, console_proxy.public_ip_address, console_proxy.public_netmask, console_proxy.guest_mac_address, console_proxy.guest_ip_address, console_proxy.guest_netmask, console_proxy.gateway, vm_instance.type FROM vm_instance INNER JOIN console_proxy ON vm_instance.id=console_proxy.id WHERE vm_instance.removed is NULL AND vm_instance.id=?"); pstmt.setLong(1, cpId); @@ -343,7 +359,15 @@ public class Upgrade218to22 implements DbUpgrade { } insertNic(conn, controlNetworkId, cpId, running, guestMac, guestIp, guestNetmask, "Start", "169.254.0.1", null, "ControlNetworkGuru", false, 0, "Static", guestIp != null ? (cpId + guestIp) : null); - insertNic(conn, managementNetworkId, cpId, running, privateMac, privateIp, privateNetmask, "Start", podGateway, null, "PodBasedNetworkGuru", false, 1, "Static", null); + long mgmtNicId = insertNic(conn, managementNetworkId, cpId, running, privateMac, privateIp, privateNetmask, "Start", podGateway, null, "PodBasedNetworkGuru", false, 1, "Static", privateIp != null ? (cpId + privateIp) : null); + if (privateIp != null) { + pstmt = conn.prepareStatement("UPDATE op_dc_ip_address_alloc SET nic_id=? WHERE ip_address=? AND data_center_id=?"); + pstmt.setLong(1, mgmtNicId); + pstmt.setString(2, privateIp); + pstmt.setLong(3, dcId); + pstmt.executeUpdate(); + pstmt.close(); + } } protected void upgradeVirtualUserVms(Connection conn, long domainRouterId, long networkId, String gateway, String vnet) throws SQLException { @@ -779,7 +803,7 @@ public class Upgrade218to22 implements DbUpgrade { pstmt.setLong(1, dcId); rs = pstmt.executeQuery(); while (rs.next()) { - upgradeConsoleProxy(conn, rs.getLong(1), basicDefaultDirectNetworkId, mgmtNetworkId, controlNetworkId, "Basic"); + upgradeConsoleProxy(conn, dcId, rs.getLong(1), basicDefaultDirectNetworkId, mgmtNetworkId, controlNetworkId, "Basic"); } } @@ -886,7 +910,7 @@ public class Upgrade218to22 implements DbUpgrade { pstmt.setLong(1, dcId); rs = pstmt.executeQuery(); while (rs.next()) { - upgradeConsoleProxy(conn, rs.getLong(1), publicNetworkId, mgmtNetworkId, controlNetworkId, "Advanced"); + upgradeConsoleProxy(conn, dcId, rs.getLong(1), publicNetworkId, mgmtNetworkId, controlNetworkId, "Advanced"); } } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 8b8a3cf9dd7..2c8104320d5 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -501,13 +501,13 @@ CREATE TABLE `cloud`.`op_dc_ip_address_alloc` ( `ip_address` char(40) NOT NULL COMMENT 'ip address', `data_center_id` bigint unsigned NOT NULL COMMENT 'data center it belongs to', `pod_id` bigint unsigned NOT NULL COMMENT 'pod it belongs to', - `instance_id` bigint unsigned NULL COMMENT 'instance id', + `nic_id` bigint unsigned NULL COMMENT 'nic id', `reservation_id` char(40) NULL COMMENT 'reservation id', `taken` datetime COMMENT 'Date taken', `mac_address` bigint unsigned NOT NULL COMMENT 'mac address for management ips', PRIMARY KEY (`id`), CONSTRAINT `fk_op_dc_ip_address_alloc__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE, - INDEX `i_op_dc_ip_address_alloc__pod_id__data_center_id__taken` (`pod_id`, `data_center_id`, `taken`, `instance_id`), + INDEX `i_op_dc_ip_address_alloc__pod_id__data_center_id__taken` (`pod_id`, `data_center_id`, `taken`, `nic_id`), UNIQUE `i_op_dc_ip_address_alloc__ip_address__data_center_id`(`ip_address`, `data_center_id`), CONSTRAINT `fk_op_dc_ip_address_alloc__pod_id` FOREIGN KEY (`pod_id`) REFERENCES `host_pod_ref` (`id`) ON DELETE CASCADE, INDEX `i_op_dc_ip_address_alloc__pod_id`(`pod_id`) diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index 5c098952b73..b1a5b36887b 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -950,4 +950,5 @@ ALTER TABLE `cloud`.`instance_group` ADD CONSTRAINT `fk_instance_group__account_ ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___group_id` FOREIGN KEY `fk_instance_group_vm_map___group_id` (`group_id`) REFERENCES `instance_group` (`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___instance_id` FOREIGN KEY `fk_instance_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`domain` MODIFY COLUMN `path` varchar(255) UNIQUE NOT NULL; -ALTER TABLE op_dc_ip_address_alloc ADD CONSTRAINT `fk_op_dc_ip_address_alloc__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE; +ALTER TABLE `cloud`.`op_dc_ip_address_alloc` CHANGE COLUMN `instance_id` `nic_id` bigint unsigned DEFAULT NULL; +ALTER TABLE op_dc_ip_address_alloc ADD CONSTRAINT `fk_op_dc_ip_address_alloc__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE; diff --git a/setup/db/db/schema-222to224.sql b/setup/db/db/schema-222to224.sql index 4f14166688b..ee5aab6337b 100644 --- a/setup/db/db/schema-222to224.sql +++ b/setup/db/db/schema-222to224.sql @@ -70,6 +70,7 @@ CREATE TABLE `cloud`.`data_center_details` ( CONSTRAINT `fk_dc_details__dc_id` FOREIGN KEY (`dc_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +#('Advanced','DEFAULT','management-server','management.network.cidr','192.168.130.0/24','The cidr of management server network'),; INSERT INTO `cloud`.`configuration` VALUES ('Advanced','DEFAULT','management-server','control.cidr','169.254.0.0/16','Changes the cidr for the control network traffic. Defaults to using link local. Must be unique within pods'), ('Advanced','DEFAULT','management-server','control.gateway','169.254.0.1','gateway for the control network traffic'), @@ -89,7 +90,6 @@ INSERT INTO `cloud`.`configuration` VALUES ('Advanced','DEFAULT','management-server','job.cancel.threshold.minutes','60','Time (in minutes) for async-jobs to be forcely cancelled if it has been in process for long'), ('Advanced','DEFAULT','management-server','kvm.private.network.device',NULL,'Specify the private bridge on host for private network'), ('Advanced','DEFAULT','management-server','kvm.public.network.device',NULL,'Specify the public bridge on host for public network'), -('Advanced','DEFAULT','management-server','management.network.cidr','192.168.130.0/24','The cidr of management server network'), ('Advanced','DEFAULT','management-server','network.gc.interval','600','Seconds to wait before checking for networks to shutdown'), ('Advanced','DEFAULT','management-server','network.gc.wait','600','Time (in seconds) to wait before shutting down a network that\'s not in used'), ('Network','DEFAULT','management-server','open.vswitch.tunnel.network','false','enable/disable open vswitch tunnel network(no vlan)'), From 204aa8668643b2472a8617d6fa3fc50d9a24058f Mon Sep 17 00:00:00 2001 From: prachi Date: Mon, 4 Apr 2011 17:28:58 -0700 Subject: [PATCH 63/72] Bug 9043 - VM manual migration - when destination host is out of memory for migration, VMs being migrated remained in 'migrating' state Changes: - When migration fails we try to do cleanup on the destination host agent. The AgentUnavailableException in this cleanup was not caught. -Due to that other cleanup like reverting capacity allocated and vm state were skipped. -Fix is to catch the AgentUnavailableException so that rest of the cleanup can happen. - Also corrected the exceptions in various cases of migration failure. - In case the VM is still starting, HA should schedule a retry. Introduced a special migration exception for handling this. --- .../com/cloud/api/commands/MigrateVMCmd.java | 6 ++- .../VirtualMachineMigrationException.java | 28 +++++++++++++ api/src/com/cloud/vm/UserVmService.java | 4 +- .../cloud/ha/HighAvailabilityManagerImpl.java | 5 +++ .../src/com/cloud/vm/UserVmManagerImpl.java | 3 +- .../com/cloud/vm/VirtualMachineManager.java | 5 ++- .../cloud/vm/VirtualMachineManagerImpl.java | 40 ++++++++++++++----- .../src/com/cloud/utils/SerialVersionUID.java | 1 + 8 files changed, 76 insertions(+), 16 deletions(-) create mode 100644 api/src/com/cloud/exception/VirtualMachineMigrationException.java diff --git a/api/src/com/cloud/api/commands/MigrateVMCmd.java b/api/src/com/cloud/api/commands/MigrateVMCmd.java index 7f8ce362532..c3a5cd4b415 100644 --- a/api/src/com/cloud/api/commands/MigrateVMCmd.java +++ b/api/src/com/cloud/api/commands/MigrateVMCmd.java @@ -31,6 +31,7 @@ import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ManagementServerException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.VirtualMachineMigrationException; import com.cloud.host.Host; import com.cloud.user.Account; import com.cloud.uservm.UserVm; @@ -123,6 +124,9 @@ public class MigrateVMCmd extends BaseAsyncCmd { } catch (ManagementServerException e) { s_logger.warn("Exception: ", e); throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage()); - } + } catch (VirtualMachineMigrationException e) { + s_logger.warn("Exception: ", e); + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage()); + } } } diff --git a/api/src/com/cloud/exception/VirtualMachineMigrationException.java b/api/src/com/cloud/exception/VirtualMachineMigrationException.java new file mode 100644 index 00000000000..3d136750f4d --- /dev/null +++ b/api/src/com/cloud/exception/VirtualMachineMigrationException.java @@ -0,0 +1,28 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package com.cloud.exception; + +import com.cloud.utils.SerialVersionUID; + +public class VirtualMachineMigrationException extends Exception { + private static final long serialVersionUID = SerialVersionUID.VirtualMachineMigrationException; + + public VirtualMachineMigrationException(String message) { + super(message); + } +} diff --git a/api/src/com/cloud/vm/UserVmService.java b/api/src/com/cloud/vm/UserVmService.java index b8b9e6d46ef..da7d9e32985 100755 --- a/api/src/com/cloud/vm/UserVmService.java +++ b/api/src/com/cloud/vm/UserVmService.java @@ -44,6 +44,7 @@ import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.StorageUnavailableException; +import com.cloud.exception.VirtualMachineMigrationException; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.offering.ServiceOffering; import com.cloud.storage.Volume; @@ -286,6 +287,7 @@ public interface UserVmService { * @throws ManagementServerException in case we get error finding the VM or host or access errors or other internal errors. * @throws ConcurrentOperationException if there are multiple users working on the same VM. * @throws ResourceUnavailableException if the destination host to migrate the VM is not currently available. + * @throws VirtualMachineMigrationException if the VM to be migrated is not in Running state */ - UserVm migrateVirtualMachine(UserVm vm, Host destinationHost) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException; + UserVm migrateVirtualMachine(UserVm vm, Host destinationHost) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException; } diff --git a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java index c5344c7d313..c456fcfc9c4 100644 --- a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java +++ b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java @@ -49,6 +49,7 @@ import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientServerCapacityException; import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.VirtualMachineMigrationException; import com.cloud.ha.dao.HighAvailabilityDao; import com.cloud.host.Host; import com.cloud.host.HostVO; @@ -479,6 +480,10 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu s_logger.warn("Insufficient capacity for migrating a VM."); _agentMgr.maintenanceFailed(srcHostId); return (System.currentTimeMillis() >> 10) + _migrateRetryInterval; + } catch (VirtualMachineMigrationException e) { + s_logger.warn("Looks like VM is still starting, we need to retry migrating the VM later."); + _agentMgr.maintenanceFailed(srcHostId); + return (System.currentTimeMillis() >> 10) + _migrateRetryInterval; } } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 99f16afc1ca..b2285ebcfe2 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -100,6 +100,7 @@ import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.StorageUnavailableException; +import com.cloud.exception.VirtualMachineMigrationException; import com.cloud.ha.HighAvailabilityManager; import com.cloud.host.Host; import com.cloud.host.HostVO; @@ -2910,7 +2911,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } @Override - public UserVm migrateVirtualMachine(UserVm vm, Host destinationHost) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException{ + public UserVm migrateVirtualMachine(UserVm vm, Host destinationHost) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException{ //access check - only root admin can migrate VM Account caller = UserContext.current().getCaller(); if(caller.getType() != Account.ACCOUNT_TYPE_ADMIN){ diff --git a/server/src/com/cloud/vm/VirtualMachineManager.java b/server/src/com/cloud/vm/VirtualMachineManager.java index 2382a4d6b55..c0e1f95eb01 100644 --- a/server/src/com/cloud/vm/VirtualMachineManager.java +++ b/server/src/com/cloud/vm/VirtualMachineManager.java @@ -29,6 +29,7 @@ import com.cloud.exception.InsufficientServerCapacityException; import com.cloud.exception.ManagementServerException; import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.VirtualMachineMigrationException; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.NetworkVO; import com.cloud.service.ServiceOfferingVO; @@ -93,9 +94,9 @@ public interface VirtualMachineManager extends Manager { boolean destroy(T vm, User caller, Account account) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException; - boolean migrateAway(VirtualMachine.Type type, long vmid, long hostId) throws InsufficientServerCapacityException; + boolean migrateAway(VirtualMachine.Type type, long vmid, long hostId) throws InsufficientServerCapacityException, VirtualMachineMigrationException; - T migrate(T vm, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException; + T migrate(T vm, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException; T reboot(T vm, Map params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException; diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 489e4b13ccb..e8e6045b483 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -85,6 +85,7 @@ import com.cloud.exception.InsufficientServerCapacityException; import com.cloud.exception.ManagementServerException; import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.VirtualMachineMigrationException; import com.cloud.ha.HighAvailabilityManager; import com.cloud.ha.HighAvailabilityManager.WorkType; import com.cloud.host.Host; @@ -959,36 +960,37 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene } @Override - public T migrate(T vm, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException { + public T migrate(T vm, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException { s_logger.info("Migrating " + vm + " to " + dest); long dstHostId = dest.getHost().getId(); Host fromHost = _hostDao.findById(srcHostId); if (fromHost == null) { s_logger.info("Unable to find the host to migrate from: " + srcHostId); - throw new ManagementServerException("Unable to find the host to migrate from: " + srcHostId); + throw new CloudRuntimeException("Unable to find the host to migrate from: " + srcHostId); } if(fromHost.getClusterId().longValue() != dest.getCluster().getId()){ s_logger.info("Source and destination host are not in same cluster, unable to migrate to host: " + dest.getHost().getId()); - throw new ManagementServerException("Source and destination host are not in same cluster, unable to migrate to host: " + dest.getHost().getId()); + throw new CloudRuntimeException("Source and destination host are not in same cluster, unable to migrate to host: " + dest.getHost().getId()); } VirtualMachineGuru vmGuru = getVmGuru(vm); - vm = vmGuru.findById(vm.getId()); + long vmId = vm.getId(); + vm = vmGuru.findById(vmId); if (vm == null) { if (s_logger.isDebugEnabled()) { s_logger.debug("Unable to find the vm " + vm); } - throw new ManagementServerException("Unable to find a virtual machine with id " + vm.getId()); + throw new ManagementServerException("Unable to find a virtual machine with id " + vmId); } if(vm.getState() != State.Running){ if (s_logger.isDebugEnabled()) { s_logger.debug("VM is not Running, unable to migrate the vm " + vm); } - throw new ManagementServerException("VM is not Running, unable to migrate the vm " + vm); + throw new VirtualMachineMigrationException("VM is not Running, unable to migrate the vm currently " + vm); } short alertType = AlertManager.ALERT_TYPE_USERVM_MIGRATE; @@ -1058,12 +1060,16 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene try { if (!checkVmOnHost(vm, dstHostId)) { s_logger.error("Unable to complete migration for " + vm); - _agentMgr.send(srcHostId, new Commands(cleanup(vm.getInstanceName())), null); + try{ + _agentMgr.send(srcHostId, new Commands(cleanup(vm.getInstanceName())), null); + }catch (AgentUnavailableException e) { + s_logger.error("AgentUnavailableException while cleanup on source host: " + srcHostId); + } cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.AgentReportStopped, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); return null; } } catch (OperationTimedoutException e) { - } + } migrated = true; return vm; @@ -1072,8 +1078,11 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene s_logger.info("Migration was unsuccessful. Cleaning up: " + vm); _alertMgr.sendAlert(alertType, fromHost.getDataCenterId(), fromHost.getPodId(), "Unable to migrate vm " + vm.getName() + " from host " + fromHost.getName() + " in zone " + dest.getDataCenter().getName() + " and pod " + dest.getPod().getName(), "Migrate Command failed. Please check logs."); - - _agentMgr.send(dstHostId, new Commands(cleanup(vm.getInstanceName())), null); + try{ + _agentMgr.send(dstHostId, new Commands(cleanup(vm.getInstanceName())), null); + }catch(AgentUnavailableException ae){ + s_logger.info("Looks like the destination Host is unavailable for cleanup"); + } stateTransitTo(vm, Event.OperationFailed, srcHostId); } @@ -1082,6 +1091,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene _workDao.update(work.getId(), work); } } + protected void cancelWorkItems(long nodeId) { GlobalLock scanLock = GlobalLock.getInternLock(this.getClass().getName()); @@ -1119,7 +1129,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene } @Override - public boolean migrateAway(VirtualMachine.Type vmType, long vmId, long srcHostId) throws InsufficientServerCapacityException { + public boolean migrateAway(VirtualMachine.Type vmType, long vmId, long srcHostId) throws InsufficientServerCapacityException, VirtualMachineMigrationException { VirtualMachineGuru vmGuru = _vmGurus.get(vmType); VMInstanceVO vm = vmGuru.findById(vmId); if (vm == null) { @@ -1170,6 +1180,14 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene s_logger.debug("Unable to migrate VM due to: " + e.getMessage()); } catch (ManagementServerException e) { s_logger.debug("Unable to migrate VM: " + e.getMessage()); + } catch (VirtualMachineMigrationException e) { + s_logger.debug("Got VirtualMachineMigrationException, Unable to migrate: " + e.getMessage()); + if(vm.getState() == State.Starting){ + s_logger.debug("VM seems to be still Starting, we should retry migration later"); + throw e; + }else{ + s_logger.debug("Unable to migrate VM, VM is not in Running or even Starting state, current state: "+vm.getState().toString()); + } } if (vmInstance != null) { return true; diff --git a/utils/src/com/cloud/utils/SerialVersionUID.java b/utils/src/com/cloud/utils/SerialVersionUID.java index a964ec0277a..fd8abffb5c1 100755 --- a/utils/src/com/cloud/utils/SerialVersionUID.java +++ b/utils/src/com/cloud/utils/SerialVersionUID.java @@ -60,4 +60,5 @@ public interface SerialVersionUID { public static final long ConnectionException = Base | 0x20; public static final long PermissionDeniedException = Base | 0x21; public static final long sshException = Base | 0x22; + public static final long VirtualMachineMigrationException = Base | 0x24; } From 534623706d6a252d4cd7a07265cc21c640f86a83 Mon Sep 17 00:00:00 2001 From: alena Date: Mon, 4 Apr 2011 17:50:36 -0700 Subject: [PATCH 64/72] bug 9305: set Mode field for domR/CPVM/SSVM nics status 9305: resolved fixed --- .../com/cloud/network/NetworkManagerImpl.java | 6 ++++ .../cloud/network/guru/PublicNetworkGuru.java | 1 - .../cloud/upgrade/dao/Upgrade222to224.java | 31 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index b3dfd7e56bd..c27f314516b 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -953,6 +953,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag continue; } + if (requested != null && requested.getMode() == null) { + profile.setMode(requested.getMode()); + } else { + profile.setMode(config.getMode()); + } + NicVO vo = new NicVO(guru.getName(), vm.getId(), config.getId(), vm.getType()); while (deviceIds[deviceId] && deviceId < deviceIds.length) { diff --git a/server/src/com/cloud/network/guru/PublicNetworkGuru.java b/server/src/com/cloud/network/guru/PublicNetworkGuru.java index 0dc57239dc1..e86bf9bf671 100644 --- a/server/src/com/cloud/network/guru/PublicNetworkGuru.java +++ b/server/src/com/cloud/network/guru/PublicNetworkGuru.java @@ -19,7 +19,6 @@ import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientVirtualNetworkCapcityException; import com.cloud.network.IPAddressVO; import com.cloud.network.Network; -import com.cloud.network.Network.GuestIpType; import com.cloud.network.Network.State; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkProfile; diff --git a/server/src/com/cloud/upgrade/dao/Upgrade222to224.java b/server/src/com/cloud/upgrade/dao/Upgrade222to224.java index 1424ceb12f2..18cff6b95d6 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade222to224.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade222to224.java @@ -22,6 +22,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.HashMap; import com.cloud.capacity.Capacity; import com.cloud.utils.exception.CloudRuntimeException; @@ -58,6 +59,7 @@ public class Upgrade222to224 implements DbUpgrade { public void performDataMigration(Connection conn) { updateClusterIdInOpHostCapacity(conn); updateGuestOsType(conn); + updateNicsWithMode(conn); } @Override @@ -144,4 +146,33 @@ public class Upgrade222to224 implements DbUpgrade { } } + + private void updateNicsWithMode(Connection conn) { + try { + HashMap nicNetworkMaps = new HashMap(); + PreparedStatement pstmt = conn.prepareStatement("SELECT id, network_id FROM nics WHERE mode IS NULL"); + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) { + nicNetworkMaps.put(rs.getLong(1), rs.getLong(2)); + } + + for (Long nic : nicNetworkMaps.keySet()) { + pstmt = conn.prepareStatement("SELECT mode FROM networks WHERE id=?"); + pstmt.setLong(1, nicNetworkMaps.get(nic)); + rs = pstmt.executeQuery(); + if (rs.next()) { + String mode = rs.getString(1); + pstmt = conn.prepareStatement("UPDATE nics SET mode=? where id=?"); + pstmt.setString(1, mode); + pstmt.setLong(2, nic); + pstmt.executeUpdate(); + } + } + rs.close(); + pstmt.close(); + + }catch (SQLException e) { + throw new CloudRuntimeException("Unable to update the Mode field for nics as a part of 222 to 224 upgrade", e); + } + } } From 49cbcac29fdd041d973df0c7b74b4045a7fd332e Mon Sep 17 00:00:00 2001 From: alena Date: Mon, 4 Apr 2011 18:01:27 -0700 Subject: [PATCH 65/72] bug 8959: fixed mac address generation for public ip addresses --- server/src/com/cloud/network/NetworkManagerImpl.java | 2 +- .../network/router/VirtualNetworkApplianceManagerImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index c27f314516b..c69d128e080 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -426,7 +426,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag List publicIps = new ArrayList(); if (userIps != null && !userIps.isEmpty()) { for (IPAddressVO userIp : userIps) { - PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), userIp.getMacAddress()); + PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress())); publicIps.add(publicIp); } } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 3b854fc36f9..f4a7fd7d438 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1010,7 +1010,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian List publicIps = new ArrayList(); if (userIps != null && !userIps.isEmpty()) { for (IPAddressVO userIp : userIps) { - PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), userIp.getMacAddress()); + PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress())); publicIps.add(publicIp); } } From d958aefe466e935ba848c6cc2424b0f4d858f5e2 Mon Sep 17 00:00:00 2001 From: Chiradeep Vittal Date: Mon, 4 Apr 2011 18:56:58 -0700 Subject: [PATCH 66/72] bug 8959: 1. rp_filter prevents connections that span eth2 and eth3 because of default route 2. delete before add of default nat rules status 8959: resolved fixed --- patches/systemvm/debian/config/etc/init.d/cloud-early-config | 1 + patches/systemvm/debian/config/root/ipassoc.sh | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/patches/systemvm/debian/config/etc/init.d/cloud-early-config b/patches/systemvm/debian/config/etc/init.d/cloud-early-config index ead55838a01..f9ee700419c 100755 --- a/patches/systemvm/debian/config/etc/init.d/cloud-early-config +++ b/patches/systemvm/debian/config/etc/init.d/cloud-early-config @@ -275,6 +275,7 @@ setup_router() { enable_svc haproxy 1 enable_svc cloud-passwd-srvr 1 enable_svc cloud 0 + disable_rpfilter enable_fwding 1 chkconfig nfs-common off cp /etc/iptables/iptables-router /etc/iptables/rules diff --git a/patches/systemvm/debian/config/root/ipassoc.sh b/patches/systemvm/debian/config/root/ipassoc.sh index e7739772747..99895b6bcc5 100644 --- a/patches/systemvm/debian/config/root/ipassoc.sh +++ b/patches/systemvm/debian/config/root/ipassoc.sh @@ -16,14 +16,19 @@ add_nat_entry() { local ipNoMask=$(echo $1 | awk -F'/' '{print $1}') sudo ip link set $ethDev up sudo ip addr add dev $ethDev $pubIp + sudo iptables -D FORWARD -i $ethDev -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT + sudo iptables -D FORWARD -i eth0 -o $ethDev -j ACCEPT + sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ; sudo iptables -A FORWARD -i $ethDev -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i eth0 -o $ethDev -j ACCEPT sudo iptables -t nat -I POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ; sudo arping -c 3 -I $ethDev -A -U -s $ipNoMask $ipNoMask; if [ $? -gt 0 -a $? -ne 2 ] then + logger -t cloud "$(basename $0):Failed adding nat entry for ip $pubIp on interface $ethDev" return 1 fi + logger -t cloud "$(basename $0):Added nat entry for ip $pubIp on interface $ethDev" return 0 From 04099a4950359318da10ccea7f34054e8a8dffec Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Tue, 5 Apr 2011 09:10:57 -0700 Subject: [PATCH 67/72] bug 9311: changed instance_id to nic_id --- .../dc/DataCenterLinkLocalIpAddressVO.java | 2 +- .../com/cloud/upgrade/dao/Upgrade218to22.java | 52 +++++++++++++++---- .../AdvanceZone217To224UpgradeTest.java | 13 +++++ setup/db/create-schema.sql | 2 +- setup/db/db/schema-21to22.sql | 2 - setup/db/db/schema-222to224.sql | 3 ++ 6 files changed, 61 insertions(+), 13 deletions(-) diff --git a/server/src/com/cloud/dc/DataCenterLinkLocalIpAddressVO.java b/server/src/com/cloud/dc/DataCenterLinkLocalIpAddressVO.java index b98138de8da..7d294e31c72 100644 --- a/server/src/com/cloud/dc/DataCenterLinkLocalIpAddressVO.java +++ b/server/src/com/cloud/dc/DataCenterLinkLocalIpAddressVO.java @@ -50,7 +50,7 @@ public class DataCenterLinkLocalIpAddressVO { @Column(name="pod_id", updatable=false, nullable=false) private long podId; - @Column(name="instance_id") + @Column(name="nic_id") private Long instanceId; @Column(name="reservation_id") diff --git a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java index 25b62734c51..b3bf4815c78 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java @@ -210,7 +210,7 @@ public class Upgrade218to22 implements DbUpgrade { return nicId; } - protected void upgradeDomR(Connection conn, long domrId, Long publicNetworkId, long guestNetworkId, long controlNetworkId, String zoneType) throws SQLException { + protected void upgradeDomR(Connection conn, long dcId, long domrId, Long publicNetworkId, long guestNetworkId, long controlNetworkId, String zoneType) throws SQLException { s_logger.debug("Upgrading domR" + domrId); PreparedStatement pstmt = conn.prepareStatement("SELECT vm_instance.id, vm_instance.state, vm_instance.private_mac_address, vm_instance.private_ip_address, vm_instance.private_netmask, domain_router.public_mac_address, domain_router.public_ip_address, domain_router.public_netmask, domain_router.guest_mac_address, domain_router.guest_ip_address, domain_router.guest_netmask, domain_router.vnet, domain_router.gateway, vm_instance.type FROM vm_instance INNER JOIN domain_router ON vm_instance.id=domain_router.id WHERE vm_instance.removed is NULL AND vm_instance.id=?"); pstmt.setLong(1, domrId); @@ -239,11 +239,28 @@ public class Upgrade218to22 implements DbUpgrade { pstmt.close(); if (zoneType.equalsIgnoreCase("Basic")) { - insertNic(conn, controlNetworkId, domrId, running, privateMac, privateIp, privateNetmask, "Start", "169.254.0.1", null, "ControlNetworkGuru", false, 1, "Static", privateIp != null ? (domrId + privateIp) : null); + long controlNicId = insertNic(conn, controlNetworkId, domrId, running, privateMac, privateIp, privateNetmask, "Start", "169.254.0.1", null, "ControlNetworkGuru", false, 1, "Static", privateIp != null ? (domrId + privateIp) : null); + if (privateIp != null) { + pstmt = conn.prepareStatement("UPDATE op_dc_link_local_ip_address_alloc SET instance_id=? WHERE ip_address=? AND data_center_id=?"); + pstmt.setLong(1, controlNicId); + pstmt.setString(2, privateIp); + pstmt.setLong(3, dcId); + pstmt.executeUpdate(); + pstmt.close(); + } + insertNic(conn, guestNetworkId, domrId, running, guestMac, guestIp, guestNetmask, "Start", gateway, vnet, "DirectPodBasedNetworkGuru", false, 0, "Static", null); } else { insertNic(conn, publicNetworkId, domrId, running, publicMac, publicIp, publicNetmask, "Create", gateway, null, "PublicNetworkGuru", true, 2, "Static", null); - insertNic(conn, controlNetworkId, domrId, running, privateMac, privateIp, privateNetmask, "Start", "169.254.0.1", null, "ControlNetworkGuru", false, 1, "Static", privateIp != null ? (domrId + privateIp) : null); + long controlNicId = insertNic(conn, controlNetworkId, domrId, running, privateMac, privateIp, privateNetmask, "Start", "169.254.0.1", null, "ControlNetworkGuru", false, 1, "Static", privateIp != null ? (domrId + privateIp) : null); + if (privateIp != null) { + pstmt = conn.prepareStatement("UPDATE op_dc_link_local_ip_address_alloc SET instance_id=? WHERE ip_address=? AND data_center_id=?"); + pstmt.setLong(1, controlNicId); + pstmt.setString(2, privateIp); + pstmt.setLong(3, dcId); + pstmt.executeUpdate(); + pstmt.close(); + } insertNic(conn, guestNetworkId, domrId, running, guestMac, guestIp, guestNetmask, "Start", null, vnet, "ExternalGuestNetworkGuru", false, 0, "Static", null); } @@ -300,10 +317,19 @@ public class Upgrade218to22 implements DbUpgrade { insertNic(conn, publicNetworkId, ssvmId, running, publicMac, publicIp, publicNetmask, "Create", gateway, null, "PublicNetworkGuru", true, 2, "Static", null); } - insertNic(conn, controlNetworkId, ssvmId, running, guestMac, guestIp, guestNetmask, "Start", "169.254.0.1", null, "ControlNetworkGuru", false, 0, "Static", guestIp != null ? (ssvmId + guestIp) : null); + long controlNicId = insertNic(conn, controlNetworkId, ssvmId, running, guestMac, guestIp, guestNetmask, "Start", "169.254.0.1", null, "ControlNetworkGuru", false, 0, "Static", guestIp != null ? (ssvmId + guestIp) : null); + if (guestIp != null) { + pstmt = conn.prepareStatement("UPDATE op_dc_link_local_ip_address_alloc SET instance_id=? WHERE ip_address=? AND data_center_id=?"); + pstmt.setLong(1, controlNicId); + pstmt.setString(2, guestIp); + pstmt.setLong(3, dataCenterId); + pstmt.executeUpdate(); + pstmt.close(); + } + long mgmtNicId = insertNic(conn, managementNetworkId, ssvmId, running, privateMac, privateIp, privateNetmask, "Start", podGateway, null, "PodBasedNetworkGuru", false, 1, "Static", null); if (privateIp != null) { - pstmt = conn.prepareStatement("UPDATE op_dc_ip_address_alloc SET nic_id=? WHERE ip_address=? AND data_center_id=?"); + pstmt = conn.prepareStatement("UPDATE op_dc_ip_address_alloc SET instance_id=? WHERE ip_address=? AND data_center_id=?"); pstmt.setLong(1, mgmtNicId); pstmt.setString(2, privateIp); pstmt.setLong(3, dataCenterId); @@ -358,10 +384,18 @@ public class Upgrade218to22 implements DbUpgrade { insertNic(conn, publicNetworkId, cpId, running, publicMac, publicIp, publicNetmask, "Create", gateway, null, "PublicNetworkGuru", true, 2, "Static", null); } - insertNic(conn, controlNetworkId, cpId, running, guestMac, guestIp, guestNetmask, "Start", "169.254.0.1", null, "ControlNetworkGuru", false, 0, "Static", guestIp != null ? (cpId + guestIp) : null); + long controlNicId = insertNic(conn, controlNetworkId, cpId, running, guestMac, guestIp, guestNetmask, "Start", "169.254.0.1", null, "ControlNetworkGuru", false, 0, "Static", guestIp != null ? (cpId + guestIp) : null); + if (guestIp != null) { + pstmt = conn.prepareStatement("UPDATE op_dc_link_local_ip_address_alloc SET instance_id=? WHERE ip_address=? AND data_center_id=?"); + pstmt.setLong(1, controlNicId); + pstmt.setString(2, guestIp); + pstmt.setLong(3, dcId); + pstmt.executeUpdate(); + pstmt.close(); + } long mgmtNicId = insertNic(conn, managementNetworkId, cpId, running, privateMac, privateIp, privateNetmask, "Start", podGateway, null, "PodBasedNetworkGuru", false, 1, "Static", privateIp != null ? (cpId + privateIp) : null); if (privateIp != null) { - pstmt = conn.prepareStatement("UPDATE op_dc_ip_address_alloc SET nic_id=? WHERE ip_address=? AND data_center_id=?"); + pstmt = conn.prepareStatement("UPDATE op_dc_ip_address_alloc SET instance_id=? WHERE ip_address=? AND data_center_id=?"); pstmt.setLong(1, mgmtNicId); pstmt.setString(2, privateIp); pstmt.setLong(3, dcId); @@ -794,7 +828,7 @@ public class Upgrade218to22 implements DbUpgrade { pstmt.close(); upgradeBasicUserVms(conn, (Long)router[0], basicDefaultDirectNetworkId, (String)router[1], "untagged"); - upgradeDomR(conn, (Long)router[0], null, basicDefaultDirectNetworkId, controlNetworkId, "Basic"); + upgradeDomR(conn, dcId, (Long)router[0], null, basicDefaultDirectNetworkId, controlNetworkId, "Basic"); } upgradeSsvm(conn, dcId, basicDefaultDirectNetworkId, mgmtNetworkId, controlNetworkId, "Basic"); @@ -852,7 +886,7 @@ public class Upgrade218to22 implements DbUpgrade { s_logger.debug("Network inserted for " + router[0] + " id = " + virtualNetworkId); upgradeVirtualUserVms(conn, (Long)router[0], virtualNetworkId, (String)router[3], vnet); - upgradeDomR(conn, (Long)router[0], publicNetworkId, virtualNetworkId, controlNetworkId, "Advanced"); + upgradeDomR(conn, dcId, (Long)router[0], publicNetworkId, virtualNetworkId, controlNetworkId, "Advanced"); } upgradePublicUserIpAddress(conn, dcId, publicNetworkId, "VirtualNetwork"); diff --git a/server/test/com/cloud/upgrade/AdvanceZone217To224UpgradeTest.java b/server/test/com/cloud/upgrade/AdvanceZone217To224UpgradeTest.java index 11b334e4544..c119d5eb07f 100644 --- a/server/test/com/cloud/upgrade/AdvanceZone217To224UpgradeTest.java +++ b/server/test/com/cloud/upgrade/AdvanceZone217To224UpgradeTest.java @@ -92,6 +92,19 @@ public class AdvanceZone217To224UpgradeTest extends TestCase { rs.close(); pstmt.close(); + pstmt = conn.prepareStatement("SELECT COUNT(*) FROM op_dc_link_local_ip_address_alloc WHERE nic_id IS NOT NULL"); + rs = pstmt.executeQuery(); + rs.next(); + int controlNics = rs.getInt(1); + rs.close(); + pstmt.close(); + + pstmt = conn.prepareStatement("SELECT COUNT(*) FROM nics WHERE reserver_name='ControlNetworkGuru' and ip4_address is NOT NULL"); + rs = pstmt.executeQuery(); + assert (rs.next() && controlNics == rs.getInt(1)) : "Allocated nics should have been " + controlNics + " but it is " + rs.getInt(1); + rs.close(); + pstmt.close(); + } finally { try { diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 2c8104320d5..65a8c463fc5 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -518,7 +518,7 @@ CREATE TABLE `cloud`.`op_dc_link_local_ip_address_alloc` ( `ip_address` char(40) NOT NULL COMMENT 'ip address', `data_center_id` bigint unsigned NOT NULL COMMENT 'data center it belongs to', `pod_id` bigint unsigned NOT NULL COMMENT 'pod it belongs to', - `instance_id` bigint unsigned NULL COMMENT 'instance id', + `nic_id` bigint unsigned NULL COMMENT 'instance id', `reservation_id` char(40) NULL COMMENT 'reservation id used to reserve this network', `taken` datetime COMMENT 'Date taken', PRIMARY KEY (`id`) diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index b1a5b36887b..26454f13f84 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -950,5 +950,3 @@ ALTER TABLE `cloud`.`instance_group` ADD CONSTRAINT `fk_instance_group__account_ ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___group_id` FOREIGN KEY `fk_instance_group_vm_map___group_id` (`group_id`) REFERENCES `instance_group` (`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___instance_id` FOREIGN KEY `fk_instance_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`domain` MODIFY COLUMN `path` varchar(255) UNIQUE NOT NULL; -ALTER TABLE `cloud`.`op_dc_ip_address_alloc` CHANGE COLUMN `instance_id` `nic_id` bigint unsigned DEFAULT NULL; -ALTER TABLE op_dc_ip_address_alloc ADD CONSTRAINT `fk_op_dc_ip_address_alloc__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE; diff --git a/setup/db/db/schema-222to224.sql b/setup/db/db/schema-222to224.sql index ee5aab6337b..4173b049fc8 100644 --- a/setup/db/db/schema-222to224.sql +++ b/setup/db/db/schema-222to224.sql @@ -113,3 +113,6 @@ INSERT INTO `cloud`.`configuration` VALUES ('Advanced','DEFAULT','management-server','vmware.service.console','Service Console','Specify the service console network name (ESX host only)'), ('Advanced','DEFAULT','AgentManager','xapiwait','600','Time (in seconds) to wait for XAPI to return'); +ALTER TABLE `cloud`.`op_dc_ip_address_alloc` CHANGE COLUMN `instance_id` `nic_id` bigint unsigned DEFAULT NULL; +ALTER TABLE op_dc_ip_address_alloc ADD CONSTRAINT `fk_op_dc_ip_address_alloc__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE; +ALTER TABLE `cloud`.`op_dc_link_local_ip_address_alloc` CHANGE COLUMN `instance_id` `nic_id` bigint unsigned DEFAULT NULL; From 61f968592bfb92ab845ec256321091a303ce6bdc Mon Sep 17 00:00:00 2001 From: alena Date: Tue, 5 Apr 2011 09:14:27 -0700 Subject: [PATCH 68/72] bug 9306: set isolationUri/broadcastUri for SSVM/domR/CPVM public nics status 9306: resolved fixed --- .../com/cloud/upgrade/dao/Upgrade218to22.java | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java index b3bf4815c78..5d5058c5d28 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java @@ -238,6 +238,16 @@ public class Upgrade218to22 implements DbUpgrade { rs.close(); pstmt.close(); + + pstmt = conn.prepareStatement("SELECT v.vlan_id from vlan v, user_ip_address u where v.id=u.vlan_db_id and u.public_ip_address=?"); + pstmt.setString(1, publicIp); + rs = pstmt.executeQuery(); + + String publicVlan = null; + while (rs.next()) { + publicVlan = rs.getString(1); + } + if (zoneType.equalsIgnoreCase("Basic")) { long controlNicId = insertNic(conn, controlNetworkId, domrId, running, privateMac, privateIp, privateNetmask, "Start", "169.254.0.1", null, "ControlNetworkGuru", false, 1, "Static", privateIp != null ? (domrId + privateIp) : null); if (privateIp != null) { @@ -251,7 +261,7 @@ public class Upgrade218to22 implements DbUpgrade { insertNic(conn, guestNetworkId, domrId, running, guestMac, guestIp, guestNetmask, "Start", gateway, vnet, "DirectPodBasedNetworkGuru", false, 0, "Static", null); } else { - insertNic(conn, publicNetworkId, domrId, running, publicMac, publicIp, publicNetmask, "Create", gateway, null, "PublicNetworkGuru", true, 2, "Static", null); + insertNic(conn, publicNetworkId, domrId, running, publicMac, publicIp, publicNetmask, "Create", gateway, publicVlan, "PublicNetworkGuru", true, 2, "Static", null); long controlNicId = insertNic(conn, controlNetworkId, domrId, running, privateMac, privateIp, privateNetmask, "Start", "169.254.0.1", null, "ControlNetworkGuru", false, 1, "Static", privateIp != null ? (domrId + privateIp) : null); if (privateIp != null) { pstmt = conn.prepareStatement("UPDATE op_dc_link_local_ip_address_alloc SET instance_id=? WHERE ip_address=? AND data_center_id=?"); @@ -310,11 +320,24 @@ public class Upgrade218to22 implements DbUpgrade { s_logger.debug("Gateway is " + podGateway); + pstmt = conn.prepareStatement("SELECT v.vlan_id from vlan v, user_ip_address u where v.id=u.vlan_db_id and u.public_ip_address=?"); + pstmt.setString(1, publicIp); + rs = pstmt.executeQuery(); + + String publicVlan = null; + while (rs.next()) { + publicVlan = rs.getString(1); + } + + rs.close(); + pstmt.close(); + + if (zoneType.equalsIgnoreCase("Basic")) { - insertNic(conn, publicNetworkId, ssvmId, running, publicMac, publicIp, publicNetmask, "Start", gateway, null, "DirectPodBasedNetworkGuru", true, 2, "Static", null); + insertNic(conn, publicNetworkId, ssvmId, running, publicMac, publicIp, publicNetmask, "Start", gateway, publicVlan, "DirectPodBasedNetworkGuru", true, 2, "Static", null); } else { - insertNic(conn, publicNetworkId, ssvmId, running, publicMac, publicIp, publicNetmask, "Create", gateway, null, "PublicNetworkGuru", true, 2, "Static", null); + insertNic(conn, publicNetworkId, ssvmId, running, publicMac, publicIp, publicNetmask, "Create", gateway, publicVlan, "PublicNetworkGuru", true, 2, "Static", null); } long controlNicId = insertNic(conn, controlNetworkId, ssvmId, running, guestMac, guestIp, guestNetmask, "Start", "169.254.0.1", null, "ControlNetworkGuru", false, 0, "Static", guestIp != null ? (ssvmId + guestIp) : null); @@ -377,11 +400,22 @@ public class Upgrade218to22 implements DbUpgrade { rs.close(); pstmt.close(); + pstmt = conn.prepareStatement("SELECT v.vlan_id from vlan v, user_ip_address u where v.id=u.vlan_db_id and u.public_ip_address=?"); + pstmt.setString(1, publicIp); + rs = pstmt.executeQuery(); + + String publicVlan = null; + while (rs.next()) { + publicVlan = rs.getString(1); + } + + rs.close(); + pstmt.close(); if (zoneType.equalsIgnoreCase("Basic")) { - insertNic(conn, publicNetworkId, cpId, running, publicMac, publicIp, publicNetmask, "Start", gateway, null, "DirectPodBasedNetworkGuru", true, 2, "Static", null); + insertNic(conn, publicNetworkId, cpId, running, publicMac, publicIp, publicNetmask, "Start", gateway, publicVlan, "DirectPodBasedNetworkGuru", true, 2, "Static", null); } else { - insertNic(conn, publicNetworkId, cpId, running, publicMac, publicIp, publicNetmask, "Create", gateway, null, "PublicNetworkGuru", true, 2, "Static", null); + insertNic(conn, publicNetworkId, cpId, running, publicMac, publicIp, publicNetmask, "Create", gateway, publicVlan, "PublicNetworkGuru", true, 2, "Static", null); } long controlNicId = insertNic(conn, controlNetworkId, cpId, running, guestMac, guestIp, guestNetmask, "Start", "169.254.0.1", null, "ControlNetworkGuru", false, 0, "Static", guestIp != null ? (cpId + guestIp) : null); From e4cffa7928d528dda055174989612ee8a1370fe0 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Tue, 5 Apr 2011 10:15:27 -0700 Subject: [PATCH 69/72] removed the DEFAULT 0 --- setup/db/create-schema.sql | 2 +- setup/db/db/schema-21to22.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 65a8c463fc5..ddad7391e0b 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -870,7 +870,7 @@ CREATE TABLE `cloud`.`domain_router` ( `public_netmask` varchar(15) COMMENT 'netmask used for the domR', `guest_netmask` varchar(15) COMMENT 'netmask used for the guest network', `guest_ip_address` char(40) COMMENT ' ip address in the guest network', - `network_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT 'network configuration that this domain router belongs to', + `network_id` bigint unsigned NOT NULL COMMENT 'network configuration that this domain router belongs to', `role` varchar(64) NOT NULL COMMENT 'type of role played by this router', PRIMARY KEY (`id`), CONSTRAINT `fk_domain_router__id` FOREIGN KEY `fk_domain_router__id` (`id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index 26454f13f84..47c58eb714a 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -335,7 +335,7 @@ CREATE TABLE `cloud`.`user_vm_details` ( ALTER TABLE `cloud`.`domain_router` MODIFY COLUMN `guest_netmask` varchar(15); ALTER TABLE `cloud`.`domain_router` MODIFY COLUMN `guest_ip_address` varchar(15); -ALTER TABLE `cloud`.`domain_router` ADD COLUMN `network_id` bigint unsigned NOT NULL DEFAULT 0; +ALTER TABLE `cloud`.`domain_router` ADD COLUMN `network_id` bigint unsigned NOT NULL; CREATE TABLE `cloud`.`upload` ( `id` bigint unsigned NOT NULL auto_increment, From 3f8dc115ec9e9ae2c303ac139025e0160ea17202 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Tue, 5 Apr 2011 11:09:39 -0700 Subject: [PATCH 70/72] bug 9323: dropped the snapshots_seq --- setup/db/db/schema-222to224.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup/db/db/schema-222to224.sql b/setup/db/db/schema-222to224.sql index 4173b049fc8..2cca467694a 100644 --- a/setup/db/db/schema-222to224.sql +++ b/setup/db/db/schema-222to224.sql @@ -116,3 +116,5 @@ INSERT INTO `cloud`.`configuration` VALUES ALTER TABLE `cloud`.`op_dc_ip_address_alloc` CHANGE COLUMN `instance_id` `nic_id` bigint unsigned DEFAULT NULL; ALTER TABLE op_dc_ip_address_alloc ADD CONSTRAINT `fk_op_dc_ip_address_alloc__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`op_dc_link_local_ip_address_alloc` CHANGE COLUMN `instance_id` `nic_id` bigint unsigned DEFAULT NULL; + +DELETE FROM `sequence` WHERE name='snapshots_seq'; \ No newline at end of file From 914952cd86703e7e41e90f5ec38e5e4c30e627a5 Mon Sep 17 00:00:00 2001 From: alena Date: Tue, 5 Apr 2011 11:17:49 -0700 Subject: [PATCH 71/72] bug 9325: DB upgrade - added missing constraints to ssh_keypair table status 9325: resolved fixed --- setup/db/db/schema-21to22.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index 47c58eb714a..90bf24f34fb 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -950,3 +950,6 @@ ALTER TABLE `cloud`.`instance_group` ADD CONSTRAINT `fk_instance_group__account_ ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___group_id` FOREIGN KEY `fk_instance_group_vm_map___group_id` (`group_id`) REFERENCES `instance_group` (`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___instance_id` FOREIGN KEY `fk_instance_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`domain` MODIFY COLUMN `path` varchar(255) UNIQUE NOT NULL; + +ALTER TABLE `cloud`.`ssh_keypairs` ADD CONSTRAINT `fk_ssh_keypairs__account_id` FOREIGN KEY `fk_ssh_keypair__account_id` (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE; +ALTER TABLE `cloud`.`ssh_keypairs` ADD CONSTRAINT `fk_ssh_keypairs__domain_id` FOREIGN KEY `fk_ssh_keypair__domain_id` (`domain_id`) REFERENCES `domain` (`id`) ON DELETE CASCADE; From c9d4e50b968cf2cde365cd7d9d7366ee58401afe Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Tue, 5 Apr 2011 11:22:56 -0700 Subject: [PATCH 72/72] bug 9323: guid doesn't have to be NOT NULL --- setup/db/db/schema-21to22.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index 90bf24f34fb..43ac416eb5c 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -949,6 +949,7 @@ ALTER TABLE `cloud`.`instance_group` ADD CONSTRAINT `fk_instance_group__account_ ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___group_id` FOREIGN KEY `fk_instance_group_vm_map___group_id` (`group_id`) REFERENCES `instance_group` (`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___instance_id` FOREIGN KEY `fk_instance_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE; +ALTER TABLE `cloud`.`secondary_storage_vm` MODIFY COLUMN `guid` varchar(255); ALTER TABLE `cloud`.`domain` MODIFY COLUMN `path` varchar(255) UNIQUE NOT NULL; ALTER TABLE `cloud`.`ssh_keypairs` ADD CONSTRAINT `fk_ssh_keypairs__account_id` FOREIGN KEY `fk_ssh_keypair__account_id` (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE;