You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2012/12/08 04:29:53 UTC
[48/57] api: move and group all under command,
org.apache.cloudstack.command.*
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/af28c069/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java
new file mode 100755
index 0000000..f16b7e2
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java
@@ -0,0 +1,134 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.template;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import com.cloud.api.response.ListResponse;
+import com.cloud.api.response.TemplateResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+import com.cloud.utils.Pair;
+
+@Implementation(description="List all public, private, and privileged templates.", responseObject=TemplateResponse.class)
+public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
+ public static final Logger s_logger = Logger.getLogger(ListTemplatesCmd.class.getName());
+
+ private static final String s_name = "listtemplatesresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, description="the hypervisor for which to restrict the search")
+ private String hypervisor;
+
+ @IdentityMapper(entityTableName="vm_template")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the template ID")
+ private Long id;
+
+ @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the template name")
+ private String templateName;
+
+ @Parameter(name=ApiConstants.TEMPLATE_FILTER, type=CommandType.STRING, required=true, description="possible values are \"featured\", \"self\", \"self-executable\", \"executable\", and \"community\"." +
+ "* featured-templates that are featured and are public" +
+ "* self-templates that have been registered/created by the owner" +
+ "* selfexecutable-templates that have been registered/created by the owner that can be used to deploy a new VM" +
+ "* executable-all templates that can be used to deploy a new VM* community-templates that are public.")
+ private String templateFilter;
+
+ @IdentityMapper(entityTableName="data_center")
+ @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="list templates by zoneId")
+ private Long zoneId;
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getHypervisor() {
+ return hypervisor;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getTemplateName() {
+ return templateName;
+ }
+
+ public String getTemplateFilter() {
+ return templateFilter;
+ }
+
+ public Long getZoneId() {
+ return zoneId;
+ }
+
+ public boolean listInReadyState() {
+
+ Account account = UserContext.current().getCaller();
+ // It is account specific if account is admin type and domainId and accountName are not null
+ boolean isAccountSpecific = (account == null || isAdmin(account.getType())) && (getAccountName() != null) && (getDomainId() != null);
+ // Show only those that are downloaded.
+ TemplateFilter templateFilter = TemplateFilter.valueOf(getTemplateFilter());
+ boolean onlyReady = (templateFilter == TemplateFilter.featured) || (templateFilter == TemplateFilter.selfexecutable) || (templateFilter == TemplateFilter.sharedexecutable)
+ || (templateFilter == TemplateFilter.executable && isAccountSpecific) || (templateFilter == TemplateFilter.community);
+ return onlyReady;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ public AsyncJob.Type getInstanceType() {
+ return AsyncJob.Type.Template;
+ }
+
+ @Override
+ public void execute(){
+ Set<Pair<Long, Long>> templateZonePairSet = _mgr.listTemplates(this);
+
+ ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
+ List<TemplateResponse> templateResponses = new ArrayList<TemplateResponse>();
+
+ for (Pair<Long, Long> template : templateZonePairSet) {
+ List<TemplateResponse> responses = new ArrayList<TemplateResponse>();
+ responses = _responseGenerator.createTemplateResponses(template.first().longValue(), template.second(), listInReadyState());
+ templateResponses.addAll(responses);
+ }
+
+ response.setResponses(templateResponses);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/af28c069/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java
new file mode 100755
index 0000000..54269ac
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java
@@ -0,0 +1,240 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.template;
+
+import java.net.URISyntaxException;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.ListResponse;
+import com.cloud.api.response.TemplateResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Registers an existing template into the CloudStack cloud. ", responseObject=TemplateResponse.class)
+public class RegisterTemplateCmd extends BaseCmd {
+ public static final Logger s_logger = Logger.getLogger(RegisterTemplateCmd.class.getName());
+
+ private static final String s_name = "registertemplateresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.BITS, type=CommandType.INTEGER, description="32 or 64 bits support. 64 by default")
+ private Integer bits;
+
+ @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of the template. This is usually used for display purposes.", length=4096)
+ private String displayText;
+
+ @Parameter(name=ApiConstants.FORMAT, type=CommandType.STRING, required=true, description="the format for the template. Possible values include QCOW2, RAW, and VHD.")
+ private String format;
+
+ @Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, required=true, description="the target hypervisor for the template")
+ private String hypervisor;
+
+ @Parameter(name=ApiConstants.IS_FEATURED, type=CommandType.BOOLEAN, description="true if this template is a featured template, false otherwise")
+ private Boolean featured;
+
+ @Parameter(name=ApiConstants.IS_PUBLIC, type=CommandType.BOOLEAN, description="true if the template is available to all accounts; default is true")
+ private Boolean publicTemplate;
+
+ @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the template")
+ private String templateName;
+
+ @Parameter(name=ApiConstants.OS_TYPE_ID, type=CommandType.LONG, required=true, description="the ID of the OS Type that best represents the OS of this template.")
+ @IdentityMapper(entityTableName="guest_os")
+ private Long osTypeId;
+
+ @Parameter(name=ApiConstants.PASSWORD_ENABLED, type=CommandType.BOOLEAN, description="true if the template supports the password reset feature; default is false")
+ private Boolean passwordEnabled;
+
+ @Parameter(name=ApiConstants.SSHKEY_ENABLED, type=CommandType.BOOLEAN, description="true if the template supports the sshkey upload feature; default is false")
+ private Boolean sshKeyEnabled;
+
+ @Parameter(name=ApiConstants.IS_EXTRACTABLE, type=CommandType.BOOLEAN, description="true if the template or its derivatives are extractable; default is false")
+ private Boolean extractable;
+
+ @Parameter(name=ApiConstants.REQUIRES_HVM, type=CommandType.BOOLEAN, description="true if this template requires HVM")
+ private Boolean requiresHvm;
+
+ @Parameter(name=ApiConstants.URL, type=CommandType.STRING, required=true, description="the URL of where the template is hosted. Possible URL include http:// and https://")
+ private String url;
+
+ @IdentityMapper(entityTableName="data_center")
+ @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the ID of the zone the template is to be hosted on")
+ private Long zoneId;
+
+ @IdentityMapper(entityTableName="domain")
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="an optional domainId. If the account parameter is used, domainId must also be used.")
+ private Long domainId;
+
+ @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="an optional accountName. Must be used with domainId.")
+ private String accountName;
+
+ @Parameter(name=ApiConstants.CHECKSUM, type=CommandType.STRING, description="the MD5 checksum value of this template")
+ private String checksum;
+
+ @Parameter(name=ApiConstants.TEMPLATE_TAG, type=CommandType.STRING, description="the tag for this template.")
+ private String templateTag;
+
+ @IdentityMapper(entityTableName="projects")
+ @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="Register template for the project")
+ private Long projectId;
+
+ @Parameter(name=ApiConstants.DETAILS, type=CommandType.MAP, description="Template details in key/value pairs.")
+ protected Map details;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Integer getBits() {
+ return bits;
+ }
+
+ public String getDisplayText() {
+ return displayText;
+ }
+
+ public String getFormat() {
+ return format;
+ }
+
+ public String getHypervisor() {
+ return hypervisor;
+ }
+
+ public Boolean isFeatured() {
+ return featured;
+ }
+
+ public Boolean isPublic() {
+ return publicTemplate;
+ }
+
+ public String getTemplateName() {
+ return templateName;
+ }
+
+ public Long getOsTypeId() {
+ return osTypeId;
+ }
+
+ public Boolean isPasswordEnabled() {
+ return passwordEnabled;
+ }
+
+ public Boolean isSshKeyEnabled() {
+ return sshKeyEnabled;
+ }
+
+ public Boolean isExtractable() {
+ return extractable;
+ }
+
+ public Boolean getRequiresHvm() {
+ return requiresHvm;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public Long getZoneId() {
+ return zoneId;
+ }
+
+ public Long getDomainId() {
+ return domainId;
+ }
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public String getChecksum() {
+ return checksum;
+ }
+
+ public String getTemplateTag() {
+ return templateTag;
+ }
+
+ public Map getDetails() {
+ if (details == null || details.isEmpty()) {
+ return null;
+ }
+
+ Collection paramsCollection = details.values();
+ Map params = (Map) (paramsCollection.toArray())[0];
+ return params;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ public AsyncJob.Type getInstanceType() {
+ return AsyncJob.Type.Template;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
+ if (accountId == null) {
+ return UserContext.current().getCaller().getId();
+ }
+
+ return accountId;
+ }
+
+ @Override
+ public void execute() throws ResourceAllocationException{
+ try {
+ VirtualMachineTemplate template = _templateService.registerTemplate(this);
+ if (template != null){
+ ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
+ List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(template.getId(), zoneId, false);
+ response.setResponses(templateResponses);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to register template");
+ }
+ } catch (URISyntaxException ex1) {
+ s_logger.info(ex1);
+ throw new ServerApiException(BaseCmd.PARAM_ERROR, ex1.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/af28c069/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java
new file mode 100755
index 0000000..5d2af34
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java
@@ -0,0 +1,79 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.template;
+
+import com.cloud.api.commands.UpdateTemplateOrIsoCmd;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.TemplateResponse;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.user.Account;
+
+@Implementation(description="Updates attributes of a template.", responseObject=TemplateResponse.class)
+public class UpdateTemplateCmd extends UpdateTemplateOrIsoCmd {
+ public static final Logger s_logger = Logger.getLogger(UpdateTemplateCmd.class.getName());
+ private static final String s_name = "updatetemplateresponse";
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public Boolean isBootable() {
+ return null;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @SuppressWarnings("unchecked")
+ public TemplateResponse getResponse() {
+ return null;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
+ if (template != null) {
+ return template.getAccountId();
+ }
+
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public void execute(){
+ VirtualMachineTemplate result = _mgr.updateTemplate(this);
+ if (result != null) {
+ TemplateResponse response = _responseGenerator.createIsoResponse(result);
+ response.setObjectName("template");
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update template");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/af28c069/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplatePermissionsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplatePermissionsCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplatePermissionsCmd.java
new file mode 100644
index 0000000..bdd4a0c
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplatePermissionsCmd.java
@@ -0,0 +1,51 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.template;
+
+import com.cloud.api.commands.UpdateTemplateOrIsoPermissionsCmd;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.Implementation;
+import com.cloud.api.response.SuccessResponse;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.user.Account;
+
+@Implementation(responseObject=SuccessResponse.class, description="Updates a template visibility permissions. " +
+ "A public template is visible to all accounts within the same domain. " +
+ "A private template is visible only to the owner of the template. " +
+ "A priviledged template is a private template with account permissions added. " +
+ "Only accounts specified under the template permissions are visible to them.")
+public class UpdateTemplatePermissionsCmd extends UpdateTemplateOrIsoPermissionsCmd {
+ protected String getResponseName() {
+ return "updatetemplatepermissionsresponse";
+ }
+
+ protected Logger getLogger() {
+ return Logger.getLogger(UpdateTemplatePermissionsCmd.class.getName());
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
+ if (template != null) {
+ return template.getAccountId();
+ }
+
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/af28c069/api/src/org/apache/cloudstack/api/command/user/user/AddVpnUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/user/AddVpnUserCmd.java b/api/src/org/apache/cloudstack/api/command/user/user/AddVpnUserCmd.java
new file mode 100644
index 0000000..a7ec871
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/user/AddVpnUserCmd.java
@@ -0,0 +1,150 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.user;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.VpnUsersResponse;
+import com.cloud.domain.Domain;
+import com.cloud.event.EventTypes;
+import com.cloud.network.VpnUser;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Adds vpn users", responseObject=VpnUsersResponse.class)
+public class AddVpnUserCmd extends BaseAsyncCreateCmd {
+ public static final Logger s_logger = Logger.getLogger(AddVpnUserCmd.class.getName());
+
+ private static final String s_name = "addvpnuserresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required=true, description="username for the vpn user")
+ private String userName;
+
+ @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required=true, description="password for the username")
+ private String password;
+
+ @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="an optional account for the vpn user. Must be used with domainId.")
+ private String accountName;
+
+ @IdentityMapper(entityTableName="projects")
+ @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="add vpn user to the specific project")
+ private Long projectId;
+
+ @IdentityMapper(entityTableName="domain")
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="an optional domainId for the vpn user. If the account parameter is used, domainId must also be used.")
+ private Long domainId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public Long getDomainId() {
+ return domainId;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public Long getProjectId() {
+ return projectId;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
+ if (accountId == null) {
+ return UserContext.current().getCaller().getId();
+ }
+
+ return accountId;
+ }
+
+ public String getEntityTable() {
+ return "vpn_users";
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Add Remote Access VPN user for account " + getEntityOwnerId() + " username= " + getUserName();
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_VPN_USER_ADD;
+ }
+
+ @Override
+ public void execute(){
+ VpnUser vpnUser = _entityMgr.findById(VpnUser.class, getEntityId());
+ Account account = _entityMgr.findById(Account.class, vpnUser.getAccountId());
+ if (!_ravService.applyVpnUsers(vpnUser.getAccountId(), userName)) {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add vpn user");
+ }
+
+ VpnUsersResponse vpnResponse = new VpnUsersResponse();
+ vpnResponse.setId(vpnUser.getId());
+ vpnResponse.setUserName(vpnUser.getUsername());
+ vpnResponse.setAccountName(account.getAccountName());
+
+ vpnResponse.setDomainId(account.getDomainId());
+ vpnResponse.setDomainName(_entityMgr.findById(Domain.class, account.getDomainId()).getName());
+
+ vpnResponse.setResponseName(getCommandName());
+ vpnResponse.setObjectName("vpnuser");
+ this.setResponseObject(vpnResponse);
+ }
+
+ @Override
+ public void create() {
+ Account owner = _accountService.getAccount(getEntityOwnerId());
+
+ VpnUser vpnUser = _ravService.addVpnUser(owner.getId(), userName, password);
+ if (vpnUser == null) {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add vpn user");
+ }
+ setEntityId(vpnUser.getId());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/af28c069/api/src/org/apache/cloudstack/api/command/user/user/ListVpnUsersCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/user/ListVpnUsersCmd.java b/api/src/org/apache/cloudstack/api/command/user/user/ListVpnUsersCmd.java
new file mode 100644
index 0000000..6149b40
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/user/ListVpnUsersCmd.java
@@ -0,0 +1,85 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.user;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import com.cloud.api.response.ListResponse;
+import com.cloud.api.response.VpnUsersResponse;
+import com.cloud.network.VpnUser;
+import com.cloud.utils.Pair;
+
+@Implementation(description="Lists vpn users", responseObject=VpnUsersResponse.class)
+public class ListVpnUsersCmd extends BaseListProjectAndAccountResourcesCmd {
+ public static final Logger s_logger = Logger.getLogger (ListVpnUsersCmd.class.getName());
+
+ private static final String s_name = "listvpnusersresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @IdentityMapper(entityTableName="vpn_users")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the ID of the vpn user")
+ private Long id;
+
+ @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, description="the username of the vpn user.")
+ private String userName;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getUsername() {
+ return userName;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute(){
+ Pair<List<? extends VpnUser>, Integer> vpnUsers = _ravService.searchForVpnUsers(this);
+
+ ListResponse<VpnUsersResponse> response = new ListResponse<VpnUsersResponse>();
+ List<VpnUsersResponse> vpnResponses = new ArrayList<VpnUsersResponse>();
+ for (VpnUser vpnUser : vpnUsers.first()) {
+ vpnResponses.add(_responseGenerator.createVpnUserResponse(vpnUser));
+ }
+
+ response.setResponses(vpnResponses, vpnUsers.second());
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/af28c069/api/src/org/apache/cloudstack/api/command/user/user/RemoveVpnUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/user/RemoveVpnUserCmd.java b/api/src/org/apache/cloudstack/api/command/user/user/RemoveVpnUserCmd.java
new file mode 100644
index 0000000..f03c1a8
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/user/RemoveVpnUserCmd.java
@@ -0,0 +1,122 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.user;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.SuccessResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Removes vpn user", responseObject=SuccessResponse.class)
+public class RemoveVpnUserCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(RemoveVpnUserCmd.class.getName());
+
+ private static final String s_name = "removevpnuserresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required=true, description="username for the vpn user")
+ private String userName;
+
+ @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="an optional account for the vpn user. Must be used with domainId.")
+ private String accountName;
+
+ @IdentityMapper(entityTableName="projects")
+ @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="remove vpn user from the project")
+ private Long projectId;
+
+ @IdentityMapper(entityTableName="domain")
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="an optional domainId for the vpn user. If the account parameter is used, domainId must also be used.")
+ private Long domainId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public Long getDomainId() {
+ return domainId;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public Long getProjecId() {
+ return projectId;
+ }
+
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
+ if (accountId == null) {
+ return UserContext.current().getCaller().getId();
+ }
+
+ return accountId;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Remove Remote Access VPN user for account " + getEntityOwnerId() + " username= " + getUserName();
+ }
+
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_VPN_USER_REMOVE;
+ }
+
+ @Override
+ public void execute(){
+ Account owner = _accountService.getAccount(getEntityOwnerId());
+ boolean result = _ravService.removeVpnUser(owner.getId(), userName, UserContext.current().getCaller());
+ if (!result) {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to remove vpn user");
+ }
+
+ if (!_ravService.applyVpnUsers(owner.getId(), userName)) {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to apply vpn user removal");
+ }
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ setResponseObject(response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/af28c069/api/src/org/apache/cloudstack/api/response/NetworkDeviceResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/NetworkDeviceResponse.java b/api/src/org/apache/cloudstack/api/response/NetworkDeviceResponse.java
new file mode 100644
index 0000000..c7fb7e8
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/response/NetworkDeviceResponse.java
@@ -0,0 +1,37 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.response;
+
+import org.apache.cloudstack.api.ApiConstants;
+import com.cloud.utils.IdentityProxy;
+import com.cloud.api.response.BaseResponse;
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+public class NetworkDeviceResponse extends BaseResponse {
+ @SerializedName(ApiConstants.ID)
+ @Param(description = "the ID of the network device")
+ private IdentityProxy id = new IdentityProxy("host");
+
+ public Long getId() {
+ return id.getValue();
+ }
+
+ public void setId(Long id) {
+ this.id.setValue(id);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/af28c069/api/src/org/apache/cloudstack/api/user/account/command/AddAccountToProjectCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/account/command/AddAccountToProjectCmd.java b/api/src/org/apache/cloudstack/api/user/account/command/AddAccountToProjectCmd.java
deleted file mode 100644
index 56dea9e..0000000
--- a/api/src/org/apache/cloudstack/api/user/account/command/AddAccountToProjectCmd.java
+++ /dev/null
@@ -1,124 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.api.user.account.command;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseAsyncCmd;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.SuccessResponse;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.projects.Project;
-import com.cloud.user.UserContext;
-
-
-@Implementation(description="Adds acoount to a project", responseObject=SuccessResponse.class, since="3.0.0")
-public class AddAccountToProjectCmd extends BaseAsyncCmd {
- public static final Logger s_logger = Logger.getLogger(AddAccountToProjectCmd.class.getName());
-
- private static final String s_name = "addaccounttoprojectresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="projects")
- @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, required=true, description="id of the project to add the account to")
- private Long projectId;
-
- @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="name of the account to be added to the project")
- private String accountName;
-
- @Parameter(name=ApiConstants.EMAIL, type=CommandType.STRING, description="email to which invitation to the project is going to be sent")
- private String email;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
-
- public String getAccountName() {
- return accountName;
- }
-
- public Long getProjectId() {
- return projectId;
- }
-
-
- public String getEmail() {
- return email;
- }
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public void execute(){
- if (accountName == null && email == null) {
- throw new InvalidParameterValueException("Either accountName or email is required");
- }
-
- UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName);
- boolean result = _projectService.addAccountToProject(getProjectId(), getAccountName(), getEmail());
- if (result) {
- SuccessResponse response = new SuccessResponse(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add account to the project");
- }
- }
-
- @Override
- public long getEntityOwnerId() {
- Project project= _projectService.getProject(getProjectId());
- //verify input parameters
- if (project == null) {
- InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified id");
- ex.addProxyObject(project, getProjectId(), "projectId");
- throw ex;
- }
-
- return _projectService.getProjectOwner(getProjectId()).getId();
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_PROJECT_ACCOUNT_ADD;
- }
-
- @Override
- public String getEventDescription() {
- if (accountName != null) {
- return "Adding account " + getAccountName() + " to project: " + getProjectId();
- } else {
- return "Sending invitation to email " + email + " to join project: " + getProjectId();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/af28c069/api/src/org/apache/cloudstack/api/user/account/command/DeleteAccountFromProjectCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/account/command/DeleteAccountFromProjectCmd.java b/api/src/org/apache/cloudstack/api/user/account/command/DeleteAccountFromProjectCmd.java
deleted file mode 100644
index d5ce0e9..0000000
--- a/api/src/org/apache/cloudstack/api/user/account/command/DeleteAccountFromProjectCmd.java
+++ /dev/null
@@ -1,108 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.api.user.account.command;
-
-import org.apache.cloudstack.api.user.project.command.DeleteProjectCmd;
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseAsyncCmd;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.SuccessResponse;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.projects.Project;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Deletes account from the project", responseObject=SuccessResponse.class, since="3.0.0")
-public class DeleteAccountFromProjectCmd extends BaseAsyncCmd {
- public static final Logger s_logger = Logger.getLogger(DeleteProjectCmd.class.getName());
-
- private static final String s_name = "deleteaccountfromprojectresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
- @IdentityMapper(entityTableName="projects")
- @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, required=true, description="id of the project to remove the account from")
- private Long projectId;
-
- @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, required=true, description="name of the account to be removed from the project")
- private String accountName;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
-
-
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- public Long getProjectId() {
- return projectId;
- }
-
- public String getAccountName() {
- return accountName;
- }
-
- @Override
- public void execute(){
- UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName);
- boolean result = _projectService.deleteAccountFromProject(projectId, accountName);
- if (result) {
- SuccessResponse response = new SuccessResponse(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete account from the project");
- }
- }
-
-
- @Override
- public long getEntityOwnerId() {
- Project project= _projectService.getProject(projectId);
- //verify input parameters
- if (project == null) {
- throw new InvalidParameterValueException("Unable to find project by id " + projectId);
- }
-
- return _projectService.getProjectOwner(projectId).getId();
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_PROJECT_ACCOUNT_REMOVE;
- }
-
- @Override
- public String getEventDescription() {
- return "Removing account " + accountName + " from project: " + projectId;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/af28c069/api/src/org/apache/cloudstack/api/user/account/command/ListAccountsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/account/command/ListAccountsCmd.java b/api/src/org/apache/cloudstack/api/user/account/command/ListAccountsCmd.java
deleted file mode 100755
index 1a41285..0000000
--- a/api/src/org/apache/cloudstack/api/user/account/command/ListAccountsCmd.java
+++ /dev/null
@@ -1,108 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.api.user.account.command;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseListDomainResourcesCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import com.cloud.api.response.AccountResponse;
-import com.cloud.api.response.ListResponse;
-import com.cloud.user.Account;
-import com.cloud.utils.Pair;
-
-@Implementation(description="Lists accounts and provides detailed account information for listed accounts", responseObject=AccountResponse.class)
-public class ListAccountsCmd extends BaseListDomainResourcesCmd {
- public static final Logger s_logger = Logger.getLogger(ListAccountsCmd.class.getName());
- private static final String s_name = "listaccountsresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @Parameter(name=ApiConstants.ACCOUNT_TYPE, type=CommandType.LONG, description="list accounts by account type. Valid account types are 1 (admin), 2 (domain-admin), and 0 (user).")
- private Long accountType;
-
- @IdentityMapper(entityTableName="account")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list account by account ID")
- private Long id;
-
- @Parameter(name=ApiConstants.IS_CLEANUP_REQUIRED, type=CommandType.BOOLEAN, description="list accounts by cleanuprequred attribute (values are true or false)")
- private Boolean cleanupRequired;
-
- @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="list account by account name")
- private String searchName;
-
- @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list accounts by state. Valid states are enabled, disabled, and locked.")
- private String state;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getAccountType() {
- return accountType;
- }
-
- public Long getId() {
- return id;
- }
-
- public Boolean isCleanupRequired() {
- return cleanupRequired;
- }
-
- public String getSearchName() {
- return searchName;
- }
-
- public String getState() {
- return state;
- }
-
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public void execute(){
- Pair<List<? extends Account>, Integer> accounts = _accountService.searchForAccounts(this);
- ListResponse<AccountResponse> response = new ListResponse<AccountResponse>();
- List<AccountResponse> accountResponses = new ArrayList<AccountResponse>();
- for (Account account : accounts.first()) {
- AccountResponse acctResponse = _responseGenerator.createAccountResponse(account);
- acctResponse.setObjectName("account");
- accountResponses.add(acctResponse);
- }
- response.setResponses(accountResponses, accounts.second());
- response.setResponseName(getCommandName());
-
- this.setResponseObject(response);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/af28c069/api/src/org/apache/cloudstack/api/user/account/command/ListProjectAccountsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/account/command/ListProjectAccountsCmd.java b/api/src/org/apache/cloudstack/api/user/account/command/ListProjectAccountsCmd.java
deleted file mode 100644
index 3ad7fe6..0000000
--- a/api/src/org/apache/cloudstack/api/user/account/command/ListProjectAccountsCmd.java
+++ /dev/null
@@ -1,95 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.api.user.account.command;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseListCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import com.cloud.api.response.ListResponse;
-import com.cloud.api.response.ProjectAccountResponse;
-import com.cloud.api.response.ProjectResponse;
-import com.cloud.projects.ProjectAccount;
-import com.cloud.user.Account;
-import com.cloud.utils.Pair;
-
-@Implementation(description="Lists project's accounts", responseObject=ProjectResponse.class, since="3.0.0")
-public class ListProjectAccountsCmd extends BaseListCmd {
- public static final Logger s_logger = Logger.getLogger(ListProjectAccountsCmd.class.getName());
-
- private static final String s_name = "listprojectaccountsresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="projects")
- @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, required=true, description="id of the project")
- private Long projectId;
-
- @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="list accounts of the project by account name")
- private String accountName;
-
- @Parameter(name=ApiConstants.ROLE, type=CommandType.STRING, description="list accounts of the project by role")
- private String role;
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public String getAccountName() {
- return accountName;
- }
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- //TODO - return project entity ownerId
-
- return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
- }
-
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public void execute(){
- Pair<List<? extends ProjectAccount>, Integer> projectAccounts = _projectService.listProjectAccounts(projectId,
- accountName, role, this.getStartIndex(), this.getPageSizeVal());
- ListResponse<ProjectAccountResponse> response = new ListResponse<ProjectAccountResponse>();
- List<ProjectAccountResponse> projectResponses = new ArrayList<ProjectAccountResponse>();
- for (ProjectAccount projectAccount : projectAccounts.first()) {
- ProjectAccountResponse projectAccountResponse = _responseGenerator.createProjectAccountResponse(projectAccount);
- projectResponses.add(projectAccountResponse);
- }
- response.setResponses(projectResponses, projectAccounts.second());
- response.setResponseName(getCommandName());
-
- this.setResponseObject(response);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/af28c069/api/src/org/apache/cloudstack/api/user/address/command/AssociateIPAddrCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/address/command/AssociateIPAddrCmd.java b/api/src/org/apache/cloudstack/api/user/address/command/AssociateIPAddrCmd.java
deleted file mode 100644
index ca98a4b..0000000
--- a/api/src/org/apache/cloudstack/api/user/address/command/AssociateIPAddrCmd.java
+++ /dev/null
@@ -1,273 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.api.user.address.command;
-
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseAsyncCmd;
-import org.apache.cloudstack.api.BaseAsyncCreateCmd;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.IPAddressResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.dc.DataCenter;
-import com.cloud.dc.DataCenter.NetworkType;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientAddressCapacityException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.IpAddress;
-import com.cloud.network.Network;
-import com.cloud.network.vpc.Vpc;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Acquires and associates a public IP to an account.", responseObject=IPAddressResponse.class)
-public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
- public static final Logger s_logger = Logger.getLogger(AssociateIPAddrCmd.class.getName());
- private static final String s_name = "associateipaddressresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING,
- description="the account to associate with this IP address")
- private String accountName;
-
- @IdentityMapper(entityTableName="domain")
- @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG,
- description="the ID of the domain to associate with this IP address")
- private Long domainId;
-
- @IdentityMapper(entityTableName="data_center")
- @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG,
- description="the ID of the availability zone you want to acquire an public IP address from")
- private Long zoneId;
-
- @IdentityMapper(entityTableName="networks")
- @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG,
- description="The network this ip address should be associated to.")
- private Long networkId;
-
- @IdentityMapper(entityTableName="projects")
- @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG,
- description="Deploy vm for the project")
- private Long projectId;
-
- @IdentityMapper(entityTableName="vpc")
- @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="the VPC you want the ip address to " +
- "be associated with")
- private Long vpcId;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public String getEntityTable() {
- return "user_ip_address";
- }
-
- public String getAccountName() {
- if (accountName != null) {
- return accountName;
- }
- return UserContext.current().getCaller().getAccountName();
- }
-
- public long getDomainId() {
- if (domainId != null) {
- return domainId;
- }
- return UserContext.current().getCaller().getDomainId();
- }
-
- private long getZoneId() {
- if (zoneId != null) {
- return zoneId;
- } else if (vpcId != null) {
- Vpc vpc = _entityMgr.findById(Vpc.class, vpcId);
- if (vpc != null) {
- return vpc.getZoneId();
- }
- } else if (networkId != null) {
- Network ntwk = _entityMgr.findById(Network.class, networkId);
- if (ntwk != null) {
- return ntwk.getDataCenterId();
- }
- }
-
- throw new InvalidParameterValueException("Unable to figure out zone to assign ip to");
- }
-
- public Long getVpcId() {
- return vpcId;
- }
-
- public Long getNetworkId() {
- if (vpcId != null) {
- return null;
- }
-
- if (networkId != null) {
- return networkId;
- }
- Long zoneId = getZoneId();
-
- if (zoneId == null) {
- return null;
- }
-
- DataCenter zone = _configService.getZone(zoneId);
- if (zone.getNetworkType() == NetworkType.Advanced) {
- List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(),
- _accountService.getAccount(getEntityOwnerId()));
- if (networks.size() == 0) {
- String domain = _domainService.getDomain(getDomainId()).getName();
- throw new InvalidParameterValueException("Account name=" + getAccountName() + " domain=" + domain +
- " doesn't have virtual networks in zone=" + zone.getName());
- }
-
- if (networks.size() < 1) {
- throw new InvalidParameterValueException("Account doesn't have any Isolated networks in the zone");
- } else if (networks.size() > 1) {
- throw new InvalidParameterValueException("Account has more than one Isolated network in the zone");
- }
-
- return networks.get(0).getId();
- } else {
- Network defaultGuestNetwork = _networkService.getExclusiveGuestNetwork(zoneId);
- if (defaultGuestNetwork == null) {
- throw new InvalidParameterValueException("Unable to find a default Guest network for account " +
- getAccountName() + " in domain id=" + getDomainId());
- } else {
- return defaultGuestNetwork.getId();
- }
- }
- }
-
- @Override
- public long getEntityOwnerId() {
- Account caller = UserContext.current().getCaller();
- if (accountName != null && domainId != null) {
- Account account = _accountService.finalizeOwner(caller, accountName, domainId, projectId);
- return account.getId();
- } else if (networkId != null){
- Network network = _networkService.getNetwork(networkId);
- return network.getAccountId();
- } else if (vpcId != null) {
- Vpc vpc = _vpcService.getVpc(getVpcId());
- if (vpc == null) {
- throw new InvalidParameterValueException("Can't find Enabled vpc by id specified");
- }
- return vpc.getAccountId();
- }
-
- return caller.getAccountId();
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_NET_IP_ASSIGN;
- }
-
- @Override
- public String getEventDescription() {
- return "associating ip to network id: " + getNetworkId() + " in zone " + getZoneId();
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- public static String getResultObjectName() {
- return "addressinfo";
- }
-
- @Override
- public void create() throws ResourceAllocationException{
- try {
- IpAddress ip = _networkService.allocateIP(_accountService.getAccount(getEntityOwnerId()), false, getZoneId());
- if (ip != null) {
- this.setEntityId(ip.getId());
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to allocate ip address");
- }
- } catch (ConcurrentOperationException ex) {
- s_logger.warn("Exception: ", ex);
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
- } catch (InsufficientAddressCapacityException ex) {
- s_logger.info(ex);
- s_logger.trace(ex);
- throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
- }
- }
-
- @Override
- public void execute() throws ResourceUnavailableException, ResourceAllocationException,
- ConcurrentOperationException, InsufficientCapacityException {
- UserContext.current().setEventDetails("Ip Id: " + getEntityId());
-
- IpAddress result = null;
-
- if (getVpcId() != null) {
- result = _vpcService.associateIPToVpc(getEntityId(), getVpcId());
- } else if (getNetworkId() != null) {
- result = _networkService.associateIPToNetwork(getEntityId(), getNetworkId());
- }
-
- if (result != null) {
- IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(result);
- ipResponse.setResponseName(getCommandName());
- this.setResponseObject(ipResponse);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to assign ip address");
- }
- }
-
-
- @Override
- public String getSyncObjType() {
- return BaseAsyncCmd.networkSyncObject;
- }
-
- @Override
- public Long getSyncObjId() {
- return getNetworkId();
- }
-
- @Override
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.IpAddress;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/af28c069/api/src/org/apache/cloudstack/api/user/address/command/DisassociateIPAddrCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/address/command/DisassociateIPAddrCmd.java b/api/src/org/apache/cloudstack/api/user/address/command/DisassociateIPAddrCmd.java
deleted file mode 100644
index 265b296..0000000
--- a/api/src/org/apache/cloudstack/api/user/address/command/DisassociateIPAddrCmd.java
+++ /dev/null
@@ -1,141 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.api.user.address.command;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseAsyncCmd;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.SuccessResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.InsufficientAddressCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.network.IpAddress;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Disassociates an ip address from the account.", responseObject=SuccessResponse.class)
-public class DisassociateIPAddrCmd extends BaseAsyncCmd {
- public static final Logger s_logger = Logger.getLogger(DisassociateIPAddrCmd.class.getName());
-
- private static final String s_name = "disassociateipaddressresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="user_ip_address")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the id of the public ip address" +
- " to disassociate")
- private Long id;
-
- // unexposed parameter needed for events logging
- @IdentityMapper(entityTableName="account")
- @Parameter(name=ApiConstants.ACCOUNT_ID, type=CommandType.LONG, expose=false)
- private Long ownerId;
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getIpAddressId() {
- return id;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public void execute() throws InsufficientAddressCapacityException{
- UserContext.current().setEventDetails("Ip Id: " + getIpAddressId());
- boolean result = _networkService.releaseIpAddress(getIpAddressId());
- if (result) {
- SuccessResponse response = new SuccessResponse(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to disassociate ip address");
- }
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_NET_IP_RELEASE;
- }
-
- @Override
- public String getEventDescription() {
- return ("Disassociating ip address with id=" + id);
- }
-
- @Override
- public long getEntityOwnerId() {
- if (ownerId == null) {
- IpAddress ip = getIpAddress(id);
- if (ip == null) {
- throw new InvalidParameterValueException("Unable to find ip address by id=" + id);
- }
- ownerId = ip.getAccountId();
- }
-
- if (ownerId == null) {
- return Account.ACCOUNT_ID_SYSTEM;
- }
- return ownerId;
- }
-
- @Override
- public String getSyncObjType() {
- return BaseAsyncCmd.networkSyncObject;
- }
-
- @Override
- public Long getSyncObjId() {
- IpAddress ip = getIpAddress(id);
- return ip.getAssociatedWithNetworkId();
- }
-
- private IpAddress getIpAddress(long id) {
- IpAddress ip = _entityMgr.findById(IpAddress.class, id);
-
- if (ip == null) {
- throw new InvalidParameterValueException("Unable to find ip address by id=" + id);
- } else {
- return ip;
- }
- }
-
- @Override
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.IpAddress;
- }
-
- @Override
- public Long getInstanceId() {
- return getIpAddressId();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/af28c069/api/src/org/apache/cloudstack/api/user/address/command/ListPublicIpAddressesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/address/command/ListPublicIpAddressesCmd.java b/api/src/org/apache/cloudstack/api/user/address/command/ListPublicIpAddressesCmd.java
deleted file mode 100644
index 85201f8..0000000
--- a/api/src/org/apache/cloudstack/api/user/address/command/ListPublicIpAddressesCmd.java
+++ /dev/null
@@ -1,179 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.api.user.address.command;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import com.cloud.api.response.IPAddressResponse;
-import com.cloud.api.response.ListResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.network.IpAddress;
-import com.cloud.utils.Pair;
-
-
-@Implementation(description="Lists all public ip addresses", responseObject=IPAddressResponse.class)
-public class ListPublicIpAddressesCmd extends BaseListTaggedResourcesCmd {
- public static final Logger s_logger = Logger.getLogger(ListPublicIpAddressesCmd.class.getName());
-
- private static final String s_name = "listpublicipaddressesresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @Parameter(name=ApiConstants.ALLOCATED_ONLY, type=CommandType.BOOLEAN, description="limits search results to allocated public IP addresses")
- private Boolean allocatedOnly;
-
- @Parameter(name=ApiConstants.FOR_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="the virtual network for the IP address")
- private Boolean forVirtualNetwork;
-
- @IdentityMapper(entityTableName="user_ip_address")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="lists ip address by id")
- private Long id;
-
- @Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, description="lists the specified IP address")
- private String ipAddress;
-
- @IdentityMapper(entityTableName="vlan")
- @Parameter(name=ApiConstants.VLAN_ID, type=CommandType.LONG, description="lists all public IP addresses by VLAN ID")
- private Long vlanId;
-
- @IdentityMapper(entityTableName="data_center")
- @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="lists all public IP addresses by Zone ID")
- private Long zoneId;
-
- @Parameter(name=ApiConstants.FOR_LOAD_BALANCING, type=CommandType.BOOLEAN, description="list only ips used for load balancing")
- private Boolean forLoadBalancing;
-
- @IdentityMapper(entityTableName="physical_network")
- @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="lists all public IP addresses by physical network id")
- private Long physicalNetworkId;
-
- @IdentityMapper(entityTableName="networks")
- @Parameter(name=ApiConstants.ASSOCIATED_NETWORK_ID, type=CommandType.LONG, description="lists all public IP addresses associated to the network specified")
- private Long associatedNetworkId;
-
- @Parameter(name=ApiConstants.IS_SOURCE_NAT, type=CommandType.BOOLEAN, description="list only source nat ip addresses")
- private Boolean isSourceNat;
-
- @Parameter(name=ApiConstants.IS_STATIC_NAT, type=CommandType.BOOLEAN, description="list only static nat ip addresses")
- private Boolean isStaticNat;
-
- @IdentityMapper(entityTableName="vpc")
- @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="List ips belonging to the VPC")
- private Long vpcId;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
- public Long getId() {
- return id;
- }
-
- public Boolean isAllocatedOnly() {
- return allocatedOnly;
- }
-
- public Boolean isForVirtualNetwork() {
- return forVirtualNetwork;
- }
-
- public String getIpAddress() {
- return ipAddress;
- }
-
- public Long getVlanId() {
- return vlanId;
- }
-
- public Long getZoneId() {
- return zoneId;
- }
-
- public Long getPhysicalNetworkId() {
- return physicalNetworkId;
- }
-
- public Long getAssociatedNetworkId() {
- return associatedNetworkId;
- }
-
- public Boolean getIsSourceNat() {
- return isSourceNat;
- }
-
- public Boolean getIsStaticNat() {
- return isStaticNat;
- }
-
- public Long getVpcId() {
- return vpcId;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public void execute(){
- Pair<List<? extends IpAddress>, Integer> result = _mgr.searchForIPAddresses(this);
- ListResponse<IPAddressResponse> response = new ListResponse<IPAddressResponse>();
- List<IPAddressResponse> ipAddrResponses = new ArrayList<IPAddressResponse>();
- for (IpAddress ipAddress : result.first()) {
- IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ipAddress);
- ipResponse.setObjectName("publicipaddress");
- ipAddrResponses.add(ipResponse);
- }
-
- response.setResponses(ipAddrResponses, result.second());
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- }
-
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.IpAddress;
- }
-
-
- public Boolean isForLoadBalancing() {
- return forLoadBalancing;
- }
-
- public Boolean getAllocatedOnly() {
- return allocatedOnly;
- }
-
- public Boolean getForVirtualNetwork() {
- return forVirtualNetwork;
- }
-
- public Boolean getForLoadBalancing() {
- return forLoadBalancing;
- }
-}