Merge branch '2.1.refactor' of ssh://git.cloud.com/var/lib/git/cloudstack-oss into 2.1.refactor

This commit is contained in:
alena 2010-09-08 19:04:13 -07:00
commit fd680189f6
53 changed files with 2292 additions and 1269 deletions

View File

@ -15,30 +15,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.vm;
import java.util.Date;
/**
* ConsoleProxy is a system VM instance that is used
* to proxy VNC traffic
*/
public interface ConsoleProxy extends VirtualMachine {
public String getGateway();
public String getDns1();
public String getDns2();
public String getDomain();
public String getPublicIpAddress();
public String getPublicNetmask();
public String getPublicMacAddress();
public Long getVlanDbId();
public String getVlanId();
public String getPrivateNetmask();
public int getRamSize();
public int getActiveSession();
public Date getLastUpdateTime();
public interface ConsoleProxy extends SystemVm {
public byte[] getSessionDetails();
}

View File

@ -17,25 +17,10 @@
*/
package com.cloud.vm;
import java.util.Date;
/**
* Secondary Storage VM is a system VM instance that is used
* to interface the management server to secondary storage
*/
public interface SecondaryStorageVm extends VirtualMachine {
public String getGateway();
public String getDns1();
public String getDns2();
public String getDomain();
public String getPublicIpAddress();
public String getPublicNetmask();
public String getPublicMacAddress();
public Long getVlanDbId();
public String getVlanId();
public String getPrivateNetmask();
public int getRamSize();
public Date getLastUpdateTime();
public interface SecondaryStorageVm extends SystemVm {
}

View File

@ -0,0 +1,36 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.vm;
import java.util.Date;
public interface SystemVm extends VirtualMachine {
public String getGateway();
public String getDns1();
public String getDns2();
public String getDomain();
public String getPublicIpAddress();
public String getPublicNetmask();
public String getPublicMacAddress();
public Long getVlanDbId();
public String getVlanId();
public String getPrivateNetmask();
public int getRamSize();
public int getActiveSession();
public Date getLastUpdateTime();
}

View File

@ -10,7 +10,7 @@ public class ListIsoPermissionsCmd extends ListTemplateOrIsoPermissionsCmd {
return "listisopermissionsresponse";
}
protected String getMediaType() {
public String getMediaType() {
return "iso";
}

View File

@ -80,6 +80,7 @@ public class ListLoadBalancerRuleInstancesCmd extends BaseListCmd {
userVmResponse.setId(instance.getId());
userVmResponse.setName(instance.getName());
userVmResponse.setDisplayName(instance.getDisplayName());
userVmResponse.setPrivateIp(instance.getPrivateIpAddress());
// TODO: implement
Account accountTemp = getManagementServer().findAccountById(instance.getAccountId());

View File

@ -25,12 +25,15 @@ import java.util.Map;
import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd;
import com.cloud.api.BaseListCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.host.Host;
import com.cloud.server.ManagementServer;
import com.cloud.utils.Pair;
public class ListStoragePoolsAndHostsCmd extends BaseCmd{
@Implementation(method="")
public class ListStoragePoolsAndHostsCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListStoragePoolsAndHostsCmd.class.getName());
private static final String s_name = "liststoragepoolsandhostsresponse";
@ -115,8 +118,7 @@ public class ListStoragePoolsAndHostsCmd extends BaseCmd{
}
@Override
public List<Pair<Enum, Boolean>> getProperties() {
return s_properties;
public String getResponse() {
}
@Override

View File

@ -20,40 +20,23 @@ package com.cloud.api.commands;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd;
import com.cloud.api.BaseListCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.StoragePoolResponse;
import com.cloud.dc.ClusterVO;
import com.cloud.server.Criteria;
import com.cloud.server.ManagementServer;
import com.cloud.serializer.SerializerHelper;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.StorageStats;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.utils.Pair;
import com.cloud.utils.component.ComponentLocator;
public class ListStoragePoolsCmd extends BaseCmd{
@Implementation(method="searchForStoragePools")
public class ListStoragePoolsCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListStoragePoolsCmd.class.getName());
private static final String s_name = "liststoragepoolsresponse";
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
static {
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.CLUSTER_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.IP_ADDRESS, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.NAME, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PATH, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.POD_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ZONE_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.KEYWORD, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGESIZE, Boolean.FALSE));
}
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
@ -114,107 +97,54 @@ public class ListStoragePoolsCmd extends BaseCmd{
return s_name;
}
@Override
public List<Pair<Enum, Boolean>> getProperties() {
return s_properties;
}
@Override
public List<Pair<String, Object>> execute(Map<String, Object> params) {
String name = (String)params.get(BaseCmd.Properties.NAME.getName());
Long zoneId = (Long)params.get(BaseCmd.Properties.ZONE_ID.getName());
Long podId = (Long)params.get(BaseCmd.Properties.POD_ID.getName());
Long clusterId = (Long)params.get(BaseCmd.Properties.CLUSTER_ID.getName());
String ipAddress = (String)params.get(BaseCmd.Properties.IP_ADDRESS.getName());
String path = (String)params.get(BaseCmd.Properties.PATH.getName());
String keyword = (String)params.get(BaseCmd.Properties.KEYWORD.getName());
Integer page = (Integer)params.get(BaseCmd.Properties.PAGE.getName());
Integer pageSize = (Integer)params.get(BaseCmd.Properties.PAGESIZE.getName());
Long startIndex = Long.valueOf(0);
int pageSizeNum = 50;
if (pageSize != null) {
pageSizeNum = pageSize.intValue();
}
if (page != null) {
int pageNum = page.intValue();
if (pageNum > 0) {
startIndex = Long.valueOf(pageSizeNum * (pageNum-1));
}
}
Criteria c = new Criteria("id", Boolean.TRUE, startIndex, Long.valueOf(pageSizeNum));
if (keyword != null) {
c.addCriteria(Criteria.KEYWORD, keyword);
} else {
c.addCriteria(Criteria.NAME, name);
c.addCriteria(Criteria.DATACENTERID, zoneId);
c.addCriteria(Criteria.PODID, podId);
c.addCriteria(Criteria.CLUSTERID, clusterId);
c.addCriteria(Criteria.ADDRESS, ipAddress);
c.addCriteria(Criteria.PATH, path);
}
List<? extends StoragePoolVO> pools = getManagementServer().searchForStoragePools(c);
if (pools == null) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "unable to find pools");
}
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
VolumeDao volDao = locator.getDao(VolumeDao.class);
List<Pair<String, Object>> poolTags = new ArrayList<Pair<String, Object>>();
Object[] sTag = new Object[pools.size()];
int i = 0;
for (StoragePoolVO pool : pools) {
StoragePoolVO netfsPool = pool;
List<Pair<String, Object>> poolData = new ArrayList<Pair<String, Object>>();
poolData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), Long.toString(pool.getId())));
poolData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), pool.getName()));
if (pool.getPoolType() != null) {
poolData.add(new Pair<String, Object>(BaseCmd.Properties.TYPE.getName(), pool.getPoolType().toString()));
}
poolData.add(new Pair<String, Object>(BaseCmd.Properties.IP_ADDRESS.getName(), netfsPool.getHostAddress()));
poolData.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_ID.getName(), Long.valueOf(pool.getDataCenterId()).toString()));
poolData.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_NAME.getName(), getManagementServer().getDataCenterBy(pool.getDataCenterId()).getName()));
if (pool.getPodId() != null) {
poolData.add(new Pair<String, Object>(BaseCmd.Properties.POD_ID.getName(), Long.valueOf(pool.getPodId()).toString()));
poolData.add(new Pair<String, Object>(BaseCmd.Properties.POD_NAME.getName(), getManagementServer().getPodBy(pool.getPodId()).getName()));
}
poolData.add(new Pair<String, Object>(BaseCmd.Properties.PATH.getName(), netfsPool.getPath().toString()));
StorageStats stats = getManagementServer().getStoragePoolStatistics(pool.getId());
long capacity = pool.getCapacityBytes();
long available = pool.getAvailableBytes() ;
long used = capacity - available;
if (stats != null) {
used = stats.getByteUsed();
available = capacity - used;
}
poolData.add(new Pair<String, Object>(BaseCmd.Properties.DISK_SIZE_TOTAL.getName(), Long.valueOf(pool.getCapacityBytes()).toString()));
poolData.add(new Pair<String, Object>(BaseCmd.Properties.DISK_SIZE_ALLOCATED.getName(), Long.valueOf(used).toString()));
if (pool.getCreated() != null) {
poolData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(pool.getCreated())));
@Override @SuppressWarnings("unchecked")
public String getResponse() {
List<? extends StoragePoolVO> pools = (List<? extends StoragePoolVO>)getResponseObject();
List<StoragePoolResponse> response = new ArrayList<StoragePoolResponse>();
for (StoragePoolVO pool : pools) {
StoragePoolResponse poolResponse = new StoragePoolResponse();
poolResponse.setId(pool.getId());
poolResponse.setName(pool.getName());
poolResponse.setPath(pool.getPath());
poolResponse.setIpAddress(pool.getHostAddress());
poolResponse.setZoneId(pool.getDataCenterId());
poolResponse.setZoneName(getManagementServer().getDataCenterBy(pool.getDataCenterId()).getName());
if (pool.getPoolType() != null) {
poolResponse.setType(pool.getPoolType().toString());
}
if (pool.getPodId() != null) {
poolResponse.setPodId(pool.getPodId());
poolResponse.setPodName(getManagementServer().getPodBy(pool.getPodId()).getName());
}
if (pool.getCreated() != null) {
poolResponse.setCreated(pool.getCreated());
}
StorageStats stats = getManagementServer().getStoragePoolStatistics(pool.getId());
long capacity = pool.getCapacityBytes();
long available = pool.getAvailableBytes() ;
long used = capacity - available;
if (stats != null) {
used = stats.getByteUsed();
available = capacity - used;
}
poolResponse.setDiskSizeTotal(pool.getCapacityBytes());
poolResponse.setDiskSizeAllocated(used);
if (pool.getClusterId() != null) {
ClusterVO cluster = getManagementServer().findClusterById(pool.getClusterId());
poolData.add(new Pair<String, Object>(BaseCmd.Properties.CLUSTER_ID.getName(), cluster.getId()));
poolData.add(new Pair<String, Object>(BaseCmd.Properties.CLUSTER_NAME.getName(), cluster.getName()));
ClusterVO cluster = getManagementServer().findClusterById(pool.getClusterId());
poolResponse.setClusterId(cluster.getId());
poolResponse.setClusterName(cluster.getName());
}
poolData.add(new Pair<String, Object>(BaseCmd.Properties.TAGS.getName(), getManagementServer().getStoragePoolTags(pool.getId())));
sTag[i++] = poolData;
volDao.getCountAndTotalByPool(pool.getId());
}
Pair<String, Object> poolTag = new Pair<String, Object>("storagepool", sTag);
poolTags.add(poolTag);
return poolTags;
poolResponse.setTags(getManagementServer().getStoragePoolTags(pool.getId()));
response.add(poolResponse);
}
return SerializerHelper.toSerializedString(response);
}
}

View File

