From acb23b6158dc97d17bcb5dfda684fb778cdc0ba1 Mon Sep 17 00:00:00 2001 From: kishan Date: Thu, 26 Aug 2010 14:53:03 +0530 Subject: [PATCH] bug 5904,5474: added listCapabilities API --- client/tomcatconf/commands.properties.in | 3 +- .../com/cloud/server/ManagementServer.java | 1 + .../api/commands/ListCapabilitiesCmd.java | 58 +++++++++++++++++++ .../cloud/server/ManagementServerImpl.java | 20 +++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 server/src/com/cloud/api/commands/ListCapabilitiesCmd.java diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index fb62d18615e..47f934cabd4 100644 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -139,6 +139,7 @@ listSystemVms=com.cloud.api.commands.ListSystemVMsCmd;1 updateConfiguration=com.cloud.api.commands.UpdateCfgCmd;1 listConfigurations=com.cloud.api.commands.ListCfgsByCmd;1 addConfig=com.cloud.api.commands.AddConfigCmd;15 +listCapabilities=com.cloud.api.commands.ListCapabilitiesCmd;15 #### pod commands createPod=com.cloud.api.commands.CreatePodCmd;1 @@ -207,4 +208,4 @@ listNetworkGroups=com.cloud.api.commands.ListNetworkGroupsCmd;11 registerPreallocatedLun=com.cloud.server.api.commands.RegisterPreallocatedLunCmd;1 deletePreallocatedLun=com.cloud.server.api.commands.DeletePreallocatedLunCmd;1 -listPreallocatedLuns=com.cloud.api.commands.ListPreallocatedLunsCmd;1 \ No newline at end of file +listPreallocatedLuns=com.cloud.api.commands.ListPreallocatedLunsCmd;1 diff --git a/core/src/com/cloud/server/ManagementServer.java b/core/src/com/cloud/server/ManagementServer.java index 840d9343ca6..85a3115ec07 100644 --- a/core/src/com/cloud/server/ManagementServer.java +++ b/core/src/com/cloud/server/ManagementServer.java @@ -2187,4 +2187,5 @@ public interface ManagementServer { boolean checkIfMaintenable(long hostId); + Map listCapabilities(); } diff --git a/server/src/com/cloud/api/commands/ListCapabilitiesCmd.java b/server/src/com/cloud/api/commands/ListCapabilitiesCmd.java new file mode 100644 index 00000000000..2532f3673d5 --- /dev/null +++ b/server/src/com/cloud/api/commands/ListCapabilitiesCmd.java @@ -0,0 +1,58 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.cloud.api.commands; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; + +import com.cloud.api.BaseCmd; +import com.cloud.utils.Pair; + +public class ListCapabilitiesCmd extends BaseCmd { + public static final Logger s_logger = Logger.getLogger(ListCapabilitiesCmd.class.getName()); + + private static final String s_name = "listcapabilitiesresponse"; + private static final List> s_properties = new ArrayList>(); + + public String getName() { + return s_name; + } + public List> getProperties() { + return s_properties; + } + + @Override + public List> execute(Map params) { + + Map capabilities = null; + capabilities = getManagementServer().listCapabilities(); + + Iterator iterator = capabilities.keySet().iterator(); + List> capabilityPair = new ArrayList>(); + while (iterator.hasNext()) { + String capability = iterator.next(); + capabilityPair.add(new Pair(capability, capabilities.get(capability))); + } + return capabilityPair; + } +} diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 290bd49f0b3..f83a482ac78 100644 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -8594,6 +8594,26 @@ public class ManagementServerImpl implements ManagementServer { return false; } + @Override + public Map listCapabilities() { + Map capabilities = new HashMap(); + + String networkGroupsEnabled = _configs.get("direct.attach.network.groups.enabled"); + if(networkGroupsEnabled == null) + networkGroupsEnabled = "false"; + + capabilities.put("networkGroupsEnabled", networkGroupsEnabled); + + final Class c = this.getClass(); + String fullVersion = c.getPackage().getImplementationVersion(); + String version = "unknown"; + if(fullVersion.length() > 0){ + version = fullVersion.substring(0,fullVersion.lastIndexOf(".")); + } + capabilities.put("cloudStackVersion", version); + return capabilities; + } + }