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/04 11:02:57 UTC

[51/55] [abbrv] api_refactor: refactor vpn and vm apis

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/BaseListCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/BaseListCmd.java b/api/src/org/apache/cloudstack/api/BaseListCmd.java
new file mode 100755
index 0000000..19cf718
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/BaseListCmd.java
@@ -0,0 +1,108 @@
+// 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;
+
+import com.cloud.async.AsyncJob;
+import com.cloud.exception.InvalidParameterValueException;
+
+public abstract class BaseListCmd extends BaseCmd {
+
+    private static Long MAX_PAGESIZE = null;
+    public static Long PAGESIZE_UNLIMITED = -1L;
+
+    // ///////////////////////////////////////////////////
+    // ///////// BaseList API parameters /////////////////
+    // ///////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.KEYWORD, type = CommandType.STRING, description = "List by keyword")
+    private String keyword;
+
+    // FIXME: Need to be able to specify next/prev/first/last, so Integer might not be right
+    @Parameter(name = ApiConstants.PAGE, type = CommandType.INTEGER)
+    private Integer page;
+
+    @Parameter(name = ApiConstants.PAGE_SIZE, type = CommandType.INTEGER)
+    private Integer pageSize;
+
+    // ///////////////////////////////////////////////////
+    // ///////////////// Accessors ///////////////////////
+    // ///////////////////////////////////////////////////
+
+    public String getKeyword() {
+        return keyword;
+    }
+
+    public Integer getPage() {
+        return page;
+    }
+
+    public Integer getPageSize() {
+        if (pageSize != null && MAX_PAGESIZE != null && pageSize.longValue() > MAX_PAGESIZE.longValue()) {
+            throw new InvalidParameterValueException("Page size can't exceed max allowed page size value: " + MAX_PAGESIZE.longValue());
+        }
+
+        if (pageSize != null && pageSize.longValue() == PAGESIZE_UNLIMITED && page != null) {
+            throw new InvalidParameterValueException("Can't specify page parameter when pagesize is -1 (Unlimited)");
+        }
+
+        return pageSize;
+    }
+
+    static void configure() {
+        if (_configService.getDefaultPageSize().longValue() != PAGESIZE_UNLIMITED) {
+            MAX_PAGESIZE = _configService.getDefaultPageSize();
+        }
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        // no owner is needed for list command
+        return 0;
+    }
+
+    public Long getPageSizeVal() {
+        Long defaultPageSize = MAX_PAGESIZE;
+        Integer pageSizeInt = getPageSize();
+        if (pageSizeInt != null) {
+            if (pageSizeInt.longValue() == PAGESIZE_UNLIMITED) {
+                defaultPageSize = null;
+            } else {
+                defaultPageSize = pageSizeInt.longValue();
+            }
+        }
+        return defaultPageSize;
+    }
+
+    public Long getStartIndex() {
+        Long startIndex = Long.valueOf(0);
+        Long pageSizeVal = getPageSizeVal();
+
+        if (pageSizeVal == null) {
+            startIndex = null;
+        } else if (page != null) {
+            int pageNum = page.intValue();
+            if (pageNum > 0) {
+                startIndex = Long.valueOf(pageSizeVal * (pageNum - 1));
+            }
+        }
+        return startIndex;
+    }
+
+    public AsyncJob.Type getInstanceType() {
+        return AsyncJob.Type.None;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/BaseListDomainResourcesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/BaseListDomainResourcesCmd.java b/api/src/org/apache/cloudstack/api/BaseListDomainResourcesCmd.java
new file mode 100644
index 0000000..709d107
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/BaseListDomainResourcesCmd.java
@@ -0,0 +1,45 @@
+// 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;
+
+public abstract class BaseListDomainResourcesCmd extends BaseListCmd {
+
+    @Parameter(name = ApiConstants.LIST_ALL, type = CommandType.BOOLEAN, description = "If set to false, " +
+            "list only resources belonging to the command's caller; if set to true - list resources that the caller is authorized to see. Default value is false")
+    private Boolean listAll;
+
+    @IdentityMapper(entityTableName = "domain")
+    @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.LONG, description = "list only resources" +
+            " belonging to the domain specified")
+    private Long domainId;
+
+    @Parameter(name = ApiConstants.IS_RECURSIVE, type = CommandType.BOOLEAN, description = "defaults to false," +
+            " but if true, lists all resources from the parent specified by the domainId till leaves.")
+    private Boolean recursive;
+
+    public boolean listAll() {
+        return listAll == null ? false : listAll;
+    }
+
+    public boolean isRecursive() {
+        return recursive == null ? false : recursive;
+    }
+
+    public Long getDomainId() {
+        return domainId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/BaseListProjectAndAccountResourcesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/BaseListProjectAndAccountResourcesCmd.java b/api/src/org/apache/cloudstack/api/BaseListProjectAndAccountResourcesCmd.java
new file mode 100644
index 0000000..d5232bc
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/BaseListProjectAndAccountResourcesCmd.java
@@ -0,0 +1,28 @@
+// 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;
+
+public abstract class BaseListProjectAndAccountResourcesCmd extends BaseListAccountResourcesCmd {
+
+    @IdentityMapper(entityTableName = "projects")
+    @Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.LONG, description = "list objects by project")
+    private Long projectId;
+
+    public Long getProjectId() {
+        return projectId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/BaseListTaggedResourcesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/BaseListTaggedResourcesCmd.java b/api/src/org/apache/cloudstack/api/BaseListTaggedResourcesCmd.java
new file mode 100644
index 0000000..88176a5
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/BaseListTaggedResourcesCmd.java
@@ -0,0 +1,48 @@
+// 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;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import com.cloud.exception.InvalidParameterValueException;
+
+public abstract class BaseListTaggedResourcesCmd extends BaseListProjectAndAccountResourcesCmd{
+    @Parameter(name = ApiConstants.TAGS, type = CommandType.MAP, description = "List resources by tags (key/value pairs)")
+    private Map tags;
+
+    public Map<String, String> getTags() {
+        Map<String, String> tagsMap = null;
+        if (tags != null && !tags.isEmpty()) {
+            tagsMap = new HashMap<String, String>();
+            Collection<?> servicesCollection = tags.values();
+            Iterator<?> iter = servicesCollection.iterator();
+            while (iter.hasNext()) {
+                HashMap<String, String> services = (HashMap<String, String>) iter.next();
+                String key = services.get("key");
+                String value = services.get("value");
+                if (value == null) {
+                    throw new InvalidParameterValueException("No value is passed in for key " + key);
+                }
+                tagsMap.put(key, value);
+            }
+        }
+        return tagsMap;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/Identity.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/Identity.java b/api/src/org/apache/cloudstack/api/Identity.java
new file mode 100644
index 0000000..22d23b7
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/Identity.java
@@ -0,0 +1,21 @@
+// 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;
+
+public interface Identity {
+    String getUuid();
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/IdentityMapper.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/IdentityMapper.java b/api/src/org/apache/cloudstack/api/IdentityMapper.java
new file mode 100644
index 0000000..0403ff7
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/IdentityMapper.java
@@ -0,0 +1,29 @@
+// 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;
+
+import static java.lang.annotation.ElementType.FIELD;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ FIELD })
+public @interface IdentityMapper {
+    String entityTableName();
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/IdentityService.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/IdentityService.java b/api/src/org/apache/cloudstack/api/IdentityService.java
new file mode 100644
index 0000000..5160884
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/IdentityService.java
@@ -0,0 +1,25 @@
+// 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;
+
+public interface IdentityService {
+    Long getIdentityId(IdentityMapper mapper, String identityString);
+
+    Long getIdentityId(String tableName, String identityString);
+
+    String getIdentityUuid(String tableName, String identityString);
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/Implementation.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/Implementation.java b/api/src/org/apache/cloudstack/api/Implementation.java
new file mode 100644
index 0000000..ec8e867
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/Implementation.java
@@ -0,0 +1,39 @@
+// 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;
+
+import static java.lang.annotation.ElementType.TYPE;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import com.cloud.api.response.BaseResponse;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ TYPE })
+public @interface Implementation {
+    Class<? extends BaseResponse> responseObject();
+
+    String description() default "";
+
+    String usage() default "";
+
+    boolean includeInApiDoc() default true;
+
+    String since() default "";
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/Parameter.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/Parameter.java b/api/src/org/apache/cloudstack/api/Parameter.java
new file mode 100644
index 0000000..2364d4f
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/Parameter.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;
+
+import static java.lang.annotation.ElementType.FIELD;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.cloudstack.api.BaseCmd.CommandType;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ FIELD })
+public @interface Parameter {
+    String name() default "";
+
+    String description() default "";
+
+    boolean required() default false;
+
+    CommandType type() default CommandType.OBJECT;
+
+    CommandType collectionType() default CommandType.OBJECT;
+
+    boolean expose() default true;
+
+    boolean includeInApiDoc() default true;
+
+    int length() default 255;
+
+    String since() default "";
+
+    Class<?>[] resourceType() default Object.class;
+
+    String retrieveMethod() default "getById";
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/PlugService.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/PlugService.java b/api/src/org/apache/cloudstack/api/PlugService.java
new file mode 100644
index 0000000..00032e3
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/PlugService.java
@@ -0,0 +1,31 @@
+// 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;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import com.cloud.utils.component.PluggableService;
+
+@Target(FIELD)
+@Retention(RUNTIME)
+public @interface PlugService {
+    Class<? extends PluggableService> pluggableService() default PluggableService.class;
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/ResponseGenerator.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
new file mode 100755
index 0000000..d711fcf
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
@@ -0,0 +1,364 @@
+// 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;
+
+import java.text.DecimalFormat;
+import java.util.EnumSet;
+import java.util.List;
+
+import org.apache.cloudstack.api.ApiConstants.HostDetails;
+import org.apache.cloudstack.api.ApiConstants.VMDetails;
+import com.cloud.api.commands.QueryAsyncJobResultCmd;
+import com.cloud.api.response.AccountResponse;
+import com.cloud.api.response.AsyncJobResponse;
+import com.cloud.api.response.AutoScalePolicyResponse;
+import com.cloud.api.response.AutoScaleVmGroupResponse;
+import com.cloud.api.response.AutoScaleVmProfileResponse;
+import com.cloud.api.response.CapacityResponse;
+import com.cloud.api.response.ClusterResponse;
+import com.cloud.api.response.ConditionResponse;
+import com.cloud.api.response.ConfigurationResponse;
+import com.cloud.api.response.CounterResponse;
+import com.cloud.api.response.CreateCmdResponse;
+import com.cloud.api.response.DiskOfferingResponse;
+import com.cloud.api.response.DomainResponse;
+import com.cloud.api.response.DomainRouterResponse;
+import com.cloud.api.response.EventResponse;
+import com.cloud.api.response.ExtractResponse;
+import com.cloud.api.response.FirewallResponse;
+import com.cloud.api.response.FirewallRuleResponse;
+import com.cloud.api.response.HostResponse;
+import com.cloud.api.response.HypervisorCapabilitiesResponse;
+import com.cloud.api.response.IPAddressResponse;
+import com.cloud.api.response.InstanceGroupResponse;
+import com.cloud.api.response.IpForwardingRuleResponse;
+import com.cloud.api.response.LBStickinessResponse;
+import com.cloud.api.response.LDAPConfigResponse;
+import com.cloud.api.response.ListResponse;
+import com.cloud.api.response.LoadBalancerResponse;
+import com.cloud.api.response.NetworkACLResponse;
+import com.cloud.api.response.NetworkOfferingResponse;
+import com.cloud.api.response.NetworkResponse;
+import com.cloud.api.response.PhysicalNetworkResponse;
+import com.cloud.api.response.PodResponse;
+import com.cloud.api.response.PrivateGatewayResponse;
+import com.cloud.api.response.ProjectAccountResponse;
+import com.cloud.api.response.ProjectInvitationResponse;
+import com.cloud.api.response.ProjectResponse;
+import com.cloud.api.response.ProviderResponse;
+import com.cloud.api.response.RemoteAccessVpnResponse;
+import com.cloud.api.response.ResourceCountResponse;
+import com.cloud.api.response.ResourceLimitResponse;
+import com.cloud.api.response.ResourceTagResponse;
+import com.cloud.api.response.SecurityGroupResponse;
+import com.cloud.api.response.ServiceOfferingResponse;
+import com.cloud.api.response.ServiceResponse;
+import com.cloud.api.response.Site2SiteCustomerGatewayResponse;
+import com.cloud.api.response.Site2SiteVpnConnectionResponse;
+import com.cloud.api.response.Site2SiteVpnGatewayResponse;
+import com.cloud.api.response.SnapshotPolicyResponse;
+import com.cloud.api.response.SnapshotResponse;
+import com.cloud.api.response.StaticRouteResponse;
+import com.cloud.api.response.StorageNetworkIpRangeResponse;
+import com.cloud.api.response.StoragePoolResponse;
+import com.cloud.api.response.SwiftResponse;
+import com.cloud.api.response.SystemVmInstanceResponse;
+import com.cloud.api.response.SystemVmResponse;
+import com.cloud.api.response.TemplatePermissionsResponse;
+import com.cloud.api.response.TemplateResponse;
+import com.cloud.api.response.TrafficTypeResponse;
+import com.cloud.api.response.UserResponse;
+import com.cloud.api.response.UserVmResponse;
+import com.cloud.api.response.VirtualRouterProviderResponse;
+import com.cloud.api.response.VlanIpRangeResponse;
+import com.cloud.api.response.VolumeResponse;
+import com.cloud.api.response.VpcOfferingResponse;
+import com.cloud.api.response.VpcResponse;
+import com.cloud.api.response.VpnUsersResponse;
+import com.cloud.api.response.ZoneResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.capacity.Capacity;
+import com.cloud.configuration.Configuration;
+import com.cloud.configuration.ResourceCount;
+import com.cloud.configuration.ResourceLimit;
+import com.cloud.dc.DataCenter;
+import com.cloud.dc.Pod;
+import com.cloud.dc.StorageNetworkIpRange;
+import com.cloud.dc.Vlan;
+import com.cloud.domain.Domain;
+import com.cloud.event.Event;
+import com.cloud.host.Host;
+import com.cloud.hypervisor.HypervisorCapabilities;
+import com.cloud.network.IpAddress;
+import com.cloud.network.Network;
+import com.cloud.network.Network.Service;
+import com.cloud.network.PhysicalNetwork;
+import com.cloud.network.PhysicalNetworkServiceProvider;
+import com.cloud.network.PhysicalNetworkTrafficType;
+import com.cloud.network.RemoteAccessVpn;
+import com.cloud.network.Site2SiteCustomerGateway;
+import com.cloud.network.Site2SiteVpnConnection;
+import com.cloud.network.Site2SiteVpnGateway;
+import com.cloud.network.VirtualRouterProvider;
+import com.cloud.network.VpnUser;
+import com.cloud.network.as.AutoScalePolicy;
+import com.cloud.network.as.AutoScaleVmGroup;
+import com.cloud.network.as.AutoScaleVmProfile;
+import com.cloud.network.as.Condition;
+import com.cloud.network.as.Counter;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.rules.FirewallRule;
+import com.cloud.network.rules.LoadBalancer;
+import com.cloud.network.rules.PortForwardingRule;
+import com.cloud.network.rules.StaticNatRule;
+import com.cloud.network.rules.StickinessPolicy;
+import com.cloud.network.security.SecurityGroup;
+import com.cloud.network.security.SecurityGroupRules;
+import com.cloud.network.security.SecurityRule;
+import com.cloud.network.vpc.PrivateGateway;
+import com.cloud.network.vpc.StaticRoute;
+import com.cloud.network.vpc.Vpc;
+import com.cloud.network.vpc.VpcOffering;
+import com.cloud.offering.DiskOffering;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.offering.ServiceOffering;
+import com.cloud.org.Cluster;
+import com.cloud.projects.Project;
+import com.cloud.projects.ProjectAccount;
+import com.cloud.projects.ProjectInvitation;
+import com.cloud.server.ResourceTag;
+import com.cloud.storage.Snapshot;
+import com.cloud.storage.StoragePool;
+import com.cloud.storage.Swift;
+import com.cloud.storage.Volume;
+import com.cloud.storage.snapshot.SnapshotPolicy;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.user.Account;
+import com.cloud.user.User;
+import com.cloud.user.UserAccount;
+import com.cloud.uservm.UserVm;
+import com.cloud.vm.InstanceGroup;
+import com.cloud.vm.VirtualMachine;
+
+public interface ResponseGenerator {
+    UserResponse createUserResponse(UserAccount user);
+
+    AccountResponse createAccountResponse(Account account);
+
+    DomainResponse createDomainResponse(Domain domain);
+
+    DiskOfferingResponse createDiskOfferingResponse(DiskOffering offering);
+
+    ResourceLimitResponse createResourceLimitResponse(ResourceLimit limit);
+
+    ResourceCountResponse createResourceCountResponse(ResourceCount resourceCount);
+
+    ServiceOfferingResponse createServiceOfferingResponse(ServiceOffering offering);
+
+    ConfigurationResponse createConfigurationResponse(Configuration cfg);
+
+    SnapshotResponse createSnapshotResponse(Snapshot snapshot);
+
+    SnapshotPolicyResponse createSnapshotPolicyResponse(SnapshotPolicy policy);
+
+    List<UserVmResponse> createUserVmResponse(String objectName, UserVm... userVms);
+
+    List<UserVmResponse> createUserVmResponse(String objectName, EnumSet<VMDetails> details, UserVm... userVms);
+
+    SystemVmResponse createSystemVmResponse(VirtualMachine systemVM);
+
+    DomainRouterResponse createDomainRouterResponse(VirtualRouter router);
+
+    HostResponse createHostResponse(Host host, EnumSet<HostDetails> details);
+
+    HostResponse createHostResponse(Host host);
+
+    VlanIpRangeResponse createVlanIpRangeResponse(Vlan vlan);
+
+    IPAddressResponse createIPAddressResponse(IpAddress ipAddress);
+
+    LoadBalancerResponse createLoadBalancerResponse(LoadBalancer loadBalancer);
+
+    LBStickinessResponse createLBStickinessPolicyResponse(List<? extends StickinessPolicy> stickinessPolicies, LoadBalancer lb);
+
+    LBStickinessResponse createLBStickinessPolicyResponse(StickinessPolicy stickinessPolicy, LoadBalancer lb);
+
+    PodResponse createPodResponse(Pod pod, Boolean showCapacities);
+
+    ZoneResponse createZoneResponse(DataCenter dataCenter, Boolean showCapacities);
+
+    VolumeResponse createVolumeResponse(Volume volume);
+
+    InstanceGroupResponse createInstanceGroupResponse(InstanceGroup group);
+
+    StoragePoolResponse createStoragePoolResponse(StoragePool pool);
+
+    ClusterResponse createClusterResponse(Cluster cluster, Boolean showCapacities);
+
+    FirewallRuleResponse createPortForwardingRuleResponse(PortForwardingRule fwRule);
+
+    IpForwardingRuleResponse createIpForwardingRuleResponse(StaticNatRule fwRule);
+
+    User findUserById(Long userId);
+
+    UserVm findUserVmById(Long vmId);
+
+    Volume findVolumeById(Long volumeId);
+
+    Account findAccountByNameDomain(String accountName, Long domainId);
+
+    VirtualMachineTemplate findTemplateById(Long templateId);
+
+    Host findHostById(Long hostId);
+
+    List<TemplateResponse> createTemplateResponses(long templateId, long zoneId, boolean readyOnly);
+
+    VpnUsersResponse createVpnUserResponse(VpnUser user);
+
+    RemoteAccessVpnResponse createRemoteAccessVpnResponse(RemoteAccessVpn vpn);
+
+    List<TemplateResponse> createTemplateResponses(long templateId, Long zoneId, boolean readyOnly);
+
+    List<TemplateResponse> createTemplateResponses(long templateId, Long snapshotId, Long volumeId, boolean readyOnly);
+
+    ListResponse<SecurityGroupResponse> createSecurityGroupResponses(List<? extends SecurityGroupRules> networkGroups);
+
+    SecurityGroupResponse createSecurityGroupResponseFromSecurityGroupRule(List<? extends SecurityRule> SecurityRules);
+
+    SecurityGroupResponse createSecurityGroupResponse(SecurityGroup group);
+
+    ExtractResponse createExtractResponse(Long uploadId, Long id, Long zoneId, Long accountId, String mode);
+
+    String toSerializedString(CreateCmdResponse response, String responseType);
+
+    AsyncJobResponse createAsyncJobResponse(AsyncJob job);
+
+    EventResponse createEventResponse(Event event);
+
+    TemplateResponse createIsoResponse(VirtualMachineTemplate result);
+
+    List<CapacityResponse> createCapacityResponse(List<? extends Capacity> result, DecimalFormat format);
+
+    TemplatePermissionsResponse createTemplatePermissionsResponse(List<String> accountNames, Long id, boolean isAdmin);
+
+    AsyncJobResponse queryJobResult(QueryAsyncJobResultCmd cmd);
+
+    NetworkOfferingResponse createNetworkOfferingResponse(NetworkOffering offering);
+
+    NetworkResponse createNetworkResponse(Network network);
+
+    UserResponse createUserResponse(User user);
+
+    AccountResponse createUserAccountResponse(UserAccount user);
+
+    Long getSecurityGroupId(String groupName, long accountId);
+
+    List<TemplateResponse> createIsoResponses(long isoId, Long zoneId, boolean readyOnly);
+
+    ProjectResponse createProjectResponse(Project project);
+
+    List<TemplateResponse> createIsoResponses(VirtualMachineTemplate iso, long zoneId, boolean readyOnly);
+
+    List<TemplateResponse> createTemplateResponses(long templateId, Long vmId);
+
+    FirewallResponse createFirewallResponse(FirewallRule fwRule);
+
+    HypervisorCapabilitiesResponse createHypervisorCapabilitiesResponse(HypervisorCapabilities hpvCapabilities);
+
+    ProjectAccountResponse createProjectAccountResponse(ProjectAccount projectAccount);
+
+    ProjectInvitationResponse createProjectInvitationResponse(ProjectInvitation invite);
+
+    SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine systemVM);
+
+    SwiftResponse createSwiftResponse(Swift swift);
+
+    PhysicalNetworkResponse createPhysicalNetworkResponse(PhysicalNetwork result);
+
+    ServiceResponse createNetworkServiceResponse(Service service);
+
+    ProviderResponse createNetworkServiceProviderResponse(PhysicalNetworkServiceProvider result);
+
+    TrafficTypeResponse createTrafficTypeResponse(PhysicalNetworkTrafficType result);
+
+    VirtualRouterProviderResponse createVirtualRouterProviderResponse(VirtualRouterProvider result);
+
+    LDAPConfigResponse createLDAPConfigResponse(String hostname, Integer port, Boolean useSSL, String queryFilter, String baseSearch, String dn);
+
+    StorageNetworkIpRangeResponse createStorageNetworkIpRangeResponse(StorageNetworkIpRange result);
+
+    /**
+     * @param tableName TODO
+     * @param token
+     * @return
+     */
+    Long getIdentiyId(String tableName, String token);
+
+    /**
+     * @param resourceTag
+     * @param keyValueOnly TODO
+     * @return
+     */
+    ResourceTagResponse createResourceTagResponse(ResourceTag resourceTag, boolean keyValueOnly);
+
+    Site2SiteVpnGatewayResponse createSite2SiteVpnGatewayResponse(Site2SiteVpnGateway result);
+
+
+    /**
+     * @param offering
+     * @return
+     */
+    VpcOfferingResponse createVpcOfferingResponse(VpcOffering offering);
+
+    /**
+     * @param vpc
+     * @return
+     */
+    VpcResponse createVpcResponse(Vpc vpc);
+
+    /**
+     * @param networkACL
+     * @return
+     */
+    NetworkACLResponse createNetworkACLResponse(FirewallRule networkACL);
+
+    /**
+     * @param result
+     * @return
+     */
+    PrivateGatewayResponse createPrivateGatewayResponse(PrivateGateway result);
+
+    /**
+     * @param result
+     * @return
+     */
+    StaticRouteResponse createStaticRouteResponse(StaticRoute result);
+
+    Site2SiteCustomerGatewayResponse createSite2SiteCustomerGatewayResponse(Site2SiteCustomerGateway result);
+
+    Site2SiteVpnConnectionResponse createSite2SiteVpnConnectionResponse(Site2SiteVpnConnection result);
+
+    CounterResponse createCounterResponse(Counter ctr);
+
+    ConditionResponse createConditionResponse(Condition cndn);
+
+    AutoScalePolicyResponse createAutoScalePolicyResponse(AutoScalePolicy policy);
+
+    AutoScaleVmProfileResponse createAutoScaleVmProfileResponse(AutoScaleVmProfile profile);
+
+    AutoScaleVmGroupResponse createAutoScaleVmGroupResponse(AutoScaleVmGroup vmGroup);
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/ResponseObject.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ResponseObject.java b/api/src/org/apache/cloudstack/api/ResponseObject.java
new file mode 100644
index 0000000..ff03c20
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/ResponseObject.java
@@ -0,0 +1,78 @@
+// 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;
+
+public interface ResponseObject {
+    /**
+     * Get the name of the API response
+     *
+     * @return the name of the API response
+     */
+    String getResponseName();
+
+    /**
+     * Set the name of the API response
+     *
+     * @param name
+     */
+    void setResponseName(String name);
+
+    /**
+     * Get the name of the API object
+     *
+     * @return the name of the API object
+     */
+    String getObjectName();
+
+    /**
+     *
+     * @param name
+     */
+    void setObjectName(String name);
+
+    /**
+     * Returns the object Id
+     */
+    Long getObjectId();
+
+    /**
+     * Returns the job id
+     *
+     * @return
+     */
+    Long getJobId();
+
+    /**
+     * Sets the job id
+     *
+     * @param jobId
+     */
+    void setJobId(Long jobId);
+
+    /**
+     * Returns the job status
+     *
+     * @return
+     */
+    Integer getJobStatus();
+
+    /**
+     *
+     * @param jobStatus
+     */
+    void setJobStatus(Integer jobStatus);
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/ServerApiException.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ServerApiException.java b/api/src/org/apache/cloudstack/api/ServerApiException.java
new file mode 100644
index 0000000..70fd34e
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/ServerApiException.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;
+import com.cloud.utils.exception.RuntimeCloudException;
+
+@SuppressWarnings("serial")
+public class ServerApiException extends RuntimeCloudException {
+    private int _errorCode;
+    private String _description;
+
+    public ServerApiException() {
+        _errorCode = 0;
+        _description = null;
+    }
+
+    public ServerApiException(int errorCode, String description) {
+        _errorCode = errorCode;
+        _description = description;
+    }
+
+    public int getErrorCode() {
+        return _errorCode;
+    }
+
+    public void setErrorCode(int errorCode) {
+        _errorCode = errorCode;
+    }
+
+    public String getDescription() {
+        return _description;
+    }
+
+    public void setDescription(String description) {
+        _description = description;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/admin/vm/command/AssignVMCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/admin/vm/command/AssignVMCmd.java b/api/src/org/apache/cloudstack/api/admin/vm/command/AssignVMCmd.java
new file mode 100644
index 0000000..57b87fa
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/admin/vm/command/AssignVMCmd.java
@@ -0,0 +1,126 @@
+// 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.admin.vm.command;
+
+
+import java.util.List;
+
+import org.apache.cloudstack.api.user.vm.command.DeployVMCmd;
+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.UserVmResponse;
+import com.cloud.user.Account;
+import com.cloud.uservm.UserVm;
+
+@Implementation(description="Move a user VM to another user under same domain.", responseObject=UserVmResponse.class, since="3.0.0")
+public class AssignVMCmd extends BaseCmd  {
+    public static final Logger s_logger = Logger.getLogger(AssignVMCmd.class.getName());
+
+    private static final String s_name = "moveuservmresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @IdentityMapper(entityTableName="vm_instance")
+    @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, required=true, description="the vm ID of the user VM to be moved")
+    private Long virtualMachineId;
+
+    @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, required=true, description="account name of the new VM owner.")
+    private String accountName;
+
+    @IdentityMapper(entityTableName="domain")
+    @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, required=true, description="domain id of the new VM owner.")
+    private Long domainId;
+
+    //Network information
+    @IdentityMapper(entityTableName="networks")
+    @Parameter(name=ApiConstants.NETWORK_IDS, type=CommandType.LIST, collectionType=CommandType.LONG, description="list of network ids that will be part of VM network after move in advanced network setting.")
+    private List<Long> networkIds;
+
+    @IdentityMapper(entityTableName="security_group")
+    @Parameter(name=ApiConstants.SECURITY_GROUP_IDS, type=CommandType.LIST, collectionType=CommandType.LONG, description="comma separated list of security groups id that going to be applied to the virtual machine. Should be passed only when vm is moved in a zone with Basic Network support.")
+    private List<Long> securityGroupIdList;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getVmId() {
+        return virtualMachineId;
+    }
+
+    public String getAccountName() {
+        return accountName;
+    }
+
+    public Long getDomainId() {
+        return domainId;
+    }
+
+    public List<Long> getNetworkIds() {
+        return networkIds;
+    }
+
+    public List<Long> getSecurityGroupIdList() {
+        return securityGroupIdList;
+    }
+
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public void execute(){
+        try {
+           UserVm userVm = _userVmService.moveVMToUser(this);
+           if (userVm == null){
+               throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to move vm");
+           }
+           UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", userVm).get(0);
+           response.setResponseName(DeployVMCmd.getResultObjectName());
+           this.setResponseObject(response);
+        }catch (Exception e){
+            e.printStackTrace();
+            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to move vm " + e.getMessage());
+        }
+
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        UserVm vm = _responseGenerator.findUserVmById(getVmId());
+        if (vm != null) {
+            return vm.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/6fc3bc37/api/src/org/apache/cloudstack/api/admin/vm/command/MigrateVMCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/admin/vm/command/MigrateVMCmd.java b/api/src/org/apache/cloudstack/api/admin/vm/command/MigrateVMCmd.java
new file mode 100644
index 0000000..57cd8fe
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/admin/vm/command/MigrateVMCmd.java
@@ -0,0 +1,171 @@
+// 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.admin.vm.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.UserVmResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ManagementServerException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.exception.VirtualMachineMigrationException;
+import com.cloud.host.Host;
+import com.cloud.storage.StoragePool;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+import com.cloud.uservm.UserVm;
+import com.cloud.vm.VirtualMachine;
+
+@Implementation(description="Attempts Migration of a VM to a different host or Root volume of the vm to a different storage pool", responseObject=UserVmResponse.class)
+public class MigrateVMCmd extends BaseAsyncCmd {
+    public static final Logger s_logger = Logger.getLogger(MigrateVMCmd.class.getName());
+
+    private static final String s_name = "migratevirtualmachineresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @IdentityMapper(entityTableName="host")
+    @Parameter(name=ApiConstants.HOST_ID, type=CommandType.LONG, required=false, description="Destination Host ID to migrate VM to. Required for live migrating a VM from host to host")
+    private Long hostId;
+
+    @IdentityMapper(entityTableName="vm_instance")
+    @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, required=true, description="the ID of the virtual machine")
+    private Long virtualMachineId;
+
+    @IdentityMapper(entityTableName="storage_pool")
+    @Parameter(name=ApiConstants.STORAGE_ID, type=CommandType.LONG, required=false, description="Destination storage pool ID to migrate VM volumes to. Required for migrating the root disk volume")
+    private Long storageId;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getHostId() {
+        return hostId;
+    }
+
+    public Long getVirtualMachineId() {
+        return virtualMachineId;
+    }
+
+    public Long getStoragePoolId() {
+        return storageId;
+    }
+
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        UserVm userVm = _entityMgr.findById(UserVm.class, getVirtualMachineId());
+        if (userVm != null) {
+            return userVm.getAccountId();
+        }
+
+        return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_VM_MIGRATE;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return  "Attempting to migrate VM Id: " + getVirtualMachineId() + " to host Id: "+ getHostId();
+    }
+
+    @Override
+    public void execute(){
+        if (getHostId() == null && getStoragePoolId() == null) {
+            throw new InvalidParameterValueException("either hostId or storageId must be specified");
+        }
+
+        if (getHostId() != null && getStoragePoolId() != null) {
+            throw new InvalidParameterValueException("only one of hostId and storageId can be specified");
+        }
+
+        UserVm userVm = _userVmService.getUserVm(getVirtualMachineId());
+        if (userVm == null) {
+            throw new InvalidParameterValueException("Unable to find the VM by id=" + getVirtualMachineId());
+        }
+
+        Host destinationHost = null;
+        if (getHostId() != null) {
+            destinationHost = _resourceService.getHost(getHostId());
+            if (destinationHost == null) {
+                throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id=" + getHostId());
+            }
+            UserContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: "+ getHostId());
+        }
+
+        StoragePool destStoragePool = null;
+        if (getStoragePoolId() != null) {
+            destStoragePool = _storageService.getStoragePool(getStoragePoolId());
+            if (destStoragePool == null) {
+                throw new InvalidParameterValueException("Unable to find the storage pool to migrate the VM");
+            }
+            UserContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to storage pool Id: "+ getStoragePoolId());
+        }
+
+        try{
+            VirtualMachine migratedVm = null;
+            if (getHostId() != null) {
+                migratedVm = _userVmService.migrateVirtualMachine(getVirtualMachineId(), destinationHost);
+            } else if (getStoragePoolId() != null) {
+                migratedVm = _userVmService.vmStorageMigration(getVirtualMachineId(), destStoragePool);
+            }
+            if (migratedVm != null) {
+                UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", (UserVm)migratedVm).get(0);
+                response.setResponseName(getCommandName());
+                this.setResponseObject(response);
+            } else {
+                throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to migrate vm");
+            }
+        } catch (ResourceUnavailableException ex) {
+            s_logger.warn("Exception: ", ex);
+            throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
+        } catch (ConcurrentOperationException e) {
+            s_logger.warn("Exception: ", e);
+            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
+        } catch (ManagementServerException e) {
+            s_logger.warn("Exception: ", e);
+            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
+        } catch (VirtualMachineMigrationException e) {
+            s_logger.warn("Exception: ", e);
+            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/admin/vm/command/RecoverVMCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/admin/vm/command/RecoverVMCmd.java b/api/src/org/apache/cloudstack/api/admin/vm/command/RecoverVMCmd.java
new file mode 100644
index 0000000..5baa67f
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/admin/vm/command/RecoverVMCmd.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.admin.vm.command;
+
+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.UserVmResponse;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.user.Account;
+import com.cloud.uservm.UserVm;
+
+@Implementation(description="Recovers a virtual machine.", responseObject=UserVmResponse.class)
+public class RecoverVMCmd extends BaseCmd {
+    public static final Logger s_logger = Logger.getLogger(RecoverVMCmd.class.getName());
+
+    private static final String s_name = "recovervirtualmachineresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @IdentityMapper(entityTableName="vm_instance")
+    @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
+    private Long id;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        UserVm userVm = _entityMgr.findById(UserVm.class, getId());
+        if (userVm != null) {
+            return userVm.getAccountId();
+        }
+
+        return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+    }
+
+    @Override
+    public void execute() throws ResourceAllocationException{
+        UserVm result = _userVmService.recoverVirtualMachine(this);
+        if (result != null){
+            UserVmResponse recoverVmResponse = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
+            recoverVmResponse.setResponseName(getCommandName());
+            this.setResponseObject(recoverVmResponse);
+        } else {
+            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to recover vm");
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/user/vm/command/DeployVMCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/vm/command/DeployVMCmd.java b/api/src/org/apache/cloudstack/api/user/vm/command/DeployVMCmd.java
new file mode 100644
index 0000000..b06241d
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/user/vm/command/DeployVMCmd.java
@@ -0,0 +1,451 @@
+// 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.vm.command;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ACL;
+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.UserVmResponse;
+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.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.network.IpAddress;
+import com.cloud.network.Network;
+import com.cloud.network.security.SecurityGroup;
+import com.cloud.offering.DiskOffering;
+import com.cloud.offering.ServiceOffering;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+import com.cloud.uservm.UserVm;
+
+
+@Implementation(description="Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject=UserVmResponse.class)
+public class DeployVMCmd extends BaseAsyncCreateCmd {
+    public static final Logger s_logger = Logger.getLogger(DeployVMCmd.class.getName());
+
+    private static final String s_name = "deployvirtualmachineresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @IdentityMapper(entityTableName="data_center")
+    @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="availability zone for the virtual machine")
+    private Long zoneId;
+
+    @ACL
+    @IdentityMapper(entityTableName="disk_offering")
+    @Parameter(name=ApiConstants.SERVICE_OFFERING_ID, type=CommandType.LONG, required=true, description="the ID of the service offering for the virtual machine", resourceType=ServiceOffering.class)
+    private Long serviceOfferingId;
+
+    @ACL
+    @IdentityMapper(entityTableName="vm_template")
+    @Parameter(name=ApiConstants.TEMPLATE_ID, type=CommandType.LONG, required=true, description="the ID of the template for the virtual machine",resourceType=VirtualMachineTemplate.class)
+    private Long templateId;
+
+    @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="host name for the virtual machine")
+    private String name;
+
+    @Parameter(name=ApiConstants.DISPLAY_NAME, type=CommandType.STRING, description="an optional user generated name for the virtual machine")
+    private String displayName;
+
+    //Owner information
+    @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="an optional account for the virtual machine. Must be used with domainId.")
+    private String accountName;
+
+    @IdentityMapper(entityTableName="domain")
+    @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="an optional domainId for the virtual machine. If the account parameter is used, domainId must also be used.", entityType=Domain.class)
+    private Long domainId;
+
+    //Network information
+    @ACL
+    @IdentityMapper(entityTableName="networks")
+    @Parameter(name=ApiConstants.NETWORK_IDS, type=CommandType.LIST, collectionType=CommandType.LONG, description="list of network ids used by virtual machine. Can't be specified with ipToNetworkList parameter", resourceType=Network.class)
+    private List<Long> networkIds;
+
+    //DataDisk information
+    @ACL
+    @IdentityMapper(entityTableName="disk_offering")
+    @Parameter(name=ApiConstants.DISK_OFFERING_ID, type=CommandType.LONG, description="the ID of the disk offering for the virtual machine. If the template is of ISO format, the diskOfferingId is for the root disk volume. Otherwise this parameter is used to indicate the offering for the data disk volume. If the templateId parameter passed is from a Template object, the diskOfferingId refers to a DATA Disk Volume created. If the templateId parameter passed is from an ISO object, the diskOfferingId refers to a ROOT Disk Volume created.", resourceType=DiskOffering.class)
+    private Long diskOfferingId;
+
+    @Parameter(name=ApiConstants.SIZE, type=CommandType.LONG, description="the arbitrary size for the DATADISK volume. Mutually exclusive with diskOfferingId")
+    private Long size;
+
+    @Parameter(name=ApiConstants.GROUP, type=CommandType.STRING, description="an optional group for the virtual machine")
+    private String group;
+
+    @Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, description="the hypervisor on which to deploy the virtual machine")
+    private String hypervisor;
+
+    @Parameter(name=ApiConstants.USER_DATA, type=CommandType.STRING, description="an optional binary data that can be sent to the virtual machine upon a successful deployment. This binary data must be base64 encoded before adding it to the request. Currently only HTTP GET is supported. Using HTTP GET (via querystring), you can send up to 2KB of data after base64 encoding.", length=2048)
+    private String userData;
+
+    @Parameter(name=ApiConstants.SSH_KEYPAIR, type=CommandType.STRING, description="name of the ssh key pair used to login to the virtual machine")
+    private String sshKeyPairName;
+
+
+    @IdentityMapper(entityTableName="host")
+    @Parameter(name=ApiConstants.HOST_ID, type=CommandType.LONG, description="destination Host ID to deploy the VM to - parameter available for root admin only")
+    private Long hostId;
+
+    @ACL
+    @IdentityMapper(entityTableName="security_group")
+    @Parameter(name=ApiConstants.SECURITY_GROUP_IDS, type=CommandType.LIST, collectionType=CommandType.LONG, description="comma separated list of security groups id that going to be applied to the virtual machine. Should be passed only when vm is created from a zone with Basic Network support. Mutually exclusive with securitygroupnames parameter", resourceType=SecurityGroup.class)
+    private List<Long> securityGroupIdList;
+
+    @ACL
+    @Parameter(name=ApiConstants.SECURITY_GROUP_NAMES, type=CommandType.LIST, collectionType=CommandType.STRING, description="comma separated list of security groups names that going to be applied to the virtual machine. Should be passed only when vm is created from a zone with Basic Network support. Mutually exclusive with securitygroupids parameter", resourceType=SecurityGroup.class)
+    private List<String> securityGroupNameList;
+
+    @ACL(checkKeyAccess=true)
+    @Parameter(name = ApiConstants.IP_NETWORK_LIST, type = CommandType.MAP, description = "ip to network mapping. Can't be specified with networkIds parameter. Example: iptonetworklist[0].ip=10.10.10.11&iptonetworklist[0].networkid=204 - requests to use ip 10.10.10.11 in network id=204",resourceType={Network.class,IpAddress.class})
+    private Map ipToNetworkList;
+
+    @Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, description="the ip address for default vm's network")
+    private String ipAddress;
+
+    @Parameter(name=ApiConstants.KEYBOARD, type=CommandType.STRING, description="an optional keyboard device type for the virtual machine. valid value can be one of de,de-ch,es,fi,fr,fr-be,fr-ch,is,it,jp,nl-be,no,pt,uk,us")
+    private String keyboard;
+
+    @IdentityMapper(entityTableName="projects")
+    @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="Deploy vm for the project")
+    private Long projectId;
+
+    @Parameter(name=ApiConstants.START_VM, type=CommandType.BOOLEAN, description="true if network offering supports specifying ip ranges; defaulted to true if not specified")
+    private Boolean startVm;
+
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public String getEntityTable() {
+        return "vm_instance";
+    }
+
+    public String getAccountName() {
+        if (accountName == null) {
+            return UserContext.current().getCaller().getAccountName();
+        }
+        return accountName;
+    }
+
+    public Long getDiskOfferingId() {
+        return diskOfferingId;
+    }
+
+    public String getDisplayName() {
+        return displayName;
+    }
+
+    public Long getDomainId() {
+        if (domainId == null) {
+            return UserContext.current().getCaller().getDomainId();
+        }
+        return domainId;
+    }
+
+    public String getGroup() {
+        return group;
+    }
+
+    public HypervisorType getHypervisor() {
+        return HypervisorType.getType(hypervisor);
+    }
+
+    public List<Long> getSecurityGroupIdList() {
+        if (securityGroupNameList != null && securityGroupIdList != null) {
+            throw new InvalidParameterValueException("securitygroupids parameter is mutually exclusive with securitygroupnames parameter");
+        }
+
+       //transform group names to ids here
+       if (securityGroupNameList != null) {
+            List<Long> securityGroupIds = new ArrayList<Long>();
+            for (String groupName : securityGroupNameList) {
+                Long groupId = _responseGenerator.getSecurityGroupId(groupName, getEntityOwnerId());
+                if (groupId == null) {
+                    throw new InvalidParameterValueException("Unable to find group by name " + groupName + " for account " + getEntityOwnerId());
+                } else {
+                    securityGroupIds.add(groupId);
+                }
+            }
+            return securityGroupIds;
+        } else {
+            return securityGroupIdList;
+        }
+    }
+
+    public Long getServiceOfferingId() {
+        return serviceOfferingId;
+    }
+
+    public Long getSize() {
+        return size;
+    }
+
+    public Long getTemplateId() {
+        return templateId;
+    }
+
+    public String getUserData() {
+        return userData;
+    }
+
+    public Long getZoneId() {
+        return zoneId;
+    }
+
+    public List<Long> getNetworkIds() {
+       if (ipToNetworkList != null) {
+           if (networkIds != null || ipAddress != null) {
+               throw new InvalidParameterValueException("ipToNetworkMap can't be specified along with networkIds or ipAddress");
+           } else {
+               List<Long> networks = new ArrayList<Long>();
+               networks.addAll(getIpToNetworkMap().keySet());
+               return networks;
+           }
+       }
+        return networkIds;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getSSHKeyPairName() {
+        return sshKeyPairName;
+    }
+
+    public Long getHostId() {
+        return hostId;
+    }
+
+    public boolean getStartVm() {
+        return startVm == null ? true : startVm;
+    }
+
+    private Map<Long, String> getIpToNetworkMap() {
+        if ((networkIds != null || ipAddress != null) && ipToNetworkList != null) {
+            throw new InvalidParameterValueException("NetworkIds and ipAddress can't be specified along with ipToNetworkMap parameter");
+        }
+        LinkedHashMap<Long, String> ipToNetworkMap = null;
+        if (ipToNetworkList != null && !ipToNetworkList.isEmpty()) {
+            ipToNetworkMap = new LinkedHashMap<Long, String>();
+            Collection ipsCollection = ipToNetworkList.values();
+            Iterator iter = ipsCollection.iterator();
+            while (iter.hasNext()) {
+                HashMap<String, String> ips = (HashMap<String, String>) iter.next();
+                Long networkId = Long.valueOf(_responseGenerator.getIdentiyId("networks", ips.get("networkid")));
+                String requestedIp = (String) ips.get("ip");
+                ipToNetworkMap.put(networkId, requestedIp);
+            }
+        }
+
+        return ipToNetworkMap;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    public static String getResultObjectName() {
+        return "virtualmachine";
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
+        if (accountId == null) {
+            return UserContext.current().getCaller().getId();
+        }
+
+        return accountId;
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_VM_CREATE;
+    }
+
+    @Override
+    public String getCreateEventType() {
+        return EventTypes.EVENT_VM_CREATE;
+    }
+
+    @Override
+    public String getCreateEventDescription() {
+        return "creating Vm";
+    }
+
+    @Override
+    public String getEventDescription() {
+        return  "starting Vm. Vm Id: "+getEntityId();
+    }
+
+    @Override
+    public AsyncJob.Type getInstanceType() {
+        return AsyncJob.Type.VirtualMachine;
+    }
+
+    @Override
+    public void execute(){
+        UserVm result;
+
+        if (getStartVm()) {
+            try {
+                UserContext.current().setEventDetails("Vm Id: "+getEntityId());
+                if (getHypervisor() == HypervisorType.BareMetal) {
+                    result = _bareMetalVmService.startVirtualMachine(this);
+                } else {
+                    result = _userVmService.startVirtualMachine(this);
+                }
+            } catch (ResourceUnavailableException ex) {
+                s_logger.warn("Exception: ", ex);
+                throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
+            } catch (ConcurrentOperationException ex) {
+                s_logger.warn("Exception: ", ex);
+                throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
+            } catch (InsufficientCapacityException ex) {
+                s_logger.info(ex);
+                s_logger.trace(ex);
+                throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
+            }
+        } else {
+            result = _userVmService.getUserVm(getEntityId());
+        }
+
+        if (result != null) {
+            UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
+            response.setResponseName(getCommandName());
+            this.setResponseObject(response);
+        } else {
+            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm");
+        }
+    }
+
+    @Override
+    public void create() throws ResourceAllocationException{
+        try {
+            //Verify that all objects exist before passing them to the service
+            Account owner = _accountService.getActiveAccountById(getEntityOwnerId());
+
+            DataCenter zone = _configService.getZone(zoneId);
+            if (zone == null) {
+                throw new InvalidParameterValueException("Unable to find zone by id=" + zoneId);
+            }
+
+            ServiceOffering serviceOffering = _configService.getServiceOffering(serviceOfferingId);
+            if (serviceOffering == null) {
+                throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
+            }
+
+            VirtualMachineTemplate template = _templateService.getTemplate(templateId);
+            // Make sure a valid template ID was specified
+            if (template == null) {
+                throw new InvalidParameterValueException("Unable to use template " + templateId);
+            }
+
+            DiskOffering diskOffering = null;
+            if (diskOfferingId != null) {
+                diskOffering = _configService.getDiskOffering(diskOfferingId);
+                if (diskOffering == null) {
+                    throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
+                }
+            }
+
+            if (!zone.isLocalStorageEnabled()) {
+                if (serviceOffering.getUseLocalStorage()) {
+                    throw new InvalidParameterValueException("Zone is not configured to use local storage but service offering " + serviceOffering.getName() + " uses it");
+                }
+                if (diskOffering != null && diskOffering.getUseLocalStorage()) {
+                    throw new InvalidParameterValueException("Zone is not configured to use local storage but disk offering " + diskOffering.getName() + " uses it");
+                }
+            }
+
+            UserVm vm = null;
+            if (getHypervisor() == HypervisorType.BareMetal) {
+                vm = _bareMetalVmService.createVirtualMachine(this);
+            } else {
+                if (zone.getNetworkType() == NetworkType.Basic) {
+                    if (getNetworkIds() != null) {
+                        throw new InvalidParameterValueException("Can't specify network Ids in Basic zone");
+                    } else {
+                        vm = _userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, getSecurityGroupIdList(), owner, name,
+                                displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress, keyboard);
+                    }
+                } else {
+                    if (zone.isSecurityGroupEnabled())  {
+                        vm = _userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, getNetworkIds(), getSecurityGroupIdList(),
+                                owner, name, displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress, keyboard);
+                    } else {
+                        if (getSecurityGroupIdList() != null && !getSecurityGroupIdList().isEmpty()) {
+                            throw new InvalidParameterValueException("Can't create vm with security groups; security group feature is not enabled per zone");
+                        }
+                        vm = _userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, getNetworkIds(), owner, name, displayName,
+                                diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress, keyboard);
+                    }
+                }
+            }
+
+            if (vm != null) {
+                setEntityId(vm.getId());
+            } else {
+                throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm");
+            }
+        } catch (InsufficientCapacityException ex) {
+            s_logger.info(ex);
+            s_logger.trace(ex);
+            throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
+        } catch (ResourceUnavailableException ex) {
+            s_logger.warn("Exception: ", ex);
+            throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
+        }  catch (ConcurrentOperationException ex) {
+            s_logger.warn("Exception: ", ex);
+            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/user/vm/command/DestroyVMCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/vm/command/DestroyVMCmd.java b/api/src/org/apache/cloudstack/api/user/vm/command/DestroyVMCmd.java
new file mode 100644
index 0000000..a308b69
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/user/vm/command/DestroyVMCmd.java
@@ -0,0 +1,115 @@
+// 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.vm.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.UserVmResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+import com.cloud.uservm.UserVm;
+
+@Implementation(description="Destroys a virtual machine. Once destroyed, only the administrator can recover it.", responseObject=UserVmResponse.class)
+public class DestroyVMCmd extends BaseAsyncCmd {
+    public static final Logger s_logger = Logger.getLogger(DestroyVMCmd.class.getName());
+
+    private static final String s_name = "destroyvirtualmachineresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @IdentityMapper(entityTableName="vm_instance")
+    @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
+    private Long id;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        UserVm vm = _responseGenerator.findUserVmById(getId());
+        if (vm != null) {
+            return vm.getAccountId();
+        }
+
+        return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_VM_DESTROY;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return  "destroying vm: " + getId();
+    }
+
+    public AsyncJob.Type getInstanceType() {
+        return AsyncJob.Type.VirtualMachine;
+    }
+
+    public Long getInstanceId() {
+        return getId();
+    }
+
+    @Override
+    public void execute() throws ResourceUnavailableException, ConcurrentOperationException{
+        UserContext.current().setEventDetails("Vm Id: "+getId());
+        UserVm result;
+        if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
+            result = _bareMetalVmService.destroyVm(this);
+        } else {
+            result = _userVmService.destroyVm(this);
+        }
+
+        if (result != null) {
+            UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
+            response.setResponseName("virtualmachine");
+            this.setResponseObject(response);
+        } else {
+            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to destroy vm");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6fc3bc37/api/src/org/apache/cloudstack/api/user/vm/command/GetVMPasswordCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/vm/command/GetVMPasswordCmd.java b/api/src/org/apache/cloudstack/api/user/vm/command/GetVMPasswordCmd.java
new file mode 100644
index 0000000..54464ee
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/user/vm/command/GetVMPasswordCmd.java
@@ -0,0 +1,84 @@
+// 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.vm.command;
+
+import java.security.InvalidParameterException;
+
+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 com.cloud.api.response.GetVMPasswordResponse;
+import com.cloud.user.Account;
+import com.cloud.uservm.UserVm;
+
+@Implementation(responseObject=GetVMPasswordResponse.class, description="Returns an encrypted password for the VM")
+public class GetVMPasswordCmd extends BaseCmd {
+    public static final Logger s_logger = Logger.getLogger(GetVMPasswordCmd.class.getName());
+    private static final String s_name = "getvmpasswordresponse";
+
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @IdentityMapper(entityTableName="vm_instance")
+    @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
+    private Long id;
+
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public void execute() {
+        String passwd = _mgr.getVMPassword(this);
+        if (passwd == null || passwd.equals(""))
+            throw new InvalidParameterException("No password for VM with id '" + getId() + "' found.");
+
+        this.setResponseObject(new GetVMPasswordResponse(getCommandName(), passwd));
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        UserVm userVm = _entityMgr.findById(UserVm.class, getId());
+        if (userVm != null) {
+            return userVm.getAccountId();
+        }
+
+        return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+    }
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+}