@ -15,43 +15,30 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.commands;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd;
import com.cloud.api.BaseListCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.response.SystemVmResponse;
import com.cloud.async.AsyncJobVO;
import com.cloud.server.Criteria;
import com.cloud.utils.Pair;
import com.cloud.serializer.SerializerHelper;
import com.cloud.vm.ConsoleProxyVO;
import com.cloud.vm.SecondaryStorageVmVO;
public class ListSystemVMsCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(ListSystemVMsCmd.class.getName());
private static final String s_name = "listsystemvmsresponse";
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
static {
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.HOST_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.NAME, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.POD_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.STATE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.SYSTEM_VM_TYPE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ZONE_ID, Boolean.FALSE));
import com.cloud.vm.SystemVm;
import com.cloud.vm.VMInstanceVO;
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.KEYWORD, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGESIZE, Boolean.FALSE));
}
@Implementation(method="searchForSystemVms")
public class ListSystemVMsCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListSystemVMsCmd.class.getName());
private static final String s_name = "listsystemvmsresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@ -118,157 +105,65 @@ public class ListSystemVMsCmd extends BaseCmd {
return s_name;
}
@Override
public List<Pair<Enum, Boolean>> getProperties() {
return s_properties;
}
@Override
public List<Pair<String, Object>> execute(Map<String, Object> params) {
Long id = (Long)params.get(BaseCmd.Properties.ID.getName());
Long zoneId = (Long)params.get(BaseCmd.Properties.ZONE_ID.getName());
Long podId = (Long)params.get(BaseCmd.Properties.POD_ID.getName());
Long hostId = (Long)params.get(BaseCmd.Properties.HOST_ID.getName());
String name = (String)params.get(BaseCmd.Properties.NAME.getName());
String state = (String)params.get(BaseCmd.Properties.STATE.getName());
String keyword = (String)params.get(BaseCmd.Properties.KEYWORD.getName());
String type = (String)params.get(BaseCmd.Properties.SYSTEM_VM_TYPE.getName());
Integer page = (Integer)params.get(BaseCmd.Properties.PAGE.getName());
Integer pageSize = (Integer)params.get(BaseCmd.Properties.PAGESIZE.getName());
Long startIndex = Long.valueOf(0);
int pageSizeNum = 50;
if (pageSize != null) {
pageSizeNum = pageSize.intValue();
}
if (page != null) {
int pageNum = page.intValue();
if (pageNum > 0) {
startIndex = Long.valueOf(pageSizeNum * (pageNum-1));
}
}
Criteria c = new Criteria("id", Boolean.TRUE, startIndex, Long.valueOf(pageSizeNum));
if (keyword != null) {
c.addCriteria(Criteria.KEYWORD, keyword);
} else {
c.addCriteria(Criteria.ID, id);
c.addCriteria(Criteria.DATACENTERID, zoneId);
c.addCriteria(Criteria.PODID, podId);
c.addCriteria(Criteria.HOSTID, hostId);
c.addCriteria(Criteria.NAME, name);
c.addCriteria(Criteria.STATE, state);
}
List<ConsoleProxyVO> proxies = null;
List<SecondaryStorageVmVO> ssVms = null;
Object[] proxyDataArray = null;
if(type == null) //search for all vm types
{
proxies = getManagementServer().searchForConsoleProxy(c);
ssVms = getManagementServer().searchForSecondaryStorageVm(c);
proxyDataArray = new Object[proxies.size() + ssVms.size()];
}
else if((type != null) && (type.equalsIgnoreCase("secondarystoragevm"))) // search for ssvm
{
ssVms = getManagementServer().searchForSecondaryStorageVm(c);
proxyDataArray = new Object[ssVms.size()];
}
else if((type != null) && (type.equalsIgnoreCase("consoleproxy"))) // search for consoleproxy
{
proxies = getManagementServer().searchForConsoleProxy(c);
proxyDataArray = new Object[proxies.size()];
}
List<Pair<String, Object>> proxiesTags = new ArrayList<Pair<String, Object>>();
int i = 0;
@Override @SuppressWarnings("unchecked")
public String getResponse() {
List<? extends VMInstanceVO> systemVMs = (List<? extends VMInstanceVO>)getResponseObject();
if(proxies != null && proxies.size() > 0)
{
for (ConsoleProxyVO proxy : proxies) {
List<Pair<String, Object>> proxyData = new ArrayList<Pair<String, Object>>();
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.SYSTEM_VM_TYPE.getName(), "consoleproxy"));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), Long.toString(proxy.getId())));
AsyncJobVO asyncJob = getManagementServer().findInstancePendingAsyncJob("console_proxy", proxy.getId());
if(asyncJob != null) {
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.JOB_ID.getName(), asyncJob.getId().toString()));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.JOB_STATUS.getName(), String.valueOf(asyncJob.getStatus())));
}
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_ID.getName(), Long.valueOf(proxy.getDataCenterId()).toString()));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_NAME.getName(), getManagementServer().findDataCenterById(proxy.getDataCenterId()).getName()));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.DNS1.getName(), proxy.getDns1()));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.DNS2.getName(), proxy.getDns2()));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.NETWORK_DOMAIN.getName(), proxy.getDomain()));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.GATEWAY.getName(), proxy.getGateway()));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), proxy.getName()));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.POD_ID.getName(), Long.valueOf(proxy.getPodId()).toString()));
if (proxy.getHostId() != null) {
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.HOST_ID.getName(), proxy.getHostId().toString()));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.HOST_NAME.getName(), getManagementServer().getHostBy(proxy.getHostId()).getName()));
}
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.PRIVATE_IP.getName(), proxy.getPrivateIpAddress()));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.PRIVATE_MAC_ADDRESS.getName(), proxy.getPrivateMacAddress()));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.PRIVATE_NETMASK.getName(), proxy.getPrivateNetmask()));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.PUBLIC_IP.getName(), proxy.getPublicIpAddress()));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.PUBLIC_MAC_ADDRESS.getName(), proxy.getPublicMacAddress()));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.PUBLIC_NETMASK.getName(), proxy.getPublicNetmask()));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.TEMPLATE_ID.getName(), Long.valueOf(proxy.getTemplateId()).toString()));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(proxy.getCreated())));
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.ACTIVE_VIEWER_SESSIONS.getName(),
String.valueOf(proxy.getActiveSession())));
if (proxy.getState() != null) {
proxyData.add(new Pair<String, Object>(BaseCmd.Properties.STATE.getName(), proxy.getState().toString()));
}
proxyDataArray[i++] = proxyData;
}
List<SystemVmResponse> response = new ArrayList<SystemVmResponse>();
for (VMInstanceVO systemVM : systemVMs) {
SystemVmResponse vmResponse = new SystemVmResponse();
if (systemVM instanceof SystemVm) {
SystemVm vm = (SystemVm)systemVM;
vmResponse.setId(vm.getId());
vmResponse.setSystemVmType(vm.getType().toString().toLowerCase());
String instanceType = "console_proxy";
if (systemVM instanceof SecondaryStorageVmVO) {
instanceType = "sec_storage_vm"; // FIXME: this should be a constant so that the async jobs get updated with the correct instance type, they are using
// different instance types at the moment
}
AsyncJobVO asyncJob = getManagementServer().findInstancePendingAsyncJob(instanceType, vm.getId());
if (asyncJob != null) {
vmResponse.setJobId(asyncJob.getId());
vmResponse.setJobStatus(asyncJob.getStatus());
}
vmResponse.setZoneId(vm.getDataCenterId());
vmResponse.setZoneName(getManagementServer().findDataCenterById(vm.getDataCenterId()).getName());
vmResponse.setDns1(vm.getDns1());
vmResponse.setDns2(vm.getDns2());
vmResponse.setNetworkDomain(vm.getDomain());
vmResponse.setGateway(vm.getGateway());
vmResponse.setName(vm.getName());
vmResponse.setPodId(vm.getPodId());
if (vm.getHostId() != null) {
vmResponse.setHostId(vm.getHostId());
vmResponse.setHostName(getManagementServer().getHostBy(vm.getHostId()).getName());
}
vmResponse.setPrivateIp(vm.getPrivateIpAddress());
vmResponse.setPrivateMacAddress(vm.getPrivateMacAddress());
vmResponse.setPrivateNetmask(vm.getPrivateNetmask());
vmResponse.setPublicIp(vm.getPublicIpAddress());
vmResponse.setPublicMacAddress(vm.getPublicMacAddress());
vmResponse.setPublicNetmask(vm.getPublicNetmask());
vmResponse.setTemplateId(vm.getTemplateId());
vmResponse.setCreated(vm.getCreated());
if (vm.getState() != null) {
vmResponse.setState(vm.getState().toString());
}
}
// for console proxies, add the active sessions
if (systemVM instanceof ConsoleProxyVO) {
ConsoleProxyVO proxy = (ConsoleProxyVO)systemVM;
vmResponse.setActiveViewerSessions(proxy.getActiveSession());
}
response.add(vmResponse);
}
if(ssVms != null && ssVms.size() > 0)
{
for (SecondaryStorageVmVO ssVm : ssVms) {
List<Pair<String, Object>> ssvmData = new ArrayList<Pair<String, Object>>();
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.SYSTEM_VM_TYPE.getName(), "secondarystoragevm"));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), ssVm.getId()));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_ID.getName(), Long.valueOf(ssVm.getDataCenterId()).toString()));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_NAME.getName(), getManagementServer().findDataCenterById(ssVm.getDataCenterId()).getName()));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.DNS1.getName(), ssVm.getDns1()));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.DNS2.getName(), ssVm.getDns2()));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.NETWORK_DOMAIN.getName(), ssVm.getDomain()));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.GATEWAY.getName(), ssVm.getGateway()));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), ssVm.getName()));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.POD_ID.getName(), Long.valueOf(ssVm.getPodId()).toString()));
if (ssVm.getHostId() != null) {
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.HOST_ID.getName(), ssVm.getHostId().toString()));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.HOST_NAME.getName(), getManagementServer().getHostBy(ssVm.getHostId()).getName()));
}
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.PRIVATE_IP.getName(), ssVm.getPrivateIpAddress()));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.PRIVATE_MAC_ADDRESS.getName(), ssVm.getPrivateMacAddress()));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.PRIVATE_NETMASK.getName(), ssVm.getPrivateNetmask()));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.PUBLIC_IP.getName(), ssVm.getPublicIpAddress()));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.PUBLIC_MAC_ADDRESS.getName(), ssVm.getPublicMacAddress()));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.PUBLIC_NETMASK.getName(), ssVm.getPublicNetmask()));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.TEMPLATE_ID.getName(), Long.valueOf(ssVm.getTemplateId()).toString()));
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(ssVm.getCreated())));
if (ssVm.getState() != null) {
ssvmData.add(new Pair<String, Object>(BaseCmd.Properties.STATE.getName(), ssVm.getState().toString()));
}
proxyDataArray[i++] = ssvmData;
}
}
proxiesTags.add(new Pair<String, Object>("systemvm", proxyDataArray));
return proxiesTags;
return SerializerHelper.toSerializedString(response);
}
}

View File

@ -1,31 +1,23 @@
package com.cloud.api.commands;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd;
import com.cloud.api.BaseListCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.domain.DomainVO;
import com.cloud.api.response.TemplatePermissionsResponse;
import com.cloud.serializer.SerializerHelper;
import com.cloud.storage.VMTemplateVO;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
import com.cloud.user.UserContext;
public class ListTemplateOrIsoPermissionsCmd extends BaseCmd {
@Implementation(method="listTemplatePermissions")
public class ListTemplateOrIsoPermissionsCmd extends BaseListCmd {
public Logger s_logger = getLogger();
protected static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
protected String s_name = getResponseName();
static {
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DOMAIN_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
}
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@ -63,9 +55,32 @@ public class ListTemplateOrIsoPermissionsCmd extends BaseCmd {
public String getName() {
return s_name;
}
@Override
public List<Pair<Enum, Boolean>> getProperties() {
return s_properties;
@Override @SuppressWarnings("unchecked")
public String getResponse() {
List<String> accountNames = (List<String>)getResponseObject();
Account account = (Account)UserContext.current().getAccountObject();
boolean isAdmin = ((account == null) || isAdmin(account.getType()));
Long templateOwnerDomain = null;
VMTemplateVO template = getManagementServer().findTemplateById(id);
if (isAdmin) {
// FIXME: we have just template id and need to get template owner from that
Account templateOwner = getManagementServer().findAccountById(template.getAccountId());
if (templateOwner != null) {
templateOwnerDomain = templateOwner.getDomainId();
}
}
TemplatePermissionsResponse response = new TemplatePermissionsResponse();
response.setId(template.getId());
response.setPublicTemplate(template.isPublicTemplate());
if (isAdmin && (templateOwnerDomain != null)) {
response.setDomainId(templateOwnerDomain);
}
response.setAccountNames(accountNames);
return SerializerHelper.toSerializedString(response);
}
protected boolean templateIsCorrectType(VMTemplateVO template) {
@ -76,87 +91,11 @@ public class ListTemplateOrIsoPermissionsCmd extends BaseCmd {
return "updatetemplateorisopermissionsresponse";
}
protected String getMediaType() {
public String getMediaType() {
return "templateOrIso";
}
protected Logger getLogger() {
return Logger.getLogger(UpdateTemplateOrIsoPermissionsCmd.class.getName());
}
@Override
public List<Pair<String, Object>> execute(Map<String, Object> params) {
Long id = (Long)params.get(BaseCmd.Properties.ID.getName());
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
String acctName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName());
Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName());
Long accountId = null;
if ((account == null) || account.getType() == Account.ACCOUNT_TYPE_ADMIN) {
// validate domainId before proceeding
if (domainId != null) {
if ((account != null) && !getManagementServer().isChildDomain(account.getDomainId(), domainId)) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Invalid domain id (" + domainId + ") given, unable to list " + getMediaType() + " permissions.");
}
if (acctName != null) {
Account userAccount = getManagementServer().findAccountByName(acctName, domainId);
if (userAccount != null) {
accountId = userAccount.getId();
} else {
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to find account " + acctName + " in domain " + domainId);
}
}
}
} else {
accountId = account.getId();
}
VMTemplateVO template = getManagementServer().findTemplateById(id.longValue());
if (template == null || !templateIsCorrectType(template)) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find " + getMediaType() + " with id " + id);
}
if (accountId != null && !template.isPublicTemplate()) {
if (account.getType() == Account.ACCOUNT_TYPE_NORMAL && template.getAccountId() != accountId) {
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "unable to list permissions for " + getMediaType() + " with id " + id);
} else if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
DomainVO accountDomain = getManagementServer().findDomainIdById(account.getDomainId());
Account templateAccount = getManagementServer().findAccountById(template.getAccountId());
DomainVO templateDomain = getManagementServer().findDomainIdById(templateAccount.getDomainId());
if (!templateDomain.getPath().contains(accountDomain.getPath())) {
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "unable to list permissions for " + getMediaType() + " with id " + id);
}
}
}
if (id == Long.valueOf(1)) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to list permissions for " + getMediaType() + " with id " + id);
}
List<String> accountNames = getManagementServer().listTemplatePermissions(id);
boolean isAdmin = ((account == null) || isAdmin(account.getType()));
Long templateOwnerDomain = null;
if (isAdmin) {
Account templateOwner = getManagementServer().findAccountById(template.getAccountId());
if (templateOwner != null) {
templateOwnerDomain = templateOwner.getDomainId();
}
}
List<Pair<String, Object>> embeddedObject = new ArrayList<Pair<String, Object>>();
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), template.getId().toString()));
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(template.isPublicTemplate()).toString()));
if (isAdmin && (templateOwnerDomain != null)) {
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN_ID.getName(), templateOwnerDomain.toString()));
}
if ((accountNames != null) && !accountNames.isEmpty()) {
for (String accountName : accountNames) {
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.ACCOUNT.getName(), accountName));
}
}
embeddedObject.add(new Pair<String, Object>(getMediaType() + "permission", new Object[] { returnValues } ));
return embeddedObject;
}
}

View File

