cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject git commit: updated refs/heads/master to bd79fb3
Date Thu, 16 Jan 2014 23:49:24 GMT
Updated Branches:
  refs/heads/master 07f73ec05 -> bd79fb33a


CLOUDSTACK-5870: API support for retrieving user data


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/bd79fb33
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/bd79fb33
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/bd79fb33

Branch: refs/heads/master
Commit: bd79fb33a6978a9dbe7933bcda1579238da4bb27
Parents: 07f73ec
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Thu Jan 16 15:31:01 2014 -0800
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Thu Jan 16 15:31:18 2014 -0800

----------------------------------------------------------------------
 api/src/com/cloud/vm/UserVmService.java         |  8 +++
 .../api/command/admin/vm/GetVMUserDataCmd.java  | 63 ++++++++++++++++++++
 .../api/response/VMUserDataResponse.java        | 26 ++++++++
 client/tomcatconf/commands.properties.in        |  1 +
 .../com/cloud/server/ManagementServerImpl.java  |  2 +
 server/src/com/cloud/vm/UserVmManagerImpl.java  | 12 ++++
 6 files changed, 112 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bd79fb33/api/src/com/cloud/vm/UserVmService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/vm/UserVmService.java b/api/src/com/cloud/vm/UserVmService.java
index e02573d..51a8fdf 100755
--- a/api/src/com/cloud/vm/UserVmService.java
+++ b/api/src/com/cloud/vm/UserVmService.java
@@ -461,4 +461,12 @@ public interface UserVmService {
 
     UserVm expungeVm(long vmId) throws ResourceUnavailableException, ConcurrentOperationException;
 
+    /**
+     * Finds and returns an encrypted password for a VM.
+     *
+     * @param  userVmId
+     * @return Base64 encoded userdata
+     */
+    String getVmUserData(long vmId);
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bd79fb33/api/src/org/apache/cloudstack/api/command/admin/vm/GetVMUserDataCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/vm/GetVMUserDataCmd.java b/api/src/org/apache/cloudstack/api/command/admin/vm/GetVMUserDataCmd.java
new file mode 100644
index 0000000..b02dc11
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/admin/vm/GetVMUserDataCmd.java
@@ -0,0 +1,63 @@
+package org.apache.cloudstack.api.command.admin.vm;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.cloudstack.api.response.VMUserDataResponse;
+import org.apache.log4j.Logger;
+
+import com.cloud.user.Account;
+import com.cloud.uservm.UserVm;
+
+@APICommand(name = "getVirtualMachineUserData", description = "Returns user data associated
with the VM", responseObject = VMUserDataResponse.class, since = "4.4")
+public class GetVMUserDataCmd extends BaseCmd {
+    public static final Logger s_logger = Logger.getLogger(GetVMUserDataCmd.class);
+    private static final String s_name = "getvirtualmachineuserdataresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type = CommandType.UUID, entityType
= UserVmResponse.class, required = true, description = "The ID of the virtual machine")
+    private Long vmId;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public long getId() {
+        return vmId;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public void execute() {
+        String userData = _userVmService.getVmUserData(getId());
+        VMUserDataResponse resp = new VMUserDataResponse();
+        resp.setVmId(_entityMgr.findById(UserVm.class, getId()).getUuid());
+        resp.setUserData(userData);
+        resp.setObjectName("virtualmachineuserdata");
+        resp.setResponseName(getCommandName());
+        this.setResponseObject(resp);
+    }
+
+    @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;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bd79fb33/api/src/org/apache/cloudstack/api/response/VMUserDataResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/VMUserDataResponse.java b/api/src/org/apache/cloudstack/api/response/VMUserDataResponse.java
new file mode 100644
index 0000000..dacf656
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/response/VMUserDataResponse.java
@@ -0,0 +1,26 @@
+package org.apache.cloudstack.api.response;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+public class VMUserDataResponse extends BaseResponse {
+    @SerializedName(ApiConstants.VIRTUAL_MACHINE_ID)
+    @Param(description = "the ID of the virtual machine")
+    private String vmId;
+
+    @SerializedName(ApiConstants.USER_DATA)
+    @Param(description = "Base 64 encoded VM user data")
+    private String userData;
+
+    public void setUserData(String userData) {
+        this.userData = userData;
+    }
+
+    public void setVmId(String vmId) {
+        this.vmId = vmId;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bd79fb33/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index c5ac7fd..4f38c31 100644
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -72,6 +72,7 @@ migrateVirtualMachine=1
 migrateVirtualMachineWithVolume=1
 recoverVirtualMachine=7
 expungeVirtualMachine=7
+getVirtualMachineUserData=15
 
 #### snapshot commands
 createSnapshot=15

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bd79fb33/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index 59767f3..bbb31cf 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -198,6 +198,7 @@ import org.apache.cloudstack.api.command.admin.vlan.ListVlanIpRangesCmd;
 import org.apache.cloudstack.api.command.admin.vlan.ReleasePublicIpRangeCmd;
 import org.apache.cloudstack.api.command.admin.vm.AssignVMCmd;
 import org.apache.cloudstack.api.command.admin.vm.ExpungeVMCmd;
+import org.apache.cloudstack.api.command.admin.vm.GetVMUserDataCmd;
 import org.apache.cloudstack.api.command.admin.vm.MigrateVMCmd;
 import org.apache.cloudstack.api.command.admin.vm.MigrateVirtualMachineWithVolumeCmd;
 import org.apache.cloudstack.api.command.admin.vm.RecoverVMCmd;
@@ -2854,6 +2855,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         cmdList.add(GenerateAlertCmd.class);
         cmdList.add(ListOvsElementsCmd.class);
         cmdList.add(ConfigureOvsElementCmd.class);
+        cmdList.add(GetVMUserDataCmd.class);
         return cmdList;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bd79fb33/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index f57e1b4..fc0ec0e 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -4806,4 +4806,16 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
     public ConfigKey<?>[] getConfigKeys() {
         return new ConfigKey<?>[] {EnableDynamicallyScaleVm};
     }
+
+    @Override
+    public String getVmUserData(long vmId) {
+        UserVmVO vm = _vmDao.findById(vmId);
+        if (vm == null) {
+            throw new InvalidParameterValueException("Unable to find virual machine with
id " + vmId);
+        }
+
+        //check permissions
+        _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, vm);
+        return vm.getUserData();
+    }
 }


Mime
View raw message