mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Api refactoring for following commands: updateAccount, updateTemplate/Iso, UpdateDomain, EnableUser/Account, DeletePod
This commit is contained in:
parent
b4adabe4a9
commit
183eb4e4a3
@ -21,16 +21,13 @@ package com.cloud.api.commands;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.BaseCmd.Manager;
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.BaseCmd.Manager;
|
|
||||||
import com.cloud.configuration.ConfigurationVO;
|
|
||||||
import com.cloud.storage.DiskOfferingVO;
|
|
||||||
|
|
||||||
@Implementation(method="addConfig", manager=Manager.ConfigManager)
|
@Implementation(method="addConfig", manager=Manager.ConfigManager)
|
||||||
public class AddConfigCmd extends BaseCmd {
|
public class AddConfigCmd extends BaseCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(AddConfigCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(AddConfigCmd.class.getName());
|
||||||
|
|
||||||
private static final String s_name = "addconfigresponse";
|
private static final String s_name = "addconfigresponse";
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
|
|||||||
@ -21,14 +21,13 @@ package com.cloud.api.commands;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.BaseCmd.Manager;
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.BaseCmd.Manager;
|
|
||||||
|
|
||||||
@Implementation(method="deleteDiskOffering", manager=Manager.ConfigManager)
|
@Implementation(method="deleteDiskOffering", manager=Manager.ConfigManager)
|
||||||
public class DeleteDiskOfferingCmd extends BaseCmd {
|
public class DeleteDiskOfferingCmd extends BaseCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(DeleteDiskOfferingCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(DeleteDiskOfferingCmd.class.getName());
|
||||||
|
|
||||||
private static final String s_name = "deletediskofferingresponse";
|
private static final String s_name = "deletediskofferingresponse";
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
|
|||||||
@ -18,29 +18,18 @@
|
|||||||
|
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.BaseCmd.Manager;
|
||||||
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.ServerApiException;
|
|
||||||
import com.cloud.dc.HostPodVO;
|
|
||||||
import com.cloud.user.User;
|
|
||||||
import com.cloud.utils.Pair;
|
|
||||||
|
|
||||||
|
@Implementation(method="deletePod", manager=Manager.ConfigManager)
|
||||||
public class DeletePodCmd extends BaseCmd {
|
public class DeletePodCmd extends BaseCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(DeletePodCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(DeletePodCmd.class.getName());
|
||||||
|
|
||||||
private static final String s_name = "deletepodresponse";
|
private static final String s_name = "deletepodresponse";
|
||||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.USER_ID, Boolean.FALSE));
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
//////////////// API parameters /////////////////////
|
||||||
@ -58,7 +47,6 @@ public class DeletePodCmd extends BaseCmd {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
/////////////// API Implementation///////////////////
|
/////////////// API Implementation///////////////////
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
@ -66,35 +54,32 @@ public class DeletePodCmd extends BaseCmd {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return s_name;
|
return s_name;
|
||||||
}
|
}
|
||||||
public List<Pair<Enum, Boolean>> getProperties() {
|
|
||||||
return s_properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||||
Long podId = (Long) params.get(BaseCmd.Properties.ID.getName());
|
// Long podId = (Long) params.get(BaseCmd.Properties.ID.getName());
|
||||||
Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
// Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
||||||
|
//
|
||||||
if (userId == null) {
|
// if (userId == null) {
|
||||||
userId = Long.valueOf(User.UID_SYSTEM);
|
// userId = Long.valueOf(User.UID_SYSTEM);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//verify parameters
|
// //verify parameters
|
||||||
HostPodVO pod = getManagementServer().findHostPodById(podId);
|
// HostPodVO pod = getManagementServer().findHostPodById(podId);
|
||||||
if (pod == null) {
|
// if (pod == null) {
|
||||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to find pod by id " + podId);
|
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to find pod by id " + podId);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
try {
|
// try {
|
||||||
getManagementServer().deletePod(userId, podId);
|
// getManagementServer().deletePod(userId, podId);
|
||||||
} catch (Exception ex) {
|
// } catch (Exception ex) {
|
||||||
s_logger.error("Exception deleting pod", ex);
|
// s_logger.error("Exception deleting pod", ex);
|
||||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
|
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), "true"));
|
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), "true"));
|
||||||
|
//
|
||||||
return returnValues;
|
// return returnValues;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,28 +18,21 @@
|
|||||||
|
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.BaseCmd.Manager;
|
||||||
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.ServerApiException;
|
|
||||||
import com.cloud.user.Account;
|
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
|
|
||||||
|
|
||||||
|
@Implementation(method="disableAccount", manager=Manager.ManagementServer)
|
||||||
public class DisableAccountCmd extends BaseCmd {
|
public class DisableAccountCmd extends BaseCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(DisableAccountCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(DisableAccountCmd.class.getName());
|
||||||
private static final String s_name = "disableaccountresponse";
|
private static final String s_name = "disableaccountresponse";
|
||||||
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.TRUE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DOMAIN_ID, Boolean.TRUE));
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
//////////////// API parameters /////////////////////
|
||||||
@ -79,36 +72,36 @@ public class DisableAccountCmd extends BaseCmd {
|
|||||||
return s_properties;
|
return s_properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||||
Account adminAccount = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
// Account adminAccount = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||||
Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName());
|
// Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName());
|
||||||
String accountName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName());
|
// String accountName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName());
|
||||||
|
//
|
||||||
if ((adminAccount != null) && !getManagementServer().isChildDomain(adminAccount.getDomainId(), domainId)) {
|
// if ((adminAccount != null) && !getManagementServer().isChildDomain(adminAccount.getDomainId(), domainId)) {
|
||||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Failed to disable account " + accountName + " in domain " + domainId + ", permission denied.");
|
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Failed to disable account " + accountName + " in domain " + domainId + ", permission denied.");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Account account = getManagementServer().findActiveAccount(accountName, domainId);
|
// Account account = getManagementServer().findActiveAccount(accountName, domainId);
|
||||||
if (account == null) {
|
// if (account == null) {
|
||||||
throw new ServerApiException (BaseCmd.PARAM_ERROR, "Unable to find active account with name " + accountName + " in domain " + domainId);
|
// throw new ServerApiException (BaseCmd.PARAM_ERROR, "Unable to find active account with name " + accountName + " in domain " + domainId);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// don't allow modify system account
|
// // don't allow modify system account
|
||||||
if (account.getId().longValue() == Account.ACCOUNT_ID_SYSTEM) {
|
// if (account.getId().longValue() == Account.ACCOUNT_ID_SYSTEM) {
|
||||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "can not disable system account");
|
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "can not disable system account");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
long jobId = getManagementServer().disableAccountAsync(account.getId().longValue());
|
// long jobId = getManagementServer().disableAccountAsync(account.getId().longValue());
|
||||||
if (jobId == 0) {
|
// if (jobId == 0) {
|
||||||
s_logger.warn("Unable to schedule async-job for DisableAccount comamnd");
|
// s_logger.warn("Unable to schedule async-job for DisableAccount comamnd");
|
||||||
} else {
|
// } else {
|
||||||
if (s_logger.isDebugEnabled())
|
// if (s_logger.isDebugEnabled())
|
||||||
s_logger.debug("DisableAccount command has been accepted, job id: " + jobId);
|
// s_logger.debug("DisableAccount command has been accepted, job id: " + jobId);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_ID.getName(), Long.valueOf(jobId)));
|
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_ID.getName(), Long.valueOf(jobId)));
|
||||||
return returnValues;
|
// return returnValues;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,26 +18,17 @@
|
|||||||
|
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.BaseCmd.Manager;
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.ServerApiException;
|
|
||||||
import com.cloud.api.BaseCmd.Manager;
|
|
||||||
import com.cloud.user.Account;
|
|
||||||
import com.cloud.utils.Pair;
|
|
||||||
|
|
||||||
@Implementation(method="enableAccount", manager=Manager.ManagementServer)
|
@Implementation(method="enableAccount", manager=Manager.ManagementServer)
|
||||||
public class EnableAccountCmd extends BaseCmd {
|
public class EnableAccountCmd extends BaseCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(EnableAccountCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(EnableAccountCmd.class.getName());
|
||||||
|
|
||||||
private static final String s_name = "enableaccountresponse";
|
private static final String s_name = "enableaccountresponse";
|
||||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
//////////////// API parameters /////////////////////
|
||||||
|
|||||||
@ -18,29 +18,20 @@
|
|||||||
|
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.BaseCmd.Manager;
|
||||||
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.ServerApiException;
|
|
||||||
import com.cloud.user.Account;
|
|
||||||
import com.cloud.user.User;
|
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
|
|
||||||
|
@Implementation(method="enableUser", manager=Manager.ManagementServer)
|
||||||
public class EnableUserCmd extends BaseCmd {
|
public class EnableUserCmd extends BaseCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(EnableUserCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(EnableUserCmd.class.getName());
|
||||||
|
|
||||||
private static final String s_name = "enableuserresponse";
|
private static final String s_name = "enableuserresponse";
|
||||||
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.ID, Boolean.TRUE));
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
//////////////// API parameters /////////////////////
|
||||||
@ -58,7 +49,6 @@ public class EnableUserCmd extends BaseCmd {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
/////////////// API Implementation///////////////////
|
/////////////// API Implementation///////////////////
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
@ -73,39 +63,39 @@ public class EnableUserCmd extends BaseCmd {
|
|||||||
return s_properties;
|
return s_properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||||
Account adminAccount = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
// Account adminAccount = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||||
Long id = (Long)params.get(BaseCmd.Properties.ID.getName());
|
// Long id = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||||
|
//
|
||||||
// Check if user with id exists in the system
|
// // Check if user with id exists in the system
|
||||||
User user = getManagementServer().findUserById(id);
|
// User user = getManagementServer().findUserById(id);
|
||||||
if (user == null) {
|
// if (user == null) {
|
||||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to find user by id");
|
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to find user by id");
|
||||||
} else if (user.getRemoved() != null) {
|
// } else if (user.getRemoved() != null) {
|
||||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to find user by id");
|
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to find user by id");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// If the user is a System user, return an error. We do not allow this
|
// // If the user is a System user, return an error. We do not allow this
|
||||||
Account account = getManagementServer().findAccountById(user.getAccountId());
|
// Account account = getManagementServer().findAccountById(user.getAccountId());
|
||||||
if ((account != null) && (account.getId() == Account.ACCOUNT_ID_SYSTEM)) {
|
// if ((account != null) && (account.getId() == Account.ACCOUNT_ID_SYSTEM)) {
|
||||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "user id : " + id + " is a system user, enabling is not allowed");
|
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "user id : " + id + " is a system user, enabling is not allowed");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if ((adminAccount != null) && !getManagementServer().isChildDomain(adminAccount.getDomainId(), account.getDomainId())) {
|
// if ((adminAccount != null) && !getManagementServer().isChildDomain(adminAccount.getDomainId(), account.getDomainId())) {
|
||||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Failed to enable user " + id + ", permission denied.");
|
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Failed to enable user " + id + ", permission denied.");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
boolean success = true;
|
// boolean success = true;
|
||||||
try {
|
// try {
|
||||||
success = getManagementServer().enableUser(id.longValue());
|
// success = getManagementServer().enableUser(id.longValue());
|
||||||
} catch (Exception ex) {
|
// } catch (Exception ex) {
|
||||||
s_logger.error("error enabling user with id: " + id, ex);
|
// s_logger.error("error enabling user with id: " + id, ex);
|
||||||
success = false;
|
// success = false;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), Boolean.valueOf(success).toString()));
|
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), Boolean.valueOf(success).toString()));
|
||||||
return returnValues;
|
// return returnValues;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,37 +18,36 @@
|
|||||||
|
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.BaseCmd.Manager;
|
||||||
|
import com.cloud.api.Implementation;
|
||||||
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
|
|
||||||
|
@Implementation(method="getCloudIdentifierResponse", manager=Manager.ManagementServer)
|
||||||
public class GetCloudIdentifierCmd extends BaseCmd {
|
public class GetCloudIdentifierCmd extends BaseCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(GetCloudIdentifierCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(GetCloudIdentifierCmd.class.getName());
|
||||||
|
|
||||||
private static final String s_name = "getcloudidentifierresponse";
|
private static final String s_name = "getcloudidentifierresponse";
|
||||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.USER_ID, Boolean.TRUE));
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
//////////////// API parameters /////////////////////
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
|
|
||||||
// none -- a no argument API command
|
@Parameter(name="userid", type=CommandType.LONG, required=true)
|
||||||
|
private Long userid;
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
/////////////////// Accessors ///////////////////////
|
/////////////////// Accessors ///////////////////////
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
|
|
||||||
// none -- a no argument API command
|
public Long getUserId() {
|
||||||
|
return userid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
@ -58,22 +57,19 @@ public class GetCloudIdentifierCmd extends BaseCmd {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return s_name;
|
return s_name;
|
||||||
}
|
}
|
||||||
public List<Pair<Enum, Boolean>> getProperties() {
|
|
||||||
return s_properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||||
Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
// Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
||||||
|
//
|
||||||
ArrayList<String> signedResponse = getManagementServer().getCloudIdentifierResponse(userId);
|
// ArrayList<String> signedResponse = getManagementServer().getCloudIdentifierResponse(userId);
|
||||||
|
//
|
||||||
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||||
|
//
|
||||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.CLOUD_IDENTIFIER.getName(),signedResponse.get(0)));
|
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.CLOUD_IDENTIFIER.getName(),signedResponse.get(0)));
|
||||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SIGNATURE.getName(),signedResponse.get(1)));
|
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SIGNATURE.getName(),signedResponse.get(1)));
|
||||||
return returnValues;
|
// return returnValues;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -18,26 +18,18 @@
|
|||||||
|
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.BaseCmd.Manager;
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.ServerApiException;
|
|
||||||
import com.cloud.api.BaseCmd.Manager;
|
|
||||||
import com.cloud.user.Account;
|
|
||||||
import com.cloud.utils.Pair;
|
|
||||||
|
|
||||||
@Implementation(method="updateAccount", manager=Manager.ManagementServer)
|
@Implementation(method="updateAccount", manager=Manager.ManagementServer)
|
||||||
public class UpdateAccountCmd extends BaseCmd{
|
public class UpdateAccountCmd extends BaseCmd{
|
||||||
public static final Logger s_logger = Logger.getLogger(UpdateAccountCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(UpdateAccountCmd.class.getName());
|
||||||
private static final String s_name = "updateaccountresponse";
|
private static final String s_name = "updateaccountresponse";
|
||||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
//////////////// API parameters /////////////////////
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
|
|||||||
@ -18,24 +18,16 @@
|
|||||||
|
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.BaseCmd.Manager;
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.ServerApiException;
|
|
||||||
import com.cloud.api.BaseCmd.Manager;
|
|
||||||
import com.cloud.user.User;
|
|
||||||
import com.cloud.utils.Pair;
|
|
||||||
|
|
||||||
@Implementation(method="updateConfiguration", manager=Manager.ConfigManager)
|
@Implementation(method="updateConfiguration", manager=Manager.ConfigManager)
|
||||||
public class UpdateCfgCmd extends BaseCmd {
|
public class UpdateCfgCmd extends BaseCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(UpdateCfgCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(UpdateCfgCmd.class.getName());
|
||||||
|
|
||||||
private static final String s_name = "updateconfigurationresponse";
|
private static final String s_name = "updateconfigurationresponse";
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
|
|||||||
@ -17,16 +17,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.BaseCmd.Manager;
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.ServerApiException;
|
import com.cloud.api.ServerApiException;
|
||||||
import com.cloud.api.BaseCmd.Manager;
|
|
||||||
import com.cloud.serializer.Param;
|
import com.cloud.serializer.Param;
|
||||||
import com.cloud.serializer.SerializerHelper;
|
import com.cloud.serializer.SerializerHelper;
|
||||||
import com.cloud.storage.DiskOfferingVO;
|
import com.cloud.storage.DiskOfferingVO;
|
||||||
|
|||||||
@ -18,29 +18,17 @@
|
|||||||
|
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.BaseCmd.Manager;
|
||||||
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.ServerApiException;
|
|
||||||
import com.cloud.domain.DomainVO;
|
@Implementation(method="updateDomain", manager=Manager.ManagementServer)
|
||||||
import com.cloud.user.Account;
|
|
||||||
import com.cloud.utils.Pair;
|
|
||||||
|
|
||||||
public class UpdateDomainCmd extends BaseCmd{
|
public class UpdateDomainCmd extends BaseCmd{
|
||||||
public static final Logger s_logger = Logger.getLogger(UpdateDomainCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(UpdateDomainCmd.class.getName());
|
||||||
private static final String s_name = "updatedomainresponse";
|
private static final String s_name = "updatedomainresponse";
|
||||||
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.ID, Boolean.TRUE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.NAME, Boolean.FALSE));
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
//////////////// API parameters /////////////////////
|
||||||
@ -72,53 +60,49 @@ public class UpdateDomainCmd extends BaseCmd{
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return s_name;
|
return s_name;
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public List<Pair<Enum, Boolean>> getProperties() {
|
|
||||||
return s_properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||||
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
// Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||||
Long domainId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
// Long domainId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||||
String newName = (String)params.get(BaseCmd.Properties.NAME.getName());
|
// String newName = (String)params.get(BaseCmd.Properties.NAME.getName());
|
||||||
Boolean editDomainResult = false;
|
// Boolean editDomainResult = false;
|
||||||
|
//
|
||||||
//check if domain exists in the system
|
// //check if domain exists in the system
|
||||||
DomainVO domain = getManagementServer().findDomainIdById(domainId);
|
// DomainVO domain = getManagementServer().findDomainIdById(domainId);
|
||||||
if (domain == null) {
|
// if (domain == null) {
|
||||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find domain " + domainId);
|
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find domain " + domainId);
|
||||||
} else if (domain.getParent() == null) {
|
// } else if (domain.getParent() == null) {
|
||||||
//check if domain is ROOT domain - and deny to edit it
|
// //check if domain is ROOT domain - and deny to edit it
|
||||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "ROOT domain can not be edited");
|
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "ROOT domain can not be edited");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// check permissions
|
// // check permissions
|
||||||
if ((account != null) && !getManagementServer().isChildDomain(account.getDomainId(), domain.getId())) {
|
// if ((account != null) && !getManagementServer().isChildDomain(account.getDomainId(), domain.getId())) {
|
||||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to update domain " + domainId + ", permission denied");
|
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to update domain " + domainId + ", permission denied");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (newName == null) {
|
// if (newName == null) {
|
||||||
newName = domain.getName();
|
// newName = domain.getName();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
try {
|
// try {
|
||||||
getManagementServer().updateDomain(domainId, newName);
|
// getManagementServer().updateDomain(domainId, newName);
|
||||||
domain = getManagementServer().findDomainIdById(domainId);
|
// domain = getManagementServer().findDomainIdById(domainId);
|
||||||
if (domain.getName().equals(newName)) {
|
// if (domain.getName().equals(newName)) {
|
||||||
editDomainResult = true;
|
// editDomainResult = true;
|
||||||
}
|
// }
|
||||||
} catch (Exception ex) {
|
// } catch (Exception ex) {
|
||||||
s_logger.error("Exception editing domain", ex);
|
// s_logger.error("Exception editing domain", ex);
|
||||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update domain " + domainId + ": internal error.");
|
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update domain " + domainId + ": internal error.");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||||
if (editDomainResult == true) {
|
// if (editDomainResult == true) {
|
||||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), new Boolean(true)));
|
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), new Boolean(true)));
|
||||||
} else {
|
// } else {
|
||||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update domain " + domainId);
|
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update domain " + domainId);
|
||||||
}
|
// }
|
||||||
return returnValues;
|
// return returnValues;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,35 +18,17 @@
|
|||||||
|
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.BaseCmd.Manager;
|
||||||
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.ServerApiException;
|
|
||||||
import com.cloud.storage.Storage;
|
@Implementation(method="updateTemplate", manager=Manager.ManagementServer)
|
||||||
import com.cloud.storage.VMTemplateVO;
|
|
||||||
import com.cloud.user.Account;
|
|
||||||
import com.cloud.utils.Pair;
|
|
||||||
|
|
||||||
public class UpdateIsoCmd extends BaseCmd {
|
public class UpdateIsoCmd extends BaseCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(UpdateIsoCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(UpdateIsoCmd.class.getName());
|
||||||
|
|
||||||
private static final String s_name = "updateisoresponse";
|
private static final String s_name = "updateisoresponse";
|
||||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.BOOTABLE, Boolean.FALSE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DISPLAY_TEXT, Boolean.FALSE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.NAME, Boolean.FALSE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.OS_TYPE_ID, Boolean.FALSE));
|
|
||||||
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
//////////////// API parameters /////////////////////
|
||||||
@ -99,63 +81,59 @@ public class UpdateIsoCmd extends BaseCmd {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return s_name;
|
return s_name;
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public List<Pair<Enum, Boolean>> getProperties() {
|
|
||||||
return s_properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||||
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
// Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||||
String displayText = (String)params.get(BaseCmd.Properties.DISPLAY_TEXT.getName());
|
// String displayText = (String)params.get(BaseCmd.Properties.DISPLAY_TEXT.getName());
|
||||||
String name = (String)params.get(BaseCmd.Properties.NAME.getName());
|
// String name = (String)params.get(BaseCmd.Properties.NAME.getName());
|
||||||
Long isoId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
// Long isoId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||||
Long guestOSId = (Long) params.get(BaseCmd.Properties.OS_TYPE_ID.getName());
|
// Long guestOSId = (Long) params.get(BaseCmd.Properties.OS_TYPE_ID.getName());
|
||||||
Boolean bootable = (Boolean) params.get(BaseCmd.Properties.BOOTABLE.getName());
|
// Boolean bootable = (Boolean) params.get(BaseCmd.Properties.BOOTABLE.getName());
|
||||||
|
//
|
||||||
VMTemplateVO iso = getManagementServer().findTemplateById(isoId.longValue());
|
// VMTemplateVO iso = getManagementServer().findTemplateById(isoId.longValue());
|
||||||
if ((iso == null) || iso.getFormat() != Storage.ImageFormat.ISO) {
|
// if ((iso == null) || iso.getFormat() != Storage.ImageFormat.ISO) {
|
||||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to find ISO with id " + isoId);
|
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to find ISO with id " + isoId);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// do a permission check
|
// // do a permission check
|
||||||
if (account != null) {
|
// if (account != null) {
|
||||||
Long isoOwner = iso.getAccountId();
|
// Long isoOwner = iso.getAccountId();
|
||||||
if (!isAdmin(account.getType())) {
|
// if (!isAdmin(account.getType())) {
|
||||||
if ((isoOwner == null) || (account.getId().longValue() != isoOwner.longValue())) {
|
// if ((isoOwner == null) || (account.getId().longValue() != isoOwner.longValue())) {
|
||||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to modify ISO with id " + isoId);
|
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to modify ISO with id " + isoId);
|
||||||
}
|
// }
|
||||||
} else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
|
// } else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
|
||||||
Long isoOwnerDomainId = getManagementServer().findDomainIdByAccountId(isoOwner);
|
// Long isoOwnerDomainId = getManagementServer().findDomainIdByAccountId(isoOwner);
|
||||||
if (!getManagementServer().isChildDomain(account.getDomainId(), isoOwnerDomainId)) {
|
// if (!getManagementServer().isChildDomain(account.getDomainId(), isoOwnerDomainId)) {
|
||||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to modify ISO with id " + isoId);
|
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to modify ISO with id " + isoId);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// do the update
|
// // do the update
|
||||||
boolean success = false;
|
// boolean success = false;
|
||||||
try {
|
// try {
|
||||||
success = getManagementServer().updateTemplate(isoId, name, displayText, null, guestOSId, null, bootable);
|
// success = getManagementServer().updateTemplate(isoId, name, displayText, null, guestOSId, null, bootable);
|
||||||
} catch (Exception ex) {
|
// } catch (Exception ex) {
|
||||||
s_logger.error("Exception editing ISO", ex);
|
// s_logger.error("Exception editing ISO", ex);
|
||||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update ISO " + isoId + ": " + ex.getMessage());
|
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update ISO " + isoId + ": " + ex.getMessage());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
VMTemplateVO updatedIso = getManagementServer().findTemplateById(isoId);
|
// VMTemplateVO updatedIso = getManagementServer().findTemplateById(isoId);
|
||||||
if (success) {
|
// if (success) {
|
||||||
List<Pair<String, Object>> isoData = new ArrayList<Pair<String, Object>>();
|
// List<Pair<String, Object>> isoData = new ArrayList<Pair<String, Object>>();
|
||||||
isoData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), updatedIso.getId().toString()));
|
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), updatedIso.getId().toString()));
|
||||||
isoData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), updatedIso.getName()));
|
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), updatedIso.getName()));
|
||||||
isoData.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_TEXT.getName(), updatedIso.getDisplayText()));
|
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_TEXT.getName(), updatedIso.getDisplayText()));
|
||||||
isoData.add(new Pair<String, Object>(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(updatedIso.isPublicTemplate()).toString()));
|
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(updatedIso.isPublicTemplate()).toString()));
|
||||||
isoData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(updatedIso.getCreated())));
|
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(updatedIso.getCreated())));
|
||||||
isoData.add(new Pair<String, Object>(BaseCmd.Properties.FORMAT.getName(), updatedIso.getFormat()));
|
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.FORMAT.getName(), updatedIso.getFormat()));
|
||||||
isoData.add(new Pair<String, Object>(BaseCmd.Properties.OS_TYPE_ID.getName(), updatedIso.getGuestOSId()));
|
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.OS_TYPE_ID.getName(), updatedIso.getGuestOSId()));
|
||||||
isoData.add(new Pair<String, Object>(BaseCmd.Properties.BOOTABLE.getName(), updatedIso.isBootable()));
|
// isoData.add(new Pair<String, Object>(BaseCmd.Properties.BOOTABLE.getName(), updatedIso.isBootable()));
|
||||||
return isoData;
|
// return isoData;
|
||||||
} else {
|
// } else {
|
||||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "internal error updating ISO");
|
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "internal error updating ISO");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,34 +18,17 @@
|
|||||||
|
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.BaseCmd.Manager;
|
||||||
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.ServerApiException;
|
|
||||||
import com.cloud.storage.VMTemplateVO;
|
@Implementation(method="updateTemplate", manager=Manager.ManagementServer)
|
||||||
import com.cloud.user.Account;
|
|
||||||
import com.cloud.utils.Pair;
|
|
||||||
|
|
||||||
public class UpdateTemplateCmd extends BaseCmd {
|
public class UpdateTemplateCmd extends BaseCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(UpdateTemplateCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(UpdateTemplateCmd.class.getName());
|
||||||
private static final String s_name = "updatetemplateresponse";
|
private static final String s_name = "updatetemplateresponse";
|
||||||
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.DISPLAY_TEXT, Boolean.FALSE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.FORMAT, Boolean.FALSE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.NAME, Boolean.FALSE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.OS_TYPE_ID, Boolean.FALSE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PASSWORD_ENABLED, Boolean.FALSE));
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
//////////////// API parameters /////////////////////
|
||||||
@ -96,6 +79,10 @@ public class UpdateTemplateCmd extends BaseCmd {
|
|||||||
public Boolean isPasswordEnabled() {
|
public Boolean isPasswordEnabled() {
|
||||||
return passwordEnabled;
|
return passwordEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean isBootable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
/////////////// API Implementation///////////////////
|
/////////////// API Implementation///////////////////
|
||||||
@ -105,67 +92,63 @@ public class UpdateTemplateCmd extends BaseCmd {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return s_name;
|
return s_name;
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public List<Pair<Enum, Boolean>> getProperties() {
|
|
||||||
return s_properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||||
Long templateId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
// Long templateId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||||
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
// Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||||
String name = (String)params.get(BaseCmd.Properties.NAME.getName());
|
// String name = (String)params.get(BaseCmd.Properties.NAME.getName());
|
||||||
String displayText = (String)params.get(BaseCmd.Properties.DISPLAY_TEXT.getName());
|
// String displayText = (String)params.get(BaseCmd.Properties.DISPLAY_TEXT.getName());
|
||||||
String format = (String)params.get(BaseCmd.Properties.FORMAT.getName());
|
// String format = (String)params.get(BaseCmd.Properties.FORMAT.getName());
|
||||||
Long guestOSId = (Long) params.get(BaseCmd.Properties.OS_TYPE_ID.getName());
|
// Long guestOSId = (Long) params.get(BaseCmd.Properties.OS_TYPE_ID.getName());
|
||||||
Boolean passwordEnabled = (Boolean)params.get(BaseCmd.Properties.PASSWORD_ENABLED.getName());
|
// Boolean passwordEnabled = (Boolean)params.get(BaseCmd.Properties.PASSWORD_ENABLED.getName());
|
||||||
|
//
|
||||||
VMTemplateVO template = getManagementServer().findTemplateById(templateId.longValue());
|
// VMTemplateVO template = getManagementServer().findTemplateById(templateId.longValue());
|
||||||
if (template == null) {
|
// if (template == null) {
|
||||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "unable to find template with id " + templateId);
|
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "unable to find template with id " + templateId);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (account != null) {
|
// if (account != null) {
|
||||||
if (!isAdmin(account.getType())) {
|
// if (!isAdmin(account.getType())) {
|
||||||
if (template.getAccountId() != account.getId()) {
|
// if (template.getAccountId() != account.getId()) {
|
||||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "unable to edit template with id " + templateId);
|
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "unable to edit template with id " + templateId);
|
||||||
}
|
// }
|
||||||
} else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
|
// } else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
|
||||||
Long templateOwnerDomainId = getManagementServer().findDomainIdByAccountId(template.getAccountId());
|
// Long templateOwnerDomainId = getManagementServer().findDomainIdByAccountId(template.getAccountId());
|
||||||
if (!getManagementServer().isChildDomain(account.getDomainId(), templateOwnerDomainId)) {
|
// if (!getManagementServer().isChildDomain(account.getDomainId(), templateOwnerDomainId)) {
|
||||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to modify template with id " + templateId);
|
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to modify template with id " + templateId);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (templateId == Long.valueOf(1)) {
|
// if (templateId == Long.valueOf(1)) {
|
||||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to update template with id " + templateId);
|
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to update template with id " + templateId);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
boolean success = false;
|
// boolean success = false;
|
||||||
try {
|
// try {
|
||||||
success = getManagementServer().updateTemplate(templateId, name, displayText, format, guestOSId, passwordEnabled, null);
|
// success = getManagementServer().updateTemplate(templateId, name, displayText, format, guestOSId, passwordEnabled, null);
|
||||||
} catch (Exception ex) {
|
// } catch (Exception ex) {
|
||||||
s_logger.error("Exception editing template", ex);
|
// s_logger.error("Exception editing template", ex);
|
||||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update template " + templateId + ": " + ex.getMessage());
|
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update template " + templateId + ": " + ex.getMessage());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
VMTemplateVO updatedTemplate = getManagementServer().findTemplateById(templateId);
|
// VMTemplateVO updatedTemplate = getManagementServer().findTemplateById(templateId);
|
||||||
if (success) {
|
// if (success) {
|
||||||
List<Pair<String, Object>> templateData = new ArrayList<Pair<String, Object>>();
|
// List<Pair<String, Object>> templateData = new ArrayList<Pair<String, Object>>();
|
||||||
templateData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), updatedTemplate.getId().toString()));
|
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), updatedTemplate.getId().toString()));
|
||||||
templateData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), updatedTemplate.getName()));
|
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), updatedTemplate.getName()));
|
||||||
templateData.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_TEXT.getName(), updatedTemplate.getDisplayText()));
|
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_TEXT.getName(), updatedTemplate.getDisplayText()));
|
||||||
templateData.add(new Pair<String, Object>(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(updatedTemplate.isPublicTemplate()).toString()));
|
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(updatedTemplate.isPublicTemplate()).toString()));
|
||||||
templateData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(updatedTemplate.getCreated())));
|
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(updatedTemplate.getCreated())));
|
||||||
templateData.add(new Pair<String, Object>(BaseCmd.Properties.FORMAT.getName(), updatedTemplate.getFormat()));
|
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.FORMAT.getName(), updatedTemplate.getFormat()));
|
||||||
templateData.add(new Pair<String, Object>(BaseCmd.Properties.OS_TYPE_ID.getName(), updatedTemplate.getGuestOSId()));
|
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.OS_TYPE_ID.getName(), updatedTemplate.getGuestOSId()));
|
||||||
templateData.add(new Pair<String, Object>(BaseCmd.Properties.PASSWORD_ENABLED.getName(), updatedTemplate.getEnablePassword()));
|
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.PASSWORD_ENABLED.getName(), updatedTemplate.getEnablePassword()));
|
||||||
templateData.add(new Pair<String, Object>(BaseCmd.Properties.CROSS_ZONES.getName(), Boolean.valueOf(updatedTemplate.isCrossZones()).toString()));
|
// templateData.add(new Pair<String, Object>(BaseCmd.Properties.CROSS_ZONES.getName(), Boolean.valueOf(updatedTemplate.isCrossZones()).toString()));
|
||||||
return templateData;
|
// return templateData;
|
||||||
} else {
|
// } else {
|
||||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "internal error updating template");
|
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "internal error updating template");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import java.util.List;
|
|||||||
import com.cloud.api.commands.AddConfigCmd;
|
import com.cloud.api.commands.AddConfigCmd;
|
||||||
import com.cloud.api.commands.CreateDiskOfferingCmd;
|
import com.cloud.api.commands.CreateDiskOfferingCmd;
|
||||||
import com.cloud.api.commands.DeleteDiskOfferingCmd;
|
import com.cloud.api.commands.DeleteDiskOfferingCmd;
|
||||||
|
import com.cloud.api.commands.DeletePodCmd;
|
||||||
import com.cloud.api.commands.UpdateCfgCmd;
|
import com.cloud.api.commands.UpdateCfgCmd;
|
||||||
import com.cloud.api.commands.UpdateDiskOfferingCmd;
|
import com.cloud.api.commands.UpdateDiskOfferingCmd;
|
||||||
import com.cloud.api.commands.UpdateZoneCmd;
|
import com.cloud.api.commands.UpdateZoneCmd;
|
||||||
@ -154,7 +155,7 @@ public interface ConfigurationManager extends Manager {
|
|||||||
* @param userId
|
* @param userId
|
||||||
* @param podId
|
* @param podId
|
||||||
*/
|
*/
|
||||||
void deletePod(long userId,long podId) throws InvalidParameterValueException, InternalErrorException;
|
void deletePod(DeletePodCmd cmd) throws InvalidParameterValueException, InternalErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new zone
|
* Creates a new zone
|
||||||
|
|||||||
@ -36,6 +36,7 @@ import com.cloud.api.ServerApiException;
|
|||||||
import com.cloud.api.commands.AddConfigCmd;
|
import com.cloud.api.commands.AddConfigCmd;
|
||||||
import com.cloud.api.commands.CreateDiskOfferingCmd;
|
import com.cloud.api.commands.CreateDiskOfferingCmd;
|
||||||
import com.cloud.api.commands.DeleteDiskOfferingCmd;
|
import com.cloud.api.commands.DeleteDiskOfferingCmd;
|
||||||
|
import com.cloud.api.commands.DeletePodCmd;
|
||||||
import com.cloud.api.commands.UpdateCfgCmd;
|
import com.cloud.api.commands.UpdateCfgCmd;
|
||||||
import com.cloud.api.commands.UpdateDiskOfferingCmd;
|
import com.cloud.api.commands.UpdateDiskOfferingCmd;
|
||||||
import com.cloud.api.commands.UpdateZoneCmd;
|
import com.cloud.api.commands.UpdateZoneCmd;
|
||||||
@ -161,7 +162,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException, InternalErrorException{
|
public void updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException, InternalErrorException{
|
||||||
long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
String name = cmd.getName();
|
String name = cmd.getName();
|
||||||
String value = cmd.getValue();
|
String value = cmd.getValue();
|
||||||
updateConfiguration (userId, name, value);
|
updateConfiguration (userId, name, value);
|
||||||
@ -365,7 +366,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DB
|
@DB
|
||||||
public void deletePod(long userId, long podId) throws InvalidParameterValueException, InternalErrorException {
|
public void deletePod(DeletePodCmd cmd) throws InvalidParameterValueException, InternalErrorException {
|
||||||
|
Long podId = cmd.getId();
|
||||||
|
Long userId = 1L;
|
||||||
|
|
||||||
|
if (UserContext.current() != null)
|
||||||
|
userId = UserContext.current().getUserId();
|
||||||
|
|
||||||
// Make sure the pod exists
|
// Make sure the pod exists
|
||||||
if (!validPod(podId)) {
|
if (!validPod(podId)) {
|
||||||
throw new InvalidParameterValueException("A pod with ID: " + podId + " does not exist.");
|
throw new InvalidParameterValueException("A pod with ID: " + podId + " does not exist.");
|
||||||
|
|||||||
@ -26,7 +26,11 @@ import java.util.Map;
|
|||||||
|
|
||||||
import com.cloud.alert.AlertVO;
|
import com.cloud.alert.AlertVO;
|
||||||
import com.cloud.api.commands.EnableAccountCmd;
|
import com.cloud.api.commands.EnableAccountCmd;
|
||||||
|
import com.cloud.api.commands.EnableUserCmd;
|
||||||
|
import com.cloud.api.commands.GetCloudIdentifierCmd;
|
||||||
import com.cloud.api.commands.UpdateAccountCmd;
|
import com.cloud.api.commands.UpdateAccountCmd;
|
||||||
|
import com.cloud.api.commands.UpdateDomainCmd;
|
||||||
|
import com.cloud.api.commands.UpdateTemplateCmd;
|
||||||
import com.cloud.async.AsyncJobResult;
|
import com.cloud.async.AsyncJobResult;
|
||||||
import com.cloud.async.AsyncJobVO;
|
import com.cloud.async.AsyncJobVO;
|
||||||
import com.cloud.capacity.CapacityVO;
|
import com.cloud.capacity.CapacityVO;
|
||||||
@ -203,15 +207,7 @@ public interface ManagementServer {
|
|||||||
* @return true if disable was successful, false otherwise
|
* @return true if disable was successful, false otherwise
|
||||||
*/
|
*/
|
||||||
boolean disableAccount(long accountId);
|
boolean disableAccount(long accountId);
|
||||||
long disableAccountAsync(long accountId);
|
long disableAccountAsync(long accountId);
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables an account by accountId
|
|
||||||
* @param accountId
|
|
||||||
* @return true if enable was successful, false otherwise
|
|
||||||
*/
|
|
||||||
boolean enableAccount(long accountId);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables an account by accountId
|
* Enables an account by accountId
|
||||||
@ -241,7 +237,7 @@ public interface ManagementServer {
|
|||||||
* @param userId
|
* @param userId
|
||||||
* @return true if enable was successful, false otherwise
|
* @return true if enable was successful, false otherwise
|
||||||
*/
|
*/
|
||||||
boolean enableUser(long userId);
|
boolean enableUser(EnableUserCmd cmd) throws InvalidParameterValueException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locks a user by userId. A locked user cannot access the API, but will still have running VMs/IP addresses allocated/etc.
|
* Locks a user by userId. A locked user cannot access the API, but will still have running VMs/IP addresses allocated/etc.
|
||||||
@ -1020,12 +1016,12 @@ public interface ManagementServer {
|
|||||||
*/
|
*/
|
||||||
HostPodVO editPod(long userId, long podId, String newPodName, String gateway, String cidr, String startIp, String endIp) throws InvalidParameterValueException, InternalErrorException;
|
HostPodVO editPod(long userId, long podId, String newPodName, String gateway, String cidr, String startIp, String endIp) throws InvalidParameterValueException, InternalErrorException;
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Deletes a pod from the database
|
// * Deletes a pod from the database
|
||||||
* @param userId
|
// * @param userId
|
||||||
* @param podId
|
// * @param podId
|
||||||
*/
|
// */
|
||||||
void deletePod(long userId, long podId) throws InvalidParameterValueException, InternalErrorException;
|
// void deletePod(long userId, long podId) throws InvalidParameterValueException, InternalErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new zone to the database
|
* Adds a new zone to the database
|
||||||
@ -1171,7 +1167,7 @@ public interface ManagementServer {
|
|||||||
* @param Boolean bootable
|
* @param Boolean bootable
|
||||||
* @return success/failure
|
* @return success/failure
|
||||||
*/
|
*/
|
||||||
boolean updateTemplate(Long id, String name, String displayText, String format, Long guestOsId, Boolean passwordEnabled, Boolean bootable) throws InvalidParameterValueException;
|
boolean updateTemplate(UpdateTemplateCmd cmd) throws InvalidParameterValueException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a template by downloading to all zones
|
* Creates a template by downloading to all zones
|
||||||
@ -1550,7 +1546,7 @@ public interface ManagementServer {
|
|||||||
* @param domainId the id of the domain to be updated
|
* @param domainId the id of the domain to be updated
|
||||||
* @param domainName the new name of the domain
|
* @param domainName the new name of the domain
|
||||||
*/
|
*/
|
||||||
void updateDomain(Long domainId, String domainName);
|
void updateDomain(UpdateDomainCmd cmd) throws InvalidParameterValueException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* find the domain Id associated with the given account
|
* find the domain Id associated with the given account
|
||||||
@ -2048,7 +2044,7 @@ public interface ManagementServer {
|
|||||||
* @param userId -- id for the user
|
* @param userId -- id for the user
|
||||||
* @return -- ArrayList of <CloudId+Signature>
|
* @return -- ArrayList of <CloudId+Signature>
|
||||||
*/
|
*/
|
||||||
ArrayList<String> getCloudIdentifierResponse(long userId);
|
ArrayList<String> getCloudIdentifierResponse(GetCloudIdentifierCmd cmd) throws InvalidParameterValueException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if a network security group name in the given account/domain is in use
|
* check if a network security group name in the given account/domain is in use
|
||||||
|
|||||||
@ -58,6 +58,7 @@ import com.cloud.alert.AlertManager;
|
|||||||
import com.cloud.alert.AlertVO;
|
import com.cloud.alert.AlertVO;
|
||||||
import com.cloud.alert.dao.AlertDao;
|
import com.cloud.alert.dao.AlertDao;
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.ServerApiException;
|
||||||
import com.cloud.api.commands.AssociateIPAddrCmd;
|
import com.cloud.api.commands.AssociateIPAddrCmd;
|
||||||
import com.cloud.api.commands.AuthorizeNetworkGroupIngressCmd;
|
import com.cloud.api.commands.AuthorizeNetworkGroupIngressCmd;
|
||||||
import com.cloud.api.commands.CancelMaintenanceCmd;
|
import com.cloud.api.commands.CancelMaintenanceCmd;
|
||||||
@ -71,6 +72,8 @@ import com.cloud.api.commands.DeleteTemplateCmd;
|
|||||||
import com.cloud.api.commands.DeleteUserCmd;
|
import com.cloud.api.commands.DeleteUserCmd;
|
||||||
import com.cloud.api.commands.DeployVMCmd;
|
import com.cloud.api.commands.DeployVMCmd;
|
||||||
import com.cloud.api.commands.EnableAccountCmd;
|
import com.cloud.api.commands.EnableAccountCmd;
|
||||||
|
import com.cloud.api.commands.EnableUserCmd;
|
||||||
|
import com.cloud.api.commands.GetCloudIdentifierCmd;
|
||||||
import com.cloud.api.commands.PrepareForMaintenanceCmd;
|
import com.cloud.api.commands.PrepareForMaintenanceCmd;
|
||||||
import com.cloud.api.commands.PreparePrimaryStorageForMaintenanceCmd;
|
import com.cloud.api.commands.PreparePrimaryStorageForMaintenanceCmd;
|
||||||
import com.cloud.api.commands.ReconnectHostCmd;
|
import com.cloud.api.commands.ReconnectHostCmd;
|
||||||
@ -78,6 +81,8 @@ import com.cloud.api.commands.StartRouterCmd;
|
|||||||
import com.cloud.api.commands.StartSystemVMCmd;
|
import com.cloud.api.commands.StartSystemVMCmd;
|
||||||
import com.cloud.api.commands.StartVMCmd;
|
import com.cloud.api.commands.StartVMCmd;
|
||||||
import com.cloud.api.commands.UpdateAccountCmd;
|
import com.cloud.api.commands.UpdateAccountCmd;
|
||||||
|
import com.cloud.api.commands.UpdateDomainCmd;
|
||||||
|
import com.cloud.api.commands.UpdateTemplateCmd;
|
||||||
import com.cloud.api.commands.UpgradeVMCmd;
|
import com.cloud.api.commands.UpgradeVMCmd;
|
||||||
import com.cloud.async.AsyncInstanceCreateStatus;
|
import com.cloud.async.AsyncInstanceCreateStatus;
|
||||||
import com.cloud.async.AsyncJobExecutor;
|
import com.cloud.async.AsyncJobExecutor;
|
||||||
@ -1044,17 +1049,31 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enableUser(long userId) {
|
public boolean enableUser(EnableUserCmd cmd) throws InvalidParameterValueException{
|
||||||
|
Long userId = cmd.getId();
|
||||||
|
Account adminAccount = (Account)UserContext.current().getAccountObject();
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
|
||||||
|
//Check if user exists in the system
|
||||||
|
User user = findUserById(userId);
|
||||||
|
if ((user == null) || (user.getRemoved() != null))
|
||||||
|
throw new InvalidParameterValueException("Unable to find active user by id " + userId);
|
||||||
|
|
||||||
|
// If the user is a System user, return an error
|
||||||
|
Account account = findAccountById(user.getAccountId());
|
||||||
|
if ((account != null) && (account.getId() == Account.ACCOUNT_ID_SYSTEM)) {
|
||||||
|
throw new InvalidParameterValueException("User id : " + userId + " is a system user, enabling is not allowed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((adminAccount != null) && !isChildDomain(adminAccount.getDomainId(), account.getDomainId())) {
|
||||||
|
throw new InvalidParameterValueException("Failed to enable user " + userId + ", permission denied.");
|
||||||
|
}
|
||||||
|
|
||||||
success = doSetUserStatus(userId, Account.ACCOUNT_STATE_ENABLED);
|
success = doSetUserStatus(userId, Account.ACCOUNT_STATE_ENABLED);
|
||||||
|
|
||||||
// make sure the account is enabled too
|
// make sure the account is enabled too
|
||||||
UserVO user = _userDao.findById(userId);
|
success = (success && enableAccount(user.getAccountId()));
|
||||||
if (user != null) {
|
|
||||||
success = (success && enableAccount(user.getAccountId()));
|
|
||||||
} else {
|
|
||||||
s_logger.warn("Unable to find user with id: " + userId);
|
|
||||||
}
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1198,7 +1217,6 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean enableAccount(long accountId) {
|
public boolean enableAccount(long accountId) {
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
AccountVO acctForUpdate = _accountDao.createForUpdate();
|
AccountVO acctForUpdate = _accountDao.createForUpdate();
|
||||||
@ -4270,10 +4288,10 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
return _configMgr.editPod(userId, podId, newPodName, gateway, cidr, startIp, endIp);
|
return _configMgr.editPod(userId, podId, newPodName, gateway, cidr, startIp, endIp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public void deletePod(long userId, long podId) throws InvalidParameterValueException, InternalErrorException {
|
// public void deletePod(long userId, long podId) throws InvalidParameterValueException, InternalErrorException {
|
||||||
_configMgr.deletePod(userId, podId);
|
// _configMgr.deletePod(userId, podId);
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange,String guestCidr) throws InvalidParameterValueException, InternalErrorException {
|
public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange,String guestCidr) throws InvalidParameterValueException, InternalErrorException {
|
||||||
@ -4716,13 +4734,49 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateTemplate(Long id, String name, String displayText, String format, Long guestOSId, Boolean passwordEnabled, Boolean bootable) throws InvalidParameterValueException {
|
public boolean updateTemplate(UpdateTemplateCmd cmd) throws InvalidParameterValueException {
|
||||||
|
Long id = cmd.getId();
|
||||||
|
String name = cmd.getName();
|
||||||
|
String displayText = cmd.getDisplayText();
|
||||||
|
String format = cmd.getFormat();
|
||||||
|
Long guestOSId = cmd.getOsTypeId();
|
||||||
|
Boolean passwordEnabled = cmd.isPasswordEnabled();
|
||||||
|
Boolean bootable = cmd.isBootable();
|
||||||
|
Account account= (Account)UserContext.current().getAccountObject();
|
||||||
|
|
||||||
|
//verify that template exists
|
||||||
|
VMTemplateVO template = findTemplateById(id);
|
||||||
|
if (template == null) {
|
||||||
|
throw new InvalidParameterValueException("unable to find template with id " + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Don't allow to modify system template
|
||||||
|
if (id == Long.valueOf(1)) {
|
||||||
|
throw new InvalidParameterValueException("Unable to update template with id " + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
//do a permission check
|
||||||
|
if (account != null) {
|
||||||
|
Long templateOwner = template.getAccountId();
|
||||||
|
if (!BaseCmd.isAdmin(account.getType())) {
|
||||||
|
if ((templateOwner == null) || (account.getId().longValue() != templateOwner.longValue())) {
|
||||||
|
throw new InvalidParameterValueException("Unable to modify template with id " + id);
|
||||||
|
}
|
||||||
|
} else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
|
||||||
|
Long templateOwnerDomainId = findDomainIdByAccountId(templateOwner);
|
||||||
|
if (!isChildDomain(account.getDomainId(), templateOwnerDomainId)) {
|
||||||
|
throw new InvalidParameterValueException("Unable to modify template with id " + id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
boolean updateNeeded = !(name == null && displayText == null && format == null && guestOSId == null && passwordEnabled == null && bootable == null);
|
boolean updateNeeded = !(name == null && displayText == null && format == null && guestOSId == null && passwordEnabled == null && bootable == null);
|
||||||
if (!updateNeeded) {
|
if (!updateNeeded) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
VMTemplateVO template = _templateDao.createForUpdate(id);
|
template = _templateDao.createForUpdate(id);
|
||||||
|
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
template.setName(name);
|
template.setName(name);
|
||||||
@ -6299,16 +6353,39 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
return success && deleteDomainSuccess;
|
return success && deleteDomainSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateDomain(Long domainId, String domainName) {
|
public void updateDomain(UpdateDomainCmd cmd) throws InvalidParameterValueException{
|
||||||
|
Long domainId = cmd.getId();
|
||||||
|
String domainName = cmd.getName();
|
||||||
|
|
||||||
|
//check if domain exists in the system
|
||||||
|
DomainVO domain = findDomainIdById(domainId);
|
||||||
|
if (domain == null) {
|
||||||
|
throw new InvalidParameterValueException("Unable to find domain " + domainId);
|
||||||
|
} else if (domain.getParent() == null) {
|
||||||
|
//check if domain is ROOT domain - and deny to edit it
|
||||||
|
throw new InvalidParameterValueException("ROOT domain can not be edited");
|
||||||
|
}
|
||||||
|
|
||||||
|
// check permissions
|
||||||
|
Account account = (Account)UserContext.current().getAccountObject();
|
||||||
|
if ((account != null) && !isChildDomain(account.getDomainId(), domain.getId())) {
|
||||||
|
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to update domain " + domainId + ", permission denied");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (domainName == null) {
|
||||||
|
domainName = domain.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SearchCriteria<DomainVO> sc = _domainDao.createSearchCriteria();
|
SearchCriteria<DomainVO> sc = _domainDao.createSearchCriteria();
|
||||||
sc.addAnd("name", SearchCriteria.Op.EQ, domainName);
|
sc.addAnd("name", SearchCriteria.Op.EQ, domainName);
|
||||||
List<DomainVO> domains = _domainDao.search(sc, null);
|
List<DomainVO> domains = _domainDao.search(sc, null);
|
||||||
if ((domains == null) || domains.isEmpty()) {
|
if ((domains == null) || domains.isEmpty()) {
|
||||||
_domainDao.update(domainId, domainName);
|
_domainDao.update(domainId, domainName);
|
||||||
DomainVO domain = _domainDao.findById(domainId);
|
domain = _domainDao.findById(domainId);
|
||||||
EventUtils.saveEvent(new Long(1), domain.getOwner(), EventVO.LEVEL_INFO, EventTypes.EVENT_DOMAIN_UPDATE, "Domain, " + domainName + " was updated");
|
EventUtils.saveEvent(new Long(1), domain.getOwner(), EventVO.LEVEL_INFO, EventTypes.EVENT_DOMAIN_UPDATE, "Domain, " + domainName + " was updated");
|
||||||
} else {
|
} else {
|
||||||
DomainVO domain = _domainDao.findById(domainId);
|
domain = _domainDao.findById(domainId);
|
||||||
EventUtils.saveEvent(new Long(1), domain.getOwner(), EventVO.LEVEL_ERROR, EventTypes.EVENT_DOMAIN_UPDATE, "Failed to update domain " + domain.getName() + " with name " + domainName + ", name in use.");
|
EventUtils.saveEvent(new Long(1), domain.getOwner(), EventVO.LEVEL_ERROR, EventTypes.EVENT_DOMAIN_UPDATE, "Failed to update domain " + domain.getName() + " with name " + domainName + ", name in use.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -8020,8 +8097,14 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getCloudIdentifierResponse(long userId)
|
public ArrayList<String> getCloudIdentifierResponse(GetCloudIdentifierCmd cmd) throws InvalidParameterValueException{
|
||||||
{
|
Long userId = cmd.getUserId();
|
||||||
|
|
||||||
|
//verify that user exists
|
||||||
|
User user = findUserById(userId);
|
||||||
|
if ((user == null) || (user.getRemoved() != null))
|
||||||
|
throw new InvalidParameterValueException("Unable to find active user by id " + userId);
|
||||||
|
|
||||||
Criteria c = new Criteria ();
|
Criteria c = new Criteria ();
|
||||||
c.addCriteria(Criteria.NAME, "cloud.identifier");
|
c.addCriteria(Criteria.NAME, "cloud.identifier");
|
||||||
|
|
||||||
@ -8037,7 +8120,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
String signature = "";
|
String signature = "";
|
||||||
try {
|
try {
|
||||||
//get the user obj to get his secret key
|
//get the user obj to get his secret key
|
||||||
User user = getUser(userId);
|
user = getUser(userId);
|
||||||
String secretKey = user.getSecretKey();
|
String secretKey = user.getSecretKey();
|
||||||
String input = cloudIdentifier;
|
String input = cloudIdentifier;
|
||||||
signature = signRequest(input, secretKey);
|
signature = signRequest(input, secretKey);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user