@ -28,7 +28,7 @@ public class ListTemplatePermissionsCmd extends ListTemplateOrIsoPermissionsCmd
return "listtemplatepermissionsresponse";
}
protected String getMediaType() {
public String getMediaType() {
return "template";
}

View File

@ -20,38 +20,21 @@ package com.cloud.api.commands;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd;
import com.cloud.api.BaseListCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.domain.DomainVO;
import com.cloud.server.Criteria;
import com.cloud.user.Account;
import com.cloud.api.response.UserResponse;
import com.cloud.serializer.SerializerHelper;
import com.cloud.user.UserAccountVO;
import com.cloud.utils.Pair;
public class ListUsersCmd extends BaseCmd {
@Implementation(method="searchForUsers")
public class ListUsersCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListUsersCmd.class.getName());
private static final String s_name = "listusersresponse";
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
static {
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_TYPE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DOMAIN_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.STATE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.USERNAME, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.KEYWORD, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGESIZE, Boolean.FALSE));
}
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
@ -107,88 +90,36 @@ public class ListUsersCmd extends BaseCmd {
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getName() {
return s_name;
}
public List<Pair<Enum, Boolean>> getProperties() {
return s_properties;
}
@Override
public List<Pair<String, Object>> execute(Map<String, Object> params) {
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
Long id = (Long)params.get(BaseCmd.Properties.ID.getName());
String userName = (String)params.get(BaseCmd.Properties.USERNAME.getName());
String accountName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName());
Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName());
Long type = (Long)params.get(BaseCmd.Properties.ACCOUNT_TYPE.getName());
String state = (String)params.get(BaseCmd.Properties.STATE.getName());
String keyword = (String)params.get(BaseCmd.Properties.KEYWORD.getName());
Integer page = (Integer)params.get(BaseCmd.Properties.PAGE.getName());
Integer pageSize = (Integer)params.get(BaseCmd.Properties.PAGESIZE.getName());
if (domainId != null) {
if ((account != null) && !getManagementServer().isChildDomain(account.getDomainId(), domainId)) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Invalid domain id (" + domainId + ") given, unable to list users.");
}
} else {
// default domainId to the admin's domain
domainId = ((account == null) ? DomainVO.ROOT_DOMAIN : account.getDomainId());
}
Long startIndex = Long.valueOf(0);
int pageSizeNum = 50;
if (pageSize != null) {
pageSizeNum = pageSize.intValue();
}
if (page != null) {
int pageNum = page.intValue();
if (pageNum > 0) {
startIndex = Long.valueOf(pageSizeNum * (pageNum-1));
}
}
Criteria c = new Criteria("id", Boolean.TRUE, startIndex, Long.valueOf(pageSizeNum));
if (keyword != null) {
c.addCriteria(Criteria.KEYWORD, keyword);
}
else {
c.addCriteria(Criteria.ID, id);
c.addCriteria(Criteria.ACCOUNTNAME, accountName);
c.addCriteria(Criteria.DOMAINID, domainId);
c.addCriteria(Criteria.USERNAME, userName);
c.addCriteria(Criteria.TYPE, type);
c.addCriteria(Criteria.STATE, state);
}
List<UserAccountVO> users = getManagementServer().searchForUsers(c);
List<Pair<String, Object>> userTags = new ArrayList<Pair<String, Object>>();
Object[] uTag = new Object[users.size()];
int i = 0;
for (UserAccountVO user: users) {
if ((user.getRemoved() == null)&&(user.getId() != 1)) {
List<Pair<String, Object>> userData = new ArrayList<Pair<String, Object>>();
userData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), Long.valueOf(user.getId()).toString()));
userData.add(new Pair<String, Object>(BaseCmd.Properties.USERNAME.getName(), user.getUsername()));
userData.add(new Pair<String, Object>(BaseCmd.Properties.FIRSTNAME.getName(), user.getFirstname()));
userData.add(new Pair<String, Object>(BaseCmd.Properties.LASTNAME.getName(), user.getLastname()));
userData.add(new Pair<String, Object>(BaseCmd.Properties.EMAIL.getName(), user.getEmail()));
userData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(user.getCreated())));
userData.add(new Pair<String, Object>(BaseCmd.Properties.STATE.getName(), user.getState()));
userData.add(new Pair<String, Object>(BaseCmd.Properties.ACCOUNT.getName(), getManagementServer().findAccountById(user.getAccountId()).getAccountName()));
userData.add(new Pair<String, Object>(BaseCmd.Properties.ACCOUNT_TYPE.getName(), getManagementServer().findAccountById(user.getAccountId()).getType()));
userData.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN_ID.getName(), user.getDomainId().toString()));
userData.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN.getName(), getManagementServer().findDomainIdById(user.getDomainId()).getName()));
userData.add(new Pair<String, Object>(BaseCmd.Properties.TIMEZONE.getName(),user.getTimezone()));
if(user.getApiKey()!=null)
userData.add(new Pair<String, Object>(BaseCmd.Properties.API_KEY.getName(), user.getApiKey()));
if(user.getSecretKey()!=null)
userData.add(new Pair<String, Object>(BaseCmd.Properties.SECRET_KEY.getName(), user.getSecretKey()));
uTag[i++] = userData;
}
}
Pair<String, Object> userTag = new Pair<String, Object>("user", uTag);
userTags.add(userTag);
return userTags;
@Override @SuppressWarnings("unchecked")
public String getResponse() {
List<UserAccountVO> users = (List<UserAccountVO>)getResponseObject();
List<UserResponse> response = new ArrayList<UserResponse>();
for (UserAccountVO user : users) {
UserResponse userResponse = new UserResponse();
userResponse.setId(user.getId());
userResponse.setUsername(user.getUsername());
userResponse.setFirstname(user.getFirstname());
userResponse.setLastname(user.getLastname());
userResponse.setEmail(user.getEmail());
userResponse.setCreated(user.getCreated());
userResponse.setState(user.getState());
userResponse.setAccountName(user.getAccountName());
userResponse.setAccountType(user.getType());
userResponse.setDomainId(user.getDomainId());
userResponse.setDomainName(getManagementServer().findDomainIdById(user.getDomainId()).getName());
userResponse.setTimezone(user.getTimezone());
userResponse.setApiKey(user.getApiKey());
userResponse.setSecretKey(user.getSecretKey());
response.add(userResponse);
}
return SerializerHelper.toSerializedString(response);
}
}

View File

@ -15,52 +15,32 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.commands;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd;
import com.cloud.api.BaseListCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.UserVmResponse;
import com.cloud.async.AsyncJobVO;
import com.cloud.domain.DomainVO;
import com.cloud.host.HostVO;
import com.cloud.server.Criteria;
import com.cloud.serializer.SerializerHelper;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.user.Account;
import com.cloud.uservm.UserVm;
import com.cloud.utils.Pair;
import com.cloud.user.UserContext;
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VmStats;
public class ListVMsCmd extends BaseCmd {
@Implementation(method="searchForUserVMs")
public class ListVMsCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListVMsCmd.class.getName());
private static final String s_name = "listvirtualmachinesresponse";
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
static {
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DOMAIN_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.HOST_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.NAME, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.POD_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.STATE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ZONE_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.KEYWORD, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGESIZE, Boolean.FALSE));
}
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
@ -134,210 +114,111 @@ public class ListVMsCmd extends BaseCmd {
public String getName() {
return s_name;
}
@Override
public List<Pair<Enum, Boolean>> getProperties() {
return s_properties;
}
@Override
public List<Pair<String, Object>> execute(Map<String, Object> params) {
Long id = (Long)params.get(BaseCmd.Properties.ID.getName());
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
String accountName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName());
Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName());
String name = (String) params.get(BaseCmd.Properties.NAME.getName());
String state = (String) params.get(BaseCmd.Properties.STATE.getName());
Long zoneId = (Long)params.get(BaseCmd.Properties.ZONE_ID.getName());
Long podId = (Long)params.get(BaseCmd.Properties.POD_ID.getName());
Long hostId = (Long)params.get(BaseCmd.Properties.HOST_ID.getName());
String keyword = (String)params.get(BaseCmd.Properties.KEYWORD.getName());
Integer page = (Integer)params.get(BaseCmd.Properties.PAGE.getName());
Integer pageSize = (Integer)params.get(BaseCmd.Properties.PAGESIZE.getName());
Long accountId = null;
Boolean isAdmin = false;
@Override @SuppressWarnings("unchecked")
public String getResponse() {
List<UserVmVO> userVms = (List<UserVmVO>)getResponseObject();
if ((account == null) || isAdmin(account.getType())) {
isAdmin = true;
if (domainId != null) {
if ((account != null) && !getManagementServer().isChildDomain(account.getDomainId(), domainId)) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Invalid domain id (" + domainId + ") given, unable to list virtual machines.");
}
if (accountName != null) {
account = getManagementServer().findActiveAccount(accountName, domainId);
if (account == null) {
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to find account " + accountName + " in domain " + domainId);
}
accountId = account.getId();
}
} else {
domainId = ((account == null) ? DomainVO.ROOT_DOMAIN : account.getDomainId());
}
} else {
accountName = account.getAccountName();
accountId = account.getId();
domainId = account.getDomainId();
}
Long[] accountIds = null;
if (accountId != null) {
accountIds = new Long[1];
accountIds[0] = accountId;
}
Long startIndex = Long.valueOf(0);
int pageSizeNum = 50;
if (pageSize != null) {
pageSizeNum = pageSize.intValue();
}
if (page != null) {
int pageNum = page.intValue();
if (pageNum > 0) {
startIndex = Long.valueOf(pageSizeNum * (pageNum-1));
}
}
Criteria c = new Criteria("id", Boolean.TRUE, startIndex, Long.valueOf(pageSizeNum));
if (keyword != null) {
c.addCriteria(Criteria.KEYWORD, keyword);
} else {
c.addCriteria(Criteria.ID, id);
c.addCriteria(Criteria.NAME, name);
c.addCriteria(Criteria.STATE, state);
if(zoneId != null)
c.addCriteria(Criteria.DATACENTERID, zoneId);
// ignore these search requests if it's not an admin
if (isAdmin == true) {
c.addCriteria(Criteria.DOMAINID, domainId);
if(podId != null)
c.addCriteria(Criteria.PODID, podId);
c.addCriteria(Criteria.HOSTID, hostId);
}
}
c.addCriteria(Criteria.ACCOUNTID, accountIds);
c.addCriteria(Criteria.ISADMIN, isAdmin);
List<? extends UserVm> virtualMachines = getManagementServer().searchForUserVMs(c);
if (virtualMachines == null) {
throw new ServerApiException(BaseCmd.VM_LIST_ERROR, "unable to find virtual machines for account id " + accountName.toString());
}
Object[] vmTag = new Object[virtualMachines.size()];
int i = 0;
HashMap<Long, HostVO> hostMap = new HashMap<Long, HostVO>();
List<HostVO> hostList = getManagementServer().listAllActiveHosts();
for (HostVO hostVO : hostList) {
hostMap.put(hostVO.getId(), hostVO);
}
for (UserVm vmInstance : virtualMachines) {
List<Pair<String, Object>> vmData = new ArrayList<Pair<String, Object>>();
AsyncJobVO asyncJob = getManagementServer().findInstancePendingAsyncJob("vm_instance", vmInstance.getId());
if(asyncJob != null) {
vmData.add(new Pair<String, Object>(BaseCmd.Properties.JOB_ID.getName(), asyncJob.getId().toString()));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.JOB_STATUS.getName(), String.valueOf(asyncJob.getStatus())));
List<UserVmResponse> response = new ArrayList<UserVmResponse>();
for (UserVmVO userVm : userVms) {
UserVmResponse userVmResponse = new UserVmResponse();
userVmResponse.setId(userVm.getId());
AsyncJobVO asyncJob = getManagementServer().findInstancePendingAsyncJob("vm_instance", userVm.getId());
if (asyncJob != null) {
userVmResponse.setJobId(asyncJob.getId());
userVmResponse.setJobStatus(asyncJob.getStatus());
}
vmData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), Long.toString(vmInstance.getId())));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), vmInstance.getName()));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(vmInstance.getCreated())));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.IP_ADDRESS.getName(), vmInstance.getPrivateIpAddress()));
if (vmInstance.getState() != null) {
vmData.add(new Pair<String, Object>(BaseCmd.Properties.STATE.getName(), vmInstance.getState().toString()));
userVmResponse.setName(userVm.getName());
userVmResponse.setCreated(userVm.getCreated());
userVmResponse.setPrivateIp(userVm.getPrivateIpAddress());
if (userVm.getState() != null) {
userVmResponse.setState(userVm.getState().toString());
}
Account acct = getManagementServer().findAccountById(Long.valueOf(vmInstance.getAccountId()));
Account acct = getManagementServer().findAccountById(Long.valueOf(userVm.getAccountId()));
if (acct != null) {
vmData.add(new Pair<String, Object>(BaseCmd.Properties.ACCOUNT.getName(), acct.getAccountName()));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN_ID.getName(), acct.getDomainId().toString()));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN.getName(), getManagementServer().findDomainIdById(acct.getDomainId()).getName()));
}
vmData.add(new Pair<String, Object>(BaseCmd.Properties.HA_ENABLE.getName(), Boolean.valueOf(vmInstance.isHaEnabled()).toString()));
if (vmInstance.getDisplayName() != null) {
vmData.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_NAME.getName(), vmInstance.getDisplayName()));
}
else {
vmData.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_NAME.getName(), vmInstance.getName()));
userVmResponse.setAccountName(acct.getAccountName());
userVmResponse.setDomainId(acct.getDomainId());
userVmResponse.setDomainName(getManagementServer().findDomainIdById(acct.getDomainId()).getName());
}
if (vmInstance.getGroup() != null) {
vmData.add(new Pair<String, Object>(BaseCmd.Properties.GROUP.getName(), vmInstance.getGroup()));
}
userVmResponse.setHaEnable(userVm.isHaEnabled());
if (userVm.getDisplayName() != null) {
userVmResponse.setDisplayName(userVm.getDisplayName());
} else {
userVmResponse.setDisplayName(userVm.getName());
}
userVmResponse.setGroup(userVm.getGroup());
// Data Center Info
vmData.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_ID.getName(), Long.valueOf(vmInstance.getDataCenterId()).toString()));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_NAME.getName(), getManagementServer().findDataCenterById(vmInstance.getDataCenterId()).getName()));
userVmResponse.setZoneId(userVm.getDataCenterId());
userVmResponse.setZoneName(getManagementServer().findDataCenterById(userVm.getDataCenterId()).getName());
Account account = (Account)UserContext.current().getAccountObject();
//if user is an admin, display host id
if ( (isAdmin == true) && (vmInstance.getHostId() != null)) {
vmData.add(new Pair<String, Object>(BaseCmd.Properties.HOST_ID.getName(), vmInstance.getHostId().toString()));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.HOST_NAME.getName(), getManagementServer().getHostBy(vmInstance.getHostId()).getName()));
if (((account == null) || isAdmin(account.getType())) && (userVm.getHostId() != null)) {
userVmResponse.setHostId(userVm.getHostId());
userVmResponse.setHostName(getManagementServer().getHostBy(userVm.getHostId()).getName());
}
// Template Info
VMTemplateVO template = getManagementServer().findTemplateById(vmInstance.getTemplateId());
VMTemplateVO template = getManagementServer().findTemplateById(userVm.getTemplateId());
if (template != null) {
vmData.add(new Pair<String, Object>(BaseCmd.Properties.TEMPLATE_ID.getName(), Long.valueOf(vmInstance.getTemplateId()).toString()));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.TEMPLATE_NAME.getName(), template.getName()));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.TEMPLATE_DISPLAY_TEXT.getName(), template.getDisplayText()));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.PASSWORD_ENABLED.getName(), template.getEnablePassword()));
userVmResponse.setTemplateId(userVm.getTemplateId());
userVmResponse.setTemplateName(template.getName());
userVmResponse.setTemplateDisplayText(template.getDisplayText());
userVmResponse.setPasswordEnabled(template.getEnablePassword());
} else {
vmData.add(new Pair<String, Object>(BaseCmd.Properties.TEMPLATE_ID.getName(), "-1"));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.TEMPLATE_NAME.getName(), "ISO Boot"));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.TEMPLATE_DISPLAY_TEXT.getName(), "ISO Boot"));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.PASSWORD_ENABLED.getName(), false));
userVmResponse.setTemplateId(-1L);
userVmResponse.setTemplateName("ISO Boot");
userVmResponse.setTemplateDisplayText("ISO Boot");
userVmResponse.setPasswordEnabled(false);
}
// ISO Info
if (vmInstance.getIsoId() != null) {
VMTemplateVO iso = getManagementServer().findTemplateById(vmInstance.getIsoId().longValue());
if (userVm.getIsoId() != null) {
VMTemplateVO iso = getManagementServer().findTemplateById(userVm.getIsoId().longValue());
if (iso != null) {
vmData.add(new Pair<String, Object>(BaseCmd.Properties.ISO_ID.getName(), Long.valueOf(vmInstance.getIsoId()).toString()));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.ISO_NAME.getName(), iso.getName()));
userVmResponse.setIsoId(userVm.getIsoId());
userVmResponse.setIsoName(iso.getName());
}
}
// Service Offering Info
ServiceOfferingVO offering = getManagementServer().findServiceOfferingById(vmInstance.getServiceOfferingId());
vmData.add(new Pair<String, Object>(BaseCmd.Properties.SERVICE_OFFERING_ID.getName(), Long.valueOf(vmInstance.getServiceOfferingId()).toString()));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.SERVICE_OFFERING_NAME.getName(), offering.getName()));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.CPU_NUMBER.getName(), Integer.valueOf(offering.getCpu()).toString()));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.CPU_SPEED.getName(), Integer.valueOf(offering.getSpeed()).toString()));
vmData.add(new Pair<String, Object>(BaseCmd.Properties.MEMORY.getName(), Integer.valueOf(offering.getRamSize()).toString()));
userVmResponse.setServiceOfferingId(userVm.getServiceOfferingId());
userVmResponse.setServiceOfferingName(offering.getName());
userVmResponse.setCpuNumber(offering.getCpu());
userVmResponse.setCpuSpeed(offering.getSpeed());
userVmResponse.setMemory(offering.getRamSize());
//stats calculation
DecimalFormat decimalFormat = new DecimalFormat("#.##");
String cpuUsed = null;
VmStats vmStats = getManagementServer().getVmStatistics(vmInstance.getId());
if (vmStats != null)
{
VmStats vmStats = getManagementServer().getVmStatistics(userVm.getId());
if (vmStats != null) {
float cpuUtil = (float) vmStats.getCPUUtilization();
cpuUsed = decimalFormat.format(cpuUtil) + "%";
vmData.add(new Pair<String, Object>(BaseCmd.Properties.CPU_USED.getName(), cpuUsed));
userVmResponse.setCpuUsed(cpuUsed);
long networkKbRead = (long)vmStats.getNetworkReadKBs();
vmData.add(new Pair<String, Object>(BaseCmd.Properties.NETWORK_KB_READ.getName(), networkKbRead));
userVmResponse.setNetworkKbsRead(networkKbRead);
long networkKbWrite = (long)vmStats.getNetworkWriteKBs();
vmData.add(new Pair<String, Object>(BaseCmd.Properties.NETWORK_KB_WRITE.getName(), networkKbWrite));
userVmResponse.setNetworkKbsWrite(networkKbWrite);
}
vmData.add(new Pair<String, Object>(BaseCmd.Properties.OS_TYPE_ID.getName(),vmInstance.getGuestOSId()));
userVmResponse.setOsTypeId(userVm.getGuestOSId());
//network groups
vmData.add(new Pair<String, Object>(BaseCmd.Properties.NETWORK_GROUP_LIST.getName(), getManagementServer().getNetworkGroupsNamesForVm(vmInstance.getId())));
vmTag[i++] = vmData;
userVmResponse.setNetworkGroupList(getManagementServer().getNetworkGroupsNamesForVm(userVm.getId()));
response.add(userVmResponse);
}
List<Pair<String, Object>> returnTags = new ArrayList<Pair<String, Object>>();
Pair<String, Object> vmTags = new Pair<String, Object>("virtualmachine", vmTag);
returnTags.add(vmTags);
return returnTags;
return SerializerHelper.toSerializedString(response);
}
}

View File

@ -15,43 +15,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.commands;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd;
import com.cloud.api.BaseListCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.VlanIpRangeResponse;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.Vlan.VlanType;
import com.cloud.dc.VlanVO;
import com.cloud.server.Criteria;
import com.cloud.serializer.SerializerHelper;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
public class ListVlanIpRangesCmd extends BaseCmd {
@Implementation(method="searchForVlans")
public class ListVlanIpRangesCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListVlanIpRangesCmd.class.getName());
private static final String s_name = "listvlaniprangesresponse";
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
static {
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DOMAIN_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.POD_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.VLAN, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ZONE_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.KEYWORD, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGESIZE, Boolean.FALSE));
}
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
@ -107,104 +92,46 @@ public class ListVlanIpRangesCmd extends BaseCmd {
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getName() {
return s_name;
}
public List<Pair<Enum, Boolean>> getProperties() {
return s_properties;
}
@Override
public List<Pair<String, Object>> execute(Map<String, Object> params) {
Long id = (Long) params.get(BaseCmd.Properties.ID.getName());
String vlanId = (String) params.get(BaseCmd.Properties.VLAN.getName());
Long zoneId = (Long) params.get(BaseCmd.Properties.ZONE_ID.getName());
String accountName = (String) params.get(BaseCmd.Properties.ACCOUNT.getName());
Long domainId = (Long) params.get(BaseCmd.Properties.DOMAIN_ID.getName());
Long podId = (Long) params.get(BaseCmd.Properties.POD_ID.getName());
String keyword = (String)params.get(BaseCmd.Properties.KEYWORD.getName());
Integer page = (Integer)params.get(BaseCmd.Properties.PAGE.getName());
Integer pageSize = (Integer)params.get(BaseCmd.Properties.PAGESIZE.getName());
Long startIndex = Long.valueOf(0);
int pageSizeNum = 50;
if (pageSize != null) {
pageSizeNum = pageSize.intValue();
}
if (page != null) {
int pageNum = page.intValue();
if (pageNum > 0) {
startIndex = Long.valueOf(pageSizeNum * (pageNum-1));
}
}
// If an account name and domain ID are specified, look up the account
Long accountId = null;
if (accountName != null && domainId != null) {
Account account = getManagementServer().findAccountByName(accountName, domainId);
if (account == null) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Please specify a valid account.");
} else {
accountId = account.getId();
}
}
Criteria c = new Criteria("id", Boolean.TRUE, startIndex, Long.valueOf(pageSizeNum));
if (keyword != null) {
c.addCriteria(Criteria.KEYWORD, keyword);
} else {
c.addCriteria(Criteria.ID, id);
c.addCriteria(Criteria.VLAN, vlanId);
c.addCriteria(Criteria.DATACENTERID, zoneId);
c.addCriteria(Criteria.ACCOUNTID, accountId);
c.addCriteria(Criteria.PODID, podId);
}
List<? extends VlanVO> vlans = getManagementServer().searchForVlans(c);
if (vlans == null) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "unable to find vlans");
}
Object[] vlanTag = new Object[vlans.size()];
int i = 0;
for (VlanVO vlan : vlans) {
accountId = getManagementServer().getAccountIdForVlan(vlan.getId());
podId = getManagementServer().getPodIdForVlan(vlan.getId());
List<Pair<String, Object>> vlanData = new ArrayList<Pair<String, Object>>();
vlanData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), vlan.getId()));
vlanData.add(new Pair<String, Object>(BaseCmd.Properties.FOR_VIRTUAL_NETWORK.getName(), (vlan.getVlanType().equals(VlanType.VirtualNetwork))));
vlanData.add(new Pair<String, Object>(BaseCmd.Properties.VLAN.getName(), vlan.getVlanId()));
vlanData.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_ID.getName(), vlan.getDataCenterId()));
if (accountId != null) {
Account account = getManagementServer().findAccountById(accountId);
vlanData.add(new Pair<String, Object>(BaseCmd.Properties.ACCOUNT.getName(), account.getAccountName()));
vlanData.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN_ID.getName(), account.getDomainId()));
vlanData.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN.getName(), getManagementServer().findDomainIdById(account.getDomainId()).getName()));
}
}
@Override @SuppressWarnings("unchecked")
public String getResponse() {
List<VlanVO> vlans = (List<VlanVO>)getResponseObject();
List<VlanIpRangeResponse> response = new ArrayList<VlanIpRangeResponse>();
for (VlanVO vlan : vlans) {
Long accountId = getManagementServer().getAccountIdForVlan(vlan.getId());
Long podId = getManagementServer().getPodIdForVlan(vlan.getId());
VlanIpRangeResponse vlanResponse = new VlanIpRangeResponse();
vlanResponse.setId(vlan.getId());
vlanResponse.setForVirtualNetwork(vlan.getVlanType().equals(VlanType.VirtualNetwork));
vlanResponse.setVlan(vlan.getVlanId());
vlanResponse.setZoneId(vlan.getDataCenterId());
if (podId != null) {
HostPodVO pod = getManagementServer().findHostPodById(podId);
vlanData.add(new Pair<String, Object>(BaseCmd.Properties.POD_ID.getName(), podId));
vlanData.add(new Pair<String, Object>(BaseCmd.Properties.POD_NAME.getName(), pod.getName()));
if (accountId != null) {
Account account = getManagementServer().findAccountById(accountId);
vlanResponse.setAccountName(account.getAccountName());
vlanResponse.setDomainId(account.getDomainId());
vlanResponse.setDomainName(getManagementServer().findDomainIdById(account.getDomainId()).getName());
}
vlanData.add(new Pair<String, Object>(BaseCmd.Properties.GATEWAY.getName(), vlan.getVlanGateway()));
vlanData.add(new Pair<String, Object>(BaseCmd.Properties.NETMASK.getName(), vlan.getVlanNetmask()));
vlanData.add(new Pair<String, Object>(BaseCmd.Properties.DESCRIPTION.getName(), vlan.getIpRange()));
vlanTag[i++] = vlanData;
}
List<Pair<String, Object>> returnTags = new ArrayList<Pair<String, Object>>();
Pair<String, Object> vlanTags = new Pair<String, Object>("vlaniprange", vlanTag);
returnTags.add(vlanTags);
return returnTags;
}
if (podId != null) {
HostPodVO pod = getManagementServer().findHostPodById(podId);
vlanResponse.setPodId(podId);
vlanResponse.setPodName(pod.getName());
}
vlanResponse.setGateway(vlan.getVlanGateway());
vlanResponse.setNetmask(vlan.getVlanNetmask());
vlanResponse.setDescription(vlan.getIpRange());
response.add(vlanResponse);
}
return SerializerHelper.toSerializedString(response);
}
}

View File

@ -15,50 +15,32 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.commands;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd;
import com.cloud.api.BaseListCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.VolumeResponse;
import com.cloud.async.AsyncJobVO;
import com.cloud.domain.DomainVO;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.server.Criteria;
import com.cloud.serializer.SerializerHelper;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.VolumeVO;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
import com.cloud.vm.VMInstanceVO;
public class ListVolumesCmd extends BaseCmd{
@Implementation(method="searchForVolumes")
public class ListVolumesCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListVolumesCmd.class.getName());
private static final String s_name = "listvolumesresponse";
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
static {
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DOMAIN_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.HOST_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.NAME, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.POD_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.TYPE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.VIRTUAL_MACHINE_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ZONE_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.KEYWORD, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGESIZE, Boolean.FALSE));
}
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
@ -138,177 +120,85 @@ public class ListVolumesCmd extends BaseCmd{
@Override
public String getName() {
return s_name;
}
@Override
public List<Pair<Enum, Boolean>> getProperties() {
return s_properties;
}
}
@Override
public List<Pair<String, Object>> execute(Map<String, Object> params) {
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
Long id = (Long)params.get(BaseCmd.Properties.ID.getName());
String type = (String)params.get(BaseCmd.Properties.TYPE.getName());
String name = (String)params.get(BaseCmd.Properties.NAME.getName());
Long zoneId = (Long)params.get(BaseCmd.Properties.ZONE_ID.getName());
Long podId = (Long)params.get(BaseCmd.Properties.POD_ID.getName());
Long vmId = (Long)params.get(BaseCmd.Properties.VIRTUAL_MACHINE_ID.getName());
String accountName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName());
Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName());
Long hostId = (Long)params.get(BaseCmd.Properties.HOST_ID.getName());
String keyword = (String)params.get(BaseCmd.Properties.KEYWORD.getName());
Integer page = (Integer)params.get(BaseCmd.Properties.PAGE.getName());
Integer pageSize = (Integer)params.get(BaseCmd.Properties.PAGESIZE.getName());
Long accountId = null;
boolean isAdmin = false;
if ((account == null) || isAdmin(account.getType())) {
isAdmin = true;
if (domainId != null) {
if ((account != null) && !getManagementServer().isChildDomain(account.getDomainId(), domainId)) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Invalid domain id (" + domainId + ") given, unable to list volumes.");
}
if (accountName != null) {
Account userAccount = getManagementServer().findActiveAccount(accountName, domainId);
if (userAccount != null) {
accountId = userAccount.getId();
} else {
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "could not find account " + accountName + " in domain " + domainId);
}
}
} else {
domainId = ((account == null) ? DomainVO.ROOT_DOMAIN : account.getDomainId());
}
} else {
accountId = account.getId();
}
Long[] accountIds = null;
if (accountId != null) {
accountIds = new Long[1];
accountIds[0] = accountId;
}
Long startIndex = Long.valueOf(0);
int pageSizeNum = 50;
if (pageSize != null) {
pageSizeNum = pageSize.intValue();
}
if (page != null) {
int pageNum = page.intValue();
if (pageNum > 0) {
startIndex = Long.valueOf(pageSizeNum * (pageNum-1));
}
}
Criteria c = new Criteria("created", Boolean.FALSE, startIndex, Long.valueOf(pageSizeNum));
c.addCriteria(Criteria.ACCOUNTID, accountIds);
if (keyword != null) {
c.addCriteria(Criteria.KEYWORD, keyword);
} else {
c.addCriteria(Criteria.ID, id);
c.addCriteria(Criteria.INSTANCEID, vmId);
c.addCriteria(Criteria.NAME, name);
if (isAdmin) {
c.addCriteria(Criteria.VTYPE, type);
c.addCriteria(Criteria.DATACENTERID, zoneId);
c.addCriteria(Criteria.PODID, podId);
c.addCriteria(Criteria.HOSTID, hostId);
c.addCriteria(Criteria.DOMAINID, domainId);
}
}
List<VolumeVO> volumes = getManagementServer().searchForVolumes(c);
if (volumes == null) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "unable to find volumes");
}
List<Pair<String, Object>> volumeTags = new ArrayList<Pair<String, Object>>();
Object[] vTag = new Object[volumes.size()];
int i = 0;
for (VolumeVO volume : volumes) {
List<Pair<String, Object>> volumeData = new ArrayList<Pair<String, Object>>();
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), volume.getId()));
@Override @SuppressWarnings("unchecked")
public String getResponse() {
List<VolumeVO> volumes = (List<VolumeVO>)getResponseObject();
List<VolumeResponse> response = new ArrayList<VolumeResponse>();
for (VolumeVO volume : volumes) {
VolumeResponse volResponse = new VolumeResponse();
volResponse.setId(volume.getId());
AsyncJobVO asyncJob = getManagementServer().findInstancePendingAsyncJob("volume", volume.getId());
if(asyncJob != null) {
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.JOB_ID.getName(), asyncJob.getId().toString()));
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.JOB_STATUS.getName(), String.valueOf(asyncJob.getStatus())));
if (asyncJob != null) {
volResponse.setJobId(asyncJob.getId());
volResponse.setJobStatus(asyncJob.getStatus());
}
if (volume.getName() != null) {
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), volume.getName()));
} else {
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), ""));
if (volume.getName() != null) {
volResponse.setName(volume.getName());
} else {
volResponse.setName("");
}
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_ID.getName(), Long.valueOf(volume.getDataCenterId()).toString()));
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_NAME.getName(), getManagementServer().findDataCenterById(volume.getDataCenterId()).getName()));
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.TYPE.getName(), volume.getVolumeType()));
//volumeData.add(new Pair<String, Object>(BaseCmd.Properties.HOST_NAME.getName(), getManagementServer().getHostBy(volume.getHostId()).getName()));
volResponse.setZoneId(volume.getDataCenterId());
volResponse.setZoneName(getManagementServer().findDataCenterById(volume.getDataCenterId()).getName());
//volume.getDeviceId() might be null
if(volume.getDeviceId() != null)
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.DEVICE_ID.getName(), Long.valueOf(volume.getDeviceId()).toString()));
Long instanceId = volume.getInstanceId();
if (instanceId != null) {
VMInstanceVO vm = getManagementServer().findVMInstanceById(instanceId);
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.VIRTUAL_MACHINE_ID.getName(), vm.getId()));
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.VIRTUAL_MACHINE_NAME.getName(), vm.getName()));
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.VIRTUAL_MACHINE_DISPLAYNAME.getName(), vm.getName()));
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.VIRTUAL_MACHINE_STATE.getName(), vm.getState()));
}
// Show the virtual size of the volume
long virtualSizeInBytes = volume.getSize();
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.SIZE.getName(), virtualSizeInBytes));
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(volume.getCreated())));
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.STATE.getName(),volume.getStatus()));
Account accountTemp = getManagementServer().findAccountById(volume.getAccountId());
if (accountTemp != null) {
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.ACCOUNT.getName(), accountTemp.getAccountName()));
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN_ID.getName(), accountTemp.getDomainId()));
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN.getName(), getManagementServer().findDomainIdById(accountTemp.getDomainId()).getName()));
}
String storageType;
volResponse.setVolumeType(volume.getVolumeType().toString());
volResponse.setDeviceId(volume.getDeviceId());
Long instanceId = volume.getInstanceId();
if (instanceId != null) {
VMInstanceVO vm = getManagementServer().findVMInstanceById(instanceId);
volResponse.setVirtualMachineId(vm.getId());
volResponse.setVirtualMachineName(vm.getName());
volResponse.setVirtualMachineDisplayName(vm.getName());
volResponse.setVirtualMachineState(vm.getState().toString());
}
// Show the virtual size of the volume
volResponse.setSize(volume.getSize());
volResponse.setCreated(volume.getCreated());
volResponse.setState(volume.getStatus().toString());
Account accountTemp = getManagementServer().findAccountById(volume.getAccountId());
if (accountTemp != null) {
volResponse.setAccountName(accountTemp.getAccountName());
volResponse.setDomainId(accountTemp.getDomainId());
volResponse.setDomainName(getManagementServer().findDomainIdById(accountTemp.getDomainId()).getName());
}
String storageType;
try {
if(volume.getPoolId() == null){
storageType = "unknown";
} else {
} else {
storageType = getManagementServer().volumeIsOnSharedStorage(volume.getId()) ? "shared" : "local";
}
} catch (InvalidParameterValueException e) {
s_logger.error(e.getMessage(), e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Volume " + volume.getName() + " does not have a valid ID");
}
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.STORAGE_TYPE.getName(), storageType));
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.DISK_OFFERING_ID.getName(),volume.getDiskOfferingId()));
if(volume.getDiskOfferingId()!=null)
{
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.DISK_OFFERING_NAME.getName(),getManagementServer().findDiskOfferingById(volume.getDiskOfferingId()).getName()));
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.DISK_OFFERING_DISPLAY_TEXT.getName(),getManagementServer().findDiskOfferingById(volume.getDiskOfferingId()).getDisplayText()));
}
} catch (InvalidParameterValueException e) {
s_logger.error(e.getMessage(), e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Volume " + volume.getName() + " does not have a valid ID");
}
volResponse.setStorageType(storageType);
volResponse.setDiskOfferingId(volume.getDiskOfferingId());
if (volume.getDiskOfferingId() != null) {
DiskOfferingVO diskOffering = getManagementServer().findDiskOfferingById(volume.getDiskOfferingId());
volResponse.setDiskOfferingName(diskOffering.getName());
volResponse.setDiskOfferingDisplayText(diskOffering.getDisplayText());
}
Long poolId = volume.getPoolId();
String poolName = (poolId == null) ? "none" : getManagementServer().findPoolById(poolId).getName();
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.STORAGE.getName(), poolName));
vTag[i++] = volumeData;
}
Pair<String, Object> volumeTag = new Pair<String, Object>("volume", vTag);
volumeTags.add(volumeTag);
return volumeTags;
String poolName = (poolId == null) ? "none" : getManagementServer().findPoolById(poolId).getName();
volResponse.setStoragePoolName(poolName);
response.add(volResponse);
}
return SerializerHelper.toSerializedString(response);
}
}

View File

@ -20,28 +20,23 @@ package com.cloud.api.commands;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd;
import com.cloud.api.BaseListCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.ZoneResponse;
import com.cloud.dc.DataCenterVO;
import com.cloud.serializer.SerializerHelper;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
//FIXME: consolidate this class and ListDataCentersByCmd
public class ListZonesByCmd extends BaseCmd {
import com.cloud.user.UserContext;
@Implementation(method="listDataCenters")
public class ListZonesByCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListZonesByCmd.class.getName());
private static final String s_name = "listzonesresponse";
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
static {
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.AVAILABLE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
}
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
@ -65,71 +60,35 @@ public class ListZonesByCmd extends BaseCmd {
@Override
public String getName() {
return s_name;
}
@Override
public List<Pair<Enum, Boolean>> getProperties() {
return s_properties;
}
}
@Override
public List<Pair<String, Object>> execute(Map<String, Object> params) {
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
Boolean available = (Boolean)params.get(BaseCmd.Properties.AVAILABLE.getName());
List<DataCenterVO> dataCenters = null;
if (account != null) {
if (available != null && available) {
dataCenters = getManagementServer().listDataCenters();
} else {
dataCenters = getManagementServer().listDataCentersBy(account.getId().longValue());
}
} else {
// available is kinda useless in this case because we can't exactly list by
// accountId if we don't have one. In this case, we just assume the user
// wants all the zones.
dataCenters = getManagementServer().listDataCenters();
}
if (dataCenters == null) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "unable to find zones for account " + account.getAccountName());
}
List<Pair<String, Object>> dcTags = new ArrayList<Pair<String, Object>>();
Object[] dcInstTag = new Object[dataCenters.size()];
int i = 0;
for (DataCenterVO dataCenter : dataCenters) {
List<Pair<String, Object>> dcData = new ArrayList<Pair<String, Object>>();
if (dataCenter.getId() != null) {
dcData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), dataCenter.getId().toString()));
}
dcData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), dataCenter.getName()));
if ((dataCenter.getDescription() != null) && !dataCenter.getDescription().equalsIgnoreCase("null")) {
dcData.add(new Pair<String, Object>(BaseCmd.Properties.DESCRIPTION.getName(), dataCenter.getDescription()));
}
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) {
if (dataCenter.getDns1() != null) {
dcData.add(new Pair<String, Object>(BaseCmd.Properties.DNS1.getName(), dataCenter.getDns1()));
}
if (dataCenter.getDns2() != null) {
dcData.add(new Pair<String, Object>(BaseCmd.Properties.DNS2.getName(), dataCenter.getDns2()));
}
if (dataCenter.getInternalDns1() != null) {
dcData.add(new Pair<String, Object>(BaseCmd.Properties.INTERNAL_DNS1.getName(), dataCenter.getInternalDns1()));
}
if (dataCenter.getInternalDns2() != null) {
dcData.add(new Pair<String, Object>(BaseCmd.Properties.INTERNAL_DNS2.getName(), dataCenter.getInternalDns2()));
}
if (dataCenter.getVnet() != null) {
dcData.add(new Pair<String, Object>("vlan", dataCenter.getVnet()));
}
if (dataCenter.getGuestNetworkCidr() != null) {
dcData.add(new Pair<String, Object>(BaseCmd.Properties.GUEST_CIDR_ADDRESS.getName(), dataCenter.getGuestNetworkCidr()));
}
}
dcInstTag[i++] = dcData;
}
Pair<String, Object> dcTag = new Pair<String, Object>("zone", dcInstTag);
dcTags.add(dcTag);
return dcTags;
@Override @SuppressWarnings("unchecked")
public String getResponse() {
List<DataCenterVO> dataCenters = (List<DataCenterVO>)getResponseObject();
Account account = (Account)UserContext.current().getAccountObject();
List<ZoneResponse> response = new ArrayList<ZoneResponse>();
for (DataCenterVO dataCenter : dataCenters) {
ZoneResponse zoneResponse = new ZoneResponse();
zoneResponse.setId(dataCenter.getId());
zoneResponse.setName(dataCenter.getName());
if ((dataCenter.getDescription() != null) && !dataCenter.getDescription().equalsIgnoreCase("null")) {
zoneResponse.setDescription(dataCenter.getDescription());
}
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) {
zoneResponse.setDns1(dataCenter.getDns1());
zoneResponse.setDns2(dataCenter.getDns2());
zoneResponse.setInternalDns1(dataCenter.getInternalDns1());
zoneResponse.setInternalDns2(dataCenter.getInternalDns2());
zoneResponse.setVlan(dataCenter.getVnet());
zoneResponse.setGuestCidrAddress(dataCenter.getGuestNetworkCidr());
}
response.add(zoneResponse);
}
return SerializerHelper.toSerializedString(response);
}
}

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.api.ResponseObject;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.api.ResponseObject;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.api.ResponseObject;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.api.ResponseObject;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.api.ResponseObject;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.api.ResponseObject;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.api.ResponseObject;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.api.ResponseObject;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.api.ResponseObject;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.List;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.api.ResponseObject;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.api.ResponseObject;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.api.ResponseObject;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.api.ResponseObject;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.api.ResponseObject;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;

View File

@ -0,0 +1,289 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;
import com.cloud.api.ResponseObject;
import com.cloud.serializer.Param;
public class SystemVmResponse implements ResponseObject {
@Param(name="id")
private Long id;
@Param(name="systemvmtype")
private String systemVmType;
@Param(name="jobid")
private Long jobId;
@Param(name="jobstatus")
private Integer jobStatus;
@Param(name="zoneid")
private Long zoneId;
@Param(name="zonename")
private String zoneName;
@Param(name="dns1")
private String dns1;
@Param(name="dns2")
private String dns2;
@Param(name="networkdomain")
private String networkDomain;
@Param(name="gateway")
private String gateway;
@Param(name="name")
private String name;
@Param(name="podid")
private Long podId;
@Param(name="hostid")
private Long hostId;
@Param(name="hostname")
private String hostName;
@Param(name="privateip")
private String privateIp;
@Param(name="privatemacaddress")
private String privateMacAddress;
@Param(name="privatenetmask")
private String privateNetmask;
@Param(name="publicip")
private String publicIp;
@Param(name="publicmacaddress")
private String publicMacAddress;
@Param(name="publicnetmask")
private String publicNetmask;
@Param(name="templateid")
private Long templateId;
@Param(name="created")
private Date created;
@Param(name="state")
private String state;
@Param(name="activeviewersessions")
private Integer activeViewerSessions;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getSystemVmType() {
return systemVmType;
}
public void setSystemVmType(String systemVmType) {
this.systemVmType = systemVmType;
}
public Long getJobId() {
return jobId;
}
public void setJobId(Long jobId) {
this.jobId = jobId;
}
public Integer getJobStatus() {
return jobStatus;
}
public void setJobStatus(Integer jobStatus) {
this.jobStatus = jobStatus;
}
public Long getZoneId() {
return zoneId;
}
public void setZoneId(Long zoneId) {
this.zoneId = zoneId;
}
public String getZoneName() {
return zoneName;
}
public void setZoneName(String zoneName) {
this.zoneName = zoneName;
}
public String getDns1() {
return dns1;
}
public void setDns1(String dns1) {
this.dns1 = dns1;
}
public String getDns2() {
return dns2;
}
public void setDns2(String dns2) {
this.dns2 = dns2;
}
public String getNetworkDomain() {
return networkDomain;
}
public void setNetworkDomain(String networkDomain) {
this.networkDomain = networkDomain;
}
public String getGateway() {
return gateway;
}
public void setGateway(String gateway) {
this.gateway = gateway;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getPodId() {
return podId;
}
public void setPodId(Long podId) {
this.podId = podId;
}
public Long getHostId() {
return hostId;
}
public void setHostId(Long hostId) {
this.hostId = hostId;
}
public String getHostName() {
return hostName;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
public String getPrivateIp() {
return privateIp;
}
public void setPrivateIp(String privateIp) {
this.privateIp = privateIp;
}
public String getPrivateMacAddress() {
return privateMacAddress;
}
public void setPrivateMacAddress(String privateMacAddress) {
this.privateMacAddress = privateMacAddress;
}
public String getPrivateNetmask() {
return privateNetmask;
}
public void setPrivateNetmask(String privateNetmask) {
this.privateNetmask = privateNetmask;
}
public String getPublicIp() {
return publicIp;
}
public void setPublicIp(String publicIp) {
this.publicIp = publicIp;
}
public String getPublicMacAddress() {
return publicMacAddress;
}
public void setPublicMacAddress(String publicMacAddress) {
this.publicMacAddress = publicMacAddress;
}
public String getPublicNetmask() {
return publicNetmask;
}
public void setPublicNetmask(String publicNetmask) {
this.publicNetmask = publicNetmask;
}
public Long getTemplateId() {
return templateId;
}
public void setTemplateId(Long templateId) {
this.templateId = templateId;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public Integer getActiveViewerSessions() {
return activeViewerSessions;
}
public void setActiveViewerSessions(Integer activeViewerSessions) {
this.activeViewerSessions = activeViewerSessions;
}
}

View File

@ -0,0 +1,69 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.List;
import com.cloud.api.ResponseObject;
import com.cloud.serializer.Param;
public class TemplatePermissionsResponse implements ResponseObject {
@Param(name="id")
private Long id;
@Param(name="ispublic")
private Boolean publicTemplate;
@Param(name="domainid")
private Long domainId;
@Param(name="account")
private List<String> accountNames;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Boolean getPublicTemplate() {
return publicTemplate;
}
public void setPublicTemplate(Boolean publicTemplate) {
this.publicTemplate = publicTemplate;
}
public Long getDomainId() {
return domainId;
}
public void setDomainId(Long domainId) {
this.domainId = domainId;
}
public List<String> getAccountNames() {
return accountNames;
}
public void setAccountNames(List<String> accountNames) {
this.accountNames = accountNames;
}
}

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;
@ -42,7 +59,11 @@ public class UserResponse implements ResponseObject {
@Param(name="timezone")
private String timezone;
// TODO: user keys?
@Param(name="apikey")
private String apiKey;
@Param(name="secretkey")
private String secretKey;
public Long getId() {
return id;
@ -139,4 +160,20 @@ public class UserResponse implements ResponseObject {
public void setTimezone(String timezone) {
this.timezone = timezone;
}
public String getApiKey() {
return apiKey;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
public String getSecretKey() {
return secretKey;
}
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
}

View File

@ -1,5 +1,24 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;
import com.cloud.api.ResponseObject;
import com.cloud.serializer.Param;
@ -25,6 +44,84 @@ public class UserVmResponse implements ResponseObject {
@Param(name="domain")
private String domainName;
@Param(name="created")
private Date created;
@Param(name="state")
private String state;
@Param(name="haenable")
private Boolean haEnable;
@Param(name="group")
private String group;
@Param(name="zoneid")
private Long zoneId;
@Param(name="zonename")
private String zoneName;
@Param(name="hostid")
private Long hostId;
@Param(name="hostname")
private String hostName;
@Param(name="templateid")
private Long templateId;
@Param(name="templatename")
private String templateName;
@Param(name="templatedisplaytext")
private String templateDisplayText;
@Param(name="passwordenabled")
private Boolean passwordEnabled;
@Param(name="isoid")
private Long isoId;
@Param(name="isoname")
private String isoName;
@Param(name="serviceofferingid")
private Long serviceOfferingId;
@Param(name="serviceofferingname")
private String serviceOfferingName;
@Param(name="cpunumber")
private Integer cpuNumber;
@Param(name="cpuspeed")
private Integer cpuSpeed;
@Param(name="memory")
private Integer memory;
@Param(name="cpuused")
private String cpuUsed;
@Param(name="networkkbsread")
private Long networkKbsRead;
@Param(name="networkkbswrite")
private Long networkKbsWrite;
@Param(name="ostypeid")
private Long osTypeId;
@Param(name="networkgrouplist")
private String networkGroupList;
@Param(name="jobid")
private Long jobId;
@Param(name="jobstatus")
private Integer jobStatus;
public Long getId() {
return id;
}
@ -80,4 +177,212 @@ public class UserVmResponse implements ResponseObject {
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public Boolean getHaEnable() {
return haEnable;
}
public void setHaEnable(Boolean haEnable) {
this.haEnable = haEnable;
}
public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = group;
}
public Long getZoneId() {
return zoneId;
}
public void setZoneId(Long zoneId) {
this.zoneId = zoneId;
}
public String getZoneName() {
return zoneName;
}
public void setZoneName(String zoneName) {
this.zoneName = zoneName;
}
public Long getHostId() {
return hostId;
}
public void setHostId(Long hostId) {
this.hostId = hostId;
}
public String getHostName() {
return hostName;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
public Long getTemplateId() {
return templateId;
}
public void setTemplateId(Long templateId) {
this.templateId = templateId;
}
public String getTemplateName() {
return templateName;
}
public void setTemplateName(String templateName) {
this.templateName = templateName;
}
public String getTemplateDisplayText() {
return templateDisplayText;
}
public void setTemplateDisplayText(String templateDisplayText) {
this.templateDisplayText = templateDisplayText;
}
public Boolean getPasswordEnabled() {
return passwordEnabled;
}
public void setPasswordEnabled(Boolean passwordEnabled) {
this.passwordEnabled = passwordEnabled;
}
public Long getIsoId() {
return isoId;
}
public void setIsoId(Long isoId) {
this.isoId = isoId;
}
public String getIsoName() {
return isoName;
}
public void setIsoName(String isoName) {
this.isoName = isoName;
}
public Long getServiceOfferingId() {
return serviceOfferingId;
}
public void setServiceOfferingId(Long serviceOfferingId) {
this.serviceOfferingId = serviceOfferingId;
}
public String getServiceOfferingName() {
return serviceOfferingName;
}
public void setServiceOfferingName(String serviceOfferingName) {
this.serviceOfferingName = serviceOfferingName;
}
public Integer getCpuNumber() {
return cpuNumber;
}
public void setCpuNumber(Integer cpuNumber) {
this.cpuNumber = cpuNumber;
}
public Integer getCpuSpeed() {
return cpuSpeed;
}
public void setCpuSpeed(Integer cpuSpeed) {
this.cpuSpeed = cpuSpeed;
}
public Integer getMemory() {
return memory;
}
public void setMemory(Integer memory) {
this.memory = memory;
}
public String getCpuUsed() {
return cpuUsed;
}
public void setCpuUsed(String cpuUsed) {
this.cpuUsed = cpuUsed;
}
public Long getNetworkKbsRead() {
return networkKbsRead;
}
public void setNetworkKbsRead(Long networkKbsRead) {
this.networkKbsRead = networkKbsRead;
}
public Long getNetworkKbsWrite() {
return networkKbsWrite;
}
public void setNetworkKbsWrite(Long networkKbsWrite) {
this.networkKbsWrite = networkKbsWrite;
}
public Long getOsTypeId() {
return osTypeId;
}
public void setOsTypeId(Long osTypeId) {
this.osTypeId = osTypeId;
}
public String getNetworkGroupList() {
return networkGroupList;
}
public void setNetworkGroupList(String networkGroupList) {
this.networkGroupList = networkGroupList;
}
public Long getJobId() {
return jobId;
}
public void setJobId(Long jobId) {
this.jobId = jobId;
}
public Integer getJobStatus() {
return jobStatus;
}
public void setJobStatus(Integer jobStatus) {
this.jobStatus = jobStatus;
}
}

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.api.ResponseObject;

View File

@ -0,0 +1,278 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import java.util.Date;
import com.cloud.api.ResponseObject;
import com.cloud.serializer.Param;
public class VolumeResponse implements ResponseObject {
@Param(name="id")
private Long id;
@Param(name="jobid")
private Long jobId;
@Param(name="jobstatus")
private Integer jobStatus;
@Param(name="name")
private String name;
@Param(name="zoneid")
private Long zoneId;
@Param(name="zonename")
private String zoneName;
@Param(name="type")
private String volumeType;
@Param(name="deviceid")
private Long deviceId;
@Param(name="virtualmachineid")
private Long virtualMachineId;
@Param(name="virtualmachinename")
private String virtualMachineName;
@Param(name="virtualmachinedisplayname")
private String virtualMachineDisplayName;
@Param(name="virtualmachinestate")
private String virtualMachineState;
@Param(name="size")
private Long size;
@Param(name="created")
private Date created;
@Param(name="state")
private String state;
@Param(name="account")
private String accountName;
@Param(name="domainid")
private Long domainId;
@Param(name="domain")
private String domainName;
@Param(name="storagetype")
private String storageType;
@Param(name="diskofferingid")
private Long diskOfferingId;
@Param(name="diskofferingname")
private String diskOfferingName;
@Param(name="diskofferingdisplaytext")
private String diskOfferingDisplayText;
@Param(name="storage")
private String storagePoolName;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getJobId() {
return jobId;
}
public void setJobId(Long jobId) {
this.jobId = jobId;
}
public Integer getJobStatus() {
return jobStatus;
}
public void setJobStatus(Integer jobStatus) {
this.jobStatus = jobStatus;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getZoneId() {
return zoneId;
}
public void setZoneId(Long zoneId) {
this.zoneId = zoneId;
}
public String getZoneName() {
return zoneName;
}
public void setZoneName(String zoneName) {
this.zoneName = zoneName;
}
public String getVolumeType() {
return volumeType;
}
public void setVolumeType(String volumeType) {
this.volumeType = volumeType;
}
public Long getDeviceId() {
return deviceId;
}
public void setDeviceId(Long deviceId) {
this.deviceId = deviceId;
}
public Long getVirtualMachineId() {
return virtualMachineId;
}
public void setVirtualMachineId(Long virtualMachineId) {
this.virtualMachineId = virtualMachineId;
}
public String getVirtualMachineName() {
return virtualMachineName;
}
public void setVirtualMachineName(String virtualMachineName) {
this.virtualMachineName = virtualMachineName;
}
public String getVirtualMachineDisplayName() {
return virtualMachineDisplayName;
}
public void setVirtualMachineDisplayName(String virtualMachineDisplayName) {
this.virtualMachineDisplayName = virtualMachineDisplayName;
}
public String getVirtualMachineState() {
return virtualMachineState;
}
public void setVirtualMachineState(String virtualMachineState) {
this.virtualMachineState = virtualMachineState;
}
public Long getSize() {
return size;
}
public void setSize(Long size) {
this.size = size;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public Long getDomainId() {
return domainId;
}
public void setDomainId(Long domainId) {
this.domainId = domainId;
}
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public String getStorageType() {
return storageType;
}
public void setStorageType(String storageType) {
this.storageType = storageType;
}
public Long getDiskOfferingId() {
return diskOfferingId;
}
public void setDiskOfferingId(Long diskOfferingId) {
this.diskOfferingId = diskOfferingId;
}
public String getDiskOfferingName() {
return diskOfferingName;
}
public void setDiskOfferingName(String diskOfferingName) {
this.diskOfferingName = diskOfferingName;
}
public String getDiskOfferingDisplayText() {
return diskOfferingDisplayText;
}
public void setDiskOfferingDisplayText(String diskOfferingDisplayText) {
this.diskOfferingDisplayText = diskOfferingDisplayText;
}
public String getStoragePoolName() {
return storagePoolName;
}
public void setStoragePoolName(String storagePoolName) {
this.storagePoolName = storagePoolName;
}
}

View File

@ -1,3 +1,20 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.api.ResponseObject;
@ -10,6 +27,9 @@ public class ZoneResponse implements ResponseObject {
@Param(name="name")
private String name;
@Param(name="description")
private String description;
@Param(name="dns1")
private String dns1;
@ -44,6 +64,14 @@ public class ZoneResponse implements ResponseObject {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDns1() {
return dns1;
}

View File

@ -55,7 +55,15 @@ import com.cloud.api.commands.ListPublicIpAddressesCmd;
import com.cloud.api.commands.ListRoutersCmd;
import com.cloud.api.commands.ListServiceOfferingsCmd;
import com.cloud.api.commands.ListSnapshotsCmd;
import com.cloud.api.commands.ListStoragePoolsCmd;
import com.cloud.api.commands.ListSystemVMsCmd;
import com.cloud.api.commands.ListTemplateOrIsoPermissionsCmd;
import com.cloud.api.commands.ListTemplatesCmd;
import com.cloud.api.commands.ListUsersCmd;
import com.cloud.api.commands.ListVMsCmd;
import com.cloud.api.commands.ListVlanIpRangesCmd;
import com.cloud.api.commands.ListVolumesCmd;
import com.cloud.api.commands.ListZonesByCmd;
import com.cloud.api.commands.LockAccountCmd;
import com.cloud.api.commands.LockUserCmd;
import com.cloud.api.commands.RebootSystemVmCmd;
@ -414,46 +422,13 @@ public interface ManagementServer {
*/
VolumeStats[] getVolumeStatistics(long[] volId);
/**
* Associate / allocate an IP address to a user
* @param userId
* @param accountId
* @param domainId
* @param zoneId
* @return allocated IP address in the zone specified
* @throws InsufficientAddressCapacityException if no more addresses are available
* @throws InvalidParameterValueException if no router for that user exists in the zone specified
* @throws InternalErrorException if the new address could not be sent down to the router
*/
// String associateIpAddress(long userId, long accountId, long domainId, long zoneId) throws ResourceAllocationException, InsufficientAddressCapacityException, InvalidParameterValueException, InternalErrorException;
// long associateIpAddressAsync(long userId, long accountId, long domainId, long zoneId);
/**
* Disassociate /unallocate an allocated IP address from a user
* @param userId
* @param accountId
* @param ipAddress
* @return success
*/
// boolean disassociateIpAddress(DisassociateIPAddrCmd cmd) throws PermissionDeniedException;
// long disassociateIpAddressAsync(long userId, long accountId, String ipAddress);
/**
* Deletes a VLAN from the database, along with all of its IP addresses. Will not delete VLANs that have allocated IP addresses.
* @param userId
* @param vlanDbId
* @return success/failure
*/
// boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId) throws InvalidParameterValueException;
/**
* Searches for vlan by the specified search criteria
* Can search by: "id", "vlan", "name", "zoneID"
* @param c
* @param cmd
* @return List of Vlans
*/
List<VlanVO> searchForVlans(Criteria c);
List<VlanVO> searchForVlans(ListVlanIpRangesCmd cmd) throws InvalidParameterValueException;
/**
* If the specified VLAN is associated with the pod, returns the pod ID. Else, returns null.
@ -808,19 +783,13 @@ public interface ManagementServer {
HostPodVO getPodBy(long podId);
/**
* Retrieves the list of all data centers
* Retrieves the list of data centers with search criteria.
* Currently the only search criteria is "available" zones for the account that invokes the API. By specifying
* available=true all zones which the account can access. By specifying available=false the zones where the
* account has virtual machine instances will be returned.
* @return a list of DataCenters
*/
List<DataCenterVO> listDataCenters();
/**
* Retrieves a list of data centers that contain domain routers
* that the specified user owns.
*
* @param userId
* @return a list of DataCenters
*/
List<DataCenterVO> listDataCentersBy(long userId);
List<DataCenterVO> listDataCenters(ListZonesByCmd cmd);
/**
* Retrieves a host by id
@ -829,15 +798,6 @@ public interface ManagementServer {
*/
HostVO getHostBy(long hostId);
// /**
// * Deletes a host
// *
// * @param hostId
// * @param true if deleted, false otherwise
// */
// boolean deleteHost(long hostId);
/**
* Retrieves all Events between the start and end date specified
*
@ -868,10 +828,10 @@ public interface ManagementServer {
/** revisit
* Searches for users by the specified search criteria
* Can search by: "id", "username", "account", "domainId", "type"
* @param c
* @param cmd
* @return List of UserAccounts
*/
List<UserAccountVO> searchForUsers(Criteria c);
List<UserAccountVO> searchForUsers(ListUsersCmd cmd) throws PermissionDeniedException;
/**
* Searches for Service Offerings by the specified search criteria
@ -1130,6 +1090,14 @@ public interface ManagementServer {
*/
List<UserVmVO> searchForUserVMs(Criteria c);
/**
* Obtains a list of virtual machines by the specified search criteria.
* Can search by: "userId", "name", "state", "dataCenterId", "podId", "hostId"
* @param cmd the API command that wraps the search criteria
* @return List of UserVMs.
*/
List<UserVmVO> searchForUserVMs(ListVMsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
/**
* Update an existing port forwarding rule on the given public IP / public port for the given protocol
* @param userId id of the user performing the action
@ -1220,10 +1188,10 @@ public interface ManagementServer {
/** revisit
* Obtains a list of storage volumes by the specified search criteria.
* Can search by: "userId", "vType", "instanceId", "dataCenterId", "podId", "hostId"
* @param c
* @param cmd
* @return List of Volumes.
*/
List<VolumeVO> searchForVolumes(Criteria c);
List<VolumeVO> searchForVolumes(ListVolumesCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
/**
* Checks that the volume is stored on a shared storage pool.
@ -1593,26 +1561,12 @@ public interface ManagementServer {
*/
List<DiskOfferingVO> findPrivateDiskOffering();
/**
* Update the permissions on a template. A private template can be made public, or individual accounts can be granted permission to launch instances from the template.
* @param templateId
* @param operation
* @param isPublic
* @param isFeatured
* @param accountNames
* @return
* @throws InvalidParameterValueException
* @throws PermissionDeniedException
* @throws InternalErrorException
*/
// boolean updateTemplatePermissions(long templateId, String operation, Boolean isPublic, Boolean isFeatured, List<String> accountNames) throws InvalidParameterValueException, PermissionDeniedException, InternalErrorException;
/**
* List the permissions on a template. This will return a list of account names that have been granted permission to launch instances from the template.
* @param templateId
* @param cmd the command wrapping the search criteria (template id)
* @return list of account names that have been granted permission to launch instances from the template
*/
List<String> listTemplatePermissions(long templateId);
List<String> listTemplatePermissions(ListTemplateOrIsoPermissionsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
/**
* List private templates for which the given account/domain has been granted permission to launch instances
@ -1807,6 +1761,13 @@ public interface ManagementServer {
StoragePoolVO findPoolById(Long id);
List<? extends StoragePoolVO> searchForStoragePools(Criteria c);
/**
* List storage pools that match the given criteria
* @param cmd the command that wraps the search criteria (zone, pod, name, IP address, path, and cluster id)
* @return a list of storage pools that match the given criteria
*/
List<? extends StoragePoolVO> searchForStoragePools(ListStoragePoolsCmd cmd);
SnapshotPolicyVO findSnapshotPolicyById(Long policyId);
/**
@ -1827,6 +1788,13 @@ public interface ManagementServer {
List<SecondaryStorageVmVO> searchForSecondaryStorageVm(Criteria c);
/**
* List system VMs by the given search criteria
* @param cmd the command that wraps the search criteria (host, name, state, type, zone, pod, and/or id)
* @return the list of system vms that match the given criteria
*/
List<? extends VMInstanceVO> searchForSystemVm(ListSystemVMsCmd cmd);
/**
* Returns back a SHA1 signed response
* @param userId -- id for the user
* @return -- ArrayList of <CloudId+Signature>

View File

@ -89,7 +89,15 @@ import com.cloud.api.commands.ListPublicIpAddressesCmd;
import com.cloud.api.commands.ListRoutersCmd;
import com.cloud.api.commands.ListServiceOfferingsCmd;
import com.cloud.api.commands.ListSnapshotsCmd;
import com.cloud.api.commands.ListStoragePoolsCmd;
import com.cloud.api.commands.ListSystemVMsCmd;
import com.cloud.api.commands.ListTemplateOrIsoPermissionsCmd;
import com.cloud.api.commands.ListTemplatesCmd;
import com.cloud.api.commands.ListUsersCmd;
import com.cloud.api.commands.ListVMsCmd;
import com.cloud.api.commands.ListVlanIpRangesCmd;
import com.cloud.api.commands.ListVolumesCmd;
import com.cloud.api.commands.ListZonesByCmd;
import com.cloud.api.commands.LockAccountCmd;
import com.cloud.api.commands.LockUserCmd;
import com.cloud.api.commands.RebootSystemVmCmd;
@ -2809,26 +2817,29 @@ public class ManagementServerImpl implements ManagementServer {
@Override
public List<DataCenterVO> listDataCenters() {
return _dcDao.listAllActive();
}
@Override
public List<DataCenterVO> listDataCentersBy(long accountId) {
public List<DataCenterVO> listDataCenters(ListZonesByCmd cmd) {
List<DataCenterVO> dcs = _dcDao.listAllActive();
List<DomainRouterVO> routers = _routerDao.listBy(accountId);
for (Iterator<DataCenterVO> iter = dcs.iterator(); iter.hasNext();) {
DataCenterVO dc = iter.next();
boolean found = false;
for (DomainRouterVO router : routers) {
if (dc.getId() == router.getDataCenterId()) {
found = true;
break;
Account account = (Account)UserContext.current().getAccountObject();
Boolean available = cmd.isAvailable();
if (account != null) {
if ((available != null) && Boolean.FALSE.equals(available)) {
List<DomainRouterVO> routers = _routerDao.listBy(account.getId());
for (Iterator<DataCenterVO> iter = dcs.iterator(); iter.hasNext();) {
DataCenterVO dc = iter.next();
boolean found = false;
for (DomainRouterVO router : routers) {
if (dc.getId() == router.getDataCenterId()) {
found = true;
break;
}
}
if (!found)
iter.remove();
}
}
if (!found)
iter.remove();
}
return dcs;
}
@ -2837,10 +2848,6 @@ public class ManagementServerImpl implements ManagementServer {
return _hostDao.findById(hostId);
}
// public boolean deleteHost(long hostId) {
// return _agentMgr.deleteHost(hostId);
// }
@Override
public long getId() {
return MacAddress.getMacAddress().toLong();
@ -3753,16 +3760,26 @@ public class ManagementServerImpl implements ManagementServer {
}
@Override
public List<UserAccountVO> searchForUsers(Criteria c) {
Filter searchFilter = new Filter(UserAccountVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit());
public List<UserAccountVO> searchForUsers(ListUsersCmd cmd) throws PermissionDeniedException {
Account account = (Account)UserContext.current().getAccountObject();
Long domainId = cmd.getDomainId();
if (domainId != null) {
if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), domainId)) {
throw new PermissionDeniedException("Invalid domain id (" + domainId + ") given, unable to list users.");
}
} else {
// default domainId to the admin's domain
domainId = ((account == null) ? DomainVO.ROOT_DOMAIN : account.getDomainId());
}
Object id = c.getCriteria(Criteria.ID);
Object username = c.getCriteria(Criteria.USERNAME);
Object type = c.getCriteria(Criteria.TYPE);
Object domainId = c.getCriteria(Criteria.DOMAINID);
Object account = c.getCriteria(Criteria.ACCOUNTNAME);
Object state = c.getCriteria(Criteria.STATE);
Object keyword = c.getCriteria(Criteria.KEYWORD);
Filter searchFilter = new Filter(UserAccountVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
Object id = cmd.getId();
Object username = cmd.getUsername();
Object type = cmd.getAccountType();
Object accountName = cmd.getAccountName();
Object state = cmd.getState();
Object keyword = cmd.getKeyword();
SearchBuilder<UserAccountVO> sb = _userAccountDao.createSearchBuilder();
sb.and("username", sb.entity().getUsername(), SearchCriteria.Op.LIKE);
@ -3772,7 +3789,7 @@ public class ManagementServerImpl implements ManagementServer {
sb.and("accountName", sb.entity().getAccountName(), SearchCriteria.Op.LIKE);
sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
if ((account == null) && (domainId != null)) {
if ((accountName == null) && (domainId != null)) {
SearchBuilder<DomainVO> domainSearch = _domainDao.createSearchBuilder();
domainSearch.and("path", domainSearch.entity().getPath(), SearchCriteria.Op.LIKE);
sb.join("domainSearch", domainSearch, sb.entity().getDomainId(), domainSearch.entity().getId());
@ -3805,8 +3822,8 @@ public class ManagementServerImpl implements ManagementServer {
sc.setParameters("type", type);
}
if (account != null) {
sc.setParameters("accountName", "%" + account + "%");
if (accountName != null) {
sc.setParameters("accountName", "%" + accountName + "%");
if (domainId != null) {
sc.setParameters("domainId", domainId);
}
@ -4004,18 +4021,30 @@ public class ManagementServerImpl implements ManagementServer {
return _dcDao.search(sc, searchFilter);
}
@Override
public List<VlanVO> searchForVlans(Criteria c) {
Filter searchFilter = new Filter(VlanVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit());
Object id = c.getCriteria(Criteria.ID);
Object vlan = c.getCriteria(Criteria.VLAN);
Object dataCenterId = c.getCriteria(Criteria.DATACENTERID);
Object accountId = c.getCriteria(Criteria.ACCOUNTID);
Object podId = c.getCriteria(Criteria.PODID);
Object keyword = c.getCriteria(Criteria.KEYWORD);
public List<VlanVO> searchForVlans(ListVlanIpRangesCmd cmd) throws InvalidParameterValueException {
// If an account name and domain ID are specified, look up the account
String accountName = cmd.getAccountName();
Long domainId = cmd.getDomainId();
Long accountId = null;
if (accountName != null && domainId != null) {
Account account = _accountDao.findActiveAccount(accountName, domainId);
if (account == null) {
throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId);
} else {
accountId = account.getId();
}
}
Filter searchFilter = new Filter(VlanVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
Object id = cmd.getId();
Object vlan = cmd.getVlan();
Object dataCenterId = cmd.getZoneId();
Object podId = cmd.getPodId();
Object keyword = cmd.getKeyword();
SearchBuilder<VlanVO> sb = _vlanDao.createSearchBuilder();
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("vlan", sb.entity().getVlanId(), SearchCriteria.Op.EQ);
@ -4861,13 +4890,62 @@ public class ManagementServerImpl implements ManagementServer {
return _templateHostDao.findByHostTemplate(secondaryStorageHost.getId(), templateId);
}
}
@Override
public List<UserVmVO> listUserVMsByHostId(long hostId) {
return _userVmDao.listByHostId(hostId);
}
@Override
public List<UserVmVO> searchForUserVMs(ListVMsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
Account account = (Account)UserContext.current().getAccountObject();
Long domainId = cmd.getDomainId();
String accountName = cmd.getAccountName();
Long accountId = null;
boolean isAdmin = false;
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();
}
} else {
domainId = ((account == null) ? DomainVO.ROOT_DOMAIN : account.getDomainId());
}
} else {
accountName = account.getAccountName();
accountId = account.getId();
domainId = account.getDomainId();
}
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());
// ignore these search requests if it's not an admin
if (isAdmin == true) {
c.addCriteria(Criteria.DOMAINID, domainId);
c.addCriteria(Criteria.PODID, cmd.getPodId());
c.addCriteria(Criteria.HOSTID, cmd.getHostId());
}
c.addCriteria(Criteria.ACCOUNTID, accountId);
c.addCriteria(Criteria.ISADMIN, isAdmin);
return searchForUserVMs(c);
}
@Override
public List<UserVmVO> searchForUserVMs(Criteria c) {
Filter searchFilter = new Filter(UserVmVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit());
@ -5532,19 +5610,52 @@ public class ManagementServerImpl implements ManagementServer {
}
@Override
public List<VolumeVO> searchForVolumes(Criteria c) {
Filter searchFilter = new Filter(VolumeVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit());
// SearchCriteria sc = _volumeDao.createSearchCriteria();
public List<VolumeVO> searchForVolumes(ListVolumesCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
Account account = (Account)UserContext.current().getAccountObject();
Long domainId = cmd.getDomainId();
String accountName = cmd.getAccountName();
Long accountId = null;
boolean isAdmin = false;
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 volumes.");
}
if (accountName != null) {
Account userAccount = _accountDao.findActiveAccount(accountName, domainId);
if (userAccount != null) {
accountId = userAccount.getId();
} else {
throw new InvalidParameterValueException("could not find account " + accountName + " in domain " + domainId);
}
}
} else {
domainId = ((account == null) ? DomainVO.ROOT_DOMAIN : account.getDomainId());
}
} else {
accountId = account.getId();
}
Object[] accountIds = (Object[]) c.getCriteria(Criteria.ACCOUNTID);
Object type = c.getCriteria(Criteria.VTYPE);
Long vmInstanceId = (Long) c.getCriteria(Criteria.INSTANCEID);
Object zone = c.getCriteria(Criteria.DATACENTERID);
Object pod = c.getCriteria(Criteria.PODID);
Object domainId = c.getCriteria(Criteria.DOMAINID);
Object id = c.getCriteria(Criteria.ID);
Object keyword = c.getCriteria(Criteria.KEYWORD);
Object name = c.getCriteria(Criteria.NAME);
Filter searchFilter = new Filter(VolumeVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal());
Object id = cmd.getId();
Long vmInstanceId = cmd.getVirtualMachineId();
Object name = cmd.getVolumeName();
Object keyword = cmd.getKeyword();
Object type = null;
Object zone = null;
Object pod = null;
//Object host = null; TODO
if (isAdmin) {
type = cmd.getType();
zone = cmd.getZoneId();
pod = cmd.getPodId();
// host = cmd.getHostId(); TODO
} else {
domainId = null;
}
// hack for now, this should be done better but due to needing a join I opted to
// do this quickly and worry about making it pretty later
@ -5569,7 +5680,7 @@ public class ManagementServerImpl implements ManagementServer {
// Only return volumes that are not destroyed
sb.and("destroyed", sb.entity().getDestroyed(), SearchCriteria.Op.EQ);
if ((accountIds == null) && (domainId != null)) {
if ((accountId == null) && (domainId != null)) {
// if accountId isn't specified, we can do a domain match for the admin case
SearchBuilder<DomainVO> domainSearch = _domainDao.createSearchBuilder();
domainSearch.and("path", domainSearch.entity().getPath(), SearchCriteria.Op.LIKE);
@ -5595,12 +5706,8 @@ public class ManagementServerImpl implements ManagementServer {
sc.setParameters("id", id);
}
if (accountIds != null) {
if ((accountIds.length == 1) && (accountIds[0] != null)) {
sc.setParameters("accountIdEQ", accountIds[0]);
} else {
sc.setParameters("accountIdIN", accountIds);
}
if (accountId != null) {
sc.setParameters("accountIdEQ", accountId);
} else if (domainId != null) {
DomainVO domain = _domainDao.findById((Long)domainId);
sc.setJoinParameters("domainSearch", "path", domain.getPath() + "%");
@ -6919,10 +7026,56 @@ public class ManagementServerImpl implements ManagementServer {
}
@Override
public List<String> listTemplatePermissions(long templateId) {
List<String> accountNames = new ArrayList<String>();
List<LaunchPermissionVO> permissions = _launchPermissionDao.findByTemplate(templateId);
public List<String> listTemplatePermissions(ListTemplateOrIsoPermissionsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
Account account = (Account)UserContext.current().getAccountObject();
Long domainId = cmd.getDomainId();
String acctName = cmd.getAccountName();
Long id = cmd.getId();
Long accountId = null;
if ((account == null) || account.getType() == Account.ACCOUNT_TYPE_ADMIN) {
// validate domainId before proceeding
if (domainId != null) {
if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), domainId)) {
throw new PermissionDeniedException("Invalid domain id (" + domainId + ") given, unable to list " + cmd.getMediaType() + " permissions.");
}
if (acctName != null) {
Account userAccount = _accountDao.findActiveAccount(acctName, domainId);
if (userAccount != null) {
accountId = userAccount.getId();
} else {
throw new PermissionDeniedException("Unable to find account " + acctName + " in domain " + domainId);
}
}
}
} else {
accountId = account.getId();
}
VMTemplateVO template = _templateDao.findById(id.longValue());
if (template == null || !templateIsCorrectType(template)) {
throw new InvalidParameterValueException("unable to find " + cmd.getMediaType() + " with id " + id);
}
if (accountId != null && !template.isPublicTemplate()) {
if (account.getType() == Account.ACCOUNT_TYPE_NORMAL && template.getAccountId() != accountId) {
throw new PermissionDeniedException("unable to list permissions for " + cmd.getMediaType() + " with id " + id);
} else if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
DomainVO accountDomain = _domainDao.findById(account.getDomainId());
Account templateAccount = _accountDao.findById(template.getAccountId());
DomainVO templateDomain = _domainDao.findById(templateAccount.getDomainId());
if (!templateDomain.getPath().contains(accountDomain.getPath())) {
throw new PermissionDeniedException("unable to list permissions for " + cmd.getMediaType() + " with id " + id);
}
}
}
if (id == Long.valueOf(1)) {
throw new PermissionDeniedException("unable to list permissions for " + cmd.getMediaType() + " with id " + id);
}
List<String> accountNames = new ArrayList<String>();
List<LaunchPermissionVO> permissions = _launchPermissionDao.findByTemplate(id);
if ((permissions != null) && !permissions.isEmpty()) {
for (LaunchPermissionVO permission : permissions) {
Account acct = _accountDao.findById(permission.getAccountId());
@ -7903,20 +8056,20 @@ public class ManagementServerImpl implements ManagementServer {
public List<ClusterVO> listClusterByPodId(long podId) {
return _clusterDao.listByPodId(podId);
}
// @Override
// public ClusterVO createCluster(long dcId, long podId, String name) {
// ClusterVO cluster = new ClusterVO(dcId, podId, name);
// try {
// cluster = _clusterDao.persist(cluster);
// } catch (Exception e) {
// cluster = _clusterDao.findBy(name, podId);
// if (cluster == null) {
// throw new CloudRuntimeException("Unable to create cluster " + name + " in pod " + podId + " and data center " + dcId, e);
// }
// }
// return cluster;
// }
@Override
public List<? extends StoragePoolVO> searchForStoragePools(ListStoragePoolsCmd cmd) {
Criteria c = new Criteria("id", Boolean.TRUE, cmd.getStartIndex(), cmd.getPageSizeVal());
c.addCriteria(Criteria.NAME, cmd.getStoragePoolName());
c.addCriteria(Criteria.CLUSTERID, cmd.getClusterId());
c.addCriteria(Criteria.ADDRESS, cmd.getIpAddress());
c.addCriteria(Criteria.KEYWORD, cmd.getKeyword());
c.addCriteria(Criteria.PATH, cmd.getPath());
c.addCriteria(Criteria.PODID, cmd.getPodId());
c.addCriteria(Criteria.DATACENTERID, cmd.getZoneId());
return searchForStoragePools(c);
}
@Override
public List<? extends StoragePoolVO> searchForStoragePools(Criteria c) {
@ -8204,7 +8357,34 @@ public class ManagementServerImpl implements ManagementServer {
return _secStorageVmDao.search(sc, searchFilter);
}
@Override @SuppressWarnings({"unchecked", "rawtypes"})
public List<? extends VMInstanceVO> searchForSystemVm(ListSystemVMsCmd cmd) {
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.DATACENTERID, cmd.getZoneId());
c.addCriteria(Criteria.PODID, cmd.getPodId());
c.addCriteria(Criteria.HOSTID, cmd.getHostId());
c.addCriteria(Criteria.NAME, cmd.getSystemVmName());
c.addCriteria(Criteria.STATE, cmd.getState());
String type = cmd.getSystemVmType();
List systemVMs = new ArrayList();
if (type == null) { //search for all vm types
systemVMs.addAll(searchForConsoleProxy(c));
systemVMs.addAll(searchForSecondaryStorageVm(c));
} else if((type != null) && (type.equalsIgnoreCase("secondarystoragevm"))) { // search for ssvm
systemVMs.addAll(searchForSecondaryStorageVm(c));
} else if((type != null) && (type.equalsIgnoreCase("consoleproxy"))) { // search for consoleproxy
systemVMs.addAll(searchForConsoleProxy(c));
}
return (List<? extends VMInstanceVO>)systemVMs;
}
@Override
public VMInstanceVO findSystemVMById(long instanceId) {
VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(instanceId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm);